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

List:       kde-commits
Subject:    playground/base/nepomuk-kde/konqueror/taskplugin
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2010-05-20 16:44:07
Message-ID: 20100520164407.A45FEAC8BB () svn ! kde ! org
[Download RAW message or body]

SVN commit 1128914 by trueg:

Use AnnotationMenu in the plugin

 M  +1 -2      CMakeLists.txt  
 M  +59 -123   konquerortaskplugin.cpp  
 M  +11 -32    konquerortaskplugin.h  
 M  +1 -13     newsitedialog.cpp  
 M  +6 -20     newsitedialog.ui  


--- trunk/playground/base/nepomuk-kde/konqueror/taskplugin/CMakeLists.txt \
#1128913:1128914 @@ -12,7 +12,6 @@
 )
 
 kde4_add_ui_files(SRCS newsitedialog.ui)
-soprano_add_ontology(SRCS ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/pimo/tmo.trig "TMO" \
"Nepomuk::Vocabulary" "trig")  
 kde4_add_plugin(khtml_nepomuk_task_linker
   ${SRCS}
@@ -26,7 +25,7 @@
   ${SOPRANO_LIBRARIES}
   nepomukutils
   nepomukcontext
-  nepomuktasks
+  nepomukannotation
 )
 
 install(TARGETS khtml_nepomuk_task_linker DESTINATION ${PLUGIN_INSTALL_DIR})
