Skip to content

Commit f5ccf0c

Browse files
committed
Plugins::WebBrowser: modify download parameters
1 parent 1373fe1 commit f5ccf0c

File tree

7 files changed

+156
-42
lines changed

7 files changed

+156
-42
lines changed

Plugins/WebBrowser/DlgSettings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ CDlgSettings::CDlgSettings(CParameterWebBrowser *para, QWidget *parent)
2020
else
2121
ui->leTabUrl->setText(m_pPara->GetTabUrl());
2222
ui->leDownloadFolder->setText(m_pPara->GetDownloadFolder());
23+
ui->cbDownloadShowWindow->setChecked(m_pPara->GetShowDownloadManager());
24+
ui->cbDownloadSave->setChecked(m_pPara->GetShowDownloadLocation());
2325
ui->cbOpenPreious->setChecked(m_pPara->GetOpenPrevious());
2426

2527
m_pSearchModel = new QStandardItemModel(this);
@@ -47,6 +49,8 @@ void CDlgSettings::accept()
4749
m_pPara->SetHomeUrl(ui->leHomeUrl->text());
4850
m_pPara->SetTabUrl(ui->leTabUrl->text());
4951
m_pPara->SetDownloadFolder(ui->leDownloadFolder->text());
52+
m_pPara->SetShowDownloadManager(ui->cbDownloadShowWindow->isChecked());
53+
m_pPara->SetShowDownloadLocation(ui->cbDownloadSave->isChecked());
5054
m_pPara->SetOpenPrevious(ui->cbOpenPreious->isChecked());
5155
auto index = ui->lstSearchEngine->currentIndex();
5256
if(index.isValid()) {

Plugins/WebBrowser/DlgSettings.ui

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>400</width>
10-
<height>300</height>
9+
<width>454</width>
10+
<height>356</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Dialog</string>
1515
</property>
16-
<layout class="QGridLayout" name="gridLayout">
16+
<layout class="QGridLayout" name="gridLayout_4">
1717
<item row="0" column="0">
1818
<widget class="QTabWidget" name="tabWidget">
1919
<property name="currentIndex">
20-
<number>1</number>
20+
<number>0</number>
2121
</property>
2222
<widget class="QWidget" name="General">
2323
<attribute name="title">
@@ -67,25 +67,70 @@
6767
</layout>
6868
</item>
6969
<item row="3" column="0">
70-
<layout class="QHBoxLayout" name="horizontalLayout_3">
71-
<item>
72-
<widget class="QLabel" name="label_3">
73-
<property name="text">
74-
<string>Download folder:</string>
75-
</property>
76-
</widget>
77-
</item>
78-
<item>
79-
<widget class="QLineEdit" name="leDownloadFolder"/>
80-
</item>
81-
<item>
82-
<widget class="QPushButton" name="pbDownloadFolder">
83-
<property name="text">
84-
<string>Browser</string>
85-
</property>
86-
</widget>
87-
</item>
88-
</layout>
70+
<widget class="QGroupBox" name="groupBox">
71+
<property name="title">
72+
<string>Download</string>
73+
</property>
74+
<layout class="QGridLayout" name="gridLayout">
75+
<item row="0" column="0">
76+
<layout class="QHBoxLayout" name="horizontalLayout_3">
77+
<item>
78+
<widget class="QLabel" name="label_3">
79+
<property name="text">
80+
<string>Download folder:</string>
81+
</property>
82+
</widget>
83+
</item>
84+
<item>
85+
<widget class="QLineEdit" name="leDownloadFolder">
86+
<property name="sizePolicy">
87+
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
88+
<horstretch>0</horstretch>
89+
<verstretch>0</verstretch>
90+
</sizepolicy>
91+
</property>
92+
</widget>
93+
</item>
94+
<item>
95+
<widget class="QPushButton" name="pbDownloadFolder">
96+
<property name="sizePolicy">
97+
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
98+
<horstretch>0</horstretch>
99+
<verstretch>0</verstretch>
100+
</sizepolicy>
101+
</property>
102+
<property name="text">
103+
<string>Browser</string>
104+
</property>
105+
</widget>
106+
</item>
107+
</layout>
108+
</item>
109+
<item row="1" column="0">
110+
<widget class="QCheckBox" name="cbDownloadShowWindow">
111+
<property name="text">
112+
<string>Always show the download manager window</string>
113+
</property>
114+
</widget>
115+
</item>
116+
<item row="2" column="0">
117+
<widget class="QCheckBox" name="cbDownloadSave">
118+
<property name="toolTip">
119+
<string>Always show the option to choose the download save location.</string>
120+
</property>
121+
<property name="statusTip">
122+
<string>Always show the option to choose the download save location.</string>
123+
</property>
124+
<property name="whatsThis">
125+
<string>Always show the option to choose the download save location.</string>
126+
</property>
127+
<property name="text">
128+
<string>Always ask for the download file save location</string>
129+
</property>
130+
</widget>
131+
</item>
132+
</layout>
133+
</widget>
89134
</item>
90135
<item row="4" column="0">
91136
<widget class="QCheckBox" name="cbOpenPreious">
@@ -94,10 +139,10 @@
94139
</property>
95140
</widget>
96141
</item>
97-
<item row="5" column="0">
142+
<item row="6" column="0">
98143
<spacer name="verticalSpacer">
99144
<property name="orientation">
100-
<enum>Qt::Orientation::Vertical</enum>
145+
<enum>Qt::Vertical</enum>
101146
</property>
102147
<property name="sizeHint" stdset="0">
103148
<size>
@@ -122,7 +167,7 @@
122167
<item>
123168
<spacer name="horizontalSpacer">
124169
<property name="orientation">
125-
<enum>Qt::Orientation::Horizontal</enum>
170+
<enum>Qt::Horizontal</enum>
126171
</property>
127172
<property name="sizeHint" stdset="0">
128173
<size>
@@ -177,10 +222,10 @@
177222
<item row="1" column="0">
178223
<widget class="QDialogButtonBox" name="buttonBox">
179224
<property name="orientation">
180-
<enum>Qt::Orientation::Horizontal</enum>
225+
<enum>Qt::Horizontal</enum>
181226
</property>
182227
<property name="standardButtons">
183-
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
228+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
184229
</property>
185230
</widget>
186231
</item>

Plugins/WebBrowser/FrmDownload.ui

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>186</width>
10-
<height>93</height>
10+
<height>95</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -28,7 +28,7 @@
2828
</sizepolicy>
2929
</property>
3030
<property name="text">
31-
<string>TextLabel</string>
31+
<string>Title</string>
3232
</property>
3333
</widget>
3434
</item>
@@ -51,7 +51,7 @@
5151
<item row="2" column="0">
5252
<widget class="QLabel" name="lbFileInfo">
5353
<property name="text">
54-
<string>TextLabel</string>
54+
<string>File Information</string>
5555
</property>
5656
</widget>
5757
</item>

Plugins/WebBrowser/FrmDownloadManager.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Author: Kang Lin <[email protected]>
22

3+
#include <QFileDialog>
34
#include <QLoggingCategory>
45
#include <QScrollArea>
56
#include <QUrl>
@@ -20,9 +21,9 @@ CFrmDownloadManager::CFrmDownloadManager(CParameterWebBrowser *para, QWidget *pa
2021
auto scroll = new QScrollArea(this);
2122
scroll->setWidgetResizable(true);
2223
layout->addWidget(scroll);
23-
QWidget *pWin = new QWidget(this);
24+
QWidget *pWin = new QWidget(scroll);
2425
scroll->setWidget(pWin);
25-
m_pItems = new QVBoxLayout(this);
26+
m_pItems = new QVBoxLayout(pWin);
2627
pWin->setLayout (m_pItems);
2728
m_pItems->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
2829
resize(600, 300);
@@ -35,18 +36,32 @@ CFrmDownloadManager::~CFrmDownloadManager()
3536

3637
void CFrmDownloadManager::slotDownloadRequested(QWebEngineDownloadRequest *download)
3738
{
39+
qDebug(log) << Q_FUNC_INFO;
3840
Q_ASSERT(download && download->state() == QWebEngineDownloadRequest::DownloadRequested);
41+
QString szPath;
42+
szPath = m_pPara->GetDownloadFolder();
43+
if(m_pPara->GetShowDownloadLocation()) {
44+
szPath = QFileDialog::getExistingDirectory(this, tr("Save as ......"), szPath);
45+
if(szPath.isEmpty())
46+
return;
47+
}
48+
3949
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
40-
download->setDownloadDirectory(m_pPara->GetDownloadFolder());
50+
download->setDownloadDirectory(szPath);
4151
qDebug(log) << "slotDownloadRequested:" << download->downloadDirectory() << download->downloadFileName() << download->url();
4252
#else
4353
QFileInfo fi(download->path());
44-
download->setPath(m_pPara->GetDownloadFolder() + QDir::separator() + fi.fileName());
54+
download->setPath(szPath + QDir::separator() + fi.fileName());
4555
qDebug(log) << "slotDownloadRequested:" << download->path() << download->url();
4656
#endif
4757
auto pDownload = new CFrmDownload(download);
4858
Add(pDownload);
49-
show();
59+
if(m_pPara) {
60+
if(m_pPara->GetShowDownloadManager()) {
61+
show();
62+
activateWindow();
63+
}
64+
}
5065
}
5166

5267
void CFrmDownloadManager::Add(CFrmDownload *item)

Plugins/WebBrowser/FrmWebBrowser.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, QWidget *parent)
130130
});
131131
m_pAddPage->setStatusTip(m_pAddPage->text());
132132
Q_ASSERT(check);
133-
m_pDownload = m_pToolBar->addAction(QIcon::fromTheme("emblem-downloads"), tr("Download Manager"));
133+
m_pDownload = m_pToolBar->addAction(
134+
QIcon::fromTheme("emblem-downloads"), tr("Download Manager"));
134135
m_pDownload->setCheckable(true);
135136
m_pDownload->setStatusTip(m_pDownload->text());
136137
check = connect(m_pDownload, &QAction::toggled,
@@ -173,8 +174,9 @@ CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, QWidget *parent)
173174
Q_ASSERT(check);
174175

