From c7be05d5db1ed09d0b9a41f5ec2c714434eceaf8 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Fri, 12 Aug 2016 19:19:32 +0200 Subject: [PATCH] moviebrowser: Fix text display in message box when deleting a movie Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/4fd7808afd9191f8a8dab491cc9e6151dcc93198 Author: Michael Liebmann Date: 2016-08-12 (Fri, 12 Aug 2016) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/gui/moviebrowser.cpp | 80 ++++++++++++++++++++-------------------- src/gui/moviebrowser.h | 1 + 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/gui/moviebrowser.cpp b/src/gui/moviebrowser.cpp index 711be53dc..fe76b04af 100644 --- a/src/gui/moviebrowser.cpp +++ b/src/gui/moviebrowser.cpp @@ -2223,61 +2223,61 @@ bool CMovieBrowser::onButtonPressMovieInfoList(neutrino_msg_t msg) return (result); } -bool CMovieBrowser::onDeleteFile(MI_MOVIE_INFO *movieinfo, bool skipAsk) +std::string CMovieBrowser::formatDeleteMsg(MI_MOVIE_INFO *movieinfo, Font *msgFont, const int boxWidth) { - //TRACE("[onDeleteFile] "); - bool result = false; -#if 0 - int test= movieinfo->file.Name.find(".ts", movieinfo->file.Name.length()-3); - if (test == -1) { - // not a TS file, return!!!!! - TRACE("show_ts_info: not a TS file "); - return; - } -#endif - size_t msgMax = 50; + int msgWidth = boxWidth - 20; std::string msg = g_Locale->getText(LOCALE_FILEBROWSER_DODELETE1); - msg += "\n "; + msg += "\n"; + if (!movieinfo->epgTitle.empty()) { - if ((movieinfo->epgTitle.length() + movieinfo->epgInfo1.length()) <= msgMax) { - msg += movieinfo->epgTitle; + int titleW = msgFont->getRenderWidth(movieinfo->epgTitle); + int infoW = 0; + int zW = 0; + if (!movieinfo->epgInfo1.empty()) { + infoW = msgFont->getRenderWidth(movieinfo->epgInfo1); + zW = msgFont->getRenderWidth(" ()"); + } + + if ((titleW+infoW+zW) <= msgWidth) { + /* one line */ + msg += trim(movieinfo->epgTitle); if (!movieinfo->epgInfo1.empty()) { msg += " ("; - msg += movieinfo->epgInfo1; + msg += trim(movieinfo->epgInfo1); msg += ")"; } } else { - if (movieinfo->epgTitle.length() > msgMax) { - msg += movieinfo->epgTitle.substr(0, msgMax); - msg += "..."; - } - else { - msg += movieinfo->epgTitle; - if (!movieinfo->epgInfo1.empty()) { - msg += "\n ("; - if (movieinfo->epgInfo1.length() > msgMax) { - msg = movieinfo->epgInfo1.substr(0, msgMax); - msg += "..."; - } - else - msg += movieinfo->epgInfo1; + /* two lines */ + msg += cutString(movieinfo->epgTitle, msgFont, msgWidth); + if (!movieinfo->epgInfo1.empty()) { + msg += "\n("; + msg += cutString(movieinfo->epgInfo1, msgFont, msgWidth); msg += ")"; - } } } } - else { - if (movieinfo->file.Name.length() > msgMax) { - msg += movieinfo->file.Name.substr(0, msgMax); - msg += "..."; - } - else - msg += movieinfo->file.Name; - } + else + msg += cutString(movieinfo->file.Name, msgFont, msgWidth); + msg += "\n"; msg += g_Locale->getText(LOCALE_FILEBROWSER_DODELETE2); - if ((skipAsk || !movieinfo->delAsk) || (ShowMsg(LOCALE_FILEBROWSER_DELETE, msg, CMessageBox::mbrYes, CMessageBox::mbYes|CMessageBox::mbNo)==CMessageBox::mbrYes)) + + return msg; +} + +bool CMovieBrowser::onDeleteFile(MI_MOVIE_INFO *movieinfo, bool skipAsk) +{ + //TRACE("[onDeleteFile] "); + bool result = false; + + /* default font for ShowMsg */ + Font *msgFont = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]; + /* default width for ShowMsg */ + int msgBoxWidth = 450; + + std::string msg = formatDeleteMsg(movieinfo, msgFont, msgBoxWidth); + if ((skipAsk || !movieinfo->delAsk) || (ShowMsg(LOCALE_FILEBROWSER_DELETE, msg, CMessageBox::mbrYes, CMessageBox::mbYes|CMessageBox::mbNo, NULL, msgBoxWidth)==CMessageBox::mbrYes)) { CHintBox * hintBox = new CHintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_MOVIEBROWSER_DELETE_INFO)); hintBox->paint(); diff --git a/src/gui/moviebrowser.h b/src/gui/moviebrowser.h index 2f662334f..01e3ca39a 100644 --- a/src/gui/moviebrowser.h +++ b/src/gui/moviebrowser.h @@ -428,6 +428,7 @@ class CMovieBrowser : public CMenuTarget void onSetGUIWindowNext(void); void onSetGUIWindowPrev(void); bool onDelete(bool cursor_only = false); + std::string formatDeleteMsg(MI_MOVIE_INFO *movieinfo, Font *msgFont, const int boxWidth = 450); 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);