--- trunk/playground/base/nepomuk-kde/konqueror/taskplugin/konquerortaskplugin.cpp \
#1128913:1128914 @@ -1,5 +1,6 @@
 /*
     Copyright (c) 2009 Charles Wautier <charles.wautier@gmail.com>
+    Copyright (c) 2010 Sebastian Trueg <trueg@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
@@ -15,13 +16,15 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "newsitedialog.h"
 #include "konquerortaskplugin.h"
+
+#include "newsitedialog.h"
 #include "ui_newsitedialog.h"
-#include "tmo.h"
-#include "tasktreedialog.h"
+#include "nepomukcontext.h"
+#include "annotationmenu.h"
 
 #include "pimo.h"
+#include "nfo.h"
 
 #include <soprano/nao.h>
 #include <soprano/rdf.h>
@@ -37,7 +40,7 @@
 #include <Nepomuk/Resource>
 #include <Nepomuk/Variant>
 
-#include <KToolBarPopupAction>
+#include <KActionMenu>
 #include <KAction>
 #include <KActionCollection>
 #include <KLocale>
@@ -59,162 +62,95 @@
 #include <dom/html_document.h>
 #include <dom/dom_string.h>
 
-#define NFO_WEBSITE_TYPE \
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Website"  
 Nepomuk::KonquerorTaskPlugin::KonquerorTaskPlugin(QObject* parent, const \
QVariantList&)  : KParts::Plugin(parent)
 {
-    // Configure the button
-    taskAction = new KToolBarPopupAction(KIcon("view-calendar-tasks"), \
                i18n("Action"), actionCollection());
-    taskAction->setText(i18n("Associate the current page to a task"));
+    m_action = new KActionMenu( KIcon( "view-calendar-tasks" ),
+                                i18n( "Associate the current page to a task or \
project" ), +                                actionCollection() );
+    actionCollection()->addAction("nepomuk_link_to_task", m_action);
 
-    actionCollection()->addAction("nepomuk_link_to_task", taskAction);
-
-    connect(taskAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)),
+    connect(m_action, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)),
             this, SLOT(slotLinkToCurrentTask(Qt::MouseButtons, \
                Qt::KeyboardModifiers)));
-    connect(taskAction->menu(), SIGNAL(aboutToShow()),
-            this, SLOT(slotUpdateTaskList()));
 
-    // Configure the connection to the context service
-    m_context = new Nepomuk::ContextServiceInterface();
-    m_currentContext = m_context->currentContext();
-    connect(m_context, SIGNAL(currentContextChanged(Nepomuk::Resource)),
-            this, SLOT(slotContextChanged(Nepomuk::Resource)));
+    m_annotationMenu = new Nepomuk::AnnotationMenu();
+    m_action->setMenu( m_annotationMenu );
+    connect( m_annotationMenu, SIGNAL( resourcesAnnotated() ),
+             this, SLOT( slotResourceAnnotatedViaMenu() ) );
+    connect( m_annotationMenu, SIGNAL( \
aboutToBeConstructed(Nepomuk::AnnotationMenu*) ), +             this, SLOT( \
slotAnnotationMenuAboutToBeConstucted() ) );  
-    // Make the connection with Nepomuk server
-    if (Nepomuk::ResourceManager::instance()->init()) {
-        //FIXME : Errormessage in dialog box ?
-        //KMessageBox::error( 0,
-        //        i18n("<b>Unable to join nepomukserver</b><br>Task Plugin won't \
                work") );
-        //kError() << "Unable to initialize KMetaData";
-        delete taskAction;
+    m_context = new Nepomuk::ContextServiceInterface(this);
     }
-}
 
+
 Nepomuk::KonquerorTaskPlugin::~KonquerorTaskPlugin()
 {
 }
 
-void Nepomuk::KonquerorTaskPlugin::slotContextChanged(Nepomuk::Resource res)
-{
-    m_currentContext = res;
-}
 
-void Nepomuk::KonquerorTaskPlugin::slotUpdateTaskList()
+void Nepomuk::KonquerorTaskPlugin::slotLinkToCurrentTask(Qt::MouseButtons, \
Qt::KeyboardModifiers)  {
-
-    // Clear the existing task list
-    taskAction->menu()->clear();
-
-    // Load the task list with the most recently used tasks
-
-    //// Unordered version:
-    //Soprano::StatementIterator it =
-    //    Nepomuk::ResourceManager::instance()->mainModel()->listStatements(Soprano::Node(),
                
-    //                                                                      \
                Soprano::Node(Soprano::Vocabulary::RDF::type()),
-    //                                                                      \
                Soprano::Node(Nepomuk::Vocabulary::TMO::Task()));
-    //for ( int i = 0 ; i < 9 && it.next() ; ++i )
-    //{
-    //    Nepomuk::Resource res((*it).subject().uri());
-    //    QAction* taskEntry = new QAction( KIcon(res.genericIcon()), res.label(), \
                this );
-    //    taskEntry->setData( QVariant( res.resourceUri().toString() ) );
-    //
-    //    connect( taskEntry, SIGNAL( triggered() ),
-    //             this, SLOT( slotLinkToTask() ) );
-    //    taskAction->menu()->addAction( taskEntry );
-    //}
-    //taskAction->menu()->addSeparator();
-    //taskAction->menu()->addAction( KIcon("nepomuk"), QString(i18n("Other ...")), \
                this, SLOT(slotLinkToSelectedTask() ) );
-
-    //// Ordered version :
-    // Make the query
-    QString query = QString("select distinct ?r where { "
-                            "?r <%1> <%2> . "
-                            "?r <%3> ?d . }"
-                            "order by DESC(?d)")  // ORDER BY creation date
-                    .arg(Soprano::Vocabulary::RDF::type().toString())
-                    .arg(Nepomuk::Vocabulary::TMO::Task().toString())
-                    .arg(Soprano::Vocabulary::NAO::created().toString());
-
-    // Parse the result
-    Soprano::QueryResultIterator it =
-        Nepomuk::ResourceManager::instance()->mainModel()->executeQuery(query, \
                Soprano::Query::QueryLanguageSparql);
-
-    // Add the tasks into the pop-up menu
-    for (int i = 0 ; i < 9 && it.next() ; ++i) {
-        Nepomuk::Resource res(it.binding("r").uri());
-        QAction* taskEntry = new QAction(KIcon(res.genericIcon()), \
                res.genericLabel(), this);
-        taskEntry->setData(QVariant(res.resourceUri()));
-
-        connect(taskEntry, SIGNAL(triggered()),
-                this, SLOT(slotLinkToTask()));
-        taskAction->menu()->addAction(taskEntry);
+    if (m_context->currentContext().isValid()) {
+        createWebsiteResource().pimoThing().addProperty(Nepomuk::Vocabulary::PIMO::isRelated(), \
m_context->currentContext());  }
-
-    //
-    taskAction->menu()->addSeparator();
-    taskAction->menu()->addAction(KIcon("nepomuk"), i18n("Other..."), this, \
SLOT(slotLinkToSelectedTask())); +    else {
+        KMessageBox::sorry( 0, i18n( "No current work context set" ) );
 }
+}
 
-void Nepomuk::KonquerorTaskPlugin::slotLinkToCurrentTask(Qt::MouseButtons, \
Qt::KeyboardModifiers) +
+void Nepomuk::KonquerorTaskPlugin::slotAnnotationMenuAboutToBeConstucted()
 {
-    if (m_currentContext.isValid()) {
-        doLinkToTask(m_currentContext);
-    } else {
-        slotLinkToSelectedTask();
+    kDebug();
+    if (parent() && parent()->inherits("KHTMLPart")) {
+        KHTMLPart* htmlPart = static_cast<KHTMLPart*>(parent());
+        m_annotationMenu->setResource( htmlPart->url() );
     }
 }
 
-void Nepomuk::KonquerorTaskPlugin::slotLinkToTask()
-{
-    Nepomuk::Resource \
                res(static_cast<QAction*>(sender())->data().toUrl());//value<KUrl>());
                
-    doLinkToTask(res);
-}
 
-void Nepomuk::KonquerorTaskPlugin::slotLinkToSelectedTask()
+void Nepomuk::KonquerorTaskPlugin::slotResourceAnnotatedViaMenu()
 {
-    // Parameters are just the title and the parent of the dialog window
-    Nepomuk::Resource res = TaskTreeDialog::selectOneTask(taskAction->menu());
-    if (res.isValid()) {
-        doLinkToTask(res);
+    kDebug();
+    // set properties on the page (after the annotation has already been done)
+    createWebsiteResource();
     }
-}
 
-void Nepomuk::KonquerorTaskPlugin::doLinkToTask(Nepomuk::Resource &tsk) const
+
+Nepomuk::Resource Nepomuk::KonquerorTaskPlugin::createWebsiteResource() const
 {
+    kDebug();
     if (parent() && parent()->inherits("KHTMLPart")) {
-
         KHTMLPart* htmlPart = static_cast<KHTMLPart*>(parent());
+        Nepomuk::Resource nfoResource(htmlPart->url(), \
Nepomuk::Vocabulary::NFO::Website()); +        if ( !nfoResource.exists() ) {
 
-        // Get the resource corresponding to the url if it exists.
-        // If it does nt exists yet, it create the resource, but don't add it in \
                Nepomuk database.
-        Nepomuk::Resource nfoResource(htmlPart->url(), \
                QUrl::fromEncoded(NFO_WEBSITE_TYPE, QUrl::StrictMode));
-
         // Configure the dialog
-        NewSiteDialog dlg(taskAction->menu());
-        dlg.setCaption(i18n("Associate Page to Task"));
+            NewSiteDialog dlg;
+            dlg.setCaption(i18n("Create Relation From Website"));
         dlg.m_url->setText(htmlPart->url().url());
-        dlg.m_url->setText(htmlPart->url().url());
-        dlg.m_title->setText(i18nc("@title:window", "Link page"));
-        dlg.m_title->setComment(i18n("to the task ") + \
QString("<i>%1</i>").arg(tsk.label())); +            \
dlg.m_title->setText(i18nc("@title:window", "Relate Page")); +//             \
dlg.m_title->setComment(i18nc("%1 is the label of a resource, %2 is its type", +//    \
"<p>to <emphasis>%1</emphasis> (%2)", +//                                           \
res.genericLabel(), +//                                           \
Nepomuk::Types::Class( res.resourceType() ).label() ));  
-        bool exists = nfoResource.exists();
-        if (exists) {
-            dlg.m_nameLabel->setText(nfoResource.genericLabel());
-        } else {
-            dlg.m_nameLabel->setText(htmlPart->htmlDocument().title().string().trimmed());
                
-            dlg.m_nameLabel->toggleEditor(true);
+            // set a default label
+            dlg.m_labelEdit->setText(htmlPart->htmlDocument().title().string().trimmed());
 +            dlg.m_labelEdit->setFocus(Qt::OtherFocusReason);
+
+            // exec the dialog -> there is no going back now
+            dlg.exec();
+
+            nfoResource.pimoThing().setLabel(dlg.m_labelEdit->text());
         }
 
-        // If Accepted, do link the page to the task (and create the page \
                corresponding resource if needed)
-        // Else, we have not create the resource corresponding to the page, since a \
                new Nepomuk::Resource X
-        // is exported in the database only if we modify it, by X.addProperty( ... ) \
                for example.
-        if (dlg.exec() == QDialog::Accepted) {
-            Nepomuk::Thing webPageThing = nfoResource.pimoThing();
-            nfoResource.addProperty(Nepomuk::Vocabulary::PIMO::isRelated(), tsk);
-            nfoResource.setLabel(dlg.m_nameLabel->text());
-            nfoResource.addSymbol("text-html");
+        return nfoResource;
         }
+    else {
+        return Resource();
     }
 }
 
--- trunk/playground/base/nepomuk-kde/konqueror/taskplugin/konquerortaskplugin.h \
#1128913:1128914 @@ -1,5 +1,6 @@
 /*
     Copyright (c) 2009 Charles Wautier <charles.wautier@gmail.com>
+    Copyright (c) 2010 Sebastian Trueg <trueg@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
@@ -19,59 +20,37 @@
 #define _KONQUEROR_TASK_PLUGIN_H_
 
 #include <kparts/plugin.h>
-#include <Nepomuk/Resource>
-#include "nepomukcontext.h"
 
-class KToolBarPopupAction;
+class KActionMenu;
 
 namespace Nepomuk
 {
+    class AnnotationMenu;
+    class ContextServiceInterface;
+    class Resource;
 
 /**
- * A button inserted in Konqueror's ToolBar to link the current webpage to a task
+     * A button inserted in Konqueror's ToolBar opening an AnnotationMenu
  */
 class KonquerorTaskPlugin : public KParts::Plugin
 {
     Q_OBJECT
 
 public:
-
     KonquerorTaskPlugin(QObject* parent, const QVariantList& args = QVariantList());
     ~KonquerorTaskPlugin();
 
 private Q_SLOTS:
-
-    /**
-     * The 'context' is a particular resource, managed by a NepomukService,
-     * so we can access and set it from any program.
-     * Changes m_currentContext.
-     */
-    void slotContextChanged(Nepomuk::Resource);
-    /**
-     * Update the list of the 9 tasks the most recently used before the user
-     * click on the pop-up menu.
-     */
-    void slotUpdateTaskList();
-
-    /**
-     * One slot per type of link button. They get the appropriate task and
-     * give it to doLinkTask which will make the effective job.
-     */
     void slotLinkToCurrentTask(Qt::MouseButtons, Qt::KeyboardModifiers);
-    void slotLinkToTask();
-    void slotLinkToSelectedTask();
+        void slotAnnotationMenuAboutToBeConstucted();
+        void slotResourceAnnotatedViaMenu();
 
 private:
+        Nepomuk::Resource createWebsiteResource() const;
 
+        Nepomuk::AnnotationMenu* m_annotationMenu;
     Nepomuk::ContextServiceInterface* m_context;
-    Nepomuk::Resource m_currentContext;
-    KToolBarPopupAction* taskAction;
-
-    /**
-     * Link the page to the task.
-     */
-    void doLinkToTask(Nepomuk::Resource &tsk) const;
-
+        KActionMenu* m_action;
 };
 }
 
