mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-28 16:01:20 +02:00
add CListHelpers class
this can be used to factor out duplicate code implementations from all the various channel-, bouquet-, eventlists etc...
This commit is contained in:
committed by
svenhoefer
parent
bee36d29f6
commit
ec4aa07e17
@@ -25,6 +25,7 @@ libneutrino_gui_widget_a_SOURCES = \
|
||||
keyboard_input.cpp \
|
||||
listbox.cpp \
|
||||
listframe.cpp \
|
||||
listhelpers.cpp \
|
||||
menue.cpp \
|
||||
messagebox.cpp \
|
||||
mountchooser.cpp \
|
||||
|
71
src/gui/widget/listhelpers.cpp
Normal file
71
src/gui/widget/listhelpers.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Helper functions for various list implementations in neutrino
|
||||
Copyright (C) 2016 Stefan Seyfried
|
||||
|
||||
License: GPL
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see http://www.gnu.org/licenses/
|
||||
*/
|
||||
|
||||
#include <driver/rcinput.h>
|
||||
#include "listhelpers.h"
|
||||
|
||||
#include <global.h>
|
||||
#include <gui/bouquetlist.h>
|
||||
|
||||
template <class T> int CListHelpers::UpDownKey(T list, neutrino_msg_t msg, int lines, int sel)
|
||||
{
|
||||
int step;
|
||||
if (list.empty())
|
||||
return -1;
|
||||
|
||||
if (msg >= CRCInput::RC_MaxRC) {
|
||||
printf("CListHelpers:%s: invalid key? 0x%lx\n", __func__, msg);
|
||||
return -1;
|
||||
}
|
||||
int key = (int)msg;
|
||||
if (key == g_settings.key_pageup)
|
||||
step = -lines;
|
||||
else if (key == g_settings.key_pagedown)
|
||||
step = lines;
|
||||
else if (msg == CRCInput::RC_up)
|
||||
step = -1;
|
||||
else if (msg == CRCInput::RC_down)
|
||||
step = 1;
|
||||
else {
|
||||
printf("CListHelpers:%s: invalid key? 0x%lx\n", __func__, msg);
|
||||
return -1;
|
||||
}
|
||||
int size = (int)list.size(); /* bigger than 0, because we checked for empty() before */
|
||||
// printf("CListHelpers:%s: key 0x%04lx lines %d size %d sel %d\n", __func__, msg, lines, size, sel);
|
||||
int new_sel = sel + step;
|
||||
if (new_sel < 0) {
|
||||
if (sel != 0 && step != 1)
|
||||
new_sel = 0;
|
||||
else
|
||||
new_sel = size - 1;
|
||||
}
|
||||
else if (new_sel > size - 1) {
|
||||
if (sel != size - 1)
|
||||
new_sel = size - 1;
|
||||
else
|
||||
new_sel = 0;
|
||||
}
|
||||
return new_sel;
|
||||
}
|
||||
|
||||
/* all used versions need to be prototyped here, to avoid linker errors */
|
||||
template int CListHelpers::UpDownKey<std::vector<CBouquet*> >(std::vector<CBouquet*>, neutrino_msg_t, int, int);
|
||||
template int CListHelpers::UpDownKey<std::vector<CZapitBouquet*> >(std::vector<CZapitBouquet*>, neutrino_msg_t, int, int);
|
||||
template int CListHelpers::UpDownKey<std::vector<CZapitChannel*> >(std::vector<CZapitChannel*>, neutrino_msg_t, int, int);
|
30
src/gui/widget/listhelpers.h
Normal file
30
src/gui/widget/listhelpers.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Helper functions for various list implementations in neutrino
|
||||
Copyright (C) 2016 Stefan Seyfried
|
||||
|
||||
License: GPL
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see http://www.gnu.org/licenses/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __LISTHELPERS__
|
||||
#define __LISTHELPERS__
|
||||
|
||||
class CListHelpers
|
||||
{
|
||||
public:
|
||||
template <class T> int UpDownKey(T list, neutrino_msg_t k, int lines, int sel);
|
||||
};
|
||||
#endif
|
Reference in New Issue
Block a user