]> jfr.im git - irc/weechat/qweechat.git/blobdiff - src/qweechat/qweechat.py
Add SSL support
[irc/weechat/qweechat.git] / src / qweechat / qweechat.py
index 8b70b5ff38ad686b99576b448f6bab0ba9dca6fe..265a60453e9a4318212c9f1e894fad9b59d734b9 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
+# Copyright (C) 2011-2012 Sebastien Helleu <flashcode@flashtux.org>
 #
 # This file is part of QWeeChat, a Qt remote GUI for WeeChat.
 #
@@ -35,7 +35,6 @@ QtCore = qt_compat.import_module('QtCore')
 QtGui = qt_compat.import_module('QtGui')
 import config
 import weechat.protocol as protocol
-import weechat.color as color
 from network import Network
 from connection import ConnectionDialog
 from buffer import BufferListWidget, Buffer
@@ -43,7 +42,7 @@ from debug import DebugDialog
 from about import AboutDialog
 
 NAME = 'QWeeChat'
-VERSION = '0.1-dev'
+VERSION = '0.0.1-dev'
 AUTHOR = 'Sébastien Helleu'
 AUTHOR_MAIL= 'flashcode@flashtux.org'
 WEECHAT_SITE = 'http://www.weechat.org/'
@@ -56,7 +55,7 @@ class MainWindow(QtGui.QMainWindow):
     """Main window."""
 
     def __init__(self, *args):
-        apply(QtGui.QMainWindow.__init__, (self,) + args)
+        QtGui.QMainWindow.__init__(*(self,) + args)
 
         self.config = config.read()
 
@@ -99,7 +98,7 @@ class MainWindow(QtGui.QMainWindow):
                        'quit'       : ['application-exit.png', 'Quit application', 'Ctrl+Q', self.close],
                        }
         self.actions = {}
-        for name, action in actions_def.iteritems():
+        for name, action in list(actions_def.items()):
             self.actions[name] = QtGui.QAction(QtGui.QIcon('data/icons/%s' % action[0]), name.capitalize(), self)
             self.actions[name].setStatusTip(action[1])
             self.actions[name].setShortcut(action[2])
@@ -140,6 +139,7 @@ class MainWindow(QtGui.QMainWindow):
         if self.config.getboolean('relay', 'autoconnect'):
             self.network.connect_weechat(self.config.get('relay', 'server'),
                                          self.config.get('relay', 'port'),
+                                         self.config.get('relay', 'ssl') == 'on',
                                          self.config.get('relay', 'password'))
 
         self.show()
@@ -153,7 +153,7 @@ class MainWindow(QtGui.QMainWindow):
         if self.network.is_connected():
             message = 'input %s %s\n' % (full_name, text)
             self.network.send_to_weechat(message)
-            self.debug_display(0, '<==', message, color='red')
+            self.debug_display(0, '<==', message, forcecolor='#AA0000')
 
     def open_preferences_dialog(self):
         pass # TODO
@@ -180,15 +180,15 @@ class MainWindow(QtGui.QMainWindow):
                 text = '(debug_%s)%s' % (text[1:pos], text[pos+1:])
             else:
                 text = '(debug) %s' % text
+            self.debug_display(0, '<==', text, forcecolor='#AA0000')
             self.network.send_to_weechat(text + '\n')
-            self.debug_display(0, '<==', text, color='red')
 
     def debug_dialog_closed(self, result):
         self.debug_dialog = None
 
     def open_about_dialog(self):
         messages = ['<b>%s</b> %s' % (NAME, VERSION),
-                    '&copy; 2011 %s &lt;<a href="mailto:%s">%s</a>&gt;' % (AUTHOR, AUTHOR_MAIL, AUTHOR_MAIL),
+                    '&copy; 2011-2012 %s &lt;<a href="mailto:%s">%s</a>&gt;' % (AUTHOR, AUTHOR_MAIL, AUTHOR_MAIL),
                     '',
                     'WeeChat site: <a href="%s">%s</a>' % (WEECHAT_SITE, WEECHAT_SITE),
                     '']
@@ -196,7 +196,7 @@ class MainWindow(QtGui.QMainWindow):
 
     def open_connection_dialog(self):
         values = {}
-        for option in ('server', 'port', 'password'):
+        for option in ('server', 'port', 'ssl', 'password'):
             values[option] = self.config.get('relay', option)
         self.connection_dialog = ConnectionDialog(values, self)
         self.connection_dialog.dialog_buttons.accepted.connect(self.connect_weechat)
@@ -204,25 +204,27 @@ class MainWindow(QtGui.QMainWindow):
     def connect_weechat(self):
         self.network.connect_weechat(self.connection_dialog.fields['server'].text(),
                                      self.connection_dialog.fields['port'].text(),
+                                     self.connection_dialog.fields['ssl'].isChecked(),
                                      self.connection_dialog.fields['password'].text())
         self.connection_dialog.close()
 
     def network_status_changed(self, status, extra):
         if self.config.getboolean('look', 'statusbar'):
             self.statusBar().showMessage(status)
