From: Soren Stoutner Date: Mon, 30 Oct 2023 22:50:12 +0000 (-0700) Subject: Update bookmarks in all windows when modified. https://redmine.stoutner.com/issues... X-Git-Tag: v0.6~24 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=86a23ca21bde2c37b8318f883bee143e063d07ff;p=PrivacyBrowserPC.git Update bookmarks in all windows when modified. https://redmine.stoutner.com/issues/1095 --- diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 8382e00..b90f132 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -43,6 +43,9 @@ // Qt toolkit headers. #include #include +#include +#include +#include #include #include #include @@ -531,8 +534,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Show the custom bookmark context menu when requested. connect(bookmarksToolBarPointer, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showBookmarkContextMenu(const QPoint&))); - // Populate the bookmarks. - populateBookmarks(); + // Populate the bookmarks in this window. + populateBookmarksInThisWindow(); // Populate the UI. // This must be done here, because otherwise, if a URL is loaded, like a local file, that does not trigger a call to TabWidget::applyDomainSettings, the UI will not be fully populated. @@ -571,7 +574,7 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double tabWidgetPointer->getCurrentTabFavoritIcon(), folderId); // Update the displayed bookmarks when a new one is added. - connect(addBookmarkDialogPointer, SIGNAL(bookmarkAdded()), this, SLOT(populateBookmarks())); + connect(addBookmarkDialogPointer, SIGNAL(bookmarkAdded()), this, SLOT(populateBookmarksInAllWindows())); // Show the dialog. addBookmarkDialogPointer->show(); @@ -585,7 +588,7 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double AddFolderDialog *addFolderDialogPointer = new AddFolderDialog(tabWidgetPointer->getCurrentTabFavoritIcon(), folderId); // Update the displayed bookmarks when a folder is added. - connect(addFolderDialogPointer, SIGNAL(folderAdded()), this, SLOT(populateBookmarks())); + connect(addFolderDialogPointer, SIGNAL(folderAdded()), this, SLOT(populateBookmarksInAllWindows())); // Show the dialog. addFolderDialogPointer->show(); @@ -659,7 +662,7 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double editFolderDialogPointer->show(); // Process bookmark events. - connect(editFolderDialogPointer, SIGNAL(folderSaved()), this, SLOT(populateBookmarks())); + connect(editFolderDialogPointer, SIGNAL(folderSaved()), this, SLOT(populateBookmarksInAllWindows())); } ); @@ -718,7 +721,7 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double BookmarksDatabase::updateFolderContentsDisplayOrder(parentFolderId); // Repopulate the bookmarks. - populateBookmarks(); + populateBookmarksInAllWindows(); } } ); @@ -811,7 +814,7 @@ void BrowserWindow::editBookmarks() const BookmarksDialog *bookmarksDialogPointer = new BookmarksDialog(tabWidgetPointer->getCurrentTabTitle(), tabWidgetPointer->getCurrentTabUrl(), tabWidgetPointer->getCurrentTabFavoritIcon()); // Update the displayed bookmarks when edited. - connect(bookmarksDialogPointer, SIGNAL(bookmarkUpdated()), this, SLOT(populateBookmarks())); + connect(bookmarksDialogPointer, SIGNAL(bookmarkUpdated()), this, SLOT(populateBookmarksInAllWindows())); // Show the dialog. bookmarksDialogPointer->show(); @@ -996,8 +999,29 @@ void BrowserWindow::newWindow() const browserWindowPointer->show(); } -void BrowserWindow::populateBookmarks() +void BrowserWindow::populateBookmarksInAllWindows() const { + // Get a list of all the registered service names. + QStringList registeredServiceNames = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); + + // Get a list of all the Privacy Browser windows, which will be `com.stoutner.privacybrowser-` with the PID appended. + QStringList privacyBrowserServiceNames = registeredServiceNames.filter("com.stoutner.privacybrowser"); + + // Repopulate the bookmarks in each window. + for (QString privacyBrowserServiceName : privacyBrowserServiceNames) + { + // Prepare the D-Bus message. + QDBusMessage dBusMessage = QDBusMessage::createMethodCall(privacyBrowserServiceName, "/privacybrowser/MainWindow_1", "com.stoutner.privacybrowser.BrowserWindow", "populateBookmarksInThisWindow"); + + // Make it so. + QDBusConnection::sessionBus().send(dBusMessage); + } +} + +void BrowserWindow::populateBookmarksInThisWindow() +{ + qDebug() << "Populating bookmarks."; + // Remove all the final bookmark folder menu actions. for (QPair *finalBookmarkFolderMenuActionPair : finalBookmarkFolderMenuActionList) { @@ -1311,7 +1335,7 @@ void BrowserWindow::showBookmarkContextMenu(const QPoint &point) editBookmarkDialogPointer->show(); // Process bookmark events. - connect(editBookmarkDialogPointer, SIGNAL(bookmarkSaved()), this, SLOT(populateBookmarks())); + connect(editBookmarkDialogPointer, SIGNAL(bookmarkSaved()), this, SLOT(populateBookmarksInAllWindows())); } ); @@ -1345,7 +1369,7 @@ void BrowserWindow::showBookmarkContextMenu(const QPoint &point) BookmarksDatabase::updateFolderContentsDisplayOrder(parentFolderId); // Repopulate the bookmarks. - populateBookmarks(); + populateBookmarksInAllWindows(); } ); } @@ -1660,7 +1684,7 @@ void BrowserWindow::toggleBookmark() } // Repopulate the bookmarks. - populateBookmarks(); + populateBookmarksInAllWindows(); } void BrowserWindow::toggleDomStorage() const diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index c4e0464..6910f8a 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -49,6 +49,10 @@ public: // The public variables. TabWidget *tabWidgetPointer; +public Q_SLOTS: + // The public slots. + void populateBookmarksInThisWindow(); // This is public so that the bookmarks can be repopulated over D-Bus when changed by another instance of Privacy Browser. + private Q_SLOTS: // The private slots. void addOrEditDomainSettings() const; @@ -67,7 +71,7 @@ private Q_SLOTS: void incrementZoom(); void loadUrlFromLineEdit(const QString &url) const; void newWindow() const; - void populateBookmarks(); + void populateBookmarksInAllWindows() const; void refresh() const; void reloadAndBypassCache() const; void showBookmarkContextMenu(const QPoint &point);