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

List:       kde-panel-devel
Subject:    Re: [Panel-devel] bookmark runner
From:       Glenn Ergeerts <glenn.ergeerts () telenet ! be>
Date:       2007-11-02 9:36:01
Message-ID: 200711021036.01469.glenn.ergeerts () telenet ! be
[Download RAW message or body]

On Thursday 01 November 2007 20:12:42 Aaron J. Seigo wrote:

> cool; other than the comments of the others here, i'd suggest putting sth
> like this at the start of match():
>
> if (search->term().length() < 3) {
>     return;
> }
>
> this will prevent searching for 1 or 2 letters, which is likely to return
> lots of crud in this case. this is a somewhat common pattern for free text
> searching runns, btw. not sure if there should be some sort of generic
> support in AbstractRunner for this... probably not =)
>
> also, if you don't mind overly much ... if this goes into kdebase, and i
> think it probably should be there eventually, i'd personally appreciate it
> if the code adhered to the plasma coding style, so that this:
>
> +      while(!currentBookmark.isNull())
> +      {
> +            if(currentBookmark.isGroup()) //recurse
> +                  matchingBookmarks +=
> searchBookmarks(currentBookmark.toGroup(), query);
> +            else
> +            {
> +                  if(currentBookmark.text().contains(query,
> Qt::CaseInsensitive)) +                     
>   matchingBookmarks.append(currentBookmark);
> +            }
> +            currentBookmark = bookmarkGrp.next(currentBookmark);
> +      }
>
> would become this:
>
> +      while (!currentBookmark.isNull()) {
> +            if (currentBookmark.isGroup()) { //recurse
> +                  matchingBookmarks +=
> searchBookmarks(currentBookmark.toGroup(), query);
> +            } else  {
> +                  if (currentBookmark.text().contains(query,
> Qt::CaseInsensitive)) {
> +                        matchingBookmarks.append(currentBookmark);
> +            }
> +            }
> +            currentBookmark = bookmarkGrp.next(currentBookmark);
> +      }
>
>
> i'm pretty relaxed when it comes to plugins, but it would be great to see
> some greater general consistency in workspace/plasma ...
>
> otherwise, i'm all for this addition ...

Hi,

attached is a new patch with the requested changes. I hope this complies with 
the coding guidelines.. 

regards,
Glenn

["bookmarkrunner2.patch" (text/x-diff)]