-        self.debug_display(0, '', status, color='blue')
+        self.debug_display(0, '', status, forcecolor='#0000AA')
         self.network_status_set(status, extra)
 
     def network_status_set(self, status, extra):
         pal = self.network_status.palette()
-        if self.network.is_connected():
+        if status == self.network.status_connected:
             pal.setColor(self.network_status.foregroundRole(), QtGui.QColor('green'))
         else:
             pal.setColor(self.network_status.foregroundRole(), QtGui.QColor('#aa0000'))
+        ssl = ' (SSL)' if status != self.network.status_disconnected and self.network.is_ssl() else ''
         self.network_status.setPalette(pal)
         icon = self.network.status_icon(status)
         if icon:
-            self.network_status.setText('<img src="data/icons/%s"> %s' % (icon, status.capitalize()))
+            self.network_status.setText('<img src="data/icons/%s"> %s' % (icon, status.capitalize() + ssl))
         else:
             self.network_status.setText(status.capitalize())
         if status == self.network.status_disconnected:
@@ -236,17 +238,21 @@ class MainWindow(QtGui.QMainWindow):
         self.debug_display(0, '==>',
                            'message (%d bytes):\n%s'
                            % (len(message), protocol.hex_and_ascii(message, 20)),
-                           color='green')
-        proto = protocol.Protocol()
-        message = proto.decode(str(message))
-        if message.uncompressed:
-            self.debug_display(0, '==>',
-                               'message uncompressed (%d bytes):\n%s'
-                               % (message.size_uncompressed,
-                                  protocol.hex_and_ascii(message.uncompressed, 20)),
-                               color='green')
-        self.debug_display(0, '', 'Message: %s' % message)
-        self.parse_message(message)
+                           forcecolor='#008800')
+        try:
+            proto = protocol.Protocol()
+            message = proto.decode(str(message))
+            if message.uncompressed:
+                self.debug_display(0, '==>',
+                                   'message uncompressed (%d bytes):\n%s'
+                                   % (message.size_uncompressed,
+                                      protocol.hex_and_ascii(message.uncompressed, 20)),
+                                   forcecolor='#008800')
+            self.debug_display(0, '', 'Message: %s' % message)
+            self.parse_message(message)
+        except:
+            print("Error while decoding message from WeeChat")
+            self.network.disconnect_weechat()
 
     def parse_message(self, message):
         if message.msgid.startswith('debug'):
@@ -276,8 +282,8 @@ class MainWindow(QtGui.QMainWindow):
                         index = [i for i, b in enumerate(self.buffers) if b.pointer() == ptrbuf]
                         if index:
                             self.buffers[index[0]].widget.chat.display(item['date'],
-                                                                       color.remove(item['prefix']),
-                                                                       color.remove(item['message']))
+                                                                       item['prefix'],
+                                                                       item['message'])
         elif message.msgid in ('_nicklist', 'nicklist'):
             buffer_nicklist = {}
             for obj in message.objects:
@@ -304,7 +310,9 @@ class MainWindow(QtGui.QMainWindow):
                         index = [i for i, b in enumerate(self.buffers) if b.pointer() == item['__path'][0]]
                         if index:
                             index = index[0]
-                            if message.msgid in ('_buffer_moved', '_buffer_merged'):
+                            if message.msgid == '_buffer_type_changed':
+                                self.buffers[index].data['type'] = item['type']
+                            elif message.msgid in ('_buffer_moved', '_buffer_merged', '_buffer_unmerged'):
                                 buf = self.buffers[index]
                                 buf.data['number'] = item['number']
                                 self.remove_buffer(index)
@@ -315,9 +323,16 @@ class MainWindow(QtGui.QMainWindow):
                                 self.buffers[index].data['short_name'] = item['short_name']
                             elif message.msgid == '_buffer_title_changed':
                                 self.buffers[index].data['title'] = item['title']
-                                self.buffers[index].widget.set_title(item['title'])
+                                self.buffers[index].update_title()
+                            elif message.msgid.startswith('_buffer_localvar_'):
+                                self.buffers[index].data['local_variables'] = item['local_variables']
+                                self.buffers[index].update_prompt()
                             elif message.msgid == '_buffer_closing':
                                 self.remove_buffer(index)
+        elif message.msgid == '_upgrade':
+            self.network.desync_weechat()
+        elif message.msgid == '_upgrade_ended':
+            self.network.sync_weechat()
 
     def create_buffer(self, item):
         buf = Buffer(item)
@@ -361,5 +376,6 @@ class MainWindow(QtGui.QMainWindow):
 
 app = QtGui.QApplication(sys.argv)
 app.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
+app.setWindowIcon(QtGui.QIcon('data/icons/weechat_icon_32.png'))
 main = MainWindow()
 sys.exit(app.exec_())