Bug 131794 - Matching by file location in a smart playlist no longer works
Summary: Matching by file location in a smart playlist no longer works
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: general (show other bugs)
Version: 1.4.2-beta1
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Amarok Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-03 18:04 UTC by Dave Baker
Modified: 2006-08-12 11:11 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Baker 2006-08-03 18:04:36 UTC
Version:           1.4.2-beta1 (using KDE KDE 3.5.3)
Installed from:    Gentoo Packages
OS:                Linux

Smart playlists that have restrictions based on the file's location no longer work, or at least, the 'starts with' filter no longer works.

Scenario: I have a smart playlist with the filter 'File path' starts with '/home/dave'. Even though a large number of songs in my collection are under this location, the smart playlist is reported to contain no tracks.
Comment 1 Maximilian Kossick 2006-08-03 23:04:55 UTC
This is a Dynamic Collection regression. I think it won't work if you
filter for the file path in the playlist or collection browser either.
Comment 2 Martin Aumueller 2006-08-05 01:13:22 UTC
While this is something that probably should be addressed, I don't think that the old functionality has to be restored 100%: instead, the changeable mount-point dependent part and the constant part relative to the medium's root could be treated separately.
Comment 3 Maximilian Kossick 2006-08-12 00:12:53 UTC
SVN commit 572221 by mkossick:

added Dynamic Collection awareness to smart playlists, in particular the file path criteria. 
It is not possible to compare the value of the file path criteria to the file's absolute 
path efficiently (because the absolute path is not stored in the database anymore). So 
instead the value of the file path criteria is compared to the relative path, and a new 
criteria "Mount Point" allows to select songs on a device where the device's mount point 
is/contains/starts with/ends with the criteria's value.
CCBUG: 131794


 M  +23 -8     smartplaylisteditor.cpp  


--- trunk/extragear/multimedia/amarok/src/smartplaylisteditor.cpp #572220:572221
@@ -48,7 +48,8 @@
     FLastPlay,
     FModfiedDate,
     FFilePath,
-    FBPM
+    FBPM,
+    FMountPoint
 };
 
 
@@ -154,15 +155,15 @@
              << i18n("Track #") << i18n("Year") << i18n("Comment") << i18n("Play Counter")
              << i18n("Score") << i18n( "Rating" ) << i18n("First Play")
              << i18n("Last Play") << i18n("Modified Date") << i18n("File Path")
-             << i18n("BPM");
+             << i18n("BPM") << i18n("Mount Point");
 
     m_dbFields.clear();
     //TODO max: make sure the search for URL works correctly
     m_dbFields << "artist.name" << "composer.name" << "album.name" << "genre.name" << "tags.title" << "tags.length"
                << "tags.track" << "year.name" << "tags.comment" << "statistics.playcounter"
                << "statistics.percentage" << "statistics.rating" << "statistics.createdate"
-               << "statistics.accessdate" << "tags.createdate" << "tags.url" << "tags.sampler"
-               << "tags.bpm";
+               << "statistics.accessdate" << "tags.createdate" << "tags.url"
+               << "tags.bpm" << "devices.lastmountpoint";
 
     m_expandableFields.clear();
     m_expandableFields << i18n("Artist") << i18n("Composer") << i18n("Album") << i18n("Genre") <<  i18n("Year");
@@ -413,7 +414,9 @@
 
                 QString str = criteria->getSearchCriteria();
                 if( str.contains( "statistics." ) && !joins.contains( "statistics" ) )
-                    joins += " LEFT JOIN statistics ON statistics.url=tags.url";
+                    joins += " LEFT JOIN statistics ON statistics.url=tags.url AND statistics.deviceid=tags.deviceid";
+                if( str.contains( "devices." ) && !joins.contains( "devices" ) )
+                    joins += " LEFT JOIN devices ON tags.deviceid=devices.id";
 
                 if( i ) //multiple conditions
                     str.prepend( " OR (");
@@ -435,7 +438,9 @@
 
                 QString str = criteria2->getSearchCriteria();
                 if( str.contains( "statistics." ) && !joins.contains( "statistics" ) )
-                    joins += " LEFT JOIN statistics ON statistics.url=tags.url";
+                    joins += " LEFT JOIN statistics ON statistics.url=tags.url AND statistics.deviceid=tags.deviceid";
+                if( str.contains( "devices." ) && !joins.contains( "devices" ) )
+                    joins += " LEFT JOIN devices ON tags.deviceid=devices.id";
 
                 if( i ) //multiple conditions
                     str.prepend( " AND (");
@@ -453,7 +458,7 @@
         if( m_orderCombo->currentItem() != m_orderCombo->count()-1 ) {
             QString field = m_dbFields[ m_orderCombo->currentItem() ];
             if( field.contains( "statistics." ) && !joins.contains( "statistics" ) )
-                joins += " LEFT JOIN statistics ON statistics.url=tags.url";
+                joins += " LEFT JOIN statistics ON statistics.url=tags.url AND statistics.deviceid=tags.deviceid";
 
             QString orderType = m_orderTypeCombo->currentItem() == 1 ? " DESC" : " ASC";
             orderStr = " ORDER BY " +  field + orderType;
@@ -493,7 +498,7 @@
         QString field = m_expandableDbFields[ m_expandCombo->currentItem() ];
         QString table = field.left( field.find('.') );
         if( !joins.contains( table ) ) {
-            joins += " LEFT JOIN statistics ON statistics.url=tags.url";
+            joins += " LEFT JOIN statistics ON statistics.url=tags.url AND statistics.deviceid=tags.deviceid";
         }
         if ( !criteriaListStr.isEmpty() )
             whereStr = QString(" WHERE (%1) AND %2 = '(*ExpandString*)'").arg(criteriaListStr).arg(field);
@@ -764,7 +769,16 @@
         searchCriteria += value;
     }
     else if( criteria == i18n("starts with") )
+    {
+        if( field == "tags.url" )
+        {
+            if( value.startsWith( "/" ) )
+                value = "." + value;
+            if( !value.startsWith( "./" ) )
+                value = "./" + value;
+        }
         searchCriteria += CollectionDB::likeCondition( value, false, true );
+    }
     else if( criteria == i18n("ends with") )
         searchCriteria += CollectionDB::likeCondition( value, true, false );
     else if( criteria == i18n("is greater than") || criteria == i18n("is after") )
@@ -1022,6 +1036,7 @@
         case FTitle:
         case FComment:
         case FFilePath:
+        case FMountPoint:
             valueType = String;
             break;
         case FLength:
Comment 4 Maximilian Kossick 2006-08-12 11:11:50 UTC
As Martin described, the changeable mount point and the fixed path relative to the medium's root are now treated separately. An even better way to handle the changeable mount point would be to create a new criteria which checks the (user-definable) device label. This would allow you to create a smart playlists which contains all songs on a external USB harddisk, and it would even work if the mount point of the harddisk changes.
But this won't be done for 1.4.2 because there is no way to edit the device/medium label in the GUI yet.