diff --git a/src/gui/bookmarkmanager.cpp b/src/gui/bookmarkmanager.cpp index dcb686ca5..a543b72da 100644 --- a/src/gui/bookmarkmanager.cpp +++ b/src/gui/bookmarkmanager.cpp @@ -57,17 +57,15 @@ #define info_height 60 - -CBookmark::CBookmark(const std::string & inName, const std::string & inUrl, const std::string & inTime) +CBookmark::CBookmark(const std::string &inName, const std::string &inUrl, const std::string &inTime) { name = inName; url = inUrl; time = inTime; } -//------------------------------ - -int CBookmarkManager::addBookmark (CBookmark inBookmark) { +int CBookmarkManager::addBookmark(CBookmark inBookmark) +{ if (bookmarks.size() < MAXBOOKMARKS) { bookmarks.push_back(inBookmark); @@ -79,12 +77,13 @@ int CBookmarkManager::addBookmark (CBookmark inBookmark) { return -1; } -//------------------------------------------------------------------------ -inline int CBookmarkManager::createBookmark (const std::string & name, const std::string & url, const std::string & time) { +inline int CBookmarkManager::createBookmark(const std::string &name, const std::string &url, const std::string &time) +{ return addBookmark(CBookmark(name, url, time)); } -int CBookmarkManager::createBookmark (const std::string & url, const std::string & time) { +int CBookmarkManager::createBookmark(const std::string &url, const std::string &time) +{ std::string bookmarkname; CStringInputSMS bookmarkname_input(LOCALE_MOVIEPLAYER_BOOKMARKNAME, &bookmarkname, 25, LOCALE_MOVIEPLAYER_BOOKMARKNAME_HINT1, LOCALE_MOVIEPLAYER_BOOKMARKNAME_HINT2, "abcdefghijklmnopqrstuvwxyz0123456789-_", this); bookmarkname_input.exec(NULL, ""); @@ -96,36 +95,36 @@ int CBookmarkManager::createBookmark (const std::string & url, const std::string return -1; } -//------------------------------------------------------------------------ -#if 0 -//never used -void CBookmarkManager::removeBookmark (unsigned int index) { - std::vector::iterator p = bookmarks.begin()+index; +#if 0 +// never used +void CBookmarkManager::removeBookmark(unsigned int index) +{ + std::vector::iterator p = bookmarks.begin() + index; bookmarks.erase(p); - bookmarksmodified=true; + bookmarksmodified = true; } -//------------------------------------------------------------------------ - -void CBookmarkManager::renameBookmark (unsigned int index) { +void CBookmarkManager::renameBookmark(unsigned int index) +{ if (index >= bookmarks.size()) return; - CBookmark & theBookmark = bookmarks[index]; + CBookmark &theBookmark = bookmarks[index]; char bookmarkname[26]; - strncpy (bookmarkname, theBookmark.getName(), 25); + strncpy(bookmarkname, theBookmark.getName(), 25); CStringInputSMS bookmarkname_input(LOCALE_MOVIEPLAYER_BOOKMARKNAME, bookmarkname, 25, LOCALE_MOVIEPLAYER_BOOKMARKNAME_HINT1, LOCALE_MOVIEPLAYER_BOOKMARKNAME_HINT2, "abcdefghijklmnopqrstuvwxyz0123456789-_"); bookmarkname_input.exec(NULL, ""); if (strcmp(theBookmark.getName(), bookmarkname) != 0) { theBookmark.setName(std::string(bookmarkname)); - bookmarksmodified=true; + bookmarksmodified = true; } } #endif -//------------------------------------------------------------------------ -void CBookmarkManager::readBookmarkFile() { + +void CBookmarkManager::readBookmarkFile() +{ if (bookmarkfile.loadConfig(BOOKMARKFILE)) { bookmarksmodified = false; @@ -147,8 +146,8 @@ void CBookmarkManager::readBookmarkFile() { } } -//------------------------------------------------------------------------ -void CBookmarkManager::writeBookmarkFile() { +void CBookmarkManager::writeBookmarkFile() +{ printf("CBookmarkManager: Writing bookmark file\n"); @@ -167,55 +166,49 @@ void CBookmarkManager::writeBookmarkFile() { bookmarksmodified = false; } -//------------------------------------------------------------------------ - -CBookmarkManager::CBookmarkManager() : bookmarkfile ('\t') +CBookmarkManager::CBookmarkManager() : bookmarkfile('\t') { bookmarkname_entered = false; bookmarksmodified = false; readBookmarkFile(); } -//------------------------------------------------------------------------ - -CBookmarkManager::~CBookmarkManager () { +CBookmarkManager::~CBookmarkManager() +{ flush(); } -//------------------------------------------------------------------------ - bool CBookmarkManager::changeNotify(const neutrino_locale_t, void *) { bookmarkname_entered = true; return false; } -//------------------------------------------------------------------------ - -#if 0 -//never used -int CBookmarkManager::getBookmarkCount(void) const { +#if 0 +// never used +int CBookmarkManager::getBookmarkCount(void) const +{ return bookmarks.size(); } -//------------------------------------------------------------------------ - -int CBookmarkManager::getMaxBookmarkCount(void) const { +int CBookmarkManager::getMaxBookmarkCount(void) const +{ return MAXBOOKMARKS; } #endif -//------------------------------------------------------------------------ -void CBookmarkManager::flush() { - if (bookmarksmodified) { +void CBookmarkManager::flush() +{ + if (bookmarksmodified) + { writeBookmarkFile(); } } -//------------------------------------------------------------------------ -#if 0 -//never used -const CBookmark * CBookmarkManager::getBookmark(CMenuTarget* parent) + +#if 0 +// never used +const CBookmark *CBookmarkManager::getBookmark(CMenuTarget *parent) { if (parent) { @@ -227,26 +220,26 @@ const CBookmark * CBookmarkManager::getBookmark(CMenuTarget* parent) selected = 0; // Max width = 90; - footerHeight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]->getHeight()+8; //initial height value for buttonbar + footerHeight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]->getHeight() + 8; // initial height value for buttonbar theight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); fheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); - x=getScreenStartX( width ); - y=getScreenStartY( height + info_height ); - listmaxshow = (height-theight-0)/(fheight*2); + x = getScreenStartX(width); + y = getScreenStartY(height + info_height); + listmaxshow = (height - theight - 0) / (fheight * 2); liststart = 0; - height = (g_settings.screen_EndY-g_settings.screen_StartY)-(info_height+50); - listmaxshow = (height-theight-0)/(fheight*2); - height = theight+0+listmaxshow*fheight*2; // recalc height + height = (g_settings.screen_EndY - g_settings.screen_StartY) - (info_height + 50); + listmaxshow = (height - theight - 0) / (fheight * 2); + height = theight + 0 + listmaxshow * fheight * 2; // recalc height if (bookmarks.size() < listmaxshow) { - listmaxshow=bookmarks.size(); - height = theight+0+listmaxshow*fheight*2; // recalc height + listmaxshow = bookmarks.size(); + height = theight + 0 + listmaxshow * fheight * 2; // recalc height } - if ((!bookmarks.empty() && selected==bookmarks.size())) + if ((!bookmarks.empty() && selected == bookmarks.size())) { - selected=bookmarks.size()-1; - liststart = (selected/listmaxshow)*listmaxshow; + selected = bookmarks.size() - 1; + liststart = (selected / listmaxshow) * listmaxshow; } @@ -256,40 +249,41 @@ const CBookmark * CBookmarkManager::getBookmark(CMenuTarget* parent) neutrino_msg_t msg; neutrino_msg_data_t data; - bool loop=true; - bool update=true; + bool loop = true; + bool update = true; while (loop) { if (update) { hide(); - update=false; + update = false; paint(); } - g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd ); + g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd); - if ( msg <= CRCInput::RC_MaxRC ) + if (msg <= CRCInput::RC_MaxRC) timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU]); - if ( ( msg == CRCInput::RC_timeout ) || - ( msg == CRCInput::RC_home) ) - { //Exit after timeout or cancel key + if ((msg == CRCInput::RC_timeout) || + (msg == CRCInput::RC_home)) + { + // Exit after timeout or cancel key res = -1; - loop=false; + loop = false; } else if ((msg == CRCInput::RC_up) && !(bookmarks.empty())) { - int prevselected=selected; - if (selected==0) + int prevselected = selected; + if (selected == 0) { - selected = bookmarks.size()-1; + selected = bookmarks.size() - 1; } else selected--; paintItem(prevselected - liststart); unsigned int oldliststart = liststart; - liststart = (selected/listmaxshow)*listmaxshow; - if (oldliststart!=liststart) + liststart = (selected / listmaxshow) * listmaxshow; + if (oldliststart != liststart) { paint(); } @@ -300,12 +294,12 @@ const CBookmark * CBookmarkManager::getBookmark(CMenuTarget* parent) } else if ((msg == CRCInput::RC_down) && !(bookmarks.empty())) { - int prevselected=selected; - selected = (selected+1)%bookmarks.size(); + int prevselected = selected; + selected = (selected + 1) % bookmarks.size(); paintItem(prevselected - liststart); unsigned int oldliststart = liststart; - liststart = (selected/listmaxshow)*listmaxshow; - if (oldliststart!=liststart) + liststart = (selected / listmaxshow) * listmaxshow; + if (oldliststart != liststart) { paint(); } @@ -317,35 +311,34 @@ const CBookmark * CBookmarkManager::getBookmark(CMenuTarget* parent) else if ((msg == CRCInput::RC_ok) && !(bookmarks.empty())) { res = selected; - loop=false; + loop = false; } else if ((msg == CRCInput::RC_red) && !(bookmarks.empty())) { removeBookmark(selected); - update=true; + update = true; } - else if ((msg==CRCInput::RC_yellow) && !(bookmarks.empty())) + else if ((msg == CRCInput::RC_yellow) && !(bookmarks.empty())) { renameBookmark(selected); - update=true; + update = true; } - else if ((msg==CRCInput::RC_blue)||(msg==CRCInput::RC_green)|| - (CRCInput::isNumeric(msg)) ) + else if ((msg == CRCInput::RC_blue) || (msg == CRCInput::RC_green) || (CRCInput::isNumeric(msg))) { - //Ignore + // Ignore } - else if (msg==CRCInput::RC_setup) + else if (msg == CRCInput::RC_setup) { - res=-1; - loop=false; + res = -1; + loop = false; } - else if ( msg == CRCInput::RC_help ) + else if (msg == CRCInput::RC_help) { // TODO Add Help } else { - if ( CNeutrinoApp::getInstance()->handleMsg( msg, data ) & messages_return::cancel_all ) + if (CNeutrinoApp::getInstance()->handleMsg(msg, data) & messages_return::cancel_all) { loop = false; res = menu_return::RETURN_EXIT_ALL; @@ -354,16 +347,16 @@ const CBookmark * CBookmarkManager::getBookmark(CMenuTarget* parent) } hide(); - if ((res >=0) && (((unsigned int)res) < bookmarks.size())) + if ((res >= 0) && (((unsigned int)res) < bookmarks.size())) return &bookmarks[res]; else return NULL; } #endif -//------------------------------------------------------------------------ + void CBookmarkManager::paintItem(int pos) { - int ypos = y+ theight+0 + pos*fheight*2; + int ypos = y + theight + 0 + pos * fheight * 2; unsigned int currpos = liststart + pos; @@ -376,40 +369,37 @@ void CBookmarkManager::paintItem(int pos) getItemColors(color, bgcolor, i_selected, i_marked, i_switch); - int real_width=width; - if (bookmarks.size()>listmaxshow) + int real_width = width; + if (bookmarks.size() > listmaxshow) { - real_width-=15; //scrollbar + real_width -= 15; // scrollbar } - frameBuffer->paintBoxRel(x,ypos, real_width, 2*fheight, bgcolor); + frameBuffer->paintBoxRel(x, ypos, real_width, 2 * fheight, bgcolor); if (currpos < bookmarks.size()) { CBookmark theBookmark = bookmarks[currpos]; - g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x+10,ypos+fheight, real_width-10, theBookmark.getName(), color, fheight); - g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x+10,ypos+2*fheight, real_width-10, theBookmark.getUrl(), color, fheight); + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x + 10, ypos + fheight, real_width - 10, theBookmark.getName(), color, fheight); + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x + 10, ypos + 2 * fheight, real_width - 10, theBookmark.getUrl(), color, fheight); // LCD Display if (i_selected) { - CVFD::getInstance()->showMenuText(0, theBookmark.getName(), -1, true); // UTF-8 - CVFD::getInstance()->showMenuText(1, theBookmark.getUrl(), -1, true); // UTF-8 + CVFD::getInstance()->showMenuText(0, theBookmark.getName(), -1, true); + CVFD::getInstance()->showMenuText(1, theBookmark.getUrl(), -1, true); } } } -//------------------------------------------------------------------------ - void CBookmarkManager::hide() { if (visible) { - frameBuffer->paintBackgroundBoxRel(x, y, width, height+ info_height+ 5); + frameBuffer->paintBackgroundBoxRel(x, y, width, height + info_height + 5); visible = false; } } -//------------------------------------------------------------------------ void CBookmarkManager::paintHead() { CComponentsHeader header(x, y, width, theight, LOCALE_BOOKMARKMANAGER_NAME, NEUTRINO_ICON_BOOKMARK_MANAGER, CComponentsHeader::CC_BTN_HELP); @@ -418,31 +408,30 @@ void CBookmarkManager::paintHead() const struct button_label BookmarkmanagerButtons[2] = { - { NEUTRINO_ICON_BUTTON_RED , LOCALE_BOOKMARKMANAGER_DELETE }, + { NEUTRINO_ICON_BUTTON_RED, LOCALE_BOOKMARKMANAGER_DELETE }, { NEUTRINO_ICON_BUTTON_YELLOW, LOCALE_BOOKMARKMANAGER_RENAME } }; -//------------------------------------------------------------------------ void CBookmarkManager::paintFoot() { int ButtonWidth = (width - 20) / 4; - frameBuffer->paintBoxRel(x,y+height, width, footerHeight, COL_MENUFOOT_PLUS_0); - frameBuffer->paintHLine(x, x+width, y, COL_MENUFOOT_PLUS_0); + frameBuffer->paintBoxRel(x, y + height, width, footerHeight, COL_MENUFOOT_PLUS_0); + frameBuffer->paintHLine(x, x + width, y, COL_MENUFOOT_PLUS_0); - if (bookmarks.empty()) { - frameBuffer->paintIcon(NEUTRINO_ICON_BUTTON_OKAY, x+width- 1* ButtonWidth + 10, y+height); - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]->RenderString(x+width-1 * ButtonWidth + 38, y+height+footerHeight - 2, ButtonWidth- 28, g_Locale->getText(LOCALE_BOOKMARKMANAGER_SELECT), COL_INFOBAR_TEXT); + if (bookmarks.empty()) + { + frameBuffer->paintIcon(NEUTRINO_ICON_BUTTON_OKAY, x + width - 1 * ButtonWidth + 10, y + height); + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]->RenderString(x + width - 1 * ButtonWidth + 38, y + height + footerHeight - 2, ButtonWidth - 28, g_Locale->getText(LOCALE_BOOKMARKMANAGER_SELECT), COL_INFOBAR_TEXT); } else { ::paintButtons(x + 10, y + height + 4, width, 2, BookmarkmanagerButtons, footerHeight, ButtonWidth); - frameBuffer->paintIcon(NEUTRINO_ICON_BUTTON_OKAY, x+width- 1* ButtonWidth + 10, y+height); - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]->RenderString(x+width-1 * ButtonWidth + 38, y+height+footerHeight - 2, ButtonWidth- 28, g_Locale->getText(LOCALE_BOOKMARKMANAGER_SELECT), COL_INFOBAR_TEXT); + frameBuffer->paintIcon(NEUTRINO_ICON_BUTTON_OKAY, x + width - 1 * ButtonWidth + 10, y + height); + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]->RenderString(x + width - 1 * ButtonWidth + 38, y + height + footerHeight - 2, ButtonWidth - 28, g_Locale->getText(LOCALE_BOOKMARKMANAGER_SELECT), COL_INFOBAR_TEXT); } } -//------------------------------------------------------------------------ void CBookmarkManager::paint() { unsigned int page_nr = (listmaxshow == 0) ? 0 : (selected / listmaxshow); @@ -452,26 +441,24 @@ void CBookmarkManager::paint() paintHead(); - for (unsigned int count=0; countlistmaxshow) + + if (bookmarks.size() > listmaxshow) { - int ypos = y+ theight; - int sb = 2*fheight* listmaxshow; - frameBuffer->paintBoxRel(x+ width- 15,ypos, 15, sb, COL_SCROLLBAR_PLUS_0); - unsigned int tmp_max = listmaxshow; - if(!tmp_max) - tmp_max = 1; - int sbc= ((bookmarks.size()- 1)/ tmp_max)+ 1; + int ypos = y + theight; + int sb = 2 * fheight * listmaxshow; + frameBuffer->paintBoxRel(x + width - 15, ypos, 15, sb, COL_SCROLLBAR_PLUS_0); + unsigned int tmp_max = listmaxshow; + if (!tmp_max) + tmp_max = 1; + int sbc = ((bookmarks.size() - 1) / tmp_max) + 1; if (sbc < 1) sbc = 1; - frameBuffer->paintBoxRel(x+ width- 13, ypos+ 2+ page_nr * (sb-4)/sbc, 11, (sb-4)/sbc, COL_SCROLLBAR_ACTIVE_PLUS_0); + frameBuffer->paintBoxRel(x + width - 13, ypos + 2 + page_nr * (sb - 4) / sbc, 11, (sb - 4) / sbc, COL_SCROLLBAR_ACTIVE_PLUS_0); } paintFoot(); visible = true; } - diff --git a/src/gui/bookmarkmanager.h b/src/gui/bookmarkmanager.h index 8e996895c..8ead3708d 100644 --- a/src/gui/bookmarkmanager.h +++ b/src/gui/bookmarkmanager.h @@ -47,71 +47,66 @@ class CFramebuffer; class CBookmark { - private: - std::string name; - std::string url; - std::string time; - public: - CBookmark(const std::string & name, const std::string & url, const std::string & time); - const char *getName(void) const { return name.c_str(); }; - const char *getUrl (void) const { return url .c_str(); }; - const char *getTime(void) const { return time.c_str(); }; - inline void setName(const std::string & new_name) { name = new_name; }; - inline void setUrl (const std::string & new_url ) { url = new_url ; }; - inline void setTime(const std::string & new_time) { time = new_time; }; + private: + std::string name; + std::string url; + std::string time; + public: + CBookmark(const std::string &name, const std::string &url, const std::string &time); + const char *getName(void) const { return name.c_str(); }; + const char *getUrl(void) const { return url .c_str(); }; + const char *getTime(void) const { return time.c_str(); }; + inline void setName(const std::string &new_name) { name = new_name; }; + inline void setUrl(const std::string &new_url) { url = new_url ; }; + inline void setTime(const std::string &new_time) { time = new_time; }; }; -//----------------------------------------- - class CBookmarkManager : public CChangeObserver { - private: - std::vector bookmarks; - CConfigFile bookmarkfile; - - CFrameBuffer *frameBuffer; - unsigned int selected; - unsigned int liststart; - unsigned int listmaxshow; - int fheight; // Fonthoehe Timerlist-Inhalt - int theight; // Fonthoehe Timerlist-Titel - int footerHeight; - bool visible; - int width; - int height; - int x; - int y; + private: + std::vector bookmarks; + CConfigFile bookmarkfile; - - //int bookmarkCount; - bool bookmarkname_entered; - bool bookmarksmodified; - void readBookmarkFile(); - void writeBookmarkFile(); - CBookmark getBookmark(); - int addBookmark(CBookmark inBookmark); - - void paintItem(int pos); - void paint(); - void paintHead(); - void paintFoot(); - void hide(); + CFrameBuffer *frameBuffer; + unsigned int selected; + unsigned int liststart; + unsigned int listmaxshow; + int fheight; // Fonthoehe Timerlist-Inhalt + int theight; // Fonthoehe Timerlist-Titel + int footerHeight; + bool visible; + int width; + int height; + int x; + int y; + //int bookmarkCount; + bool bookmarkname_entered; + bool bookmarksmodified; + void readBookmarkFile(); + void writeBookmarkFile(); + CBookmark getBookmark(); + int addBookmark(CBookmark inBookmark); + void paintItem(int pos); + void paint(); + void paintHead(); + void paintFoot(); + void hide(); - public: - CBookmarkManager(); - ~CBookmarkManager(); - bool changeNotify(const neutrino_locale_t, void *); - int createBookmark(const std::string & name, const std::string & url, const std::string & time); - int createBookmark(const std::string & url, const std::string & time); - void removeBookmark(unsigned int index); - void renameBookmark(unsigned int index); - int getBookmarkCount(void) const; - int getMaxBookmarkCount(void) const; - void flush(); - - const CBookmark * getBookmark(CMenuTarget* parent); + public: + CBookmarkManager(); + ~CBookmarkManager(); + bool changeNotify(const neutrino_locale_t, void *); + int createBookmark(const std::string &name, const std::string &url, const std::string &time); + int createBookmark(const std::string &url, const std::string &time); + void removeBookmark(unsigned int index); + void renameBookmark(unsigned int index); + int getBookmarkCount(void) const; + int getMaxBookmarkCount(void) const; + void flush(); + + const CBookmark *getBookmark(CMenuTarget *parent); }; #endif