Skip to content

Commit cabda3a

Browse files
committed
Plugins::WebBrowser: add bookmark dialog
1 parent c7d7e8d commit cabda3a

File tree

7 files changed

+280
-4
lines changed

7 files changed

+280
-4
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Author: Kang Lin <[email protected]>
2+
3+
#include "FrmAddBookmark.h"
4+
#include "ui_FrmAddBookmark.h"
5+
6+
CFrmAddBookmark::CFrmAddBookmark(CParameterWebBrowser* pPara,
7+
CBookmarkDatabase *db, QWidget *parent)
8+
: QWidget(parent)
9+
, ui(new Ui::CFrmAddBookmark)
10+
, m_pPara(pPara)
11+
, m_pDatabase(db)
12+
{
13+
ui->setupUi(this);
14+
setWindowIcon(QIcon::fromTheme("user-bookmarks"));
15+
16+
if(m_pPara) {
17+
ui->cbSave->setChecked(m_pPara->GetBookmarkShowEditor());
18+
}
19+
}
20+
21+
CFrmAddBookmark::~CFrmAddBookmark()
22+
{
23+
delete ui;
24+
}
25+
26+
void CFrmAddBookmark::on_pbAdd_clicked()
27+
{
28+
if(!m_pPara) return;
29+
m_pPara->SetBookmarkShowEditor(ui->cbSave->isChecked());
30+
close();
31+
}
32+
33+
void CFrmAddBookmark::on_pbCancel_clicked()
34+
{
35+
close();
36+
}
37+
38+
void CFrmAddBookmark::on_pbDelete_clicked()
39+
{
40+
41+
}
42+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Author: Kang Lin <[email protected]>
2+
3+
#pragma once
4+
5+
#include <QWidget>
6+
#include "BookmarkDatabase.h"
7+
#include "ParameterWebBrowser.h"
8+
9+
namespace Ui {
10+
class CFrmAddBookmark;
11+
}
12+
13+
class CFrmAddBookmark : public QWidget
14+
{
15+
Q_OBJECT
16+
17+
public:
18+
explicit CFrmAddBookmark(CParameterWebBrowser* pPara,
19+
CBookmarkDatabase *db, QWidget *parent = nullptr);
20+
~CFrmAddBookmark();
21+
22+
private slots:
23+
void on_pbAdd_clicked();
24+
25+
void on_pbCancel_clicked();
26+
27+
void on_pbDelete_clicked();
28+
29+
private:
30+
Ui::CFrmAddBookmark *ui;
31+
CParameterWebBrowser* m_pPara;
32+
CBookmarkDatabase *m_pDatabase;
33+
};
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>CFrmAddBookmark</class>
4+
<widget class="QWidget" name="CFrmAddBookmark">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Add bookmark</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout_3">
17+
<item row="0" column="0">
18+
<layout class="QHBoxLayout" name="horizontalLayout">
19+
<item>
20+
<widget class="QLabel" name="label">
21+
<property name="text">
22+
<string>Title:</string>
23+
</property>
24+
</widget>
25+
</item>
26+
<item>
27+
<widget class="QLineEdit" name="leTitle"/>
28+
</item>
29+
</layout>
30+
</item>
31+
<item row="1" column="0">
32+
<widget class="QGroupBox" name="groupBox">
33+
<property name="title">
34+
<string>Position:</string>
35+
</property>
36+
<layout class="QGridLayout" name="gridLayout">
37+
<item row="0" column="0">
38+
<widget class="QTreeWidget" name="twFolder">
39+
<column>
40+
<property name="text">
41+
<string notr="true">1</string>
42+
</property>
43+
</column>
44+
</widget>
45+
</item>
46+
</layout>
47+
</widget>
48+
</item>
49+
<item row="2" column="0">
50+
<widget class="QGroupBox" name="groupBox_2">
51+
<property name="title">
52+
<string>Tag:</string>
53+
</property>
54+
<layout class="QGridLayout" name="gridLayout_2">
55+
<item row="0" column="0">
56+
<widget class="QListWidget" name="listWidget"/>
57+
</item>
58+
</layout>
59+
</widget>
60+
</item>
61+
<item row="3" column="0">
62+
<widget class="QCheckBox" name="cbSave">
63+
<property name="text">
64+
<string>Show editor when saving</string>
65+
</property>
66+
</widget>
67+
</item>
68+
<item row="4" column="0">
69+
<layout class="QHBoxLayout" name="horizontalLayout_2">
70+
<item>
71+
<spacer name="horizontalSpacer">
72+
<property name="orientation">
73+
<enum>Qt::Orientation::Horizontal</enum>
74+
</property>
75+
<property name="sizeHint" stdset="0">
76+
<size>
77+
<width>40</width>
78+
<height>20</height>
79+
</size>
80+
</property>
81+
</spacer>
82+
</item>
83+
<item>
84+
<widget class="QPushButton" name="pbDelete">
85+
<property name="text">
86+
<string>Delete</string>
87+
</property>
88+
</widget>
89+
</item>
90+
<item>
91+
<widget class="QPushButton" name="pbAdd">
92+
<property name="text">
93+
<string>Add</string>
94+
</property>
95+
</widget>
96+
</item>
97+
<item>
98+
<widget class="QPushButton" name="pbCancel">
99+
<property name="text">
100+
<string>Cancel</string>
101+
</property>
102+
</widget>
103+
</item>
104+
</layout>
105+
</item>
106+
</layout>
107+
</widget>
108+
<resources/>
109+
<connections/>
110+
</ui>

