3
3
#include "helper.h"
4
4
5
5
#include <vdr/channels.h>
6
+ #include <vdr/device.h>
6
7
7
8
8
9
namespace cDBusChannelsHelper
@@ -15,6 +16,10 @@ namespace cDBusChannelsHelper
15
16
" <method name=\"Count\">\n"
16
17
" <arg name=\"count\" type=\"i\" direction=\"out\"/>\n"
17
18
" </method>\n"
19
+ " <method name=\"Current\">\n"
20
+ " <arg name=\"number\" type=\"i\" direction=\"out\"/>\n"
21
+ " <arg name=\"text\" type=\"s\" direction=\"out\"/>\n"
22
+ " </method>\n"
18
23
" <method name=\"GetFromTo\">\n"
19
24
" <arg name=\"from_index\" type=\"i\" direction=\"in\"/>\n"
20
25
" <arg name=\"to_index\" type=\"i\" direction=\"in\"/>\n"
@@ -56,6 +61,34 @@ namespace cDBusChannelsHelper
56
61
g_dbus_method_invocation_return_value (Invocation , g_variant_new ("(i)" , channels -> Count ()));
57
62
}
58
63
64
+ static void Current (cDBusObject * Object , GVariant * Parameters , GDBusMethodInvocation * Invocation )
65
+ {
66
+ int number = cDevice ::CurrentChannel ();
67
+ cString text = "" ;
68
+ const cChannel * currentChannel = NULL ;
69
+ #if VDRVERSNUM > 20300
70
+ LOCK_CHANNELS_READ ;
71
+ const cChannels * channels = Channels ;
72
+ currentChannel = channels -> GetByNumber (number );
73
+ #else
74
+ currentChannel = Channels .GetByNumber (number );
75
+ #endif
76
+ if (currentChannel != NULL ) {
77
+ text = currentChannel -> ToText ();
78
+ int len = strlen (* text );
79
+ if ((len > 0 ) && ((* text )[len - 1 ] == '\n' ))
80
+ text .Truncate (-1 );
81
+ cDBusHelper ::ToUtf8 (text );
82
+ }
83
+
84
+ GVariantBuilder * builder = g_variant_builder_new (G_VARIANT_TYPE ("(is)" ));
85
+ g_variant_builder_add (builder , "i" , number );
86
+ g_variant_builder_add (builder , "s" , * text );
87
+
88
+ g_dbus_method_invocation_return_value (Invocation , g_variant_builder_end (builder ));
89
+ g_variant_builder_unref (builder );
90
+ }
91
+
59
92
static void GetFromTo (cDBusObject * Object , GVariant * Parameters , GDBusMethodInvocation * Invocation )
60
93
{
61
94
gint32 from_index = -1 ;
@@ -163,6 +196,7 @@ cDBusChannels::cDBusChannels(void)
163
196
:cDBusObject ("/Channels" , cDBusChannelsHelper ::_xmlNodeInfo )
164
197
{
165
198
AddMethod ("Count" , cDBusChannelsHelper ::Count );
199
+ AddMethod ("Current" , cDBusChannelsHelper ::Current );
166
200
AddMethod ("GetFromTo" , cDBusChannelsHelper ::GetFromTo );
167
201
AddMethod ("List" , cDBusChannelsHelper ::List );
168
202
}
0 commit comments