1 /***************************************************************************
6 * begin : Tue Jan 29 2002
7 * copyright : (C) 2002 by Patrick Charbonnier
8 * : Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss
9 * email : pch@freeshell.org
11 ****************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 ***************************************************************************/
27 #include <kapplication.h>
28 #include <kstandarddirs.h>
30 #include <kiconloader.h>
33 #include <kmessagebox.h>
34 #include <ksimpleconfig.h>
35 #include <kio/netaccess.h>
38 #include "transferlist.h"
42 static int defaultColumnWidth
[] = {
44 160, // LOCAL FILENAME
55 TransferList::TransferList(QWidget
* parent
, const char *name
)
56 : KListView(parent
, name
)
58 // enable selection of more than one item
59 setSelectionMode( QListView::Extended
);
61 // // disable sorting and clicking on headers
64 setAllColumnsShowFocus(true);
66 lv_pixmap
= addColumn(i18n("S"));
67 lv_filename
= addColumn(i18n("Local File Name"));
68 lv_resume
= addColumn(i18n("Resumed"));
69 lv_count
= addColumn(i18n("Count"));
70 lv_progress
= addColumn(i18n("%"));
71 lv_total
= addColumn(i18n("Total"));
72 lv_speed
= addColumn(i18n("Speed"));
73 lv_remaining
= addColumn(i18n("Rem. Time"));
74 lv_url
= addColumn(i18n("Address (URL)"));
79 KConfig
*config
= KGlobal::config();
80 config
->setGroup("ListView");
81 if ( config
->readListEntry("ColumnWidths").isEmpty() )
83 for (int i
= 0; i
< NUM_COLS
; i
++)
84 setColumnWidth(i
, defaultColumnWidth
[i
]);
87 restoreLayout( KGlobal::config(), "ListView" );
89 QString connectPath
= "pics/connect%2.png";
90 QString tryPath
= "pics/try%2.png";
94 if (animConn
.count() == 0) {
95 animConn
.setAutoDelete(true);
96 animTry
.setAutoDelete(true);
97 for (int i
= 0; i
< 8; i
++) {
98 curPix
= new QPixmap();
99 curPix
->load(locate("appdata", connectPath
.arg(i
)));
100 animConn
.append(curPix
);
102 curPix
= new QPixmap();
103 curPix
->load(locate("appdata", tryPath
.arg(i
)));
104 animTry
.append(curPix
);
108 pixQueued
= UserIcon("md_queued");
109 pixScheduled
= UserIcon("md_scheduled");
110 pixDelayed
= UserIcon("md_delayed.png");
111 pixFinished
= UserIcon("md_finished");
112 pixRetrying
= UserIcon("retrying");
114 phasesNum
= animConn
.count();
116 connect(this, SIGNAL(doubleClicked(QListViewItem
*)), SLOT(slotTransferSelected(QListViewItem
*)));
117 connect(this, SIGNAL(rightButtonPressed(QListViewItem
*, const QPoint
&, int)), SLOT(slotPopupMenu(QListViewItem
*)));
121 TransferList::~TransferList()
123 saveLayout( KGlobal::config(), "ListView" );
127 Transfer
*TransferList::addTransfer(const KURL
& _source
, const KURL
& _dest
,
130 Transfer
*last
= static_cast<Transfer
*>( lastItem() );
131 Transfer
*new_item
= new Transfer(this, last
, _source
, _dest
, jobid
);
134 new_item
->maybeShow();
140 void TransferList::slotTransferSelected(QListViewItem
* item
)
142 emit
transferSelected((Transfer
*) item
);
146 void TransferList::slotPopupMenu(QListViewItem
* item
)
150 emit
popupMenu((Transfer
*) item
);
154 void TransferList::setSelected(QListViewItem
* item
, bool selected
)
156 bool tmpb
= selected
;
158 if (tmpb
&& item
->isSelected()) {
162 QListView::setSelected(item
, tmpb
);
166 void TransferList::moveToBegin(Transfer
* item
)
170 Transfer
*oldfirst
=static_cast<Transfer
*>(firstChild());
171 item
->moveItem(oldfirst
); //move item after oldfirst
172 oldfirst
->moveItem(item
); //move oldfirst after item
176 void TransferList::moveToEnd(Transfer
* item
)
180 Transfer
*oldlast
=static_cast<Transfer
*>(lastItem());
181 item
->moveItem(oldlast
);
185 bool TransferList::updateStatus(int counter
)
187 bool isTransfer
= false;
189 TransferIterator
it(this);
191 for (; it
.current(); ++it
) {
192 isTransfer
|= it
.current()->updateStatus(counter
);
199 bool TransferList::areTransfersQueuedOrScheduled()
201 TransferIterator
it(this);
203 if (childCount() > 0) {
204 for (; it
.current(); ++it
) {
205 if ((it
.current()->getMode() == Transfer::MD_QUEUED
)|| \
206 (it
.current()->getMode() == Transfer::MD_SCHEDULED
))
214 Transfer
* TransferList::find(const KURL
& _src
)
216 TransferIterator
it(this);
218 for (; it
.current(); ++it
) {
219 if (it
.current()->getSrc() == _src
) {
228 void TransferList::readTransfers(const KURL
& file
)
232 if (KIO::NetAccess::download(file
, tmpFile
, (QWidget
*)parent())) {
233 KSimpleConfig
config(tmpFile
);
235 config
.setGroup("Common");
236 int num
= config
.readNumEntry("Count", 0);
241 for ( int i
= 0; i
< num
; i
++ )
245 str
.sprintf("Item%d", i
);
246 config
.setGroup(str
);
248 src
= KURL::fromPathOrURL( config
.readPathEntry("Source") );
249 dest
= KURL::fromPathOrURL( config
.readPathEntry("Dest") );
250 item
= addTransfer( src
, dest
, false ); // don't show!
252 if (!item
->read(&config
, i
))
256 // configuration read, now we know the status to determine
257 // whether to show or not
264 void TransferList::writeTransfers(const QString
& file
)
266 sDebug
<< ">>>>Entering with file =" << file
<< endl
;
268 KSimpleConfig
config(file
);
269 int num
= childCount();
271 config
.setGroup("Common");
272 config
.writeEntry("Count", num
);
274 TransferIterator
it(this);
276 for (int id
= 0; it
.current(); ++it
, ++id
)
277 it
.current()->write(&config
, id
);
280 sDebug
<< "<<<<Leaving" << endl
;
283 #include "transferlist.moc"