~ubuntu-branches/ubuntu/lucid/ktorrent/lucid

« back to all changes in this revision

Viewing changes to ktorrent/view.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-12-08 19:17:41 UTC
  • mfrom: (1.2.1 upstream) (0.7.12 sid)
  • Revision ID: james.westby@ubuntu.com-20091208191741-lqlq0xvnlv8ki19u
Tags: 3.3.1+dfsg.1-1ubuntu1
* Merge with Debian Testing remaining changes:
  - Build-depend directly on libboost-serialization1.40-dev since
    libboost-serialization-dev from boost-defaults is not in Main
  - Add in rules: include /usr/lib/kubuntu-desktop-i18n/debhelper/kubuntu.mk
  - Don't use dpkg-source 3.0 format
  - Add quilt to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 ***************************************************************************/
21
21
#include <QHeaderView>
22
22
#include <QFileInfo>
 
23
#include <QDropEvent>
 
24
#include <QDragEnterEvent>
23
25
#include <QSortFilterProxyModel>
24
26
#include <krun.h>
25
27
#include <kmenu.h>
30
32
#include <kinputdialog.h>
31
33
#include <interfaces/torrentinterface.h>
32
34
#include <torrent/queuemanager.h>
 
35
#include <torrent/jobqueue.h>
33
36
#include <util/functions.h>
34
37
#include <util/log.h>
35
38
#include <interfaces/functions.h>
42
45
#include "speedlimitsdlg.h"
43
46
#include "addpeersdlg.h"
44
47
#include "viewselectionmodel.h"
45
 
 
 
48
#include "viewdelegate.h"
 
49
#include "scanlistener.h"
46
50
 
47
51
using namespace bt;
48
52
 
62
66
                setDragEnabled(true);
63
67
                setSelectionMode(QAbstractItemView::ExtendedSelection);
64
68
                setSelectionBehavior(QAbstractItemView::SelectRows);
65
 
                setUniformRowHeights(true);
 
69
                setAcceptDrops(true);
 
70
                setDragDropMode(DragDrop);
 
71
//              setUniformRowHeights(true);
66
72
                
67
 
                connect(this,SIGNAL(wantToRemove(bt::TorrentInterface*,bool )),core,SLOT(remove(bt::TorrentInterface*,bool )));
68
 
                connect(this,SIGNAL(wantToStart( QList<bt::TorrentInterface*> & )),core,SLOT(start( QList<bt::TorrentInterface*> & )));
69
 
                connect(this,SIGNAL(wantToStop( bt::TorrentInterface*, bool )),core,SLOT(stop( bt::TorrentInterface*, bool )));
70
73
                connect(this,SIGNAL(customContextMenuRequested(const QPoint & ) ),this,SLOT(showMenu( const QPoint& )));
71
74
        
72
75
                header()->setContextMenuPolicy(Qt::CustomContextMenu);
97
100
                connect(selectionModel(),SIGNAL(selectionChanged(const QItemSelection &,const QItemSelection)),
98
101
                                this,SLOT(onSelectionChanged(const QItemSelection &,const QItemSelection)));
99
102
                connect(model,SIGNAL(sorted()),selection_model,SLOT(sorted()));
 
103
                
 
104
                delegate = new ViewDelegate(core,model,this);
 
105
                setItemDelegate(delegate);
100
106
        }
101
107
 
102
108
        View::~View()
103
109
        {
 
110
                delegate->contractAll();
104
111
        }
105
112
        
106
113
        void View::setupDefaultColumns()
131
138
 
132
139
        void View::update()
133
140
        {
134
 
                model->update();
 
141
                model->update(delegate);
135
142
        }
136
143
 
137
144
        bool View::needToUpdateCaption()
175
182
        {
176
183
                QList<bt::TorrentInterface*> sel;
177
184
                getSelection(sel);
178
 
                wantToStart(sel);
 
185
                if (sel.count() > 0)
 
186
                        core->start(sel);
179
187
        }
180
188
 
181
189
        void View::stopTorrents()
182
190
        {
183
191
                QList<bt::TorrentInterface*> sel;
184
192
                getSelection(sel);
185
 
                foreach(bt::TorrentInterface* tc,sel)
186
 
                {
187
 
                        wantToStop(tc,true);
188
 
                }
 
193
                if (sel.count() > 0)
 
194
                        core->stop(sel);
189
195
        }
190
196
 
191
197
        void View::removeTorrents()
194
200
                getSelection(sel);
195
201
                foreach(bt::TorrentInterface* tc,sel)
