File indexing completed on 2024-04-28 03:51:50
0001 /* 0002 This file is part of the KDE Baloo Project 0003 SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #ifndef BALOO_KIO_TAGS_H_ 0009 #define BALOO_KIO_TAGS_H_ 0010 0011 #include <KFileMetaData/UserMetaData> 0012 #include <KIO/ForwardingWorkerBase> 0013 0014 #include "query.h" 0015 0016 namespace Baloo 0017 { 0018 0019 class TagsProtocol : public KIO::ForwardingWorkerBase 0020 { 0021 Q_OBJECT 0022 public: 0023 TagsProtocol(const QByteArray& pool_socket, const QByteArray& app_socket); 0024 ~TagsProtocol() override; 0025 0026 enum UrlType { 0027 InvalidUrl, 0028 FileUrl, 0029 TagUrl, 0030 }; 0031 Q_ENUM(UrlType) 0032 0033 /** 0034 * List all files and folders tagged with the corresponding tag, along with 0035 * additional tags that can be used to filter the results 0036 */ 0037 KIO::WorkerResult listDir(const QUrl& url) override; 0038 0039 /** 0040 * Will be forwarded for files. 0041 */ 0042 KIO::WorkerResult get(const QUrl& url) override; 0043 0044 /** 0045 * Files and folders can be copied to the virtual folders resulting 0046 * is assignment of the corresponding tag. 0047 */ 0048 KIO::WorkerResult copy(const QUrl& src, const QUrl& dest, int permissions, KIO::JobFlags flags) override; 0049 0050 /** 0051 * File renaming will be forwarded. 0052 * Folder renaming results in renaming of the tag. 0053 */ 0054 KIO::WorkerResult rename(const QUrl& src, const QUrl& dest, KIO::JobFlags flags) override; 0055 0056 /** 0057 * File deletion means remocing the tag 0058 * Folder deletion will result in deletion of the tag. 0059 */ 0060 KIO::WorkerResult del(const QUrl& url, bool isfile) override; 0061 0062 /** 0063 * Files will be forwarded. 0064 * Tags will be created as virtual folders. 0065 */ 0066 KIO::WorkerResult mimetype(const QUrl& url) override; 0067 0068 /** 0069 * Virtual folders will be created. 0070 */ 0071 KIO::WorkerResult mkdir(const QUrl& url, int permissions) override; 0072 0073 /** 0074 * Files will be forwarded. 0075 * Tags will be created as virtual folders. 0076 */ 0077 KIO::WorkerResult stat(const QUrl& url) override; 0078 0079 protected: 0080 bool rewriteUrl(const QUrl& url, QUrl& newURL) override; 0081 0082 private: 0083 enum ParseFlags { 0084 ChopLastSection, 0085 LazyValidation, 0086 }; 0087 0088 struct ParseResult { 0089 UrlType urlType = InvalidUrl; 0090 QString decodedUrl; 0091 QString tag; 0092 QUrl fileUrl; 0093 KFileMetaData::UserMetaData metaData = KFileMetaData::UserMetaData(QString()); 0094 Query query; 0095 KIO::UDSEntryList pathUDSResults; 0096 }; 0097 0098 ParseResult parseUrl(const QUrl& url, const QList<ParseFlags> &flags = QList<ParseFlags>()); 0099 QStringList m_unassignedTags; 0100 }; 0101 } 0102 0103 #endif // BALOO_KIO_TAGS_H_