-/*
- * 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.
#include <QFileDialog>
// Construct the class.
-EditFolderDialog::EditFolderDialog(const int databaseId, QIcon ¤tWebsiteFavoriteIcon) : QDialog(nullptr), folderDatabaseId(databaseId)
+EditFolderDialog::EditFolderDialog(QWidget *parentWidgetPointer, const int databaseId, QIcon ¤tWebsiteFavoriteIcon) : QDialog(parentWidgetPointer), folderDatabaseId(databaseId)
{
// Set the window title.
setWindowTitle(i18nc("The edit folder dialog window title.", "Edit Folder"));
// Get handles for the widgets.
currentFolderIconRadioButtonPointer = editFolderDialogUi.currentFolderIconRadioButton;
+ defaultFolderIconRadioButtonPointer = editFolderDialogUi.defaultFolderIconRadioButton;
currentWebsiteFavoriteIconRadioButtonPointer = editFolderDialogUi.currentWebsiteFavoriteIconRadioButton;
customFolderIconRadioButtonPointer = editFolderDialogUi.customFolderIconRadioButton;
parentFolderTreeWidgetPointer = editFolderDialogUi.parentFolderTreeWidget;
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.
// 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()));
// 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.
// 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.
// 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();