--- trunk/playground/base/nepomuk-kde/konqueror/taskplugin/newsitedialog.cpp \
#1128913:1128914 @@ -28,26 +28,14 @@
 NewSiteDialog::NewSiteDialog(QWidget* parent)
         : KDialog(parent)
 {
-    setButtons(Ok | Cancel);
+    setButtons(Ok);
     setupUi(mainWidget());
 
     m_title->setPixmap(KIcon("nepomuk").pixmap(32, 32));
 
-    m_nameLabel->setMaximumSize(16000, 19);
-    m_nameLabel->setMinimumSize(300, 19);
-    m_nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
-
-    m_url->setMaximumSize(16000, 19);
-    m_url->setMinimumSize(300, 19);
-    m_url->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
-
-    m_title->setMaximumSize(16000, 16000);
-    m_title->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
-
     setMaximumSize(800, 16000);
     setMinimumSize(400, 200);
     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-
 }
 
 NewSiteDialog::~NewSiteDialog()
--- trunk/playground/base/nepomuk-kde/konqueror/taskplugin/newsitedialog.ui \
#1128913:1128914 @@ -85,25 +85,12 @@
        </property>
       </widget>
      </item>
-     <item row="0" column="1">
-      <widget class="LabelEditWidget" name="m_nameLabel" native="true">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="minimumSize">
-        <size>
-         <width>0</width>
-         <height>19</height>
-        </size>
-       </property>
-      </widget>
-     </item>
      <item row="1" column="1">
       <widget class="KSqueezedTextLabel" name="m_url"/>
      </item>
+     <item row="0" column="1">
+      <widget class="KLineEdit" name="m_labelEdit"/>
+     </item>
     </layout>
    </item>
    <item>
@@ -133,10 +120,9 @@
    <header>ktitlewidget.h</header>
   </customwidget>
   <customwidget>
-   <class>LabelEditWidget</class>
-   <extends>QWidget</extends>
-   <header>labeleditwidget.h</header>
-   <container>1</container>
+   <class>KLineEdit</class>
+   <extends>QLineEdit</extends>
+   <header>klineedit.h</header>
   </customwidget>
  </customwidgets>
  <resources/>


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

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