]> git.sur5r.net Git - minitube/blob - src/downloadview.cpp
Imported Upstream version 2.1.3
[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) : QWidget(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 #ifdef APP_MAC
44     listView->setAlternatingRowColors(true);
45 #endif
46     /*
47     QPalette p = listView->palette();
48     p.setColor(QPalette::Base, palette().color(QPalette::Window));
49     listView->setPalette(p);
50     */
51     PlaylistItemDelegate *delegate = new PlaylistItemDelegate(this, true);
52     listView->setItemDelegate(delegate);
53     listView->setSelectionMode(QAbstractItemView::NoSelection);
54
55     // cosmetics
56     listView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
57     listView->setFrameShape(QFrame::NoFrame);
58     listView->setAttribute(Qt::WA_MacShowFocusRect, false);
59     listView->setMinimumSize(320,240);
60     listView->setUniformItemSizes(true);
61
62     listModel = DownloadManager::instance()->getModel();
63     listView->setModel(listModel);
64     connect(listView, SIGNAL(downloadButtonPushed(QModelIndex)), SLOT(buttonPushed(QModelIndex)));
65     connect(listView, SIGNAL(entered(const QModelIndex &)), SLOT(itemEntered(const QModelIndex &)));
66
67     layout->addWidget(listView);
68
69     updateTimer = new QTimer(this);
70     updateTimer->setInterval(1000);
71     connect(updateTimer, SIGNAL(timeout()), listModel, SLOT(sendReset()));
72
73     downloadSettings = new DownloadSettings(this);
74     layout->addWidget(downloadSettings);
75 }
76
77 void DownloadView::appear() {
78     listView->setEnabled(true);
79     listModel->sendReset();
80     listView->setMouseTracking(true);
81     updateTimer->start();
82 }
83
84 void DownloadView::disappear() {
85     listView->setEnabled(false);
86     listView->setMouseTracking(false);
87 }
88
89 void DownloadView::itemEntered(const QModelIndex &index) {
90     listModel->setHoveredRow(index.row());
91 }
92
93 void DownloadView::buttonPushed(QModelIndex index) {
94     const DownloadItemPointer downloadItemPointer = index.data(DownloadItemRole).value<DownloadItemPointer>();
95     DownloadItem *downloadItem = downloadItemPointer.data();
96
97     switch (downloadItem->status()) {
98     case Downloading:
99     case Starting:
100         downloadItem->stop();
101         break;
102     case Idle:
103     case Failed:
104         downloadItem->tryAgain();
105         break;
106     case Finished:
107         downloadItem->openFolder();
108     }
109
110 }