]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/dialogs/EditFolderDialog.cpp
Block all CSP requests. https://redmine.stoutner.com/issues/1193
[PrivacyBrowserPC.git] / src / dialogs / EditFolderDialog.cpp
index 4d332cea30d1061967a5e79b7ae7b206ec39adef..5ad5f0582e877f7c0f12373fd3743048bdc81fc7 100644 (file)
@@ -1,20 +1,20 @@
-/*
- * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+/* SPDX-License-Identifier: GPL-3.0-or-later
+ * SPDX-FileCopyrightText: 2023-2024 Soren Stoutner <soren@stoutner.com>
  *
- * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/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.
+ * This program 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.
+ * This program 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 <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 // Application headers.
@@ -26,7 +26,7 @@
 #include <QFileDialog>
 
 // Construct the class.
-EditFolderDialog::EditFolderDialog(const int databaseId, QIcon &currentWebsiteFavoriteIcon) : QDialog(nullptr), folderDatabaseId(databaseId)
+EditFolderDialog::EditFolderDialog(QWidget *parentWidgetPointer, const int databaseId, QIcon &currentWebsiteFavoriteIcon) : QDialog(parentWidgetPointer), folderDatabaseId(databaseId)
 {
     // Set the window title.
     setWindowTitle(i18nc("The edit folder dialog window title.", "Edit Folder"));
@@ -42,6 +42,7 @@ EditFolderDialog::EditFolderDialog(const int databaseId, QIcon &currentWebsiteFa
 
     // Get handles for the widgets.
     currentFolderIconRadioButtonPointer = editFolderDialogUi.currentFolderIconRadioButton;
+    defaultFolderIconRadioButtonPointer = editFolderDialogUi.defaultFolderIconRadioButton;
     currentWebsiteFavoriteIconRadioButtonPointer = editFolderDialogUi.currentWebsiteFavoriteIconRadioButton;
     customFolderIconRadioButtonPointer = editFolderDialogUi.customFolderIconRadioButton;
     parentFolderTreeWidgetPointer = editFolderDialogUi.parentFolderTreeWidget;
@@ -50,11 +51,11 @@ EditFolderDialog::EditFolderDialog(const int databaseId, QIcon &currentWebsiteFa
     QDialogButtonBox *dialogButtonBoxPointer = editFolderDialogUi.dialogButtonBox;
     saveButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::Save);
 
-    // Get the bookmark struct.
-    bookmarkStructPointer = BookmarksDatabase::getBookmark(databaseId);
+    // Get the folder bookmark struct.
+    folderBookmarkStructPointer = BookmarksDatabase::getBookmark(databaseId);
 
     // Set the folder icons.
-    currentFolderIconRadioButtonPointer->setIcon(bookmarkStructPointer->favoriteIcon);
+    currentFolderIconRadioButtonPointer->setIcon(folderBookmarkStructPointer->favoriteIcon);
     currentWebsiteFavoriteIconRadioButtonPointer->setIcon(currentWebsiteFavoriteIcon);
 
     // Instantiate a folder helper.
@@ -74,27 +75,27 @@ EditFolderDialog::EditFolderDialog(const int databaseId, QIcon &currentWebsiteFa
 
     // 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("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 (bookmarkStructPointer->parentFolderId == 0)
+    if (folderBookmarkStructPointer->parentFolderId == 0)
         bookmarksTreeWidgetItemPointer->setSelected(true);
 
     // Populate the subfolders, except for the one being edited.
-    folderHelperPointer->populateSubfoldersExcept(databaseId, bookmarksTreeWidgetItemPointer, bookmarkStructPointer->parentFolderId);
+    folderHelperPointer->populateSubfoldersExcept(databaseId, bookmarksTreeWidgetItemPointer, folderBookmarkStructPointer->parentFolderId);
 
     // Open all the folders.
     parentFolderTreeWidgetPointer->expandAll();
 
     // Populate the line edits.
-    folderNameLineEditPointer->setText(bookmarkStructPointer->name);
+    folderNameLineEditPointer->setText(folderBookmarkStructPointer->name);
 
-    // Scroll to the beginning of the line edits.
-    folderNameLineEditPointer->setCursorPosition(0);
+    // Focus the folder name line edit.
+    folderNameLineEditPointer->setFocus();
 
     // Connect the buttons.
     connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(browse()));
@@ -136,11 +137,14 @@ void EditFolderDialog::save()
     // Get the parent folder ID.
     double parentFolderId = selectedFolderPointer->text(folderHelperPointer->FOLDER_ID_COLUMN).toDouble();
 
+    // Determine if it has moved to a new folder.
+    bool movedToNewFolder =  parentFolderId != folderBookmarkStructPointer->parentFolderId;
+
     // Get the original display order.
-    int displayOrder = bookmarkStructPointer->displayOrder;
+    int displayOrder = folderBookmarkStructPointer->displayOrder;
 
     // Get the new display order if the parent folder has changed.
-    if (parentFolderId != bookmarkStructPointer->parentFolderId)
+    if (movedToNewFolder)
         displayOrder = BookmarksDatabase::getFolderItemCount(parentFolderId);
 
     // Create a favorite icon.
@@ -149,6 +153,8 @@ void EditFolderDialog::save()
     // Get the favorite icon.
     if (currentFolderIconRadioButtonPointer->isChecked())  // The current folder icon is checked.
         favoriteIcon = currentFolderIconRadioButtonPointer->icon();
+    else if (defaultFolderIconRadioButtonPointer->isChecked())  // The default folder icon is checked.
+        favoriteIcon = defaultFolderIconRadioButtonPointer->icon();
     else if (currentWebsiteFavoriteIconRadioButtonPointer->isChecked())  // The current website favorite icon is checked.
         favoriteIcon = currentWebsiteFavoriteIconRadioButtonPointer->icon();
     else  // The custom favorite icon is checked.
@@ -167,11 +173,12 @@ void EditFolderDialog::save()
     // Update the folder.
     BookmarksDatabase::updateBookmark(updatedBookmarkStructPointer);
 
-    // Update the display order of all the items in the previous folder.
-    BookmarksDatabase::updateFolderContentsDisplayOrder(bookmarkStructPointer->parentFolderId);
+    // Update the display order of all the items in the previous folder if it has moved to a new folder.
+    if (movedToNewFolder)
+        BookmarksDatabase::updateFolderContentsDisplayOrder(folderBookmarkStructPointer->parentFolderId);
 
     // Emit the folder saved signal.
-    emit folderSaved();
+    Q_EMIT folderSaved();
 
     // Close the dialog.
     close();