Skip to content

Commit 684ec3d

Browse files
committed
add AskUser to remote interface
1 parent ada9838 commit 684ec3d

File tree

8 files changed

+164
-3
lines changed

8 files changed

+164
-3
lines changed

HISTORY

+4
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,7 @@ VDR Plugin 'dbus2vdr' Revision History
9999
2012-01-26: Version 0.0.3g
100100

101101
- add "List" to setup interface
102+
103+
2012-02-08: Version 0.0.3h
104+
105+
- add "AskUser" to remote interface

README

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ If the SVDRP command doesn't take a parameter you can ommit it or pass an empty
8787
- hit a key
8888
vdr-dbus-send.sh /Remote remote.HitKey string:'Menu'
8989

90+
- display list of strings on the osd and let the user select one
91+
vdr-dbus-send.sh /Remote remote.AskUser string:'title' string:'item 1' string:'item 2' ...
92+
93+
The zero-based index of the selected item will be returned with the signal "AskUserSelect",
94+
the first parameter is the title-string, the second the index.
95+
An index of -1 means, no item is selected (or osd closed because of a timeout).
96+
9097
- open the main menu entry of a plugin
9198
vdr-dbus-send.sh /Remote remote.CallPlugin string:'name-of-plugin'
9299

dbus2vdr.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
#include "skin.h"
1919
#include "timer.h"
2020

21+
#include <vdr/osdbase.h>
2122
#include <vdr/plugin.h>
2223

23-
static const char *VERSION = "0.0.3g";
24+
static const char *VERSION = "0.0.3h";
2425
static const char *DESCRIPTION = trNOOP("control vdr via D-Bus");
2526
static const char *MAINMENUENTRY = NULL;
2627

@@ -150,7 +151,7 @@ time_t cPluginDbus2vdr::WakeupTime(void)
150151
cOsdObject *cPluginDbus2vdr::MainMenuAction(void)
151152
{
152153
// Perform the action when selected from the main VDR menu.
153-
return NULL;
154+
return cDBusDispatcherRemote::MainMenuAction;
154155
}
155156

156157
cMenuSetupPage *cPluginDbus2vdr::SetupMenu(void)

message.c

+6
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ bool cDBusMessageDispatcher::Introspect(DBusMessage *msg, cString &Data)
116116
return false;
117117
}
118118

119+
void cDBusMessageDispatcher::Stop()
120+
{
121+
for (cDBusMessageDispatcher *d = _dispatcher.First(); d; d = _dispatcher.Next(d))
122+
d->OnStop();
123+
}
124+
119125
void cDBusMessageDispatcher::Shutdown(void)
120126
{
121127
cDBusMessageHandler::DeleteHandler();

message.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ class cDBusMessageDispatcher : public cListObject
2020
protected:
2121
virtual cDBusMessage *CreateMessage(DBusConnection* conn, DBusMessage* msg) = 0;
2222
virtual bool OnIntrospect(DBusMessage *msg, cString &Data) { return false; }
23+
virtual void OnStop(void) {}
2324

2425
public:
2526
static bool Dispatch(DBusConnection* conn, DBusMessage* msg);
2627
static bool Introspect(DBusMessage *msg, cString &Data);
28+
static void Stop(void);
2729
static void Shutdown(void);
2830

2931
cDBusMessageDispatcher(const char *interface);

monitor.c

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ void cDBusMonitor::Action(void)
110110
dbus_message_unref(msg);
111111
}
112112
}
113+
cDBusMessageDispatcher::Stop();
113114
isyslog("dbus2vdr: monitor stopped on bus %s", DBUS_VDR_BUSNAME);
114115
dbus_connection_unref(conn);
115116
}

remote.c

+134
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,70 @@
66
#include <vdr/remote.h>
77

88

