[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [sprinter/gko/master] runners: recent documents runner
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2014-03-06 10:20:26
Message-ID: E1WLVPe-0007ZS-EL () scm ! kde ! org
[Download RAW message or body]

Git commit b26fa40d0e31dca018559cc922be2526cc5befa3 by Aaron J. Seigo.
Committed on 26/02/2014 at 15:20.
Pushed by aseigo into branch 'gko/master'.

recent documents runner

numerous improvements over the 4.x version including:

* matching on the actual name of the file, not the .desktop
    (funny tip: enter "desktop" into krunner and you get all your recent docs!)
* duplicate removal
* use the url in the .desktop file (one less layer of indirection)
* differentiate between exact/partial matching

M  +3    -0    runners/CMakeLists.txt
A  +8    -0    runners/recentdocs/CMakeLists.txt
A  +123  -0    runners/recentdocs/recentdocs.cpp     [License: GPL (v2+)]
A  +92   -0    runners/recentdocs/recentdocs.desktop
A  +57   -0    runners/recentdocs/recentdocs.h     [License: GPL (v2+)]
A  +9    -0    runners/recentdocs/recentdocs.json

http://commits.kde.org/sprinter/b26fa40d0e31dca018559cc922be2526cc5befa3

diff --git a/runners/CMakeLists.txt b/runners/CMakeLists.txt
index 92a1531..58f312f 100644
--- a/runners/CMakeLists.txt
+++ b/runners/CMakeLists.txt
@@ -1,6 +1,8 @@
 find_package(KF5DBusAddons)
 find_package(KF5KIO)
 find_package(KF5Activities)
+find_package(KF5CoreAddons)
+find_package(KF5ConfigCore)
 find_package(Qalculate)
 
 if (QALCULATE_FOUND)
@@ -14,6 +16,7 @@ endif (KF5Activities_FOUND)
 if (KF5KIO_FOUND)
 #     currently this guy crashes somewhere in KIO
 #     add_subdirectory(uri)
+    add_subdirectory(recentdocs)
 endif (KF5KIO_FOUND)
 
 add_subdirectory(c)
diff --git a/runners/recentdocs/CMakeLists.txt b/runners/recentdocs/CMakeLists.txt
new file mode 100644
index 0000000..1341200
--- /dev/null
+++ b/runners/recentdocs/CMakeLists.txt
@@ -0,0 +1,8 @@
+project(sprinter_org_kde_sprinter_recentdocts)
+
+add_definitions(-DQT_PLUGIN)
+include_directories(${CMAKE_CURRENT_BINARY_DIR} KF5::KIOCore KF5::CoreAddons \
KF5::ConfigCore) +add_library(${PROJECT_NAME} SHARED recentdocs.cpp)
+qt5_use_modules(${PROJECT_NAME} Core Gui)
+target_link_libraries(${PROJECT_NAME} KF5::KIOCore KF5::KIOWidgets  KF5::CoreAddons \
KF5::ConfigCore) +install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION \
${SPRINTER_PLUGINS_PATH}) \ No newline at end of file
diff --git a/runners/recentdocs/recentdocs.cpp b/runners/recentdocs/recentdocs.cpp
new file mode 100644
index 0000000..92ace6d
--- /dev/null
+++ b/runners/recentdocs/recentdocs.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "recentdocs.h"
+
+#include <QCoreApplication>
+#include <QDebug>
+#include <QEventLoop>
+#include <QIcon>
+
+#include <KConfig>
+#include <KDesktopFile>
+#include <KIOCore/KRecentDocument>
+#include <KIOWidgets/KRun>
+#include <KCoreAddons/KDirWatch>
+
+RecentDocsSessionData::RecentDocsSessionData(Sprinter::Runner *runner)
+    : Sprinter::RunnerSessionData(runner)
+{
+    updateRecentDocsList();
+
+    KDirWatch *watch = new KDirWatch(this);
+    watch->addDir(KRecentDocument::recentDocumentDirectory(),
+                  KDirWatch::WatchFiles);
+    connect(watch, &KDirWatch::created,
+            this, &RecentDocsSessionData::updateRecentDocsList);
+    connect(watch, &KDirWatch::deleted,
+            this, &RecentDocsSessionData::updateRecentDocsList);
+    connect(watch, &KDirWatch::dirty,
+            this, &RecentDocsSessionData::updateRecentDocsList);
+}
+
+void RecentDocsSessionData::updateRecentDocsList()
+{
+    recentDocs.clear();
+    QSet<QString> seen;
+    RecentDoc doc;
+
+    foreach (const QString desktopFile, KRecentDocument::recentDocuments()) {
+        KDesktopFile file(desktopFile);
+        doc.name = file.readName();
+        if (seen.contains(doc.name)) {
+            continue;
+        }
+
+        seen.insert(doc.name);
+        doc.icon = file.readIcon();
+        doc.url = file.readUrl();
+        recentDocs << doc;
+    }
+}
+
+RecentDocsRunner::RecentDocsRunner(QObject *parent)
+    : Sprinter::Runner(parent)
+{
+    setMatchTypesGenerated(QVector<Sprinter::QuerySession::MatchType>()
+                                << Sprinter::QuerySession::FileType);
+    setSourcesUsed(QVector<Sprinter::QuerySession::MatchSource>()
+                        << Sprinter::QuerySession::FromFilesystem);
+}
+
+Sprinter::RunnerSessionData *RecentDocsRunner::createSessionData()
+{
+    return new RecentDocsSessionData(this);
+}
+
+void RecentDocsRunner::match(Sprinter::MatchData &matchData)
+{
+    RecentDocsSessionData *sessionData = qobject_cast<RecentDocsSessionData \
*>(matchData.sessionData()); +    if (!sessionData || \
sessionData->recentDocs.isEmpty()) { +        return;
+    }
+
+    const QString term = matchData.queryContext().query();
+    for (int i = 0; i < sessionData->recentDocs.count(); ++i) {
+        if (sessionData->recentDocs[i].name.contains(term, Qt::CaseInsensitive)) {
+            Sprinter::QueryMatch match;
+            match.setTitle(sessionData->recentDocs[i].name);
+            match.setText(tr("Recent Document"));
+            match.setType(Sprinter::QuerySession::FileType);
+            match.setSource(Sprinter::QuerySession::FromFilesystem);
+
+            if (sessionData->recentDocs[i].name.compare(term, Qt::CaseInsensitive) \
== 0) { +                match.setPrecision(Sprinter::QuerySession::ExactMatch);
+            } else {
+                match.setPrecision(Sprinter::QuerySession::CloseMatch);
+            }
+
+            match.setImage(QIcon::fromTheme(sessionData->recentDocs[i].icon).pixmap(matchData.queryContext().imageSize()).toImage());
 +            match.setUserData(sessionData->recentDocs[i].url);
+            match.setData(sessionData->recentDocs[i].url);
+            matchData << match;
+        }
+    }
+}
+
+bool RecentDocsRunner::exec(const Sprinter::QueryMatch &match)
+{
+    bool success = false;
+    QEventLoop loop;
+    KRun *krun = new KRun(match.data().toString(), 0, false);
+    connect(krun, &KRun::finished,
+            [&]() { success = !krun->hasError(); loop.exit(); });
+    krun->moveToThread(QCoreApplication::instance()->thread());
+    loop.exec();
+    return success;
+}
+
+#include "moc_recentdocs.cpp"
diff --git a/runners/recentdocs/recentdocs.desktop \
b/runners/recentdocs/recentdocs.desktop new file mode 100644
index 0000000..c16842f
--- /dev/null
+++ b/runners/recentdocs/recentdocs.desktop
@@ -0,0 +1,92 @@
+[Desktop Entry]
+Name=Recent Documents
+Name[ar]=المسندات الحديثة
+Name[ast]=Documentos recientes
+Name[be]=Нядаўнія дакументы
+Name[be@latin]=Niadaŭnyja dakumenty
+Name[bg]=Последно използвани
+Name[bn]=সম্প্রতি ব্যবহৃত নথী
+Name[br]=Teulioù nevez
+Name[bs]=nedavnii dokumenti
+Name[ca]=Documents recents
+Name[ca@valencia]=Documents recents
+Name[cs]=Nedávné dokumenty
+Name[cy]=Dogfenni Diweddar
+Name[da]=Nylige dokumenter
+Name[de]=Zuletzt geöffnete Dokumente
+Name[el]= ρόσφατα έγγραφα
+Name[en_GB]=Recent Documents
+Name[eo]=Lastlaboritaj dokumentoj
+Name[es]=Documentos recientes
+Name[et]=Viimati kasutatud dokumendid
+Name[eu]=Azken dokumentuak
+Name[fa]=سندهای اخیر
+Name[fi]=Viimeksi käytetyt asiakirjat
+Name[fr]=Documents récents
+Name[fy]=Koatlyn brûkte dokuminten
+Name[ga]=Cáipéisí is Déanaí
+Name[gl]=Documentos recentes
+Name[gu]=હાલનાં દસ્તાવેજો
+Name[he]=מסמכים שהיו בשימוש לאחרו ה
+Name[hi]=हाल ही में प्रयुक्त \
दस्तावेज़ +Name[hne]=हाल ही मं \
प्रयुक्त कागद +Name[hr]=Nedavno pristupljeni dokumenti
+Name[hu]=Nemrég használt dokumentumok
+Name[ia]=Documentos recente
+Name[id]=Dokumen Terkini
+Name[is]=Nýleg skjöl
+Name[it]=Documenti recenti
+Name[ja]=最近の文書
+Name[ka]=ბოლო დოკუმენტები
+Name[kk]=Жуырда ашылғандар
+Name[km]=ឯកសារ​បច្ចុប្បន្ន
+Name[kn]=ಇತ್ತೀಚಿನ ದಸ್ತಾವೇಜುಗಳು
+Name[ko]=최근 문서
+Name[ku]=Pelgeyên Hatine Bikaranîn
+Name[lt]=Neseni dokumentai
+Name[lv]=Nesenie dokumenti
+Name[mai]=हालक दस्ताबेज
+Name[mk]=Скорешни документи
+Name[ml]=ഈയിടെ തുറന്ന രേഖകള്‍
+Name[mr]=अलिकडील दस्तऐवज
+Name[nb]=Nylig brukte dokumenter
+Name[nds]=Tolest bruukt Dokmenten
+Name[nl]=Recente documenten
+Name[nn]=Nyleg brukte dokument
+Name[or]=ପ୍ରଚଳିତ ଦଲିଲଗୁଡ଼ିକ
+Name[pa]=ਤਾਜ਼ਾ ਡੌਕੂਮੈਂਟ
+Name[pl]=Ostatnie dokumenty
+Name[pt]=Documentos Recentes
+Name[pt_BR]=Documentos recentes
+Name[ro]=Documente recente
+Name[ru]=Последние документы
+Name[si]=මෑතකදි භාවිත කළ ලේඛන
+Name[sk]=Nedávne dokumenty
+Name[sl]=Nedavni dokumenti
+Name[sr]=недавни документи
+Name[sr@ijekavian]=недавни документи
+Name[sr@ijekavianlatin]=nedavni dokumenti
+Name[sr@latin]=nedavni dokumenti
+Name[sv]=Senaste dokument
+Name[ta]=Recent Documents
+Name[te]=ఇటీవలి పత్రములు
+Name[tg]=Ҳуҷҷатҳои кушодашуда
+Name[th]=เอกสารที่เรียกใช้ไม่นานนี้
 +Name[tr]=Son Kullanılan Belgeler
