Skip to content

Commit 4f695c7

Browse files
committed
Plugins::WebBrowser: add history
1 parent 0cfbed9 commit 4f695c7

File tree

15 files changed

+801
-7
lines changed

15 files changed

+801
-7
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: 9 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+
HistoryListWidget.cpp
39+
History.cpp
40+
HistoryDatabase.cpp
41+
HistoryModel.cpp
3842
)
3943
set(WebBrowser_HEADER_FILES
4044
PluginWebBrowser.h
@@ -49,6 +53,10 @@ set(WebBrowser_HEADER_FILES
4953
PasswordStore.h
5054
CaptureFullPage.h
5155
MultimediaRecord.h
56+
HistoryListWidget.h
57+
History.h
58+
HistoryDatabase.h
59+
HistoryModel.h
5260
)
5361
set(WebBrowser_UI_FILES
5462
FrmDownload.ui

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: 40 additions & 1 deletion
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 "HistoryListWidget.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()
@@ -552,6 +580,17 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
552580
m_pStop->setEnabled(false);
553581
m_pStop->setShortcuts(QKeySequence::Cancel);
554582
m_pStop->setStatusTip(m_pStop->text());
583+
584+
pMenu->addSeparator();
585+
pMenu->addAction(tr("History"), this, [&](){
586+
CHistoryListWidget* pHistory = new CHistoryListWidget();
587+
if(!pHistory) return;
588+
pHistory->setAttribute(Qt::WA_DeleteOnClose);
589+
CFrmWebView* pWeb = CurrentView();
590+
if(pWeb)
591+
pHistory->slotSetWebView(pWeb);
592+
pHistory->showNormal();
593+
});
555594

556595
pMenu->addSeparator();
557596
pMenu->addAction(m_pAddPage);

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 "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
};

Plugins/WebBrowser/History.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "History.h"
2+
3+
CHistory::CHistory(QObject *parent)
4+
: QObject{parent}
5+
{}
6+
7+
void CHistory::slotAddUrl(QUrl &url)
8+
{}

Plugins/WebBrowser/History.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef HISTORY_H
2+
#define HISTORY_H
3+
4+
#include <QObject>
5+
6+
class CHistory : public QObject
7+
{
8+
Q_OBJECT
9+
public:
10+
explicit CHistory(QObject *parent = nullptr);
11+
12+
public Q_SLOTS:
13+
void slotAddUrl(QUrl& url);
14+
15+
signals:
16+
};
17+
18+
#endif // HISTORY_H

0 commit comments

Comments
 (0)