Now the systrayicon change it's color when a download is in progress. I simply change...
[kdenetwork.git] / kget / dlgIndividual.cpp
blobb5bea3b072f840a45b82c1c8a6d9d5e9ed185395
1 /***************************************************************************
2 * dlgIndividual.cpp
3 * -------------------
5 * Revision : $Id$
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 ***************************************************************************/
28 #include <qlayout.h>
30 #include "dockindividual.h"
32 #include <qlabel.h>
33 #include <qtabwidget.h>
34 #include <kprogress.h>
35 #include <qtextedit.h>
36 #include <qcheckbox.h>
37 #include <kpushbutton.h>
38 #include <ksqueezedtextlabel.h>
39 #include <kdatetimewidget.h>
41 #include <kapplication.h>
42 #include <kaction.h>
43 #include <klocale.h>
44 #include <ktoolbar.h>
45 #include <krun.h>
46 #include "common.h"
48 #include "transfer.h"
50 #include "settings.h"
51 #include "dlgIndividual.h"
54 DlgIndividual::DlgIndividual(Transfer * _item)
55 : QWidget(0, "dialog", WDestructiveClose)
57 item = _item;
59 //create dock
60 m_pDockIndividual =new DockIndividual(this);
63 // Actions
65 m_paDock = new KToggleAction(i18n("&Dock"),"tool_dock.png", 0, this, SLOT(slotToggleDock()), this, "dockIndividual");
68 QVBoxLayout *topLayout = new QVBoxLayout( this, KDialog::marginHint(),KDialog::spacingHint() );
69 topLayout->addStrut( 360 ); // makes dlg at least that wide
71 QGridLayout *grid = new QGridLayout( 2, 3 );
72 topLayout->addLayout(grid);
73 grid->addColSpacing(1, KDialog::spacingHint());
75 grid->addWidget(new QLabel(i18n("Source:"), this), 0, 0);
77 sourceLabel = new KSqueezedTextLabel(this);
78 grid->addWidget(sourceLabel, 0, 2);
79 sourceLabel->setText(i18n("Source Label"));
80 grid->addWidget(new QLabel(i18n("Destination:"), this), 1, 0);
82 destLabel = new KSqueezedTextLabel(this);
83 grid->addWidget(destLabel, 1, 2);
84 destLabel->setText(i18n("Source Label"));
86 m_pProgressBar = new KProgress(this);
87 topLayout->addWidget( m_pProgressBar );
89 // processed info
90 QHBoxLayout *hBox = new QHBoxLayout();
91 topLayout->addLayout(hBox);
93 sizeLabel = new QLabel(this);
94 hBox->addWidget(sizeLabel);
95 resumeLabel = new QLabel(this);
96 hBox->addWidget(resumeLabel);
98 speedLabel = new QLabel(this);
99 speedLabel->setText(i18n("0 B/s"));
100 topLayout->addWidget(speedLabel);
102 // setup toolbar
103 KToolBar *toolBar = new KToolBar(this);
104 toolBar->setIconText(KToolBar::IconOnly);
105 toolBar->setBarPos(KToolBar::Bottom);
106 toolBar->setMovingEnabled(false);
107 toolBar->setFlat(true);
109 topLayout->addWidget( toolBar );
111 // insert toolbar actions
112 item->m_paResume->plug(toolBar);
113 item->m_paPause->plug(toolBar);
114 item->m_paDelete->plug(toolBar);
116 toolBar->insertLineSeparator();
118 item->m_paQueue->plug(toolBar);
119 item->m_paTimer->plug(toolBar);
120 item->m_paDelay->plug(toolBar);
122 toolBar->insertLineSeparator();
123 m_paDock->plug(toolBar);
127 QCheckBox * keepOpen = new QCheckBox( i18n("&Keep this window open after the operation is complete."), this);
128 connect( keepOpen, SIGNAL( toggled(bool) ), SLOT( slotKeepOpenToggled(bool) ) );
129 topLayout->addWidget(keepOpen);
131 QFrame *line3 = new QFrame( this );
132 line3->setFrameShape( QFrame::HLine );
133 line3->setFrameShadow( QFrame::Sunken );
134 topLayout->addWidget( line3 );
136 hBox = new QHBoxLayout();
137 topLayout->addLayout(hBox);
139 openFile = new KPushButton( i18n("Open &File"), this );
140 connect( openFile, SIGNAL( clicked() ), SLOT( slotOpenFile() ) );
141 hBox->addWidget( openFile );
142 openFile->setEnabled(false);
144 openLocation = new KPushButton( i18n("Open &Destination"), this );
145 connect( openLocation, SIGNAL( clicked() ), SLOT( slotOpenLocation() ) );
146 hBox->addWidget( openLocation );
148 hBox->addStretch(1);
150 pbAdvanced = new KPushButton( i18n("Advanced"), this );
152 connect(pbAdvanced, SIGNAL(clicked()), SLOT(slotToggleAdvanced()));
154 hBox->addWidget( pbAdvanced );
157 // setup tab dialog
158 panelAdvanced = new QTabWidget(this);
160 // if the time was already set somewhere in the future, keep it
161 // otherwise set it to the current time
162 QDateTime dt;
164 if (item->getStartTime() < QDateTime::currentDateTime() && item->getMode() != Transfer::MD_SCHEDULED)
166 dt = QDateTime::currentDateTime();
168 else
170 dt = item->getStartTime();
173 spins = new KDateTimeWidget(dt, this, "spins");
175 panelAdvanced->addTab(spins, i18n("Timer"));
176 panelAdvanced->hide();
178 connect(spins, SIGNAL(valueChanged(const QDateTime &)), item, SLOT(slotStartTime(const QDateTime &)));
180 // adding item log
181 ml_log = new QTextEdit(panelAdvanced);
182 ml_log->setTextFormat(LogText);
183 ml_log->setReadOnly(true);
184 // ml_log->setFixedSize(sizeHint());
185 ml_log->setVScrollBarMode(QScrollView::Auto);
186 ml_log->setWordWrap(QTextEdit::NoWrap);
188 // ml_log->setSizePolicy(policy);
190 panelAdvanced->addTab(ml_log, i18n("Log"));
191 // panelAdvanced->setFixedSize(sizeHint());
195 topLayout->addWidget(panelAdvanced);
196 advanced = ksettings.b_advancedIndividual;
197 slotToggleAdvanced();
199 resize( minimumSizeHint() );
201 //bool keepOpenChecked = false;
202 //bool noCaptionYet = true;
203 setCaption(i18n("Progress Dialog"));
205 bKeepDlgOpen=false;
209 void DlgIndividual::setTotalSize(unsigned long bytes)
211 m_iTotalSize = bytes;
215 void DlgIndividual::setPercent(unsigned long percent)
217 m_pProgressBar->setValue(percent);
218 m_pDockIndividual->setValue(percent);
219 setCaption(i18n("%1% of %2 - %3").arg(percent).arg(KIO::convertSize(m_iTotalSize)).arg(m_location.fileName()));
223 void DlgIndividual::setProcessedSize(unsigned long bytes)
225 sizeLabel->setText(i18n("%1 of %2").arg(KIO::convertSize(bytes)).arg(KIO::convertSize(m_iTotalSize)));
229 void DlgIndividual::setSpeed(QString speed)
231 speedLabel->setText(speed);
232 m_pDockIndividual->setTip(speed);
236 void DlgIndividual::setCopying(const KURL & from, const KURL & to)
238 m_location=to;
239 setCaption(m_location.fileName());
241 sourceLabel->setText(from.prettyURL());
242 destLabel->setText(to.prettyURL());
246 void DlgIndividual::setCanResume(bool resume)
248 if (resume)
249 resumeLabel->setText(i18n("Resumed"));
250 else
251 resumeLabel->setText(i18n("Not resumed"));
254 //void DlgIndividual::slotToggleAdvanced(bool advanced)
255 void DlgIndividual::slotToggleAdvanced()
257 #ifdef _DEBUG
258 sDebugIn<<endl;
259 #endif
261 if (advanced)
262 panelAdvanced->show();
263 else
265 panelAdvanced->hide();
266 adjustSize();
268 advanced = !advanced;
270 #ifdef _DEBUG
271 sDebugOut<<endl;
272 #endif
275 void DlgIndividual::slotToggleDock()
277 #ifdef _DEBUG
278 sDebugIn<<endl;
279 #endif
281 if (m_paDock->isChecked())
283 m_pDockIndividual->show();
284 hide();
286 else
287 m_pDockIndividual->hide();
289 #ifdef _DEBUG
290 sDebugOut<<endl;
291 #endif
295 /** Sets the whole log */
296 void DlgIndividual::setLog(const QString & _msg)
298 ml_log->setText(_msg);
301 void DlgIndividual::appendLog(const QString & _msg)
303 ml_log->append(_msg);
307 void DlgIndividual::slotKeepOpenToggled(bool bToggled)
309 #ifdef _DEBUG
310 sDebugIn <<"bToggled= "<<bToggled<<endl;
311 #endif
314 bKeepDlgOpen=bToggled;
316 if (!bKeepDlgOpen && item->getStatus()==Transfer::ST_FINISHED)
318 hide();
319 m_pDockIndividual->hide();
322 #ifdef _DEBUG
323 sDebugOut<<endl;
324 #endif
328 void DlgIndividual::slotOpenLocation()
330 #ifdef _DEBUG
331 sDebugIn<<endl;
332 #endif
334 KURL location=m_location;
335 location.setFileName("");
336 kapp->invokeBrowser( location.url() );
338 #ifdef _DEBUG
339 sDebugOut<<endl;
340 #endif
343 void DlgIndividual::slotOpenFile()
345 #ifdef _DEBUG
346 sDebugIn "Starting kfmclient with url "<<m_location.prettyURL()<<endl;
347 #endif
349 (void) new KRun( m_location );
351 #ifdef _DEBUG
352 sDebugOut<<endl;
353 #endif
357 void DlgIndividual::enableOpenFile()
359 #ifdef _DEBUG
360 sDebugIn<<endl;
361 #endif
364 openFile->setEnabled(true);
366 if (!bKeepDlgOpen)
368 hide();
369 m_pDockIndividual->hide();
372 #ifdef _DEBUG
373 sDebugOut<<endl;
374 #endif
377 #include "dlgIndividual.moc"