2 * Copyright Johannes Sixt
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
9 #include <kfiledialog.h>
10 #include <klocale.h> /* i18n */
13 PgmArgs::PgmArgs(QWidget
* parent
, const QString
& pgm
, Q3Dict
<EnvVar
>& envVars
,
14 const QStringList
& allOptions
) :
20 m_envVars
.setAutoDelete(false);
24 QString newText
= labelArgs
->text().arg(fi
.fileName());
25 labelArgs
->setText(newText
);
28 // add options only if the option list is non-empty
29 if (!allOptions
.isEmpty())
31 xsldbgOptions
->insertStringList(allOptions
);
35 delete xsldbgOptionsPage
;
36 xsldbgOptionsPage
= 0;
46 // initializes the selected options
47 void PgmArgs::setOptions(const QStringList
& selectedOptions
)
49 QStringList::ConstIterator it
;
50 for (it
= selectedOptions
.begin(); it
!= selectedOptions
.end(); ++it
) {
51 for (uint i
= 0; i
< xsldbgOptions
->count(); i
++) {
52 if (xsldbgOptions
->text(i
) == *it
) {
53 xsldbgOptions
->setSelected(i
, true);
60 // returns the selected options
61 QStringList
PgmArgs::options() const
64 if (xsldbgOptionsPage
!= 0)
66 for (uint i
= 0; i
< xsldbgOptions
->count(); i
++) {
67 if (xsldbgOptions
->isSelected(i
))
68 sel
.append(xsldbgOptions
->text(i
));
75 void PgmArgs::on_buttonModify_clicked()
77 modifyVar(true); // re-add deleted entries
80 void PgmArgs::modifyVar(bool resurrect
)
83 parseEnvInput(name
, value
);
84 if (name
.isEmpty() || name
.find(' ') >= 0) /* disallow spaces in names */
87 // lookup the value in the dictionary
88 EnvVar
* val
= m_envVars
[name
];
90 // see if this is a zombie
91 if (val
->status
== EnvVar::EVdeleted
) {
96 val
->status
= EnvVar::EVdirty
;
97 val
->item
= new Q3ListViewItem(envList
, name
, value
); // inserts itself
98 m_envVars
.insert(name
, val
);
100 } else if (value
!= val
->value
) {
103 val
->status
= EnvVar::EVdirty
;
104 val
->item
->setText(1, value
);
110 val
->status
= EnvVar::EVnew
;
111 val
->item
= new Q3ListViewItem(envList
, name
, value
); // inserts itself
112 m_envVars
.insert(name
, val
);
114 envList
->setSelected(val
->item
, true);
115 buttonDelete
->setEnabled(true);
118 // delete the selected item
119 void PgmArgs::on_buttonDelete_clicked()
121 Q3ListViewItem
* item
= envList
->selectedItem();
124 QString name
= item
->text(0);
126 // lookup the value in the dictionary
127 EnvVar
* val
= m_envVars
[name
];
132 // if this is a new item, delete it completely, otherwise zombie-ize it
133 if (val
->status
== EnvVar::EVnew
) {
134 m_envVars
.remove(name
);
137 // mark value deleted
138 val
->status
= EnvVar::EVdeleted
;
142 // there is no selected item anymore
143 buttonDelete
->setEnabled(false);
146 void PgmArgs::parseEnvInput(QString
& name
, QString
& value
)
148 // parse input from edit field
149 QString input
= envVar
->text();
150 int equalSign
= input
.find('=');
151 if (equalSign
>= 0) {
152 name
= input
.left(equalSign
).stripWhiteSpace();
153 value
= input
.mid(equalSign
+1);
155 name
= input
.stripWhiteSpace();
156 value
= QString(); /* value is empty */
160 void PgmArgs::initEnvList()
162 Q3DictIterator
<EnvVar
> it
= m_envVars
;
165 for (; (val
= it
) != 0; ++it
) {
166 val
->status
= EnvVar::EVclean
;
167 name
= it
.currentKey();
168 val
->item
= new Q3ListViewItem(envList
, name
, val
->value
); // inserts itself
171 envList
->setAllColumnsShowFocus(true);
172 buttonDelete
->setEnabled(envList
->selectedItem() != 0);
175 void PgmArgs::on_envList_selectionChanged()
177 Q3ListViewItem
* item
= envList
->selectedItem();
178 buttonDelete
->setEnabled(item
!= 0);
182 // must get name from list box
183 QString name
= item
->text(0);
184 EnvVar
* val
= m_envVars
[name
];
187 envVar
->setText(name
+ "=" + val
->value
);
189 envVar
->setText(name
);
193 void PgmArgs::accept()
195 // simulate that the Modify button was pressed, but don't revive
196 // dead entries even if the user changed the edit box
201 void PgmArgs::on_wdBrowse_clicked()
203 // browse for the working directory
204 QString newDir
= KFileDialog::getExistingDirectory(wd(), this);
205 if (!newDir
.isEmpty()) {
210 void PgmArgs::on_insertFile_clicked()
212 QString caption
= i18n("Select a file name to insert as program argument");
214 // use the selection as default
215 QString f
= programArgs
->markedText();
216 f
= KFileDialog::getSaveFileName(f
, QString::null
,
218 // don't clear the selection if no file was selected
220 programArgs
->insert(f
);
224 void PgmArgs::on_insertDir_clicked()
226 QString caption
= i18n("Select a directory to insert as program argument");
228 // use the selection as default
229 QString f
= programArgs
->markedText();
230 f
= KFileDialog::getExistingDirectory(f
, this, caption
);
231 // don't clear the selection if no file was selected
233 programArgs
->insert(f
);
237 #include "pgmargs.moc"