196
202
                {
197
 
                        bool dummy;
198
 
                        if (tc && !tc->isCheckingData(dummy))
 
203
                        if (tc && !tc->getJobQueue()->runningJobs())
199
204
                        {       
200
205
                                const TorrentStats & s = tc->getStats();
201
206
                                bool data_to = false;
215
220
                                        else if (ret == KMessageBox::Yes)
216
221
                                                data_to = true;
217
222
                                }
218
 
                                wantToRemove(tc,data_to);
 
223
                                core->remove(tc,data_to);
219
224
                        }
220
225
                }
221
226
        }
233
238
 
234
239
                foreach(bt::TorrentInterface* tc,sel)
235
240
                {
236
 
                        bool dummy = false;
237
 
                        if (tc && !tc->isCheckingData(dummy))
238
 
                                wantToRemove(tc,true);
 
241
                        if (tc && !tc->getJobQueue()->runningJobs())
 
242
                                core->remove(tc,true);
239
243
                }
240
244
        }
241
245
 
243
247
        {
244
248
                QList<bt::TorrentInterface*> all;
245
249
                model->allTorrents(all);
246
 
                wantToStart(all);
 
250
                core->start(all);
247
251
        }
248
252
 
249
253
        void View::stopAllTorrents()
250
254
        {
251
255
                QList<bt::TorrentInterface*> all;
252
256
                model->allTorrents(all);
253
 
                foreach (bt::TorrentInterface* tc,all)
254
 
                {
255
 
                        wantToStop(tc,true);
256
 
                }
257
 
        }
258
 
 
259
 
        void View::queueTorrents()
260
 
        {
261
 
                QList<bt::TorrentInterface*> sel;
262
 
                getSelection(sel);
263
 
                foreach(bt::TorrentInterface* tc,sel)
264
 
                {
265
 
                        bool dummy;
266
 
                        if (tc && !tc->isCheckingData(dummy))
267
 
                                core->queue(tc);
268
 
                }
 
257
                core->stop(all);
269
258
        }
270
259
 
271
260
        void View::addPeers()
374
363
                getSelection(sel);
375
364
                foreach(bt::TorrentInterface* tc,sel)
376
365
                {
377
 
                        bool dummy;
378
 
                        if (tc && !tc->isCheckingData(dummy))
 
366
                        if (tc)
379
367
                        {
380
368
                                bool on = tc->isFeatureEnabled(bt::DHT_FEATURE);
381
369
                                tc->setFeatureEnabled(bt::DHT_FEATURE,!on);
382
370
                        }
383
 
                }                                                       
 
371
                }
384
372
        }
385
373
 
386
374
        void View::togglePEX()
389
377
                getSelection(sel);
390
378
                foreach(bt::TorrentInterface* tc,sel)
391
379
                {
392
 
                        bool dummy;
393
 
                        if (tc && !tc->isCheckingData(dummy))
 
380
                        if (tc)
394
381
                        {
395
382
                                bool on = tc->isFeatureEnabled(bt::UT_PEX_FEATURE);
396
383
                                tc->setFeatureEnabled(bt::UT_PEX_FEATURE,!on);
413
400
        {
414
401
                QList<bt::TorrentInterface*> sel;
415
402
                getSelection(sel);
416
 
                if (sel.count() == 0)
 
403
                if (sel.count() > 0)
 
404
                {
 
405
                        core->doDataCheck(sel.front());
 
406
                        core->startUpdateTimer(); // make sure update timer of core is running
 
407
                }
 
408
        }
 
409
 
 
410
        void View::dataScanStarted(ScanListener* listener)
 
411
        {
 
412
                if (delegate->extended(listener->torrent()))
417
413
                        return;
418
414
                
419
 
                ScanDlg* dlg = new ScanDlg(core,false,this);
420
 
                dlg->show();
421
 
                dlg->execute(sel.front(),false);
422
 
                core->startUpdateTimer(); // make sure update timer of core is running
423
 
        }
 
415
                QWidget* ext = listener->createExtender();
 
416
                if (ext)
 
417
                {
 
418
                        ext->hide();
 
419
                        delegate->extend(listener->torrent(),ext);
 
420
                }
 
421
        }
 
422
        
 
423
        void View::dataScanClosed(ScanListener* listener)
 
424
        {
 
425
                delegate->closeExtender(listener->torrent());
 
426
        }
 
427
 
424
428
 
425
429
        void View::showMenu(const QPoint & pos)
426
430
        {
427
 
                showMenu(this,mapToGlobal(pos));
 
431
                showMenu(this,viewport()->mapToGlobal(pos));
428
432
        }
429
433
        
430
434
        void View::showHeaderMenu(const QPoint& pos)
514
518
                
515
519
                return ret;
516
520
        }
 
521
 
 
522
        
517
523
}
518
524
 
519
525
#include "view.moc"