2 ** Copyright (C) 1999,2000 Toivo Pedaste <toivo@ucs.uwa.edu.au>
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
28 #include <QtGui/QLabel>
30 #include <QtGui/QShowEvent>
31 #include <QtCore/QList>
32 #include <QtGui/QBoxLayout>
33 #include <QtGui/QCloseEvent>
34 #include <QtGui/QListWidget>
35 #include <QtGui/QApplication>
39 #include <kglobalsettings.h>
40 #include <kseparator.h>
42 #include <kpushbutton.h>
43 #include <KStandardGuiItem>
45 #include "pkgOptions.h"
46 #include "managementWidget.h"
49 ///////////////////////////////////////////////////////////////////////////
50 ///////////////////////////////////////////////////////////////////////////
52 pkgOptions::pkgOptions(pkgInterface
*pki
, QWidget
*parent
, const QString
&caption
)
55 // setFrameStyle(QFrame::Raised | QFrame::Panel);
57 // kDebug() << "pkgOptions::pkgOptions\n";
66 pkgOptions::~pkgOptions()
69 // for (i = 0; i < bnumber; i++) {
74 // Set up the sub-widgets
75 void pkgOptions::setupWidgets(QList
<param
*> &pars
)
80 title
= new QLabel("", this);
81 QFont
f( KGlobalSettings::generalFont());
83 f
.setPointSize(f
.pointSize()+6);
85 // title->setAutoResize(true);
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
];
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
);
102 Keep
= new QCheckBox(i18n("Keep this window"));
105 connect(installButton
,SIGNAL(clicked()),SLOT(pkginstallButtonClicked()));
106 connect(cancelButton
,SIGNAL(clicked()),SLOT(cancelButtonClicked()));
107 connect(Keep
, SIGNAL(toggled(bool)), SLOT(keepToggle(bool)));
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);
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);
157 bool pkgOptions::setup(packageInfo
*p
) {
158 // QList<packageInfo *> *pl = new QList<packageInfo *>;
159 QList
<packageInfo
*> pl
;
164 void pkgOptions::resetPackages(bool init
)
166 //kDebug() << "resetPackages()\n";
167 installButton
->setEnabled(false);
169 int packCount
= packList
.count();
171 packListChecked
.clear();
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
)
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
;
199 if (checked
.count() > 0) {
200 rlist
= pkgInt
->listInstalls(checked
, installer
, cancel
);
202 // kDebug() << "rlist=" << rlist << "\n";
205 while ((wd
= packages
->takeItem(packCount
))) {
206 // kDebug() << "packages del " << wd->text() << "\n";
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
)
229 QStringList plist
, rlist
, clist
;
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
= i18np("%2: 1 Package","%2: %1 Packages",plist
.count(),insType
);
241 // kDebug() << "plist=" << plist << "\n";
245 foreach (const QString
&pit
, plist
) {
246 QListWidgetItem
*pw
= new QListWidgetItem(pit
, packages
);
247 if (i
< packList
.count()) {
248 pw
->setCheckState(Qt::Checked
);
253 cancelButton
->setGuiItem(KStandardGuiItem::cancel());
258 // install button has been clicked....so install the package
259 void pkgOptions::pkginstallButtonClicked()
265 // Collect data from check boxes
266 int installFlags
= 0;
268 for (i
= 0; i
< bnumber
; i
++) {
269 installFlags
|= (Boxes
[i
]->isChecked()) << i
;
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";
279 cancelButtonClicked();
280 } else if (s
.left(2) == "1=") {
281 term
->textIn(s
.mid(2), true);
283 connect(term
,SIGNAL(result(QStringList
&, int)),
284 this,SLOT(slotResult(QStringList
&, int)));
286 installButton
->setEnabled(false);
288 if (term
->run(s
, r
)) {
290 cancelButton
->setGuiItem(KStandardGuiItem::cancel());
297 void pkgOptions::slotSearch(QListWidgetItem
*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
);
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)));
321 void pkgOptions::slotResult(QStringList
&, int ret
)
324 if (ret
== 0 && !test
&& !keep
) {
330 void pkgOptions::terminate() {
337 void pkgOptions::cancelButtonClicked()
342 if (!modified
|| test
)
348 void pkgOptions::closeEvent ( QCloseEvent
* e
) {
349 // kDebug() << "pkgOptions::QCloseEvent\n";
352 QWidget::closeEvent (e
);
355 void pkgOptions::showEvent ( QShowEvent
*e
) {
356 // kDebug() << "pkgOptions::showEvent\n";
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
);
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");
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");
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"