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() {
38 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose the download location"),
39 QDesktopServices::storageLocation(QDesktopServices::HomeLocation),
40 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
44 settings.setValue("downloadFolder", dir);
46 QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
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);
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);
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));