# Use KDE Frameworks to handle internationalization of the following UI files.
ki18n_wrap_ui(privacybrowser
+ uis/AddBookmarkDialog.ui
uis/AddOrEditCookieDialog.ui
uis/AddTabWidget.ui
+ uis/BookmarksDialog.ui
uis/CookiesDialog.ui
uis/DomainSettingsDialog.ui
uis/DurableCookiesDialog.ui
--- /dev/null
+/*
+ * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Application headers.
+#include "BookmarksDatabase.h"
+
+// Define the private static schema constants.
+const int BookmarksDatabase::SCHEMA_VERSION = 0;
+
+// Define the public static constants.
+const QString BookmarksDatabase::CONNECTION_NAME = "bookmarks_database";
+const QString BookmarksDatabase::BOOKMARK_NAME = "bookmark_name";
+const QString BookmarksDatabase::BOOKMARKS_TABLE = "bookmarks";
+const QString BookmarksDatabase::BOOKMARK_URL = "bookmark_url";
+const QString BookmarksDatabase::DISPLAY_ORDER = "display_order";
+const QString BookmarksDatabase::FAVORITE_ICON = "favorite_icon";
+const QString BookmarksDatabase::FOLDER_ID = "folder_id";
+const QString BookmarksDatabase::ID = "_id";
+const QString BookmarksDatabase::IS_FOLDER = "is_folder";
+const QString BookmarksDatabase::PARENT_FOLDER_ID = "parent_folder_id";
+
+// Construct the class.
+BookmarksDatabase::BookmarksDatabase() {}
+
+void BookmarksDatabase::addDatabase()
+{
+ // Add the bookmarks database.
+ QSqlDatabase bookmarksDatabase = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), CONNECTION_NAME);
+
+ // Set the database name.
+ bookmarksDatabase.setDatabaseName(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/bookmarks.db");
+
+ // Open the database.
+ if (bookmarksDatabase.open()) // Opening the database succeeded.
+ {
+ // Check to see if the bookmarks table already exists.
+ if (bookmarksDatabase.tables().contains(BOOKMARKS_TABLE)) // The bookmarks table already exists.
+ {
+ // Query the database schema version.
+ QSqlQuery schemaVersionQuery = bookmarksDatabase.exec(QStringLiteral("PRAGMA user_version"));
+
+ // Move to the first record.
+ schemaVersionQuery.first();
+
+ // Get the current schema version.
+ int currentSchemaVersion = schemaVersionQuery.value(0).toInt();
+
+ // Check to see if the schema has been updated.
+ if (currentSchemaVersion < SCHEMA_VERSION)
+ {
+ // Run the schema update code.
+
+ // Update the schema version.
+ bookmarksDatabase.exec("PRAGMA user_version = " + QString::number(SCHEMA_VERSION));
+ }
+ }
+ else // The bookmarks table does not exist.
+ {
+ // Instantiate a create table query.
+ QSqlQuery createTableQuery(bookmarksDatabase);
+
+ // Populate the create table query.
+ createTableQuery.prepare("CREATE TABLE " + BOOKMARKS_TABLE + "(" +
+ ID + " INTEGER PRIMARY KEY, " +
+ BOOKMARK_NAME + " TEXT, " +
+ BOOKMARK_URL + " TEXT, " +
+ PARENT_FOLDER_ID + " INTEGER DEFAULT 0, " +
+ DISPLAY_ORDER + " INTEGER DEFAULT 0, " +
+ IS_FOLDER + " BOOLEAN DEFAULT FALSE, " +
+ FOLDER_ID + " INTEGER DEFAULT 0, " +
+ FAVORITE_ICON + " BLOB)");
+
+ // Execute the query.
+ if (!createTableQuery.exec())
+ {
+ // Log any errors.
+ qDebug().noquote().nospace() << "Error creating table: " << bookmarksDatabase.lastError();
+ }
+
+ // Set the schema version.
+ bookmarksDatabase.exec("PRAGMA user_version = " + QString::number(SCHEMA_VERSION));
+ }
+ }
+ else // Opening the database failed.
+ {
+ // Write the last database error message to the debug output.
+ qDebug().noquote().nospace() << "Error opening database: " << bookmarksDatabase.lastError();
+ }
+};
+
+void BookmarksDatabase::addBookmark(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon)
+{
+ // Get a handle for the bookmarks database.
+ QSqlDatabase bookmarksDatabase = QSqlDatabase::database(CONNECTION_NAME);
+
+ // Get a favorite icon pixmap.
+ QPixmap favoriteIconPixmap = favoriteIcon.pixmap(32, 32);
+
+ // Create a favorite icon byte array.
+ QByteArray favoriteIconByteArray;
+
+ // Create a favorite icon buffer.
+ QBuffer favoriteIconBuffer(&favoriteIconByteArray);
+
+ // Open the buffer.
+ favoriteIconBuffer.open(QIODevice::WriteOnly);
+
+ // Convert the favorite icon pixmap into a byte array in PNG format.
+ favoriteIconPixmap.save(&favoriteIconBuffer, "PNG");
+
+ // Close the buffer.
+ favoriteIconBuffer.close();
+
+ // Convert the favorite icon byte array to a base 64 string.
+ QString favoriteIconBase64String = favoriteIconByteArray.toBase64();
+
+ // Instantiate an add bookmark query.
+ QSqlQuery addBookmarkQuery(bookmarksDatabase);
+
+ // Prepare the add bookmark query.
+ addBookmarkQuery.prepare("INSERT INTO " + BOOKMARKS_TABLE + " (" +
+ BOOKMARK_NAME + ", " +
+ BOOKMARK_URL + ", " +
+ FAVORITE_ICON + ") "
+ "VALUES (:bookmark_name, :bookmark_url, :favorite_icon)"
+ );
+
+ // Bind the values.
+ addBookmarkQuery.bindValue(":bookmark_name", bookmarkName);
+ addBookmarkQuery.bindValue(":bookmark_url", bookmarkUrl);
+ addBookmarkQuery.bindValue(":favorite_icon", favoriteIconBase64String);
+
+ // Execute the query.
+ addBookmarkQuery.exec();
+}
+
+std::list<BookmarkStruct>* BookmarksDatabase::getBookmarks()
+{
+ // Get a handle for the bookmarks database.
+ QSqlDatabase bookmarksDatabase = QSqlDatabase::database(CONNECTION_NAME);
+
+ // Instantiate a bookmarks query.
+ QSqlQuery bookmarksQuery(bookmarksDatabase);
+
+ // Set the query to be forward only, which is more performant.
+ bookmarksQuery.setForwardOnly(true);
+
+ // Prepare the bookmarks query.
+ bookmarksQuery.prepare("SELECT * FROM " + BOOKMARKS_TABLE);
+
+ // Execute the query.
+ bookmarksQuery.exec();
+
+ // Create a bookmark list.
+ std::list<BookmarkStruct> *bookmarkListPointer = new std::list<BookmarkStruct>;
+
+ // Populate the bookmark list.
+ while (bookmarksQuery.next())
+ {
+ // Create a bookmark struct.
+ struct BookmarkStruct bookmarkStruct;
+
+ // Get the favorite icon base 64 bute array.
+ QByteArray favoriteIconByteArray = QByteArray::fromBase64(bookmarksQuery.value(FAVORITE_ICON).toByteArray());
+
+ // Create a favorite icon pixmap.
+ QPixmap favoriteIconPixmap;
+
+ // Load the pixmap from byte array.
+ favoriteIconPixmap.loadFromData(favoriteIconByteArray);
+
+ // Populate the bookmark struct.
+ bookmarkStruct.id = bookmarksQuery.value(ID).toInt();
+ bookmarkStruct.bookmarkName = bookmarksQuery.value(BOOKMARK_NAME).toString();
+ bookmarkStruct.bookmarkUrl = bookmarksQuery.value(BOOKMARK_URL).toString();
+ bookmarkStruct.favoriteIcon = QIcon(favoriteIconPixmap);
+
+ // Add the bookmark to the list.
+ bookmarkListPointer->push_back(bookmarkStruct);
+ }
+
+ // Return the bookmark list.
+ return bookmarkListPointer;
+}
+
+void BookmarksDatabase::updateBookmarkName(const int bookmarkId, const QString &bookmarkName)
+{
+ // Get a handle for the bookmarks database.
+ QSqlDatabase bookmarksDatabase = QSqlDatabase::database(CONNECTION_NAME);
+
+ // Instantiate an update bookmark name query.
+ QSqlQuery updateBookmarkNameQuery(bookmarksDatabase);
+
+ // Prepare the update bookmark name query.
+ updateBookmarkNameQuery.prepare("UPDATE " + BOOKMARKS_TABLE +
+ " SET " + BOOKMARK_NAME + " = :bookmark_name " +
+ "WHERE " + ID + " = :id");
+
+ // Bind the values.
+ updateBookmarkNameQuery.bindValue(":bookmark_name", bookmarkName);
+ updateBookmarkNameQuery.bindValue(":id", bookmarkId);
+
+ // Execute the query.
+ updateBookmarkNameQuery.exec();
+}
+
+void BookmarksDatabase::updateBookmarkUrl(const int bookmarkId, const QString &bookmarkUrl)
+{
+ // Get a handle for the bookmarks database.
+ QSqlDatabase bookmarksDatabase = QSqlDatabase::database(CONNECTION_NAME);
+
+ // Instantiate an update bookmark URL query.
+ QSqlQuery updateBookmarkUrlQuery(bookmarksDatabase);
+
+ // Prepare the update bookmark URL query.
+ updateBookmarkUrlQuery.prepare("UPDATE " + BOOKMARKS_TABLE +
+ " SET " + BOOKMARK_URL + " = :bookmark_url " +
+ "WHERE " + ID + " = :id");
+
+ // Bind the values.
+ updateBookmarkUrlQuery.bindValue(":bookmark_url", bookmarkUrl);
+ updateBookmarkUrlQuery.bindValue(":id", bookmarkId);
+
+ // Execute the query.
+ updateBookmarkUrlQuery.exec();
+}
--- /dev/null
+/*
+ * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef BOOKMARKSDATABASE_H
+#define BOOKMARKSDATABASE_H
+
+// Application headers.
+#include "structs/BookmarkStruct.h"
+
+// Qt framework headers.
+#include <QtSql>
+
+class BookmarksDatabase
+{
+public:
+ // The default constructor.
+ BookmarksDatabase();
+
+ // The public functions.
+ static void addBookmark(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon);
+ static void addDatabase();
+ static std::list<BookmarkStruct>* getBookmarks();
+ static void updateBookmarkName(const int bookmarkId, const QString &bookmarkName);
+ static void updateBookmarkUrl(const int bookmarkId, const QString &bookmarkUrl);
+
+ // The public constants.
+ static const QString CONNECTION_NAME;
+ static const QString BOOKMARK_NAME;
+ static const QString BOOKMARKS_TABLE;
+ static const QString BOOKMARK_URL;
+ static const QString DISPLAY_ORDER;
+ static const QString FAVORITE_ICON;
+ static const QString FOLDER_ID;
+ static const QString ID;
+ static const QString IS_FOLDER;
+ static const QString PARENT_FOLDER_ID;
+
+ private:
+ // The private static constants.
+ static const int SCHEMA_VERSION;
+};
+#endif
# List the sources to include in the executable.
target_sources(privacybrowser PRIVATE
+ BookmarksDatabase.cpp
CookiesDatabase.cpp
DomainsDatabase.cpp
)
// Instantiate a cookies query.
QSqlQuery cookiesQuery(cookiesDatabase);
- // Set the query to be forward only.
+ // Set the query to be forward only, which is more performant.
cookiesQuery.setForwardOnly(true);
// Prepare the cookies query.
// Create the update cookie query.
QSqlQuery updateCookieQuery(cookiesDatabase);
- // Prepare the edit cookie query.
+ // Prepare the update cookie query.
updateCookieQuery.prepare("UPDATE " + COOKIES_TABLE +
" SET " + EXPIRATION_DATE + " = :expiration_date , " +
HTTP_ONLY + " = :http_only , " +
--- /dev/null
+/*
+ * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Application headers.
+#include "AddBookmarkDialog.h"
+#include "ui_AddBookmarkDialog.h"
+#include "databases/BookmarksDatabase.h"
+
+// KDE Framework headers.
+#include <KLocalizedString>
+
+// Qt toolkit headers.
+#include <QPushButton>
+
+// Construct the class.
+AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon) : QDialog(nullptr), icon(favoriteIcon)
+{
+ // Set the window title.
+ setWindowTitle(i18nc("The add bookmark dialog window title.", "Add Bookmark"));
+
+ // Set the window modality.
+ setWindowModality(Qt::WindowModality::ApplicationModal);
+
+ // Instantiate the bookmarks dialog UI.
+ Ui::AddBookmarkDialog addBookmarkDialogUi;
+
+ // Setup the UI.
+ addBookmarkDialogUi.setupUi(this);
+
+ // Get handles for the widgets.
+ QGraphicsView *favoriteIconGraphicsViewPointer = addBookmarkDialogUi.favoriteIconGraphicsView;
+ bookmarkNamePointer = addBookmarkDialogUi.bookmarkNameLineEdit;
+ bookmarkUrlPointer = addBookmarkDialogUi.bookmarkUrlLineEdit;
+ QDialogButtonBox *dialogButtonBoxPointer = addBookmarkDialogUi.dialogButtonBox;
+
+ // Create a graphics scene.
+ QGraphicsScene *favoriteIconGraphicsScenePointer = new QGraphicsScene(this);
+
+ // Set the graphics scene.
+ favoriteIconGraphicsViewPointer->setScene(favoriteIconGraphicsScenePointer);
+
+ // Set the background of the graphics view to be the same as the window
+ favoriteIconGraphicsViewPointer->setBackgroundRole(QPalette::Window);
+
+ // Add the MIME type icon to the scene.
+ favoriteIconGraphicsScenePointer->addPixmap(favoriteIcon.pixmap(32, 32));
+
+ // Populate the line edits.
+ bookmarkNamePointer->setText(bookmarkName);
+ bookmarkUrlPointer->setText(bookmarkUrl);
+
+ // Scroll the the beginning of the line edits.
+ bookmarkNamePointer->setCursorPosition(0);
+ bookmarkUrlPointer->setCursorPosition(0);
+
+ // Add buttons to the dialog button box.
+ QPushButton *addBookmarkButtonPointer = dialogButtonBoxPointer->addButton(i18nc("The add bookmark button", "Add"), QDialogButtonBox::AcceptRole);
+
+ // Set the button icons.
+ addBookmarkButtonPointer->setIcon(QIcon::fromTheme("list-add"));
+
+ // Connect the buttons.
+ connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(addBookmark()));
+ connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject()));
+}
+
+void AddBookmarkDialog::addBookmark()
+{
+ // Add the bookmark.
+ BookmarksDatabase::addBookmark(bookmarkNamePointer->text(), bookmarkUrlPointer->text(), icon);
+
+ // Close the dialog.
+ close();
+}
+
--- /dev/null
+/*
+ * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ADDBOOKMARKDIALOG_H
+#define ADDBOOKMARKDIALOG_H
+
+// Qt toolkit headers.
+#include <QDialog>
+#include <QIcon>
+#include <QLineEdit>
+
+class AddBookmarkDialog : public QDialog
+{
+ // Include the Q_OBJECT macro.
+ Q_OBJECT
+
+public:
+ // The primary constructor.
+ explicit AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon);
+
+private Q_SLOTS:
+ // The private slots.
+ void addBookmark();
+
+private:
+ // The private widgets.
+ QLineEdit *bookmarkNamePointer;
+ QLineEdit *bookmarkUrlPointer;
+
+ // The private variables.
+ const QIcon icon;
+};
+#endif
/*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
*
// Set the window modality.
setWindowModality(Qt::WindowModality::ApplicationModal);
- // Instantiate the cookie settings dialog UI.
+ // Instantiate the cookie dialog UI.
Ui::AddOrEditCookieDialog addOrEditCookieDialogUi;
// Setup the UI.
secureCheckBoxPointer->setChecked(originalCookie.isSecure());
valueLineEditPointer->setText(originalCookie.value());
+ // Scroll to the beginning of the line edits.
+ domainLineEditPointer->setCursorPosition(0);
+ nameLineEditPointer->setCursorPosition(0);
+ pathLineEditPointer->setCursorPosition(0);
+ valueLineEditPointer->setCursorPosition(0);
+
// Populate the expiration date if it exists.
if (!originalCookie.isSessionCookie())
{
emit addCookie(cookie, isDurable);
// Close the dialog.
- reject();
+ close();
}
void AddOrEditCookieDialog::updateExpirationDateTimeState(const int &newState) const
/*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
*
--- /dev/null
+/*
+ * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Application headers.
+#include "BookmarksDialog.h"
+#include "ui_BookmarksDialog.h"
+#include "databases/BookmarksDatabase.h"
+
+// KDE Frameworks headers.
+#include <KLocalizedString>
+
+// Qt toolkit headers.
+#include <QDebug>
+#include <QStandardItemModel>
+#include <QTreeView>
+
+// Construct the class.
+BookmarksDialog::BookmarksDialog() : QDialog(nullptr)
+{
+ // Set the dialog window title.
+ setWindowTitle(i18nc("The bookmarks dialog window title", "Bookmarks"));
+
+ // Set the window modality.
+ setWindowModality(Qt::WindowModality::ApplicationModal);
+
+ // Instantiate the bookmarks settings dialog UI.
+ Ui::BookmarksDialog bookmarksDialogUi;
+
+ // Setup the UI.
+ bookmarksDialogUi.setupUi(this);
+
+ // Get the list of bookmarks.
+ std::list<BookmarkStruct> *bookmarksListPointer = BookmarksDatabase::getBookmarks();
+
+ // Get a handle for the tree view.
+ QTreeView *treeViewPointer = bookmarksDialogUi.treeView;
+
+ // Initialize the tree model.
+ QStandardItemModel *treeModelPointer = new QStandardItemModel();
+
+ // Set the column count.
+ treeModelPointer->setColumnCount(3);
+
+ // Set the tree header data. The first column is the database ID, which is not displayed.
+ treeModelPointer->setHeaderData(1, Qt::Horizontal, i18nc("The bookmark Name header.", "Name"));
+ treeModelPointer->setHeaderData(2, Qt::Horizontal, i18nc("The bookmark URL header.", "URL"));
+
+ // Populate the bookmarks tree view.
+ for (BookmarkStruct bookmarkStruct : *bookmarksListPointer)
+ {
+ // Create a list for the bookmark items.
+ QList<QStandardItem*> bookmarkItemList;
+
+ // Create the bookmark items.
+ QStandardItem *idItemPointer = new QStandardItem(QString::number(bookmarkStruct.id));
+ QStandardItem *nameItemPointer = new QStandardItem(bookmarkStruct.favoriteIcon, bookmarkStruct.bookmarkName);
+ QStandardItem *urlItemPointer = new QStandardItem(bookmarkStruct.bookmarkUrl);
+
+ // Populate the cookie standard item list.
+ bookmarkItemList.append(idItemPointer);
+ bookmarkItemList.append(nameItemPointer);
+ bookmarkItemList.append(urlItemPointer);
+
+ // Add the cookie to the tree.
+ treeModelPointer->appendRow(bookmarkItemList);
+ }
+
+ // Auto resize the headers.
+ treeViewPointer->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+
+ // Indicate that all the rows are the same height, which improves performance.
+ treeViewPointer->setUniformRowHeights(true);
+
+ // Set the tree model.
+ treeViewPointer->setModel(treeModelPointer);
+
+ // Hide the database ID column.
+ treeViewPointer->setColumnHidden(0, true);
+
+ // Get handles for the buttons.
+ QDialogButtonBox *dialogButtonBoxPointer = bookmarksDialogUi.dialogButtonBox;
+
+ // Connect the buttons.
+ connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject()));
+
+ // Monitor editing of data in the tree model.
+ connect(treeModelPointer, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateBookmarkFromTree(QStandardItem*)));
+}
+
+void BookmarksDialog::updateBookmarkFromTree(QStandardItem *modifiedStandardItem)
+{
+ // Get the model index of the modified item.
+ QModelIndex modifiedItemModelIndex = modifiedStandardItem->index();
+
+ // Get the model index of the database ID.
+ QModelIndex databaseIdModelIndex = modifiedItemModelIndex.siblingAtColumn(0);
+
+ // Get the database ID.
+ int databaseId = databaseIdModelIndex.data().toInt();
+
+ // Check to see if the bookmark name or the URL was edited.
+ if (modifiedStandardItem->column() == 1) // The bookmark name was edited.
+ {
+ // Update the bookmark name.
+ BookmarksDatabase::updateBookmarkName(databaseId, modifiedStandardItem->text());
+ }
+ else // The bookmark URL was edited.
+ {
+ // Update the bookmark URL.
+ BookmarksDatabase::updateBookmarkUrl(databaseId, modifiedStandardItem->text());
+ }
+
+ // Emit the bookmark updated signal.
+ emit bookmarkUpdated();
+}
--- /dev/null
+/*
+ * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef BOOKMARKSDIALOG_H
+#define BOOKMARKSDIALOG_H
+
+// Application headers.
+#include "structs/BookmarkStruct.h"
+
+// Qt toolkit headers.
+#include <QDialog>
+#include <QStandardItem>
+
+class BookmarksDialog : public QDialog
+{
+ // Include the Q_OBJECT macro.
+ Q_OBJECT
+
+public:
+ // The primary constructor.
+ explicit BookmarksDialog();
+
+signals:
+ // The signals.
+ void bookmarkUpdated() const;
+
+private Q_SLOTS:
+ // The private slots.
+ void updateBookmarkFromTree(QStandardItem *modifiedStandardItem);
+};
+#endif
# List the sources to include in the executable.
target_sources(privacybrowser PRIVATE
+ AddBookmarkDialog.cpp
AddOrEditCookieDialog.cpp
+ BookmarksDialog.cpp
CookiesDialog.cpp
DomainSettingsDialog.cpp
DurableCookiesDialog.cpp
/*
- * Copyright © 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
*
// Create the cookie items.
QStandardItem *nameItemPointer = new QStandardItem(QString(cookie.name()));
- QStandardItem *durableItemPointer = new QStandardItem(QString(isDurable ? i18n("yes") : i18n("no")));
- QStandardItem *pathItemPointer = new QStandardItem(QString(cookie.path()));
- QStandardItem *expirationDateItemPointer = new QStandardItem(QString(cookie.expirationDate().toString()));
- QStandardItem *isHttpOnlyItemPointer = new QStandardItem(QString(cookie.isHttpOnly() ? i18n("yes") : i18n("no")));
- QStandardItem *isSecureItemPointer = new QStandardItem(QString(cookie.isSecure() ? i18n("yes") : i18n("no")));
+ QStandardItem *durableItemPointer = new QStandardItem(isDurable ? i18n("yes") : i18n("no"));
+ QStandardItem *pathItemPointer = new QStandardItem(cookie.path());
+ QStandardItem *expirationDateItemPointer = new QStandardItem(cookie.expirationDate().toString());
+ QStandardItem *isHttpOnlyItemPointer = new QStandardItem(cookie.isHttpOnly() ? i18n("yes") : i18n("no"));
+ QStandardItem *isSecureItemPointer = new QStandardItem(cookie.isSecure() ? i18n("yes") : i18n("no"));
QStandardItem *valueItemPointer = new QStandardItem(QString(cookie.value()));
// Populate the cookie standard item list.
// Don't elide the Value field (or any other field).
treeViewPointer->setTextElideMode(Qt::ElideNone);
- // Indicate that all the rows are the same height, wich improves performance.
+ // Indicate that all the rows are the same height, which improves performance.
treeViewPointer->setUniformRowHeights(true);
// Disable editing in the tree view.
/*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
*
*/
// Application headers.
+#include "databases/BookmarksDatabase.h"
#include "databases/CookiesDatabase.h"
#include "databases/DomainsDatabase.h"
#include "windows/BrowserWindow.h"
QDir().mkdir(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).first());
// Add the databases.
- DomainsDatabase::addDatabase();
+ BookmarksDatabase::addDatabase();
CookiesDatabase::addDatabase();
+ DomainsDatabase::addDatabase();
// Create the main window.
BrowserWindow *browserWindowPointer = new BrowserWindow();
--- /dev/null
+/*
+ * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef BOOKMARKSTRUCT_H
+#define BOOKMARKSTRUCT_H
+
+// Qt framework headers.
+#include <QIcon>
+#include <QString>
+
+struct BookmarkStruct
+{
+ int id;
+ QString bookmarkName;
+ QString bookmarkUrl;
+ QIcon favoriteIcon;
+};
+#endif
</Menu>
</Menu>
+ <!-- Bookmarks. -->
+ <Menu name="bookmarks">
+ <Action name="view_bookmarks_toolbar" />
+
+ <Separator />
+ </Menu>
+
<!-- Settings. -->
<Menu name="settings">
<Action name="domain_settings" />
<Action name="find_case_sensitive" />
<Action name="hide_find_actions" />
</ToolBar>
+
+ <!-- The bookmarks toolbar. -->
+ <ToolBar name="bookmarks_toolbar" iconText="icontextright" newline="true" hidden="true"> <text>Bookmarks Toolbar</text> </ToolBar>
</gui>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+
+ This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+
+ Privacy Browser PC is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Privacy Browser PC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>. -->
+
+<ui version="4.0">
+ <class>AddBookmarkDialog</class>
+
+ <widget class="QWidget">
+ <layout class="QVBoxLayout">
+
+ <!-- First row. -->
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="alignment">
+ <enum>Qt::AlignLeft</enum>
+ </property>
+
+ <!-- Icon. -->
+ <item>
+ <widget class="QGraphicsView" name="favoriteIconGraphicsView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+
+ <property name="maximumSize">
+ <size>
+ <width>32</width>
+ <height>32</height>
+ </size>
+ </property>
+
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+
+ <!-- Spacer label. -->
+ <item>
+ <widget class="QLabel">
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="text">
+ <string>&nbsp;</string>
+ </property>
+ </widget>
+ </item>
+
+ <!-- Bookmark name. -->
+ <item>
+ <widget class="QLabel">
+ <property name="toolTip">
+ <string>The name of the bookmark.</string>
+ </property>
+
+ <property name="text">
+ <string>Bookmark name</string>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QLineEdit" name="bookmarkNameLineEdit" />
+ </item>
+ </layout>
+ </item>
+
+ <!-- Second row. -->
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="alignment">
+ <enum>Qt::AlignLeft</enum>
+ </property>
+
+ <!-- Bookmark URL. -->
+ <item>
+ <widget class="QLabel">
+ <property name="toolTip">
+ <string>The URL of the bookmark.</string>
+ </property>
+
+ <property name="text">
+ <string>Bookmark URL</string>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QLineEdit" name="bookmarkUrlLineEdit">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+
+ <property name="minimumSize">
+ <size>
+ <width>700</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+
+ <!-- Spacer. -->
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ </spacer>
+ </item>
+
+ <!-- Dialog buttons. -->
+ <item>
+ <widget class="QDialogButtonBox" name="dialogButtonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+</ui>
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ Copyright 2022 Soren Stoutner <soren@stoutner.com>.
This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+
+ This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+
+ Privacy Browser PC is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Privacy Browser PC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>. -->
+
+<ui version="4.0">
+ <class>BookmarksDialog</class>
+
+ <widget class="QWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <height>1000</height>
+ <width>1500</width>
+ </rect>
+ </property>
+
+ <layout class="QVBoxLayout">
+ <!-- Tree view. -->
+ <item>
+ <widget class="QTreeView" name="treeView" />
+ </item>
+
+ <!-- Buttons. -->
+ <item>
+ <layout class="QHBoxLayout">
+ <!-- Close button - dialog button box. -->
+ <item>
+ <widget class="QDialogButtonBox" name="dialogButtonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+</ui>
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 2022 Soren Stoutner <soren@stoutner.com>.
+ Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
<ui version="4.0">
<class>CookiesDialog</class>
-
<widget class="QWidget">
<property name="geometry">
<rect>
return currentPrivacyWebEngineViewPointer->cookieListPointer;
}
+QIcon TabWidget::getCurrentTabFavoritIcon() const
+{
+ // Return the current Privacy WebEngine favorite icon.
+ return currentPrivacyWebEngineViewPointer->favoriteIcon;
+}
+
+QString TabWidget::getCurrentTabTitle() const
+{
+ // Return the current Privacy WebEngine title.
+ return currentPrivacyWebEngineViewPointer->title();
+}
+
+QString TabWidget::getCurrentTabUrl() const
+{
+ // Return the current Privacy WebEngine URL as a string.
+ return currentPrivacyWebEngineViewPointer->url().toString();
+}
+
QString& TabWidget::getDomainSettingsName() const
{
// Return the domain settings name.
void loadInitialWebsite();
void findPrevious(const QString &text) const;
std::list<QNetworkCookie>* getCookieList() const;
+ QIcon getCurrentTabFavoritIcon() const;
+ QString getCurrentTabTitle() const;
+ QString getCurrentTabUrl() const;
QString& getDomainSettingsName() const;
void setTabBarVisible(const bool visible) const;
void toggleDomStorage() const;
#include "ui_SettingsGeneral.h"
#include "ui_SettingsPrivacy.h"
#include "ui_SettingsSpellCheck.h"
+#include "databases/BookmarksDatabase.h"
+#include "dialogs/AddBookmarkDialog.h"
+#include "dialogs/BookmarksDialog.h"
#include "dialogs/CookiesDialog.h"
#include "dialogs/DomainSettingsDialog.h"
#include "helpers/SearchEngineHelper.h"
#include "helpers/UserAgentHelper.h"
+#include "structs/BookmarkStruct.h"
// KDE Frameworks headers.
#include <KActionCollection>
#include <KColorScheme>
-#include <KToolBar>
+#include <KXMLGUIFactory>
// Qt toolkit headers.
#include <QFileDialog>
QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
+ KStandardAction::addBookmark(this, SLOT(addBookmark()), actionCollectionPointer);
+ QAction *editBookmarksActionPointer = KStandardAction::editBookmarks(this, SLOT(editBookmarks()), actionCollectionPointer);
KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollectionPointer);
KStandardAction::find(this, SLOT(showFindTextActions()), actionCollectionPointer);
findNextActionPointer = KStandardAction::findNext(this, SLOT(findNext()), actionCollectionPointer);
QAction *reloadAndBypassCacheActionPointer = actionCollectionPointer->addAction(QLatin1String("reload_and_bypass_cache"));
viewSourceActionPointer = actionCollectionPointer->addAction(QLatin1String("view_source"));
viewSourceInNewTabActionPointer = actionCollectionPointer->addAction(QLatin1String("view_source_in_new_tab"));
+ javaScriptActionPointer = actionCollectionPointer->addAction(QLatin1String("javascript"));
+ localStorageActionPointer = actionCollectionPointer->addAction(QLatin1String("local_storage"));
+ domStorageActionPointer = actionCollectionPointer->addAction(QLatin1String("dom_storage"));
userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_privacy_browser"));
userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_webengine_default"));
userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_firefox_linux"));
searchEngineBingActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_bing"));
searchEngineYahooActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_yahoo"));
searchEngineCustomActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_custom"));
+ viewBookmarksToolBarActionPointer = actionCollectionPointer->addAction(QLatin1String("view_bookmarks_toolbar"));
QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QLatin1String("domain_settings"));
cookiesActionPointer = actionCollectionPointer->addAction(QLatin1String("cookies"));
- javaScriptActionPointer = actionCollectionPointer->addAction(QLatin1String("javascript"));
- localStorageActionPointer = actionCollectionPointer->addAction(QLatin1String("local_storage"));
- domStorageActionPointer = actionCollectionPointer->addAction(QLatin1String("dom_storage"));
findCaseSensitiveActionPointer = actionCollectionPointer->addAction(QLatin1String("find_case_sensitive"));
hideFindTextActionPointer = actionCollectionPointer->addAction(QLatin1String("hide_find_actions"));
searchEngineBingActionPointer->setCheckable(true);
searchEngineYahooActionPointer->setCheckable(true);
searchEngineCustomActionPointer->setCheckable(true);
+ viewBookmarksToolBarActionPointer->setCheckable(true);
// Instantiate the user agent helper.
UserAgentHelper *userAgentHelperPointer = new UserAgentHelper();
newWindowActionPointer->setText(i18nc("New window action", "New Window"));
zoomDefaultActionPointer->setText(i18nc("Zoom default action", "Zoom Default"));
reloadAndBypassCacheActionPointer->setText(i18nc("Reload and bypass cache action", "Reload and Bypass Cache"));
+ javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
+ localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage"));
+ domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage"));
userAgentPrivacyBrowserActionPointer->setText(userAgentHelperPointer->PRIVACY_BROWSER_TRANSLATED);
userAgentWebEngineDefaultActionPointer->setText(userAgentHelperPointer->WEB_ENGINE_DEFAULT_TRANSLATED);
userAgentFirefoxLinuxActionPointer->setText(userAgentHelperPointer->FIREFOX_LINUX_TRANSLATED);
searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
+ viewBookmarksToolBarActionPointer->setText(i18nc("View bookmarks toolbar", "View Bookmarks Toolbar"));
domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", 0));
- javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
- localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage"));
- domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage"));
findCaseSensitiveActionPointer->setText(i18nc("Find Case Sensitive action", "Find Case Sensitive"));
hideFindTextActionPointer->setText(i18nc("Hide Find Text action (the text should include the language-specific escape keyboard shortcut).", "Hide Find Text (Esc)"));
reloadAndBypassCacheActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-refresh")));
viewSourceActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-choose"), QIcon::fromTheme(QLatin1String("accessories-text-editor"))));
viewSourceInNewTabActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-choose"), QIcon::fromTheme(QLatin1String("accessories-text-editor"))));
+ domStorageActionPointer->setIcon(QIcon::fromTheme(QLatin1String("code-class"), QIcon(QLatin1String("/usr/share/icons/gnome/32x32/actions/gtk-unindent-ltr.png"))));
userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode.svg"));
userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QLatin1String("qtlogo"), QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new")))));
userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr"), QIcon::fromTheme(QLatin1String("user-group-properties"),
searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QLatin1String("im-yahoo"), QIcon::fromTheme(QLatin1String("edit-find"))));
searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QLatin1String("edit-find")));
zoomFactorActionPointer->setIcon(QIcon::fromTheme(QLatin1String("zoom-fit-best")));
+ viewBookmarksToolBarActionPointer->setIcon(QIcon::fromTheme(QLatin1String("bookmarks")));
domainSettingsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("settings-configure"), QIcon::fromTheme(QLatin1String("preferences-desktop"))));
cookiesActionPointer->setIcon(QIcon::fromTheme(QLatin1String("preferences-web-browser-cookies"), QIcon::fromTheme(QLatin1String("appointment-new"))));
- domStorageActionPointer->setIcon(QIcon::fromTheme(QLatin1String("code-class"), QIcon(QLatin1String("/usr/share/icons/gnome/32x32/actions/gtk-unindent-ltr.png"))));
findCaseSensitiveActionPointer->setIcon(QIcon::fromTheme(QLatin1String("format-text-lowercase"), QIcon::fromTheme(QLatin1String("/usr/share/icons/gnome/32x32/apps/fonts.png"))));
hideFindTextActionPointer->setIcon(QIcon::fromTheme(QLatin1String("window-close-symbolic")));
QKeySequence ctrlShiftBKeySequence = QKeySequence(i18nc("The Bing search engine key sequence.", "Ctrl+Shift+B"));
QKeySequence ctrlShiftYKeySequence = QKeySequence(i18nc("The Yahoo search engine key sequence.", "Ctrl+Shift+Y"));
QKeySequence ctrlShiftCKeySequence = QKeySequence(i18nc("The custom search engine key sequence.", "Ctrl+Shift+C"));
+ QKeySequence ctrlAltShiftBKeySequence = QKeySequence(i18nc("The edit bookmarks key sequence.", "Ctrl+Alt+Shift+B"));
+ QKeySequence ctrlAltBKeySequence = QKeySequence(i18nc("The view bookmarks toolbar key sequence.", "Ctrl+Alt+B"));
QKeySequence ctrlShiftDKeySequence = QKeySequence(i18nc("The domain settings key sequence.", "Ctrl+Shift+D"));
QKeySequence ctrlSemicolonKeySequence = QKeySequence(i18nc("The cookies dialog key sequence.", "Ctrl+;"));
actionCollectionPointer->setDefaultShortcut(searchEngineBingActionPointer, ctrlShiftBKeySequence);
actionCollectionPointer->setDefaultShortcut(searchEngineYahooActionPointer, ctrlShiftYKeySequence);
actionCollectionPointer->setDefaultShortcut(searchEngineCustomActionPointer, ctrlShiftCKeySequence);
+ actionCollectionPointer->setDefaultShortcut(editBookmarksActionPointer, ctrlAltShiftBKeySequence);
+ actionCollectionPointer->setDefaultShortcut(viewBookmarksToolBarActionPointer, ctrlAltBKeySequence);
actionCollectionPointer->setDefaultShortcut(domainSettingsActionPointer, ctrlShiftDKeySequence);
actionCollectionPointer->setDefaultShortcut(cookiesActionPointer, ctrlSemicolonKeySequence);
connect(viewSourceActionPointer, SIGNAL(triggered()), this, SLOT(toggleViewSource()));
connect(viewSourceInNewTabActionPointer, SIGNAL(triggered()), this, SLOT(toggleViewSourceInNewTab()));
connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
+ connect(viewBookmarksToolBarActionPointer, SIGNAL(triggered()), this, SLOT(toggleViewBookmarksToolBar()));
connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
// Get handles for the toolbars.
navigationToolBarPointer = toolBar(QLatin1String("navigation_toolbar"));
urlToolBarPointer = toolBar(QLatin1String("url_toolbar"));
+ bookmarksToolBarPointer = toolBar(QLatin1String("bookmarks_toolbar"));
+
+ // Populate the view bookmarks toolbar checkbox.
+ connect(bookmarksToolBarPointer, SIGNAL(visibilityChanged(bool)), this, SLOT(updateViewBookmarksToolBarCheckbox(bool)));
// Create the line edits.
urlLineEditPointer = new KLineEdit();
connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger()));
connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape()));
+ // Get a handle for the Bookmarks menu.
+ bookmarksMenuPointer = qobject_cast<QMenu*>(guiFactory()->container("bookmarks", this));
+
+ // Add a separator to the bookmarks menu.
+ bookmarksMenuPointer->addSeparator();
+
+ // Initialize the current bookmarks lists.
+ bookmarksMenuCurrentActionList = QList<QAction*>();
+ bookmarksToolBarCurrentActionList = QList<QAction*>();
+
+ // Populate the bookmarks.
+ populateBookmarks();
+
// 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.
updateJavaScriptAction(Settings::javaScriptEnabled());
tabWidgetPointer->loadInitialWebsite();
}
+void BrowserWindow::addBookmark() const
+{
+ // Instantiate an add bookmark dialog.
+ AddBookmarkDialog *addBookmarkDialogPointer = new AddBookmarkDialog(tabWidgetPointer->getCurrentTabTitle(), tabWidgetPointer->getCurrentTabUrl(), tabWidgetPointer->getCurrentTabFavoritIcon());
+
+ // Show the dialog.
+ addBookmarkDialogPointer->show();
+}
+
void BrowserWindow::addOrEditDomainSettings() const
{
// Remove the focus from the URL line edit.
updateZoomActions(currentZoomFactor);
}
+void BrowserWindow::editBookmarks() const
+{
+ // Instantiate an edit bookmarks dialog.
+ BookmarksDialog *bookmarksDialogPointer = new BookmarksDialog();
+
+ // Update the displayed bookmarks when edited.
+ connect(bookmarksDialogPointer, SIGNAL(bookmarkUpdated()), this, SLOT(populateBookmarks()));
+
+ // Show the dialog.
+ bookmarksDialogPointer->show();
+}
+
void BrowserWindow::escape() const
{
// Process the escape according to the status of the browser.
// Toggle full screen mode.
if (toggleOn) // Turn full screen mode on.
{
- // Set the window to be full screen.
+ // Enable full screen mode.
fullScreenActionPointer->setFullScreen(window(), true);
- // Hide all the bars.
- menuBar()->setVisible(false);
- navigationToolBarPointer->setVisible(false);
- urlToolBarPointer->setVisible(false);
- tabWidgetPointer->setTabBarVisible(false);
- statusBar()->setVisible(false);
+ // Hide the menu bar if specified.
+ if (Settings::fullScreenHideMenuBar())
+ menuBar()->setVisible(false);
+
+ // Hide the toolbars if specified.
+ if (Settings::fullScreenHideToolBars())
+ {
+ navigationToolBarPointer->setVisible(false);
+ urlToolBarPointer->setVisible(false);
+ bookmarksToolBarPointer->setVisible(false);
+ }
+
+ // Hide the tab bar if specified.
+ if (Settings::fullScreenHideTabBar())
+ tabWidgetPointer->setTabBarVisible(false);
+
+ // Hide the status bar if specified.
+ if (Settings::fullScreenHideStatusBar())
+ statusBar()->setVisible(false);
}
- else // Turn full screen mode off.
+ else // Disable full screen browsing mode.
{
- // Set the window to not be full screen.
+ // Disable full screen mode.
fullScreenActionPointer->setFullScreen(window(), false);
- // Show all the bars.
+ // Show the menu bar.
menuBar()->setVisible(true);
+
+ // Show the toolbars.
navigationToolBarPointer->setVisible(true);
urlToolBarPointer->setVisible(true);
+
+ // Only show the bookmarks toolbar if it was previously visible.
+ if (bookmarksToolBarIsVisible)
+ bookmarksToolBarPointer->setVisible(true);
+
+ // Show the tab bar.
tabWidgetPointer->setTabBarVisible(true);
+
+ // Show the status bar.
statusBar()->setVisible(true);
}
}
(new BrowserWindow)->show();
}
+void BrowserWindow::populateBookmarks()
+{
+ // Remove all the current menu bookmarks.
+ for (QAction *bookmarkAction : bookmarksMenuCurrentActionList)
+ {
+ // Remove the bookmark.
+ bookmarksMenuPointer->removeAction(bookmarkAction);
+ }
+
+ // Remove all the current toolbar bookmarks.
+ for (QAction *bookmarkAction : bookmarksToolBarCurrentActionList)
+ {
+ // Remove the bookmark.
+ bookmarksToolBarPointer->removeAction(bookmarkAction);
+ }
+
+ // Clear the current bookmark lists.
+ bookmarksMenuCurrentActionList.clear();
+ bookmarksToolBarCurrentActionList.clear();
+
+ // Get a list of the bookmarks.
+ std::list<BookmarkStruct> *bookmarkListPointer = BookmarksDatabase::getBookmarks();
+
+ // Populate the bookmarks menu.
+ for (BookmarkStruct bookmarkStruct : *bookmarkListPointer)
+ {
+ // Get the bookmark URL.
+ QString bookmarkUrl = bookmarkStruct.bookmarkUrl;
+
+ // Add the bookmark to the menu.
+ QAction *menuBookmarkActionPointer = bookmarksMenuPointer->addAction(bookmarkStruct.favoriteIcon, bookmarkStruct.bookmarkName, [=]
+ {
+ // Remove the focus from the URL line edit.
+ urlLineEditPointer->clearFocus();
+
+ // Load the URL.
+ tabWidgetPointer->loadUrlFromLineEdit(bookmarkUrl);
+ }
+ );
+
+ // Add the bookmark to the toolbar.
+ QAction *toolBarBookmarkActionPointer = bookmarksToolBarPointer->addAction(bookmarkStruct.favoriteIcon, bookmarkStruct.bookmarkName, [=]
+ {
+ // Remove the focus from the URL line edit.
+ urlLineEditPointer->clearFocus();
+
+ // Load the URL.
+ tabWidgetPointer->loadUrlFromLineEdit(bookmarkUrl);
+ }
+ );
+
+ // Add the actions to the current bookmarks lists.
+ bookmarksMenuCurrentActionList.append(menuBookmarkActionPointer);
+ bookmarksToolBarCurrentActionList.append(toolBarBookmarkActionPointer);
+ }
+
+ // Get a handle for the bookmark toolbar layout.
+ QLayout *bookmarksToolBarLayoutPointer = bookmarksToolBarPointer->layout();
+
+ // Get the count of the bookmarks.
+ int bookmarkCount = bookmarksToolBarLayoutPointer->count();
+
+ // Set the layout of each bookmark to be left aligned.
+ for(int i = 0; i < bookmarkCount; ++i)
+ bookmarksToolBarLayoutPointer->itemAt(i)->setAlignment(Qt::AlignLeft);
+}
+
void BrowserWindow::refresh() const
{
// Remove the focus from the URL line edit.
void BrowserWindow::toggleFullScreen()
{
// Toggle the full screen status.
- if (fullScreenActionPointer->isChecked()) // Enable full screen browsing mode.
- {
- // Enable full screen mode.
- fullScreenActionPointer->setFullScreen(window(), true);
-
- // Hide the menu bar if specified.
- if (Settings::fullScreenHideMenuBar())
- menuBar()->setVisible(false);
-
- // Hide the toolbars if specified.
- if (Settings::fullScreenHideToolBars())
- {
- navigationToolBarPointer->setVisible(false);
- urlToolBarPointer->setVisible(false);
- }
-
- // Hide the tab bar if specified.
- if (Settings::fullScreenHideTabBar())
- tabWidgetPointer->setTabBarVisible(false);
-
- // Hide the status bar if specified.
- if (Settings::fullScreenHideStatusBar())
- statusBar()->setVisible(false);
- }
- else // Disable full screen browsing mode.
- {
- // Disable full screen mode.
- fullScreenActionPointer->setFullScreen(window(), false);
-
- // Show the menu bar.
- menuBar()->setVisible(true);
-
- // Show the toolbars.
- navigationToolBarPointer->setVisible(true);
- urlToolBarPointer->setVisible(true);
-
- // Show the tab bar.
- tabWidgetPointer->setTabBarVisible(true);
-
- // Show the status bar.
- statusBar()->setVisible(true);
- }
+ fullScreenRequested(fullScreenActionPointer->isChecked());
}
void BrowserWindow::toggleViewSource() const
loadUrlFromLineEdit(url);
}
+void BrowserWindow::toggleViewBookmarksToolBar()
+{
+ // Store the current status of the bookmarks toolbar, which is used when exiting full screen browsing.
+ bookmarksToolBarIsVisible = viewBookmarksToolBarActionPointer->isChecked();
+
+ // Update the visibility of the bookmarks toolbar.
+ bookmarksToolBarPointer->setVisible(bookmarksToolBarIsVisible);
+}
+
void BrowserWindow::toggleViewSourceInNewTab() const
{
// Get the current URL.
userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
}
+void BrowserWindow::updateViewBookmarksToolBarCheckbox(const bool visible)
+{
+ // Update the view bookmarks toolbar checkbox.
+ viewBookmarksToolBarActionPointer->setChecked(visible);
+
+ // Initialize the bookmarks toolbar visibility tracker if Privacy Browser has just launched.
+ if (bookmarksToolBarUninitialized)
+ {
+ // Set the initialization flag.
+ bookmarksToolBarUninitialized = false;
+
+ // Store the current status of the bookmarks toolbar, which is used when exiting full screen browsing.
+ bookmarksToolBarIsVisible = visible;
+ }
+}
+
void BrowserWindow::updateWindowTitle(const QString &title)
{
// Update the window title.
// KDE Frameworks headers.
#include <KConfigDialog>
#include <KToggleFullScreenAction>
+#include <KToolBar>
#include <KXmlGuiWindow>
// Qt toolkit headers.
private Q_SLOTS:
// The private slots.
+ void addBookmark() const;
void addOrEditDomainSettings() const;
void back() const;
void clearUrlLineEditFocus() const;
void decrementZoom();
+ void editBookmarks() const;
void escape() const;
void findNext() const;
void findPrevious() const;
void incrementZoom();
void loadUrlFromLineEdit(const QString &url) const;
void newWindow() const;
+ void populateBookmarks();
void refresh() const;
void reloadAndBypassCache() const;
void showCookiesDialog();
void toggleJavaScript() const;
void toggleLocalStorage() const;
void toggleFullScreen();
+ void toggleViewBookmarksToolBar();
void toggleViewSource() const;
void toggleViewSourceInNewTab() const;
void updateCookiesAction(const int numberOfCookies) const;
void updateSearchEngineLabel(const QString &searchEngineString) const;
void updateUrlLineEdit(const QUrl &newUrl);
void updateUserAgentLabel(const QString &userAgentDatabaseName) const;
+ void updateViewBookmarksToolBarCheckbox(const bool visible);
void updateWindowTitle(const QString &title);
void zoomDefault();
private:
// The private variables.
+ QList<QAction*> bookmarksMenuCurrentActionList;
+ QMenu *bookmarksMenuPointer;
+ QList<QAction*> bookmarksToolBarCurrentActionList;
+ KToolBar *bookmarksToolBarPointer;
+ bool bookmarksToolBarIsVisible = false;
+ bool bookmarksToolBarUninitialized = true;
KConfigDialog *configDialogPointer;
QAction *cookiesActionPointer;
QUrl currentUrl;
QAction *userAgentCustomActionPointer;
KLineEdit *urlLineEditPointer;
KToolBar *urlToolBarPointer;
+ QAction *viewBookmarksToolBarActionPointer;
QAction *viewSourceActionPointer;
QAction *viewSourceInNewTabActionPointer;
QAction *zoomDefaultActionPointer;