2 * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
6 * Privacy Browser PC is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser PC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
20 // Application headers.
21 #include "AddBookmarkDialog.h"
22 #include "ui_AddBookmarkDialog.h"
23 #include "databases/BookmarksDatabase.h"
25 // KDE Framework headers.
26 #include <KLocalizedString>
28 // Qt toolkit headers.
29 #include <QPushButton>
31 // Construct the class.
32 AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon) : QDialog(nullptr), icon(favoriteIcon)
34 // Set the window title.
35 setWindowTitle(i18nc("The add bookmark dialog window title.", "Add Bookmark"));
37 // Set the window modality.
38 setWindowModality(Qt::WindowModality::ApplicationModal);
40 // Instantiate the bookmarks dialog UI.
41 Ui::AddBookmarkDialog addBookmarkDialogUi;
44 addBookmarkDialogUi.setupUi(this);
46 // Get handles for the widgets.
47 QGraphicsView *favoriteIconGraphicsViewPointer = addBookmarkDialogUi.favoriteIconGraphicsView;
48 bookmarkNamePointer = addBookmarkDialogUi.bookmarkNameLineEdit;
49 bookmarkUrlPointer = addBookmarkDialogUi.bookmarkUrlLineEdit;
50 QDialogButtonBox *dialogButtonBoxPointer = addBookmarkDialogUi.dialogButtonBox;
52 // Create a graphics scene.
53 QGraphicsScene *favoriteIconGraphicsScenePointer = new QGraphicsScene(this);
55 // Set the graphics scene.
56 favoriteIconGraphicsViewPointer->setScene(favoriteIconGraphicsScenePointer);
58 // Set the background of the graphics view to be the same as the window
59 favoriteIconGraphicsViewPointer->setBackgroundRole(QPalette::Window);
61 // Add the MIME type icon to the scene.
62 favoriteIconGraphicsScenePointer->addPixmap(favoriteIcon.pixmap(32, 32));
64 // Populate the line edits.
65 bookmarkNamePointer->setText(bookmarkName);
66 bookmarkUrlPointer->setText(bookmarkUrl);
68 // Scroll the the beginning of the line edits.
69 bookmarkNamePointer->setCursorPosition(0);
70 bookmarkUrlPointer->setCursorPosition(0);
72 // Add buttons to the dialog button box.
73 QPushButton *addBookmarkButtonPointer = dialogButtonBoxPointer->addButton(i18nc("The add bookmark button", "Add"), QDialogButtonBox::AcceptRole);
75 // Set the button icons.
76 addBookmarkButtonPointer->setIcon(QIcon::fromTheme("list-add"));
78 // Connect the buttons.
79 connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(addBookmark()));
80 connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject()));
83 void AddBookmarkDialog::addBookmark()
86 BookmarksDatabase::addBookmark(bookmarkNamePointer->text(), bookmarkUrlPointer->text(), icon);