Changeset 9459

Show
Ignore:
Timestamp:
04/11/08 05:52:45 (8 months ago)
Author:
bct
Message:

functioning tic-tac-toe :D

Location:
branches/session_centric
Files:
1 added
5 modified

Legend:

Unmodified
Added
Removed
  • branches/session_centric/data/glade/roster_contact_context_menu.glade

    r8706 r9459  
    9090          </widget> 
    9191        </child> 
     92      </widget> 
     93    </child> 
     94    <child> 
     95      <widget class="GtkImageMenuItem" id="tictactoe_menuitem"> 
     96        <property name="visible">True</property> 
     97        <property name="label" translatable="yes">Play Tic Tac Toe</property> 
     98        <property name="use_underline">True</property> 
    9299      </widget> 
    93100    </child> 
  • branches/session_centric/src/common/connection_handlers.py

    r9447 r9459  
    5151 
    5252# XXX interface leaking into the back end? 
    53 import session 
     53from session import ChatControlSession 
     54import tictactoe 
    5455 
    5556STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', 
     
    769770                                        q.addChild('feature', attrs = {'var': common.xmpp.NS_MOOD + '+notify'}) 
    770771                                q.addChild('feature', attrs = {'var': common.xmpp.NS_ESESSION_INIT}) 
     772                                q.addChild('feature', attrs = {'var': 'http://jabber.org/protocol/games'}) 
    771773 
    772774                        if (node is None or extension == 'cstates') and gajim.config.get('outgoing_chat_state_notifactions') != 'disabled': 
     
    779781                                q.addChild('feature', attrs = {'var': common.xmpp.NS_PING}) 
    780782                                q.addChild('feature', attrs = {'var': common.xmpp.NS_TIME_REVISED}) 
     783 
     784                        if node == 'http://jabber.org/protocol/games': 
     785                                q.addChild('feature', attrs = {'var': 'http://jabber.org/protocol/games/tictactoe'}) 
    781786 
    782787                        if q.getChildren(): 
     
    15391544                        mtype = 'normal' 
    15401545 
    1541                 if not mtype == 'groupchat': 
     1546                game_invite = msg.getTag('invite', namespace='http://jabber.org/protocol/games') 
     1547                if game_invite: 
     1548                        game = game_invite.getTag('game') 
     1549 
     1550                        if game.getAttr('var') == 'http://jabber.org/protocol/games/tictactoe': 
     1551                                klass = tictactoe.TicTacToeSession 
     1552 
     1553                        # this assumes that the invitation came with a thread_id we haven't seen 
     1554                        session = self.make_new_session(frm, thread_id, klass=klass) 
     1555 
     1556                        session.invited(msg) 
     1557 
     1558                        return 
     1559                elif mtype != 'groupchat': 
    15421560                        session = self.get_session(frm, thread_id, mtype) 
    15431561 
     
    15511569 
    15521570                # check if the message is a xep70-confirmation-request 
    1553                 if msg.getTag('confirm') and msg.getTag('confirm').namespace == \ 
    1554                 common.xmpp.NS_HTTP_AUTH: 
     1571                if msg.getTag('confirm', namespace=common.xmpp.NS_HTTP_AUTH): 
    15551572                        self._HttpAuthCB(con, msg) 
    15561573                        return 
    15571574 
    15581575                # check if the message is a XEP 0020 feature negotiation request 
    1559                 if msg.getTag('feature') and msg.getTag('feature').namespace == \ 
    1560                 common.xmpp.NS_FEATURE: 
     1576                if msg.getTag('feature', namespace=common.xmpp.NS_FEATURE): 
    15611577                        if gajim.HAVE_PYCRYPTO: 
    15621578                                self._FeatureNegCB(con, msg, session) 
     
    15641580 
    15651581                # check if the message is initiating an ESession negotiation 
    1566                 if msg.getTag('init') and msg.getTag('init').namespace == \ 
    1567                 common.xmpp.NS_ESESSION_INIT: 
     1582                if msg.getTag('init', namespace=common.xmpp.NS_ESESSION_INIT): 
    15681583                        self._InitE2ECB(con, msg, session) 
    15691584 
    15701585                encrypted = False 
    15711586 
    1572                 e2e_tag = msg.getTag('c', namespace = common.xmpp.NS_STANZA_CRYPTO) 
    1573                 if e2e_tag: 
     1587                if msg.getTag('c', namespace = common.xmpp.NS_STANZA_CRYPTO): 
    15741588                        encrypted = True 
    15751589 
     
    17021716                        mtype = treat_as 
    17031717 
    1704                 session.received(frm, msgtxt, tim, encrypted, mtype, subject, chatstate, 
    1705       msg_id, composing_xep, user_nick, msghtml, form_node) 
     1718                # XXX horrible hack 
     1719                if isinstance(session, ChatControlSession): 
     1720                        session.received(frm, msgtxt, tim, encrypted, mtype, subject, chatstate, 
     1721                                msg_id, composing_xep, user_nick, msghtml, form_node) 
     1722                else: 
     1723                        session.received(msg) 
    17061724        # END messageCB 
    17071725 
    17081726        # process and dispatch an error message 
    1709         def dispatch_error_message(self, msg, msgtxt, session, frm, tim, subject) 
     1727        def dispatch_error_message(self, msg, msgtxt, session, frm, tim, subject): 
    17101728                error_msg = msg.getError() 
    17111729 
     
    17621780                                        self.dispatch('ERROR', (_('Disk Write Error'), str(e))) 
    17631781 
    1764         def dispatch_invite_message(self, invite, frm) 
     1782        def dispatch_invite_message(self, invite, frm): 
    17651783                item = invite.getTag('invite') 
    17661784 
     
    18341852 
    18351853returns the session that we last sent a message to.''' 
    1836                  
     1854 
    18371855                sessions_with_jid = self.sessions[jid].values() 
    18381856                no_threadid_sessions = filter(lambda s: not s.received_thread_id, sessions_with_jid) 
     
    18441862                        return None 
    18451863 
    1846         def make_new_session(self, jid, thread_id = None, type = 'chat'): 
    1847                 sess = session.ChatControlSession(self, common.xmpp.JID(jid), thread_id, type) 
     1864        def make_new_session(self, jid, thread_id=None, type='chat', klass=None): 
     1865                if not klass: 
     1866                        klass = ChatControlSession 
     1867 
     1868                sess = klass(self, common.xmpp.JID(jid), thread_id, type) 
    18481869 
    18491870                if not jid in self.sessions: 
  • branches/session_centric/src/common/stanza_session.py

    r9299 r9459  
    3333                                self.thread_id = self.generate_thread_id() 
    3434 
     35                self.loggable = True 
     36 
    3537                self.last_send = 0 
    3638                self.status = None 
    3739                self.negotiated = {} 
     40 
     41        def is_loggable(self): 
     42                account = self.conn.name 
     43                no_log_for = gajim.config.get_per('accounts', account, 'no_log_for') 
     44 
     45                if not no_log_for: 
     46                        no_log_for = '' 
     47 
     48                no_log_for = no_log_for.split() 
     49 
     50                return self.loggable and account not in no_log_for and self.jid not in no_log_for 
    3851 
    3952        def generate_thread_id(self): 
     
    132145        def __init__(self, conn, jid, thread_id, type = 'chat'): 
    133146                StanzaSession.__init__(self, conn, jid, thread_id, type = 'chat') 
    134  
    135                 self.loggable = True 
    136147 
    137148                self.xes = {} 
     
    892903                self.km_o = '' 
    893904 
    894         def is_loggable(self): 
    895                 account = self.conn.name 
    896                 no_log_for = gajim.config.get_per('accounts', account, 'no_log_for') 
    897  
    898                 if not no_log_for: 
    899                         no_log_for = '' 
    900  
    901                 no_log_for = no_log_for.split() 
    902  
    903                 return self.loggable and account not in no_log_for and self.jid not in no_log_for 
    904  
    905905        def cancelled_negotiation(self): 
    906906                StanzaSession.cancelled_negotiation(self) 
  • branches/session_centric/src/roster_window.py

    r9326 r9459  
    23462346 
    23472347                else: # one resource 
     2348                        tictactoe_menuitem = xml.get_widget( 'tictactoe_menuitem') 
     2349                        tictactoe_menuitem.connect('activate', self.play_tictactoe, contact, account, contact.resource) 
     2350 
    23482351                        start_chat_menuitem.connect('activate', 
    23492352                                self.on_open_chat_window, contact, account) 
     
    42784281                        return True 
    42794282                return False 
     4283 
     4284        def play_tictactoe(self, widget, contact, account, resource=None): 
     4285                jid = contact.jid 
     4286 
     4287                if resource is not None: 
     4288                        jid = jid + u'/' + resource 
     4289 
     4290                import tictactoe 
     4291 
     4292                sess = gajim.connections[account].make_new_session(jid, klass=tictactoe.TicTacToeSession) 
     4293                sess.begin() 
    42804294 
    42814295        def on_execute_command(self, widget, contact, account, resource=None): 
  • branches/session_centric/src/session.py

    r9308 r9459  
    1717                self.control = None 
    1818 
     19        # dispatch a received <message> stanza 
    1920        def received(self, full_jid_with_resource, message, tim, encrypted, msg_type, subject, chatstate, msg_id, composing_xep, user_nick, xhtml, form_node): 
    2021 
     
    115116                                                composing_xep, user_nick, xhtml, form_node])) 
    116117 
     118        # display the message or show notification in the roster 
    117119        def roster_message(self, jid, msg, tim, encrypted=False, msg_type='', 
    118120        subject=None, resource='', msg_id=None, user_nick='',