3#include <QStandardPaths>
4#include <QLoggingCategory>
5#include <QWebEngineProfile>
6#include "ParameterWebBrowser.h"
7#include "ParameterGlobal.h"
9static Q_LOGGING_CATEGORY(log,
"WebBrowser.Parameter")
13 , m_MediaDevices(
this)
14 , m_bOpenPrevious(
false)
15 , m_bShowDownloadManager(
true)
16 , m_bShowDownloadLocation(
false)
17 , m_ClearHttpCache(
false)
18 , m_ClearCookie(
false)
19 , m_bPromptPrintFinished(
true)
20 , m_bAutoFillUserAndPassword(
false)
21 , m_nDatabaseViewLimit(100)
22 , m_nAddCompleterLines(10)
23 , m_WindowSize(600, 450)
24 , m_nBookmarkCurrentFolder(1)
25 , m_bBookmarkShowEditor(
true)
27 SetHomeUrl(
"https://github.com/KangLin");
28 SetTabUrl(
"https://github.com/KangLin/RabbitRemoteControl");
30 SetDownloadFolder(QWebEngineProfile::defaultProfile()->downloadPath());
31 qDebug(log) <<
"Download folder:" << GetDownloadFolder();
32 if(QLocale::system().language() == QLocale::Language::Chinese)
33 SetSearchEngine(
"https://www.bing.com/search?q=%s");
35 SetSearchEngine(
"https://www.google.com/search?q=%s");
36 SetSearchRelaceString(
"%s");
37 QStringList searchEngines;
38 searchEngines <<
"https://www.bing.com/search?q=%s"
39 <<
"https://www.google.com/search?q=%s"
40 <<
"https://www.baidu.com/s?wd=%s";
41 SetSearchEngineList(searchEngines);
44CParameterWebBrowser::~CParameterWebBrowser()
47int CParameterWebBrowser::OnLoad(QSettings &set)
50 SetHomeUrl(set.value(
"Url/Home", GetHomeUrl()).toString());
51 SetTabUrl(set.value(
"Url/Tab", GetTabUrl()).toString());
52 SetOpenPrevious(set.value(
"OpenPrevious/Enable", GetOpenPrevious()).toBool());
53 SetDownloadFolder(set.value(
"Download/Folder", GetDownloadFolder()).toString());
54 SetShowDownloadManager(set.value(
"Download/Show/Manager", GetShowDownloadManager()).toBool());
55 SetShowDownloadLocation(set.value(
"Download/Show/Location", GetShowDownloadLocation()).toBool());
56 SetClearHttpCache(set.value(
"Clear/HttpCache", GetClearHttpCache()).toBool());
57 SetClearCookie(set.value(
"Clear/Cookie", GetClearCookie()).toBool());
58 SetSearchEngine(set.value(
"SearchEngine", GetSearchEngine()).toString());
59 SetSearchRelaceString(set.value(
"SearchEngine/SearchEngine", GetSearchRelaceString()).toString());
60 SetSearchEngineList(set.value(
"SearchEngine/List", GetSearchEngineList()).toStringList());
61 SetAutoFillUserAndPassword(set.value(
"AutoFillUserPassword", GetAutoFillUserAndPassword()).toBool());
62 SetPromptPrintFinished(set.value(
"Print/Finished", GetPromptPrintFinished()).toBool());
63 SetDatabaseViewLimit(set.value(
"Database/View/Limit", GetDatabaseViewLimit()).toInt());
64 SetAddCompleterLines(set.value(
"AddCompleter/Lines", GetAddCompleterLines()).toInt());
65 SetWindowSize(set.value(
"WindowSize", GetWindowSize()).toSize());
66 SetBookmarkShowEditor(set.value(
"Bookmark/ShowEditor", GetBookmarkShowEditor()).toBool());
67 SetBookmarkCurrentFolder(set.value(
"Bookmark/CurrentFolder", GetBookmarkCurrentFolder()).toInt());
71int CParameterWebBrowser::OnSave(QSettings &set)
74 set.setValue(
"Url/Home", GetHomeUrl());
75 set.setValue(
"Url/Tab", GetTabUrl());
76 set.setValue(
"OpenPrevious/Enable", GetOpenPrevious());
77 set.setValue(
"Download/Folder", GetDownloadFolder());
78 set.setValue(
"Download/Show/Manager", GetShowDownloadManager());
79 set.setValue(
"Download/Show/Location", GetShowDownloadLocation());
80 set.setValue(
"Clear/HttpCache", GetClearHttpCache());
81 set.setValue(
"Clear/Cookie", GetClearCookie());
82 set.setValue(
"SearchEngine", GetSearchEngine());
83 set.setValue(
"SearchEngine/SearchEngine", GetSearchRelaceString());
84 set.setValue(
"SearchEngine/List", GetSearchEngineList());
85 set.setValue(
"AutoFillUserPassword", GetAutoFillUserAndPassword());
86 set.setValue(
"Print/Finished", GetPromptPrintFinished());
87 set.setValue(
"Database/View/Limit", GetDatabaseViewLimit());
88 set.setValue(
"AddCompleter/Lines", GetAddCompleterLines());
89 set.setValue(
"WindowSize", GetWindowSize());
90 set.setValue(
"Bookmark/ShowEditor", GetBookmarkShowEditor());
91 set.setValue(
"Bookmark/CurrentFolder", GetBookmarkCurrentFolder());
95void CParameterWebBrowser::slotSetGlobalParameters()
99 QString szErr =
"The CParameterClient is null";
100 qCritical(log) << szErr;
101 Q_ASSERT_X(
false,
"CParameterWebBrowser", szErr.toStdString().c_str());
104 m_Record = pPlugin->m_Record;
105 m_MediaDevices = pPlugin->m_MediaDevices;
107 auto pg = pPlugin->GetGlobalParameters();
108 bool bRet = m_HistoryDatabase.
SetDatabase(&pg->m_DatabaseRemote);
110 bRet = m_BookmarkDatabase.
SetDatabase(&pg->m_DatabaseRemote);
114QString CParameterWebBrowser::GetHomeUrl()
119int CParameterWebBrowser::SetHomeUrl(
const QString& url)
121 if(m_szHomeUrl == url)
128QString CParameterWebBrowser::GetTabUrl()
133int CParameterWebBrowser::SetTabUrl(
const QString& url)
135 if(m_szTabUrl == url)
142bool CParameterWebBrowser::GetOpenPrevious()
144 return m_bOpenPrevious;
147void CParameterWebBrowser::SetOpenPrevious(
bool bOpen)
149 if(m_bOpenPrevious == bOpen)
151 m_bOpenPrevious = bOpen;
155QString CParameterWebBrowser::GetDownloadFolder()
157 return m_szDownloadFolder;
160int CParameterWebBrowser::SetDownloadFolder(
const QString& folder)
162 if(m_szDownloadFolder == folder)
164 m_szDownloadFolder = folder;
166 emit sigDownloadFolderChanged();
170bool CParameterWebBrowser::GetShowDownloadManager()
const
172 return m_bShowDownloadManager;
175void CParameterWebBrowser::SetShowDownloadManager(
bool newShowDownloadManager)
177 if(m_bShowDownloadManager == newShowDownloadManager)
179 m_bShowDownloadManager = newShowDownloadManager;
183bool CParameterWebBrowser::GetShowDownloadLocation()
const
185 return m_bShowDownloadLocation;
188void CParameterWebBrowser::SetShowDownloadLocation(
bool newShowDownloadLocation)
190 if(m_bShowDownloadLocation == newShowDownloadLocation)
192 m_bShowDownloadLocation = newShowDownloadLocation;
196bool CParameterWebBrowser::GetClearCookie()
const
198 return m_ClearCookie;
201void CParameterWebBrowser::SetClearCookie(
bool newClearCookie)
203 if(m_ClearCookie == newClearCookie)
205 m_ClearCookie = newClearCookie;
209bool CParameterWebBrowser::GetClearHttpCache()
const
211 return m_ClearHttpCache;
214void CParameterWebBrowser::SetClearHttpCache(
bool newClearHttpCache)
216 if(m_ClearHttpCache == newClearHttpCache)
218 m_ClearHttpCache = newClearHttpCache;
222QString CParameterWebBrowser::GetSearchEngine()
const
224 return m_szSearchEngine;
227void CParameterWebBrowser::SetSearchEngine(
const QString &newSearchEngine)
229 if(m_szSearchEngine == newSearchEngine)
231 m_szSearchEngine = newSearchEngine;
235QString CParameterWebBrowser::GetSearchRelaceString()
const
237 return m_szSearchRelaceString;
240void CParameterWebBrowser::SetSearchRelaceString(
const QString &newSearchRelaceString)
242 if(m_szSearchRelaceString == newSearchRelaceString)
244 m_szSearchRelaceString = newSearchRelaceString;
248QStringList CParameterWebBrowser::GetSearchEngineList()
const
250 return m_SearchEngineList;
253void CParameterWebBrowser::SetSearchEngineList(
const QStringList &newSearchEngineList)
255 if(m_SearchEngineList == newSearchEngineList)
257 m_SearchEngineList = newSearchEngineList;
261bool CParameterWebBrowser::GetPromptPrintFinished()
const
263 return m_bPromptPrintFinished;
266void CParameterWebBrowser::SetPromptPrintFinished(
bool newPromptPrintFinished)
268 if(m_bPromptPrintFinished == newPromptPrintFinished)
270 m_bPromptPrintFinished = newPromptPrintFinished;
274bool CParameterWebBrowser::GetAutoFillUserAndPassword()
const
276 return m_bAutoFillUserAndPassword;
279void CParameterWebBrowser::SetAutoFillUserAndPassword(
bool newAutoFillUserAndPassword)
281 if(m_bAutoFillUserAndPassword == newAutoFillUserAndPassword)
283 m_bAutoFillUserAndPassword = newAutoFillUserAndPassword;
287int CParameterWebBrowser::GetDatabaseViewLimit()
const
289 return m_nDatabaseViewLimit;
292void CParameterWebBrowser::SetDatabaseViewLimit(
int newLimit)
294 if(m_nDatabaseViewLimit == newLimit)
296 m_nDatabaseViewLimit = newLimit;
300int CParameterWebBrowser::GetAddCompleterLines()
const
302 return m_nAddCompleterLines;
305void CParameterWebBrowser::SetAddCompleterLines(
int newAddCompleterLines)
307 if(m_nAddCompleterLines == newAddCompleterLines)
309 m_nAddCompleterLines = newAddCompleterLines;
313QSize CParameterWebBrowser::GetWindowSize()
const
318void CParameterWebBrowser::SetWindowSize(
const QSize &newWindowSize)
320 if(m_WindowSize == newWindowSize)
322 m_WindowSize = newWindowSize;
326int CParameterWebBrowser::GetBookmarkCurrentFolder()
const
328 return m_nBookmarkCurrentFolder;
331void CParameterWebBrowser::SetBookmarkCurrentFolder(
int newCurrentBookmarkFolder)
333 if(m_nBookmarkCurrentFolder == newCurrentBookmarkFolder)
335 m_nBookmarkCurrentFolder = newCurrentBookmarkFolder;
339bool CParameterWebBrowser::GetBookmarkShowEditor()
const
341 return m_bBookmarkShowEditor;
344void CParameterWebBrowser::SetBookmarkShowEditor(
bool newBookmarkShowEditor)
346 if(m_bBookmarkShowEditor == newBookmarkShowEditor)
348 m_bBookmarkShowEditor = newBookmarkShowEditor;
bool SetDatabase(const CDatabase *db)
Share an existing database.
Operational parameter interface.
CParameterPlugin * GetGlobalParameters()
Get CParameterPlugin.
Global parameters of plugins.
int SetModified(bool bModified=true)
When setting parameters, if there is a modification, it is called.