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"
24 #include "compatibility/pathsservice.h"
26 DownloadSettings::DownloadSettings(QWidget *parent) : QWidget(parent) {
28 QBoxLayout *layout = new QHBoxLayout(this);
29 layout->setMargin(10);
31 message = new QLabel(this);
32 message->setOpenExternalLinks(true);
33 layout->addWidget(message);
35 changeFolderButton = new QPushButton(this);
36 changeFolderButton->setText(tr("Change location..."));
37 changeFolderButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
38 connect(changeFolderButton, SIGNAL(clicked()), SLOT(changeFolder()));
39 layout->addWidget(changeFolderButton);
44 void DownloadSettings::paintEvent(QPaintEvent * /*event*/) {
45 QPainter painter(this);
48 if (window()->isActiveWindow()) {
49 brush = QBrush(QColor(0xdd, 0xe4, 0xeb));
51 brush = palette().window();
53 painter.fillRect(0, 0, width(), height(), brush);
55 painter.setPen(palette().color(QPalette::Mid));
56 painter.drawLine(0, 0, width(), 0);
59 void DownloadSettings::changeFolder() {
60 const QString path = Paths::getHomeLocation();
62 QFileDialog* dialog = new QFileDialog(this);
63 dialog->setFileMode(QFileDialog::Directory);
64 dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
65 dialog->setDirectory(path);
66 dialog->open(this, SLOT(folderChosen(const QString &)));
69 QString folder = QFileDialog::getExistingDirectory(window(), tr("Choose the download location"),
71 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
76 void DownloadSettings::folderChosen(const QString &dir) {
79 settings.setValue("downloadFolder", dir);
81 QString status = tr("Download location changed.");
82 if (DownloadManager::instance()->activeItems() > 0)
83 status += " " + tr("Current downloads will still go in the previous location.");
84 MainWindow::instance()->showMessage(status);
88 void DownloadSettings::updateMessage() {
89 const QString path = DownloadManager::instance()->currentDownloadFolder();
90 const QString home = Paths::getHomeLocation();
91 QString displayPath = path;
92 displayPath = displayPath.remove(home + "/");
94 tr("Downloading to: %1")
95 .arg("<a href='file://%1' style='text-decoration:none; color:palette(text); font-weight:bold'>%2</a>")
96 .arg(path, displayPath));