extragear/multimedia/amarok/src/browsers/collectionbrowser

Leo Franchi lfranchi at kde.org
Thu Feb 12 00:31:44 CET 2009


SVN commit 924956 by lfranchi:

add filter for date added to collection. you can add a string like "added:today" or "added:<1m3d" to the filter textedit. there is no GUI for it at the moment, but this at least provides the backend support. yes, this as a discoverability of -1000,  but i need some UI ideas (and i think Dan has plans to redo the edit filter dialog completely, so i'm somewhat holding off).

CCMAIL: amarok-devel at kde.org

 M  +40 -0     CollectionTreeItemModelBase.cpp  


--- trunk/extragear/multimedia/amarok/src/browsers/collectionbrowser/CollectionTreeItemModelBase.cpp #924955:924956
@@ -574,6 +574,46 @@
                 else if( lcField.compare( "tracknumber", Qt::CaseInsensitive ) == 0 || lcField.compare( i18n( "tracknumber" ), Qt::CaseInsensitive ) == 0 )
                 {
                     ADD_OR_EXCLUDE_NUMBER_FILTER( Meta::valTrackNr, elem.text.toInt(), compare );
+                } else if( lcField.compare( "added", Qt::CaseInsensitive ) == 0 || lcField.compare( i18n( "added" ), Qt::CaseInsensitive ) == 0 )
+                {
+                    if( compare == QueryMaker::Equals ) // just do some basic string matching
+                    {
+                        QDateTime curTime = QDateTime::currentDateTime();
+                        uint dateCutOff = 0;
+                        if( ( elem.text.compare( "today", Qt::CaseInsensitive ) == 0 ) || ( elem.text.compare( i18n( "today" ), Qt::CaseInsensitive ) == 0 ) )
+                            dateCutOff = curTime.addDays( -1 ).toTime_t();
+                        else if( ( elem.text.compare( "last week", Qt::CaseInsensitive ) == 0 ) || ( elem.text.compare( i18n( "last week" ), Qt::CaseInsensitive ) == 0 ) )
+                            dateCutOff = curTime.addDays( -7 ).toTime_t();
+                        else if( ( elem.text.compare( "last month", Qt::CaseInsensitive ) == 0 ) || ( elem.text.compare( i18n( "last month" ), Qt::CaseInsensitive ) == 0 ) )
+                            dateCutOff = curTime.addMonths( -1 ).toTime_t();
+                        else if( ( elem.text.compare( "two months ago", Qt::CaseInsensitive ) == 0 ) || ( elem.text.compare( i18n( "two months ago" ), Qt::CaseInsensitive ) == 0 ) )
+                            dateCutOff = curTime.addMonths( -2 ).toTime_t();
+                        else if( ( elem.text.compare( "three months ago", Qt::CaseInsensitive ) == 0 ) || ( elem.text.compare( i18n( "three months ago" ), Qt::CaseInsensitive ) == 0 ) )
+                            dateCutOff = curTime.addMonths( -3 ).toTime_t();
+                        
+                        if( dateCutOff > 0 )
+                            ADD_OR_EXCLUDE_NUMBER_FILTER( Meta::valCreateDate, dateCutOff, QueryMaker::GreaterThan );
+                    } else if( compare == QueryMaker::LessThan ) // parse a "#m#d" (discoverability == 0, but without a GUI, how to do it?)
+                    {
+                        int months = 0, days = 0;
+                        QString tmp;
+                        for( int i = 0; i < elem.text.length(); i++ )
+                        {
+                            QChar c = elem.text.at( i );
+                            if( c.isNumber() )
+                                tmp += c;
+                            else if( c == 'm' )
+                            {
+                                months = 0 - QString( tmp ).toInt();
+                                tmp = "";
+                            } else if( c == 'd' )
+                            {   
+                                days = 0 - QString( tmp ).toInt();
+                                break;
+                            }
+                        }
+                        ADD_OR_EXCLUDE_NUMBER_FILTER( Meta::valCreateDate, QDateTime::currentDateTime().addMonths( months ).addDays( days ).toTime_t(), QueryMaker::GreaterThan );
+                    }
                 }
             }
             qm->endAndOr();


More information about the Amarok-devel mailing list