X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fdialogs%2FAddBookmarkDialog.cpp;h=e35759b0929393e36b9305d46a1bcf23890ee93a;hb=5e66d268d985552aeeae3e9ae7d0967d359a557f;hp=222a69a2fd71c7c1815e0ae765193df7cdee0772;hpb=f18185adbdce9891be0cbd2197838441aaa5ed3e;p=PrivacyBrowserPC.git diff --git a/src/dialogs/AddBookmarkDialog.cpp b/src/dialogs/AddBookmarkDialog.cpp index 222a69a..e35759b 100644 --- a/src/dialogs/AddBookmarkDialog.cpp +++ b/src/dialogs/AddBookmarkDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -30,7 +30,8 @@ #include // Construct the class. -AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon) : QDialog(nullptr) +AddBookmarkDialog::AddBookmarkDialog(QWidget *parentWidgetPointer, const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon, const double parentFolderId) : + QDialog(parentWidgetPointer) { // Set the window title. setWindowTitle(i18nc("The add bookmark dialog window title.", "Add Bookmark")); @@ -38,54 +39,105 @@ AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString // Set the window modality. setWindowModality(Qt::WindowModality::ApplicationModal); - // Instantiate the bookmarks dialog UI. + // Instantiate the add bookmark dialog UI. Ui::AddBookmarkDialog addBookmarkDialogUi; // Setup the UI. addBookmarkDialogUi.setupUi(this); // Get handles for the widgets. - defaultFavoriteIconRadioButtonPointer = addBookmarkDialogUi.defaultFavoriteIconRadioButton; + websiteFavoriteIconRadioButtonPointer = addBookmarkDialogUi.websiteFavoriteIconRadioButton; customFavoriteIconRadioButtonPointer = addBookmarkDialogUi.customFavoriteIconRadioButton; - bookmarkNamePointer = addBookmarkDialogUi.bookmarkNameLineEdit; - bookmarkUrlPointer = addBookmarkDialogUi.bookmarkUrlLineEdit; + parentFolderTreeWidgetPointer = addBookmarkDialogUi.parentFolderTreeWidget; + bookmarkNameLineEditPointer = addBookmarkDialogUi.bookmarkNameLineEdit; + bookmarkUrlLineEditPointer = addBookmarkDialogUi.bookmarkUrlLineEdit; QPushButton *browseButtonPointer = addBookmarkDialogUi.browseButton; QDialogButtonBox *dialogButtonBoxPointer = addBookmarkDialogUi.dialogButtonBox; - // Set the default favorite icon. - defaultFavoriteIconRadioButtonPointer->setIcon(favoriteIcon); + // Set the icons. + websiteFavoriteIconRadioButtonPointer->setIcon(favoriteIcon); + customFavoriteIconRadioButtonPointer->setIcon(QIcon::fromTheme(QLatin1String("globe"), QIcon::fromTheme(QLatin1String("applications-internet")))); + + // Instantiate a folder helper. + folderHelperPointer = new FolderHelper(); + + // Set the parent folder tree widget column count. + parentFolderTreeWidgetPointer->setColumnCount(2); + + // Hide the second column. + parentFolderTreeWidgetPointer->hideColumn(folderHelperPointer->FOLDER_ID_COLUMN); + + // Set the column header. + parentFolderTreeWidgetPointer->setHeaderLabel(i18nc("The folder tree widget header", "Select Parent Folder")); + + // Create a bookmarks tree widget item. + QTreeWidgetItem *bookmarksTreeWidgetItemPointer = new QTreeWidgetItem(); + + // Populate the bookmarks tree widget item. + bookmarksTreeWidgetItemPointer->setText(folderHelperPointer->FOLDER_NAME_COLUMN, i18nc("The bookmarks root tree widget name", "Bookmarks")); + bookmarksTreeWidgetItemPointer->setIcon(folderHelperPointer->FOLDER_NAME_COLUMN, QIcon::fromTheme(QLatin1String("bookmarks"), QIcon::fromTheme(QLatin1String("bookmark-new")))); + bookmarksTreeWidgetItemPointer->setText(folderHelperPointer->FOLDER_ID_COLUMN, QLatin1String("0")); + + // Add the bookmarks tree widget item to the root of the tree. + parentFolderTreeWidgetPointer->addTopLevelItem(bookmarksTreeWidgetItemPointer); + + // Select the root bookmarks folder if it is the initial parent folder. + if (parentFolderId == 0) + bookmarksTreeWidgetItemPointer->setSelected(true); + + // Populate the subfolders. + folderHelperPointer->populateSubfolders(bookmarksTreeWidgetItemPointer, parentFolderId); + + // Open all the folders. + parentFolderTreeWidgetPointer->expandAll(); // Populate the line edits. - bookmarkNamePointer->setText(bookmarkName); - bookmarkUrlPointer->setText(bookmarkUrl); + bookmarkNameLineEditPointer->setText(bookmarkName); + bookmarkUrlLineEditPointer->setText(bookmarkUrl); + + // Scroll to the beginning of the bookmark URL line edit. + bookmarkUrlLineEditPointer->setCursorPosition(0); - // Scroll to the beginning of the line edits. - bookmarkNamePointer->setCursorPosition(0); - bookmarkUrlPointer->setCursorPosition(0); + // Focus the bookmark name line edit. + bookmarkNameLineEditPointer->setFocus(); // Add buttons to the dialog button box. - QPushButton *addBookmarkButtonPointer = dialogButtonBoxPointer->addButton(i18nc("The add bookmark button", "Add"), QDialogButtonBox::AcceptRole); + addButtonPointer = dialogButtonBoxPointer->addButton(i18nc("The add bookmark button", "Add"), QDialogButtonBox::AcceptRole); // Set the button icons. - addBookmarkButtonPointer->setIcon(QIcon::fromTheme("list-add")); + addButtonPointer->setIcon(QIcon::fromTheme("list-add")); // Connect the buttons. connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(browse())); connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(addBookmark())); connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject())); + + // Update the UI when the line edits change. + connect(bookmarkNameLineEditPointer, SIGNAL(textEdited(const QString&)), this, SLOT(updateUi())); + connect(bookmarkUrlLineEditPointer, SIGNAL(textEdited(const QString&)), this, SLOT(updateUi())); + + // Set the initial UI status. + updateUi(); } void AddBookmarkDialog::addBookmark() { + // Get the selected folders list. + QList selectedFoldersList = parentFolderTreeWidgetPointer->selectedItems(); + + // Get the selected folder. + QTreeWidgetItem *selectedFolderPointer = selectedFoldersList.first(); + // Get the favorite icon. - QIcon favoriteIcon = defaultFavoriteIconRadioButtonPointer->isChecked() ? defaultFavoriteIconRadioButtonPointer->icon() : customFavoriteIconRadioButtonPointer->icon(); + QIcon favoriteIcon = websiteFavoriteIconRadioButtonPointer->isChecked() ? websiteFavoriteIconRadioButtonPointer->icon() : customFavoriteIconRadioButtonPointer->icon(); // Create a bookmark struct. BookmarkStruct *bookmarkStructPointer = new BookmarkStruct; // Populate the bookmark struct. - bookmarkStructPointer->bookmarkName = bookmarkNamePointer->text(); - bookmarkStructPointer->bookmarkUrl = bookmarkUrlPointer->text(); + bookmarkStructPointer->name = bookmarkNameLineEditPointer->text(); + bookmarkStructPointer->url = bookmarkUrlLineEditPointer->text(); + bookmarkStructPointer->parentFolderId = selectedFolderPointer->text(folderHelperPointer->FOLDER_ID_COLUMN).toDouble(); bookmarkStructPointer->favoriteIcon = favoriteIcon; // Add the bookmark. @@ -114,3 +166,18 @@ void AddBookmarkDialog::browse() customFavoriteIconRadioButtonPointer->setChecked(true); } } + +void AddBookmarkDialog::updateUi() +{ + // Determine if both line edits are populated. + if (bookmarkNameLineEditPointer->text().isEmpty() || bookmarkUrlLineEditPointer->text().isEmpty()) // At least one of the line edits is empty. + { + // Disable the add button. + addButtonPointer->setEnabled(false); + } + else // Both of the line edits are populated. + { + // Enable the add button. + addButtonPointer->setEnabled(true); + } +}