summaryrefslogtreecommitdiffstats
path: root/kget/dlgIndividual.cpp
blob: a22bccea8556d0a16dfdcc8f232f442378324ab0 (plain)
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
/***************************************************************************
*                               dlgIndividual.cpp
*                             -------------------
*
*    Revision     : $Id$
*    begin        : Tue Jan 29 2002
*    copyright    : (C) 2002 by Patrick Charbonnier
*                 : Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss
*    email        : [email protected]
*
****************************************************************************/

/***************************************************************************
 *
 *   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.
 *
 ***************************************************************************/


#include <tqlayout.h>

#include "dockindividual.h"

#include <tqlabel.h>
#include <tqtabwidget.h>
#include <kprogress.h>
#include <tqtextedit.h>
#include <tqcheckbox.h>
#include <kpushbutton.h>
#include <ksqueezedtextlabel.h>
#include <kdatetimewidget.h>

#include <kapplication.h>
#include <kaction.h>
#include <klocale.h>
#include <ktoolbar.h>
#include <krun.h>
#include <kio/global.h>
#include "common.h"

#include "transfer.h"

#include "settings.h"
#include "dlgIndividual.h"


DlgIndividual::DlgIndividual(Transfer * _item)
    : TQWidget(0, "dialog", WDestructiveClose)
{
    item = _item;

    //create dock
    m_pDockIndividual =new DockIndividual(this);


    // Actions

    m_paDock = new KToggleAction(i18n("&Dock"),"tool_dock.png", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleDock()), TQT_TQOBJECT(this), "dockIndividual");


    TQVBoxLayout *topLayout = new TQVBoxLayout( this, KDialog::marginHint(),KDialog::spacingHint() );
    topLayout->addStrut( 360 );   // makes dlg at least that wide

    TQGridLayout *grid = new TQGridLayout( 2, 3 );
    topLayout->addLayout(grid);
    grid->addColSpacing(1, KDialog::spacingHint());

    grid->addWidget(new TQLabel(i18n("Source:"), this), 0, 0);

    sourceLabel = new KSqueezedTextLabel(this);
    grid->addWidget(sourceLabel, 0, 2);
    sourceLabel->setText(i18n("Source Label"));
    grid->addWidget(new TQLabel(i18n("Destination:"), this), 1, 0);

    destLabel = new KSqueezedTextLabel(this);
    grid->addWidget(destLabel, 1, 2);
    destLabel->setText(i18n("Source Label"));

    m_pProgressBar = new KProgress(this);
    topLayout->addWidget( m_pProgressBar );

    // processed info
    TQHBoxLayout *hBox = new TQHBoxLayout();
    topLayout->addLayout(hBox);

    sizeLabel = new TQLabel(this);
    hBox->addWidget(sizeLabel);
    resumeLabel = new TQLabel(this);
    hBox->addWidget(resumeLabel);

    speedLabel = new TQLabel(this);
    speedLabel->setText(i18n("0 B/s"));
    topLayout->addWidget(speedLabel);

    // setup toolbar
    KToolBar *toolBar = new KToolBar(this);
    toolBar->setIconText(KToolBar::IconOnly);
    toolBar->setBarPos(KToolBar::Bottom);
    toolBar->setMovingEnabled(false);
    toolBar->setFlat(true);

    topLayout->addWidget( toolBar );

    // insert toolbar actions
    item->m_paResume->plug(toolBar);
    item->m_paPause->plug(toolBar);
    item->m_paDelete->plug(toolBar);

    toolBar->insertLineSeparator();

    item->m_paQueue->plug(toolBar);
    item->m_paTimer->plug(toolBar);
    item->m_paDelay->plug(toolBar);

    toolBar->insertLineSeparator();
    m_paDock->plug(toolBar);



    TQCheckBox * keepOpen = new TQCheckBox( i18n("&Keep this window open after the operation is complete."), this);
    connect( keepOpen, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( slotKeepOpenToggled(bool) ) );
    topLayout->addWidget(keepOpen);

    TQFrame *line3 = new TQFrame( this );
    line3->setFrameShape( TQFrame::HLine );
    line3->setFrameShadow( TQFrame::Sunken );
    topLayout->addWidget( line3 );

    hBox = new TQHBoxLayout();
    topLayout->addLayout(hBox);

    openFile = new KPushButton( i18n("Open &File"), this );
    connect( openFile, TQT_SIGNAL( clicked() ), TQT_SLOT( slotOpenFile() ) );
    hBox->addWidget( openFile );
    openFile->setEnabled(false);

    openLocation = new KPushButton( i18n("Open &Destination"), this );
    connect( openLocation, TQT_SIGNAL( clicked() ), TQT_SLOT( slotOpenLocation() ) );
    hBox->addWidget( openLocation );

    hBox->addStretch(1);

    pbAdvanced = new KPushButton( i18n("Advanced"), this );

    connect(pbAdvanced, TQT_SIGNAL(clicked()), TQT_SLOT(slotToggleAdvanced()));

    hBox->addWidget( pbAdvanced );


    // setup tab dialog
    panelAdvanced = new TQTabWidget(this);

    // if the time was already set somewhere in the future, keep it
    // otherwise set it to the current time
    TQDateTime dt;

    if (item->getStartTime() < TQDateTime::currentDateTime() && item->getMode() != Transfer::MD_SCHEDULED)
    {
        dt = TQDateTime::currentDateTime();
    }
    else
    {
        dt = item->getStartTime();
    }

    spins = new KDateTimeWidget(dt, this, "spins");

    panelAdvanced->addTab(spins, i18n("Timer"));
    panelAdvanced->hide();

    connect(spins, TQT_SIGNAL(valueChanged(const TQDateTime &)), item, TQT_SLOT(slotStartTime(const TQDateTime &)));

    // adding item log
    ml_log = new TQTextEdit(panelAdvanced);
    ml_log->setTextFormat(LogText);
    ml_log->setReadOnly(true);
    // ml_log->setFixedSize(sizeHint());
    ml_log->setVScrollBarMode(TQScrollView::Auto);
    ml_log->setWordWrap(TQTextEdit::NoWrap);

    // ml_log->setSizePolicy(policy);

    panelAdvanced->addTab(ml_log, i18n("Log"));
    // panelAdvanced->setFixedSize(sizeHint());



    topLayout->addWidget(panelAdvanced);
    advanced = ksettings.b_advancedIndividual;
    slotToggleAdvanced();

    resize( minimumSizeHint() );
    setMaximumHeight( height() );

    //bool keepOpenChecked = false;
    //bool noCaptionYet = true;
    setCaption(i18n("Progress Dialog"));

    bKeepDlgOpen=false;
}


