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 ***************************************************************************/
30 #include "dockindividual.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>
51 #include "dlgIndividual.h"
54 DlgIndividual::DlgIndividual(Transfer
* _item
)
55 : QWidget(0, "dialog", WDestructiveClose
)
60 m_pDockIndividual
=new DockIndividual(this);
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
);
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
);
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
);
150 pbAdvanced
= new KPushButton( i18n("Advanced"), this );
152 connect(pbAdvanced
, SIGNAL(clicked()), SLOT(slotToggleAdvanced()));
154 hBox
->addWidget( pbAdvanced
);
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
164 if (item
->getStartTime() < QDateTime::currentDateTime() && item
->getMode() != Transfer::MD_SCHEDULED
)
166 dt
= QDateTime::currentDateTime();
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
&)));
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"));
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
)
239 setCaption(m_location
.fileName());
241 sourceLabel
->setText(from
.prettyURL());
242 destLabel
->setText(to
.prettyURL());
246 void DlgIndividual::setCanResume(bool resume
)
249 resumeLabel
->setText(i18n("Resumed"));
251 resumeLabel
->setText(i18n("Not resumed"));
254 //void DlgIndividual::slotToggleAdvanced(bool advanced)
255 void DlgIndividual::slotToggleAdvanced()
262 panelAdvanced
->show();
265 panelAdvanced
->hide();
268 advanced
= !advanced
;
275 void DlgIndividual::slotToggleDock()
281 if (m_paDock
->isChecked())
283 m_pDockIndividual
->show();
287 m_pDockIndividual
->hide();
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
)
310 sDebugIn
<<"bToggled= "<<bToggled
<<endl
;
314 bKeepDlgOpen
=bToggled
;
316 if (!bKeepDlgOpen
&& item
->getStatus()==Transfer::ST_FINISHED
)
319 m_pDockIndividual
->hide();
328 void DlgIndividual::slotOpenLocation()
334 KURL location
=m_location
;
335 location
.setFileName("");
336 kapp
->invokeBrowser( location
.url() );
343 void DlgIndividual::slotOpenFile()
346 sDebugIn
"Starting kfmclient with url "<<m_location
.prettyURL()<<endl
;
349 (void) new KRun( m_location
);
357 void DlgIndividual::enableOpenFile()
364 openFile
->setEnabled(true);
369 m_pDockIndividual
->hide();
377 #include "dlgIndividual.moc"