mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-13 17:20:21 +00:00
add xchat r1489
This commit is contained in:
56
src/common/dbus/Makefile.am
Normal file
56
src/common/dbus/Makefile.am
Normal file
@@ -0,0 +1,56 @@
|
||||
noinst_LIBRARIES = libxchatdbus.a
|
||||
libxchatdbus_a_SOURCES = \
|
||||
dbus-plugin.c \
|
||||
dbus-plugin.h \
|
||||
dbus-client.c \
|
||||
dbus-client.h
|
||||
|
||||
EXTRA_DIST = \
|
||||
remote-object.xml \
|
||||
apps_xchat_url_handler.schemas \
|
||||
marshallers.list \
|
||||
example.py \
|
||||
org.xchat.service.service.in \
|
||||
README
|
||||
|
||||
BUILT_SOURCES = \
|
||||
marshallers.h \
|
||||
remote-object-glue.h
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
INCLUDES = $(COMMON_CFLAGS) $(DBUS_CFLAGS)
|
||||
|
||||
noinst_PROGRAMS = example
|
||||
example_SOURCES = example.c
|
||||
example_LDADD = $(DBUS_LIBS) $(GLIB_LIBS)
|
||||
|
||||
remote-object-glue.h: remote-object.xml
|
||||
$(LIBTOOL) --mode=execute $(DBUS_BINDING_TOOL) --prefix=remote_object --mode=glib-server --output=$@ $<
|
||||
|
||||
marshallers.h: marshallers.list
|
||||
$(LIBTOOL) --mode=execute $(GLIB_GENMARSHAL) --header --body $< > $@
|
||||
|
||||
# Dbus service file
|
||||
servicedir = $(DBUS_SERVICES_DIR)
|
||||
service_in_files = org.xchat.service.service.in
|
||||
service_DATA = $(service_in_files:.service.in=.service)
|
||||
|
||||
# Rule to make the service file with bindir expanded
|
||||
$(service_DATA): $(service_in_files) Makefile
|
||||
@sed -e "s|\@bindir\@|$(bindir)|" $< > $@
|
||||
|
||||
if DO_GCONF
|
||||
GCONF_SCHEMA_CONFIG_SOURCE = `$(GCONFTOOL) --get-default-source`
|
||||
GCONF_SCHEMA_FILE_DIR = $(sysconfdir)/gconf/schemas
|
||||
schemadir = $(GCONF_SCHEMA_FILE_DIR)
|
||||
schema_DATA = apps_xchat_url_handler.schemas
|
||||
install-data-local:
|
||||
if test -z "$(DESTDIR)" ; then \
|
||||
for p in $(schema_DATA) ; do \
|
||||
GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(srcdir)/$$p; \
|
||||
done \
|
||||
fi
|
||||
else
|
||||
install-data-local:
|
||||
endif
|
||||
198
src/common/dbus/README
Normal file
198
src/common/dbus/README
Normal file
@@ -0,0 +1,198 @@
|
||||
For more help you can see the xchat plugin interface documentation.
|
||||
http://www.xchat.org/docs/plugin20.html
|
||||
WARNING: The dbus interface may change in the future.
|
||||
|
||||
You can use the "/org/xchat/Remote" object with interface "org.xchat.plugin",
|
||||
but his context can be changed by other clients at any moment and
|
||||
you may receive signal asked by other clients. So for more complex usage it's
|
||||
better to get your own remote object. Using "Connect" method on interface
|
||||
"org.xchat.connection"
|
||||
|
||||
Available methods on org.xchat.connection interface:
|
||||
|
||||
"Connect"
|
||||
- Parameters:
|
||||
- gchar*: filename
|
||||
- gchar*: name
|
||||
- gchar*: description
|
||||
- gchar*: version
|
||||
- Returns:
|
||||
- gchar*: Your own object's path.
|
||||
|
||||
"Disconnect"
|
||||
No parameter, no return value. It frees your remote object.
|
||||
|
||||
Available methods on org.xchat.plugin interface:
|
||||
|
||||
"Command"
|
||||
- Parameters:
|
||||
- gchar*: the command name without the "/". (e.g. "nick pseudo")
|
||||
|
||||
"Print"
|
||||
- Parameters:
|
||||
- gchar*: text to print on the xchat window.
|
||||
|
||||
"FindContext"
|
||||
- Parameters:
|
||||
- gchar*: the server name. Can be NULL.
|
||||
- gchar*: the channel name. Can be NULL.
|
||||
- Returns:
|
||||
- guint: context ID
|
||||
|
||||
"GetContext"
|
||||
- Returns:
|
||||
- guint: current context's ID
|
||||
|
||||
"SetContext"
|
||||
- Parameters:
|
||||
- guint: context ID to switch, returned by "FindContext" or "GetContext"
|
||||
- Returns:
|
||||
- gboolean: 1 for success, 0 for failure.
|
||||
|
||||
"GetInfo"
|
||||
- Parameters:
|
||||
- gchar*: ID of the information you want.
|
||||
- Returns:
|
||||
- gchar*: information you requested.
|
||||
|
||||
"GetPrefs"
|
||||
- Parameters:
|
||||
- gchar*: Setting name required.
|
||||
- Returns:
|
||||
- int: 0-Failed 1-Returned a string 2-Returned an Integer
|
||||
3-Returned a Boolean.
|
||||
- gchar*: the information requested if it's a string.
|
||||
- int: the information requested if it's a integer or boolean.
|
||||
|
||||
"HookCommand"
|
||||
- Parameters:
|
||||
- gchar*: Name of the command (without the forward slash).
|
||||
- int: Priority of this command.
|
||||
- gchar*: String of text to display when the user executes /help
|
||||
for this command. May be NULL if you're lazy.
|
||||
- int: Value to returns when the command is catched. See XCHAT_EAT_*.
|
||||
- Returns:
|
||||
- guint: The ID of the hook.
|
||||
|
||||
"HookServer"
|
||||
- Parameters:
|
||||
- gchar*: Name of the server event.
|
||||
- int: Priority of this command.
|
||||
- int: Value to returns when the command is catched. See XCHAT_EAT_*.
|
||||
- Returns:
|
||||
- guint: The ID of the hook.
|
||||
|
||||
"HookPrint"
|
||||
- Parameters:
|
||||
- gchar*: Name of the print event.
|
||||
- int: Priority of this command.
|
||||
- int: Value to returns when the command is catched. See XCHAT_EAT_*.
|
||||
- Returns:
|
||||
- guint: The ID of the hook.
|
||||
|
||||
"Unhook"
|
||||
- Parameters:
|
||||
- guint: ID of the hook to unhook.
|
||||
(the return value of "HookCommand", "HookServer" or "HookPrint")
|
||||
|
||||
"ListGet"
|
||||
- Parameters:
|
||||
- gchar*: The list name.
|
||||
- Returns:
|
||||
- guint: List ID.
|
||||
|
||||
"ListNext"
|
||||
- Parameters:
|
||||
- guint: List ID returned by "ListGet".
|
||||
- Returns:
|
||||
- gboolean: says if there is no more item in the list.
|
||||
|
||||
"ListStr"
|
||||
- Parameters:
|
||||
- guint: List ID returned by "ListGet".
|
||||
- gchar*: Name of the information needed.
|
||||
- Returns:
|
||||
- gchar*: The information requested.
|
||||
Warning: "context" attribut of "channels" list should be get with "ListInt"
|
||||
|
||||
"ListInt"
|
||||
- Parameters:
|
||||
- guint: List ID returned by "ListGet".
|
||||
- gchar*: Name of the information needed.
|
||||
- Returns:
|
||||
- guint: The information requested.
|
||||
|
||||
"ListTime"
|
||||
- Parameters:
|
||||
- guint: List ID returned by "ListGet".
|
||||
- gchar*: Name of the information needed.
|
||||
- Returns:
|
||||
- guint64: The information requested.
|
||||
|
||||
"ListFields"
|
||||
- Parameters:
|
||||
- gchar*: The list name.
|
||||
- Returns:
|
||||
- gchar**: information names in this list.
|
||||
|
||||
"ListFree"
|
||||
- Parameters:
|
||||
- guint: List ID returned by "ListGet".
|
||||
|
||||
"EmitPrint"
|
||||
- Parameters:
|
||||
- gchar*: Text event to print.
|
||||
- gchar**: NULL terminated array of string.
|
||||
- Returns:
|
||||
- gboolean: 1-Success 0-Failure.
|
||||
|
||||
"Nickcmp"
|
||||
- Parameters:
|
||||
- gchar*: String to compare.
|
||||
- gchar*: String to compare.
|
||||
- Returns:
|
||||
- int: An integer less than, equal to, or greater than zero if s1 is found,
|
||||
respectively, to be less than, to match, or be greater than s2.
|
||||
|
||||
"Strip"
|
||||
- Parameters:
|
||||
- gchar*: String to strip.
|
||||
- int: Length of the string (or -1 for NULL terminated).
|
||||
- int: Bit-field of flags: 0-Strip mIRC colors, 1-Strip text attributes.
|
||||
- Returns:
|
||||
- gchar*: striped string.
|
||||
|
||||
"SendModes"
|
||||
- Parameters:
|
||||
- gchar**: NULL terminated array of targets (strings). The names of people
|
||||
whom the action will be performed on.
|
||||
- int: Maximum modes to send per line.
|
||||
- gchar: Mode sign, '-' or '+'.
|
||||
- gchar: Mode char, e.g. 'o' for Ops.
|
||||
|
||||
|
||||
Available signals:
|
||||
|
||||
"ServerSignal"
|
||||
- Parameters:
|
||||
- gchar**: word returned by xchat.
|
||||
- gchar**: word_eol returned bu xchat.
|
||||
- guint: the ID of the hook. (the return value of "HookServer").
|
||||
- guint: the ID of the context where the event come from.
|
||||
|
||||
"CommandSignal"
|
||||
- Parameters:
|
||||
- gchar**: word returned by xchat.
|
||||
- gchar**: word_eol returned bu xchat.
|
||||
- guint: the ID of the hook. (the return value of "HookCommand").
|
||||
- guint: the ID of the context where the event come from.
|
||||
|
||||
"PrintSignal"
|
||||
- Parameters:
|
||||
- gchar**: word returned by xchat.
|
||||
- guint: the ID of the hook. (the return value of "HookPrint").
|
||||
- guint: the ID of the context where the event come from.
|
||||
|
||||
"UnloadSignal"
|
||||
emited when the user asks to unload your program.
|
||||
Please exit(0); when received !
|
||||
37
src/common/dbus/apps_xchat_url_handler.schemas
Normal file
37
src/common/dbus/apps_xchat_url_handler.schemas
Normal file
@@ -0,0 +1,37 @@
|
||||
<gconfschemafile>
|
||||
<schemalist>
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/url-handlers/irc/command</key>
|
||||
<applyto>/desktop/gnome/url-handlers/irc/command</applyto>
|
||||
<owner>xchat</owner>
|
||||
<type>string</type>
|
||||
<default>xchat --existing --url=%u</default>
|
||||
<locale name="C">
|
||||
<short>The handler for "irc://" URLs</short>
|
||||
</locale>
|
||||
</schema>
|
||||
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/url-handlers/irc/enabled</key>
|
||||
<applyto>/desktop/gnome/url-handlers/irc/enabled</applyto>
|
||||
<owner>xchat</owner>
|
||||
<type>bool</type>
|
||||
<default>true</default>
|
||||
<locale name="C">
|
||||
<short>Set it at TRUE if you want it activated</short>
|
||||
</locale>
|
||||
</schema>
|
||||
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/url-handlers/irc/needs_terminal</key>
|
||||
<applyto>/desktop/gnome/url-handlers/irc/needs_terminal</applyto>
|
||||
<owner>xchat</owner>
|
||||
<type>bool</type>
|
||||
<default>false</default>
|
||||
<locale name="C">
|
||||
<short>Run xchat in a terminal?</short>
|
||||
</locale>
|
||||
</schema>
|
||||
|
||||
</schemalist>
|
||||
</gconfschemafile>
|
||||
118
src/common/dbus/dbus-client.c
Normal file
118
src/common/dbus/dbus-client.c
Normal file
@@ -0,0 +1,118 @@
|
||||
/* dbus-client.c - XChat command-line options for D-Bus
|
||||
* Copyright (C) 2006 Claessens Xavier
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*
|
||||
* Claessens Xavier
|
||||
* xclaesse@gmail.com
|
||||
*/
|
||||
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include "dbus-client.h"
|
||||
#include "../xchat.h"
|
||||
#include "../xchatc.h"
|
||||
|
||||
#define DBUS_SERVICE "org.xchat.service"
|
||||
#define DBUS_REMOTE "/org/xchat/Remote"
|
||||
#define DBUS_REMOTE_INTERFACE "org.xchat.plugin"
|
||||
|
||||
static void
|
||||
write_error (char *message,
|
||||
GError **error)
|
||||
{
|
||||
if (error == NULL || *error == NULL) {
|
||||
return;
|
||||
}
|
||||
g_printerr ("%s: %s\n", message, (*error)->message);
|
||||
g_clear_error (error);
|
||||
}
|
||||
|
||||
void
|
||||
xchat_remote (void)
|
||||
/* TODO: dbus_g_connection_unref (connection) are commented because it makes
|
||||
* dbus to crash. Fixed in dbus >=0.70 ?!?
|
||||
* https://launchpad.net/distros/ubuntu/+source/dbus/+bug/54375
|
||||
*/
|
||||
{
|
||||
DBusGConnection *connection;
|
||||
DBusGProxy *dbus = NULL;
|
||||
DBusGProxy *remote_object = NULL;
|
||||
gboolean xchat_running;
|
||||
GError *error = NULL;
|
||||
char *command = NULL;
|
||||
|
||||
/* GnomeVFS >=2.15 uses D-Bus and threads, so threads should be
|
||||
* initialised before opening for the first time a D-Bus connection */
|
||||
if (!g_thread_supported ()) {
|
||||
g_thread_init (NULL);
|
||||
}
|
||||
dbus_g_thread_init ();
|
||||
|
||||
/* if there is nothing to do, return now. */
|
||||
if (!arg_existing || !(arg_url || arg_command)) {
|
||||
return;
|
||||
}
|
||||
|
||||
arg_dont_autoconnect = TRUE;
|
||||
|
||||
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
|
||||
if (!connection) {
|
||||
write_error (_("Couldn't connect to session bus"), &error);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Checks if xchat is already running */
|
||||
dbus = dbus_g_proxy_new_for_name (connection,
|
||||
DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS,
|
||||
DBUS_INTERFACE_DBUS);
|
||||
if (!dbus_g_proxy_call (dbus, "NameHasOwner", &error,
|
||||
G_TYPE_STRING, DBUS_SERVICE,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_BOOLEAN, &xchat_running,
|
||||
G_TYPE_INVALID)) {
|
||||
write_error (_("Failed to complete NameHasOwner"), &error);
|
||||
xchat_running = FALSE;
|
||||
}
|
||||
g_object_unref (dbus);
|
||||
|
||||
if (!xchat_running) {
|
||||
//dbus_g_connection_unref (connection);
|
||||
return;
|
||||
}
|
||||
|
||||
remote_object = dbus_g_proxy_new_for_name (connection,
|
||||
DBUS_SERVICE,
|
||||
DBUS_REMOTE,
|
||||
DBUS_REMOTE_INTERFACE);
|
||||
|
||||
if (arg_url) {
|
||||
command = g_strdup_printf ("url %s", arg_url);
|
||||
} else if (arg_command) {
|
||||
command = g_strdup (arg_command);
|
||||
}
|
||||
|
||||
if (command) {
|
||||
if (!dbus_g_proxy_call (remote_object, "Command",
|
||||
&error,
|
||||
G_TYPE_STRING, command,
|
||||
G_TYPE_INVALID,G_TYPE_INVALID)) {
|
||||
write_error (_("Failed to complete Command"), &error);
|
||||
}
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
exit (0);
|
||||
}
|
||||
27
src/common/dbus/dbus-client.h
Normal file
27
src/common/dbus/dbus-client.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/* dbus-client.h - XChat command-line options for D-Bus
|
||||
* Copyright (C) 2006 Claessens Xavier
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*
|
||||
* Claessens Xavier
|
||||
* xclaesse@gmail.com
|
||||
*/
|
||||
|
||||
#ifndef __DBUS_PLUGIN_H__
|
||||
#define __DBUS_PLUGIN_H__
|
||||
|
||||
void xchat_remote (void);
|
||||
|
||||
#endif /* __DBUS_PLUGIN_H__ */
|
||||
1087
src/common/dbus/dbus-plugin.c
Normal file
1087
src/common/dbus/dbus-plugin.c
Normal file
File diff suppressed because it is too large
Load Diff
31
src/common/dbus/dbus-plugin.h
Normal file
31
src/common/dbus/dbus-plugin.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/* dbus-plugin.c - xchat plugin for remote access using DBUS
|
||||
* Copyright (C) 2006 Claessens Xavier
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*
|
||||
* Claessens Xavier
|
||||
* xclaesse@gmail.com
|
||||
*/
|
||||
|
||||
#ifndef XCHAT_DBUS_PLUGIN_H
|
||||
#define XCHAT_DBUS_PLUGIN_H
|
||||
|
||||
int dbus_plugin_init (xchat_plugin *plugin_handle,
|
||||
char **plugin_name,
|
||||
char **plugin_desc,
|
||||
char **plugin_version,
|
||||
char *arg);
|
||||
|
||||
#endif
|
||||
201
src/common/dbus/example.c
Normal file
201
src/common/dbus/example.c
Normal file
@@ -0,0 +1,201 @@
|
||||
/* example.c - program to demonstrate some D-BUS stuffs.
|
||||
* Copyright (C) 2006 Claessens Xavier
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* Claessens Xavier
|
||||
* xclaesse@gmail.com
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <stdlib.h>
|
||||
#include "marshallers.h"
|
||||
|
||||
#define DBUS_SERVICE "org.xchat.service"
|
||||
#define DBUS_REMOTE "/org/xchat/Remote"
|
||||
#define DBUS_REMOTE_CONNECTION_INTERFACE "org.xchat.connection"
|
||||
#define DBUS_REMOTE_PLUGIN_INTERFACE "org.xchat.plugin"
|
||||
|
||||
guint command_id;
|
||||
guint server_id;
|
||||
|
||||
static void
|
||||
write_error (char *message,
|
||||
GError **error)
|
||||
{
|
||||
if (error == NULL || *error == NULL) {
|
||||
return;
|
||||
}
|
||||
g_printerr ("%s: %s\n", message, (*error)->message);
|
||||
g_clear_error (error);
|
||||
}
|
||||
|
||||
static void
|
||||
test_server_cb (DBusGProxy *proxy,
|
||||
char *word[],
|
||||
char *word_eol[],
|
||||
guint hook_id,
|
||||
guint context_id,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (hook_id == server_id) {
|
||||
g_print ("message: %s\n", word_eol[0]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_command_cb (DBusGProxy *proxy,
|
||||
char *word[],
|
||||
char *word_eol[],
|
||||
guint hook_id,
|
||||
guint context_id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (hook_id == command_id) {
|
||||
if (!dbus_g_proxy_call (proxy, "Unhook",
|
||||
&error,
|
||||
G_TYPE_UINT, hook_id,
|
||||
G_TYPE_INVALID, G_TYPE_INVALID)) {
|
||||
write_error ("Failed to complete unhook", &error);
|
||||
}
|
||||
/* Now if you write "/test blah" again in the xchat window
|
||||
* you'll get a "Unknown command" error message */
|
||||
g_print ("test command received: %s\n", word_eol[1]);
|
||||
if (!dbus_g_proxy_call (proxy, "Print",
|
||||
&error,
|
||||
G_TYPE_STRING, "test command succeed",
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID)) {
|
||||
write_error ("Failed to complete Print", &error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unload_cb (void)
|
||||
{
|
||||
g_print ("Good bye !\n");
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
DBusGConnection *connection;
|
||||
DBusGProxy *remote_object;
|
||||
GMainLoop *mainloop;
|
||||
gchar *path;
|
||||
GError *error = NULL;
|
||||
|
||||
g_type_init ();
|
||||
|
||||
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
|
||||
if (connection == NULL) {
|
||||
write_error ("Couldn't connect to session bus", &error);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
remote_object = dbus_g_proxy_new_for_name (connection,
|
||||
DBUS_SERVICE,
|
||||
DBUS_REMOTE,
|
||||
DBUS_REMOTE_CONNECTION_INTERFACE);
|
||||
if (!dbus_g_proxy_call (remote_object, "Connect",
|
||||
&error,
|
||||
G_TYPE_STRING, argv[0],
|
||||
G_TYPE_STRING, "example",
|
||||
G_TYPE_STRING, "Example of a D-Bus client",
|
||||
G_TYPE_STRING, "1.0",
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_STRING, &path, G_TYPE_INVALID)) {
|
||||
write_error ("Failed to complete Connect", &error);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
g_object_unref (remote_object);
|
||||
|
||||
remote_object = dbus_g_proxy_new_for_name (connection,
|
||||
DBUS_SERVICE,
|
||||
path,
|
||||
DBUS_REMOTE_PLUGIN_INTERFACE);
|
||||
g_free (path);
|
||||
|
||||
if (!dbus_g_proxy_call (remote_object, "HookCommand",
|
||||
&error,
|
||||
G_TYPE_STRING, "test",
|
||||
G_TYPE_INT, 0,
|
||||
G_TYPE_STRING, "Simple D-BUS example",
|
||||
G_TYPE_INT, 1, G_TYPE_INVALID,
|
||||
G_TYPE_UINT, &command_id, G_TYPE_INVALID)) {
|
||||
write_error ("Failed to complete HookCommand", &error);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
g_print ("Command hook id=%d\n", command_id);
|
||||
|
||||
if (!dbus_g_proxy_call (remote_object, "HookServer",
|
||||
&error,
|
||||
G_TYPE_STRING, "RAW LINE",
|
||||
G_TYPE_INT, 0,
|
||||
G_TYPE_INT, 0, G_TYPE_INVALID,
|
||||
G_TYPE_UINT, &server_id, G_TYPE_INVALID)) {
|
||||
write_error ("Failed to complete HookServer", &error);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
g_print ("Server hook id=%d\n", server_id);
|
||||
|
||||
dbus_g_object_register_marshaller (
|
||||
g_cclosure_user_marshal_VOID__POINTER_POINTER_UINT_UINT,
|
||||
G_TYPE_NONE,
|
||||
G_TYPE_STRV, G_TYPE_STRV, G_TYPE_UINT, G_TYPE_UINT,
|
||||
G_TYPE_INVALID);
|
||||
|
||||
dbus_g_object_register_marshaller (
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE,
|
||||
G_TYPE_INVALID);
|
||||
|
||||
dbus_g_proxy_add_signal (remote_object, "CommandSignal",
|
||||
G_TYPE_STRV,
|
||||
G_TYPE_STRV,
|
||||
G_TYPE_UINT,
|
||||
G_TYPE_UINT,
|
||||
G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (remote_object, "CommandSignal",
|
||||
G_CALLBACK (test_command_cb),
|
||||
NULL, NULL);
|
||||
|
||||
dbus_g_proxy_add_signal (remote_object, "ServerSignal",
|
||||
G_TYPE_STRV,
|
||||
G_TYPE_STRV,
|
||||
G_TYPE_UINT,
|
||||
G_TYPE_UINT,
|
||||
G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (remote_object, "ServerSignal",
|
||||
G_CALLBACK (test_server_cb),
|
||||
NULL, NULL);
|
||||
|
||||
dbus_g_proxy_add_signal (remote_object, "UnloadSignal",
|
||||
G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (remote_object, "UnloadSignal",
|
||||
G_CALLBACK (unload_cb),
|
||||
NULL, NULL);
|
||||
|
||||
/* Now you can write on the xchat windows: "/test arg1 arg2 ..." */
|
||||
mainloop = g_main_loop_new (NULL, FALSE);
|
||||
g_main_loop_run (mainloop);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
28
src/common/dbus/example.py
Normal file
28
src/common/dbus/example.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#! /usr/bin/python
|
||||
|
||||
import dbus
|
||||
|
||||
bus = dbus.SessionBus()
|
||||
proxy = bus.get_object('org.xchat.service', '/org/xchat/Remote')
|
||||
remote = dbus.Interface(proxy, 'org.xchat.connection')
|
||||
path = remote.Connect ("example.py",
|
||||
"Python example",
|
||||
"Example of a D-Bus client written in python",
|
||||
"1.0")
|
||||
proxy = bus.get_object('org.xchat.service', path)
|
||||
xchat = dbus.Interface(proxy, 'org.xchat.plugin')
|
||||
|
||||
channels = xchat.ListGet ("channels")
|
||||
while xchat.ListNext (channels):
|
||||
name = xchat.ListStr (channels, "channel")
|
||||
print "------- " + name + " -------"
|
||||
xchat.SetContext (xchat.ListInt (channels, "context"))
|
||||
xchat.EmitPrint ("Channel Message", ["John", "Hi there", "@"])
|
||||
users = xchat.ListGet ("users")
|
||||
while xchat.ListNext (users):
|
||||
print "Nick: " + xchat.ListStr (users, "nick")
|
||||
xchat.ListFree (users)
|
||||
xchat.ListFree (channels)
|
||||
|
||||
print xchat.Strip ("\00312Blue\003 \002Bold!\002", -1, 1|2)
|
||||
|
||||
1
src/common/dbus/marshallers.list
Normal file
1
src/common/dbus/marshallers.list
Normal file
@@ -0,0 +1 @@
|
||||
VOID:POINTER,POINTER,UINT,UINT
|
||||
3
src/common/dbus/org.xchat.service.service.in
Normal file
3
src/common/dbus/org.xchat.service.service.in
Normal file
@@ -0,0 +1,3 @@
|
||||
[D-BUS Service]
|
||||
Name=org.xchat.service
|
||||
Exec=@bindir@/xchat
|
||||
142
src/common/dbus/remote-object.xml
Normal file
142
src/common/dbus/remote-object.xml
Normal file
@@ -0,0 +1,142 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<node name="/">
|
||||
|
||||
<interface name="org.xchat.connection">
|
||||
<method name="Connect">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<arg type="s" name="filename" direction="in"/>
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="s" name="desc" direction="in"/>
|
||||
<arg type="s" name="version" direction="in"/>
|
||||
<arg type="s" name="path" direction="out"/>
|
||||
</method>
|
||||
<method name="Disconnect">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
</method>
|
||||
</interface>
|
||||
|
||||
<interface name="org.xchat.plugin">
|
||||
<method name="Command">
|
||||
<arg type="s" name="command" direction="in"/>
|
||||
</method>
|
||||
<method name="Print">
|
||||
<arg type="s" name="text" direction="in"/>
|
||||
</method>
|
||||
<method name="FindContext">
|
||||
<arg type="s" name="server" direction="in"/>
|
||||
<arg type="s" name="channel" direction="in"/>
|
||||
<arg type="u" name="ret_id" direction="out"/>
|
||||
</method>
|
||||
<method name="GetContext">
|
||||
<arg type="u" name="ret_id" direction="out"/>
|
||||
</method>
|
||||
<method name="SetContext">
|
||||
<arg type="u" name="id" direction="in"/>
|
||||
<arg type="b" name="ret" direction="out"/>
|
||||
</method>
|
||||
<method name="GetInfo">
|
||||
<arg type="s" name="id" direction="in"/>
|
||||
<arg type="s" name="ret_info" direction="out"/>
|
||||
</method>
|
||||
<method name="GetPrefs">
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="i" name="ret_type" direction="out"/>
|
||||
<arg type="s" name="ret_str" direction="out"/>
|
||||
<arg type="i" name="ret_int" direction="out"/>
|
||||
</method>
|
||||
<method name="HookCommand">
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="i" name="priority" direction="in"/>
|
||||
<arg type="s" name="help_text" direction="in"/>
|
||||
<arg type="i" name="return_value" direction="in"/>
|
||||
<arg type="u" name="ret_id" direction="out"/>
|
||||
</method>
|
||||
<method name="HookServer">
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="i" name="priority" direction="in"/>
|
||||
<arg type="i" name="return_value" direction="in"/>
|
||||
<arg type="u" name="ret_id" direction="out"/>
|
||||
</method>
|
||||
<method name="HookPrint">
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="i" name="priority" direction="in"/>
|
||||
<arg type="i" name="return_value" direction="in"/>
|
||||
<arg type="u" name="ret_id" direction="out"/>
|
||||
</method>
|
||||
<method name="Unhook">
|
||||
<arg type="u" name="id" direction="in"/>
|
||||
</method>
|
||||
<method name="ListGet">
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="u" name="ret_id" direction="out"/>
|
||||
</method>
|
||||
<method name="ListNext">
|
||||
<arg type="u" name="id" direction="in"/>
|
||||
<arg type="b" name="ret" direction="out"/>
|
||||
</method>
|
||||
<method name="ListStr">
|
||||
<arg type="u" name="id" direction="in"/>
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="s" name="ret_str" direction="out"/>
|
||||
</method>
|
||||
<method name="ListInt">
|
||||
<arg type="u" name="id" direction="in"/>
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="i" name="ret_int" direction="out"/>
|
||||
</method>
|
||||
<method name="ListTime">
|
||||
<arg type="u" name="id" direction="in"/>
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="t" name="ret_time" direction="out"/>
|
||||
</method>
|
||||
<method name="ListFields">
|
||||
<arg type="s" name="name" direction="in"/>
|
||||
<arg type="as" name="ret" direction="out"/>
|
||||
</method>
|
||||
<method name="ListFree">
|
||||
<arg type="u" name="id" direction="in"/>
|
||||
</method>
|
||||
<method name="EmitPrint">
|
||||
<arg type="s" name="event_name" direction="in"/>
|
||||
<arg type="as" name="args" direction="in"/>
|
||||
<arg type="b" name="ret" direction="out"/>
|
||||
</method>
|
||||
<method name="Nickcmp">
|
||||
<arg type="s" name="nick1" direction="in"/>
|
||||
<arg type="s" name="nick2" direction="in"/>
|
||||
<arg type="i" name="ret" direction="out"/>
|
||||
</method>
|
||||
<method name="Strip">
|
||||
<arg type="s" name="str" direction="in"/>
|
||||
<arg type="i" name="len" direction="in"/>
|
||||
<arg type="i" name="flag" direction="in"/>
|
||||
<arg type="s" name="ret_str" direction="out"/>
|
||||
</method>
|
||||
<method name="SendModes">
|
||||
<arg type="as" name="targets" direction="in"/>
|
||||
<arg type="i" name="modes_per_line" direction="in"/>
|
||||
<arg type="y" name="sign" direction="in"/>
|
||||
<arg type="y" name="mode" direction="in"/>
|
||||
</method>
|
||||
|
||||
<signal name="CommandSignal">
|
||||
<arg type="as" name="word"/>
|
||||
<arg type="as" name="word_eol"/>
|
||||
<arg type="u" name="hook_id"/>
|
||||
<arg type="u" name="context_id"/>
|
||||
</signal>
|
||||
<signal name="ServerSignal">
|
||||
<arg type="as" name="word"/>
|
||||
<arg type="as" name="word_eol"/>
|
||||
<arg type="u" name="hook_id"/>
|
||||
<arg type="u" name="context_id"/>
|
||||
</signal>
|
||||
<signal name="PrintSignal">
|
||||
<arg type="as" name="word"/>
|
||||
<arg type="u" name="hook_id"/>
|
||||
<arg type="u" name="context_id"/>
|
||||
</signal>
|
||||
<signal name="UnloadSignal"/>
|
||||
</interface>
|
||||
</node>
|
||||
Reference in New Issue
Block a user