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
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
|
/*
** Copyright (C) 1999,2000 Toivo Pedaste <toivo@ucs.uwa.edu.au>
**
// Author: Damyan Pepper
// Toivo Pedaste
//
// See kpackage.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 "../config.h"
#include <tqdir.h>
#include <tqlabel.h>
#include <tqframe.h>
#include <kdebug.h>
#include <kapplication.h>
#include <kfiledialog.h>
#include <kprogress.h>
#include <kurl.h>
#include <kapplication.h>
#include <kaccel.h>
#include <kaction.h>
#include <klocale.h>
#include <kinputdialog.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kstdaction.h>
#include <kedittoolbar.h>
#include <kmimemagic.h>
#include <kurldrag.h>
#include "kpackage.h"
#include "managementWidget.h"
#include "pkgOptions.h"
#include "kio.h"
#include "findf.h"
#include "search.h"
#include "options.h"
#include "cache.h"
extern Opts *opts;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
KPKG::KPKG(KConfig *_config)
: KMainWindow(0)
{
kpackage = new KPACKAGE(_config, this);
setCentralWidget(kpackage);
config = kapp->config();
config->setGroup("Kpackage");
kpackage->management->readPSeparator();
// Get a nice default size
resize(760,540);
setupMenu();
disableNext();
disablePrevious();
optiondialog = new Options(this);
prop_restart = false;
setAutoSaveSettings();
}
// Set up the menu
void KPKG::setupMenu()
{
pack_open = KStdAction::open(TQT_TQOBJECT(kpackage), TQT_SLOT(fileOpen()),
actionCollection());
recent = KStdAction::openRecent(TQT_TQOBJECT(this), TQT_SLOT(openRecent(const KURL&)),
actionCollection());
recent->loadEntries( config );
pack_find = new KAction( i18n("Find &Package..."), "find",
KStdAccel::shortcut(KStdAccel::Find), TQT_TQOBJECT(kpackage),
TQT_SLOT(find()), actionCollection(), "pack_find");
pack_findf = new KAction( i18n("Find &File..."), "filefind",
0, TQT_TQOBJECT(kpackage),
TQT_SLOT(findf()), actionCollection(), "pack_findf");
kpack_reload = new KAction( i18n("&Reload"), "reload",
KStdAccel::shortcut(KStdAccel::Reload), TQT_TQOBJECT(kpackage),
TQT_SLOT(reload()), actionCollection(), "kpack_reload");
(void) KStdAction::quit(TQT_TQOBJECT(kpackage), TQT_SLOT(fileQuit()),
actionCollection());
pack_prev = KStdAction::back(TQT_TQOBJECT(kpackage->management->treeList), TQT_SLOT(previous()),
actionCollection(),"pack_prev");
pack_next = KStdAction::forward(TQT_TQOBJECT(kpackage->management->treeList), TQT_SLOT(next()),
actionCollection(),"pack_next");
(void) (new KAction( i18n("&Expand Tree"), "ftout",
0, TQT_TQOBJECT(kpackage),
TQT_SLOT(expandTree()), actionCollection(), "kpack_expand"));
(void) (new KAction( i18n("&Collapse Tree"), "ftin",
0, TQT_TQOBJECT(kpackage),
TQT_SLOT(collapseTree()), actionCollection(), "kpack_collapse"));
(void) (new KAction( i18n("Clear &Marked"), TQString(),
0, TQT_TQOBJECT(kpackage),
TQT_SLOT(clearMarked()), actionCollection(), "kpack_clear"));
(void) (new KAction( i18n("Mark &All"), TQString(),
0, TQT_TQOBJECT(kpackage),
TQT_SLOT(markAll()), actionCollection(), "kpack_markall"));
pack_install = new KAction( i18n("&Install"), TQString(),
0, TQT_TQOBJECT(kpackage->management),
TQT_SLOT(installSingleClicked()), actionCollection(), "install_single");
pack_install->setEnabled(false);
kpackage->management->setInstallAction(pack_install);
pack_uninstall = new KAction( i18n("&Uninstall"), TQString(),
0, TQT_TQOBJECT(kpackage->management),
TQT_SLOT(uninstallSingleClicked()), actionCollection(), "uninstall_single");
pack_uninstall->setEnabled(false);
kpackage->management->setUninstallAction(pack_uninstall);
(void) (new KAction( i18n("&Install Marked"), TQString(),
0, TQT_TQOBJECT(kpackage->management),
TQT_SLOT(installMultClicked()), actionCollection(), "install_marked"));
(void) (new KAction( i18n("&Uninstall Marked"), TQString(),
0, TQT_TQOBJECT(kpackage->management),
TQT_SLOT(uninstallMultClicked()), actionCollection(), "uninstall_marked"));
setStandardToolBarMenuEnabled(true);
KStdAction::configureToolbars( TQT_TQOBJECT(this), TQT_SLOT(configureToolBars()),
actionCollection());
KStdAction::saveOptions( TQT_TQOBJECT(this), TQT_SLOT(saveSettings()), actionCollection());
KStdAction::keyBindings( guiFactory(), TQT_SLOT(configureShortcuts()), actionCollection());
(void) (new KAction( i18n("Configure &KPackage..."), "configure",
0, TQT_TQOBJECT(this),
TQT_SLOT(setOptions()), actionCollection(), "kpack_options"));
(void) (new KAction( i18n("Clear Package &Folder Cache"), TQString(),
0, TQT_TQOBJECT(this),
TQT_SLOT(clearDCache()), actionCollection(), "clear_dcache"));
(void) (new KAction( i18n("Clear &Package Cache"), TQString(),
0, TQT_TQOBJECT(this),
TQT_SLOT(clearPCache()), actionCollection(), "clear_pcache"));
int i;
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
kpinterface[i]->makeMenu(actionCollection());
}
}
// urlList.setAutoDelete(TRUE);
createGUI();
}
void KPKG::disableMenu()
{
pack_open->setEnabled(false);
pack_find->setEnabled(false);
pack_findf->setEnabled(false);
kpack_reload->setEnabled(false);
recent->setEnabled(false);
}
void KPKG::enableMenu()
{
pack_open->setEnabled(true);
pack_find->setEnabled(true);
pack_findf->setEnabled(true);
kpack_reload->setEnabled(true);
recent->setEnabled(true);
}
void KPKG::disableNext() {
pack_next->setEnabled(false);
}
void KPKG::enableNext() {
pack_next->setEnabled(true);
}
void KPKG::disablePrevious() {
pack_prev->setEnabled(false);
}
void KPKG::enablePrevious() {
pack_prev->setEnabled(true);
}
void KPKG::openRecent(const KURL& url){
kpackage->openNetFile( url );
}
void KPKG::add_recent_file(const TQString &newfile){
KURL url = KURL(newfile);
recent->addURL( url );
}
void KPKG::configureToolBars() {
KEditToolbar dlg(actionCollection());
connect(&dlg,TQT_SIGNAL(newToolbarConfig()),this,TQT_SLOT(slotNewToolbarConfig()));
dlg.exec();
}
void KPKG::slotNewToolbarConfig() {
createGUI();
}
void KPKG::writeSettings(){
kpackage->management->writePSeparator();
KConfig *config = kapp->config();
config->setGroup("Kpackage");
recent->saveEntries( config );
kpackage->management->treeList->writeTreeConfig();
kpackage->management->treeList->writeTreeType();
config->sync();
}
void KPKG::setOptions(){
optiondialog->restore();
}
void KPKG::saveSettings(){
writeSettings();
}
void KPKG::clearPCache(){
cacheObj::clearPCache();
}
void KPKG::clearDCache(){
cacheObj::clearDCache();
}
void KPKG::saveProperties(KConfig *config )
{
config->writePathEntry("Name", kpackage->save_url.url());
}
void KPKG::readProperties(KConfig *config)
{
TQString entry = config->readPathEntry("Name"); // no default
if (entry.isNull())
return;
kpackage->openNetFiles(entry);
prop_restart = true;
}
bool KPKG::queryClose() {
kpackage->cleanUp();
return true;
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
KPACKAGE::KPACKAGE(KConfig *_config, TQWidget *parent)
: TQWidget(parent)
{
// Save copy of config
config = _config;
setAcceptDrops(true);
setupModeWidgets();
setupStatusBar();
file_dialog = NULL;
findialog = NULL;
srchdialog = NULL;
}
// Destructor
KPACKAGE::~KPACKAGE()
{
// destroyModeWidgets();
// delete status;
// delete processProgress;
}
// resize event -- arrange the widgets
void KPACKAGE::resizeEvent(TQResizeEvent *re)
{
re = re; // prevent warning
arrangeWidgets();
}
// Set up the mode widgets
void KPACKAGE::setupModeWidgets()
{
management = new managementWidget(this);
for (int i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
kpinterface[i]->uninstallation = new pkgOptionsU(kpinterface[i]);
kpinterface[i]->installation = new pkgOptionsI(kpinterface[i]);
}
}
}
// destroy the mode widgets
void KPACKAGE::destroyModeWidgets()
{
// delete management;
// for (int i = 0; i < kpinterfaceN; i++) {
// if (kpinterface[i]) {
// delete kpinterface[i]->installation;
// delete kpinterface[i]->uninstallation;
// }
// }
}
// Set up the status bar
void KPACKAGE::setupStatusBar()
{
statusbar = new TQFrame(this);
statusbar->setFrameStyle(TQFrame::Raised | TQFrame::Panel);
processProgress = new KProgress(100,statusbar);
processProgress->setTextEnabled(FALSE);
status = new TQLabel(i18n("Management Mode"), statusbar);
}
// Arrange the widgets nicely
void KPACKAGE::arrangeWidgets()
{
int i;
statusbar->resize(width(),20);
statusbar->move(0,height()-20);
status->resize((statusbar->width() / 4) * 3, 16);
status->move(2,2);
processProgress->resize(statusbar->width() / 4 - 4, 16);
processProgress->move((statusbar->width() / 4) * 3 + 3, 2);
management->resize(width(),height() - 20);
for (i = 0; i < kpinterfaceN; i++)
if (kpinterface[i]) {
kpinterface[i]->installation->resize(width(),height() - 20);
}
}
void KPACKAGE::setup()
{
management->collectData(1);
}
void KPACKAGE::fileQuit() // file->quit selected from menu
{
cleanUp();
TDEApplication::exit(0); // exit the application
}
void KPACKAGE::cleanUp() // file->quit selected from menu
{
kpkg->writeSettings();
if (opts->DCache >= Opts::SESSION) {
cacheObj::clearDCache(); // clear dir caches if needed
}
if (opts->PCache >= Opts::SESSION) {
cacheObj::clearPCache(); // clear package caches if needed
}
}
void KPACKAGE::reload()
{
kpackage->management->collectData(TRUE);
}
void KPACKAGE::fileOpen() // file->quit selected from menu
{
KFileDialog *box;
box = getFileDialog(i18n("Select Package"));
if( box->exec())
{
if(!box->selectedURL().isEmpty())
{
openNetFile( box->selectedURL() );
}
}
}
void KPACKAGE::clearMarked()
{
management->treeList->clearMarked(management->treeList->firstChild());
}
void KPACKAGE::markAll()
{
management->treeList->markAll(management->treeList->firstChild());
}
void KPACKAGE::expandTree()
{
management->treeList->expandTree(management->treeList);
}
void KPACKAGE::collapseTree()
{
management->treeList->collapseTree(management->treeList);
}
pkgInterface *KPACKAGE::pkType(const TQString &fname)
{
// Get the package information for this package
char buf[51];
int i;
FILE *file= fopen(TQFile::encodeName(fname),"r");
if (file) {
fgets(buf,sizeof(buf)-1,file);
buf[50] = 0;
// check enabled package handlers
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
if (opts->handlePackage[i] && kpinterface[i]->isType(buf, fname)) {
fclose(file);
return kpinterface[i];
}
}
}
// check unenabled package handlers
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
if (!opts->handlePackage[i] && kpinterface[i]->isType(buf, fname)) {
fclose(file);
return kpinterface[i];
}
}
}
fclose(file);
KpMsgE(i18n("Unknown package type: %1").arg(fname),TRUE);
} else {
KpMsgE(i18n("File not found: %1").arg(fname),TRUE);
}
return 0;
}
/////////////////////////////////////////////////////////////////////////
int KPACKAGE::typeIndex(pkgInterface *type) {
int i;
for (i = 0; i < kpinterfaceN; i++) {
if (type == kpinterface[i]) {
return i;
}
}
return -1;
}
void KPACKAGE::openNetFiles (const TQStringList &urls, bool install )
{
TQStringList files;
int i;
int index;
TQPtrList<packageInfo> **lst = new TQPtrList<packageInfo>*[kpinterfaceN];
packageInfo *pk = 0;
kdDebug() << "openNetFiles\n";
for (TQStringList::ConstIterator it = urls.begin(); it != urls.end(); ++it) {
files.append(fetchNetFile(*it));
kpkg->add_recent_file(*it);
}
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
lst[i] = new TQPtrList<packageInfo>;
}
}
for (TQStringList::Iterator t = files.begin(); t != files.end(); ++t) {
pkgInterface *type = pkType(*t);
index = typeIndex(type);
if (index >= 0) {
pk = type->getPackageInfo('u', *t, 0);
if (pk) {
pk->pkgFileIns(*t);
lst[index]->insert(0,pk);
}
}
}
if (install)
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
if ( lst[i]->count() > 0) {
kpinterface[i]->installation->setup(lst[i],kpinterface[i]->head);
if (kpinterface[i]->installation->exec()) {
for (packageInfo *inf = lst[i]->first(); inf != 0; inf = lst[i]->next()) {
kpackage->management->updatePackage(inf,TRUE);
}
}
}
}
} else {
if (pk) {
KpTreeListItem *pt = pk->item;
// NOT the best place for this CODE
kpackage->management->tabChanged(Opts::ALL);
if (pt)
kpackage->management->packageHighlighted(pt);
}
}
// Dealloc memory
for (i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i]) {
delete lst[i];
}
}
delete [] lst;
}
void KPACKAGE::openNetFile(const KURL &url, bool install )
{
openNetFiles(url.url(), install);
}
// KMimeMagic *magic = KMimeMagic::self();
// KMimeMagicResult *r = magic->findFileType(s);
// printf("r=%s\n",(r->mimeType()).data());
TQString KPACKAGE::getFileName(const KURL & url, TQString &cacheName )
{
TQString none = "";
TQString fname = "";
if ( !url.isValid() ) {
KpMsgE(i18n("Malformed URL: %1").arg(url.url()),TRUE);
} else {
// Just a usual file ?
if ( url.isLocalFile() ) {
cacheName = url.path();
fname = url.path();
} else {
TQString tmpd = cacheObj::PDir();
if (!tmpd.isEmpty()) {
TQString cacheFile = tmpd + url.fileName();
cacheName = cacheFile;
TQFileInfo f(cacheFile);
if (f.exists() && (opts->DCache != Opts::NEVER)) {
fname = cacheFile;
}
}
}
}
return fname;
}
bool KPACKAGE::isFileLocal( const KURL & url )
{
TQString cf;
TQString f = getFileName(url, cf);
if (cf.isEmpty()) {
return false;
} else {
if (!f.isEmpty()) {
return true;
} else {
return false;
}
}
}
TQString KPACKAGE::fetchNetFile( const KURL & url )
{
TQString cf;
TQString f = getFileName(url, cf);
if (cf.isEmpty()) {
return "";
} else {
if (!f.isEmpty()) {
return f;
} else {
save_url = url;
setStatus(i18n("Starting KIO"));
Kio kio;
if (kio.download(url, cf)) {
setStatus(i18n("KIO finished"));
TQFileInfo fi(cf);
if (!(fi.exists() && fi.size() > 0)) {
unlink(TQFile::encodeName(cf));
return "";
} else {
CacheList cl(fi.dirPath());
cl.append(fi.fileName());
cl.write();
return cf;
}
} else {
setStatus(i18n("KIO failed"));
return "";
}
}
}
}
/////////////////////////////////////////////////////////////////////////
void KPACKAGE::fileOpenUrl(){
bool ok;
TQString url = KInputDialog::getText( TQString(),
i18n( "Open location:" ), save_url.prettyURL(), &ok, this );
if ( ok )
{
kpkg->add_recent_file( url );
openNetFile( url );
}
}
void KPACKAGE::find(){
if (srchdialog)
srchdialog->show();
else
srchdialog = new Search(this, "find package");
}
void KPACKAGE::findf(){
if (findialog)
findialog->show();
else
findialog = new FindF(this);
}
KFileDialog* KPACKAGE::getFileDialog(const TQString &captiontext)
{
if(!file_dialog) {
file_dialog = new KFileDialog(TQDir::currentDirPath(), "",
this,"file_dialog",TRUE);
}
TQString pat;
for (int i = 0; i < kpinterfaceN; i++) {
if (kpinterface[i] && opts->handlePackage[i]) {
pat += kpinterface[i]->packagePattern;
pat += " ";
}
}
file_dialog->setFilter(pat);
file_dialog->setCaption(captiontext);
// file_dialog->rereadDir();
return file_dialog;
}
void KPACKAGE::dragEnterEvent(TQDragEnterEvent* e)
{
e->accept(KURLDrag::canDecode(e));
}
void KPACKAGE::dropEvent(TQDropEvent *de) // something has been dropped
{
KURL::List list;
if (!KURLDrag::decode(de, list) || list.isEmpty())
return;
openNetFiles(list.toStringList());
}
void KPACKAGE::setStatus(const TQString &s) // set the text in the status bar
{
status->setText(s);
kapp->processEvents(); // refresh the screen
}
TQString KPACKAGE::getStatus() // get the text in the status bar
{
if(status)
return status->text();
else
return "";
}
void KPACKAGE::setPercent(int x) // set the progress in the status bar
{
processProgress->setValue(x);
kapp->processEvents(); // refresh it
}
//////////////////////////////////////////////////////////////////////////////
#include "kpackage.moc"
|