diff --git a/src/gui/channellist.cpp b/src/gui/channellist.cpp index 17165f2ee..13b71dbb3 100644 --- a/src/gui/channellist.cpp +++ b/src/gui/channellist.cpp @@ -576,6 +576,30 @@ bool CChannelList::updateSelection(int newpos) return actzap; } +int CChannelList::getPrevNextBouquet(bool next) +{ + bool found = true; + int dir = next ? 1 : -1; + int b_size = bouquetList->Bouquets.size(); /* bigger than 0 */ + int nNext = (bouquetList->getActiveBouquetNumber() + b_size + dir) % b_size; + if(bouquetList->Bouquets[nNext]->channelList->isEmpty() ) { + found = false; + int n_old = nNext; + nNext = (nNext + b_size + dir) % b_size; + for (int i = nNext; i != n_old; i = (i + b_size + dir) % b_size) { + if( !bouquetList->Bouquets[i]->channelList->isEmpty() ) { + found = true; + nNext = i; + break; + } + } + } + if (found) + return nNext; + + return -1; +} + #define CHANNEL_SMSKEY_TIMEOUT 800 /* return: >= 0 to zap, -1 on cancel, -3 on list mode change, -4 list edited, -2 zap but no restore old list/chan ?? */ int CChannelList::show() @@ -766,23 +790,8 @@ int CChannelList::show() if (dline) dline->kill(); //kill details line on change to next page if (!bouquetList->Bouquets.empty()) { - bool found = true; - int dir = msg == (neutrino_msg_t)g_settings.key_bouquet_up ? 1 : -1; - int b_size = bouquetList->Bouquets.size(); /* bigger than 0 */ - int nNext = (bouquetList->getActiveBouquetNumber() + b_size + dir) % b_size; - if(bouquetList->Bouquets[nNext]->channelList->isEmpty() ) { - found = false; - int n_old = nNext; - nNext = (nNext + b_size + dir) % b_size; - for (int i = nNext; i != n_old; i = (i + b_size + dir) % b_size) { - if( !bouquetList->Bouquets[i]->channelList->isEmpty() ) { - found = true; - nNext = i; - break; - } - } - } - if(found) { + int nNext = getPrevNextBouquet(msg == (neutrino_msg_t)g_settings.key_bouquet_up); + if(nNext >= 0) { bouquetList->activateBouquet(nNext, false); res = bouquetList->showChannelList(); loop = false; @@ -1458,21 +1467,22 @@ CZapitChannel* CChannelList::getPrevNextChannel(int key, unsigned int &sl) printf("CChannelList::getPrevNextChannel: selected %d total %d active bouquet %d total %d\n", (int)cactive, (int)chanlist.size(), bactive, bsize); if ((key == g_settings.key_quickzap_down) || (key == CRCInput::RC_left)) { if(cactive == 0) { - if(bactive == 0) - bactive = bsize - 1; - else - bactive--; - bouquetList->activateBouquet(bactive, false); - cactive = bouquetList->Bouquets[bactive]->channelList->getSize() - 1; + bactive = getPrevNextBouquet(false); + if (bactive >= 0) { + bouquetList->activateBouquet(bactive, false); + cactive = bouquetList->Bouquets[bactive]->channelList->getSize() - 1; + } } else --cactive; } else if ((key == g_settings.key_quickzap_up) || (key == CRCInput::RC_right)) { cactive++; if(cactive >= chanlist.size()) { - bactive = (bactive + 1) % bsize; - bouquetList->activateBouquet(bactive, false); - cactive = 0; + bactive = getPrevNextBouquet(true); + if (bactive >= 0) { + bouquetList->activateBouquet(bactive, false); + cactive = 0; + } } } sl = cactive; diff --git a/src/gui/channellist.h b/src/gui/channellist.h index 8457334c8..ce34914d1 100644 --- a/src/gui/channellist.h +++ b/src/gui/channellist.h @@ -123,6 +123,7 @@ private: int emptyLineCount; void addTextToArray( const std::string & text, int screening ); void processTextToArray(std::string text, int screening = 0); + int getPrevNextBouquet(bool next); public: CChannelList(const char * const Name, bool historyMode = false, bool _vlist = false);