2 * Copyright 2023-2024 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
6 * Privacy Browser PC is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser PC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
20 // Application headers.
21 #include "FolderHelper.h"
22 #include "databases/BookmarksDatabase.h"
23 #include "structs/BookmarkStruct.h"
25 // Construct the class.
26 FolderHelper::FolderHelper() {}
28 void FolderHelper::populateSubfolders(QTreeWidgetItem *treeWidgetItemPointer, const double initialParentFolderId)
30 // Get the list of subfolders.
31 QList<BookmarkStruct> *subfoldersList = BookmarksDatabase::getSubfolders(treeWidgetItemPointer->text(FOLDER_ID_COLUMN).toDouble());
33 // Populate each subfolder.
34 for (BookmarkStruct bookmarkStruct : *subfoldersList)
36 // Create a tree widget item.
37 QTreeWidgetItem *subfolderWidgetItemPointer = new QTreeWidgetItem();
39 // Populate the tree widget item.
40 subfolderWidgetItemPointer->setText(FOLDER_NAME_COLUMN, bookmarkStruct.name);
41 subfolderWidgetItemPointer->setIcon(FOLDER_NAME_COLUMN, bookmarkStruct.favoriteIcon);
42 subfolderWidgetItemPointer->setText(FOLDER_ID_COLUMN, QString::number(bookmarkStruct.folderId, 'f', 0)); // Format the folder ID as a floating point with no trailing zeros.
44 // Add the subfolder to the tree widget item.
45 treeWidgetItemPointer->addChild(subfolderWidgetItemPointer);
47 // Select the folder if it is the initial parent folder.
48 if (bookmarkStruct.folderId == initialParentFolderId)
49 subfolderWidgetItemPointer->setSelected(true);
51 // Add any subfolders.
52 populateSubfolders(subfolderWidgetItemPointer, initialParentFolderId);
56 void FolderHelper::populateSubfoldersExcept(const double exceptSubfolderDatabaseId, QTreeWidgetItem *treeWidgetItemPointer, const double initialParentFolderId)
58 // Get the list of subfolders.
59 QList<BookmarkStruct> *subfoldersList = BookmarksDatabase::getSubfolders(treeWidgetItemPointer->text(FOLDER_ID_COLUMN).toDouble());
61 // Populate each subfolder.
62 for (BookmarkStruct bookmarkStruct : *subfoldersList)
64 // Determine if this is an excepted folder.
65 bool exceptedFolder = bookmarkStruct.databaseId == exceptSubfolderDatabaseId;
67 // Create a tree widget item.
68 QTreeWidgetItem *subfolderWidgetItemPointer = new QTreeWidgetItem();
70 // Populate the tree widget item.
71 subfolderWidgetItemPointer->setText(FOLDER_NAME_COLUMN, bookmarkStruct.name);
72 subfolderWidgetItemPointer->setIcon(FOLDER_NAME_COLUMN, bookmarkStruct.favoriteIcon);
73 subfolderWidgetItemPointer->setText(FOLDER_ID_COLUMN, QString::number(bookmarkStruct.folderId, 'f', 0)); // Format the folder ID as a floating point with no trailing zeros.
75 // Disable the folder widget if it is excepted. All subfolders will automatically be disabled.
77 subfolderWidgetItemPointer->setDisabled(true);
79 // Add the subfolder to the tree widget item.
80 treeWidgetItemPointer->addChild(subfolderWidgetItemPointer);
82 // Select the folder if it is the initial parent folder.
83 if (bookmarkStruct.folderId == initialParentFolderId)
84 subfolderWidgetItemPointer->setSelected(true);
86 // Add any subfolders.
87 populateSubfoldersExcept(exceptSubfolderDatabaseId, subfolderWidgetItemPointer, initialParentFolderId);