175176
m_DownloadManager.hide();
176-
QObject::connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested,
177+
check = connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested,
177178
&m_DownloadManager, &CFrmDownloadManager::slotDownloadRequested);
179+
Q_ASSERT(check);
178180
}
179181

180182
CFrmWebBrowser::~CFrmWebBrowser()
@@ -330,12 +332,15 @@ QWebEngineProfile* CFrmWebBrowser::GetProfile(bool offTheRecord)
330332
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
331333
g_profile->settings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false);
332334
#endif
333-
QObject::connect(g_profile.get(), &QWebEngineProfile::downloadRequested,
334-
&m_DownloadManager, &CFrmDownloadManager::slotDownloadRequested);
335-
qDebug(log) << "Persistent path:" << g_profile->persistentStoragePath()
335+
bool check = connect(g_profile.get(), &QWebEngineProfile::downloadRequested,
336+
&m_DownloadManager, &CFrmDownloadManager::slotDownloadRequested);
337+
Q_ASSERT(check);
338+
qDebug(log) << "User agent:" << g_profile->httpUserAgent()
339+
<< "Persistent path:" << g_profile->persistentStoragePath()
336340
<< "Cache path:" << g_profile->cachePath()
337341
<< "Storage name:" << g_profile->storageName()
338-
<< "Is off the Record:" << g_profile->isOffTheRecord();
342+
<< "Is off the Record:" << g_profile->isOffTheRecord()
343+
<< "Download:" << g_profile->downloadPath();
339344
}
340345
return offTheRecord ? QWebEngineProfile::defaultProfile() : g_profile.get();
341346
}

