Falkon Develop
Cross-platform Qt-based web browser
downloadoptionsdialog.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
19#include "ui_downloadoptionsdialog.h"
20#include "iconprovider.h"
21
22#include <QClipboard>
23#include <QMimeDatabase>
24#include <QWebEngineDownloadRequest>
25
26DownloadOptionsDialog::DownloadOptionsDialog(const QString &fileName, QWebEngineDownloadRequest *downloadItem, QWidget *parent)
27 : QDialog(parent)
28 , ui(new Ui::DownloadOptionsDialog)
29 , m_downloadItem(downloadItem)
30 , m_signalEmited(false)
31{
32 ui->setupUi(this);
33
34 ui->fileName->setText(QSL("<b>") + fileName + QSL("</b>"));
35 ui->fromServer->setText(m_downloadItem->url().host());
36
37 const QIcon fileIcon = IconProvider::instance()->standardIcon(QStyle::SP_FileIcon);
38
39 QMimeDatabase db;
40 const QMimeType mime = db.mimeTypeForName(downloadItem->mimeType());
41 if (mime.isValid() && !mime.isDefault()) {
42 ui->mimeName->setText(mime.comment());
43 ui->iconLabel->setPixmap(QIcon::fromTheme(mime.iconName(), fileIcon).pixmap(22));
44 } else {
45 ui->mimeFrame->hide();
46 ui->iconLabel->setPixmap(fileIcon.pixmap(22));
47 }
48
49 setWindowTitle(tr("Opening %1").arg(fileName));
50
51 ui->buttonBox->setFocus();
52
53 connect(ui->copyDownloadLink, &ClickableLabel::clicked, this, &DownloadOptionsDialog::copyDownloadLink);
54 connect(this, &QDialog::finished, this, &DownloadOptionsDialog::emitDialogFinished);
55}
56
58{
59 ui->radioExternal->setVisible(show);
60}
61
63{
64 ui->fromFrame->setVisible(show);
65}
66
68{
69 switch (option) {
71 if (!ui->radioExternal->isHidden()) {
72 ui->radioExternal->setChecked(true);
73 break;
74 }
75 // fallthrough
76
78 ui->radioOpen->setChecked(true);
79 break;
80
82 ui->radioSave->setChecked(true);
83 break;
84
85 default:
86 break;
87 }
88}
89
91{
92 int status = QDialog::exec();
93
94 if (status != 0) {
95 if (ui->radioOpen->isChecked()) {
96 status = 1;
97 }
98 else if (ui->radioSave->isChecked()) {
99 status = 2;
100 }
101 else if (ui->radioExternal->isChecked()) {
102 status = 3;
103 }
104 }
105
106 return status;
107}
108
109void DownloadOptionsDialog::copyDownloadLink()
110{
111 QApplication::clipboard()->setText(m_downloadItem->url().toString());
112 ui->copyDownloadLink->setText(tr("Download link copied."));
113}
114
115void DownloadOptionsDialog::emitDialogFinished(int status)
116{
117 if (status != 0) {
118 if (ui->radioOpen->isChecked()) {
119 status = 1;
120 }
121 else if (ui->radioSave->isChecked()) {
122 status = 2;
123 }
124 else if (ui->radioExternal->isChecked()) {
125 status = 3;
126 }
127 }
128
129 m_signalEmited = true;
130 Q_EMIT dialogFinished(status);
131}
132
134{
135 if (!m_signalEmited) {
136 Q_EMIT dialogFinished(-1);
137 }
138
139 delete ui;
140}
void clicked(QPoint)
void showExternalManagerOption(bool show)
void setLastDownloadOption(const DownloadManager::DownloadOption &option)
DownloadOptionsDialog(const QString &fileName, QWebEngineDownloadRequest *downloadItem, QWidget *parent=nullptr)
static IconProvider * instance()
static QIcon standardIcon(QStyle::StandardPixmap icon)
#define QSL(x)
Definition: qzcommon.h:40