Skip to content

Commit 2491b84

Browse files
committed
Plugins::WebBrowser: add history
1 parent 0cfbed9 commit 2491b84

19 files changed

+1297
-18
lines changed

Plugins/FtpServer/ParameterFtpServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CParameterFtpServer::CParameterFtpServer(QObject *parent, const QString &szPrefi
88
, m_nPort(21)
99
, m_bAnonymousLogin(true)
1010
, m_bReadOnly(true)
11-
, m_ConnectCount(-1)
11+
, m_ConnectCount(2)
1212
, m_bListenAll(true)
1313
{}
1414

Plugins/WebBrowser/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(CMAKE_AUTORCC ON)
99
set(CMAKE_CXX_STANDARD 17)
1010
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1111

12-
set(WebBrowser_QT_COMPONENTS Core Gui Widgets WebEngineWidgets WebEngineCore)
12+
set(WebBrowser_QT_COMPONENTS Core Gui Widgets WebEngineWidgets WebEngineCore Sql)
1313
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${WebBrowser_QT_COMPONENTS})
1414
if(Qt${QT_VERSION_MAJOR}_FOUND)
1515
FOREACH(_COMPONENT ${WebBrowser_QT_COMPONENTS})
@@ -35,6 +35,10 @@ set(WebBrowser_SOURCE_FILES
3535
PasswordStore.cpp
3636
CaptureFullPage.cpp
3737
MultimediaRecord.cpp
38+
History/FrmHistory.cpp
39+
History/HistoryDatabase.cpp
40+
History/HistoryModel.cpp
41+
History/ParameterHistory.cpp
3842
)
3943
set(WebBrowser_HEADER_FILES
4044
PluginWebBrowser.h
@@ -49,11 +53,16 @@ set(WebBrowser_HEADER_FILES
4953
PasswordStore.h
5054
CaptureFullPage.h
5155
MultimediaRecord.h
56+
History/FrmHistory.h
57+
History/HistoryDatabase.h
58+
History/HistoryModel.h
59+
History/ParameterHistory.h
5260
)
5361
set(WebBrowser_UI_FILES
5462
FrmDownload.ui
5563
DlgSettings.ui
5664
DlgWebAuth.ui
65+
History/FrmHistory.ui
5766
Resource/Resource.qrc
5867
)
5968
if(QT_VERSION GREATER_EQUAL "6.7.0")

Plugins/WebBrowser/FrmDownloadManager.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#ifndef FRMDOWNLOADMANAGER_H
2-
#define FRMDOWNLOADMANAGER_H
1+
// Author: Kang Lin <[email protected]>
32

3+
#pragma once
44
#include <QWidget>
55
#include <QVBoxLayout>
66
#include "FrmDownload.h"
@@ -30,5 +30,3 @@ private Q_SLOTS:
3030
QVBoxLayout* m_pItems;
3131
CParameterWebBrowser* m_pPara;
3232
};
33-
34-
#endif // FRMDOWNLOADMANAGER_H

Plugins/WebBrowser/FrmPopup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Author: Kang Lin <[email protected]>
12

23
#include <QIcon>
34
#include <QVBoxLayout>

Plugins/WebBrowser/FrmWebBrowser.cpp

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "FrmWebBrowser.h"
3030
#include "FrmPopup.h"
3131
#include "CaptureFullPage.h"
32+
#include "History/FrmHistory.h"
3233