Plugins/WebBrowser/ParameterWebBrowser.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ static Q_LOGGING_CATEGORY(log, "WebBrowser.Parameter")
88
CParameterWebBrowser::CParameterWebBrowser(QObject *parent, const QString &szPrefix)
99
: CParameterOperate{parent, szPrefix}
1010
, m_bOpenPrevious(false)
11+
, m_bShowDownloadManager(false)
12+
, m_bShowDownloadLocation(false)
1113
{
1214
m_szDownloadFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
1315
SetSearchEngine("https://cn.bing.com/search?q=%s");
@@ -28,6 +30,8 @@ int CParameterWebBrowser::OnLoad(QSettings &set)
2830
SetTabUrl(set.value("Url/Tab", GetTabUrl()).toString());
2931
SetOpenPrevious(set.value("OpenPrevious/Enable", GetOpenPrevious()).toBool());
3032
SetDownloadFolder(set.value("Download/Folder", GetDownloadFolder()).toString());
33+
SetShowDownloadManager(set.value("Download/Show/Manager", GetShowDownloadManager()).toBool());
34+
SetShowDownloadLocation(set.value("Download/Show/Location", GetShowDownloadLocation()).toBool());
3135
SetSearchEngine(set.value("SearchEngine", GetSearchEngine()).toString());
3236
SetSearchRelaceString(set.value("SearchEngine/SearchEngine", GetSearchRelaceString()).toString());
3337
SetSearchEngineList(set.value("SearchEngine/List", GetSearchEngineList()).toStringList());
@@ -41,6 +45,8 @@ int CParameterWebBrowser::OnSave(QSettings &set)
4145
set.setValue("Url/Tab", GetTabUrl());
4246
set.setValue("OpenPrevious/Enable", GetOpenPrevious());
4347
set.setValue("Download/Folder", GetDownloadFolder());
48+
set.setValue("Download/Show/Manager", GetShowDownloadManager());
49+
set.setValue("Download/Show/Location", GetShowDownloadLocation());
4450
set.setValue("SearchEngine", GetSearchEngine());
4551
set.setValue("SearchEngine/SearchEngine", GetSearchRelaceString());
4652
set.setValue("SearchEngine/List", GetSearchEngineList());
@@ -106,6 +112,32 @@ int CParameterWebBrowser::SetDownloadFolder(const QString& folder)
106112
return 0;
107113
}
108114

