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 "downloadsettings.h"
22 #include "downloadmanager.h"
23 #include "mainwindow.h"
25 DownloadSettings::DownloadSettings(QWidget *parent) : QWidget(parent) {
27 QBoxLayout *layout = new QHBoxLayout(this);
28 layout->setMargin(10);
30 message = new QLabel(this);
31 message->setOpenExternalLinks(true);
32 layout->addWidget(message);
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);
43 void DownloadSettings::paintEvent(QPaintEvent * /*event*/) {
44 QPainter painter(this);
47 if (window()->isActiveWindow()) {
48 brush = QBrush(QColor(0xdd, 0xe4, 0xeb));
50 brush = palette().window();
52 painter.fillRect(0, 0, width(), height(), brush);
54 painter.setPen(palette().color(QPalette::Mid));
55 painter.drawLine(0, 0, width(), 0);
58 void DownloadSettings::changeFolder() {
61 QFileDialog* dialog = new QFileDialog(this);
62 dialog->setFileMode(QFileDialog::Directory);
63 dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
64 #if QT_VERSION >= 0x050000
65 path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
67 path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
69 dialog->setDirectory(path);
70 dialog->open(this, SLOT(folderChosen(const QString &)));
73 #if QT_VERSION >= 0x050000
74 path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
76 path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
78 QString folder = QFileDialog::getExistingDirectory(window(), tr("Choose the download location"),
80 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
85 void DownloadSettings::folderChosen(const QString &dir) {
88 settings.setValue("downloadFolder", dir);
90 QString status = tr("Download location changed.");
91 if (DownloadManager::instance()->activeItems() > 0)
92 status += " " + tr("Current downloads will still go in the previous location.");
93 MainWindow::instance()->showMessage(status);
97 void DownloadSettings::updateMessage() {
98 QString path = DownloadManager::instance()->currentDownloadFolder();
99 #if QT_VERSION >= 0x050000
100 QString home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
102 QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
104 QString displayPath = path;
105 displayPath = displayPath.remove(home + "/");
107 tr("Downloading to: %1")
108 .arg("<a href='file://%1' style='text-decoration:none; color:palette(text); font-weight:bold'>%2</a>")
109 .arg(path, displayPath));