]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Implemented tagging of multiple files at the same time.
authorSebastian Trueg <sebastian@trueg.de>
Tue, 1 Apr 2008 12:27:06 +0000 (12:27 +0000)
committerSebastian Trueg <sebastian@trueg.de>
Tue, 1 Apr 2008 12:27:06 +0000 (12:27 +0000)
The result is always an intersection of the tags of all files.
Another possibility would be to only change the clicked tag. Feedback?

BUG: 160157

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

src/metadatawidget.cpp
src/tagcloud/resourcetaggingwidget.cpp
src/tagcloud/resourcetaggingwidget.h

index 8b9176707b37e9c1d2d941029478e213af8ee0ba..e9acac7cea0f558e97150bae645bad21daedeeea 100644 (file)
@@ -145,7 +145,7 @@ void MetaDataWidget::setFiles(const KUrl::List& urls)
         }
         first = false;
     }
-    d->tagWidget->setResource( fileRes.first() );
+    d->tagWidget->setResources( fileRes );
 #endif
 }
 
index b67e8f47de8812518f2250ae72caea6647f86687..8eba24a9cebaf31ff876513e155db808c5d8c9b3 100644 (file)
 #include <QtGui/QContextMenuEvent>
 #include <QtGui/QCursor>
 #include <QtGui/QLabel>
+#include <QtCore/QSet>
 
 #include <KLocale>
 
+namespace Nepomuk {
+    inline uint qHash( const Tag& res )
+    {
+        return qHash( res.resourceUri().toString() );
+    }
+}
+
 
 class Nepomuk::ResourceTaggingWidget::Private
 {
 public:
-    Nepomuk::Resource resource;
+    QList<Nepomuk::Resource> resources;
 
     TagCloud* resourceTagCloud;
     TaggingPopup* popup;
@@ -41,20 +49,25 @@ public:
 
     void showTaggingPopup( const QPoint& );
     void _k_slotShowTaggingPopup();
+    static QList<Tag> intersectTags( const QList<Resource>& );
 };
 
 
 void Nepomuk::ResourceTaggingWidget::Private::showTaggingPopup( const QPoint& pos )
 {
     popup->showAllTags();
-    resourceTags = resource.tags();
+    resourceTags = intersectTags( resources );
     Q_FOREACH( Tag tag, resourceTags ) {
         popup->setTagSelected( tag, true );
     }
 
     popup->exec( pos );
 
-    resource.setTags( resourceTags );
+    foreach( Resource res, resources ) {
+        res.setTags( resourceTags );
+    }
+
+    resourceTagCloud->showTags( resourceTags );
 }
 
 
@@ -64,6 +77,26 @@ void Nepomuk::ResourceTaggingWidget::Private::_k_slotShowTaggingPopup()
 }
 
 
+QList<Nepomuk::Tag> Nepomuk::ResourceTaggingWidget::Private::intersectTags( const QList<Resource>& res )
+{
+    if ( res.count() == 1 ) {
+        return res.first().tags();
+    }
+    else if ( !res.isEmpty() ) {
+        // determine the tags used for all resources
+        QSet<Tag> tags = QSet<Tag>::fromList( res.first().tags() );
+        QList<Resource>::const_iterator it = res.begin();
+        for ( ++it; it != res.end(); ++it ) {
+            tags.intersect( QSet<Tag>::fromList( (*it).tags() ) );
+        }
+        return tags.values();
+    }
+    else {
+        return QList<Tag>();
+    }
+}
+
+
 Nepomuk::ResourceTaggingWidget::ResourceTaggingWidget( QWidget* parent )
     : QWidget( parent ),
       d( new Private() )
@@ -101,8 +134,14 @@ Nepomuk::ResourceTaggingWidget::~ResourceTaggingWidget()
 
 void Nepomuk::ResourceTaggingWidget::setResource( const Nepomuk::Resource& res )
 {
-    d->resource = res;
-    d->resourceTagCloud->showResourceTags( res );
+    setResources( QList<Resource>() << res );
+}
+
+
+void Nepomuk::ResourceTaggingWidget::setResources( const QList<Nepomuk::Resource>& resList )
+{
+    d->resources = resList;
+    d->resourceTagCloud->showTags( d->intersectTags( resList ) );
 }
 
 
@@ -122,7 +161,7 @@ void Nepomuk::ResourceTaggingWidget::slotTagAdded( const Nepomuk::Tag& tag )
 {
     // assign it right away
     d->resourceTags.append( tag );
-    d->resource.addTag( tag );
+//    d->resource.addTag( tag );
 }
 
 
index a7574634841925360255db16ef9bbb80c29eb092..692b2e207e4c9e1701c4f9852e926e5d629f1ed9 100644 (file)
@@ -41,6 +41,7 @@ namespace Nepomuk {
 
     public Q_SLOTS:
         void setResource( const Nepomuk::Resource& );
+        void setResources( const QList<Nepomuk::Resource>& );
 
     private Q_SLOTS:
         void slotTagToggled( const Nepomuk::Tag& tag, bool enabled );