Changeset View
Changeset View
Standalone View
Standalone View
src/contentlist/ContentQuery.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Arjen Hiemstra <ahiemstra@heimr.nl> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "ContentQuery.h" | ||||
22 | | ||||
23 | #include <QMimeDatabase> | ||||
24 | #include <QtGui/QImageReader> | ||||
25 | | ||||
26 | class ContentQuery::Private | ||||
27 | { | ||||
28 | public: | ||||
29 | QStringList mimeTypesForType(Type type); | ||||
30 | | ||||
31 | Type type = Any; | ||||
32 | QString searchString; | ||||
33 | QStringList locations; | ||||
34 | QStringList mimeTypes; | ||||
35 | }; | ||||
36 | | ||||
37 | ContentQuery::ContentQuery(QObject* parent) | ||||
38 | : QObject(parent), d(new Private) | ||||
39 | { | ||||
40 | } | ||||
41 | | ||||
42 | ContentQuery::~ContentQuery() | ||||
43 | { | ||||
44 | } | ||||
45 | | ||||
46 | ContentQuery::Type ContentQuery::type() const | ||||
47 | { | ||||
48 | return d->type; | ||||
49 | } | ||||
50 | | ||||
51 | QString ContentQuery::searchString() const | ||||
52 | { | ||||
53 | return d->searchString; | ||||
54 | } | ||||
55 | | ||||
56 | QStringList ContentQuery::locations() const | ||||
57 | { | ||||
58 | return d->locations; | ||||
59 | } | ||||
60 | | ||||
61 | QStringList ContentQuery::mimeTypes() const | ||||
62 | { | ||||
63 | if(!d->mimeTypes.isEmpty()) | ||||
64 | return d->mimeTypes; | ||||
65 | | ||||
66 | return d->mimeTypesForType(d->type); | ||||
67 | } | ||||
68 | | ||||
69 | void ContentQuery::setType(ContentQuery::Type type) | ||||
70 | { | ||||
71 | if(type == d->type) | ||||
72 | return; | ||||
73 | | ||||
74 | d->type = type; | ||||
75 | emit typeChanged(); | ||||
76 | } | ||||
77 | | ||||
78 | void ContentQuery::setSearchString(const QString& searchString) | ||||
79 | { | ||||
80 | if(searchString == d->searchString) | ||||
81 | return; | ||||
82 | | ||||
83 | d->searchString = searchString; | ||||
84 | emit searchStringChanged(); | ||||
85 | } | ||||
86 | | ||||
87 | void ContentQuery::setLocations(const QStringList& locations) | ||||
88 | { | ||||
89 | if(locations == d->locations) | ||||
90 | return; | ||||
91 | | ||||
92 | d->locations = locations; | ||||
93 | emit locationsChanged(); | ||||
94 | } | ||||
95 | | ||||
96 | void ContentQuery::setMimeTypes(const QStringList& mimeTypes) | ||||
97 | { | ||||
98 | if(mimeTypes == d->mimeTypes) | ||||
99 | return; | ||||
100 | | ||||
101 | d->mimeTypes = mimeTypes; | ||||
102 | emit mimeTypesChanged(); | ||||
103 | } | ||||
104 | | ||||
105 | QStringList ContentQuery::Private::mimeTypesForType(ContentQuery::Type type) | ||||
106 | { | ||||
107 | QStringList result; | ||||
108 | QMimeDatabase mimeDatabase; | ||||
109 | | ||||
110 | //TODO: Find a better solution for this. | ||||
111 | switch(type) { | ||||
112 | case ContentQuery::Video: | ||||
113 | result << QStringLiteral("video/x-matroska"); | ||||
114 | result << QStringLiteral("video/mp4"); | ||||
115 | result << QStringLiteral("video/mpeg"); | ||||
116 | result << QStringLiteral("video/ogg"); | ||||
117 | result << QStringLiteral("video/quicktime"); | ||||
118 | result << QStringLiteral("video/webm"); | ||||
119 | result << QStringLiteral("video/x-ms-wmv"); | ||||
120 | result << QStringLiteral("video/x-msvideo"); | ||||
121 | result << QStringLiteral("video/x-ogm+ogg"); | ||||
122 | result << QStringLiteral("video/x-theora+ogg"); | ||||
123 | break; | ||||
124 | case ContentQuery::Audio: | ||||
125 | result << QStringLiteral("audio/aac"); | ||||
126 | result << QStringLiteral("audio/flac"); | ||||
127 | result << QStringLiteral("audio/mp2"); | ||||
128 | result << QStringLiteral("audio/mp4"); | ||||
129 | result << QStringLiteral("audio/mpeg"); | ||||
130 | result << QStringLiteral("audio/ogg"); | ||||
131 | result << QStringLiteral("audio/webm"); | ||||
132 | result << QStringLiteral("audio/x-opus+ogg"); | ||||
133 | result << QStringLiteral("audio/x-ms-wma"); | ||||
134 | result << QStringLiteral("audio/x-vorbis+ogg"); | ||||
135 | result << QStringLiteral("audio/x-wav"); | ||||
136 | break; | ||||
137 | case ContentQuery::Documents: | ||||
138 | result << QStringLiteral("application/vnd.oasis.opendocument.text"); | ||||
139 | result << QStringLiteral("application/vnd.oasis.opendocument.spreadsheet"); | ||||
140 | result << QStringLiteral("application/vnd.oasis.opendocument.presentation"); | ||||
141 | result << QStringLiteral("application/vnd.ms-word"); | ||||
142 | result << QStringLiteral("application/vnd.ms-excel"); | ||||
143 | result << QStringLiteral("application/vnd.ms-powerpoint"); | ||||
144 | result << QStringLiteral("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.xml"); | ||||
145 | result << QStringLiteral("application/vnd.openxmlformats-officedocument.wordprocessingml.document.xml"); | ||||
146 | result << QStringLiteral("application/vnd.openxmlformats-officedocument.presentationml.presentation.xml"); | ||||
147 | result << QStringLiteral("text/plain"); | ||||
148 | result << QStringLiteral("application/pdf"); | ||||
149 | break; | ||||
150 | case ContentQuery::Images: | ||||
151 | for(const auto& item : QImageReader::supportedMimeTypes()) | ||||
152 | { | ||||
153 | result << QString::fromUtf8(item); | ||||
154 | } | ||||
155 | break; | ||||
156 | case ContentQuery::Comics: | ||||
157 | result << QStringLiteral("application/x-cbz"); | ||||
158 | result << QStringLiteral("application/x-cbr"); | ||||
159 | result << QStringLiteral("application/x-cb7"); | ||||
160 | result << QStringLiteral("application/x-cbt"); | ||||
161 | result << QStringLiteral("application/x-cba"); | ||||
162 | result << QStringLiteral("application/vnd.comicbook+zip"); | ||||
163 | result << QStringLiteral("application/vnd.comicbook+rar"); | ||||
164 | result << QStringLiteral("application/vnd.ms-htmlhelp"); | ||||
165 | result << QStringLiteral("image/vnd.djvu"); | ||||
166 | result << QStringLiteral("image/x-djvu"); | ||||
167 | result << QStringLiteral("application/epub+zip"); | ||||
168 | result << QStringLiteral("application/pdf"); | ||||
169 | break; | ||||
170 | default: | ||||
171 | break; | ||||
172 | } | ||||
173 | | ||||
174 | return result; | ||||
175 | } |