Skip to content

Commit c7d7e8d

Browse files
committed
Plugins::WebBrowser: modify bookmark
1 parent eb074f0 commit c7d7e8d

File tree

4 files changed

+72
-60
lines changed

4 files changed

+72
-60
lines changed

Plugins/WebBrowser/Bookmark/FrmBookmark.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void CFrmBookmark::loadBookmarks()
195195
QStandardItem *pFolderItem = new QStandardItem(folder.getIcon(), folder.title);
196196
if(!pFolderItem) continue;
197197
pFolderItem->setData(folder.id, ID);
198-
pFolderItem->setData(Folder, Type);
198+
pFolderItem->setData(BookmarkType_Folder, Type);
199199
rootItem->appendRow(pFolderItem);
200200
m_folderItems[folder.id] = pFolderItem;
201201
continue;
@@ -209,7 +209,7 @@ void CFrmBookmark::loadBookmarks()
209209
QStandardItem *pFolderItem = new QStandardItem(folder.getIcon(), folder.title);
210210
if(!pFolderItem) continue;
211211
pFolderItem->setData(folder.id, ID);
212-
pFolderItem->setData(Folder, Type);
212+
pFolderItem->setData(BookmarkType_Folder, Type);
213213
(*it)->appendRow(pFolderItem);
214214
m_folderItems[folder.id] = pFolderItem;
215215
}
@@ -227,7 +227,7 @@ void CFrmBookmark::loadBookmarks()
227227

228228
QStandardItem *bookmarkItem = new QStandardItem(bookmark.getIcon(), bookmark.title);
229229
bookmarkItem->setData(bookmark.id, ID);
230-
bookmarkItem->setData(Bookmark, Type);
230+
bookmarkItem->setData(BookmarkType_Bookmark, Type);
231231
bookmarkItem->setData(bookmark.url, Url);
232232

