aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/desktops/deepin/dde-file-manager/dde-file-manager.fix-mime-cache-paths.patch
blob: 253a67b04ec7b10798b6333574871ab7ccc3ac8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
From 29f4ad88e2294ae70b10180e7361d135c4e5c896 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Romildo=20Malaquias?= <malaquias@gmail.com>
Date: Mon, 13 May 2019 00:09:42 -0300
Subject: [PATCH 2/2] Use XDG to look for mime cache

---
 .../shutil/mimesappsmanager.cpp               | 230 ++++++++++--------
 .../shutil/mimesappsmanager.h                 |   6 +-
 2 files changed, 125 insertions(+), 111 deletions(-)

diff --git a/dde-file-manager-lib/shutil/mimesappsmanager.cpp b/dde-file-manager-lib/shutil/mimesappsmanager.cpp
index c9e53630..7a21df51 100644
--- a/dde-file-manager-lib/shutil/mimesappsmanager.cpp
+++ b/dde-file-manager-lib/shutil/mimesappsmanager.cpp
@@ -552,14 +552,20 @@ QString MimesAppsManager::getMimeAppsCacheFile()
     return QString("%1/%2").arg(DFMStandardPaths::location(DFMStandardPaths::CachePath), "MimeApps.json");
 }
 
-QString MimesAppsManager::getMimeInfoCacheFilePath()
+QStringList MimesAppsManager::getMimeInfoCacheFilePath()
 {
-    return "/usr/share/applications/mimeinfo.cache";
+    QStringList paths;
+    for (const QString dir : getMimeInfoCacheFileRootPath() )
+       paths.append(dir + QDir::separator() + "mimeinfo.cache");
+    qDebug() << "getMimeInfoCacheFilePath: " << paths;
+    return paths;
 }
 
-QString MimesAppsManager::getMimeInfoCacheFileRootPath()
+QStringList MimesAppsManager::getMimeInfoCacheFileRootPath()
 {
-    return "/usr/share/applications";
+    QStringList paths = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
+    qDebug() << "getMimeInfoCacheFileRootPath: " << paths;
+    return paths;
 }
 
 QString MimesAppsManager::getDesktopFilesCacheFile()
@@ -574,23 +580,27 @@ QString MimesAppsManager::getDesktopIconsCacheFile()
 
 QStringList MimesAppsManager::getDesktopFiles()
 {
-      QStringList desktopFiles;
+    QStringList desktopFiles;
 
-      foreach (QString desktopFolder, getApplicationsFolders()) {
-          QDirIterator it(desktopFolder, QStringList("*.desktop"),
-                          QDir::Files | QDir::NoDotAndDotDot,
-                          QDirIterator::Subdirectories);
-          while (it.hasNext()) {
-            it.next();
-            desktopFiles.append(it.filePath());
-          }
-      }
-      return desktopFiles;
+    foreach (QString desktopFolder, getApplicationsFolders()) {
+        QDirIterator it(desktopFolder, QStringList("*.desktop"),
+                        QDir::Files | QDir::NoDotAndDotDot,
+                        QDirIterator::Subdirectories);
+        while (it.hasNext()) {
+          it.next();
+          desktopFiles.append(it.filePath());
+        }
+    }
+    return desktopFiles;
 }
 
-QString MimesAppsManager::getDDEMimeTypeFile()
+QStringList MimesAppsManager::getDDEMimeTypeFile()
 {
-    return QString("%1/%2/%3").arg(getMimeInfoCacheFileRootPath(), "deepin", "dde-mimetype.list");
+    QStringList paths;
+    for (const QString path : getMimeInfoCacheFileRootPath())
+       paths.append(QString("%1/%2/%3").arg(path, "deepin", "dde-mimetype.list"));
+    qDebug() << "getDDEMimeTypeFile: " << paths;
+    return paths;
 }
 
 QMap<QString, DesktopFile> MimesAppsManager::getDesktopObjs()
@@ -663,124 +673,128 @@ void MimesAppsManager::initMimeTypeApps()
         MimeApps.insert(key, orderApps);
     }
 
-    //check mime apps from cache
-    QFile f(getMimeInfoCacheFilePath());
-    if(!f.open(QIODevice::ReadOnly)){
-        qDebug () << "failed to read mime info cache file:" << f.errorString();
-        return;
-    }
-
     QStringList audioDesktopList;
     QStringList imageDeksopList;
     QStringList textDekstopList;
     QStringList videoDesktopList;
 
