X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fdatabases%2FBookmarksDatabase.cpp;fp=src%2Fdatabases%2FBookmarksDatabase.cpp;h=1050ba7e903d9ba4fe0ecbdce7efe9aa7dbb03bf;hb=234200f6e94439df6133a8eb61552a68dc9b3a5e;hp=e786eb62accbe5dc04d3bfc20cdc75de65c0a374;hpb=29dbafaca706ea6a34cd881060ebf680378f39b4;p=PrivacyBrowserPC.git diff --git a/src/databases/BookmarksDatabase.cpp b/src/databases/BookmarksDatabase.cpp index e786eb6..1050ba7 100644 --- a/src/databases/BookmarksDatabase.cpp +++ b/src/databases/BookmarksDatabase.cpp @@ -188,6 +188,56 @@ void BookmarksDatabase::deleteBookmark(const int databaseId) deleteBookmarkQuery.exec(); } +void BookmarksDatabase::deleteBookmarks(const QString url) +{ + // Get a handle for the bookmarks database. + QSqlDatabase bookmarksDatabase = QSqlDatabase::database(CONNECTION_NAME); + + // Instantiate a parent folder IDs query. + QSqlQuery parentFolderIdsQuery(bookmarksDatabase); + + // Prepare the parent folder IDs query. + parentFolderIdsQuery.prepare("SELECT " + PARENT_FOLDER_ID + " FROM " + BOOKMARKS_TABLE + " WHERE " + IS_FOLDER + " = 0 AND " + BOOKMARK_URL + " = :url"); + + // Bind the query values. + parentFolderIdsQuery.bindValue(":url", url); + + // Execute the query. + parentFolderIdsQuery.exec(); + + // Instantiate a delete bookmarks query. + QSqlQuery deleteBookmarksQuery(bookmarksDatabase); + + // Prepare the delete bookmark query. + deleteBookmarksQuery.prepare("DELETE FROM " + BOOKMARKS_TABLE + " WHERE " + IS_FOLDER + " = 0 AND " + BOOKMARK_URL + " = :url"); + + // Bind the query values. + deleteBookmarksQuery.bindValue(":url", url); + + // Execute the query. + deleteBookmarksQuery.exec(); + + // Create a parent folder IDs list. A standard list can be sorted and deduplicated. + std::list parentFolderIdsList; + + // Populate the parent folder IDs list. + while (parentFolderIdsQuery.next()) + { + // Add the parent folder ID to the list. + parentFolderIdsList.push_back(parentFolderIdsQuery.value(PARENT_FOLDER_ID).toDouble()); + } + + // Sort the parent folder IDs list. + parentFolderIdsList.sort(); + + // Remove duplicate entries from the parent folder IDs list. + parentFolderIdsList.unique(); + + // Update the display order of each folder where a bookmark was deleted. + for (const double parentFolderId : parentFolderIdsList) + updateFolderContentsDisplayOrder(parentFolderId); +} + double BookmarksDatabase::generateFolderId() { // Get the current time in epoch format (milliseconds). @@ -760,6 +810,33 @@ QList* BookmarksDatabase::getSubfolders(const double folderId) return subfoldersListPointer; } +bool BookmarksDatabase::isBookmarked(const QString url) +{ + // Get a handle for the bookmarks database. + QSqlDatabase bookmarksDatabase = QSqlDatabase::database(CONNECTION_NAME); + + // Instantiate an is bookmarked query. + QSqlQuery isBookmarkedQuery(bookmarksDatabase); + + // Set the query to be forward only, which is more performant. + isBookmarkedQuery.setForwardOnly(true); + + // Prepare the is bookmarked query. + isBookmarkedQuery.prepare("SELECT " + ID + " FROM " + BOOKMARKS_TABLE + " WHERE " + IS_FOLDER + " = 0 AND " + BOOKMARK_URL + " = :url"); + + // Bind the query values. + isBookmarkedQuery.bindValue(":url", url); + + // Execute the query. + isBookmarkedQuery.exec(); + + // Move to the first entry. + isBookmarkedQuery.first(); + + // Return true if the query is valid (there is at least one item). + return isBookmarkedQuery.isValid(); +} + bool BookmarksDatabase::isFolder(const int databaseId) { // Get a handle for the bookmarks database.