From 8193e526155c77c9e1b7c9be36788c968908dc03 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 24 Mar 2013 19:24:38 +0100 Subject: [PATCH] channellist: refactor to avoid duplicated code --- src/gui/channellist.cpp | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/gui/channellist.cpp b/src/gui/channellist.cpp index 85e187aa3..800835167 100644 --- a/src/gui/channellist.cpp +++ b/src/gui/channellist.cpp @@ -746,14 +746,17 @@ int CChannelList::show() } actzap = updateSelection(new_selected); } - else if (msg == (neutrino_msg_t)g_settings.key_bouquet_up) { + else if (msg == (neutrino_msg_t)g_settings.key_bouquet_up || + msg == (neutrino_msg_t)g_settings.key_bouquet_down) { if (!bouquetList->Bouquets.empty()) { bool found = true; - uint32_t nNext = (bouquetList->getActiveBouquetNumber()+1) % bouquetList->Bouquets.size(); + int dir = msg == (neutrino_msg_t)g_settings.key_bouquet_up ? 1 : -1; + int b_size = bouquetList->Bouquets.size(); + int nNext = (bouquetList->getActiveBouquetNumber() + b_size + dir) % b_size; if(bouquetList->Bouquets[nNext]->channelList->isEmpty() ) { found = false; - nNext = nNext < bouquetList->Bouquets.size()-1 ? nNext+1 : 0; - for(uint32_t i = nNext; i < bouquetList->Bouquets.size(); i++) { + nNext = (nNext + b_size + dir) % b_size; + for (int i = nNext; i < b_size; i++) { if( !bouquetList->Bouquets[i]->channelList->isEmpty() ) { found = true; nNext = i; @@ -768,28 +771,6 @@ int CChannelList::show() } } } - else if (msg == (neutrino_msg_t)g_settings.key_bouquet_down) { - if (!bouquetList->Bouquets.empty()) { - bool found = true; - int nNext = (bouquetList->getActiveBouquetNumber()+bouquetList->Bouquets.size()-1) % bouquetList->Bouquets.size(); - if(bouquetList->Bouquets[nNext]->channelList->isEmpty() ) { - found = false; - nNext = nNext > 0 ? nNext-1 : bouquetList->Bouquets.size()-1; - for(int i = nNext; i > 0; i--) { - if(!bouquetList->Bouquets[i]->channelList->isEmpty()) { - found = true; - nNext = i; - break; - } - } - } - if(found) { - bouquetList->activateBouquet(nNext, false); - res = bouquetList->showChannelList(); - loop = false; - } - } - } else if ( msg == CRCInput::RC_ok ) { if(SameTP()) { zapOnExit = true;