Plugins/WebBrowser/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ set(WebBrowser_SOURCE_FILES
4242
AddressCompleter.cpp
4343
Bookmark/BookmarkDatabase.cpp
4444
Bookmark/FrmBookmark.cpp
45+
Bookmark/FrmAddBookmark.cpp
4546
)
4647
set(WebBrowser_HEADER_FILES
4748
PluginWebBrowser.h
@@ -63,12 +64,14 @@ set(WebBrowser_HEADER_FILES
6364
AddressCompleter.h
6465
Bookmark/BookmarkDatabase.h
6566
Bookmark/FrmBookmark.h
67+
Bookmark/FrmAddBookmark.h
6668
)
6769
set(WebBrowser_UI_FILES
6870
FrmDownload.ui
6971
DlgSettings.ui
7072
History/FrmHistory.ui
7173
Bookmark/FrmBookmark.ui
74+
Bookmark/FrmAddBookmark.ui
7275
Resource/Resource.qrc
7376
)
7477

Plugins/WebBrowser/FrmWebBrowser.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
#include "FrmPopup.h"
3131
#include "CaptureFullPage.h"
3232
#include "History/FrmHistory.h"
33-
#include "Bookmark/FrmBookmark.h"
3433
#include "AddressCompleter.h"
34+
#include "Bookmark/FrmBookmark.h"
35+
#include "Bookmark/FrmAddBookmark.h"
3536

3637
static Q_LOGGING_CATEGORY(log, "WebBrowser.Browser")
3738
CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, bool bMenuBar, QWidget *parent)
@@ -794,7 +795,7 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
794795
if(pWeb)
795796
pWeb->load(url);
796797
});
797-
pBookmark->show();
798+
RC_SHOW_WINDOW(pBookmark);
798799
});
799800
pMenu->addAction(tr("History"), this, [&]() {
800801
CFrmHistory* pHistory = new CFrmHistory(m_pHistoryDatabase, &m_pPara->m_History);
@@ -815,7 +816,7 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
815816
if(pWeb)
816817
pWeb->load(url);
817818
});
818-
pHistory->show();
819+
RC_SHOW_WINDOW(pHistory);
819820
});
820821

821822
pMenu->addSeparator();
@@ -1295,5 +1296,6 @@ void CFrmWebBrowser::slotRecordTimeout()
12951296

12961297
void CFrmWebBrowser::slotAddBookmark()
12971298
{
1298-
1299+
CFrmAddBookmark* pAdd = new CFrmAddBookmark(m_pPara, m_pBookmarkDatabase);
1300+
RC_SHOW_WINDOW(pAdd);
12991301
}

