radioapp/radiouiengine/src/radiohistorymodel_p.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 19 afea38384506
parent 33 11b6825f0862
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    31 #include "radiohistoryitem.h"
    31 #include "radiohistoryitem.h"
    32 #include "radiohistoryitem_p.h"
    32 #include "radiohistoryitem_p.h"
    33 #include "radiostation.h"
    33 #include "radiostation.h"
    34 #include "radiologger.h"
    34 #include "radiologger.h"
    35 
    35 
    36 const char* DATABASE_NAME       = "radioplayhistory.db";
    36 static const QLatin1String DATABASE_NAME    ( "radioplayhistory.db" );
    37 const char* DATABASE_DRIVER     = "QSQLITE";
    37 static const QLatin1String DATABASE_DRIVER  ( "QSQLITE" );
    38 const char* HISTORY_TABLE       = "history";
    38 static const QLatin1String HISTORY_TABLE    ( "history" );
    39 const char* SQL_CREATE_TABLE    = "CREATE TABLE history ("
    39 static const QLatin1String SQL_CREATE_TABLE ( "CREATE TABLE history ("
    40                                   "id INTEGER PRIMARY KEY AUTOINCREMENT, "
    40                                                 "id INTEGER PRIMARY KEY AUTOINCREMENT, "
    41                                   "artist TEXT NOT NULL, "
    41                                                 "artist TEXT NOT NULL, "
    42                                   "title TEXT NOT NULL, "
    42                                                 "title TEXT NOT NULL, "
    43                                   "station TEXT NOT NULL, "
    43                                                 "station TEXT NOT NULL, "
    44                                   "frequency INTEGER NOT NULL, "
    44                                                 "frequency INTEGER NOT NULL, "
    45                                   "tagged INTEGER NOT NULL DEFAULT 0, "
    45                                                 "tagged INTEGER NOT NULL DEFAULT 0, "
    46                                   "fromRds INTEGER NOT NULL DEFAULT 1, "
    46                                                 "fromRds INTEGER NOT NULL DEFAULT 1, "
    47                                   "time TIMESTAMP NOT NULL)";
    47                                                 "time INTEGER NOT NULL)" );
    48 
    48 
    49 const char* SQL_ADD_ITEM         = "INSERT INTO history (artist,title,station,frequency,fromRds,time) "
    49 static const QLatin1String SQL_ADD_ITEM     ( "INSERT INTO history (artist,title,station,frequency,fromRds,time) "
    50                                             "VALUES ( ?,?,?,?,?,? )";
    50                                                 "VALUES ( ?,?,?,?,?,? )" );
    51 
    51 
    52 const char* SQL_SELECT_ALL       = "SELECT * FROM history ORDER BY id DESC";
    52 static const QLatin1String SQL_SELECT_ALL   ( "SELECT * FROM history ORDER BY id DESC" );
    53 const char* SQL_SELECT_TAGGED    = "SELECT * FROM history WHERE tagged=1";// ORDER BY id DESC";
    53 static const QLatin1String SQL_SELECT_TAGGED( "SELECT * FROM history WHERE tagged=1" );// ORDER BY id DESC";
    54 
    54 
    55 const char* SQL_DELETE_ALL       = "DELETE FROM history";
    55 static const QLatin1String SQL_DELETE_ALL   ( "DELETE FROM history" );
    56 
    56 static const QLatin1String SQL_DELETE_RECENT( "DELETE FROM history WHERE tagged=0" );
    57 //static const char* SQL_FIND_ITEM_BY_ID = "SELECT * FROM history WHERE id = ?";
    57 //static const QLatin1String SQL_DELETE_TAGGED    = "DELETE FROM history WHERE tagged=1";
    58 const char* SQL_TOGGLE_TAG       = "UPDATE history SET tagged = ? WHERE id = ?";
    58 static const QLatin1String SQL_CLEAR_TAGS   ( "UPDATE history SET tagged = 0 WHERE tagged = 1" );
    59 
    59 
       
    60 //static static const QLatin1String SQL_FIND_ITEM_BY_ID( "SELECT * FROM history WHERE id = ?" );
       
    61 static const QLatin1String SQL_TOGGLE_TAG   ( "UPDATE history SET tagged = ? WHERE id = ?" );
    60 
    62 
    61 #ifdef LOGGING_ENABLED
    63 #ifdef LOGGING_ENABLED
    62 #   define GET_ERR( param ) GETSTRING( param.lastError().text() )
    64 #   define GET_ERR( param ) GETSTRING( param.lastError().text() )
    63 #   define GET_ERR_PTR( param ) GETSTRING( param->lastError().text() )
    65 #   define GET_ERR_PTR( param ) GETSTRING( param->lastError().text() )
    64 #endif // LOGGING_ENABLED
    66 #endif // LOGGING_ENABLED
    77  */
    79  */
    78 RadioHistoryModelPrivate::RadioHistoryModelPrivate( RadioHistoryModel* model,
    80 RadioHistoryModelPrivate::RadioHistoryModelPrivate( RadioHistoryModel* model,
    79                                                     RadioUiEngine& uiEngine ) :
    81                                                     RadioUiEngine& uiEngine ) :
    80     q_ptr( model ),
    82     q_ptr( model ),
    81     mUiEngine( uiEngine ),
    83     mUiEngine( uiEngine ),
       
    84     mRtItemClass( -1 ),
    82     mTopItemIsPlaying( false ),
    85     mTopItemIsPlaying( false ),
    83     mShowDetails( true ),
    86     mShowDetails( true ),
    84     mViewMode( ShowAll ),
    87     mViewMode( ShowAll )
    85     mRtItemClass( -1 )
       
    86 {
    88 {
    87 }
    89 }
    88 
    90 
    89 /*!
    91 /*!
    90  *
    92  *
   190             const QString station = record.value( RadioHistoryValue::Station ).toString();
   192             const QString station = record.value( RadioHistoryValue::Station ).toString();
   191             const uint frequency = record.value( RadioHistoryValue::Frequency ).toUInt() * 1000;
   193             const uint frequency = record.value( RadioHistoryValue::Frequency ).toUInt() * 1000;
   192 
   194 
   193             QStringList list;
   195             QStringList list;
   194             if ( mShowDetails ) {
   196             if ( mShowDetails ) {
   195                 list.append( qtTrId( "txt_rad_dblist_1_2" ).arg( artist ).arg( title ) );
   197                 QString formatter = qtTrId( "txt_rad_dblist_1_2" );
   196                 QDateTime dateTime = record.value( RadioHistoryValue::Time ).toDateTime();
   198                 LOG_FORMAT( "---formatter--- %s", GETSTRING( formatter ) );
   197                 const QString time = dateTime.toLocalTime().toString();
   199                 formatter = "%1 - %2";  // TODO!
       
   200 
       
   201                 const QString firstRow = QString( formatter ).arg( artist ).arg( title );
       
   202                 LOG_FORMAT( "---firstRow--- %s", GETSTRING( firstRow ) );
       
   203                 list.append( firstRow );
       
   204 
       
   205                 const uint timeInSecs = record.value( RadioHistoryValue::Time ).toUInt();
       
   206                 QDateTime dateTime;
       
   207                 dateTime.setTime_t( timeInSecs );
       
   208 
       
   209                 QString time = dateTime.toString( Qt::SystemLocaleShortDate );
       
   210                 LOG_FORMAT( "---time--- %s", GETSTRING( time ) );
   198 
   211 
   199                 QString name = !station.isEmpty() ? station : parseFrequency( frequency );
   212                 QString name = !station.isEmpty() ? station : parseFrequency( frequency );
   200                 list.append( qtTrId( "txt_rad_dblist_1_2" ).arg( time ).arg( name ) );
   213                 LOG_FORMAT( "---name--- %s", GETSTRING( name ) );
       
   214                 const QString secondRow = QString( formatter ).arg( time ).arg( name );
       
   215                 LOG_FORMAT( "---secondRow--- %s", GETSTRING( secondRow ) );
       
   216 
       
   217                 list.append( secondRow );
   201             } else {
   218             } else {
   202                 list.append( artist );
   219                 list.append( artist );
   203                 list.append( title );
   220                 list.append( title );
   204             }
   221             }
   205 
   222 
   220 }
   237 }
   221 
   238 
   222 /*!
   239 /*!
   223  *
   240  *
   224  */
   241  */
   225 void RadioHistoryModelPrivate::removeAll()
   242 void RadioHistoryModelPrivate::removeAll( bool removeTagged )
   226 {
   243 {
   227     if ( !mQueryModel ) {
   244     if ( !mQueryModel ) {
   228         return;
   245         return;
   229     }
   246     }
   230 
   247 
   231     QSqlQuery query = beginTransaction();
   248     QSqlQuery query = beginTransaction();
   232 
   249 
   233     query.prepare( SQL_DELETE_ALL );
   250     query.prepare( removeTagged ? SQL_CLEAR_TAGS : SQL_DELETE_ALL );
   234 
   251 
   235     // Commented out because rowsRemoved() seems to crash HbListView
   252     // Commented out because rowsRemoved() seems to crash HbListView
   236 //    commitTransaction( query, RemoveRows, 0, rowCount() - 1 );
   253 //    commitTransaction( query, RemoveRows, 0, rowCount() - 1 );
   237 
   254 
   238     commitTransaction( query, NoOp, 0 );
   255     commitTransaction( query, NoOp, 0 );
   248         return;
   265         return;
   249     }
   266     }
   250 
   267 
   251     mViewMode = mode;
   268     mViewMode = mode;
   252     mQueryModel->setQuery( mode == ShowTagged ? SQL_SELECT_TAGGED : SQL_SELECT_ALL, *mDatabase );
   269     mQueryModel->setQuery( mode == ShowTagged ? SQL_SELECT_TAGGED : SQL_SELECT_ALL, *mDatabase );
   253     q_ptr->reset();
       
   254 }
   270 }
   255 
   271 
   256 /*!
   272 /*!
   257  *
   273  *
   258  */
   274  */
   262 
   278 
   263     updateQuery.prepare( SQL_TOGGLE_TAG );
   279     updateQuery.prepare( SQL_TOGGLE_TAG );
   264     updateQuery.addBindValue( item.isTagged() ? 0 : 1 );
   280     updateQuery.addBindValue( item.isTagged() ? 0 : 1 );
   265     updateQuery.addBindValue( item.id() );
   281     updateQuery.addBindValue( item.id() );
   266 
   282 
   267     commitTransaction( updateQuery, ChangeData, row );
   283     Operation operation = ChangeData;
       
   284     if ( mViewMode == ShowTagged && item.isTagged() ) {
       
   285         operation = RemoveRows;
       
   286     }
       
   287     commitTransaction( updateQuery, operation, row );
   268 }
   288 }
   269 
   289 
   270 /*!
   290 /*!
   271  *
   291  *
   272  */
   292  */