]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/dialogs/AddBookmarkDialog.cpp
Partial bookmark implementation. https://redmine.stoutner.com/issues/968
[PrivacyBrowserPC.git] / src / dialogs / AddBookmarkDialog.cpp
diff --git a/src/dialogs/AddBookmarkDialog.cpp b/src/dialogs/AddBookmarkDialog.cpp
new file mode 100644 (file)
index 0000000..cc0d132
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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();
+}
+