#include "dialogs/BookmarksDialog.h"
#include "dialogs/CookiesDialog.h"
#include "dialogs/DomainSettingsDialog.h"
+#include "dialogs/EditBookmarkDialog.h"
#include "helpers/SearchEngineHelper.h"
#include "helpers/UserAgentHelper.h"
#include "structs/BookmarkStruct.h"
#include <KXMLGUIFactory>
// Qt toolkit headers.
+#include <QClipboard>
+#include <QContextMenuEvent>
#include <QFileDialog>
#include <QInputDialog>
#include <QNetworkCookie>
#include <QWebEngineFindTextResult>
// Construct the class.
-BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
+BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) : KXmlGuiWindow()
{
// Initialize the variables.
javaScriptEnabled = false;
updateUserAgentActions(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()), true);
updateZoomActions(Settings::zoomFactor());
- // Load the initial website if this is the first window.
- if (firstWindow)
+ // Populate the first tab.
+ if (firstWindow) // This is the first window.
+ {
+ // Load the initial website.
tabWidgetPointer->loadInitialWebsite();
+ }
+ else if (initialUrlStringPointer) // An initial URL was specified.
+ {
+ // Load the initial URL.
+ tabWidgetPointer->loadUrlFromLineEdit(*initialUrlStringPointer);
+ }
}
void BrowserWindow::addOrEditDomainSettings() const
void BrowserWindow::newWindow() const
{
- // Display a new instance of Privacy Browser.
- (new BrowserWindow)->show();
+ // Create a new browser window.
+ BrowserWindow *browserWindowPointer = new BrowserWindow();
+
+ // Show the new browser window.
+ browserWindowPointer->show();
}
void BrowserWindow::populateBookmarks()
}
);
+ // Add the bookmark database ID to the toolbar action.
+ toolBarBookmarkActionPointer->setData(bookmarkStruct.id);
+
// Add the actions to the current bookmarks lists.
bookmarksMenuCurrentActionList.append(menuBookmarkActionPointer);
bookmarksToolBarCurrentActionList.append(toolBarBookmarkActionPointer);
addBookmarkDialogPointer->show();
}
-void BrowserWindow::showBookmarkContextMenu(const QPoint&) const
+void BrowserWindow::showBookmarkContextMenu(const QPoint &point)
{
- qDebug() << "Show the bookmark context menu.";
+ // Get the bookmark action.
+ QAction *bookmarkActionPointer = bookmarksToolBarPointer->actionAt(point);
+
+ // Check to see if an bookmark was clicked.
+ if (bookmarkActionPointer) // A bookmark was clicked.
+ {
+ // Create a bookmark context menu.
+ QMenu *bookmarkContextMenuPointer = new QMenu();
+
+ // Get the bookmark ID from the action.
+ int bookmarkId = bookmarkActionPointer->data().toInt();
+
+ // Add the open in new tab action to the menu.
+ bookmarkContextMenuPointer->addAction(QIcon::fromTheme(QLatin1String("tab-new")), i18nc("Open bookmark in new tab context menu entry", "Open in New Tab"), [=]
+ {
+ // Get the bookmark.
+ BookmarkStruct *bookmarkStructPointer = BookmarksDatabase::getBookmark(bookmarkId);
+
+ // Open the bookmark in a new tab. `true` removes the URL line edit focus, `false` does not load a background tab.
+ tabWidgetPointer->addTab(true, false, bookmarkStructPointer->bookmarkUrl);
+ }
+ );
+
+ // Add the open in background tab action to the menu.
+ bookmarkContextMenuPointer->addAction(QIcon::fromTheme(QLatin1String("tab-new")), i18nc("Open bookmark in background tab context menu entry", "Open in Background Tab"), [=]
+ {
+ // Get the bookmark.
+ BookmarkStruct *bookmarkStructPointer = BookmarksDatabase::getBookmark(bookmarkId);
+
+ // Open the bookmark in a new tab. `true` removes the URL line edit focus, `true` loads a background tab.
+ tabWidgetPointer->addTab(true, true, bookmarkStructPointer->bookmarkUrl);
+ }
+ );
+
+ // Add the open in new window action to the menu.
+ bookmarkContextMenuPointer->addAction(QIcon::fromTheme(QLatin1String("window-new")), i18nc("Open bookmark in new window context menu entry", "Open in New Window"), [=]
+ {
+ // Get the bookmark.
+ BookmarkStruct *bookmarkStructPointer = BookmarksDatabase::getBookmark(bookmarkId);
+
+ // Create a new browser window.
+ BrowserWindow *browserWindowPointer = new BrowserWindow(false, &bookmarkStructPointer->bookmarkUrl);
+
+ // Show the new browser window.
+ browserWindowPointer->show();
+ }
+ );
+
+ // Add a separator.
+ bookmarkContextMenuPointer->addSeparator();
+
+ // Add the edit action to the menu.
+ bookmarkContextMenuPointer->addAction(QIcon::fromTheme(QLatin1String("edit-entry")), i18nc("Edit bookmark context menu entry", "Edit"), [=]
+ {
+ // Get the current tab favorite icon.
+ QIcon currentTabFavoriteIcon = tabWidgetPointer->getCurrentTabFavoritIcon();
+
+ // Instantiate an edit bookmark dialog.
+ QDialog *editBookmarkDialogPointer = new EditBookmarkDialog(bookmarkId, currentTabFavoriteIcon);
+
+ // Show the dialog.
+ editBookmarkDialogPointer->show();
+
+ // Process bookmark events.
+ connect(editBookmarkDialogPointer, SIGNAL(bookmarkSaved()), this, SLOT(populateBookmarks()));
+ }
+ );
+
+ // Add the copy URL action to the menu.
+ bookmarkContextMenuPointer->addAction(QIcon::fromTheme(QLatin1String("edit-copy")), i18nc("Copy bookmark url context menu entry", "Copy URL"), [=]
+ {
+ // Get the bookmark.
+ BookmarkStruct *bookmarkStructPointer = BookmarksDatabase::getBookmark(bookmarkId);
+
+ // Get a handle for the clipboard.
+ QClipboard *clipboard = QGuiApplication::clipboard();
+
+ // Place the URL on the keyboard.
+ clipboard->setText(bookmarkStructPointer->bookmarkUrl);
+ }
+ );
+
+ // Add a separator.
+ bookmarkContextMenuPointer->addSeparator();
+
+ // Add the delete action to the menu.
+ bookmarkContextMenuPointer->addAction(QIcon::fromTheme(QLatin1String("delete")), i18nc("Delete bookmark context menu entry", "Delete"), [=]
+ {
+ // Delete the bookmark.
+ BookmarksDatabase::deleteBookmark(bookmarkId);
+
+ // Repopulate the bookmarks.
+ populateBookmarks();
+ }
+ );
+
+ // Delete the menu from memory when it is closed.
+ bookmarkContextMenuPointer->setAttribute(Qt::WA_DeleteOnClose);
+
+ // Display the context menu.
+ bookmarkContextMenuPointer->popup(bookmarksToolBarPointer->mapToGlobal(point));
+ }
+ else // The toolbar background was clicked.
+ {
+ // Temporarily set the context menu policy to the default.
+ bookmarksToolBarPointer->setContextMenuPolicy(Qt::DefaultContextMenu);
+
+ // Create a context menu event with the same position.
+ QContextMenuEvent *contextMenuEventPointer = new QContextMenuEvent(QContextMenuEvent::Mouse, point);
+
+ // Send the context menu event to the toolbar.
+ QCoreApplication::sendEvent(bookmarksToolBarPointer, contextMenuEventPointer);
+
+ // Reset the context menu policy.
+ bookmarksToolBarPointer->setContextMenuPolicy(Qt::CustomContextMenu);
+ }
}
void BrowserWindow::showCookiesDialog()