]> git.sur5r.net Git - minitube/blob - src/downloadview.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / downloadview.cpp
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
18
19 $END_LICENSE */
20
21 #include "downloadview.h"
22 #include "downloadmodel.h"
23 #include "downloadmanager.h"
24 #include "downloadlistview.h"
25 #include "downloaditem.h"
26 #include "downloadsettings.h"
27 #include "playlistmodel.h"
28 #include "playlistitemdelegate.h"
29 #include "segmentedcontrol.h"
30
31 DownloadView::DownloadView(QWidget *parent) : View(parent) {
32
33     QBoxLayout *layout = new QVBoxLayout(this);
34     layout->setMargin(0);
35     layout->setSpacing(0);
36
37     bar = new SegmentedControl(this);
38     QAction *action = new QAction(tr("Downloads"), this);
39     bar->addAction(action);
40     layout->addWidget(bar);
41
42     listView = new DownloadListView(this);
43     PlaylistItemDelegate *delegate = new PlaylistItemDelegate(listView, true);
44     listView->setItemDelegate(delegate);
45     listView->setSelectionMode(QAbstractItemView::NoSelection);
46
47     // cosmetics
48     listView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
49     listView->setFrameShape(QFrame::NoFrame);
50     listView->setAttribute(Qt::WA_MacShowFocusRect, false);
51     listView->setMinimumSize(320,240);
52     listView->setUniformItemSizes(true);
53
54     listModel = DownloadManager::instance()->getModel();
55     listView->setModel(listModel);
56     connect(listView, SIGNAL(downloadButtonPushed(QModelIndex)), SLOT(buttonPushed(QModelIndex)));
57     connect(listView, SIGNAL(entered(const QModelIndex &)), SLOT(itemEntered(const QModelIndex &)));
58
59     layout->addWidget(listView);
60
61     updateTimer = new QTimer(this);
62     updateTimer->setInterval(1000);
63     connect(updateTimer, SIGNAL(timeout()), listModel, SLOT(sendReset()));
64
65     downloadSettings = new DownloadSettings(this);
66     layout->addWidget(downloadSettings);
67 }
68
69 void DownloadView::appear() {
70     listView->setEnabled(true);
71     listModel->sendReset();
72     listView->setMouseTracking(true);
73     updateTimer->start();
74 }
75
76 void DownloadView::disappear() {
77     listView->setEnabled(false);
78     listView->setMouseTracking(false);
79 }
80
81 void DownloadView::itemEntered(const QModelIndex &index) {
82     listModel->setHoveredRow(index.row());
83 }
84
85 void DownloadView::buttonPushed(QModelIndex index) {
86     const DownloadItemPointer downloadItemPointer = index.data(DownloadItemRole).value<DownloadItemPointer>();
87     DownloadItem *downloadItem = downloadItemPointer.data();
88
89     switch (downloadItem->status()) {
90     case Downloading:
91     case Starting:
92         downloadItem->stop();
93         break;
94     case Idle:
95     case Failed:
96         downloadItem->tryAgain();
97         break;
98     case Finished:
99         downloadItem->openFolder();
100     }
101
102 }