• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

recentdocuments.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 Sebastian Kügler <sebas@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "recentdocuments.h"
00021 
00022 #include <KConfig>
00023 #include <KConfigGroup>
00024 #include <KDebug>
00025 #include <KDirWatch>
00026 #include <KIcon>
00027 #include <KStandardDirs>
00028 #include <KRun>
00029 #include <KRecentDocument>
00030 
00031 
00032 RecentDocuments::RecentDocuments(QObject *parent, const QVariantList& args)
00033     : Plasma::AbstractRunner(parent, args)
00034 {
00035     Q_UNUSED(args);
00036     KGlobal::locale()->insertCatalog("krunner_recentdocuments");
00037     setObjectName("Recent Documents");
00038     m_icon = KIcon("document-open-recent");
00039     loadRecentDocuments();
00040     // listen for changes to the list of recent documents
00041     KDirWatch *recentDocWatch = new KDirWatch(this);
00042     recentDocWatch->addDir(KRecentDocument::recentDocumentDirectory(), KDirWatch::WatchFiles);
00043     connect(recentDocWatch,SIGNAL(created(QString)),this,SLOT(loadRecentDocuments()));
00044     connect(recentDocWatch,SIGNAL(deleted(QString)),this,SLOT(loadRecentDocuments()));
00045     connect(recentDocWatch,SIGNAL(dirty(QString)),this,SLOT(loadRecentDocuments()));
00046 }
00047 
00048 RecentDocuments::~RecentDocuments()
00049 {
00050 }
00051 
00052 void RecentDocuments::loadRecentDocuments()
00053 {
00054     kDebug()<<" Refreshing recent documents.";
00055     m_recentdocuments = KRecentDocument::recentDocuments();
00056 }
00057 
00058 
00059 void RecentDocuments::match(Plasma::RunnerContext &context)
00060 {
00061     if (m_recentdocuments.isEmpty()) {
00062         return;
00063     }
00064 
00065     const QString term = context.query();
00066     if (term.length() < 3) {
00067         return;
00068     }
00069 
00070     foreach (const QString &document, m_recentdocuments) {
00071         if (document.contains(term, Qt::CaseInsensitive)) {
00072             KConfig _config( document, KConfig::SimpleConfig );
00073             KConfigGroup config(&_config, "Desktop Entry" );
00074             QString niceName =  config.readEntry( "Name" );
00075             Plasma::QueryMatch match(this);
00076             match.setType(Plasma::QueryMatch::PossibleMatch);
00077             match.setRelevance(1.0);
00078             match.setIcon(KIcon(config.readEntry("Icon")));
00079             match.setData(document); // TODO: Read URL[$e], or can we just pass the path to the .desktop file?
00080             match.setText(niceName);
00081             match.setSubtext(i18n("Recent Document"));
00082             context.addMatch(term, match);
00083         }
00084     }
00085 }
00086 
00087 void RecentDocuments::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
00088 {
00089     Q_UNUSED(context)
00090     QString url = match.data().toString();
00091     kDebug() << "Opening Recent Document" << url;
00092     new KRun(url, 0);
00093 }
00094 
00095 #include "recentdocuments.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal