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 <qpushbutton.h>
10 #include <q3listview.h>
11 #include <q3listbox.h>
12 #include <qtabwidget.h>
13 #include <kfiledialog.h>
14 #include <klocale.h> /* i18n */
17 PgmArgs::PgmArgs(QWidget
* parent
, const QString
& pgm
, Q3Dict
<EnvVar
>& envVars
,
18 const QStringList
& allOptions
) :
19 PgmArgsBase(parent
, "pgmargs", true),
22 m_envVars
.setAutoDelete(false);
26 QString newText
= labelArgs
->text().arg(fi
.fileName());
27 labelArgs
->setText(newText
);
30 // add options only if the option list is non-empty
31 if (!allOptions
.isEmpty())
33 xsldbgOptions
->insertStringList(allOptions
);
37 delete xsldbgOptionsPage
;
38 xsldbgOptionsPage
= 0;
48 // initializes the selected options
49 void PgmArgs::setOptions(const QStringList
& selectedOptions
)
51 QStringList::ConstIterator it
;
52 for (it
= selectedOptions
.begin(); it
!= selectedOptions
.end(); ++it
) {
53 for (uint i
= 0; i
< xsldbgOptions
->count(); i
++) {
54 if (xsldbgOptions
->text(i
) == *it
) {
55 xsldbgOptions
->setSelected(i
, true);
62 // returns the selected options
63 QStringList
PgmArgs::options() const
66 if (xsldbgOptionsPage
!= 0)
68 for (uint i
= 0; i
< xsldbgOptions
->count(); i
++) {
69 if (xsldbgOptions
->isSelected(i
))
70 sel
.append(xsldbgOptions
->text(i
));
77 void PgmArgs::modifyVar()
79 modifyVar(true); // re-add deleted entries
82 void PgmArgs::modifyVar(bool resurrect
)
85 parseEnvInput(name
, value
);
86 if (name
.isEmpty() || name
.find(' ') >= 0) /* disallow spaces in names */
89 // lookup the value in the dictionary
90 EnvVar
* val
= m_envVars
[name
];
92 // see if this is a zombie
93 if (val
->status
== EnvVar::EVdeleted
) {
98 val
->status
= EnvVar::EVdirty
;
99 val
->item
= new Q3ListViewItem(envList
, name
, value
); // inserts itself
100 m_envVars
.insert(name
, val
);
102 } else if (value
!= val
->value
) {
105 val
->status
= EnvVar::EVdirty
;
106 val
->item
->setText(1, value
);
112 val
->status
= EnvVar::EVnew
;
113 val
->item
= new Q3ListViewItem(envList
, name
, value
); // inserts itself
114 m_envVars
.insert(name
, val
);
116 envList
->setSelected(val
->item
, true);
117 buttonDelete
->setEnabled(true);
120 // delete the selected item
121 void PgmArgs::deleteVar()
123 Q3ListViewItem
* item
= envList
->selectedItem();
126 QString name
= item
->text(0);
128 // lookup the value in the dictionary
129 EnvVar
* val
= m_envVars
[name
];
134 // if this is a new item, delete it completely, otherwise zombie-ize it
135 if (val
->status
== EnvVar::EVnew
) {
136 m_envVars
.remove(name
);
139 // mark value deleted
140 val
->status
= EnvVar::EVdeleted
;
144 // there is no selected item anymore
145 buttonDelete
->setEnabled(false);
148 void PgmArgs::parseEnvInput(QString
& name
, QString
& value
)
150 // parse input from edit field
151 QString input
= envVar
->text();
152 int equalSign
= input
.find('=');
153 if (equalSign
>= 0) {
154 name
= input
.left(equalSign
).stripWhiteSpace();
155 value
= input
.mid(equalSign
+1);
157 name
= input
.stripWhiteSpace();
158 value
= QString(); /* value is empty */
162 void PgmArgs::initEnvList()
164 Q3DictIterator
<EnvVar
> it
= m_envVars
;
167 for (; (val
= it
) != 0; ++it
) {
168 val
->status
= EnvVar::EVclean
;
169 name
= it
.currentKey();
170 val
->item
= new Q3ListViewItem(envList
, name
, val
->value
); // inserts itself
173 envList
->setAllColumnsShowFocus(true);
174 buttonDelete
->setEnabled(envList
->selectedItem() != 0);
177 void PgmArgs::envListCurrentChanged()
179 Q3ListViewItem
* item
= envList
->selectedItem();
180 buttonDelete
->setEnabled(item
!= 0);
184 // must get name from list box
185 QString name
= item
->text(0);
186 EnvVar
* val
= m_envVars
[name
];
189 envVar
->setText(name
+ "=" + val
->value
);
191 envVar
->setText(name
);
195 void PgmArgs::accept()
197 // simulate that the Modify button was pressed, but don't revive
198 // dead entries even if the user changed the edit box
203 void PgmArgs::browseWd()
205 // browse for the working directory
206 QString newDir
= KFileDialog::getExistingDirectory(wd(), this);
207 if (!newDir
.isEmpty()) {
212 void PgmArgs::browseArgFile()
214 QString caption
= i18n("Select a file name to insert as program argument");
216 // use the selection as default
217 QString f
= programArgs
->markedText();
218 f
= KFileDialog::getSaveFileName(f
, QString::null
,
220 // don't clear the selection if no file was selected
222 programArgs
->insert(f
);
226 void PgmArgs::browseArgDir()
228 QString caption
= i18n("Select a directory to insert as program argument");
230 // use the selection as default
231 QString f
= programArgs
->markedText();
232 f
= KFileDialog::getExistingDirectory(f
, this, caption
);
233 // don't clear the selection if no file was selected
235 programArgs
->insert(f
);
239 #include "pgmargs.moc"