233233
if (bookmark.isFavorite) {
@@ -264,7 +264,7 @@ void CFrmBookmark::onAddBookmark()
264264
QModelIndex currentIndex = m_pTreeView->currentIndex();
265265
if (currentIndex.isValid()) {
266266
int type = currentIndex.data(Type).toInt();
267-
if (Folder == type) {
267+
if (BookmarkType_Folder == type) {
268268
item.folderId = currentIndex.data(Qt::UserRole).toInt();
269269
}
270270
}
@@ -286,7 +286,7 @@ void CFrmBookmark::onAddFolder()
286286
QModelIndex currentIndex = m_pTreeView->currentIndex();
287287
if (currentIndex.isValid()) {
288288
int type = currentIndex.data(Type).toInt();
289-
if (Folder == type) {
289+
if (BookmarkType_Folder == type) {
290290
parentId = currentIndex.data(Qt::UserRole).toInt();
291291
}
292292
}
@@ -304,7 +304,7 @@ void CFrmBookmark::onEditBookmark()
304304
int type = index.data(Type).toInt();
305305
int id = index.data(Qt::UserRole).toInt();
306306

307-
if (Bookmark == type) {
307+
if (BookmarkType_Bookmark == type) {
308308
BookmarkItem item = m_pDatabase->getBookmark(id);
309309
if (item.id == 0) return;
310310

@@ -325,7 +325,7 @@ void CFrmBookmark::onEditBookmark()
325325
if (m_pDatabase->updateBookmark(item)) {
326326
refresh();
327327
}
328-
} else if (Folder == type) {
328+
} else if (BookmarkType_Folder == type) {
329329
QString oldName = index.data(Qt::DisplayRole).toString();
330330

331331
bool ok;
@@ -348,15 +348,15 @@ void CFrmBookmark::onDeleteBookmark()
348348
int type = index.data(Type).toInt();
349349
QString name = index.data(Qt::DisplayRole).toString();
350350
int id = index.data(Qt::UserRole).toInt();
351-
if(1 == id && Folder == type) {
351+
if(1 == id && BookmarkType_Folder == type) {
352352
QMessageBox::warning(this, tr("Warning"), tr("The folder \"%1\" is not delete").arg(name));
353353
return;
354354
}
355355

356356
QString message;
357-
if (Bookmark == type) {
357+
if (BookmarkType_Bookmark == type) {
358358
message = tr("Are you sure you want to delete the bookmark \"%1\"?").arg(name);
359-
} else if (Folder == type) {
359+
} else if (BookmarkType_Folder == type) {
360360
message = tr("Are you sure you want to delete the folder \"%1\"?\n"
361361
"The bookmarks inside the folder will be moved to the root directory.").arg(name);
362362
} else {
@@ -370,9 +370,9 @@ void CFrmBookmark::onDeleteBookmark()
370370
);
371371

372372
if (reply == QMessageBox::Yes) {
373-
if (Bookmark == type) {
373+
if (BookmarkType_Bookmark == type) {
374374
m_pDatabase->deleteBookmark(id);
375-
} else if (Folder == type) {
375+
} else if (BookmarkType_Folder == type) {
376376
m_pDatabase->deleteFolder(id);
377377
}
378378
refresh();
@@ -385,7 +385,7 @@ void CFrmBookmark::onSetFavorite()
385385
if (!index.isValid()) return;
386386

387387
int type = index.data(Type).toInt();
388-
if (type != Bookmark) return;
388+
if (type != BookmarkType_Bookmark) return;
389389

390390
int id = index.data(ID).toInt();
391391
BookmarkItem item = m_pDatabase->getBookmark(id);
@@ -446,7 +446,7 @@ void CFrmBookmark::onSearchTextChanged(const QString &text)
446446
for (const auto &bookmark : bookmarks) {
447447
QStandardItem *item = new QStandardItem(bookmark.getIcon(), bookmark.title);
448448
item->setData(bookmark.id, ID);
449-
item->setData(Bookmark, Type);
449+
item->setData(BookmarkType_Bookmark, Type);
450450
item->setData(bookmark.url, Url);
451451

452452
// 显示路径
@@ -467,7 +467,7 @@ void CFrmBookmark::onSearchTextChanged(const QString &text)
467467
void CFrmBookmark::onTreeViewDoubleClicked(const QModelIndex &index)
468468
{
469469
int type = index.data(Type).toInt();
470-
if (Bookmark == type) {
470+
if (BookmarkType_Bookmark == type) {
471471
QString url = index.data(Url).toString();
472472
if (!url.isEmpty()) {
473473
emit openUrlRequested(url);
@@ -487,7 +487,7 @@ void CFrmBookmark::onCustomContextMenu(const QPoint &pos)
487487
int id = index.data(ID).toInt();
488488
int type = index.data(Type).toInt();
489489

490-
if (Bookmark == type) {
490+
if (BookmarkType_Bookmark == type) {
491491
menu.addAction(QIcon::fromTheme("document-open"), tr("Open"), this, [this, index]() {
492492
QString url = index.data(Url).toString();
493493
if (!url.isEmpty()) {
@@ -502,7 +502,7 @@ void CFrmBookmark::onCustomContextMenu(const QPoint &pos)
502502
connect(favoriteAction, &QAction::triggered, this, &CFrmBookmark::onSetFavorite);
503503

504504
menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"), this, &CFrmBookmark::onDeleteBookmark);
505-
} else if (Folder == type) {
505+
} else if (BookmarkType_Folder == type) {
506506
menu.addAction(QIcon::fromTheme("Add"), tr("Add bookmark"), this, &CFrmBookmark::onAddBookmark);
507507
menu.addAction(QIcon::fromTheme("folder-new"), tr("Add folder"), this, &CFrmBookmark::onAddFolder);
508508
menu.addSeparator();

Plugins/WebBrowser/Bookmark/FrmBookmark.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,11 @@ private slots:
4242
void setupTreeView();
4343
void loadBookmarks();
4444

45-
enum emRole {
45+
enum Role {
4646
ID = Qt::UserRole,
4747
Type,
4848
Url
4949
};
50-
enum emType{
51-
Bookmark,
52-
Folder
53-
};
5450

5551
private:
5652
Ui::CFrmBookmark *ui;

Plugins/WebBrowser/FrmWebBrowser.cpp

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, bool bMenuBar, QWidg
4343
, m_pForward(nullptr)
4444
, m_pRefresh(nullptr)
4545
, m_pStop(nullptr)
46+
, m_pAddBookmark(nullptr)
4647
, m_pFind(nullptr)
4748
, m_pFindNext(nullptr)
4849
, m_pFindPrevious(nullptr)
@@ -189,6 +190,10 @@ CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, bool bMenuBar, QWidg
189190
});
190191
Q_ASSERT(check);
191192

193+
m_pAddBookmark = m_pToolBar->addAction(
194+
QIcon::fromTheme("user-bookmarks"),
195+
tr("Add bookmark"), this, SLOT(slotAddBookmark()));
196+
192197
m_pAddPage = m_pToolBar->addAction(QIcon::fromTheme("add"), tr("Add tab page"),
193198
this, [&](){
194199
CreateWindow(QWebEnginePage::WebBrowserTab);
@@ -615,44 +620,6 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
615620
m_pStop->setShortcuts(QKeySequence::Cancel);
616621
m_pStop->setStatusTip(m_pStop->text());
617622

618-
pMenu->addSeparator();
619-
pMenu->addAction(tr("Bookmark"), this, [&]{
620-
CFrmBookmark* pBookmark = new CFrmBookmark(m_pBookmarkDatabase);
621-
if(!pBookmark) return;
622-
pBookmark->setAttribute(Qt::WA_DeleteOnClose);
623-
connect(this, &CFrmWebBrowser::destroyed, pBookmark, &CFrmBookmark::close);
624-
connect(pBookmark, &CFrmBookmark::openUrlRequested, this, [&](const QString& url) {
625-
CFrmWebView* pWeb = CurrentView();
626-
if(!pWeb) {
627-
pWeb = qobject_cast<CFrmWebView*>(CreateWindow(QWebEnginePage::WebBrowserTab));
628-
}
629-
if(pWeb)
630-
pWeb->load(url);
631-
});
632-
pBookmark->show();
633-
});
634-
pMenu->addAction(tr("History"), this, [&]() {
635-
CFrmHistory* pHistory = new CFrmHistory(m_pHistoryDatabase, &m_pPara->m_History);
636-
if(!pHistory) return;
637-
pHistory->setAttribute(Qt::WA_DeleteOnClose);
638-
connect(this, &CFrmWebBrowser::destroyed, pHistory, &CFrmHistory::close);
639-
connect(pHistory, &CFrmHistory::sigOpenUrl, this, [&](const QString& url) {
640-
CFrmWebView* pWeb = CurrentView();
641-
if(!pWeb) {
642-
pWeb = qobject_cast<CFrmWebView*>(CreateWindow(QWebEnginePage::WebBrowserTab));
643-
}
644-
if(pWeb)
645-
pWeb->load(url);
646-
});
647-
connect(pHistory, &CFrmHistory::sigOpenUrlInNewTab,
648-
this, [&](const QString& url) {
649-
auto pWeb = qobject_cast<CFrmWebView*>(CreateWindow(QWebEnginePage::WebBrowserTab));
650-
if(pWeb)
651-
pWeb->load(url);
652-
});
653-
pHistory->show();
654-
});
655-
656623
pMenu->addSeparator();
657624
pMenu->addAction(m_pAddPage);
658625
m_pAddPageIncognito = pMenu->addAction(
@@ -809,6 +776,48 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
809776
});
810777
}
811778

779+
pMenu->addSeparator();
780+
QMenu* pMenuBookmark = new QMenu(tr("Bookmark"), pMenu);
781+
pMenuBookmark->setIcon(QIcon::fromTheme("user-bookmarks"));
782+
pMenu->addMenu(pMenuBookmark);
783+
pMenuBookmark->addAction(m_pAddBookmark);
784+
pMenuBookmark->addAction(tr("Manage Bookmark "), this, [&]{
785+
CFrmBookmark* pBookmark = new CFrmBookmark(m_pBookmarkDatabase);
786+
if(!pBookmark) return;
787+
pBookmark->setAttribute(Qt::WA_DeleteOnClose);
788+
connect(this, &CFrmWebBrowser::destroyed, pBookmark, &CFrmBookmark::close);
789+
connect(pBookmark, &CFrmBookmark::openUrlRequested, this, [&](const QString& url) {
790+
CFrmWebView* pWeb = CurrentView();
791+
if(!pWeb) {
792+
pWeb = qobject_cast<CFrmWebView*>(CreateWindow(QWebEnginePage::WebBrowserTab));
793+
}
794+
if(pWeb)
795+
pWeb->load(url);
796+
});
797+
pBookmark->show();
798+
});
799+
pMenu->addAction(tr("History"), this, [&]() {
800+
CFrmHistory* pHistory = new CFrmHistory(m_pHistoryDatabase, &m_pPara->m_History);
801+
if(!pHistory) return;
802+
pHistory->setAttribute(Qt::WA_DeleteOnClose);
803+
connect(this, &CFrmWebBrowser::destroyed, pHistory, &CFrmHistory::close);
804+
connect(pHistory, &CFrmHistory::sigOpenUrl, this, [&](const QString& url) {
805+
CFrmWebView* pWeb = CurrentView();
806+
if(!pWeb) {
807+
pWeb = qobject_cast<CFrmWebView*>(CreateWindow(QWebEnginePage::WebBrowserTab));
808+
}
809+
if(pWeb)
810+
pWeb->load(url);
811+
});
812+
connect(pHistory, &CFrmHistory::sigOpenUrlInNewTab,
813+
this, [&](const QString& url) {
814+
auto pWeb = qobject_cast<CFrmWebView*>(CreateWindow(QWebEnginePage::WebBrowserTab));
815+
if(pWeb)
816+
pWeb->load(url);
817+
});
818+
pHistory->show();
819+
});
820+
812821
pMenu->addSeparator();
813822
m_pCapturePage = pMenu->addAction(
814823
QIcon::fromTheme("screen-shot"), tr("Capture page"),
@@ -1284,3 +1293,7 @@ void CFrmWebBrowser::slotRecordTimeout()
12841293
Q_ARG(QImage, image));
12851294
}
12861295

1296+
void CFrmWebBrowser::slotAddBookmark()
1297+
{
1298+
1299+
}

Plugins/WebBrowser/FrmWebBrowser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ private Q_SLOTS:
6868
void slotRecord();
6969
void slotRecordTimeout();
7070

71+
void slotAddBookmark();
72+
7173
public Q_SLOTS:
7274
void slotFullScreen(bool bFullScreen);
7375

@@ -96,6 +98,7 @@ public Q_SLOTS:
9698
QAction* m_pForward;
9799
QAction* m_pRefresh;
98100
QAction* m_pStop;
101+
QAction* m_pAddBookmark;
99102
QAction* m_pFind;
100103
QAction* m_pFindNext;
101104
QAction* m_pFindPrevious;

0 commit comments

Comments
 (0)