+Name[ug]=يېقىنقى پۈتۈكلەر
+Name[uk]=Недавні документи
+Name[uz]=Yaqinda ochilgan hujjatlar
+Name[uz@cyrillic]=Яқинда очилган ҳужжатлар
+Name[vi]=T i liệu gần đây
+Name[wa]=Documints d' enawaire
+Name[xh]=Uxwebhu Olusandukusebenziswa
+Name[x-test]=xxRecent Documentsxx
+Name[zh_CN]=最近的文档
+Name[zh_TW]=最近的文件
+Icon=document-open-recent
+
+X-KDE-PluginInfo-Author=Aaron Seigo
+X-KDE-PluginInfo-Email=aseigo@kde.org
+X-KDE-PluginInfo-Name=recentdocuments
+X-KDE-PluginInfo-Version=1.0
+X-KDE-PluginInfo-License=GPL
diff --git a/runners/recentdocs/recentdocs.h b/runners/recentdocs/recentdocs.h
new file mode 100644
index 0000000..fd4d39a
--- /dev/null
+++ b/runners/recentdocs/recentdocs.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RUNNER_RECENTDOCS
+#define RUNNER_RECENTDOCS
+
+#include <sprinter/runner.h>
+
+struct RecentDoc
+{
+    QString name;
+    QString icon;
+    QString url;
+};
+
+class RecentDocsSessionData : public Sprinter::RunnerSessionData
+{
+    Q_OBJECT
+
+public:
+    RecentDocsSessionData(Sprinter::Runner *runner);
+
+    QVector<RecentDoc> recentDocs;
+
+public Q_SLOTS:
+    void updateRecentDocsList();
+};
+
+class RecentDocsRunner : public Sprinter::Runner
+{
+    Q_OBJECT
+    Q_PLUGIN_METADATA(IID "org.kde.sprinter.recentdocs" FILE "recentdocs.json")
+    Q_INTERFACES(Sprinter::Runner)
+
+public:
+    RecentDocsRunner(QObject *parent = 0);
+
+    Sprinter::RunnerSessionData *createSessionData();
+    void match(Sprinter::MatchData &matchData);
+    bool exec(const Sprinter::QueryMatch &match);
+};
+
+#endif
diff --git a/runners/recentdocs/recentdocs.json b/runners/recentdocs/recentdocs.json
new file mode 100644
index 0000000..b8f213f
--- /dev/null
+++ b/runners/recentdocs/recentdocs.json
@@ -0,0 +1,9 @@
+{
+    "Icon": "document-open-recent",
+    "Name": "Recent Documents",
+    "X-KDE-PluginInfo-Author": "Aaron Seigo",
+    "X-KDE-PluginInfo-Email": "aseigo@kde.org",
+    "X-KDE-PluginInfo-License": "GPL",
+    "X-KDE-PluginInfo-Name": "recentdocuments",
+    "X-KDE-PluginInfo-Version": "1.0"
+}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic