1 #include "downloadsettings.h"
2 #include "downloadmanager.h"
3 #include "mainwindow.h"
5 DownloadSettings::DownloadSettings(QWidget *parent) : QWidget(parent) {
7 QBoxLayout *layout = new QHBoxLayout(this);
10 message = new QLabel(this);
11 message->setOpenExternalLinks(true);
12 layout->addWidget(message);
14 changeFolderButton = new QPushButton(this);
15 changeFolderButton->setText(tr("Change location..."));
16 changeFolderButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
17 connect(changeFolderButton, SIGNAL(clicked()), SLOT(changeFolder()));
18 layout->addWidget(changeFolderButton);
23 void DownloadSettings::paintEvent(QPaintEvent * /*event*/) {
24 QPainter painter(this);
27 if (window()->isActiveWindow()) {
28 brush = QBrush(QColor(0xdd, 0xe4, 0xeb));
30 brush = palette().window();
32 painter.fillRect(0, 0, width(), height(), brush);
34 painter.setPen(palette().color(QPalette::Mid));
35 painter.drawLine(0, 0, width(), 0);
38 void DownloadSettings::changeFolder() {
41 QFileDialog* dialog = new QFileDialog(this);
42 dialog->setFileMode(QFileDialog::Directory);
43 dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
44 dialog->setDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
45 dialog->open(this, SLOT(folderChosen(const QString &)));
47 QString folder = QFileDialog::getExistingDirectory(window(), tr("Choose the download location"),
48 QDesktopServices::storageLocation(QDesktopServices::HomeLocation),
49 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
54 void DownloadSettings::folderChosen(const QString &dir) {
57 settings.setValue("downloadFolder", dir);
59 QString status = tr("Download location changed.");
60 if (DownloadManager::instance()->activeItems() > 0)
61 status += " " + tr("Current downloads will still go in the previous location.");
62 MainWindow::instance()->showMessage(status);
66 void DownloadSettings::updateMessage() {
67 QString path = DownloadManager::instance()->currentDownloadFolder();
68 QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/";
69 QString displayPath = path;
70 displayPath = displayPath.remove(home);
72 tr("Downloading to: %1")
73 .arg("<a href='file://%1' style='text-decoration:none; color:palette(text); font-weight:bold'>%2</a>")
74 .arg(path, displayPath));