X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fdialogs%2FEditBookmarkDialog.cpp;fp=src%2Fdialogs%2FEditBookmarkDialog.cpp;h=35582f18b3811907ee3e04585e41027e4e6e80a1;hp=0000000000000000000000000000000000000000;hb=f18185adbdce9891be0cbd2197838441aaa5ed3e;hpb=7c6edb3608791950c6146ac242e2b6f493ca8e8c diff --git a/src/dialogs/EditBookmarkDialog.cpp b/src/dialogs/EditBookmarkDialog.cpp new file mode 100644 index 0000000..35582f1 --- /dev/null +++ b/src/dialogs/EditBookmarkDialog.cpp @@ -0,0 +1,123 @@ +/* + * 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 "EditBookmarkDialog.h" +#include "ui_EditBookmarkDialog.h" +#include "databases/BookmarksDatabase.h" + +// Qt toolkit headers. +#include + +// Construct the class. +EditBookmarkDialog::EditBookmarkDialog(const int bookmarkId, QIcon ¤tWebsiteFavoriteIcon) : QDialog(nullptr), bookmarkDatabaseId(bookmarkId) +{ + // Set the window title. + setWindowTitle(i18nc("The edit bookmark dialog window title.", "Edit Bookmark")); + + // Set the window modality. + setWindowModality(Qt::WindowModality::ApplicationModal); + + // Instantiate the bookmarks dialog UI. + Ui::EditBookmarkDialog editBookmarkDialogUi; + + // Setup the UI. + editBookmarkDialogUi.setupUi(this); + + // Get handles for the widgets. + currentFavoriteIconRadioButtonPointer = editBookmarkDialogUi.currentFavoriteIconRadioButton; + currentWebsiteFavoritIconRadioButtonPointer = editBookmarkDialogUi.currentWebsiteFavoriteIconRadioButton; + customFavoriteIconRadioButtonPointer = editBookmarkDialogUi.customFavoriteIconRadioButton; + bookmarkNamePointer = editBookmarkDialogUi.bookmarkNameLineEdit; + bookmarkUrlPointer = editBookmarkDialogUi.bookmarkUrlLineEdit; + QPushButton *browseButtonPointer = editBookmarkDialogUi.browseButton; + QDialogButtonBox *dialogButtonBoxPointer = editBookmarkDialogUi.dialogButtonBox; + + // Get the bookmark struct. + bookmarkStructPointer = BookmarksDatabase::getBookmark(bookmarkId); + + // Set the favorite icons. + currentFavoriteIconRadioButtonPointer->setIcon(bookmarkStructPointer->favoriteIcon); + currentWebsiteFavoritIconRadioButtonPointer->setIcon(currentWebsiteFavoriteIcon); + + // Populate the line edits. + bookmarkNamePointer->setText(bookmarkStructPointer->bookmarkName); + bookmarkUrlPointer->setText(bookmarkStructPointer->bookmarkUrl); + + // Scroll to the beginning of the line edits. + bookmarkNamePointer->setCursorPosition(0); + bookmarkUrlPointer->setCursorPosition(0); + + // Connect the buttons. + connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(browse())); + connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(save())); + connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject())); +} + +void EditBookmarkDialog::browse() +{ + // Get an image file string from the user. + QString imageFileString = QFileDialog::getOpenFileName(this, tr("Favorite Icon Image"), QDir::homePath(), + tr("Image Files — *.bmp, *.gif, *.jpg, *.jpeg, *.png, *.svg (*.bmp *.gif *.jpg *.jpeg *.png *.svg);;All Files (*)")); + + // Check to see if an image file string was returned. This will be empty if the user selected cancel. + if (!imageFileString.isEmpty()) + { + // Set the custom favorite icon. + customFavoriteIconRadioButtonPointer->setIcon(QIcon(imageFileString)); + + // Check the custom favorite icon radio button. + customFavoriteIconRadioButtonPointer->setChecked(true); + } +} + +void EditBookmarkDialog::save() +{ + // Create a favorite icon. + QIcon favoriteIcon; + + // Get the favorite icon. + if (currentFavoriteIconRadioButtonPointer->isChecked()) // The current favorite icon is checked. + favoriteIcon = currentFavoriteIconRadioButtonPointer->icon(); + else if (currentWebsiteFavoritIconRadioButtonPointer->isChecked()) // The current website favorite icon is checked. + favoriteIcon = currentWebsiteFavoritIconRadioButtonPointer->icon(); + else // The custom favorite icon is checked. + favoriteIcon = customFavoriteIconRadioButtonPointer->icon(); + + qDebug() << "Favorite icon: " << favoriteIcon; + + // Create a bookmark struct. + BookmarkStruct *bookmarkStructPointer = new BookmarkStruct; + + // Populate the bookmark struct. + bookmarkStructPointer->id = bookmarkDatabaseId; + bookmarkStructPointer->bookmarkName = bookmarkNamePointer->text(); + bookmarkStructPointer->bookmarkUrl = bookmarkUrlPointer->text(); + bookmarkStructPointer->displayOrder = bookmarkStructPointer->displayOrder; + bookmarkStructPointer->favoriteIcon = favoriteIcon; + + // Update the bookmark. + BookmarksDatabase::updateBookmark(bookmarkStructPointer); + + // Emit the bookmark saved signal. + emit bookmarkSaved(); + + // Close the dialog. + close(); +}