3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
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.
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.
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/>.
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"
31 DownloadView::DownloadView(QWidget *parent) : View(parent) {
33 QBoxLayout *layout = new QVBoxLayout(this);
35 layout->setSpacing(0);
37 bar = new SegmentedControl(this);
38 QAction *action = new QAction(tr("Downloads"), this);
39 bar->addAction(action);
40 layout->addWidget(bar);
42 listView = new DownloadListView(this);
43 PlaylistItemDelegate *delegate = new PlaylistItemDelegate(this, true);
44 listView->setItemDelegate(delegate);
45 listView->setSelectionMode(QAbstractItemView::NoSelection);
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);
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 &)));
59 layout->addWidget(listView);
61 updateTimer = new QTimer(this);
62 updateTimer->setInterval(1000);
63 connect(updateTimer, SIGNAL(timeout()), listModel, SLOT(sendReset()));
65 downloadSettings = new DownloadSettings(this);
66 layout->addWidget(downloadSettings);
69 void DownloadView::appear() {
70 listView->setEnabled(true);
71 listModel->sendReset();
72 listView->setMouseTracking(true);
76 void DownloadView::disappear() {
77 listView->setEnabled(false);
78 listView->setMouseTracking(false);
81 void DownloadView::itemEntered(const QModelIndex &index) {
82 listModel->setHoveredRow(index.row());
85 void DownloadView::buttonPushed(QModelIndex index) {
86 const DownloadItemPointer downloadItemPointer = index.data(DownloadItemRole).value<DownloadItemPointer>();
87 DownloadItem *downloadItem = downloadItemPointer.data();
89 switch (downloadItem->status()) {
96 downloadItem->tryAgain();
99 downloadItem->openFolder();