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 <kapplication.h>
14 #include <kfiledialog.h>
15 #include <klocale.h> /* i18n */
19 PgmArgs::PgmArgs(QWidget
* parent
, const QString
& pgm
, QDict
<EnvVar
>& envVars
,
20 const QStringList
& allOptions
) :
21 PgmArgsBase(parent
, "pgmargs", true),
24 m_envVars
.setAutoDelete(false);
28 QString newText
= labelArgs
->text().arg(fi
.fileName());
29 labelArgs
->setText(newText
);
32 // add options only if the option list is non-empty
33 if (!allOptions
.isEmpty())
35 xsldbgOptions
->insertStringList(allOptions
);
39 delete xsldbgOptionsPage
;
40 xsldbgOptionsPage
= 0;
50 // initializes the selected options
51 void PgmArgs::setOptions(const QStringList
& selectedOptions
)
53 QStringList::ConstIterator it
;
54 for (it
= selectedOptions
.begin(); it
!= selectedOptions
.end(); ++it
) {
55 for (uint i
= 0; i
< xsldbgOptions
->count(); i
++) {
56 if (xsldbgOptions
->text(i
) == *it
) {
57 xsldbgOptions
->setSelected(i
, true);
64 // returns the selected options
65 QStringList
PgmArgs::options() const
68 if (xsldbgOptionsPage
!= 0)
70 for (uint i
= 0; i
< xsldbgOptions
->count(); i
++) {
71 if (xsldbgOptions
->isSelected(i
))
72 sel
.append(xsldbgOptions
->text(i
));
79 void PgmArgs::modifyVar()
81 modifyVar(true); // re-add deleted entries
84 void PgmArgs::modifyVar(bool resurrect
)
87 parseEnvInput(name
, value
);
88 if (name
.isEmpty() || name
.find(' ') >= 0) /* disallow spaces in names */
91 // lookup the value in the dictionary
92 EnvVar
* val
= m_envVars
[name
];
94 // see if this is a zombie
95 if (val
->status
== EnvVar::EVdeleted
) {
100 val
->status
= EnvVar::EVdirty
;
101 val
->item
= new QListViewItem(envList
, name
, value
); // inserts itself
102 m_envVars
.insert(name
, val
);
104 } else if (value
!= val
->value
) {
107 val
->status
= EnvVar::EVdirty
;
108 val
->item
->setText(1, value
);
114 val
->status
= EnvVar::EVnew
;
115 val
->item
= new QListViewItem(envList
, name
, value
); // inserts itself
116 m_envVars
.insert(name
, val
);
118 envList
->setSelected(val
->item
, true);
119 buttonDelete
->setEnabled(true);
122 // delete the selected item
123 void PgmArgs::deleteVar()
125 QListViewItem
* item
= envList
->selectedItem();
128 QString name
= item
->text(0);
130 // lookup the value in the dictionary
131 EnvVar
* val
= m_envVars
[name
];
136 // if this is a new item, delete it completely, otherwise zombie-ize it
137 if (val
->status
== EnvVar::EVnew
) {
138 m_envVars
.remove(name
);
141 // mark value deleted
142 val
->status
= EnvVar::EVdeleted
;
146 // there is no selected item anymore
147 buttonDelete
->setEnabled(false);
150 void PgmArgs::parseEnvInput(QString
& name
, QString
& value
)
152 // parse input from edit field
153 QString input
= envVar
->text();
154 int equalSign
= input
.find('=');
155 if (equalSign
>= 0) {
156 name
= input
.left(equalSign
).stripWhiteSpace();
157 value
= input
.mid(equalSign
+1);
159 name
= input
.stripWhiteSpace();
160 value
= QString(); /* value is empty */
164 void PgmArgs::initEnvList()
166 QDictIterator
<EnvVar
> it
= m_envVars
;
169 for (; (val
= it
) != 0; ++it
) {
170 val
->status
= EnvVar::EVclean
;
171 name
= it
.currentKey();
172 val
->item
= new QListViewItem(envList
, name
, val
->value
); // inserts itself
175 envList
->setAllColumnsShowFocus(true);
176 buttonDelete
->setEnabled(envList
->selectedItem() != 0);
179 void PgmArgs::envListCurrentChanged()
181 QListViewItem
* item
= envList
->selectedItem();
182 buttonDelete
->setEnabled(item
!= 0);
186 // must get name from list box
187 QString name
= item
->text(0);
188 EnvVar
* val
= m_envVars
[name
];
191 envVar
->setText(name
+ "=" + val
->value
);
193 envVar
->setText(name
);
197 void PgmArgs::accept()
199 // simulate that the Modify button was pressed, but don't revive
200 // dead entries even if the user changed the edit box
205 void PgmArgs::browseWd()
207 // browse for the working directory
208 QString newDir
= KFileDialog::getExistingDirectory(wd(), this);
209 if (!newDir
.isEmpty()) {
214 void PgmArgs::browseArgFile()
216 QString caption
= i18n("Select a file name to insert as program argument");
218 // use the selection as default
219 QString f
= programArgs
->markedText();
220 f
= KFileDialog::getSaveFileName(f
, QString::null
,
222 // don't clear the selection if no file was selected
224 programArgs
->insert(f
);
228 void PgmArgs::browseArgDir()
230 QString caption
= i18n("Select a directory to insert as program argument");
232 // use the selection as default
233 QString f
= programArgs
->markedText();
234 f
= KFileDialog::getExistingDirectory(f
, this, caption
);
235 // don't clear the selection if no file was selected
237 programArgs
->insert(f
);
241 void PgmArgs::invokeHelp()
243 kapp
->invokeHTMLHelp("kdbg/argspwdenv.html");
246 #include "pgmargs.moc"