3334
static Q_LOGGING_CATEGORY(log, "WebBrowser.Browser")
3435
CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, bool bMenuBar, QWidget *parent)
@@ -65,6 +66,7 @@ CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, bool bMenuBar, QWidg
6566
, m_pCaptureFulPage(nullptr)
6667
, m_pRecord(nullptr)
6768
, m_pMultimediaRecord(nullptr)
69+
, m_pHistoryDatabase(nullptr)
6870
{
6971
qDebug(log) << Q_FUNC_INFO;
7072
bool check = false;
@@ -227,6 +229,17 @@ CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, bool bMenuBar, QWidg
227229

228230
check = connect(&m_tmRecord, &QTimer::timeout, this, &CFrmWebBrowser::slotRecordTimeout);
229231
Q_ASSERT(check);
232+
233+
m_pHistoryDatabase = new CHistoryDatabase(this);
234+
if(m_pHistoryDatabase) {
235+
QString szDb = GetProfile()->persistentStoragePath()
236+
+ QDir::separator() + "History.db";
237+
bool bRet = m_pHistoryDatabase->openDatabase(szDb);
238+
if(!bRet) {
239+
delete m_pHistoryDatabase;
240+
m_pHistoryDatabase = nullptr;
241+
}
242+
}
230243
}
231244

