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.
8 #include <kfiledialog.h>
9 #include <klocale.h> /* i18n */
12 PgmArgs::PgmArgs(QWidget
* parent
, const QString
& pgm
, Q3Dict
<EnvVar
>& envVars
,
13 const QStringList
& allOptions
) :
19 m_envVars
.setAutoDelete(false);
23 QString newText
= labelArgs
->text().arg(fi
.fileName());
24 labelArgs
->setText(newText
);
27 // add options only if the option list is non-empty
28 if (!allOptions
.isEmpty())
30 xsldbgOptions
->addItems(allOptions
);
34 delete xsldbgOptionsPage
;
35 xsldbgOptionsPage
= 0;
45 // initializes the selected options
46 void PgmArgs::setOptions(const QStringList
& selectedOptions
)
48 QStringList::ConstIterator it
;
49 for (it
= selectedOptions
.begin(); it
!= selectedOptions
.end(); ++it
) {
50 for (int i
= 0; i
< xsldbgOptions
->count(); i
++) {
51 if (xsldbgOptions
->item(i
)->text() == *it
) {
52 xsldbgOptions
->item(i
)->setSelected(true);
59 // returns the selected options
60 QStringList
PgmArgs::options() const
63 if (xsldbgOptionsPage
!= 0)
65 for (int i
= 0; i
< xsldbgOptions
->count(); i
++) {
66 if (xsldbgOptions
->item(i
)->isSelected())
67 sel
.append(xsldbgOptions
->item(i
)->text());
74 void PgmArgs::on_buttonModify_clicked()
76 modifyVar(true); // re-add deleted entries
79 void PgmArgs::modifyVar(bool resurrect
)
82 parseEnvInput(name
, value
);
83 if (name
.isEmpty() || name
.find(' ') >= 0) /* disallow spaces in names */
86 // lookup the value in the dictionary
87 EnvVar
* val
= m_envVars
[name
];
89 // see if this is a zombie
90 if (val
->status
== EnvVar::EVdeleted
) {
95 val
->status
= EnvVar::EVdirty
;
96 val
->item
= new QTreeWidgetItem(envList
, QStringList() << name
<< value
);
97 m_envVars
.insert(name
, val
);
99 } else if (value
!= val
->value
) {
102 val
->status
= EnvVar::EVdirty
;
103 val
->item
->setText(1, value
);
109 val
->status
= EnvVar::EVnew
;
110 val
->item
= new QTreeWidgetItem(envList
, QStringList() << name
<< value
);
111 m_envVars
.insert(name
, val
);
113 envList
->setCurrentItem(val
->item
);
114 buttonDelete
->setEnabled(true);
117 // delete the selected item
118 void PgmArgs::on_buttonDelete_clicked()
120 QTreeWidgetItem
* item
= envList
->currentItem();
123 QString name
= item
->text(0);
125 // lookup the value in the dictionary
126 EnvVar
* val
= m_envVars
[name
];
131 // if this is a new item, delete it completely, otherwise zombie-ize it
132 if (val
->status
== EnvVar::EVnew
) {
133 m_envVars
.remove(name
);
136 // mark value deleted
137 val
->status
= EnvVar::EVdeleted
;
141 // there is no selected item anymore
142 buttonDelete
->setEnabled(false);
145 void PgmArgs::parseEnvInput(QString
& name
, QString
& value
)
147 // parse input from edit field
148 QString input
= envVar
->text();
149 int equalSign
= input
.find('=');
150 if (equalSign
>= 0) {
151 name
= input
.left(equalSign
).stripWhiteSpace();
152 value
= input
.mid(equalSign
+1);
154 name
= input
.stripWhiteSpace();
155 value
= QString(); /* value is empty */
159 void PgmArgs::initEnvList()
161 Q3DictIterator
<EnvVar
> it
= m_envVars
;
164 for (; (val
= it
) != 0; ++it
) {
165 val
->status
= EnvVar::EVclean
;
166 name
= it
.currentKey();
167 val
->item
= new QTreeWidgetItem(envList
, QStringList() << name
<< val
->value
);
170 envList
->setAllColumnsShowFocus(true);
171 buttonDelete
->setEnabled(envList
->currentItem() != 0);
174 void PgmArgs::on_envList_currentItemChanged()
176 QTreeWidgetItem
* item
= envList
->currentItem();
177 buttonDelete
->setEnabled(item
!= 0);
181 // must get name from list box
182 QString name
= item
->text(0);
183 EnvVar
* val
= m_envVars
[name
];
186 envVar
->setText(name
+ "=" + val
->value
);
188 envVar
->setText(name
);
192 void PgmArgs::accept()
194 // simulate that the Modify button was pressed, but don't revive
195 // dead entries even if the user changed the edit box
200 void PgmArgs::on_wdBrowse_clicked()
202 // browse for the working directory
203 QString newDir
= KFileDialog::getExistingDirectory(wd(), this);
204 if (!newDir
.isEmpty()) {
209 void PgmArgs::on_insertFile_clicked()
211 QString caption
= i18n("Select a file name to insert as program argument");
213 // use the selection as default
214 QString f
= programArgs
->markedText();
215 f
= KFileDialog::getSaveFileName(f
, QString::null
,
217 // don't clear the selection if no file was selected
219 programArgs
->insert(f
);
223 void PgmArgs::on_insertDir_clicked()
225 QString caption
= i18n("Select a directory to insert as program argument");
227 // use the selection as default
228 QString f
= programArgs
->markedText();
229 f
= KFileDialog::getExistingDirectory(f
, this, caption
);
230 // don't clear the selection if no file was selected
232 programArgs
->insert(f
);
236 #include "pgmargs.moc"