void DlgIndividual::setTotalSize(TDEIO::filesize_t bytes)
{
    m_iTotalSize = bytes;
}


void DlgIndividual::setPercent(unsigned long percent)
{
    m_pProgressBar->setValue(percent);
    m_pDockIndividual->setValue(percent);
    setCaption(i18n("%1% of %2 - %3").arg(percent).arg(TDEIO::convertSize(m_iTotalSize)).arg(m_location.fileName()));
}


void DlgIndividual::setProcessedSize(TDEIO::filesize_t bytes)
{
    sizeLabel->setText(i18n("%1 of %2").arg(TDEIO::convertSize(bytes)).arg(TDEIO::convertSize(m_iTotalSize)));
}


void DlgIndividual::setSpeed(TQString speed)
{
    speedLabel->setText(speed);
    m_pDockIndividual->setTip(speed);
}


void DlgIndividual::setCopying(const KURL & from, const KURL & to)
{
    m_location=to;
    setCaption(m_location.fileName());

    sourceLabel->setText(from.prettyURL());
    destLabel->setText(to.prettyURL());
}


void DlgIndividual::setCanResume(bool resume)
{
    if (resume)
        resumeLabel->setText(i18n("Resumed"));
    else
        resumeLabel->setText(i18n("Not resumed"));
}

//void DlgIndividual::slotToggleAdvanced(bool advanced)
void DlgIndividual::slotToggleAdvanced()
{
#ifdef _DEBUG
    sDebugIn<<endl;
#endif

    if (advanced)
        panelAdvanced->show();
    else
    {
        panelAdvanced->hide();
        adjustSize();
    }
    advanced = !advanced;

#ifdef _DEBUG
    sDebugOut<<endl;
#endif
}

void DlgIndividual::slotToggleDock()
{
#ifdef _DEBUG
    sDebugIn<<endl;
#endif

    if (m_paDock->isChecked())
    {
        m_pDockIndividual->show();
        hide();
    }
    else
        m_pDockIndividual->hide();

#ifdef _DEBUG
    sDebugOut<<endl;
#endif
}


/** Sets the whole log */
void DlgIndividual::setLog(const TQString & _msg)
{
    ml_log->setText(_msg);
}

void DlgIndividual::appendLog(const TQString & _msg)
{
    ml_log->append(_msg);
}


void DlgIndividual::slotKeepOpenToggled(bool bToggled)
{
#ifdef _DEBUG
  sDebugIn <<"bToggled= "<<bToggled<<endl;
#endif


    bKeepDlgOpen=bToggled;

    if (!bKeepDlgOpen && item->getStatus()==Transfer::ST_FINISHED)
    {
        hide();
        m_pDockIndividual->hide();
    }

#ifdef _DEBUG
    sDebugOut<<endl;
#endif
}


void DlgIndividual::slotOpenLocation()
{
#ifdef _DEBUG
    sDebugIn<<endl;
#endif

    KURL location=m_location;
    location.setFileName("");
    kapp->invokeBrowser( location.url() );

#ifdef _DEBUG
    sDebugOut<<endl;
#endif
}

void DlgIndividual::slotOpenFile()
{
#ifdef _DEBUG
  sDebugIn "Starting kfmclient with url "<<m_location.prettyURL()<<endl;
#endif

    (void) new KRun( m_location );

#ifdef _DEBUG
    sDebugOut<<endl;
#endif
}


void DlgIndividual::enableOpenFile()
{
#ifdef _DEBUG
    sDebugIn<<endl;
#endif


    openFile->setEnabled(true);

    if (!bKeepDlgOpen)
    {
        hide();
        m_pDockIndividual->hide();
    }

#ifdef _DEBUG
    sDebugOut<<endl;
#endif
}

#include "dlgIndividual.moc"