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

List:       kde-commits
Subject:    playground/base/nepomuk-kde/annotation/lib/gui
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2010-05-04 10:41:59
Message-ID: 20100504104159.AD85CAC8AB () svn ! kde ! org
[Download RAW message or body]

SVN commit 1122621 by trueg:

Create more resource actions using the annotation plugin system.

 M  +87 -1     annotationmenu.cpp  
 M  +3 -0      annotationmenu.h  


--- trunk/playground/base/nepomuk-kde/annotation/lib/gui/annotationmenu.cpp \
#1122620:1122621 @@ -25,6 +25,8 @@
 #include "nuao.h"
 #include "tmo.h"
 #include "nepomukcontext.h"
+#include "resourceannotationmodel.h"
+#include "annotation.h"
 
 #include <QtCore/QPointer>
 #include <QtCore/QList>
@@ -61,13 +63,16 @@
 // TODO: most of the "related resources" and "set context" action methods are \
similar and could be merged  
 Q_DECLARE_METATYPE( Nepomuk::Types::Class )
+Q_DECLARE_METATYPE( Nepomuk::Annotation* )
 
 
 class Nepomuk::AnnotationMenu::Private
 {
 public:
     Private()
-        : m_enableNewResourceActions( true ) {
+        : m_enableNewResourceActions( true ),
+          m_annotationTitleCreated( false ),
+          m_annotationModel( 0 ) {
     }
 
     typedef QPair<Nepomuk::Types::Class, Nepomuk::Query::Term> TypeElement;
@@ -78,20 +83,25 @@
     QAction* createBusyAction() const;
     QAction* createRelateToAction( const QUrl& resource ) const;
     QAction* createContextAction( const QUrl& resource ) const;
+    QAction* createAnnotationAction( Annotation* annotation ) const;
 
     void addNewResourceActions( KMenu* menu );
     void addRatingAction( KMenu* menu );
     void addRelateToActions( KMenu* menu );
     void addContextActions( KMenu* menu );
+    void addAnnotationActions( KMenu* menu );
 
     void _k_ratingChanged(unsigned int);
     void _k_relateToActionTriggered();
     void _k_contextActionTriggered();
     void _k_newResourceActionTriggered();
+    void _k_annotationActionTriggered();
     void _k_nextRelateToResourceReady( Soprano::Util::AsyncQuery* query );
     void _k_relateToResourceQueryFinished( Soprano::Util::AsyncQuery* );
     void _k_nextContextReady( Soprano::Util::AsyncQuery* );
     void _k_contextQueryFinished( Soprano::Util::AsyncQuery* );
+    void _k_newAnnotation( Nepomuk::Annotation* );
+    void _k_annotationModelFinished();
 
     bool m_enableNewResourceActions;
 
@@ -102,7 +112,11 @@
     QPointer<KMenu> m_menu;
     QPointer<QAction> m_relateToBusyAction;
     QPointer<QAction> m_contextQueryBusyAction;
+    QPointer<QAction> m_annotationsBusyAction;
+    bool m_annotationTitleCreated;
 
+    ResourceAnnotationModel* m_annotationModel;
+
     AnnotationMenu* q;
 };
 
@@ -196,6 +210,17 @@
 }
 
 
+QAction* Nepomuk::AnnotationMenu::Private::createAnnotationAction( Annotation* \
annotation ) const +{
+    kDebug();
+    QAction* action = new QAction( m_menu );
+    action->setText( annotation->comment() );
+    action->setData( QVariant::fromValue( annotation ) );
+    q->connect( action, SIGNAL( triggered() ), SLOT(_k_annotationActionTriggered()) \
); +    return action;
+}
+
+
 void Nepomuk::AnnotationMenu::Private::addRatingAction( KMenu* menu )
 {
     kDebug();
@@ -333,6 +358,28 @@
 }
 
 
