-
Notifications
You must be signed in to change notification settings - Fork 38
/
appsmodel.cpp
79 lines (72 loc) · 2.2 KB
/
appsmodel.cpp
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
#include "appsmodel.h"
#include <QDebug>
#include <QFont>
#include <QBrush>
#include <lua.hpp>
#include <QSettings>
#include <QProcessEnvironment>
#include <QDir>
#include <QFile>
#include "selectoutput.h"
#include "vcard.h"
#include "bhj_help.hpp"
#include <QByteArray>
#include <QPixmap>
#include <algorithm>
#include <QTextStream>
#include "wrench.h"
AppsModel::AppsModel(QObject *parent) :
FilteringModel(parent),
mDefaultAvatar("emojis/iphone-emoji/WRENCH.png")
{
mAppClasses.clear();
if (gDataDir.exists("apps.info")) {
QFile appsFile(gDataDir.absoluteFilePath("apps.info"));
if (appsFile.open(QFile::ReadOnly | QFile::Text)) {
QTextStream in(&appsFile);
in.setCodec("UTF-8");
QString lines = in.readAll();
foreach (const QString& line, lines.split("\n")) {
QStringList info = line.split("=");
if (info.size() == 3) {
mAppClasses.push_back(info[0]);
mAppPackageMap[info[0]] = info[1];
mAppLabelMap[info[0]] = QStringList() << info[2] << getPinyinSpelling(info[2]);
mAppIconMap[info[0]] = QPixmap(gDataDir.absoluteFilePath(info[0] + ".png")).scaled(48, 48);
}
}
}
}
initHistory();
}
void AppsModel::filterSelectedItems(const QStringList& split)
{
foreach (const QString& app, mAppClasses) {
int match = 1;
foreach (const QString& stem, split) {
int stem_match = 0;
foreach(const QString& label, mAppLabelMap[app]) {
if (label.contains(stem, Qt::CaseInsensitive)) {
stem_match = 1;
break;
}
}
if (! stem_match) {
match = 0;
break;
}
}
if (match) {
SelectedItem si(app, mAppLabelMap[app][0]);
si.icon = mAppIconMap[app];
if (!mSelectedItemsRevMap.contains(si.displayText)) {
mSelectedItems << si;
mSelectedItemsRevMap[si.displayText] = si;
}
}
}
}
QString AppsModel::getHistoryName()
{
return "apps-history";
}