1 #include "downloadsettings.h"
2 #include "downloadmanager.h"
4 DownloadSettings::DownloadSettings(QWidget *parent) : QWidget(parent) {
6 QBoxLayout *layout = new QHBoxLayout(this);
9 message = new QLabel(this);
10 message->setOpenExternalLinks(true);
11 layout->addWidget(message);
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);
22 void DownloadSettings::paintEvent(QPaintEvent * /*event*/) {
23 QPainter painter(this);
26 if (window()->isActiveWindow()) {
27 brush = QBrush(QColor(0xdd, 0xe4, 0xeb));
29 brush = palette().window();
31 painter.fillRect(0, 0, width(), height(), brush);
33 painter.setPen(palette().color(QPalette::Mid));
34 painter.drawLine(0, 0, width(), 0);
37 void DownloadSettings::changeFolder() {
40 QFileDialog* dialog = new QFileDialog(this);
41 dialog->setFileMode(QFileDialog::Directory);
42 dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
43 dialog->setDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
44 dialog->open(this, SLOT(folderChosen(const QString &)));
46 QString folder = QFileDialog::getExistingDirectory(window(), tr("Choose the download location"),
47 QDesktopServices::storageLocation(QDesktopServices::HomeLocation),
48 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
53 void DownloadSettings::folderChosen(const QString &dir) {
56 settings.setValue("downloadFolder", dir);
58 QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
61 status = tr("Download location changed.");
62 if (DownloadManager::instance()->activeItems() > 0)
63 status += " " + tr("Current downloads will still go in the previous location.");
64 mainWindow->statusBar()->showMessage(status);
69 void DownloadSettings::updateMessage() {
70 QString path = DownloadManager::instance()->currentDownloadFolder();
71 QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/";
72 QString displayPath = path;
73 displayPath = displayPath.remove(home);
75 tr("Downloading to: %1")
76 .arg("<a href='file://%1' style='text-decoration:none; color:palette(text); font-weight:bold'>%2</a>")
77 .arg(path, displayPath));