#!/usr/bin/python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
+# qweechat.py - WeeChat remote GUI using Qt toolkit
+#
+# Copyright (C) 2011-2013 Sebastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
#
#
-# QWeeChat - WeeChat remote GUI using Qt toolkit.
-# (this script requires WeeChat 0.3.7 or newer, running on local or remote host)
+# This script requires WeeChat 0.3.7 or newer, running on local or remote host.
#
# History:
#
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
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/'
"""Main window."""
def __init__(self, *args):
- apply(QtGui.QMainWindow.__init__, (self,) + args)
+ QtGui.QMainWindow.__init__(*(self,) + args)
self.config = config.read()
'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])
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()
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
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),
- '© 2011 %s <<a href="mailto:%s">%s</a>>' % (AUTHOR, AUTHOR_MAIL, AUTHOR_MAIL),
+ '© 2011-2013 %s <<a href="mailto:%s">%s</a>>' % (AUTHOR, AUTHOR_MAIL, AUTHOR_MAIL),
+ '',
+ 'Running with %s' % ('PySide' if qt_compat.uses_pyside else 'PyQt4'),
'',
'WeeChat site: <a href="%s">%s</a>' % (WEECHAT_SITE, WEECHAT_SITE),
'']
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)
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:
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'):
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:
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)
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)