Warning, file /maui/mauikit-filebrowsing/src/code/tagdb.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *   Copyright 2018 Camilo Higuita <milo.h@aol.com>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 #pragma once
0021 
0022 #include <QObject>
0023 
0024 #include <QString>
0025 #include <QStringList>
0026 #include <QVariantMap>
0027 #include <QSqlDatabase>
0028 
0029 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0030 #include <MauiKit3/Core/fmh.h>
0031 #else
0032 #include <MauiKit4/Core/fmh.h>
0033 #endif
0034 
0035 #include "fmstatic.h"
0036 
0037 #include "filebrowsing_export.h"
0038 
0039 /**
0040  * @private
0041  */
0042 namespace TAG
0043 {
0044     enum class TABLE : uint8_t { APP_TAGS, TAGS, TAGS_URLS, APPS, NONE };
0045     
0046     static const QMap<TABLE, QString> TABLEMAP = {{TABLE::TAGS, QStringLiteral("tags")},
0047     {TABLE::TAGS_URLS, QStringLiteral("tags_urls")},
0048     {TABLE::APP_TAGS, QStringLiteral("app_tags")},
0049     {TABLE::APPS, QStringLiteral("apps")}};
0050     
0051     static const QString TaggingPath = FMStatic::DataPath + QStringLiteral("/maui/tagging/");
0052     static const QString DBName = QStringLiteral("tagging-v2.db");
0053 }
0054 
0055 /**
0056  * @brief The TAGDB class exposes methods to add, remove and modify tags in the MauiKit FileBrowsing Tagging system.
0057  * @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.
0058  */
0059 class FILEBROWSING_EXPORT TAGDB : public QObject
0060 {
0061     Q_OBJECT
0062     Q_DISABLE_COPY(TAGDB)
0063     
0064 private:
0065     QString name;
0066     QSqlDatabase m_db;    
0067     
0068     void openDB(const QString &name);
0069 
0070     void prepareCollectionDB() const;
0071 
0072    const QSqlDatabase& db() const;
0073    
0074 public:    
0075 
0076     TAGDB();
0077     ~TAGDB();
0078     
0079     //Utils
0080     /**
0081      * @brief Check for the existence of an entry
0082      * @param tableName the name of the table
0083      * @param searchId the search query
0084      * @param search the search value
0085      * @return whether the entry exists
0086      */
0087     bool checkExistance(const QString &tableName, const QString &searchId, const QString &search) const;
0088 
0089     /**
0090      * @brief Check if a entry exists given a query
0091      * @param queryStr the plain string query
0092      * @return whether the entry exists
0093      */
0094     bool checkExistance(const QString &queryStr) const;
0095 
0096     /**
0097      * @brief Retrieve the database query object of a performed a query
0098      * @param queryTxt the query to perform
0099      * @return the results
0100      */
0101     QSqlQuery getQuery(const QString &queryTxt) const;
0102 
0103     /**
0104      * @brief Return an empty query object to use arbitrary with any query.
0105      */
0106     QSqlQuery getQuery() const;
0107 
0108     /**
0109      * @brief Insert data into the given table
0110      * @param tableName table name
0111      * @param insertData the data map to be inserted
0112      * @return whether the operation was successful
0113      */
0114     bool insert(const QString &tableName, const QVariantMap &insertData) const;
0115 
0116     /**
0117      * @brief Update data in the database
0118      * @param tableName the table name
0119      * @param updateData the updated data 
0120      * @param where the key-value to match in the database
0121      * @return whether the operation was successful
0122      */
0123     bool update(const QString &tableName, const FMH::MODEL &updateData, const QVariantMap &where) const;
0124 
0125     /**
0126      * @brief Update data in the database
0127      * @param table table name
0128      * @param column the column name
0129      * @param newValue the new value
0130      * @param op the operation to match
0131      * @param id the value of the operation `op`
0132      * @return whether the operation was successful
0133      */
0134     bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id) const;
0135 
0136     /**
0137      * @brief remove
0138      * @param tableName
0139      * @param removeData
0140      * @return
0141      */
0142     bool remove(const QString &tableName, const FMH::MODEL &removeData) const;
0143     
0144 };
0145