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#include <MauiKit4/Core/fmh.h>
30
31#include "fmstatic.h"
32
33#include "filebrowsing_export.h"
34
35/**
36 * @private
37 */
38namespace TAG
39{
40 enum class TABLE : uint8_t { APP_TAGS, TAGS, TAGS_URLS, APPS, NONE };
41
42 static const QMap<TABLE, QString> TABLEMAP = {{TABLE::TAGS, QStringLiteral("tags")},
43 {TABLE::TAGS_URLS, QStringLiteral("tags_urls")},
44 {TABLE::APP_TAGS, QStringLiteral("app_tags")},
45 {TABLE::APPS, QStringLiteral("apps")}};
46
47 static const QString TaggingPath = FMStatic::DataPath + QStringLiteral("/maui/tagging/");
48 static const QString DBName = QStringLiteral("tagging-v2.db");
49}
50
51/**
52 * @brief The TAGDB class exposes methods to add, remove and modify tags in the MauiKit FileBrowsing Tagging system.
53 * @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.
54 */
55class FILEBROWSING_EXPORT TAGDB : public QObject
56{
57 Q_OBJECT
58 Q_DISABLE_COPY(TAGDB)
59
60private:
61 QString name;
62 QSqlDatabase m_db;
63
64 void openDB(const QString &name);
65
66 void prepareCollectionDB() const;
67
68 const QSqlDatabase& db() const;
69
70public:
71
72 /**
73 * @private
74 */
75 TAGDB();
76
77 /**
78 * @private
79 */
80 ~TAGDB();
81
82 //Utils
83 /**
84 * @brief Check for the existence of an entry
85 * @param tableName the name of the table
86 * @param searchId the search query
87 * @param search the search value
88 * @return whether the entry exists
89 */
90 bool checkExistance(const QString &tableName, const QString &searchId, const QString &search) const;
91
92 /**
93 * @brief Check if a entry exists given a query
94 * @param queryStr the plain string query
95 * @return whether the entry exists
96 */
97 bool checkExistance(const QString &queryStr) const;
98
99 /**
100 * @brief Retrieve the database query object of a performed a query
101 * @param queryTxt the query to perform
102 * @return the results
103 */
104 QSqlQuery getQuery(const QString &queryTxt) const;
105
106 /**
107 * @brief Return an empty query object to use arbitrary with any query.
108 */
109 QSqlQuery getQuery() const;
110
111 /**
112 * @brief Insert data into the given table
113 * @param tableName table name
114 * @param insertData the data map to be inserted
115 * @return whether the operation was successful
116 */
117 bool insert(const QString &tableName, const QVariantMap &insertData) const;
118
119 /**
120 * @brief Update data in the database
121 * @param tableName the table name
122 * @param updateData the updated data
123 * @param where the key-value to match in the database
124 * @return whether the operation was successful
125 */
126 bool update(const QString &tableName, const FMH::MODEL &updateData, const QVariantMap &where) const;
127
128 /**
129 * @brief Update data in the database
130 * @param table table name
131 * @param column the column name
132 * @param newValue the new value
133 * @param op the operation to match
134 * @param id the value of the operation `op`
135 * @return whether the operation was successful
136 */
137 bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id) const;
138
139 /**
140 * @brief remove
141 * @param tableName
142 * @param removeData
143 * @return
144 */
145 bool remove(const QString &tableName, const FMH::MODEL &removeData) const;
146
147};
148
static const QString DataPath
Standard Data location path
Definition fmstatic.h:392
The TAGDB class exposes methods to add, remove and modify tags in the MauiKit FileBrowsing Tagging sy...
Definition tagdb.h:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:11:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.