]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fixed context menu to delete tags.
authorSebastian Trueg <sebastian@trueg.de>
Tue, 28 Apr 2009 08:17:59 +0000 (08:17 +0000)
committerSebastian Trueg <sebastian@trueg.de>
Tue, 28 Apr 2009 08:17:59 +0000 (08:17 +0000)
BUG: 165188

svn path=/trunk/KDE/kdebase/apps/; revision=960282

src/panels/information/resourcetaggingwidget.cpp
src/panels/information/tagcloud.cpp
src/panels/information/taggingpopup.h

index 34892f30c76da7421b7d6cbbef151542ec9434af..ac14e45a065759c8ca2b09d7ffca62a69265c687 100644 (file)
@@ -51,6 +51,7 @@ public:
     bool tagsChanged;
 
     void showTaggingPopup( const QPoint& );
+    void updateResources();
     void _k_slotShowTaggingPopup();
     void _k_metadataUpdateDone();
     static QList<Tag> intersectTags( const QList<Resource>& );
@@ -71,17 +72,23 @@ void Nepomuk::ResourceTaggingWidget::Private::showTaggingPopup( const QPoint& po
     popup->exec( pos );
 
     if( tagsChanged ) {
-        MassUpdateJob* job = MassUpdateJob::tagResources( resources, resourceTags );
-        connect( job, SIGNAL( result( KJob* ) ),
-                 q, SLOT( _k_metadataUpdateDone() ) );
-        q->setEnabled( false ); // no updates during execution
-        job->start();
+        updateResources();
     }
 
     resourceTagCloud->showTags( resourceTags );
 }
 
 
+void Nepomuk::ResourceTaggingWidget::Private::updateResources()
+{
+    MassUpdateJob* job = MassUpdateJob::tagResources( resources, resourceTags );
+    connect( job, SIGNAL( result( KJob* ) ),
+             q, SLOT( _k_metadataUpdateDone() ) );
+    q->setEnabled( false ); // no updates during execution
+    job->start();
+}
+
+
 void Nepomuk::ResourceTaggingWidget::Private::_k_slotShowTaggingPopup()
 {
     showTaggingPopup( QCursor::pos() );
@@ -181,7 +188,7 @@ void Nepomuk::ResourceTaggingWidget::slotTagAdded( const Nepomuk::Tag& tag )
 {
     // assign it right away
     d->resourceTags.append( tag );
-//    d->resource.addTag( tag );
+    d->updateResources();
 }
 
 
index 0074d17968239a33e4bee172739b796ee65b7ee0..ef1df5fa4fba4bc0c37411903fe8e00c171eb208 100644 (file)
@@ -36,6 +36,9 @@
 #include <KLocale>
 #include <KColorScheme>
 #include <KDebug>
+#include <KMenu>
+#include <KIcon>
+#include <KMessageBox>
 
 #include <Soprano/Client/DBusModel>
 #include <Soprano/QueryResultIterator>
@@ -58,6 +61,10 @@ namespace {
               selected( false ) {
         }
 
+        bool operator==( const TagNode& other ) const {
+            return tag == other.tag;
+        }
+
         // fixed info
         Nepomuk::Tag tag;
         int weight;
@@ -126,6 +133,7 @@ public:
           alignment( Qt::AlignCenter ),
           sorting( SortAlpabetically ),
           zoomEnabled( true ),
+          contextMenuEnabled( true ),
           showAllTags( false ),
           customNewTagAction( 0 ),
           hoverTag( 0 ),
@@ -142,6 +150,7 @@ public:
     Qt::Alignment alignment;
     Sorting sorting;
     bool zoomEnabled;
+    bool contextMenuEnabled;
 
     // The resource whose tags we are showing
     // invalid if we show all tags or a selection
@@ -612,7 +621,7 @@ void Nepomuk::TagCloud::setZoomEnabled( bool zoom )
 
 void Nepomuk::TagCloud::setContextMenuEnabled( bool enabled )
 {
-    Q_UNUSED(enabled);
+    d->contextMenuEnabled = enabled;
 }
 
 
@@ -641,7 +650,7 @@ void Nepomuk::TagCloud::showAllTags()
 void Nepomuk::TagCloud::showResourceTags( const Resource& resource )
 {
     showTags( resource.tags() );
-    d->resource = resource.uri();
+    d->resource = resource.resourceUri();
 }
 
 
@@ -903,6 +912,24 @@ void Nepomuk::TagCloud::mousePressEvent( QMouseEvent* e )
             }
         }
     }
+    else if ( d->contextMenuEnabled &&
+              e->button() == Qt::RightButton ) {
+        if ( TagNode* node = d->tagAt( e->pos() ) ) {
+            KMenu menu;
+            QAction* a = menu.addAction( KIcon( "edit-delete" ), i18nc( "@action:menu", "Delete tag '%1'", node->text ) );
+            if ( menu.exec( e->globalPos() ) == a &&
+                 KMessageBox::questionYesNo( this, i18n( "Do you really want to delete tag '%1'", node->text ) ) == KMessageBox::Yes ) {
+                if ( d->selectionEnabled &&
+                     node->selected ) {
+                    node->selected = false;
+                    emit tagToggled( node->tag, false );
+                }
+                node->tag.remove();
+                d->nodes.removeAll( *node );
+                d->rebuildCloud();
+            }
+        }
+    }
 }
 
 
index 99cee701cd9f5053fdc83cb667ebff17c69aebdb..db9472b2393c15c083075aa21249a6265c2e94f6 100644 (file)
@@ -35,7 +35,7 @@ namespace Nepomuk {
         void popup( const QPoint& pos );
         void exec( const QPoint& pos );
 
-       bool event( QEvent* e );
+        bool event( QEvent* e );
 
     protected:
         void mousePressEvent( QMouseEvent* e );