9+
class cDbusSelectMenu : public cOsdMenu
10+
{
11+
private:
12+
DBusConnection *_conn;
13+
bool _selected;
14+
15+
void SendSelectedItem(int item)
16+
{
17+
if (cDBusDispatcherRemote::MainMenuAction != this)
18+
return;
19+
20+
DBusMessage *msg = dbus_message_new_signal("/Remote", DBUS_VDR_REMOTE_INTERFACE, "AskUserSelect");
21+
if (msg == NULL) {
22+
esyslog("dbus2vdr: can't create signal");
23+
return;
24+
}
25+
26+
dbus_uint32_t serial = 0;
27+
const char *title = Title();
28+
DBusMessageIter args;
29+
dbus_message_iter_init_append(msg, &args);
30+
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &title))
31+
esyslog("dbus2vdr: can't add title to signal");
32+
else if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &item))
33+
esyslog("dbus2vdr: can't add selected item to signal");
34+
else if (!dbus_connection_send(_conn, msg, &serial))
35+
esyslog("dbus2vdr: can't send signal");
36+
else
37+
dbus_connection_flush(_conn);
38+
dbus_message_unref(msg);
39+
}
40+
41+
public:
42+
cDbusSelectMenu(DBusConnection* conn, const char *title)
43+
:cOsdMenu(title)
44+
,_conn(conn)
45+
,_selected(false)
46+
{
47+
}
48+
49+
virtual ~cDbusSelectMenu(void)
50+
{
51+
if (!_selected) {
52+
isyslog("dbus2vdr: selected nothing");
53+
SendSelectedItem(-1);
54+
}
55+
cDBusDispatcherRemote::MainMenuAction = NULL;
56+
}
57+
58+
virtual eOSState ProcessKey(eKeys Key)
59+
{
60+
int state = cOsdMenu::ProcessKey(Key);
61+
if (state > os_User) {
62+
_selected = true;
63+
int item = state - os_User - 1;
64+
isyslog("dbus2vdr: select item %d", item);
65+
SendSelectedItem(item);
66+
return osEnd;
67+
}
68+
return (eOSState)state;
69+
}
70+
};
71+
72+
973
cDBusMessageRemote::cDBusMessageRemote(cDBusMessageRemote::eAction action, DBusConnection* conn, DBusMessage* msg)
1074
:cDBusMessage(conn, msg)
1175
,_action(action)
@@ -34,6 +98,9 @@ void cDBusMessageRemote::Process(void)
3498
case dmrHitKey:
3599
HitKey();
36100
break;
101+
case dmrAskUser:
102+
AskUser();
103+
break;
37104
}
38105
}
39106

@@ -134,6 +201,55 @@ void cDBusMessageRemote::HitKey(void)
134201
}
135202

136203

