Changeset View
Changeset View
Standalone View
Standalone View
app/plasma/runner/kdevelopsessions.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
46 | { | 46 | { | ||
47 | setObjectName(QStringLiteral("KDevelop Sessions")); | 47 | setObjectName(QStringLiteral("KDevelop Sessions")); | ||
48 | setIgnoredTypes(Plasma::RunnerContext::File | Plasma::RunnerContext::Directory | Plasma::RunnerContext::NetworkLocation); | 48 | setIgnoredTypes(Plasma::RunnerContext::File | Plasma::RunnerContext::Directory | Plasma::RunnerContext::NetworkLocation); | ||
49 | m_icon = QIcon::fromTheme(QStringLiteral("kdevelop")); | 49 | m_icon = QIcon::fromTheme(QStringLiteral("kdevelop")); | ||
50 | 50 | | |||
51 | loadSessions(); | 51 | loadSessions(); | ||
52 | 52 | | |||
53 | // listen for changes to the list of kdevelop sessions | 53 | // listen for changes to the list of kdevelop sessions | ||
54 | KDirWatch *historyWatch = new KDirWatch(this); | 54 | auto *historyWatch = new KDirWatch(this); | ||
55 | const QStringList sessiondirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | 55 | const QStringList sessiondirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | ||
56 | QStringLiteral("kdevelop/sessions"), QStandardPaths::LocateDirectory); | 56 | QStringLiteral("kdevelop/sessions"), QStandardPaths::LocateDirectory); | ||
57 | foreach (const QString &dir, sessiondirs) { | 57 | for (const QString& dir : sessiondirs) { | ||
58 | historyWatch->addDir(dir); | 58 | historyWatch->addDir(dir); | ||
59 | } | 59 | } | ||
60 | connect(historyWatch, &KDirWatch::dirty, this, &KDevelopSessions::loadSessions); | 60 | connect(historyWatch, &KDirWatch::dirty, this, &KDevelopSessions::loadSessions); | ||
61 | connect(historyWatch, &KDirWatch::created, this, &KDevelopSessions::loadSessions); | 61 | connect(historyWatch, &KDirWatch::created, this, &KDevelopSessions::loadSessions); | ||
62 | connect(historyWatch, &KDirWatch::deleted, this, &KDevelopSessions::loadSessions); | 62 | connect(historyWatch, &KDirWatch::deleted, this, &KDevelopSessions::loadSessions); | ||
63 | 63 | | |||
64 | Plasma::RunnerSyntax s(QStringLiteral(":q:"), i18n("Finds KDevelop sessions matching :q:.")); | 64 | Plasma::RunnerSyntax s(QStringLiteral(":q:"), i18n("Finds KDevelop sessions matching :q:.")); | ||
65 | s.addExampleQuery(QStringLiteral("kdevelop :q:")); | 65 | s.addExampleQuery(QStringLiteral("kdevelop :q:")); | ||
66 | addSyntax(s); | 66 | addSyntax(s); | ||
67 | 67 | | |||
68 | setDefaultSyntax(Plasma::RunnerSyntax(QStringLiteral("kdevelop"), i18n("Lists all the KDevelop editor sessions in your account."))); | 68 | setDefaultSyntax(Plasma::RunnerSyntax(QStringLiteral("kdevelop"), i18n("Lists all the KDevelop editor sessions in your account."))); | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | KDevelopSessions::~KDevelopSessions() = default; | 71 | KDevelopSessions::~KDevelopSessions() = default; | ||
72 | 72 | | |||
73 | QStringList findSessions() | 73 | QStringList findSessions() | ||
74 | { | 74 | { | ||
75 | QStringList sessionDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | 75 | const QStringList sessionDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | ||
76 | QStringLiteral("kdevelop/sessions"), | 76 | QStringLiteral("kdevelop/sessions"), | ||
77 | QStandardPaths::LocateDirectory); | 77 | QStandardPaths::LocateDirectory); | ||
78 | QStringList sessionrcs; | 78 | QStringList sessionrcs; | ||
79 | Q_FOREACH(const QString& dir, sessionDirs) { | 79 | for (const QString& dir : sessionDirs) { | ||
80 | QDir d(dir); | 80 | QDir d(dir); | ||
81 | Q_FOREACH(const QString& sessionDir, d.entryList(QDir::Dirs)) { | 81 | Q_FOREACH(const QString& sessionDir, d.entryList(QDir::Dirs)) { | ||
82 | QDir sd(d.absoluteFilePath(sessionDir)); | 82 | QDir sd(d.absoluteFilePath(sessionDir)); | ||
83 | QString path(sd.filePath(QStringLiteral("sessionrc"))); | 83 | QString path(sd.filePath(QStringLiteral("sessionrc"))); | ||
84 | if(QFile::exists(path)) { | 84 | if(QFile::exists(path)) { | ||
85 | sessionrcs += path; | 85 | sessionrcs += path; | ||
86 | } | 86 | } | ||
87 | } | 87 | } | ||
88 | } | 88 | } | ||
89 | return sessionrcs; | 89 | return sessionrcs; | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | void KDevelopSessions::loadSessions() | 92 | void KDevelopSessions::loadSessions() | ||
93 | { | 93 | { | ||
94 | m_sessions.clear(); | 94 | m_sessions.clear(); | ||
95 | // Switch kdevelop session: -u | 95 | // Switch kdevelop session: -u | ||
96 | // Should we add a match for this option or would that clutter the matches too much? | 96 | // Should we add a match for this option or would that clutter the matches too much? | ||
97 | const QStringList list = findSessions(); | 97 | const QStringList list = findSessions(); | ||
98 | foreach (const QString &sessionfile, list) | 98 | m_sessions.reserve(list.size()); | ||
99 | { | 99 | for (const QString& sessionfile : list) { | ||
100 | Session session; | 100 | Session session; | ||
101 | session.id = sessionfile.section('/', -2, -2); | 101 | session.id = sessionfile.section(QLatin1Char('/'), -2, -2); | ||
102 | KConfig cfg(sessionfile, KConfig::SimpleConfig); | 102 | KConfig cfg(sessionfile, KConfig::SimpleConfig); | ||
103 | KConfigGroup group = cfg.group(QString()); | 103 | KConfigGroup group = cfg.group(QString()); | ||
104 | session.name = group.readEntry("SessionPrettyContents");; | 104 | session.name = group.readEntry("SessionPrettyContents"); | ||
105 | m_sessions << session; | 105 | m_sessions << session; | ||
106 | } | 106 | } | ||
107 | std::sort(m_sessions.begin(), m_sessions.end(), kdevelopsessions_runner_compare_sessions); | 107 | std::sort(m_sessions.begin(), m_sessions.end(), kdevelopsessions_runner_compare_sessions); | ||
108 | } | 108 | } | ||
109 | 109 | | |||
110 | void KDevelopSessions::match(Plasma::RunnerContext &context) | 110 | void KDevelopSessions::match(Plasma::RunnerContext &context) | ||
111 | { | 111 | { | ||
112 | if (m_sessions.isEmpty()) { | 112 | if (m_sessions.isEmpty()) { | ||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |