Skip to content

Commit ae58483

Browse files
committed
add method channel.Current to get the current channel
1 parent 314f95e commit ae58483

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Diff for: README

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ Interface "channel"
8383
- get count of channels
8484
vdr-dbus-send.sh /Channels channel.Count
8585

86+
- get current channel
87+
vdr-dbus-send.sh /Channels channel.Current
88+
8689
- get channels between from_index and to_index
8790
vdr-dbus-send.sh /Channels channel.GetFromTo int32:from_index int32:to_index
8891

Diff for: channel.c

+34
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "helper.h"
44

55
#include <vdr/channels.h>
6+
#include <vdr/device.h>
67

78

89
namespace cDBusChannelsHelper
@@ -15,6 +16,10 @@ namespace cDBusChannelsHelper
1516
" <method name=\"Count\">\n"
1617
" <arg name=\"count\" type=\"i\" direction=\"out\"/>\n"
1718
" </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"
1823
" <method name=\"GetFromTo\">\n"
1924
" <arg name=\"from_index\" type=\"i\" direction=\"in\"/>\n"
2025
" <arg name=\"to_index\" type=\"i\" direction=\"in\"/>\n"
@@ -56,6 +61,34 @@ namespace cDBusChannelsHelper
5661
g_dbus_method_invocation_return_value(Invocation, g_variant_new("(i)", channels->Count()));
5762
}
5863

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+
5992
static void GetFromTo(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
6093
{
6194
gint32 from_index = -1;
@@ -163,6 +196,7 @@ cDBusChannels::cDBusChannels(void)
163196
:cDBusObject("/Channels", cDBusChannelsHelper::_xmlNodeInfo)
164197
{
165198
AddMethod("Count", cDBusChannelsHelper::Count);
199+
AddMethod("Current", cDBusChannelsHelper::Current);
166200
AddMethod("GetFromTo", cDBusChannelsHelper::GetFromTo);
167201
AddMethod("List", cDBusChannelsHelper::List);
168202
}

Diff for: dbus2vdr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "avahi-helper.h"
3838

3939

40-
static const char *VERSION = "26";
40+
static const char *VERSION = "27";
4141
static const char *DESCRIPTION = trNOOP("control vdr via D-Bus");
4242
static const char *MAINMENUENTRY = NULL;
4343

0 commit comments

Comments
 (0)