From 151d7f25a404dd63f9f871900ba7fdad630b3a42 Mon Sep 17 00:00:00 2001 From: vanhofen Date: Sat, 12 Dec 2015 21:59:21 +0100 Subject: [PATCH] moviebrowser: don't reload full movie archive after delete Thanks to SatBaby and micha-bbg for support. Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/8f810d52fa7c4603b0ba474af6f9f8a81ba7e7e8 Author: vanhofen Date: 2015-12-12 (Sat, 12 Dec 2015) Origin message was: ------------------ - moviebrowser: don't reload full movie archive after delete Thanks to SatBaby and micha-bbg for support. ------------------ This commit was generated by Migit --- src/gui/moviebrowser.cpp | 146 ++++++++++++++++++++++----------------- src/gui/moviebrowser.h | 1 + src/gui/movieinfo.cpp | 1 + src/gui/movieinfo.h | 1 + 4 files changed, 85 insertions(+), 64 deletions(-) diff --git a/src/gui/moviebrowser.cpp b/src/gui/moviebrowser.cpp index fcbcaffdf..82c02eee2 100644 --- a/src/gui/moviebrowser.cpp +++ b/src/gui/moviebrowser.cpp @@ -967,7 +967,7 @@ int CMovieBrowser::exec(CMenuTarget* parent, const std::string & actionKey) { if (m_movieSelectionHandler != NULL) { - if (onDeleteFile(m_movieSelectionHandler, false /*don't skipAsk*/)) + if (onDelete(true /*cursor only*/)) { m_doLoadMovies = true; m_doRefresh = true; @@ -1831,63 +1831,9 @@ bool CMovieBrowser::onButtonPressMainFrame(neutrino_msg_t msg) } else if (msg == CRCInput::RC_spkr) { - MI_MOVIE_INFO *movieinfo; - movieinfo = NULL; - filelist_it = filelist.end(); - if (getSelectedFiles(filelist, movielist)) - filelist_it = filelist.begin(); - if (filelist.empty()) { //just add the m_movieSelectionHandler - filelist.push_back(m_movieSelectionHandler->file); - movielist.push_back(m_movieSelectionHandler); - } - - MI_MOVIE_LIST dellist; - MI_MOVIE_LIST::iterator dellist_it; - dellist.clear(); - unsigned int dellist_cnt = 0; - bool skipAsk = false; - for (filelist_it = filelist.begin(); filelist_it != filelist.end(); ++filelist_it) + if (m_movieSelectionHandler != NULL) { - unsigned int idx = filelist_it - filelist.begin(); - movieinfo = movielist[idx]; - TRACE("[mb]-> try to delete %d:%s\n", idx, movieinfo->file.Name.c_str()); - - if ((!m_vMovieInfo.empty()) && (movieinfo != NULL)) { - bool onDelete = true; - skipAsk = false; - CRecordInstance* inst = CRecordManager::getInstance()->getRecordInstance(movieinfo->file.Name); - if (inst != NULL) { - std::string delName = movieinfo->epgTitle; - if (delName.empty()) - delName = movieinfo->file.getFileName(); - char buf1[1024]; - snprintf(buf1, sizeof(buf1), g_Locale->getText(LOCALE_MOVIEBROWSER_ASK_REC_TO_DELETE), delName.c_str()); - if (ShowMsg(LOCALE_RECORDINGMENU_RECORD_IS_RUNNING, buf1, - CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo, NULL, 450, 30, false) == CMessageBox::mbrNo) - onDelete = false; - else { - CTimerd::RecordingStopInfo recinfo; - recinfo.channel_id = inst->GetChannelId(); - recinfo.eventID = inst->GetRecordingId(); - CRecordManager::getInstance()->Stop(&recinfo); - g_Timerd->removeTimerEvent(recinfo.eventID); - skipAsk = true; - } - } - if (onDelete) - { - dellist.push_back(*movieinfo); - dellist_cnt++; - } - } - } - if (!dellist.empty()) { - if (dellist_cnt > 1) - skipAsk = (ShowMsg(LOCALE_FILEBROWSER_DELETE, LOCALE_MOVIEBROWSER_DELETE_ALL, CMessageBox::mbrNo, CMessageBox:: mbYes | CMessageBox::mbNo) == CMessageBox::mbrYes); - for (dellist_it = dellist.begin(); dellist_it != dellist.end(); ++dellist_it) - onDeleteFile((MI_MOVIE_INFO *)&(*dellist_it), skipAsk); - dellist.clear(); - loadMovies(); + onDelete(); } } else if (msg == CRCInput::RC_help || msg == CRCInput::RC_info) @@ -2162,10 +2108,10 @@ bool CMovieBrowser::onDeleteFile(MI_MOVIE_INFO *movieinfo, bool skipAsk) size_t msgMax = 50; std::string msg = g_Locale->getText(LOCALE_FILEBROWSER_DODELETE1); msg += "\n "; - if (movieinfo->epgTitle != "") { + if (!movieinfo->epgTitle.empty()) { if ((movieinfo->epgTitle.length() + movieinfo->epgInfo1.length()) <= msgMax) { msg += movieinfo->epgTitle; - if (movieinfo->epgInfo1 != "") { + if (!movieinfo->epgInfo1.empty()) { msg += " ("; msg += movieinfo->epgInfo1; msg += ")"; @@ -2178,7 +2124,7 @@ bool CMovieBrowser::onDeleteFile(MI_MOVIE_INFO *movieinfo, bool skipAsk) } else { msg += movieinfo->epgTitle; - if (movieinfo->epgInfo1 != "") { + if (!movieinfo->epgInfo1.empty()) { msg += "\n ("; if (movieinfo->epgInfo1.length() > msgMax) { msg = movieinfo->epgInfo1.substr(0, msgMax); @@ -2201,7 +2147,7 @@ bool CMovieBrowser::onDeleteFile(MI_MOVIE_INFO *movieinfo, bool skipAsk) } msg += "\n"; msg += g_Locale->getText(LOCALE_FILEBROWSER_DODELETE2); - if ((skipAsk) || (ShowMsg(LOCALE_FILEBROWSER_DELETE, msg, CMessageBox::mbrYes, CMessageBox::mbYes|CMessageBox::mbNo)==CMessageBox::mbrYes)) + if ((skipAsk || !movieinfo->delAsk) || (ShowMsg(LOCALE_FILEBROWSER_DELETE, msg, CMessageBox::mbrYes, CMessageBox::mbYes|CMessageBox::mbNo)==CMessageBox::mbrYes)) { CHintBox * hintBox = new CHintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_MOVIEBROWSER_DELETE_INFO)); hintBox->paint(); @@ -2218,9 +2164,17 @@ bool CMovieBrowser::onDeleteFile(MI_MOVIE_INFO *movieinfo, bool skipAsk) delete hintBox; g_RCInput->clearRCMsg(); -#if 0 - m_vMovieInfo.erase((std::vector::iterator)movieinfo); TRACE("List size: %d\n", (int)m_vMovieInfo.size()); + for (std::vector::iterator mi_it = m_vMovieInfo.begin(); mi_it != m_vMovieInfo.end(); ++mi_it) + { + if ( + mi_it->file.Name == movieinfo->file.Name + && mi_it->epgTitle == movieinfo->epgTitle + && mi_it->epgInfo1 == movieinfo->epgInfo1 + && mi_it->length == movieinfo->length + ) + m_vMovieInfo.erase(mi_it--); + } updateSerienames(); refreshBrowserList(); @@ -2228,12 +2182,76 @@ bool CMovieBrowser::onDeleteFile(MI_MOVIE_INFO *movieinfo, bool skipAsk) refreshLastRecordList(); refreshMovieInfo(); refresh(); -#endif + result = true; } return (result); } +bool CMovieBrowser::onDelete(bool cursor_only) +{ + //TRACE("[onDelete] "); + bool result = false; + + MI_MOVIE_INFO *movieinfo; + movieinfo = NULL; + filelist_it = filelist.end(); + if (!cursor_only && getSelectedFiles(filelist, movielist)) + filelist_it = filelist.begin(); + if (filelist.empty()) { //just add the m_movieSelectionHandler + filelist.push_back(m_movieSelectionHandler->file); + movielist.push_back(m_movieSelectionHandler); + } + + MI_MOVIE_LIST dellist; + MI_MOVIE_LIST::iterator dellist_it; + dellist.clear(); + unsigned int dellist_cnt = 0; + for (filelist_it = filelist.begin(); filelist_it != filelist.end(); ++filelist_it) + { + unsigned int idx = filelist_it - filelist.begin(); + movieinfo = movielist[idx]; + TRACE("[mb]-> try to delete %d:%s\n", idx, movieinfo->file.Name.c_str()); + + if ((!m_vMovieInfo.empty()) && (movieinfo != NULL)) { + bool toDelete = true; + CRecordInstance* inst = CRecordManager::getInstance()->getRecordInstance(movieinfo->file.Name); + if (inst != NULL) { + std::string delName = movieinfo->epgTitle; + if (delName.empty()) + delName = movieinfo->file.getFileName(); + char buf1[1024]; + snprintf(buf1, sizeof(buf1), g_Locale->getText(LOCALE_MOVIEBROWSER_ASK_REC_TO_DELETE), delName.c_str()); + if (ShowMsg(LOCALE_RECORDINGMENU_RECORD_IS_RUNNING, buf1, + CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo, NULL, 450, 30, false) == CMessageBox::mbrNo) + toDelete = false; + else { + CTimerd::RecordingStopInfo recinfo; + recinfo.channel_id = inst->GetChannelId(); + recinfo.eventID = inst->GetRecordingId(); + CRecordManager::getInstance()->Stop(&recinfo); + g_Timerd->removeTimerEvent(recinfo.eventID); + movieinfo->delAsk = false; //delete this file w/o any more question + } + } + if (toDelete) + { + dellist.push_back(*movieinfo); + dellist_cnt++; + } + } + } + if (!dellist.empty()) { + bool skipAsk = false; + if (dellist_cnt > 1) + skipAsk = (ShowMsg(LOCALE_FILEBROWSER_DELETE, LOCALE_MOVIEBROWSER_DELETE_ALL, CMessageBox::mbrNo, CMessageBox:: mbYes | CMessageBox::mbNo) == CMessageBox::mbrYes); + for (dellist_it = dellist.begin(); dellist_it != dellist.end(); ++dellist_it) + result |= onDeleteFile((MI_MOVIE_INFO *)&(*dellist_it), skipAsk); + dellist.clear(); + } + return (result); +} + void CMovieBrowser::onSetGUIWindow(MB_GUI gui) { TRACE("[mb]->onSetGUIWindow: gui %d -> %d\n", m_settings.gui, gui); diff --git a/src/gui/moviebrowser.h b/src/gui/moviebrowser.h index 486372bb3..2c01809fb 100644 --- a/src/gui/moviebrowser.h +++ b/src/gui/moviebrowser.h @@ -425,6 +425,7 @@ class CMovieBrowser : public CMenuTarget void onSetGUIWindow(MB_GUI gui); void onSetGUIWindowNext(void); void onSetGUIWindowPrev(void); + bool onDelete(bool cursor_only = false); bool onDeleteFile(MI_MOVIE_INFO *movieinfo, bool skipAsk = false); // P4 bool onSortMovieInfoHandleList(std::vector& pv_handle_list, MB_INFO_ITEM sort_type, MB_DIRECTION direction); diff --git a/src/gui/movieinfo.cpp b/src/gui/movieinfo.cpp index 10375da1c..451f6c72f 100644 --- a/src/gui/movieinfo.cpp +++ b/src/gui/movieinfo.cpp @@ -897,6 +897,7 @@ void MI_MOVIE_INFO::clear(void) ytid = ""; ytitag = 0; marked = false; + delAsk = true; } /************************************************************************ diff --git a/src/gui/movieinfo.h b/src/gui/movieinfo.h index 4901dd0de..f6d271a69 100644 --- a/src/gui/movieinfo.h +++ b/src/gui/movieinfo.h @@ -175,6 +175,7 @@ class MI_MOVIE_INFO int VideoType; int epgVTXPID; // currently not used, we just do not want to loose this info if movie info is saved backed bool marked; + bool delAsk; std::string tfile; // thumbnail/cover file name std::string ytdate; // yt published std::string ytid; // yt published