X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=nullclient.py;h=8386d7c90f8a856c837227a91a590b50325a7b43;hb=refs%2Fheads%2Fmaster;hp=c9e1953223f1473f4f5c724638d576078fe93e06;hpb=7875a5e5e9f90b84fb2893adb2ac779f61e85668;p=python-purple diff --git a/nullclient.py b/nullclient.py index c9e1953..8386d7c 100644 --- a/nullclient.py +++ b/nullclient.py @@ -1,45 +1,72 @@ -import purple -import ecore +# +# 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 . +# + import getpass -import sys +import sys, dl +import time + +sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL) + +import purple + +# The information below is needed by libpurple +__NAME__ = "nullclient" +__VERSION__ = "0.1" +__WEBSITE__ = "N/A" +__DEV_WEBSITE__ = "N/A" -class NullClient: - def __init__(self): - self.p = purple.Purple() - 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): - self.p.purple_init() + # 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) + # 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() - ecore.main_loop_begin() + while True: + try: + core.iterate_main_loop() + time.sleep(0.01) + except KeyboardInterrupt: + core.destroy() + break