cpw.qulogic.vala: 7c901b34: Add vala nullclient sample.

qulogic at pidgin.im qulogic at pidgin.im
Fri May 6 02:36:35 EDT 2011


----------------------------------------------------------------------
Revision: 7c901b34f36936131873c2ce797d14edd37165f3
Parent:   1378e24f6299a6404dace796bd0a4b33de12c540
Author:   qulogic at pidgin.im
Date:     03/27/11 21:59:57
Branch:   im.pidgin.cpw.qulogic.vala
URL: http://d.pidgin.im/viewmtn/revision/info/7c901b34f36936131873c2ce797d14edd37165f3

Changelog: 

Add vala nullclient sample.

Changes against parent 1378e24f6299a6404dace796bd0a4b33de12c540

  added    vala/nullclient
  added    vala/Makefile.am
  added    vala/nullclient/Makefile.am
  added    vala/nullclient/config.vala
  added    vala/nullclient/conv.vala
  added    vala/nullclient/core.vala
  added    vala/nullclient/eventloop.vala
  added    vala/nullclient/main.vala
  added    vala/nullclient/signals.vala
  patched  .mtn-ignore
  patched  configure.ac

-------------- next part --------------
============================================================
--- configure.ac	7e11bc1f3bc1cef1dd667cd361acb14a1f2b4609
+++ configure.ac	398187c5cccb4a7683f1b88ab5b325c944398bb9
@@ -1686,7 +1686,11 @@ if test "x$enable_vala" != "xno"; then
 	PKG_CHECK_MODULES(VALA, vala-0.10 >= "$VALA_REQUIRED", [VALA_PKG=0.10], [
 		PKG_CHECK_MODULES(VALA, [vala-1.0 >= "$VALA_REQUIRED"], [VALA_PKG=1.0])
 		])
-	AC_PATH_PROG(VALA, vala)
+	dnl AM_PROG_VALA was added in automake 1.11
+	m4_ifdef([AM_PROG_VALA],[AM_PROG_VALA($VALA_REQUIRED)],[AC_PATH_PROG(VALAC, valac)])
+	if test "x$VALAC" = "x" ; then
+		AC_MSG_ERROR([Cannot find the "valac" compiler in your PATH])
+	fi
 
 	# vala-gen-introspect is useless, but it's just a wrapper,
 	#  so we go use the real parser