Index: workspace/plasma/runners/bookmarks/plasma-runner-bookmarks.desktop
===================================================================
--- workspace/plasma/runners/bookmarks/plasma-runner-bookmarks.desktop	(revision 0)
+++ workspace/plasma/runners/bookmarks/plasma-runner-bookmarks.desktop	(revision 0)
@@ -0,0 +1,8 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=Bookmark Runner
+Comment=Open bookmark
+ServiceTypes=Plasma/Runner
+Type=Service
+X-KDE-Library=krunner_bookmarksrunner
+X-Krunner-ID=Bookmarks Runner
Index: workspace/plasma/runners/bookmarks/bookmarksrunner.cpp
===================================================================
--- workspace/plasma/runners/bookmarks/bookmarksrunner.cpp	(revision 0)
+++ workspace/plasma/runners/bookmarks/bookmarksrunner.cpp	(revision 0)
@@ -0,0 +1,90 @@
+/*
+ *   Copyright 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License as
+ *   published by the Free Software Foundation; either version 2, 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 Library General Public
+ *   License along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "bookmarksrunner.h"
+
+#include <QAction>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QWidget>
+#include <QScriptEngine>
+#include <QList>
+
+#include <KIcon>
+#include <KBookmarkManager>
+#include <KToolInvocation>
+#include <KUrl>
+
+
+BookmarksRunner::BookmarksRunner( QObject* parent, const QVariantList &args )
+    : Plasma::AbstractRunner(parent)
+{
+    Q_UNUSED(args)
+
+    setObjectName(i18n("Bookmarks"));
+}
+
+BookmarksRunner::~BookmarksRunner()
+{
+}
+
+void BookmarksRunner::match(Plasma::SearchContext *search)
+{
+    if (search->searchTerm().length() < 3) {
+        return;
+    }
+
+    KBookmarkManager *bookmarkMgr = KBookmarkManager::userBookmarksManager();
+    KBookmarkGroup bookmarkGrp = bookmarkMgr->root();
+
+    QList<KBookmark> matchingBookmarks = searchBookmarks(bookmarkGrp, \
search->searchTerm()); +    foreach(KBookmark bookmark, matchingBookmarks) {
+        kDebug() << "Found bookmark: " << bookmark.text() << " (" << \
bookmark.url().prettyUrl() << ")"; +        Plasma::SearchAction *action = \
search->addPossibleMatch(this); +        action->setIcon(KIcon("bookmark"));
+        action->setText(bookmark.text());
+        action->setData(bookmark.url().url());
+    }
+}
+
+QList<KBookmark> BookmarksRunner::searchBookmarks(const KBookmarkGroup &bookmarkGrp, \
const QString &query) +{
+    QList<KBookmark> matchingBookmarks;
+    KBookmark currentBookmark = bookmarkGrp.first();
+    while(!currentBookmark.isNull()) {
+        if(currentBookmark.isGroup()) { //recurse
+            matchingBookmarks += searchBookmarks(currentBookmark.toGroup(), query);
+        } else {
+            if(currentBookmark.text().contains(query, Qt::CaseInsensitive)) {
+                matchingBookmarks.append(currentBookmark);
+            }
+        }
+        currentBookmark = bookmarkGrp.next(currentBookmark);
+    }
+    return matchingBookmarks;
+}
+
+void BookmarksRunner::exec(Plasma::SearchAction *action)
+{
+    KUrl url = (KUrl)action->data().toString();
+    kDebug() << "BookmarksRunner::exec opening: " << url.url();
+    KToolInvocation::invokeBrowser(url.url());
+}
+
+#include "bookmarksrunner.moc"
Index: workspace/plasma/runners/bookmarks/bookmarksrunner.h
===================================================================
--- workspace/plasma/runners/bookmarks/bookmarksrunner.h	(revision 0)
+++ workspace/plasma/runners/bookmarks/bookmarksrunner.h	(revision 0)
@@ -0,0 +1,50 @@
+/*
+ *   Copyright 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License as
+ *   published by the Free Software Foundation; either version 2, 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 Library General Public
+ *   License along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef BOOKMARKSRUNNER_H
+#define BOOKMARKSRUNNER_H
+
+#include <KGenericFactory>
+
+#include <plasma/abstractrunner.h>
+
+class QWidget;
+
+class KBookmark;
+class KBookmarkGroup;
+
+
+class BookmarksRunner : public Plasma::AbstractRunner
+{
+    Q_OBJECT
+
+    public:
+        BookmarksRunner(QObject* parent, const QVariantList &args);
+        ~BookmarksRunner();
+
+        void match(Plasma::SearchContext *context);
+        void exec(Plasma::SearchAction *action);
+
+    private:
+        QList<KBookmark> searchBookmarks(const KBookmarkGroup &bookmarkGrp, const \
QString &query); +};
+
+K_EXPORT_PLASMA_RUNNER(bookmarksrunner, BookmarksRunner)
+
+#endif
Index: workspace/plasma/runners/bookmarks/CMakeLists.txt
===================================================================
--- workspace/plasma/runners/bookmarks/CMakeLists.txt	(revision 0)
+++ workspace/plasma/runners/bookmarks/CMakeLists.txt	(revision 0)
@@ -0,0 +1,17 @@
+
+########### next target ###############
+
+set(krunner_bookmarksrunner_SRCS
+    bookmarksrunner.cpp
+)
+
+kde4_add_plugin(krunner_bookmarksrunner ${krunner_bookmarksrunner_SRCS})
+target_link_libraries(krunner_bookmarksrunner ${KDE4_KDECORE_LIBS} \
${QT_QTSCRIPT_LIBRARY} plasma) +
+install(TARGETS krunner_bookmarksrunner DESTINATION ${PLUGIN_INSTALL_DIR} )
+
+
+########### install files ###############
+
+install(FILES plasma-runner-bookmarks.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+
Index: workspace/plasma/runners/CMakeLists.txt
===================================================================
--- workspace/plasma/runners/CMakeLists.txt	(revision 731904)
+++ workspace/plasma/runners/CMakeLists.txt	(working copy)
@@ -1,3 +1,4 @@
 add_subdirectory(calculator)
 add_subdirectory(search)
 add_subdirectory(webshortcuts)
+add_subdirectory(bookmarks)
\ No newline at end of file



_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


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

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