1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
/*
** Copyright (C) 1999,2000 Toivo Pedaste <toivo@ucs.uwa.edu.au>
**
// Author: Damyan Pepper
// Author: Toivo Pedaste
//
// See managementWidget.h for more information
*/
/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/
/*
** Bug reports and questions can be sent to kde-devel@kde.org
*/
#include <tqsplitter.h>
#include <tqtoolbutton.h>
#include <klocale.h>
#include <kdebug.h>
#include <klistviewsearchline.h>
#include <kaction.h>
#include <kstdaction.h>
#include <ktoolbar.h>
#include <kiconloader.h>
// kpackage.headers
#include "kpackage.h"
#include "kplview.h"
#include "managementWidget.h"
#include "pkgInterface.h"
#include "pkgOptions.h"
#include "packageDisplay.h"
#include "packageProperties.h"
#include "options.h"
extern Opts *opts;
KpListViewSearchLine::KpListViewSearchLine(TQWidget *parent, KpTreeList *listView)
:KListViewSearchLine(parent, listView)
{
list = listView;
}
KpListViewSearchLine::~KpListViewSearchLine()
{
}
void KpListViewSearchLine::updateSearch(const TQString &s)
{
list->expand();
KListViewSearchLine::updateSearch(s);
KListViewSearchLine::updateSearch(s); // Yes both are needed
list->sweep(false);
}
// constructor -- initialise variables
managementWidget::managementWidget(TQWidget *parent)
: TQFrame(parent)
{
install_action = 0;
uninstall_action = 0;
allPackages = new TQPtrList<packageInfo>;
tType[0] = i18n("Installed");
tType[1] = i18n("Updated");
tType[2] = i18n("New");
tType[3] = i18n("All");
dirInstPackages = new TQDict<packageInfo>(7717);
dirUninstPackages = new TQDict<packageInfo>(7717);
dirInfoPackages = new TQDict<packageInfo>(7717);
setupWidgets();
connect(treeList,TQT_SIGNAL(updateMarked()),
this, TQT_SLOT( checkMarked()));
}
managementWidget::~managementWidget()
{
// if(allPackages)
// delete allPackages;
// delete dirInstPackages;
// delete dirUninstPackages;
}
void managementWidget::resizeEvent(TQResizeEvent *)
{
arrangeWidgets();
}
void managementWidget::setupWidgets()
{
TQTab t;
top = new TQBoxLayout(this,TQBoxLayout::TopToBottom);
vPan = new TQSplitter(Qt::Horizontal, this);
top->addWidget(vPan);
// the left panel
leftpanel = new TQFrame(vPan);
leftbox = new TQBoxLayout(leftpanel,TQBoxLayout::TopToBottom);
TQTabBar *ltab = new TQTabBar(leftpanel);
treeList = new KpTreeList(leftpanel);
for (int i = 0; i < 4; i++) {
TQTab *t = new TQTab();
t->setText( tType[i] );
ltab->addTab(t);
}
// Quick Search Bar
searchToolBar = new KToolBar( leftpanel, "search toolbar");
TQToolButton *clearSearch = new TQToolButton(searchToolBar);
clearSearch->setTextLabel(i18n("Clear Search"), true);
clearSearch->setIconSet(SmallIconSet(TQApplication::reverseLayout() ? "clear_left"
: "locationbar_erase"));
(void) new TQLabel(i18n("Search: "),searchToolBar);
searchLine = new KpListViewSearchLine(searchToolBar, treeList);
// searchLine->setKeepParentsVisible(false);
connect( clearSearch, TQT_SIGNAL( pressed() ), searchLine, TQT_SLOT( clear() ));
TQValueList<int> clist; clist.append(0); clist.append(2);
searchLine->setSearchColumns(clist);
searchToolBar->setStretchableWidget( searchLine );
connect( treeList, TQT_SIGNAL( cleared() ), searchLine, TQT_SLOT( clear() ));
connect(ltab,TQT_SIGNAL(selected (int)),TQT_SLOT(tabChanged(int)));
ltab->setCurrentTab(treeList->treeType);
leftbox->addWidget(ltab,10);
leftbox->addWidget(searchToolBar,10);
leftbox->addWidget(treeList,10);
leftbox->addStretch();
lbuttons = new TQBoxLayout(TQBoxLayout::LeftToRight);
luinstButton = new TQPushButton(i18n("Uninstall Marked"),leftpanel);
luinstButton->setEnabled(FALSE);
connect(luinstButton,TQT_SIGNAL(clicked()),
TQT_SLOT(uninstallMultClicked()));
linstButton = new TQPushButton(i18n("Install Marked"),leftpanel);
linstButton->setEnabled(FALSE);
connect(linstButton,TQT_SIGNAL(clicked()),
TQT_SLOT(installMultClicked()));
leftbox->addLayout(lbuttons,0); // top level layout as child
// Setup the `buttons' layout
lbuttons->addWidget(linstButton,1,AlignBottom);
lbuttons->addWidget(luinstButton,1,AlignBottom);
lbuttons->addStretch(1);
connect(treeList, TQT_SIGNAL(selectionChanged(TQListViewItem *)),
TQT_SLOT(packageHighlighted(TQListViewItem *)));
// the right panel
rightpanel = new TQFrame(vPan);
rightbox = new TQBoxLayout(rightpanel,TQBoxLayout::TopToBottom);
packageDisplay = new packageDisplayWidget(rightpanel);
// connect(this, TQT_SIGNAL(changePackage(packageInfo *)),
// packageDisplay, TQT_SLOT(changePackage(packageInfo *)));
rbuttons = new TQBoxLayout(TQBoxLayout::LeftToRight);
uinstButton = new TQPushButton(i18n("Uninstall"),rightpanel);
uinstButton->setEnabled(FALSE);
connect(uinstButton,TQT_SIGNAL(clicked()),
TQT_SLOT(uninstallSingleClicked()));
instButton = new TQPushButton(i18n("Install"),rightpanel);
instButton->setEnabled(FALSE);
connect(instButton,TQT_SIGNAL(clicked()),
TQT_SLOT(installSingleClicked()));
// Setup the `right panel' layout
rightbox->addWidget(packageDisplay,10);
rightbox->addLayout(rbuttons,0); // top level layout as child
// Setup the `buttons' layout
rbuttons->addWidget(instButton,1);
rbuttons->addWidget(uinstButton,1);
rbuttons->addStretch(1);
}
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
void managementWidget::writePSeparator()
{
TDEConfig *config = kapp->config();
config->setGroup("Kpackage");
config->writeEntry("panel1Width",vPan->sizes().first());
config->writeEntry("panel2Width",vPan->sizes().last());
}
void managementWidget::readPSeparator()
{
TDEConfig *config = kapp->config();
config->setGroup("Kpackage");
int w1 = config->readNumEntry("panel1Width",200);
int w2 = config->readNumEntry("panel2Width",200);
TQValueList<int> size;
size << w1 << w2;
vPan->setSizes(size);
}
///////////////////////////////////////////////////////////////////
void managementWidget::setupMultButton(int &cntInstall, int &cntUnInstall)
{
if (cntInstall)
linstButton->setEnabled(true);
else
linstButton->setEnabled(false);
if (cntUnInstall)
luinstButton->setEnabled(true);
else
luinstButton->setEnabled(false);
}
void managementWidget::setupInstButton()
{
bool u,i;
packageInfo *package = packageDisplay->package;
if (!package) {
i = false;
u = false;
} else {
if (package->isFetchable() ) {
instButton->setText(i18n("Install"));
} else {
instButton->setText(i18n("Fetch"));
}
if (package->isInstallable() ) {
i = true;
u = false;
} else {
i = false;
u = true;
}
}
instButton->setEnabled(i);
if (install_action)
install_action->setEnabled(i);
uinstButton->setEnabled(u);
if (uninstall_action)
uninstall_action->setEnabled(u);
}
void managementWidget::arrangeWidgets()
{
// this is done automatically by the layout managers
}
void managementWidget::tabChanged(int tab)
{
treeList->treeType = tab;
searchLine->updateSearch();
}
// Collect data from package.
void managementWidget::collectData(bool refresh)
{
int i;
if (!refresh && allPackages) {
treeList->sweep(true);
return; // if refresh not required already initialised
}
TQApplication::setOverrideCursor( waitCursor );
// stop clear() sending selectionChanged signal
disconnect(treeList, TQT_SIGNAL(selectionChanged(TQListViewItem *)),
this, TQT_SLOT(packageHighlighted(TQListViewItem *)));
treeList->hide(); // hide list tree
treeList->clear(); // empty it
connect(treeList, TQT_SIGNAL(selectionChanged(TQListViewItem *)),
TQT_SLOT(packageHighlighted(TQListViewItem *)));
packageDisplay->changePackage(0);
// Delete old list if necessary
if(allPackages) {
delete allPackages;
}
allPackages = new TQPtrList<packageInfo>;
allPackages->setAutoDelete(TRUE);
dirInstPackages->clear();
dirUninstPackages->clear();
// List installed packages
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i] && kpinterface[i]->hasProgram && opts->handlePackage[i]) {
if (hostName.isEmpty() || (kpinterface[i]->hasRemote)) {
kpinterface[i]->listPackages(allPackages);
}
}
}
// Rebuild the list tree
rebuildListTree();
TQApplication::restoreOverrideCursor();
}
// Rebuild the list tree
void managementWidget::rebuildListTree()
{
packageInfo *i;
int n = 0;
kpackage->setStatus(i18n("Building package tree"));
kpackage->setPercent(0);
treeList->setSorting(-1);
// place all the packages found
int count = allPackages->count();
int incr = count/50;
if (incr == 0)
incr = 1;
for(i=allPackages->first(); i!=0; i=allPackages->next())
{
i->place(treeList,TRUE);
if (!(n % incr)) {
kpackage->setPercent(int (n*100/count));
}
n++;
}
treeList->sweep(true);
treeList->show(); // show the list tree
treeList->setSorting(0);
kpackage->setPercent(100); // set the progress
kpackage->setStatus("");
checkMarked();
}
// A package has been highlighted in the list tree
void managementWidget::packageHighlighted(TQListViewItem *item)
{
treeList->packageHighlighted(item, packageDisplay);
setupInstButton();
kpackage->setPercent(100);
}
/////////////////////////////////////////////////////////////////////////
// install has been clicked
void managementWidget::installSingleClicked()
{
int result;
TQPtrList<packageInfo> plist;
packageInfo *package = packageDisplay->package;
if (package) {
TQString filename = package->getFilename();
kdDebug() << "File=" << filename <<"\n";
pkgInterface *interface = package->interface;
if (interface->noFetch || !filename.isEmpty()) {
plist.append(package);
if (!interface->installation->setup(&plist, interface->head)) {
return;
}
result = interface->installation->exec();
if (interface->installation->result() == TQDialog::Accepted ||
interface->installation->modified) {
// it was accepted, so the package has been installed
packageInfo *inf;
for (inf = plist.first(); inf != 0; inf = plist.next()) {
updatePackage(inf,TRUE);
}
if (treeList->currentItem()) {
KpTreeListItem *p = treeList->currentItem();
packageDisplay->changePackage(p->info);
} else {
packageDisplay->changePackage(0); // change package to no package
}
setupInstButton();
}
// kdDebug() << "Result=" << result <<"\n";
} else {
TQString url = package->getUrl();
if (!url.isEmpty()) {
TQString s = kpackage->fetchNetFile(url);
if (!s.isEmpty()) {
packageDisplay->changePackage(package);
setupInstButton();
}
} else {
KpMsgE(i18n("Filename not available\n"),TRUE);
}
}
}
kpackage->setPercent(100);
searchLine->updateSearch();
checkMarked();
}
// install has been clicked
void managementWidget::installMultClicked()
{
int i;
KpTreeListItem *it;
packageInfo *inf;
TQPtrList<packageInfo> **lst = new TQPtrList<packageInfo>*[kpinterfaceN];
selList.clear();
treeList->findMarked(treeList->firstChild(), selList);
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
lst[i] = new TQPtrList<packageInfo>;
for (it = selList.first(); it != 0; it = selList.next()) {
if (it->info->interface == kpinterface[i] &&
it->childCount() == 0 &&
(it->info->packageState == packageInfo::UPDATED ||
it->info->packageState == packageInfo::NEW)
) {
lst[i]->insert(0,it->info);
}
}
}
}
selList.clear();
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
if (lst[i]->count() > 0) {
if (kpinterface[i]->installation->setup(lst[i],kpinterface[i]->head)) {
if (kpinterface[i]->installation->exec() ||
kpinterface[i]->installation->modified) {
for (inf = lst[i]->first(); inf != 0; inf = lst[i]->next()) {
updatePackage(inf,TRUE);
}
}
}
delete lst[i];
}
}
}
delete [] lst;
searchLine->updateSearch();
checkMarked();
}
/////////////////////////////////////////////////////////////////////////////
// Uninstall has been clicked
void managementWidget::uninstallSingleClicked()
{
int result;
TQPtrList<packageInfo> plist;
packageInfo *package = packageDisplay->package;
if (package) { // check that there is a package to uninstall
pkgInterface *interface = package->interface;
plist.append(package);
if (!interface->uninstallation->setup(&plist, interface->head)) {
return;
}
result = interface->uninstallation->exec();
if(result == TQDialog::Accepted ||
interface->installation->modified) {
packageInfo *inf;
for (inf = plist.first(); inf != 0; inf = plist.next()) {
updatePackage(inf,FALSE);
}
if (treeList->currentItem()) {
KpTreeListItem *p = treeList->currentItem();
packageDisplay->changePackage(p->info);
} else {
packageDisplay->changePackage(0); // change package to no package
}
setupInstButton();
}
// kdDebug() << "Result=" << result <<"\n";
}
kpackage->setPercent(100);
searchLine->updateSearch();
checkMarked();
}
void managementWidget::uninstallMultClicked()
{
int i;
KpTreeListItem *it;
packageInfo *inf;
TQPtrList<packageInfo> **lst = new TQPtrList<packageInfo>*[kpinterfaceN];
selList.clear();
treeList->findMarked(treeList->firstChild(), selList);
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
lst[i] = new TQPtrList<packageInfo>;
for (it = selList.first(); it != 0; it = selList.next()) {
if (it->info->interface == kpinterface[i] &&
it->childCount() == 0 &&
(it->info->packageState == packageInfo::INSTALLED ||
it->info->packageState == packageInfo::BAD_INSTALL)
) {
lst[i]->insert(0,it->info);
}
}
}
}
selList.clear();
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
if (lst[i]->count() > 0) {
if (kpinterface[i]->uninstallation->setup(lst[i],kpinterface[i]->head)) {
if (kpinterface[i]->uninstallation->exec()||
kpinterface[i]->installation->modified ) {
for (inf = lst[i]->first(); inf != 0; inf = lst[i]->next()) {
updatePackage(inf,FALSE);
}
}
}
delete lst[i];
}
}
}
delete [] lst;
searchLine->updateSearch();
checkMarked();
}
///////////////////////////////////////////////////////////////////////////
void managementWidget::doChangePackage(packageInfo *p)
{
packageDisplay->changePackage(p);
}
///////////////////////////////////////////////////////////////////////////
KpTreeListItem *managementWidget::search(TQString str, bool subStr, bool wrap,
bool start)
{
return treeList->search(str, subStr, wrap, start);
}
///////////////////////////////////////////////////////////////////////////
KpTreeListItem *managementWidget::updatePackage(packageInfo *pki, bool install)
{
TQString version;
KpTreeListItem *q;
if (allPackages) {
TQString name(pki->getProperty("name"));
if (pki->hasProperty("version"))
version = pki->getProperty("version");
else
version = "";
pkgInterface *interface = pki->interface;
packageInfo *pnew = interface->getPackageInfo('i', name, version);
packageInfo *ptree;
TQString pkgId = name + interface->typeID;
if (install) {
if (pnew) {
if (pnew->packageState != packageInfo::BAD_INSTALL) {
ptree = dirInstPackages->find(pkgId); // remove installed entry
dirInstPackages->remove(pkgId);
if (ptree) {
if (ptree->getItem()) {
delete ptree->getItem();
ptree->item = 0;
}
}
ptree = dirUninstPackages->find(pkgId); // remove uninstalled entry
if (ptree) {
ptree->packageState = packageInfo::HIDDEN;
if (ptree->getItem()) {
delete ptree->getItem();
ptree->item = 0;
}
}
}
dirInstPackages->insert(pkgId,pnew);
q = pnew->place(treeList,TRUE);
allPackages->insert(0,pnew);
if (!q) {
printf("NOTP=%s \n",pnew->getProperty("name").ascii());
} else {
return q;
}
}
} else { // uninstalling
if (!pnew) {
dirInstPackages->remove(pkgId);
KpTreeListItem *qt = pki->getItem();
if (qt) {
treeList->stackRemove(qt);
treeList->setSelected(qt,false);
if (treeList->markPkg == qt)
treeList->markPkg = 0;
delete qt;
} else {
kdDebug() << "DEL=" << name << endl;
}
packageInfo *pb = dirUninstPackages->find(pkgId);
if (pb) { // available package matching the one just uninstalled
pb->packageState = packageInfo::NEW;
q = pb->place(treeList,TRUE);
if (!q) {
printf("NOTP=%s \n",pb->getProperty("name").ascii());
} else {
return q;
}
}
} else {
delete pnew;
}
}
}
return 0;
}
///////////////////////////////////////////////////////////////////////////
void managementWidget::checkMarked()
{
int cntInstall = 0;
int cntUnInstall = 0;
treeList->countMarked(treeList->firstChild(), cntInstall, cntUnInstall);
setupMultButton(cntInstall, cntUnInstall);
}
#include "managementWidget.moc"
|