radioapp/radiouiengine/src/radiohistorymodel_p.cpp
changeset 32 189d20c34778
parent 28 075425b8d9a4
child 33 11b6825f0862
equal deleted inserted replaced
28:075425b8d9a4 32:189d20c34778
    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 const char* 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 const char* SQL_SELECT_ALL       = "SELECT * FROM history ORDER BY id DESC";
   193             const QString station = record.value( RadioHistoryValue::Station ).toString();
   193             const QString station = record.value( RadioHistoryValue::Station ).toString();
   194             const uint frequency = record.value( RadioHistoryValue::Frequency ).toUInt() * 1000;
   194             const uint frequency = record.value( RadioHistoryValue::Frequency ).toUInt() * 1000;
   195 
   195 
   196             QStringList list;
   196             QStringList list;
   197             if ( mShowDetails ) {
   197             if ( mShowDetails ) {
   198                 list.append( qtTrId( "txt_rad_dblist_1_2" ).arg( artist ).arg( title ) );
   198                 QString formatter = qtTrId( "txt_rad_dblist_1_2" );
   199                 QDateTime dateTime = record.value( RadioHistoryValue::Time ).toDateTime();
   199                 LOG_FORMAT( "---formatter--- %s", GETSTRING( formatter ) );
   200                 const QString time = dateTime.toLocalTime().toString();
   200                 formatter = "%1 - %2";  // TODO!
       
   201 
       
   202                 const QString firstRow = QString( formatter ).arg( artist ).arg( title );
       
   203                 LOG_FORMAT( "---firstRow--- %s", GETSTRING( firstRow ) );
       
   204                 list.append( firstRow );
       
   205 
       
   206                 const uint timeInSecs = record.value( RadioHistoryValue::Time ).toUInt();
       
   207                 QDateTime dateTime;
       
   208                 dateTime.setTime_t( timeInSecs );
       
   209 
       
   210                 QString time = dateTime.toString();
       
   211                 LOG_FORMAT( "---time--- %s", GETSTRING( time ) );
   201 
   212 
   202                 QString name = !station.isEmpty() ? station : parseFrequency( frequency );
   213                 QString name = !station.isEmpty() ? station : parseFrequency( frequency );
   203                 list.append( qtTrId( "txt_rad_dblist_1_2" ).arg( time ).arg( name ) );
   214                 LOG_FORMAT( "---name--- %s", GETSTRING( name ) );
       
   215                 const QString secondRow = QString( formatter ).arg( time ).arg( name );
       
   216                 LOG_FORMAT( "---secondRow--- %s", GETSTRING( secondRow ) );
       
   217 
       
   218                 list.append( secondRow );
   204             } else {
   219             } else {
   205                 list.append( artist );
   220                 list.append( artist );
   206                 list.append( title );
   221                 list.append( title );
   207             }
   222             }
   208 
   223 
   251         return;
   266         return;
   252     }
   267     }
   253 
   268 
   254     mViewMode = mode;
   269     mViewMode = mode;
   255     mQueryModel->setQuery( mode == ShowTagged ? SQL_SELECT_TAGGED : SQL_SELECT_ALL, *mDatabase );
   270     mQueryModel->setQuery( mode == ShowTagged ? SQL_SELECT_TAGGED : SQL_SELECT_ALL, *mDatabase );
   256     q_ptr->reset();
       
   257 }
   271 }
   258 
   272 
   259 /*!
   273 /*!
   260  *
   274  *
   261  */
   275  */
   265 
   279 
   266     updateQuery.prepare( SQL_TOGGLE_TAG );
   280     updateQuery.prepare( SQL_TOGGLE_TAG );
   267     updateQuery.addBindValue( item.isTagged() ? 0 : 1 );
   281     updateQuery.addBindValue( item.isTagged() ? 0 : 1 );
   268     updateQuery.addBindValue( item.id() );
   282     updateQuery.addBindValue( item.id() );
   269 
   283 
   270     commitTransaction( updateQuery, ChangeData, row );
   284     Operation operation = ChangeData;
       
   285     if ( mViewMode == ShowTagged && item.isTagged() ) {
       
   286         operation = RemoveRows;
       
   287     }
       
   288     commitTransaction( updateQuery, operation, row );
   271 }
   289 }
   272 
   290 
   273 /*!
   291 /*!
   274  *
   292  *
   275  */
   293  */