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 <qlistview.h>
12 #include <qtabwidget.h>
13 #include <kfiledialog.h>
14 #include <klocale.h> /* i18n */
18 PgmArgs::PgmArgs(QWidget
* parent
, const QString
& pgm
, QDict
<EnvVar
>& envVars
,
19 const QStringList
& allOptions
) :
20 PgmArgsBase(parent
, "pgmargs", true),
23 m_envVars
.setAutoDelete(false);
27 QString newText
= labelArgs
->text().arg(fi
.fileName());
28 labelArgs
->setText(newText
);
31 // add options only if the option list is non-empty
32 if (!allOptions
.isEmpty())
34 xsldbgOptions
->insertStringList(allOptions
);
38 delete xsldbgOptionsPage
;
39 xsldbgOptionsPage
= 0;
49 // initializes the selected options
50 void PgmArgs::setOptions(const QStringList
& selectedOptions
)
52 QStringList::ConstIterator it
;
53 for (it
= selectedOptions
.begin(); it
!= selectedOptions
.end(); ++it
) {
54 for (uint i
= 0; i
< xsldbgOptions
->count(); i
++) {
55 if (xsldbgOptions
->text(i
) == *it
) {
56 xsldbgOptions
->setSelected(i
, true);
63 // returns the selected options
64 QStringList
PgmArgs::options() const
67 if (xsldbgOptionsPage
!= 0)
69 for (uint i
= 0; i
< xsldbgOptions
->count(); i
++) {
70 if (xsldbgOptions
->isSelected(i
))
71 sel
.append(xsldbgOptions
->text(i
));
78 void PgmArgs::modifyVar()
80 modifyVar(true); // re-add deleted entries
83 void PgmArgs::modifyVar(bool resurrect
)
86 parseEnvInput(name
, value
);
87 if (name
.isEmpty() || name
.find(' ') >= 0) /* disallow spaces in names */
90 // lookup the value in the dictionary
91 EnvVar
* val
= m_envVars
[name
];
93 // see if this is a zombie
94 if (val
->status
== EnvVar::EVdeleted
) {
99 val
->status
= EnvVar::EVdirty
;
100 val
->item
= new QListViewItem(envList
, name
, value
); // inserts itself
101 m_envVars
.insert(name
, val
);
103 } else if (value
!= val
->value
) {
106 val
->status
= EnvVar::EVdirty
;
107 val
->item
->setText(1, value
);
113 val
->status
= EnvVar::EVnew
;
114 val
->item
= new QListViewItem(envList
, name
, value
); // inserts itself
115 m_envVars
.insert(name
, val
);
117 envList
->setSelected(val
->item
, true);
118 buttonDelete
->setEnabled(true);
121 // delete the selected item
122 void PgmArgs::deleteVar()
124 QListViewItem
* item
= envList
->selectedItem();
127 QString name
= item
->text(0);
129 // lookup the value in the dictionary
130 EnvVar
* val
= m_envVars
[name
];
135 // if this is a new item, delete it completely, otherwise zombie-ize it
136 if (val
->status
== EnvVar::EVnew
) {
137 m_envVars
.remove(name
);
140 // mark value deleted
141 val
->status
= EnvVar::EVdeleted
;
145 // there is no selected item anymore
146 buttonDelete
->setEnabled(false);
149 void PgmArgs::parseEnvInput(QString
& name
, QString
& value
)
151 // parse input from edit field
152 QString input
= envVar
->text();
153 int equalSign
= input
.find('=');
154 if (equalSign
>= 0) {
155 name
= input
.left(equalSign
).stripWhiteSpace();
156 value
= input
.mid(equalSign
+1);
158 name
= input
.stripWhiteSpace();
159 value
= QString(); /* value is empty */
163 void PgmArgs::initEnvList()
165 QDictIterator
<EnvVar
> it
= m_envVars
;
168 for (; (val
= it
) != 0; ++it
) {
169 val
->status
= EnvVar::EVclean
;
170 name
= it
.currentKey();
171 val
->item
= new QListViewItem(envList
, name
, val
->value
); // inserts itself
174 envList
->setAllColumnsShowFocus(true);
175 buttonDelete
->setEnabled(envList
->selectedItem() != 0);
178 void PgmArgs::envListCurrentChanged()
180 QListViewItem
* item
= envList
->selectedItem();
181 buttonDelete
->setEnabled(item
!= 0);
185 // must get name from list box
186 QString name
= item
->text(0);
187 EnvVar
* val
= m_envVars
[name
];
190 envVar
->setText(name
+ "=" + val
->value
);
192 envVar
->setText(name
);
196 void PgmArgs::accept()
198 // simulate that the Modify button was pressed, but don't revive
199 // dead entries even if the user changed the edit box
204 void PgmArgs::browseWd()
206 // browse for the working directory
207 QString newDir
= KFileDialog::getExistingDirectory(wd(), this);
208 if (!newDir
.isEmpty()) {
213 void PgmArgs::browseArgFile()
215 QString caption
= i18n("Select a file name to insert as program argument");
217 // use the selection as default
218 QString f
= programArgs
->markedText();
219 f
= KFileDialog::getSaveFileName(f
, QString::null
,
221 // don't clear the selection if no file was selected
223 programArgs
->insert(f
);
227 void PgmArgs::browseArgDir()
229 QString caption
= i18n("Select a directory to insert as program argument");
231 // use the selection as default
232 QString f
= programArgs
->markedText();
233 f
= KFileDialog::getExistingDirectory(f
, this, caption
);
234 // don't clear the selection if no file was selected
236 programArgs
->insert(f
);
240 #include "pgmargs.moc"