-import purple
+#
+# Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
+#
+# This file is part of python-purple.
+#
+# python-purple 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 3 of the License, or
+# (at your option) any later version.
+#
+# python-purple 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, see <http://www.gnu.org/licenses/>.
+#
+
import ecore
import getpass
+import purple
import sys
-cbs = {}
-acc_cbs = {}
-blist_cbs = {}
-conn_cbs = {}
-conv_cbs = {}
-notify_cbs = {}
-request_cbs = {}
-signal_cbs = {}
-
-def account_callback(name):
- print "---- account callback example: %s" % name
-
-acc_cbs["notify_added"] = account_callback
-acc_cbs["status_changed"] = account_callback
-acc_cbs["request_add"] = account_callback
-acc_cbs["request_authorize"] = account_callback
-acc_cbs["close_account_request"] = account_callback
-
-cbs["account"] = acc_cbs
-
-def blist_callback(name):
- print "---- blist callback example: %s" % name
-
-blist_cbs["new_list"] = blist_callback
-blist_cbs["new_node"] = blist_callback
-blist_cbs["show"] = blist_callback
-blist_cbs["update"] = blist_callback
-blist_cbs["remove"] = blist_callback
-blist_cbs["destroy"] = blist_callback
-blist_cbs["set_visible"] = blist_callback
-blist_cbs["request_add_buddy"] = blist_callback
-blist_cbs["request_add_chat"] = blist_callback
-blist_cbs["request_add_group"] = blist_callback
-
-cbs["blist"] = blist_cbs
-
-def conn_callback(name):
- print "---- connection callback example: %s" % name
-
-conn_cbs["connect_progress"] = conn_callback
-conn_cbs["connected"] = conn_callback
-conn_cbs["disconnected"] = conn_callback
-conn_cbs["notice"] = conn_callback
-conn_cbs["report_disconnect"] = conn_callback
-conn_cbs["network_connected"] = conn_callback
-conn_cbs["network_disconnected"] = conn_callback
-conn_cbs["report_disconnect_reason"] = conn_callback
-
-cbs["connection"] = conn_cbs
-
-def conv_callback(name):
- print "---- conversation callback example: %s" % name
+# The information below is needed by libpurple
+__NAME__ = "nullclient"
+__VERSION__ = "0.1"
+__WEBSITE__ = "N/A"
+__DEV_WEBSITE__ = "N/A"
-conv_cbs["create_conversation"] = conv_callback
-conv_cbs["destroy_conversation"] = conv_callback
-conv_cbs["write_chat"] = conv_callback
-conv_cbs["write_im"] = conv_callback
-conv_cbs["write_conv"] = conv_callback
-conv_cbs["chat_add_users"] = conv_callback
-conv_cbs["chat_rename_user"] = conv_callback
-conv_cbs["chat_remove_users"] = conv_callback
-conv_cbs["chat_update_user"] = conv_callback
-conv_cbs["present"] = conv_callback
-conv_cbs["has_focus"] = conv_callback
-conv_cbs["custom_smiley_add"] = conv_callback
-conv_cbs["custom_smiley_write"] = conv_callback
-conv_cbs["custom_smiley_close"] = conv_callback
-conv_cbs["send_confirm"] = conv_callback
-
-cbs["conversation"] = conv_cbs
-
-def notify_callback(name):
- print "---- notify callback example: %s" % name
-
-notify_cbs["notify_message"] = notify_callback
-notify_cbs["notify_email"] = notify_callback
-notify_cbs["notify_emails"] = notify_callback
-notify_cbs["notify_formatted"] = notify_callback
-notify_cbs["notify_searchresults"] = notify_callback
-notify_cbs["notify_searchresults_new_rows"] = notify_callback
-notify_cbs["notify_userinfo"] = notify_callback
-notify_cbs["notify_uri"] = notify_callback
-notify_cbs["close_notify"] = notify_callback
-
-cbs["notify"] = notify_cbs
-
-def request_callback(name):
- print "---- request callback example: %s" % name
-
-request_cbs["request_input"] = request_callback
-request_cbs["request_choice"] = request_callback
-request_cbs["request_action"] = request_callback
-request_cbs["request_fields"] = request_callback
-request_cbs["request_file"] = request_callback
-request_cbs["close_request"] = request_callback
-request_cbs["request_folder"] = request_callback
-
-cbs["request"] = request_cbs
-
-def buddy_signed_off_cb(name):
- print "---- sign off from buddy %s" % name
-
-def receiving_im_msg_cb(sender, name, message):
- print "---- receiving IM message from %s: %s" % (name, message)
- return False
-
-signal_cbs["buddy_signed_off"] = buddy_signed_off_cb
-signal_cbs["receiving_im_msg"] = receiving_im_msg_cb
-
-class NullClient:
- def __init__(self):
- self.p = purple.Purple(debug_enabled=False)
- self.account = None
+if __name__ == '__main__':
+ # Sets initial parameters
+ core = purple.Purple(__NAME__, __VERSION__, __WEBSITE__, __DEV_WEBSITE__, \
+ debug_enabled=True, default_path="/tmp")
- def execute(self):
- global cbs
- self.p.purple_init(cbs)
+ # Initializes libpurple
+ core.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
+ # Get username from user
+ sys.stdout.write("Enter GTalk account: ")
+ username = sys.stdin.readline()[:-1]
- 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)
- def get_buddies(self):
- buddies = self.account.get_buddies_online()
- print buddies
+ # Initialize protocol class
+ protocol = purple.Protocol('prpl-jabber')
-def getuser():
- sys.stdout.write("GTalk account: ")
- username = sys.stdin.readline()
- return username[:-1]
+ # Creates new account inside libpurple
+ account = purple.Account(username, protocol, core)
+ account.new()
-def getpassword():
- return getpass.getpass()
+ # Get password from user
+ account.set_password(getpass.getpass())
-if __name__ == '__main__':
+ # Set account protocol options
+ info = {}
+ info['connect_server'] = 'talk.google.com'
+ info['port'] = '443'
+ info['old_ssl'] = True
+ account.set_protocol_options(info)
- client = NullClient()
- client.execute()
- client.set_protocol("XMPP")
- username = getuser()
- password = getpassword()
- client.new_account(username, client.protocol, password)
+ # Enable account (connects automatically)
+ account.set_enabled(True)
- client.p.connect()
- client.p.attach_signals(signal_cbs)
- ecore.timer_add(20, client.get_buddies)
+ # Initializes ecore mainloop
ecore.main_loop_begin()