@@ -2644,6 +2648,7 @@ AC_CONFIG_FILES([Makefile
 		   finch/libgnt/wms/Makefile
 		   finch/plugins/Makefile
 		   vala/Makefile
+		   vala/nullclient/Makefile
 		   vala/vapi/Makefile
 		   vala/vapi/purple.deps
 		   vala/vapi/purple.files
============================================================
--- .mtn-ignore	6eb34ec4088ea6a574b45933ae8a63cc5793a2be
+++ .mtn-ignore	ad495afba6792100dd147dc00d4bd17b8c6bcc59
@@ -95,4 +95,5 @@ stamp-h1
 po/pidgin.pot
 po/stamp-it
 stamp-h1
+vala/nullclient/nullclient
 win32-install-dir(\.release)?
============================================================
--- /dev/null	
+++ vala/Makefile.am	5c1f1fcc43c8fec889d65180a0c0cd0709f963ad
@@ -0,0 +1,3 @@
+
+SUBDIRS = vapi nullclient
+
============================================================
--- /dev/null	
+++ vala/nullclient/Makefile.am	93a6b55fcda82f2e7b69c8d4293165486b828d19
@@ -0,0 +1,30 @@
+
+noinst_PROGRAMS = nullclient
+
+VALAFLAGS = --vapidir=$(top_builddir)/vala/vapi/ --pkg purple --pkg posix
+
+AM_CFLAGS = \
+	-I$(top_builddir)/libpurple \
+	-I$(top_srcdir)/libpurple \
+	-I$(top_srcdir) \
+	$(GLIB_CFLAGS)
+
+nullclient_VALASOURCES = \
+	main.vala \
+	config.vala \
+	core.vala \
+	eventloop.vala \
+	conv.vala \
+	signals.vala
+
+nullclient_SOURCES = \
+	$(nullclient_VALASOURCES:.vala=.c)
+
+$(nullclient_SOURCES): nullclient.vala.stamp
+
+nullclient.vala.stamp: $(nullclient_VALASOURCES) $(top_builddir)/vala/vapi/purple.vapi
+	$(AM_V_GEN)$(VALAC) -C $(VALAFLAGS) $(addprefix $(srcdir)/,$(nullclient_VALASOURCES))
+	$(AM_V_at)touch $@
+
+nullclient_LDADD = $(top_builddir)/libpurple/libpurple.la
+
============================================================
--- /dev/null	
+++ vala/nullclient/config.vala	efb30ccf21c9cb30a6a25305410086e5cf5fcbec
@@ -0,0 +1,30 @@
+/*
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+
+namespace NullConfig {
+	const string CUSTOM_USER_DIRECTORY = "/dev/null";
+	const string CUSTOM_PLUGIN_PATH = "";
+	const string PLUGIN_SAVE_PREF = "/purple/nullclient/plugins/saved";
+	const string UI_ID = "nullclient";
+}
+
============================================================
--- /dev/null	
+++ vala/nullclient/conv.vala	d7381bce6061cf40eb3ffe686b738b9a5bab5dc0
@@ -0,0 +1,51 @@
+/*
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+
+namespace NullConv {
+public Purple.ConversationUiOps uiops;
+public void init()
+{
+	uiops.write_conv = (GLib.Callback)write_conv;
+}
+
+private void
+write_conv(Purple.Conversation conv, string? who, string? alias,
+			string? message, Purple.MessageFlags flags, time_t mtime)
+{
+	string name;
+	GLib.Time t;
+	if (alias != null && alias.length > 0)
+		name = alias;
+	else if (who != null && who.length > 0)
+		name = who;
+	else
+		name = null;
+
+	t = GLib.Time.local(mtime);
+	stdout.printf("(%s) %s %s: %s\n",
+	              conv.name, Purple.utf8_strftime("(%H:%M:%S)", &t),
+	              name, message);
+}
+
+}
+
============================================================
--- /dev/null	
+++ vala/nullclient/core.vala	91bec321d69c323d1b2a36f9c83627f132b0ca24
@@ -0,0 +1,42 @@
+/*
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+
+namespace NullCore {
+Purple.CoreUiOps uiops;
+public void init() {
+	uiops.ui_init = ui_init;
+}
+
+private void
+ui_init()
+{
+	/**
+	 * This should initialize the UI components for all the modules. Here we
+	 * just initialize the UI for conversations.
+	 */
+	NullConv.init();
+	Purple.conversations_set_ui_ops(NullConv.uiops);
+}
+
+}
+
============================================================
--- /dev/null	
+++ vala/nullclient/eventloop.vala	dfc79c7a98a22afc13f18e878d6d0f92da70204e
@@ -0,0 +1,110 @@
+/*
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+
+namespace NullEventLoop {
+public Purple.EventLoopUiOps uiops;
+public static void init()
+{
+	uiops.timeout_add = (GLib.Callback)timeout_add;
+	uiops.timeout_remove = (GLib.Callback)GLib.Source.remove;
+	uiops.input_add = (GLib.Callback)PurpleGLibIOClosure.glib_input_add;
+	uiops.input_remove = (GLib.Callback)GLib.Source.remove;
+	uiops.input_get_error = null;
+	uiops.timeout_add_seconds = (GLib.Callback)timeout_add_seconds;
+}
+
+/**
+ * The following eventloop functions are used in both pidgin and purple-text. If your
+ * application uses glib mainloop, you can safely use this verbatim.
+ */
+
+class PurpleGLibIOClosure {
+	private const int PURPLE_GLIB_READ_COND  = (GLib.IOCondition.IN |
+	                                            GLib.IOCondition.HUP |
+	                                            GLib.IOCondition.ERR);
+	private const int PURPLE_GLIB_WRITE_COND = (GLib.IOCondition.OUT |
+	                                            GLib.IOCondition.HUP |
+	                                            GLib.IOCondition.ERR |
+	                                            GLib.IOCondition.NVAL);
+
+	private Purple.InputFunction function;
+	private uint result;
+	private void* data;
+
+	private PurpleGLibIOClosure(int fd, Purple.InputCondition condition,
+	                            Purple.InputFunction function, void* data)
+	{
+		GLib.IOChannel channel;
+		GLib.IOCondition cond = 0;
+
+		this.function = function;
+		this.data = data;
+
+		if ((condition & Purple.InputCondition.READ) != 0)
+			cond |= PURPLE_GLIB_READ_COND;
+		if ((condition & Purple.InputCondition.WRITE) != 0)
+			cond |= PURPLE_GLIB_WRITE_COND;
+
+		channel = new GLib.IOChannel.unix_new(fd);
+		this.result = channel.add_watch_full(GLib.Priority.DEFAULT, cond,
+		                                     this.glib_io_invoke);
+	}
+
+	private bool
+	glib_io_invoke(GLib.IOChannel source, GLib.IOCondition condition)
+	{
+		Purple.InputCondition purple_cond = 0;
+
+		if ((condition & PURPLE_GLIB_READ_COND) != 0)
+			purple_cond |= Purple.InputCondition.READ;
+		if ((condition & PURPLE_GLIB_WRITE_COND) != 0)
+			purple_cond |= Purple.InputCondition.WRITE;
+
+		this.function(this.data, source.unix_get_fd(), purple_cond);
+
+		return true;
+	}
+
+	public static uint
+	glib_input_add(int fd, Purple.InputCondition condition,
+	               Purple.InputFunction function, void* data)
+	{
+		PurpleGLibIOClosure closure;
+		closure = new PurpleGLibIOClosure(fd, condition, function, data);
+		return closure.result;
+	}
+
+}
+
+/* The GLib bindings only expose the _full version. */
+private uint timeout_add(uint interval, GLib.SourceFunc function)
+{
+	return GLib.Timeout.add(interval, function);
+}
+private uint timeout_add_seconds(uint interval, GLib.SourceFunc function)
+{
+	return GLib.Timeout.add_seconds(interval, function);
+}
+
+}
+
============================================================
--- /dev/null	
+++ vala/nullclient/main.vala	8d5e7bb8aabb6f4a9ba147f40b2d2027f42dc6cf
@@ -0,0 +1,152 @@
+/*
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+
+int main()
+{
+	unowned List<Purple.Plugin> plugins;
+	int i, num;
+	var names = new List<string>();
+	string prpl;
+	string name;
+	string password;
+	GLib.MainLoop loop = new GLib.MainLoop(null, false);
+	Purple.Account account;
+	Purple.SavedStatus status;
+
+	/* libpurple's built-in DNS resolution forks processes to perform
+	 * blocking lookups without blocking the main process.  It does not
+	 * handle SIGCHLD itself, so if the UI does not you quickly get an army
+	 * of zombie subprocesses marching around.
+	 */
+	Posix.signal(Posix.SIGCHLD, Posix.SIG_IGN);
+
+	if (!init_libpurple()) {
+		return 1;
+	}
+
+	stdout.printf("libpurple initialized.\n");
+
+	plugins = Purple.plugins_get_protocols();
+	i = 0;
+	foreach (unowned Purple.Plugin plugin in plugins) {
+		weak Purple.PluginInfo info = plugin.info;
+		if (info != null && info.name != null) {
+			stdout.printf("\t%d: %s\n", i++, info.name);
+			names.append(info.id);
+		}
+	}
+
+	stdout.printf("Select the protocol [0-%d]: ", i - 1);
+	name = stdin.read_line();
+	if (name == null) {
+		stderr.printf("Failed to gets protocol selection.\n");
+		return 1;
+	}
+	num = name.to_int();
+	prpl = names.nth_data(num);
+
+	stdout.printf("Username: ");
+	name = stdin.read_line();
+	if (name == null) {
+		stderr.printf("Failed to read user name.\n");
+		return 1;
+	}
+
+	/* Create the account */
+	account = new Purple.Account(name, prpl);
+
+	/* Get the password for the account */
+	password = Posix.getpass("Password: ");
+	account.set_password(password);
+
+	/* It's necessary to enable the account first. */
+	account.set_enabled(NullConfig.UI_ID, true);
+
+	/* Now, to connect the account(s), create a status and activate it. */
+	status = new Purple.SavedStatus(null, Purple.StatusPrimitive.AVAILABLE);
+	status.activate();
+
+	NullSignals.connect_for_demonstration_purposes_only();
+
+	loop.run();
+
+	return 0;
+}
+
+static bool
+init_libpurple()
+{
+	/* Set a custom user directory (optional) */
+	Purple.util_set_user_dir(NullConfig.CUSTOM_USER_DIRECTORY);
+
+	/* We do not want any debugging for now to keep the noise to a minimum. */
+	Purple.debug_set_enabled(false);
+
+	/* Set the core-uiops, which is used to
+	 * 	- initialize the ui specific preferences.
+	 * 	- initialize the debug ui.
+	 * 	- initialize the ui components for all the modules.
+	 * 	- uninitialize the ui components for all the modules when the core terminates.
+	 */
+	NullCore.init();
+	Purple.Core.set_ui_ops(NullCore.uiops);
+
+	/* Set the uiops for the eventloop. If your client is glib-based, you can safely
+	 * copy this verbatim. */
+	NullEventLoop.init();
+	Purple.eventloop_set_ui_ops(NullEventLoop.uiops);
+
+	/* Set path to search for plugins. The core (libpurple) takes care of loading the
+	 * core-plugins, which includes the protocol-plugins. So it is not essential to add
+	 * any path here, but it might be desired, especially for ui-specific plugins. */
+	Purple.plugins_add_search_path(NullConfig.CUSTOM_PLUGIN_PATH);
+
+	/* Now that all the essential stuff has been set, let's try to init the core. It's
+	 * necessary to provide a non-NULL name for the current ui to the core. This name
+	 * is used by stuff that depends on this ui, for example the ui-specific plugins. */
+	if (!Purple.Core.init(NullConfig.UI_ID)) {
+		/* Initializing the core failed. Terminate. */
+		stderr.printf(
+				"libpurple initialization failed.\n" +
+				"Please report this!\n");
+		return false;
+	}
+
+	/* Create and load the buddylist. */
+	Purple.set_blist(Purple.blist_new());
+	Purple.blist_load();
+
+	/* Load the preferences. */
+	Purple.prefs_load();
+
+	/* Load the desired plugins. The client should save the list of loaded plugins in
+	 * the preferences using purple_plugins_save_loaded(PLUGIN_SAVE_PREF) */
+	Purple.plugins_load_saved(NullConfig.PLUGIN_SAVE_PREF);
+
+	/* Load the pounces. */
+	Purple.pounces_load();
+
+	return true;
+}
+
+
============================================================
--- /dev/null	
+++ vala/nullclient/signals.vala	af26743e1d849ce086f315e61d8b249138e84f1f
@@ -0,0 +1,44 @@
+/*
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+
+namespace NullSignals {
+
+private void
+signed_on(Purple.Connection pc, void* unused)
+{
+	unowned Purple.Account account = pc.get_account();
+	stdout.printf("Account connected: %s %s\n",
+	              account.username,
+	              account.protocol_id);
+}
+
+static int handle;
+public void
+connect_for_demonstration_purposes_only()
+{
+	Purple.signal_connect(Purple.connections_get_handle(), "signed-on", &handle,
+	                      (Purple.Callback)signed_on, null);
+}
+
+}
+


More information about the Commits mailing list