summaryrefslogtreecommitdiff
path: root/skindesclient-0.0.1/osdmenu.c
blob: aa1f983f40ec9d96aaf861464165319a7f209352 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <vdr/osdbase.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include "libskindesigner/skindesignerosdbase.h"

enum eMenus {
	meListMain,
    meListSub,
	meDetail
};

class cPlugOsdMenu : public cSkindesignerOsdMenu {
private:
	void SetMenu(int numItems, bool subfolder = false);
    void SetDetailView(int element);
public:
	cPlugOsdMenu(void);
    virtual ~cPlugOsdMenu();
    virtual eOSState ProcessKey(eKeys key);
};


//***************************************************************************
// Public Functions
//***************************************************************************

cPlugOsdMenu::cPlugOsdMenu(void) : cSkindesignerOsdMenu("Skindesigner Client") {
	SetPluginName("skindesclient");
	SetMenu(10);
}

cPlugOsdMenu::~cPlugOsdMenu(void) {
	
}

eOSState cPlugOsdMenu::ProcessKey(eKeys key) {
    eOSState state = cOsdMenu::ProcessKey(key);
    switch (key) {
        case kOk: {
            int element = Current();
            if (element%2)
                SetDetailView(element);
            else
                SetMenu(25, true);
            state = osContinue;
            break;
        } case kLeft: {
            TextKeyLeft();
            state = osContinue;
            break;
        } case kRight: {
            TextKeyRight();
            state = osContinue;            
            break;
        } case kUp: {
            TextKeyUp();
            state = osContinue;            
            break;
        } case kDown: {
            TextKeyDown();
            state = osContinue;            
            break;
        }
        default:
            break;
    }
    return state;
}

//***************************************************************************
// Private Functions
//***************************************************************************

void cPlugOsdMenu::SetMenu(int numItems, bool subfolder) {
    eMenus menu = subfolder ? meListSub : meListMain;
    SetPluginMenu(menu, mtList);
    Clear();

    for (int i=0; i < numItems; i++) {
        cSkindesignerOsdItem *item = new cSkindesignerOsdItem();
        //add some tokens to the menu item
        stringstream text;
        if (i%2)
            text << "DetailItem" << (i+1);
        else
            text << "FolderItem" << (i+1);
        item->SetText(text.str().c_str());
        item->AddIntToken("itemnumber", i);
        item->AddStringToken("menuitemtext", text.str().c_str());

        stringstream text2;
        text2 << "CurrentItemText" << (i+1) << "\n";
        text2 << "CurrentItemText" << (i+1) << "\n";
        text2 << "CurrentItemText" << (i+1) << "\n";
        text2 << "CurrentItemText" << (i+1) << "\n";
        text2 << "CurrentItemText" << (i+1) << "\n";
        text2 << "CurrentItemText" << (i+1) << "\n";
        item->AddStringToken("currentitemtext", text2.str().c_str());
        
        //Loop Token Example
        for (int row=0; row<20; row++) {
            map<string, string> tokens;
            for (int col=0; col<3; col++) {
                stringstream key;
                stringstream value;
                key << "loop1[" << "col" << col << "]";
                value << "menuitem" << i << "-" << row << "x" << col;
                tokens.insert(pair<string,string>(key.str(), value.str()));
            }
            item->AddLoopToken("loop1", tokens);
        }
        //Add item
        bool current = (i==0)?true:false;
        Add(item, current);
    }
    SetHelp("Red", "Green", "Yellow", "Blue");
    Display();
}

void cPlugOsdMenu::SetDetailView(int element) {
    SetPluginMenu(meDetail, mtText);
    Clear();
    ClearTokens();
    
    SetText("Text to be displayed if skindesigner templates are not available");

    AddIntToken("menuitem", element);
    AddStringToken("tabtext", "String Token to be displayed if skindesigner template is available");

    //Loop Token Example
    for (int row=0; row<25; row++) {
        map<string, string> tokens;
        for (int col=0; col<10; col++) {
            stringstream key;
            stringstream value;
            key << "loop1[" << "col" << col << "]";
            value << "row" << row << "-" << "col" << "-" << col;
            tokens.insert(pair<string,string>(key.str(), value.str()));
        }
        AddLoopToken("loop1", tokens);
    }

    SetHelp("Red", "Green", "Yellow", "Blue");
    Display();
}