Plugins/WebBrowser/ParameterWebBrowser.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ CParameterWebBrowser::CParameterWebBrowser(QObject *parent, const QString &szPre
1818
, m_ClearCookie(false)
1919
, m_bPromptPrintFinished(true)
2020
, m_bAutoFillUserAndPassword(false)
21+
, m_nDatabaseViewLimit(100)
22+
, m_WindowSize(600, 450)
23+
, m_nCurrentBookmarkFolder(1)
24+
, m_bBookmarkShowEditor(true)
2125
{
2226
SetHomeUrl("https://github.com/KangLin");
2327
SetTabUrl("https://github.com/KangLin/RabbitRemoteControl");
@@ -52,6 +56,9 @@ int CParameterWebBrowser::OnLoad(QSettings &set)
5256
SetSearchEngineList(set.value("SearchEngine/List", GetSearchEngineList()).toStringList());
5357
SetAutoFillUserAndPassword(set.value("AutoFillUserPassword", GetAutoFillUserAndPassword()).toBool());
5458
SetPromptPrintFinished(set.value("Print/Finished", GetPromptPrintFinished()).toBool());
59+
SetDatabaseViewLimit(set.value("Database/View/Limit", GetDatabaseViewLimit()).toInt());
60+
SetWindowSize(set.value("WindowSize", GetWindowSize()).toSize());
61+
SetBookmarkShowEditor(set.value("Bookmark/ShowEditor", GetBookmarkShowEditor()).toBool());
5562
return nRet;
5663
}
5764

@@ -71,6 +78,9 @@ int CParameterWebBrowser::OnSave(QSettings &set)
7178
set.setValue("SearchEngine/List", GetSearchEngineList());
7279
set.setValue("AutoFillUserPassword", GetAutoFillUserAndPassword());
7380
set.setValue("Print/Finished", GetPromptPrintFinished());
81+
set.setValue("Database/View/Limit", GetDatabaseViewLimit());
82+
set.setValue("WindowSize", GetWindowSize());
83+
set.setValue("Bookmark/ShowEditor", GetBookmarkShowEditor());
7484
return nRet;
7585
}
7686

@@ -259,3 +269,55 @@ void CParameterWebBrowser::SetAutoFillUserAndPassword(bool newAutoFillUserAndPas
259269
m_bAutoFillUserAndPassword = newAutoFillUserAndPassword;
260270
SetModified(true);
261271
}
272+
273+
int CParameterWebBrowser::GetDatabaseViewLimit() const
274+
{
275+
return m_nDatabaseViewLimit;
276+
}
277+
278+
void CParameterWebBrowser::SetDatabaseViewLimit(int newLimit)
279+
{
280+
if(m_nDatabaseViewLimit == newLimit)
281+
return;
282+
m_nDatabaseViewLimit = newLimit;
283+
SetModified(true);
284+
}
285+
286+
QSize CParameterWebBrowser::GetWindowSize() const
287+
{
288+
return m_WindowSize;
289+
}
290+
291+
void CParameterWebBrowser::SetWindowSize(const QSize &newWindowSize)
292+
{
293+
if(m_WindowSize == newWindowSize)
294+
return;
295+
m_WindowSize = newWindowSize;
296+
SetModified(true);
297+
}
298+
299+
int CParameterWebBrowser::GetCurrentBookmarkFolder() const
300+
{
301+
return m_nCurrentBookmarkFolder;
302+
}
303+
304+
void CParameterWebBrowser::SetCurrentBookmarkFolder(int newCurrentBookmarkFolder)
305+
{
306+
if(m_nCurrentBookmarkFolder == newCurrentBookmarkFolder)
307+
return;
308+
m_nCurrentBookmarkFolder = newCurrentBookmarkFolder;
309+
SetModified(true);
310+
}
311+
312+
bool CParameterWebBrowser::GetBookmarkShowEditor() const
313+
{
314+
return m_bBookmarkShowEditor;
315+
}
316+
317+
void CParameterWebBrowser::SetBookmarkShowEditor(bool newBookmarkShowEditor)
318+
{
319+
if(m_bBookmarkShowEditor == newBookmarkShowEditor)
320+
return;
321+
m_bBookmarkShowEditor = newBookmarkShowEditor;
322+
SetModified(true);
323+
}

Plugins/WebBrowser/ParameterWebBrowser.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ class CParameterWebBrowser : public CParameterOperate
8989
private:
9090
bool m_bAutoFillUserAndPassword;
9191

92+
public:
93+
int GetDatabaseViewLimit() const;
94+
void SetDatabaseViewLimit(int newLimit);
95+
private:
96+
int m_nDatabaseViewLimit;
97+
98+
public:
99+
QSize GetWindowSize() const;
100+
void SetWindowSize(const QSize &newWindowSize);
101+
private:
102+
QSize m_WindowSize;
103+
104+
public:
105+
int GetCurrentBookmarkFolder() const;
106+
void SetCurrentBookmarkFolder(int newCurrentBookmarkFolder);
107+
private:
108+
int m_nCurrentBookmarkFolder;
109+
110+
public:
111+
bool GetBookmarkShowEditor() const;
112+
void SetBookmarkShowEditor(bool newBookmarkShowEditor);
113+
private:
114+
bool m_bBookmarkShowEditor;
115+
92116
// CParameter interface
93117
protected:
94118
virtual int OnLoad(QSettings &set) override;

0 commit comments

Comments
 (0)