SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kpackage / pkgOptions.cpp
blob12f00e1c3ffb06cc47d0db44d656235446acb871
1 /*
2 ** Copyright (C) 1999,2000 Toivo Pedaste <toivo@ucs.uwa.edu.au>
3 **
4 */
6 /*
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program in a file called COPYING; if not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 ** MA 02110-1301, USA.
24 ** Bug reports and questions can be sent to kde-devel@kde.org
27 // qt headers
28 #include <QtGui/QLabel>
29 //Added by qt3to4:
30 #include <QtGui/QShowEvent>
31 #include <QtCore/QList>
32 #include <QtGui/QBoxLayout>
33 #include <QtGui/QCloseEvent>
34 #include <QtGui/QListWidget>
35 #include <QtGui/QApplication>
37 #include <klocale.h>
38 #include <kglobal.h>
39 #include <kglobalsettings.h>
40 #include <kseparator.h>
41 #include <kdebug.h>
42 #include <kpushbutton.h>
43 #include <KStandardGuiItem>
45 #include "pkgOptions.h"
46 #include "managementWidget.h"
47 #include "kpackage.h"
49 ///////////////////////////////////////////////////////////////////////////
50 ///////////////////////////////////////////////////////////////////////////
52 pkgOptions::pkgOptions(pkgInterface *pki, QWidget *parent, const QString &caption)
53 : QDialog(parent)
55 // setFrameStyle(QFrame::Raised | QFrame::Panel);
57 // kDebug() << "pkgOptions::pkgOptions\n";
58 pkgInt = pki;
60 hide();
62 setCaption(caption);
65 // Destructor
66 pkgOptions::~pkgOptions()
68 // int i;
69 // for (i = 0; i < bnumber; i++) {
70 // delete(Boxes[i]);
71 // }
74 // Set up the sub-widgets
75 void pkgOptions::setupWidgets(QList<param *> &pars)
77 int i;
79 // Create widgets
80 title = new QLabel("", this);
81 QFont f( KGlobalSettings::generalFont());
82 f.setBold(true);
83 f.setPointSize(f.pointSize()+6);
84 title->setFont(f);
85 // title->setAutoResize(true);
86 // title->update();
88 installButton = new QPushButton(insType);
89 cancelButton = new KPushButton(KStandardGuiItem::cancel());
90 // count number of buttons
91 bnumber = pars.count();
93 Boxes = new QCheckBox *[bnumber];
94 i = 0;
95 // for ( p=pars.first(); p != 0; p=pars.next(), i++ ) {
96 foreach (param *p, pars) {
97 Boxes[i] = new QCheckBox(p->name);
98 Boxes[i]->setChecked(p->init);
99 i++;
102 Keep = new QCheckBox(i18n("Keep this window"));
104 // Connections
105 connect(installButton,SIGNAL(clicked()),SLOT(pkginstallButtonClicked()));
106 connect(cancelButton,SIGNAL(clicked()),SLOT(cancelButtonClicked()));
107 connect(Keep, SIGNAL(toggled(bool)), SLOT(keepToggle(bool)));
109 // Do the layout
110 vlayout = new QBoxLayout(this, QBoxLayout::TopToBottom);
111 vlayout->addWidget(title,0);
114 hlayout = new QBoxLayout(vlayout,QBoxLayout::LeftToRight);
117 layout = new QBoxLayout(hlayout,QBoxLayout::TopToBottom);
119 packages = new QListWidget();
120 layout->addWidget(packages,20);
122 QStringList heads;
124 connect(packages, SIGNAL(itemClicked( QListWidgetItem *)),
125 this, SLOT(slotSearch( QListWidgetItem *)));
128 layout->addStretch(1);
129 for (i = 0; i < bnumber; i++) {
130 layout->addWidget(Boxes[i],1);
132 layout->addWidget(new KSeparator(Qt::Horizontal), 2);
134 QBoxLayout *slayout = new QBoxLayout(layout, QBoxLayout::LeftToRight);
135 slayout->addStretch(1);
136 slayout->addWidget(Keep, 1);
137 slayout->addStretch(1);
139 layout->addWidget(new KSeparator(Qt::Horizontal), 2);
141 QBoxLayout *buttons = new QBoxLayout(QBoxLayout::LeftToRight);
142 layout->addLayout(buttons);
144 buttons->addWidget(installButton,2);
145 buttons->addStretch(1);
146 buttons->addWidget(cancelButton,2);
149 term = new kpTerm(kpty);
150 hlayout->addWidget(term, 1000);
153 setLayout(vlayout);
154 resize(800, 400);
157 bool pkgOptions::setup(packageInfo *p) {
158 // QList<packageInfo *> *pl = new QList<packageInfo *>;
159 QList<packageInfo *> pl;
160 pl.append(p);
161 return setup(pl);
164 void pkgOptions::resetPackages(bool init)
166 //kDebug() << "resetPackages()\n";
167 installButton->setEnabled(false);
169 int packCount = packList.count();
171 packListChecked.clear();
172 QStringList checked;
173 QSet<QString> isChecked;
174 for (int i = 0; i < packCount; i++) {
175 QListWidgetItem *w = packages->item(i);
176 if (w->checkState() == Qt::Checked) {
177 kDebug() << "CK=" << w->text() << "\n";
178 checked << w->text();
179 isChecked.insert(w->text());
183 if (checked == checkedPackages && !init)
184 return;
186 QApplication::setOverrideCursor( Qt::WaitCursor );
187 checkedPackages = checked;
189 packListChecked.clear();
190 foreach (packageInfo *p, packList) {
191 // kDebug() << "PC=" << p->fetchFilename() << "\n";
192 if (isChecked.contains(p->fetchFilename())) {
193 packListChecked << p;
197 bool cancel;
198 QStringList rlist;
199 if (checked.count() > 0) {
200 rlist = pkgInt->listInstalls(checked, installer, cancel);
202 // kDebug() << "rlist=" << rlist << "\n";
204 QListWidgetItem *wd;
205 while ((wd = packages->takeItem(packCount))) {
206 // kDebug() << "packages del " << wd->text() << "\n";
207 delete wd;
210 foreach (const QString &ritem, rlist) {
211 if (!isChecked.contains(ritem)) {
212 new QListWidgetItem(ritem, packages);
216 if (packListChecked.count() > 0)
217 installButton->setEnabled(true);
219 QApplication::restoreOverrideCursor();
222 bool pkgOptions::setup(QList<packageInfo *> pl)
224 QString s;
225 modified = false;
227 packList = pl;
229 QStringList plist, rlist, clist;
230 QSet<QString> dict;
231 // kDebug() << "pl=" << pl << "\n";
233 foreach (packageInfo *p, pl) {
234 plist += p->fetchFilename();
235 dict.insert(p->getInfo("name"));
237 // kDebug() << "clist=" << clist << "\n";
239 s = i18ncp("Used when listing how many packages are to be installed, and how many are to be uninstalled. The argument on the left is a translation of Install or Uninstall respectively.", "%2: 1 Package","%2: %1 Packages",plist.count(),insType);
240 title->setText(s);
241 // kDebug() << "plist=" << plist << "\n";
243 packages->clear();
244 int i = 0;
245 foreach (const QString &pit, plist) {
246 QListWidgetItem *pw = new QListWidgetItem(pit, packages);
247 if (i < packList.count()) {
248 pw->setCheckState(Qt::Checked);
250 i++;
253 cancelButton->setGuiItem(KStandardGuiItem::cancel());
254 resetPackages(true);
255 return true;
258 // install button has been clicked....so install the package
259 void pkgOptions::pkginstallButtonClicked()
261 int i;
262 QStringList r;
263 modified = true;
265 // Collect data from check boxes
266 int installFlags = 0;
268 for (i = 0; i < bnumber; i++) {
269 installFlags |= (Boxes[i]->isChecked()) << i;
272 test = false;
273 QString s = doPackages(installFlags, packListChecked, test);
274 // A "0=" or "1=" indicates it was actually (un)installed by the doPackages
275 // routine instead of just returning a command to execute
277 // kDebug() << "S=" << s << "\n";
278 if (s == "0=") {
279 cancelButtonClicked();
280 } else if (s.left(2) == "1=") {
281 term->textIn(s.mid(2), true);
282 } else {
283 connect(term,SIGNAL(result(QStringList &, int)),
284 this,SLOT(slotResult(QStringList &, int)));
286 installButton->setEnabled(false);
288 if (term->run(s, r)) {
289 running = true;
290 cancelButton->setGuiItem(KStandardGuiItem::cancel());
291 } else {
292 reset();
297 void pkgOptions::slotSearch(QListWidgetItem *item)
299 if (item) {
300 QString s = item->text();
301 // kDebug() << "searchI=" << s << "\n";
303 foreach (packageInfo *p, packList) {
304 if (s == p->getInfo("name")) {
305 kpackage->management->doChangePackage(p);
306 break;
309 resetPackages(false);
313 void pkgOptions::reset() {
314 installButton->setEnabled(true);
315 cancelButton->setGuiItem(KGuiItem(i18n("Done"))); //clear icon
316 disconnect(term,SIGNAL(result(QStringList &, int)),
317 this,SLOT(slotResult(QStringList &, int)));
318 running = false;
321 void pkgOptions::slotResult(QStringList &, int ret)
323 reset();
324 if (ret == 0 && !test && !keep) {
325 term->done();
326 accept();
330 void pkgOptions::terminate() {
331 if (running) {
332 term->cancel();
333 reset();
337 void pkgOptions::cancelButtonClicked()
339 terminate();
340 term->done();
342 if (!modified || test)
343 reject();
344 else
345 accept();
348 void pkgOptions::closeEvent ( QCloseEvent * e ) {
349 // kDebug() << "pkgOptions::QCloseEvent\n";
350 terminate();
352 QWidget::closeEvent (e);
355 void pkgOptions::showEvent ( QShowEvent *e ) {
356 // kDebug() << "pkgOptions::showEvent\n";
357 getKeep();
359 modified = false;
360 running = false;
362 QWidget::showEvent(e);
365 void pkgOptions::keepToggle(bool kp)
367 // kDebug() << "KEEP " << kp << "\n";
369 KConfigGroup config = KGlobal::config()->group("Kpackage");
371 config.writeEntry("keepIWin", kp);
373 keep = kp;
376 void pkgOptions::getKeep()
378 KConfigGroup config(KGlobal::config(), "Kpackage");
379 keep = config.readEntry("keepIWin", true);
380 // kDebug() << "getKeeP " << keep << "\n";
381 Keep->setChecked(keep);
385 ///////////////////////////////////////////////////////////////////////////
386 ///////////////////////////////////////////////////////////////////////////
387 pkgOptionsI::pkgOptionsI(pkgInterface *pkg, QWidget *parent):
388 pkgOptions(pkg, parent, i18n("Install"))
390 // kDebug() << "pkgOptionsI::pkgOptionsI\n";
391 insType = i18n("Install");
392 installer = true;
393 setupWidgets(pkg->paramsInst);
396 QString pkgOptionsI::doPackages(int installFlags, QList<packageInfo *> p, bool &test)
398 return pkgInt->install(installFlags, p, test);
401 ///////////////////////////////////////////////////////////////////////////
402 ///////////////////////////////////////////////////////////////////////////
403 pkgOptionsU::pkgOptionsU(pkgInterface *pkg, QWidget *parent):
404 pkgOptions(pkg, parent, i18n("Uninstall"))
406 // kDebug() << "pkgOptionsU::pkgOptionsU\n";
407 insType = i18n("Uninstall");
408 installer = false;
409 setupWidgets(pkg->paramsUninst);
412 QString pkgOptionsU::doPackages(int installFlags, QList<packageInfo *> p, bool &test)
414 return pkgInt->uninstall(installFlags, p, test);
416 #include "pkgOptions.moc"