1 /*
2     This file is part of the KDE Baloo Project
3     SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
4 
5     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #ifndef BALOO_KIO_TAGS_H_
9 #define BALOO_KIO_TAGS_H_
10 
11 #include <KFileMetaData/UserMetaData>
12 #include <KIO/ForwardingSlaveBase>
13 
14 #include "query.h"
15 
16 namespace Baloo
17 {
18 
19 class TagsProtocol : public KIO::ForwardingSlaveBase
20 {
21     Q_OBJECT
22 public:
23     TagsProtocol(const QByteArray& pool_socket, const QByteArray& app_socket);
24     ~TagsProtocol() override;
25 
26     enum UrlType {
27         InvalidUrl,
28         FileUrl,
29         TagUrl,
30     };
31     Q_ENUM(UrlType)
32 
33     /**
34      * List all files and folders tagged with the corresponding tag, along with
35      * additional tags that can be used to filter the results
36      */
37     void listDir(const QUrl& url) override;
38 
39     /**
40      * Will be forwarded for files.
41      */
42     void get(const QUrl& url) override;
43 
44     /**
45      * Files and folders can be copied to the virtual folders resulting
46      * is assignment of the corresponding tag.
47      */
48     void copy(const QUrl& src, const QUrl& dest, int permissions, KIO::JobFlags flags) override;
49 
50     /**
51      * File renaming will be forwarded.
52      * Folder renaming results in renaming of the tag.
53      */
54     void rename(const QUrl& src, const QUrl& dest, KIO::JobFlags flags) override;
55 
56     /**
57      * File deletion means remocing the tag
58      * Folder deletion will result in deletion of the tag.
59      */
60     void del(const QUrl& url, bool isfile) override;
61 
62     /**
63      * Files will be forwarded.
64      * Tags will be created as virtual folders.
65      */
66     void mimetype(const QUrl& url) override;
67 
68     /**
69      * Virtual folders will be created.
70      */
71     void mkdir(const QUrl& url, int permissions) override;
72 
73     /**
74      * Files will be forwarded.
75      * Tags will be created as virtual folders.
76      */
77     void stat(const QUrl& url) override;
78 protected:
79     bool rewriteUrl(const QUrl& url, QUrl& newURL) override;
80 
81 private:
82     enum ParseFlags {
83         ChopLastSection,
84         LazyValidation,
85     };
86 
87     struct ParseResult {
88         UrlType urlType = InvalidUrl;
89         QString decodedUrl;
90         QString tag;
91         QUrl fileUrl;
92         KFileMetaData::UserMetaData metaData = KFileMetaData::UserMetaData(QString());
93         Query query;
94         KIO::UDSEntryList pathUDSResults;
95     };
96 
97     ParseResult parseUrl(const QUrl& url, const QList<ParseFlags> &flags = QList<ParseFlags>());
98     QStringList m_unassignedTags;
99 };
100 }
101 
102 #endif // BALOO_KIO_TAGS_H_
103