Ticket #2958: mythmusic_cleanup.diff

File mythmusic_cleanup.diff, 1.8 KB (added by otto at kolsi dot fi, 20 years ago)
  • mythmusic/mythmusic/main.cpp

     
    245245    }
    246246}
    247247
     248void cleanDB()
     249{
     250    MythProgressDialog *clean_progress;
     251    clean_progress = new MythProgressDialog(
     252        QObject::tr("Cleaning music database"), 3);
     253
     254    int counter = 0;
     255
     256    MSqlQuery query(MSqlQuery::InitCon());
     257    query.exec("DELETE FROM music_genres "
     258               "WHERE genre_id not in "
     259               "(SELECT DISTINCT genre_id FROM music_songs);");
     260    clean_progress->setProgress(++counter);
     261
     262    query.exec("DELETE FROM music_albums "
     263               "WHERE album_id not in "
     264               "(SELECT DISTINCT album_id FROM music_songs);");
     265    clean_progress->setProgress(++counter);
     266
     267    query.exec("DELETE FROM music_artists "
     268               "WHERE artist_id not in "
     269               "(SELECT DISTINCT artist_id FROM music_songs);");
     270    clean_progress->setProgress(++counter);
     271
     272    clean_progress->Close();
     273    delete clean_progress;
     274}
     275
    248276void SearchDir(QString &directory)
    249277{
    250278    MusicLoadedMap music_files;
     
    313341       3) UpdateFileInDB, same as 1.
    314342     */
    315343
     344    bool files_removed = false;
    316345    counter = 0;
    317346    for (iter = music_files.begin(); iter != music_files.end(); iter++)
    318347    {
    319348        if (*iter == kFileSystem)
    320349            AddFileToDB(iter.key());
    321350        else if (*iter == kDatabase)
     351        {
    322352            RemoveFileFromDB(directory, iter.key ());
     353            files_removed = true;
     354        }
    323355        else if (*iter == kNeedUpdate)
    324356            UpdateFileInDB(iter.key());
    325357
    326358        file_checking->setProgress(++counter);
    327359    }
     360
    328361    file_checking->Close();
    329362    delete file_checking;
     363
     364    if(files_removed)
     365      cleanDB();
    330366}
    331367
    332368void startPlayback(PlaylistsContainer *all_playlists, AllMusic *all_music)