X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fdialogs%2FAddBookmarkDialog.cpp;fp=src%2Fdialogs%2FAddBookmarkDialog.cpp;h=cc0d132d0c2a41d5b3fbea32a79f5f09be3b8e52;hp=0000000000000000000000000000000000000000;hb=7c6edb3608791950c6146ac242e2b6f493ca8e8c;hpb=697f5cae65577dcdf01cfa85840de8d44d835358 diff --git a/src/dialogs/AddBookmarkDialog.cpp b/src/dialogs/AddBookmarkDialog.cpp new file mode 100644 index 0000000..cc0d132 --- /dev/null +++ b/src/dialogs/AddBookmarkDialog.cpp @@ -0,0 +1,91 @@ +/* + * Copyright 2023 Soren Stoutner . + * + * This file is part of 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 . + */ + +// Application headers. +#include "AddBookmarkDialog.h" +#include "ui_AddBookmarkDialog.h" +#include "databases/BookmarksDatabase.h" + +// KDE Framework headers. +#include + +// Qt toolkit headers. +#include + +// 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(); +} +