232245
CFrmWebBrowser::~CFrmWebBrowser()
@@ -343,10 +356,13 @@ void CFrmWebBrowser::SetConnect(CFrmWebView* pWeb)
343356
}
344357
});
345358
check = connect(pWeb, &QWebEngineView::urlChanged,
346-
this, [&](const QUrl &url){
359+
this, [&](const QUrl &url) {
347360
CFrmWebView* pWeb = qobject_cast<CFrmWebView*>(sender());
348361
if(IsCurrentView(pWeb))
349362
m_pUrlLineEdit->setText(url.toString());
363+
if(m_pHistoryDatabase) {
364+
m_pHistoryDatabase->addHistoryEntry(url.toString(), "");
365+
}
350366
});
351367
Q_ASSERT(check);
352368
check = connect(pWeb, &CFrmWebView::titleChanged,
@@ -359,6 +375,9 @@ void CFrmWebBrowser::SetConnect(CFrmWebView* pWeb)
359375
setWindowTitle(title);
360376
emit sigUpdateTitle();
361377
}
378+
if(m_pHistoryDatabase) {
379+
m_pHistoryDatabase->addHistoryEntry(pWeb->url().toString(), title);
380+
}
362381
});
363382
Q_ASSERT(check);
364383
check = connect(pWeb, &CFrmWebView::favIconChanged,
@@ -442,7 +461,16 @@ QWebEngineProfile* CFrmWebBrowser::GetProfile(bool offTheRecord)
442461
bool check = connect(m_profile.get(), &QWebEngineProfile::downloadRequested,
443462
&m_DownloadManager, &CFrmDownloadManager::slotDownloadRequested);
444463
Q_ASSERT(check);
464+
//m_profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
465+
//m_profile->setPersistentStoragePath(m_profile->cachePath() + QDir::separator() + "Persistent");
466+
//m_profile->setHttpCacheMaximumSize(50);
445467
qDebug(log) << "User agent:" << m_profile->httpUserAgent()
468+
#if QT_VERSION > QT_VERSION_CHECK(6, 8, 0)
469+
//<< "AllPermissions:" << m_profile->listAllPermissions()
470+
<< "persistentPermissionsPolicy:" << m_profile->persistentPermissionsPolicy()
471+
#endif
472+
<< "persistentCookiesPolicy:" << m_profile->persistentCookiesPolicy()
473+
<< "httpCacheMaximumSize:" << m_profile->httpCacheMaximumSize()
446474
<< "Persistent path:" << m_profile->persistentStoragePath()
447475
<< "Cache path:" << m_profile->cachePath()
448476
<< "Storage name:" << m_profile->storageName()
@@ -544,7 +572,7 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
544572
pMenu->addAction(m_pForward);
545573
pMenu->addAction(m_pRefresh);
546574
m_pStop = pMenu->addAction(
547-
QIcon::fromTheme("media-playback-stop"), tr("Stop"), this, [&](){
575+
QIcon::fromTheme("media-playback-stop"), tr("Stop"), this, [&]() {
548576
CFrmWebView* pWeb = CurrentView();
549577
if(pWeb && pWeb->page())
550578
pWeb->page()->action(QWebEnginePage::Stop)->trigger();
@@ -553,11 +581,34 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
553581
m_pStop->setShortcuts(QKeySequence::Cancel);
554582
m_pStop->setStatusTip(m_pStop->text());
555583

584+
pMenu->addSeparator();
585+
pMenu->addAction(tr("History"), this, [&]() {
586+
CFrmHistory* pHistory = new CFrmHistory(m_pHistoryDatabase, &m_pPara->m_History);
587+
if(!pHistory) return;
588+
pHistory->setAttribute(Qt::WA_DeleteOnClose);
589+
connect(this, &CFrmWebBrowser::destroyed, pHistory, &CFrmHistory::close);
590+
connect(pHistory, &CFrmHistory::sigOpenUrl, this, [&](const QString& url) {
591+
CFrmWebView* pWeb = CurrentView();
592+
if(!pWeb) {
593+
pWeb = qobject_cast<CFrmWebView*>(CreateWindow(QWebEnginePage::WebBrowserTab));
594+
}
595+
if(pWeb)
596+
pWeb->load(url);
597+
});
598+
connect(pHistory, &CFrmHistory::sigOpenUrlInNewTab,
599+
this, [&](const QString& url) {
600+
auto pWeb = qobject_cast<CFrmWebView*>(CreateWindow(QWebEnginePage::WebBrowserTab));
601+
if(pWeb)
602+
pWeb->load(url);
603+
});
604+
pHistory->show();
605+
});
606+
556607
pMenu->addSeparator();
557608
pMenu->addAction(m_pAddPage);
558609
m_pAddPageIncognito = pMenu->addAction(
559610
QIcon::fromTheme("add"), tr("Add incognito tab"),
560-
this, [&](){
611+
this, [&]() {
561612
CreateWindow(QWebEnginePage::WebBrowserTab, true);
562613
if(!m_pPara->GetTabUrl().isEmpty()) {
563614
m_pUrlLineEdit->setText(m_pPara->GetTabUrl());
@@ -567,14 +618,14 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
567618
m_pAddPageIncognito->setStatusTip(m_pAddPageIncognito->text());
568619
m_pAddWindow = pMenu->addAction(
569620
QIcon::fromTheme("add"), tr("Add window"),
570-
this, [&](){
621+
this, [&]() {
571622
CreateWindow(QWebEnginePage::WebBrowserWindow);
572623
});
573624
m_pAddWindow->setVisible(false);
574625
m_pAddWindow->setStatusTip(m_pAddWindow->text());
575626
m_pAddWindowIncognito = pMenu->addAction(
576627
QIcon::fromTheme("add"), tr("Add Incognito Window"),
577-
this, [&](){
628+
this, [&]() {
578629
CreateWindow(QWebEnginePage::WebBrowserWindow, true);
579630
});
580631
m_pAddWindowIncognito->setVisible(false);
@@ -583,7 +634,7 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
583634
pMenu->addSeparator();
584635
m_pFind = pMenu->addAction(
585636
QIcon::fromTheme("edit-find"), tr("&Find"), this,
586-
[&](){
637+
[&]() {
587638
CFrmWebView* pWeb = CurrentView();
588639
if(pWeb) {
589640
bool ok = false;

Plugins/WebBrowser/FrmWebBrowser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "FrmDownloadManager.h"
1717
#include "ParameterWebBrowser.h"
1818
#include "MultimediaRecord.h"
19+
#include "History/HistoryDatabase.h"
1920

2021
class CFrmWebBrowser : public QWidget
2122
{
@@ -125,4 +126,6 @@ public Q_SLOTS:
125126

126127
CMultimediaRecordThread* m_pMultimediaRecord;
127128
QTimer m_tmRecord;
129+
130+
CHistoryDatabase* m_pHistoryDatabase;
128131
};

0 commit comments

Comments
 (0)