204+
void cDBusMessageRemote::AskUser(void)
205+
{
206+
if (cDBusDispatcherRemote::MainMenuAction != NULL) {
207+
cDBusHelper::SendReply(_conn, _msg, 550, "another selection menu already open");
208+
return;
209+
}
210+
211+
cDbusSelectMenu *menu = NULL;
212+
DBusMessageIter args;
213+
if (!dbus_message_iter_init(_msg, &args))
214+
esyslog("dbus2vdr: %s.HitKey: message misses an argument for the keyName", DBUS_VDR_REMOTE_INTERFACE);
215+
else {
216+
const char *item = NULL;
217+
int i = 0;
218+
while (cDBusHelper::GetNextArg(args, DBUS_TYPE_STRING, &item) >= 0) {
219+
if (menu == NULL)
220+
menu = new cDbusSelectMenu(_conn, item);
221+
else {
222+
menu->Add(new cOsdItem(item, (eOSState)(osUser1 + i)));
223+
i++;
224+
}
225+
}
226+
}
227+
228+
if (menu == NULL) {
229+
cDBusHelper::SendReply(_conn, _msg, 501, "no title for selection menu given");
230+
return;
231+
}
232+
233+
if (menu->Count() == 0) {
234+
delete menu;
235+
cDBusHelper::SendReply(_conn, _msg, 501, "no items for selection menu given");
236+
return;
237+
}
238+
239+
cDBusDispatcherRemote::MainMenuAction = menu;
240+
if (!cRemote::CallPlugin("dbus2vdr")) {
241+
cDBusDispatcherRemote::MainMenuAction = NULL;
242+
delete menu;
243+
cDBusHelper::SendReply(_conn, _msg, 550, "can't display selection menu");
244+
return;
245+
}
246+
247+
cDBusHelper::SendReply(_conn, _msg, 250, "display selection menu");
248+
}
249+
250+
251+
cOsdObject *cDBusDispatcherRemote::MainMenuAction = NULL;
252+
137253
cDBusDispatcherRemote::cDBusDispatcherRemote(void)
138254
:cDBusMessageDispatcher(DBUS_VDR_REMOTE_INTERFACE)
139255
{
@@ -167,6 +283,9 @@ cDBusMessage *cDBusDispatcherRemote::CreateMessage(DBusConnection* conn, DBusMes
167283
if (dbus_message_is_method_call(msg, DBUS_VDR_REMOTE_INTERFACE, "HitKey"))
168284
return new cDBusMessageRemote(cDBusMessageRemote::dmrHitKey, conn, msg);
169285

286+
if (dbus_message_is_method_call(msg, DBUS_VDR_REMOTE_INTERFACE, "AskUser"))
287+
return new cDBusMessageRemote(cDBusMessageRemote::dmrAskUser, conn, msg);
288+
170289
return NULL;
171290
}
172291

@@ -200,7 +319,22 @@ bool cDBusDispatcherRemote::OnIntrospect(DBusMessage *msg, cString &Dat
200319
" <arg name=\"replycode\" type=\"i\" direction=\"out\"/>\n"
201320
" <arg name=\"replymessage\" type=\"s\" direction=\"out\"/>\n"
202321
" </method>\n"
322+
" <method name=\"AskUser\">\n"
323+
" <arg name=\"title\" type=\"s\" direction=\"in\"/>\n"
324+
" <arg name=\"items\" type=\"as\" direction=\"in\"/>\n"
325+
" <arg name=\"replycode\" type=\"i\" direction=\"out\"/>\n"
326+
" <arg name=\"replymessage\" type=\"s\" direction=\"out\"/>\n"
327+
" </method>\n"
328+
" <signal name=\"AskUserSelect\">\n"
329+
" <arg name=\"title\" type=\"s\"/>\n"
330+
" <arg name=\"index\" type=\"i\"/>\n"
331+
" </signal>\n"
203332
" </interface>\n"
204333
"</node>\n";
205334
return true;
206335
}
336+
337+
void cDBusDispatcherRemote::OnStop(void)
338+
{
339+
MainMenuAction = NULL;
340+
}

remote.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
#include "message.h"
55

6+
#include <vdr/osdbase.h>
7+
68

79
class cDBusMessageRemote : public cDBusMessage
810
{
911
friend class cDBusDispatcherRemote;
1012

1113
public:
12-
enum eAction { dmrCallPlugin, dmrEnable, dmrDisable, dmrStatus, dmrHitKey };
14+
enum eAction { dmrCallPlugin, dmrEnable, dmrDisable, dmrStatus, dmrHitKey, dmrAskUser };
1315

1416
virtual ~cDBusMessageRemote(void);
1517

@@ -23,19 +25,23 @@ friend class cDBusDispatcherRemote;
2325
void Disable(void);
2426
void Status(void);
2527
void HitKey(void);
28+
void AskUser(void);
2629

2730
eAction _action;
2831
};
2932

3033
class cDBusDispatcherRemote : public cDBusMessageDispatcher
3134
{
3235
public:
36+
static cOsdObject *MainMenuAction;
37+
3338
cDBusDispatcherRemote(void);
3439
virtual ~cDBusDispatcherRemote(void);
3540

3641
protected:
3742
virtual cDBusMessage *CreateMessage(DBusConnection* conn, DBusMessage* msg);
3843
virtual bool OnIntrospect(DBusMessage *msg, cString &Data);
44+
virtual void OnStop(void);
3945
};
4046

4147
#endif

0 commit comments

Comments
 (0)