summaryrefslogtreecommitdiff
path: root/mg_menu.h
blob: b9c2be29cbef9d3bb04056dc52e9f16455619e20 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*!
 * \file   vdr_menu.h
 * \brief  Implements menu handling for broswing media libraries within VDR
 *
 * \version $Revision: 1.13 $
 * \date    $Date: 2008-03-17 14:58:54 +0100 (Mo, 17 Mär 2008) $
 * \author  Ralf Klueber, Lars von Wedel, Andreas Kellner, Wolfgang Rohdewald
 * \author  Responsible author: $Author: woro $
 *
 *  $Id: vdr_menu.h 1051 2008-03-17 13:58:54Z woro $
 */

#ifndef _MG_MENU_H
#define _MG_MENU_H

#include <string>
// #include <list>
#include <vector>

#include <vdr/osd.h>
#include <vdr/plugin.h>
#include <vdr/status.h>
#include "vdr_actions.h"

void showmessage(int duration, const char *msg, ...);

class cCommands;

class mgSelection;
class mgMenu;
class mgOsd;
class mgIncrementalSearch;
class mgPlayerControl;
class mgItemGd;

//! \brief callback class, monitors state changes in vdr
class mgStatus : public cStatus
{
	private:
		//! \brief the mgOsd that wants to be notified
		mgOsd *main;
	public:
		//! \brief default constructor
		mgStatus(mgOsd* m) { main = m;}
	protected:
		//! \brief the event we want to know about
		virtual void OsdCurrentItem(const char *Text);
};

/*!
 * \brief the muggle main OSD
 */

class mgOsd : public cOsdMenu
{
	protected:
		bool m_save_warned;
		mgMenu *m_root;
		char *m_message;
		void LoadExternalCommands();
		void showMessage();
	public:

		mgActions CurrentType();

		virtual void SetHelpKeys(const char *Red,const char *Green, const char *Yellow, const char *Blue) { SetHelp(Red,Green,Yellow,Blue); }

		//! \brief callback object, lets vdr notify us about OSD changes
		mgStatus *m_Status;

		//! \brief the different menus, the last one is active
		vector < mgMenu * >Menus;

		//! \brief parent menu if any
		mgMenu * Parent ();

		//! \brief default constructor
		mgOsd ();

		//! \brief default destructor
		virtual ~mgOsd ();

		//! \brief save the entire muggle state
		virtual void SaveState() =0 ;

		//! \brief adds a new mgMenu to the stack
		virtual void AddMenu (mgMenu * m,int position=0);

		//! \brief

		//! \brief initializes using values from nv
		void InitMapFromSetup (mgValmap& nv);

		//! \brief main entry point, called from vdr
		virtual eOSState ProcessKey (eKeys Key);

		/*! \brief selects a certain line on the OSD and displays the OSD
		 */
		void DisplayGoto ();

		//! \brief external commands
		cCommands *external_commands;

		//! \brief Actions can set newmenu which will then be displayed next
		mgMenu *newmenu;

		//! \brief Actions can set newstate which will then be returned to main vdr
		eOSState newstate;

		//! \brief Actions can set forcerefresh. This will force a redisplay of the OSD
		bool forcerefresh;

		//! \brief show a message. Can be called by actions. It will
		// only be shown at the end of the next mgOsd::ProcessKey
		// because that might do forcerefresh which overwrites the message
		void Message (const char *msg) { m_message = strdup(msg); }
		const char* Message1 (const char *msg, ...)
			__attribute__ ((format (printf, 2, 3)));

		const char* Message1 (const char *msg, const string &arg);

		//! \brief Actions can request a new position. -1 means none wanted
		int newposition;

		//! \brief clears the screen, sets a title and the hotkey flag
		void InitOsd (std::string title,const bool hashotkeys);

#if VDRVERSNUM >= 10307
		//! \brief expose the protected DisplayMenu() from cOsdMenu
		cSkinDisplayMenu *DisplayMenu(void) { return cOsdMenu::DisplayMenu(); }
#endif

		//! \brief expose the protected cOsdMenu::hk()
		const char *hk (const char *s) { return cOsdMenu::hk (s); }

		void AddItem(mgAction *a);

		void AddText(const char* text,bool selectable=true);

		void AddLongText(const char* text);

		void AddFile(const string filename);

		void CloseMenu();

		void RefreshTitle();

		virtual void SetHotkeyAction(eKeys key,mgActions action);
};

//! \brief a generic muggle menu
class mgMenu
{
	private:
		const char *HKey(const mgActions act,mgActions on=mgActions(0));
	protected:
		mgOsd*  m_osd;
		unsigned int m_prevpos;
		virtual mgActions ButtonAction(eKeys key);

		eOSState ExecuteButton(eKeys key);
		//! \brief adds the wanted action to the OSD menu
		// \param hotkey if true, add this as a hotkey
		void AddAction(const mgActions action, mgActions on = mgActions(0),const bool hotkey=true);

		//! \brief add an external action, always with hotkey
		void AddExternalAction(const mgActions action, const char *title);

		//! \brief the name of the blue button depends of where we are
		int m_parent_index;
		string m_parent_name;
	public:
		//! sets the correct help keys.
		void SetHelpKeys(mgActions on = mgActions(0));
		//! \brief generates an object for the wanted action
		mgAction* GenerateAction(const mgActions action,mgActions on);

		//! \brief executes the wanted action
		eOSState ExecuteAction (const mgActions action, const mgActions on);

		//! \brief sets the pointer to the owning mgOsd
		virtual void setosd (mgOsd* osd);

		void setParentIndex(int idx) { m_parent_index = idx; }
		int getParentIndex() { return m_parent_index; }
		void setParentName(std::string name) { m_parent_name = name; }
		string getParentName() { return m_parent_name; }

		//! \brief the pointer to the owning mgOsd
		mgOsd* osd () const { return m_osd; }

		mgMenu ();

		virtual ~ mgMenu () { }

		//! \brief computes the title
		virtual string Title() const = 0;

		//! \brief clears the screen, sets a title and the hotkey flag
		virtual void InitOsd (const bool hashotkeys=true);

		//! \brief display OSD and go to osd()->newposition
		void Display ();

		//! \brief BuildOsd() should be abstract but then we cannot compile
		virtual void BuildOsd () {
		}

		/*! \brief Process() should be abstract but then we cannot compile.
		 * \return Process may decide that we want another screen to be displayed.
		 * If the mgMenu* returned is not "this", the caller will use the return
		 * value for a new display. If NULL is returned, the caller will display
		 * the previous menu.
		 */
		virtual eOSState Process (eKeys Key);

		//! \brief the ID of the action defined by the red button.
		mgActions RedAction;

		//! \brief the ID of the action defined by the green button.
		mgActions GreenAction;

		//! \brief the action defined by the yellow button.
		mgActions YellowAction;

		//! \brief the action defined by the blue button.
		mgActions BlueAction;

		virtual void SetHotkeyAction(eKeys key,mgActions action);

		const mgItemGd * PlayingItem(void ) const;
		mgItemGd * mutPlayingItem(void );
};
#endif