+void Nepomuk::AnnotationMenu::Private::addAnnotationActions( KMenu* menu )
+{
+    kDebug();
+
+    // add widget action showing a busy thingi and query the resources async
+    m_annotationsBusyAction = createBusyAction();
+    menu->addAction( m_annotationsBusyAction );
+
+    m_annotationTitleCreated = false;
+
+    if ( !m_annotationModel ) {
+        m_annotationModel = new ResourceAnnotationModel( q );
+        q->connect( m_annotationModel, SIGNAL( newAnnotation( Nepomuk::Annotation* ) \
), +                    SLOT( _k_newAnnotation( Nepomuk::Annotation* ) ) );
+        q->connect( m_annotationModel, SIGNAL( finished() ),
+                    SLOT( _k_annotationModelFinished() ) );
+    }
+
+    m_annotationModel->setResource( m_resource );
+}
+
+
 void Nepomuk::AnnotationMenu::Private::_k_ratingChanged( unsigned int rating )
 {
     kDebug();
@@ -372,6 +419,14 @@
 }
 
 
+void Nepomuk::AnnotationMenu::Private::_k_annotationActionTriggered()
+{
+    kDebug();
+    Nepomuk::Annotation* annotation = qobject_cast<QAction*>( q->sender() \
)->data().value<Nepomuk::Annotation*>(); +    annotation->create( m_resource );
+}
+
+
 void Nepomuk::AnnotationMenu::Private::_k_nextRelateToResourceReady( \
Soprano::Util::AsyncQuery* query )  {
     kDebug();
@@ -416,6 +471,32 @@
 }
 
 
+void Nepomuk::AnnotationMenu::Private::_k_newAnnotation( Nepomuk::Annotation* \
annotation ) +{
+    kDebug();
+
+    if ( !m_menu )
+        return;
+
+    if ( !m_annotationTitleCreated ) {
+        m_annotationTitleCreated = true;
+        m_menu->addTitle( i18nc( "@title:menu title above a set of possible \
annotations for the current resource.", +                                 "Annotate:" \
), +                          m_annotationsBusyAction );
+    }
+
+    m_menu->insertAction( m_annotationsBusyAction, createAnnotationAction( \
annotation ) ); +}
+
+
+void Nepomuk::AnnotationMenu::Private::_k_annotationModelFinished()
+{
+    kDebug();
+    delete m_annotationsBusyAction;
+}
+
+
+
 Nepomuk::AnnotationMenu::AnnotationMenu( QObject* parent )
     : QObject( parent ),
       d( new Private() )
@@ -508,6 +589,11 @@
         menu.addSeparator();
     }
 
+    if ( d->m_resource.isValid() ) {
+        // a header will only be added in case that we actually find some possible \
annotations +        d->addAnnotationActions( &menu );
+    }
+
     menu.exec( pos );
 }
 
--- trunk/playground/base/nepomuk-kde/annotation/lib/gui/annotationmenu.h \
#1122620:1122621 @@ -97,10 +97,13 @@
         Q_PRIVATE_SLOT( d, void _k_relateToActionTriggered() )
         Q_PRIVATE_SLOT( d, void _k_contextActionTriggered() )
         Q_PRIVATE_SLOT( d, void _k_newResourceActionTriggered() )
+        Q_PRIVATE_SLOT( d, void _k_annotationActionTriggered() )
         Q_PRIVATE_SLOT( d, void _k_nextRelateToResourceReady( \
                Soprano::Util::AsyncQuery* ) )
         Q_PRIVATE_SLOT( d, void _k_relateToResourceQueryFinished( \
                Soprano::Util::AsyncQuery* ) )
         Q_PRIVATE_SLOT( d, void _k_nextContextReady( Soprano::Util::AsyncQuery* ) )
         Q_PRIVATE_SLOT( d, void _k_contextQueryFinished( Soprano::Util::AsyncQuery* \
) ) +        Q_PRIVATE_SLOT( d, void _k_newAnnotation( Nepomuk::Annotation* ) )
+        Q_PRIVATE_SLOT( d, void _k_annotationModelFinished() )
     };
 }
 


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

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