-    while (!f.atEnd()) {
-        QString data = f.readLine();
-        QString _desktops = data.split("=").last();
-        QString mimeType = data.split("=").first();
-        QStringList desktops = _desktops.split(";");
-
-        foreach (const QString desktop, desktops) {
-            if(desktop.isEmpty() || audioDesktopList.contains(desktop))
-                continue;
+    //check mime apps from cache
+    for (const QString path : getMimeInfoCacheFilePath()) {
+        QFile f(path);
+        if(!f.open(QIODevice::ReadOnly)){
+            qDebug () << "failed to read mime info cache file:" << f.errorString();
+            return;
+        }
 
-            if(mimeType.startsWith("audio")){
-                if(!audioDesktopList.contains(desktop))
-                    audioDesktopList << desktop;
-            } else if(mimeType.startsWith("image")){
-                if(!imageDeksopList.contains(desktop))
-                    imageDeksopList << desktop;
-            } else if(mimeType.startsWith("text")){
-                if(!textDekstopList.contains(desktop))
-                    textDekstopList << desktop;
-            } else if(mimeType.startsWith("video")){
-                if(!videoDesktopList.contains(desktop))
-                    videoDesktopList << desktop;
+        while (!f.atEnd()) {
+            QString data = f.readLine();
+            QString _desktops = data.split("=").last();
+            QString mimeType = data.split("=").first();
+            QStringList desktops = _desktops.split(";");
+
+            foreach (const QString desktop, desktops) {
+                if(desktop.isEmpty() || audioDesktopList.contains(desktop))
+                    continue;
+
+                if(mimeType.startsWith("audio")){
+                    if(!audioDesktopList.contains(desktop))
+                        audioDesktopList << desktop;
+                } else if(mimeType.startsWith("image")){
+                    if(!imageDeksopList.contains(desktop))
+                        imageDeksopList << desktop;
+                } else if(mimeType.startsWith("text")){
+                    if(!textDekstopList.contains(desktop))
+                        textDekstopList << desktop;
+                } else if(mimeType.startsWith("video")){
+                    if(!videoDesktopList.contains(desktop))
+                        videoDesktopList << desktop;
+                }
             }
         }
+        f.close();
     }
-    f.close();
 
-    const QString mimeInfoCacheRootPath = getMimeInfoCacheFileRootPath();
-    foreach (QString desktop, audioDesktopList) {
-        const QString path = QString("%1/%2").arg(mimeInfoCacheRootPath,desktop);
-        if(!QFile::exists(path))
-            continue;
-        DesktopFile df(path);
-        AudioMimeApps.insert(path, df);
-    }
+    for (const QString mimeInfoCacheRootPath : getMimeInfoCacheFileRootPath()) {
+        foreach (QString desktop, audioDesktopList) {
+            const QString path = QString("%1/%2").arg(mimeInfoCacheRootPath,desktop);
+            if(!QFile::exists(path))
+                continue;
+            DesktopFile df(path);
+            AudioMimeApps.insert(path, df);
+        }
 
-    foreach (QString desktop, imageDeksopList) {
-        const QString path = QString("%1/%2").arg(mimeInfoCacheRootPath,desktop);
-        if(!QFile::exists(path))
-            continue;
-        DesktopFile df(path);
-        ImageMimeApps.insert(path, df);
-    }
+        foreach (QString desktop, imageDeksopList) {
+            const QString path = QString("%1/%2").arg(mimeInfoCacheRootPath,desktop);
+            if(!QFile::exists(path))
+                continue;
+            DesktopFile df(path);
+            ImageMimeApps.insert(path, df);
+        }
 
-    foreach (QString desktop, textDekstopList) {
-        const QString path = QString("%1/%2").arg(mimeInfoCacheRootPath,desktop);
-        if(!QFile::exists(path))
-            continue;
-        DesktopFile df(path);
-        TextMimeApps.insert(path, df);
-    }
+        foreach (QString desktop, textDekstopList) {
+            const QString path = QString("%1/%2").arg(mimeInfoCacheRootPath,desktop);
+            if(!QFile::exists(path))
+                continue;
+            DesktopFile df(path);
+            TextMimeApps.insert(path, df);
+        }
 
-    foreach (QString desktop, videoDesktopList) {
-        const QString path = QString("%1/%2").arg(mimeInfoCacheRootPath,desktop);
-        if(!QFile::exists(path))
-            continue;
-        DesktopFile df(path);
-        VideoMimeApps.insert(path, df);
+        foreach (QString desktop, videoDesktopList) {
+            const QString path = QString("%1/%2").arg(mimeInfoCacheRootPath,desktop);
+            if(!QFile::exists(path))
+                continue;
+            DesktopFile df(path);
+            VideoMimeApps.insert(path, df);
+        }
     }
-
     return;
 }
 
 void MimesAppsManager::loadDDEMimeTypes()
 {
-    QSettings settings(getDDEMimeTypeFile(), QSettings::IniFormat);
-    qDebug() << settings.childGroups();
+    for (const QString path : getDDEMimeTypeFile()) {
+        QSettings settings(path, QSettings::IniFormat);
+        qDebug() << settings.childGroups();
 
-    QFile file(getDDEMimeTypeFile());
-    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
-        return;
-    }
+        QFile file(path);
+        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+            continue;
+        }
+
+        // Read propeties
+        QTextStream in(&file);
+        QString desktopKey;
+        while (!in.atEnd()) {
 
-    // Read propeties
-    QTextStream in(&file);
-    QString desktopKey;
-    while (!in.atEnd()) {
+          // Read new line
+          QString line = in.readLine();
 
-      // Read new line
-      QString line = in.readLine();
+          // Skip empty line or line with invalid format
+          if (line.trimmed().isEmpty()) {
+            continue;
+          }
 
-      // Skip empty line or line with invalid format
-      if (line.trimmed().isEmpty()) {
-        continue;
-      }
+          // Read group
+          // NOTE: symbols '[' and ']' can be found not only in group names, but
+          // only group can start with '['
 
-      // Read group
-      // NOTE: symbols '[' and ']' can be found not only in group names, but
-      // only group can start with '['
+          if (line.trimmed().startsWith("[") && line.trimmed().endsWith("]")) {
+                QString tmp = line.trimmed().replace("[", "").replace("]", "");
+                desktopKey = tmp;
+                continue;
+          }
 
-      if (line.trimmed().startsWith("[") && line.trimmed().endsWith("]")) {
-            QString tmp = line.trimmed().replace("[", "").replace("]", "");
-            desktopKey = tmp;
-            continue;
-      }
-
-      // If we are in correct group and line contains assignment then read data
-      int first_equal = line.indexOf('=');
-      if (!desktopKey.isEmpty() && first_equal >= 0) {
-            QString value = line.mid(first_equal + 1);
-            QStringList mimetypes = value.split(";");
-            DDE_MimeTypes.insert(desktopKey, mimetypes);
-            desktopKey.clear();
+          // If we are in correct group and line contains assignment then read data
+          int first_equal = line.indexOf('=');
+          if (!desktopKey.isEmpty() && first_equal >= 0) {
+                QString value = line.mid(first_equal + 1);
+                QStringList mimetypes = value.split(";");
+                DDE_MimeTypes.insert(desktopKey, mimetypes);
+                desktopKey.clear();
+            }
         }
+        file.close();
     }
-    file.close();
 }
 
 bool MimesAppsManager::lessByDateTime(const QFileInfo &f1, const QFileInfo &f2)
diff --git a/dde-file-manager-lib/shutil/mimesappsmanager.h b/dde-file-manager-lib/shutil/mimesappsmanager.h
index 223c80aa..00a61302 100644
--- a/dde-file-manager-lib/shutil/mimesappsmanager.h
+++ b/dde-file-manager-lib/shutil/mimesappsmanager.h
@@ -101,12 +101,12 @@ public:
 
     static QStringList getApplicationsFolders();
     static QString getMimeAppsCacheFile();
-    static QString getMimeInfoCacheFilePath();
-    static QString getMimeInfoCacheFileRootPath();
+    static QStringList getMimeInfoCacheFilePath();
+    static QStringList getMimeInfoCacheFileRootPath();
     static QString getDesktopFilesCacheFile();
     static QString getDesktopIconsCacheFile();
     static QStringList getDesktopFiles();
-    static QString getDDEMimeTypeFile();
+    static QStringList getDDEMimeTypeFile();
     static QMap<QString, DesktopFile> getDesktopObjs();
     static void initMimeTypeApps();
     static void loadDDEMimeTypes();
-- 
2.21.0