MauiKit File Browsing

tagdb.h
1/*
2 * Copyright 2018 Camilo Higuita <milo.h@aol.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#pragma once
21
22#include <QObject>
23
24#include <QString>
25#include <QStringList>
26#include <QVariantMap>
27#include <QSqlDatabase>
28
29#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
30#include <MauiKit3/Core/fmh.h>
31#else
32#include <MauiKit4/Core/fmh.h>
33#endif
34
35#include "fmstatic.h"
36
37#include "filebrowsing_export.h"
38
39/**
40 * @private
41 */
42namespace TAG
43{
44 enum class TABLE : uint8_t { APP_TAGS, TAGS, TAGS_URLS, APPS, NONE };
45
46 static const QMap<TABLE, QString> TABLEMAP = {{TABLE::TAGS, QStringLiteral("tags")},
47 {TABLE::TAGS_URLS, QStringLiteral("tags_urls")},
48 {TABLE::APP_TAGS, QStringLiteral("app_tags")},
49 {TABLE::APPS, QStringLiteral("apps")}};
50
51 static const QString TaggingPath = FMStatic::DataPath + QStringLiteral("/maui/tagging/");
52 static const QString DBName = QStringLiteral("tagging-v2.db");
53}
54
55/**
56 * @brief The TAGDB class exposes methods to add, remove and modify tags in the MauiKit FileBrowsing Tagging system.
57 * @warning This class should not be used- use the Tagging object instead, which already wraps this class and exposes most of the functionality needed. In case some functionality is missing, instead of using this class, open a merge request to add the missing functionality to the Tagging class.
58 */
59class FILEBROWSING_EXPORT TAGDB : public QObject
60{
61 Q_OBJECT
62 Q_DISABLE_COPY(TAGDB)
63
64private:
65 QString name;
66 QSqlDatabase m_db;
67
68 void openDB(const QString &name);
69
70 void prepareCollectionDB() const;
71
72 const QSqlDatabase& db() const;
73
74public:
75
76 /**
77 * @private
78 */
79 TAGDB();
80
81 /**
82 * @private
83 */
84 ~TAGDB();
85
86 //Utils
87 /**
88 * @brief Check for the existence of an entry
89 * @param tableName the name of the table
90 * @param searchId the search query
91 * @param search the search value
92 * @return whether the entry exists
93 */
94 bool checkExistance(const QString &tableName, const QString &searchId, const QString &search) const;
95
96 /**
97 * @brief Check if a entry exists given a query
98 * @param queryStr the plain string query
99 * @return whether the entry exists
100 */
101 bool checkExistance(const QString &queryStr) const;
102
103 /**
104 * @brief Retrieve the database query object of a performed a query
105 * @param queryTxt the query to perform
106 * @return the results
107 */
108 QSqlQuery getQuery(const QString &queryTxt) const;
109
110 /**
111 * @brief Return an empty query object to use arbitrary with any query.
112 */
113 QSqlQuery getQuery() const;
114
115 /**
116 * @brief Insert data into the given table
117 * @param tableName table name
118 * @param insertData the data map to be inserted
119 * @return whether the operation was successful
120 */
121 bool insert(const QString &tableName, const QVariantMap &insertData) const;
122
123 /**
124 * @brief Update data in the database
125 * @param tableName the table name
126 * @param updateData the updated data
127 * @param where the key-value to match in the database
128 * @return whether the operation was successful
129 */
130 bool update(const QString &tableName, const FMH::MODEL &updateData, const QVariantMap &where) const;
131
132 /**
133 * @brief Update data in the database
134 * @param table table name
135 * @param column the column name
136 * @param newValue the new value
137 * @param op the operation to match
138 * @param id the value of the operation `op`
139 * @return whether the operation was successful
140 */
141 bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id) const;
142
143 /**
144 * @brief remove
145 * @param tableName
146 * @param removeData
147 * @return
148 */
149 bool remove(const QString &tableName, const FMH::MODEL &removeData) const;
150
151};
152
static const QString DataPath
Standard Data location path
Definition fmstatic.h:398
The TAGDB class exposes methods to add, remove and modify tags in the MauiKit FileBrowsing Tagging sy...
Definition tagdb.h:60
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:51:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.