]> git.sur5r.net Git - minitube/blob - src/downloadsettings.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / downloadsettings.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 "downloadsettings.h"
22 #include "downloadmanager.h"
23 #include "mainwindow.h"
24
25 DownloadSettings::DownloadSettings(QWidget *parent) : QWidget(parent) {
26
27     QBoxLayout *layout = new QHBoxLayout(this);
28     layout->setMargin(10);
29
30     message = new QLabel(this);
31     message->setOpenExternalLinks(true);
32     layout->addWidget(message);
33
34     changeFolderButton = new QPushButton(this);
35     changeFolderButton->setText(tr("Change location..."));
36     changeFolderButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
37     connect(changeFolderButton, SIGNAL(clicked()), SLOT(changeFolder()));
38     layout->addWidget(changeFolderButton);
39
40     updateMessage();
41 }
42
43 void DownloadSettings::paintEvent(QPaintEvent * /*event*/) {
44     QPainter painter(this);
45 #ifdef APP_MAC
46     QBrush brush;
47     if (window()->isActiveWindow()) {
48         brush = QBrush(QColor(0xdd, 0xe4, 0xeb));
49     } else {
50         brush = palette().window();
51     }
52     painter.fillRect(0, 0, width(), height(), brush);
53 #endif
54     painter.setPen(palette().color(QPalette::Mid));
55     painter.drawLine(0, 0, width(), 0);
56 }
57
58 void DownloadSettings::changeFolder() {
59     const QString path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
60 #ifdef APP_MAC
61     QFileDialog* dialog = new QFileDialog(this);
62     dialog->setFileMode(QFileDialog::Directory);
63     dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
64     dialog->setDirectory(path);
65     dialog->open(this, SLOT(folderChosen(const QString &)));
66 #else
67
68     QString folder = QFileDialog::getExistingDirectory(window(), tr("Choose the download location"),
69                                                        path,
70                                                        QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
71     folderChosen(folder);
72 #endif
73 }
74
75 void DownloadSettings::folderChosen(const QString &dir) {
76     if (!dir.isEmpty()) {
77         QSettings settings;
78         settings.setValue("downloadFolder", dir);
79         updateMessage();
80         QString status = tr("Download location changed.");
81         if (DownloadManager::instance()->activeItems() > 0)
82             status += " " + tr("Current downloads will still go in the previous location.");
83         MainWindow::instance()->showMessage(status);
84     }
85 }
86
87 void DownloadSettings::updateMessage() {
88     const QString path = DownloadManager::instance()->currentDownloadFolder();
89     const QString home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
90     QString displayPath = path;
91     displayPath = displayPath.remove(home + "/");
92     message->setText(
93                 tr("Downloading to: %1")
94                 .arg("<a href='file://%1' style='text-decoration:none; color:palette(text); font-weight:bold'>%2</a>")
95                 .arg(path, displayPath));
96 }