nullclient.py
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 2 Dec 2008 20:13:03 +0000 (20:13 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:09 +0000 (17:11 -0400)
Implementation of a very simple python program which connects to a valid jabber account (gtalk, for example).
You need to connect on WANO and edit nullclient.py adding your email/password.

Signed-off-by: Anderson Briglia <anderson.briglia@indt.org.br>

git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1283 596f6dd7-e928-0410-a184-9e12fd12cf7e

core/connection.pxd
glib.pxd
nullclient.py [new file with mode: 0644]
purple.pyx

index 0504324..48893da 100644 (file)
 #
 
 cdef extern from "libpurple/connection.h":
-    ctypedef struct PurpleConnection:
-        pass
+    cdef struct PurpleConnection
 
-    PurpleAccount* c_purple_connection_get_account "purple_connection_get_account" (PurpleConnection *gc)
+    void connect_to_signals_for_demonstration_purposes_only()
 
-class Connection(object):
+cdef class Connection:
     """ Connection class """
+    cdef PurpleConnection *__conn
 
-    def __init__(self):
-        purple_connection = None
-
-    # FIXME
-    """
-    def purple_connection_get_account(gc):
-        return purple_connection_get_account(gc)
-    """
+    def connect(self):
+        connect_to_signals_for_demonstration_purposes_only()
index 014a177..9b589c5 100644 (file)
--- a/glib.pxd
+++ b/glib.pxd
@@ -22,6 +22,7 @@ cdef extern from "glib.h":
     ctypedef void *gconstpointer
     ctypedef int gint
     ctypedef unsigned int guint
+    ctypedef unsigned long gulong
     ctypedef gint gboolean
     ctypedef gboolean (*GSourceFunc) (gpointer data)
 
diff --git a/nullclient.py b/nullclient.py
new file mode 100644 (file)
index 0000000..375625f
--- /dev/null
@@ -0,0 +1,32 @@
+import purple
+
+class NullClient:
+    def __init__(self):
+        self.p = purple.Purple()
+        self.account = None
+
+    def execute(self):
+        self.p.purple_init()
+
+    def set_protocol(self, protocol):
+        for i in self.p.get_protocols():
+            if i[1] == protocol:
+                print "-- NULLCLIENT --: Choosing %s as protocol" % protocol
+                self.protocol = i[0]
+                print "-- NULLCLIENT --: Protocol successfully chosen: %s" % i[0]
+                return
+
+    def new_account(self, username, protocol, password):
+        self.account = purple.Account(username, protocol)
+        self.account.set_password(password)
+        self.account.set_enabled("carman-purple-python", True)
+
+if __name__ == '__main__':
+
+    client = NullClient()
+    client.execute()
+    client.set_protocol("XMPP")
+    client.new_account("seu_email@email.com", client.protocol,"sua_senha_aqui")
+
+    client.p.connect()
+    client.p.run_loop()
index cde5123..6bf2428 100644 (file)
@@ -78,7 +78,19 @@ cdef extern from "libpurple/eventloop.h":
     void c_purple_eventloop_set_ui_ops "purple_eventloop_set_ui_ops" (PurpleEventLoopUiOps *ops)
 
 cdef extern from "libpurple/plugin.h":
+    ctypedef struct PurplePlugin
+
+    cdef struct _PurplePluginInfo:
+        char *id
+        char *name
+    ctypedef _PurplePluginInfo PurplePluginInfo
+
+    cdef struct _PurplePlugin:
+        PurplePluginInfo *info                # The plugin information.
+    ctypedef _PurplePlugin PurplePlugin
+
     void c_purple_plugins_add_search_path "purple_plugins_add_search_path" (const_char_ptr path)
+    GList *c_purple_plugins_get_protocols "purple_plugins_get_protocols" ()
 
 cdef extern from "libpurple/pounce.h":
     gboolean c_purple_pounces_load "purple_pounces_load" ()
@@ -94,8 +106,9 @@ cdef extern from "libpurple/util.h":
 
 cdef extern from "c_purple.h":
      guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data)
+     void glib_main_loop()
 
-__DEFAULT_PATH__ = "/home/user/MyDocs/Carman"
+__DEFAULT_PATH__ = "/tmp"
 __APP_NAME__ = "carman-purple-python"
 __APP_VERSION__ = "0.1"
 
@@ -209,8 +222,29 @@ cdef class Purple:
 
 # Purple
 
+    def get_protocols(self):
+        cdef GList *iter
+        cdef PurplePlugin *plugin
+        protocols = []
+        iter = c_purple_plugins_get_protocols()
+        while iter:
+            plugin = <PurplePlugin*> iter.data
+            if plugin.info and plugin.info.name:
+                protocols += [(plugin.info.id, plugin.info.name)]
+            iter = iter.next
+        return protocols
+
+    def connect(self):
+        conn = Connection()
+        conn.connect()
+
+    def run_loop(self):
+        glib_main_loop()
+
 include "core/account.pxd"
 include "core/buddy.pxd"
-#include "core/connection.pxd"
+include "glib.pxd"
+#include "core/blist.pxd"
+include "core/connection.pxd"
 #include "core/core.pxd"
 #include "core/idle.pxd"