]> git.sur5r.net Git - minitube/blob - src/downloadsettings.cpp
Imported Upstream version 1.2
[minitube] / src / downloadsettings.cpp
1 #include "downloadsettings.h"
2 #include "downloadmanager.h"
3
4 DownloadSettings::DownloadSettings(QWidget *parent) : QWidget(parent) {
5
6     QBoxLayout *layout = new QHBoxLayout(this);
7     layout->setMargin(10);
8
9     message = new QLabel(this);
10     message->setOpenExternalLinks(true);
11     layout->addWidget(message);
12
13     changeFolderButton = new QPushButton(this);
14     changeFolderButton->setText(tr("Change location..."));
15     changeFolderButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
16     connect(changeFolderButton, SIGNAL(clicked()), SLOT(changeFolder()));
17     layout->addWidget(changeFolderButton);
18
19     updateMessage();
20 }
21
22 void DownloadSettings::paintEvent(QPaintEvent * /*event*/) {
23     QPainter painter(this);
24 #ifdef APP_MAC
25     QBrush brush;
26     if (window()->isActiveWindow()) {
27         brush = QBrush(QColor(0xdd, 0xe4, 0xeb));
28     } else {
29         brush = palette().window();
30     }
31     painter.fillRect(0, 0, width(), height(), brush);
32 #endif
33     painter.setPen(palette().color(QPalette::Mid));
34     painter.drawLine(0, 0, width(), 0);
35 }
36
37 void DownloadSettings::changeFolder() {
38     QString dir = QFileDialog::getExistingDirectory(this, tr("Choose the download location"),
39                                                     QDesktopServices::storageLocation(QDesktopServices::HomeLocation),
40                                                     QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
41
42     if (!dir.isEmpty()) {
43         QSettings settings;
44         settings.setValue("downloadFolder", dir);
45         updateMessage();
46         QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
47         if (mainWindow) {
48             QString status;
49             status = tr("Download location changed.");
50             if (DownloadManager::instance()->activeItems() > 0)
51                 status += " " + tr("Current downloads will still go in the previous location.");
52             mainWindow->statusBar()->showMessage(status);
53         }
54     }
55 }
56
57 void DownloadSettings::updateMessage() {
58     QString path = DownloadManager::instance()->currentDownloadFolder();
59     QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/";
60     QString displayPath = path;
61     displayPath = displayPath.remove(home);
62     message->setText(
63             tr("Downloading to: %1")
64             .arg("<a href='file://%1' style='text-decoration:none; color:palette(text); font-weight:bold'>%2</a>")
65             .arg(path, displayPath));
66 }