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) : QWidget(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);
44 listView->setAlternatingRowColors(true);
47 QPalette p = listView->palette();
48 p.setColor(QPalette::Base, palette().color(QPalette::Window));
49 listView->setPalette(p);
51 PlaylistItemDelegate *delegate = new PlaylistItemDelegate(this, true);
52 listView->setItemDelegate(delegate);
53 listView->setSelectionMode(QAbstractItemView::NoSelection);
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);
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 &)));
67 layout->addWidget(listView);
69 updateTimer = new QTimer(this);
70 updateTimer->setInterval(1000);
71 connect(updateTimer, SIGNAL(timeout()), listModel, SLOT(sendReset()));
73 downloadSettings = new DownloadSettings(this);
74 layout->addWidget(downloadSettings);
77 void DownloadView::appear() {
78 listView->setEnabled(true);
79 listModel->sendReset();
80 listView->setMouseTracking(true);
84 void DownloadView::disappear() {
85 listView->setEnabled(false);
86 listView->setMouseTracking(false);
89 void DownloadView::itemEntered(const QModelIndex &index) {
90 listModel->setHoveredRow(index.row());
93 void DownloadView::buttonPushed(QModelIndex index) {
94 const DownloadItemPointer downloadItemPointer = index.data(DownloadItemRole).value<DownloadItemPointer>();
95 DownloadItem *downloadItem = downloadItemPointer.data();
97 switch (downloadItem->status()) {
100 downloadItem->stop();
104 downloadItem->tryAgain();
107 downloadItem->openFolder();