115+
bool CParameterWebBrowser::GetShowDownloadManager() const
116+
{
117+
return m_bShowDownloadManager;
118+
}
119+
120+
void CParameterWebBrowser::SetShowDownloadManager(bool newShowDownloadManager)
121+
{
122+
if(m_bShowDownloadManager == newShowDownloadManager)
123+
return;
124+
m_bShowDownloadManager = newShowDownloadManager;
125+
SetModified(true);
126+
}
127+
128+
bool CParameterWebBrowser::GetShowDownloadLocation() const
129+
{
130+
return m_bShowDownloadLocation;
131+
}
132+
133+
void CParameterWebBrowser::SetShowDownloadLocation(bool newShowDownloadLocation)
134+
{
135+
if(m_bShowDownloadLocation == newShowDownloadLocation)
136+
return;
137+
m_bShowDownloadLocation = newShowDownloadLocation;
138+
SetModified(true);
139+
}
140+
109141
QString CParameterWebBrowser::GetSearchEngine() const
110142
{
111143
return m_szSearchEngine;

Plugins/WebBrowser/ParameterWebBrowser.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,23 @@ class CParameterWebBrowser : public CParameterOperate
2525
void SetOpenPrevious(bool bOpen);
2626
private:
2727
bool m_bOpenPrevious;
28+
2829
public:
2930
QString GetDownloadFolder();
3031
int SetDownloadFolder(const QString& folder);
3132
private:
3233
QString m_szDownloadFolder;
34+
public:
35+
bool GetShowDownloadManager() const;
36+
void SetShowDownloadManager(bool newShowDownloadManager);
37+
private:
38+
bool m_bShowDownloadManager;
39+
public:
40+
bool GetShowDownloadLocation() const;
41+
void SetShowDownloadLocation(bool newShowDownloadLocation);
42+
private:
43+
bool m_bShowDownloadLocation;
44+
3345
public:
3446
QString GetSearchEngine() const;
3547
void SetSearchEngine(const QString &newSearchEngine);
@@ -45,6 +57,7 @@ class CParameterWebBrowser : public CParameterOperate
4557
void SetSearchEngineList(const QStringList &newSearchEngineList);
4658
private:
4759
QStringList m_SearchEngineList;
60+
4861
// CParameter interface
4962
protected:
5063
virtual int OnLoad(QSettings &set) override;

0 commit comments

Comments
 (0)