]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/dialogs/AddBookmarkDialog.cpp
Partial bookmark implementation. https://redmine.stoutner.com/issues/968
[PrivacyBrowserPC.git] / src / dialogs / AddBookmarkDialog.cpp
1 /*
2  * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 // Application headers.
21 #include "AddBookmarkDialog.h"
22 #include "ui_AddBookmarkDialog.h"
23 #include "databases/BookmarksDatabase.h"
24
25 // KDE Framework headers.
26 #include <KLocalizedString>
27
28 // Qt toolkit headers.
29 #include <QPushButton>
30
31 // Construct the class.
32 AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon) : QDialog(nullptr), icon(favoriteIcon)
33 {
34     // Set the window title.
35     setWindowTitle(i18nc("The add bookmark dialog window title.", "Add Bookmark"));
36
37     // Set the window modality.
38     setWindowModality(Qt::WindowModality::ApplicationModal);
39
40     // Instantiate the bookmarks dialog UI.
41     Ui::AddBookmarkDialog addBookmarkDialogUi;
42
43     // Setup the UI.
44     addBookmarkDialogUi.setupUi(this);
45
46     // Get handles for the widgets.
47     QGraphicsView *favoriteIconGraphicsViewPointer = addBookmarkDialogUi.favoriteIconGraphicsView;
48     bookmarkNamePointer = addBookmarkDialogUi.bookmarkNameLineEdit;
49     bookmarkUrlPointer = addBookmarkDialogUi.bookmarkUrlLineEdit;
50     QDialogButtonBox *dialogButtonBoxPointer = addBookmarkDialogUi.dialogButtonBox;
51
52     // Create a graphics scene.
53     QGraphicsScene *favoriteIconGraphicsScenePointer = new QGraphicsScene(this);
54
55     // Set the graphics scene.
56     favoriteIconGraphicsViewPointer->setScene(favoriteIconGraphicsScenePointer);
57
58     // Set the background of the graphics view to be the same as the window
59     favoriteIconGraphicsViewPointer->setBackgroundRole(QPalette::Window);
60
61     // Add the MIME type icon to the scene.
62     favoriteIconGraphicsScenePointer->addPixmap(favoriteIcon.pixmap(32, 32));
63
64     // Populate the line edits.
65     bookmarkNamePointer->setText(bookmarkName);
66     bookmarkUrlPointer->setText(bookmarkUrl);
67
68     // Scroll the the beginning of the line edits.
69     bookmarkNamePointer->setCursorPosition(0);
70     bookmarkUrlPointer->setCursorPosition(0);
71
72     // Add buttons to the dialog button box.
73     QPushButton *addBookmarkButtonPointer = dialogButtonBoxPointer->addButton(i18nc("The add bookmark button", "Add"), QDialogButtonBox::AcceptRole);
74
75     // Set the button icons.
76     addBookmarkButtonPointer->setIcon(QIcon::fromTheme("list-add"));
77
78     // Connect the buttons.
79     connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(addBookmark()));
80     connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject()));
81 }
82
83 void AddBookmarkDialog::addBookmark()
84 {
85     // Add the bookmark.
86     BookmarksDatabase::addBookmark(bookmarkNamePointer->text(), bookmarkUrlPointer->text(), icon);
87
88     // Close the dialog.
89     close();
90 }
91