From f16f567d128dd99fd23f908fe090dc3d265aad90 Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Sun, 19 May 2013 16:36:02 +0100 Subject: [PATCH 1/4] hacinh away --- .gitignore | 5 + pytalk/ConnectionDialog.py | 3 +- pytalk/ConnectorThread.py | 16 +- pytalk/__init__.py | 7 + pytalk/pytalk.py | 363 +++++++++++++++++-------------- pytalk/ui/ConnectionDialog.py | 134 ++++++++++++ pytalk/ui/MainWindow.py | 145 ++++++++++++ pytalk/ui/ui_ConnectionDialog.py | 2 +- 8 files changed, 500 insertions(+), 175 deletions(-) create mode 100644 .gitignore mode change 100644 => 100755 pytalk/pytalk.py create mode 100644 pytalk/ui/ConnectionDialog.py create mode 100644 pytalk/ui/MainWindow.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..65f4f5c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.pyc +.project +.pydevproject + + diff --git a/pytalk/ConnectionDialog.py b/pytalk/ConnectionDialog.py index ae7c9d7..da20483 100644 --- a/pytalk/ConnectionDialog.py +++ b/pytalk/ConnectionDialog.py @@ -2,7 +2,8 @@ from PyQt4.QtCore import QSettings, QVariant, SIGNAL from ui.ui_ConnectionDialog import Ui_ConnectionDialog -class ConnectionDialog(QDialog, Ui_ConnectionDialog): + +class DEADConnectionDialog(QDialog, Ui_ConnectionDialog): def __init__(self, parent): QDialog.__init__(self, parent) self.setupUi(self) diff --git a/pytalk/ConnectorThread.py b/pytalk/ConnectorThread.py index 3fa4e2f..7af57aa 100644 --- a/pytalk/ConnectorThread.py +++ b/pytalk/ConnectorThread.py @@ -1,5 +1,7 @@ +# -*- coding: utf-8 -*- + +import xmpp import time -import xmpp import sys import settings import platform @@ -45,8 +47,8 @@ def connect(self): self.port = settings.value("port", QVariant("5223")).toInt() else: self.port = settings.value("port", QVariant("5222")).toInt() - - self.port = int(self.port[0]) + + self.port = int(self.port[0]) self.ressource = settings.value("ressource", QVariant("PyTalk")).toString().__str__() @@ -54,10 +56,10 @@ def connect(self): self.jid = xmpp.protocol.JID(self.userID.__str__()) self.jabber = xmpp.Client(self.jid.getDomain(), debug=[]) - - if self.server: - server = (self.server, self.port) - else: + + if self.server: + server = (self.server, self.port) + else: server = None connection = self.jabber.connect(server) diff --git a/pytalk/__init__.py b/pytalk/__init__.py index e69de29..7fd094c 100644 --- a/pytalk/__init__.py +++ b/pytalk/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +import os, sys +PROJECT_ROOT = os.path.abspath( os.path.dirname( __file__ ) + '/../' ) + + +print "===DDDDDd=====", PROJECT_ROOT \ No newline at end of file diff --git a/pytalk/pytalk.py b/pytalk/pytalk.py old mode 100644 new mode 100755 index 7e8c998..4bd54fd --- a/pytalk/pytalk.py +++ b/pytalk/pytalk.py @@ -1,12 +1,32 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -import sys, datetime + +import sys, os +ROOT = os.path.abspath( os.path.dirname( __file__ ) + '/../' ) +""" +print "===========", project_path +if not project_path in sys.path: + sys.path.append(project_path) +""" + +inc_paths = ["enum-0.4.3", "pydns-2.3.1", "xmpppy-CVS20080120"] + +for ip in inc_paths: + p = ROOT + "/deps/" + ip + print p + if not p in sys.path: + sys.path.insert(0, p) + + + +import datetime + from PyQt4.QtGui import * -from PyQt4.QtCore import SIGNAL, SLOT, Qt, QSize +from PyQt4.QtCore import SIGNAL, SLOT, Qt, QSize, QTimer from ui.ui_mainwindow import Ui_MainWindow from AboutDialog import AboutDialog -from ConnectionDialog import ConnectionDialog +from ui.ConnectionDialog import ConnectionDialog from ConnectorThread import ConnectorThread from MessageBox import MessageBox from BuddyList import BuddyList @@ -16,169 +36,180 @@ from jabber import STATUS + + class MainWindow(QMainWindow, Ui_MainWindow): - connectorThread = None - - def __init__(self, parent = None): - - QMainWindow.__init__(self, parent) - self.setupUi(self) - - self.console = QDialog() - self.te = QTextEdit(self.console) - self.te.setReadOnly(True) - vl = QVBoxLayout() - vl.addWidget(self.te) - self.console.setLayout(vl) - - # Set status Offline - self.statusBox.setCurrentIndex(5) - self.statusEdit.hide() - - # Set connect - self.connect(self.statusBox, SIGNAL("currentIndexChanged(int)"), self.changeStatus) - self.connect(self.statusEdit, SIGNAL("returnPressed()"), self.changeStatus) - - # Set BuddyList - self.BuddyList = BuddyList(self) - self.vboxlayout.insertWidget(0, self.BuddyList) - self.connect(self.BuddyList, SIGNAL("rename"), self.addBuddy) - - # Connection - connection = ConnectionDialog(self) - self.connect(self.actionConnection, SIGNAL("triggered()"), connection, SLOT("exec()")) - self.connect(self.actionDeconnection, SIGNAL("triggered()"), self.disconnect) - self.connect(connection, SIGNAL("configured()"), self.connection) - - # Contacts - self.connect(self.actionAdd_a_buddy, SIGNAL("triggered()"), self.addBuddy) - self.connect(self.actionAdd_a_group, SIGNAL("triggered()"), self.addGroup) - - # View - self.connect(self.actionAway_buddies, SIGNAL("toogled()"), self.setAway) - self.connect(self.actionOffline_buddies, SIGNAL("toogled()"), self.setOffline) - self.connect(self.actionAway_buddies, SIGNAL("triggered()"), self.setAway) - self.connect(self.actionOffline_buddies, SIGNAL("triggered()"), self.setOffline) - - # Tools - self.connect(self.actionConsole, SIGNAL("triggered()"), self.swapConsole) - - # About Dialog - about = AboutDialog(self) - self.connect(self.actionAbout, SIGNAL("triggered()"), about, SLOT("exec()")) - self.connect(self.actionAboutQt, SIGNAL("triggered()"), QApplication.instance(), SLOT("aboutQt()")) - - # Quit Signal connection - self.connect(self.actionQuit, SIGNAL("triggered()"), self.quit) - - def connection(self, status=STATUS.available): - if not self.connectorThread: - self.connectorThread = ConnectorThread(status) - self.connectorThread.start() - self.connect(self.connectorThread, SIGNAL("message"), self.BuddyList.message) - self.connect(self.connectorThread, SIGNAL("error"), self.error) - self.connect(self.connectorThread, SIGNAL("connected()"), self.connected) - self.connect(self.connectorThread, SIGNAL("disconnected()"), self.disconnect) - self.connect(self.connectorThread, SIGNAL("presence"), self.BuddyList.presence) - self.connect(self.connectorThread, SIGNAL("debug"), self.debug) - self.connect(self.connectorThread, SIGNAL("subscriptionRequest"), self.subscriptionRequest) - self.connect(self.connectorThread, SIGNAL("addBuddy"), self.addBuddy) - elif self.connectorThread.isConnected(): - self.connectorThread.changeStatus(status, self.statusEdit.text()) - self.statusEdit.clearFocus() - - def disconnect(self): - self.actionConnection.setEnabled(True) - self.actionDeconnection.setEnabled(False) - self.statusEdit.hide() - self.statusBox.setCurrentIndex(STATUS.unavailable.index) - if self.connectorThread: - self.connectorThread.disconnect() - self.connectorThread = None - self.BuddyList.clear() - QApplication.instance().quit() - - - def connected(self): - self.actionConnection.setEnabled(False) - self.actionDeconnection.setEnabled(True) - if self.statusBox.currentIndex() == STATUS.unavailable.index: - self.statusBox.setCurrentIndex(STATUS.available.index) - else: - self.connectorThread.changeStatus(self.statusBox.currentIndex(), self.statusEdit.text()) - self.statusEdit.show() - self.statusEdit.setFocus() - self.BuddyList.setConnection(self.connectorThread) - self.getRoster() - self.setAway() - self.setOffline() - - def error(self, title, content): - QMessageBox.critical(self, title, content, QMessageBox.Ok) - - def closeEvent(self, event): - self.quit() - - def quit(self): - self.disconnect() - - def changeStatus(self, index=-1): - if index == -1: - index = self.statusBox.currentIndex() - if index == STATUS.unavailable.index: - self.statusEdit.hide() - self.disconnect() - else: - self.connection(index) - - def getRoster(self): - roster = self.connectorThread.getRoster() - for buddy in roster: - self.BuddyList.addItem(buddy) - self.connect(self.BuddyList, SIGNAL("itemDoubleClicked(QTreeWidgetItem *,int)"), self.sendMessage) - - def sendMessage(self, item, col): - if item and item.type() == QTreeWidgetItem.UserType+1: - item.sendMessage() - - def setAway(self, checked=-1): - if checked == -1: - checked = self.actionAway_buddies.isChecked() - self.BuddyList.setAway(not checked) - - def setOffline(self, checked=-1): - if checked == -1: - checked = self.actionOffline_buddies.isChecked() - self.BuddyList.setOffline(not checked) - - def subscriptionRequest(self, presence): - request = RosterRequest(self, self.connectorThread.jabber, presence) - request.show() - - def debug(self, message): - self.te.append(datetime.datetime.now().strftime("[%H:%M:%S]")+" : \n"+message) - - def swapConsole(self): - self.console.setWindowTitle("XML Console") - self.console.resize(QSize(1024, 500)) - self.console.show() - self.console.raise_() - - def addBuddy(self, item=None): - if self.connectorThread: - if item: - jid = item.jid - else: - jid = "" - newBuddy = AddBuddyDialog(self, self.connectorThread.jabber, self.BuddyList.groups.keys(), jid) - newBuddy.show() - - def addGroup(self): - newGroup = AddGroupDialog(self, self.BuddyList) - newGroup.show() + connectorThread = None + + def __init__(self, parent = None): + + QMainWindow.__init__(self, parent) + self.setupUi(self) + + self.console = QDialog() + self.te = QTextEdit(self.console) + self.te.setReadOnly(True) + vl = QVBoxLayout() + vl.addWidget(self.te) + self.console.setLayout(vl) + + # Set status Offline + self.statusBox.setCurrentIndex(5) + self.statusEdit.hide() + + # Set connect + self.connect(self.statusBox, SIGNAL("currentIndexChanged(int)"), self.changeStatus) + self.connect(self.statusEdit, SIGNAL("returnPressed()"), self.changeStatus) + + # Set BuddyList + self.BuddyList = BuddyList(self) + self.vboxlayout.insertWidget(0, self.BuddyList) + self.connect(self.BuddyList, SIGNAL("rename"), self.addBuddy) + + # Connection + """ + connection = ConnectionDialog(self) + self.connect(self.actionConnection, SIGNAL("triggered()"), connection, SLOT("exec()")) + self.connect(self.actionDeconnection, SIGNAL("triggered()"), self.disconnect) + self.connect(connection, SIGNAL("configured()"), self.on_connection) + """ + # Contacts + self.connect(self.actionAdd_a_buddy, SIGNAL("triggered()"), self.addBuddy) + self.connect(self.actionAdd_a_group, SIGNAL("triggered()"), self.addGroup) + + # View + self.connect(self.actionAway_buddies, SIGNAL("toogled()"), self.setAway) + self.connect(self.actionOffline_buddies, SIGNAL("toogled()"), self.setOffline) + self.connect(self.actionAway_buddies, SIGNAL("triggered()"), self.setAway) + self.connect(self.actionOffline_buddies, SIGNAL("triggered()"), self.setOffline) + + # Tools + self.connect(self.actionConsole, SIGNAL("triggered()"), self.swapConsole) + + # About Dialog + about = AboutDialog(self) + self.connect(self.actionAbout, SIGNAL("triggered()"), about, SLOT("exec()")) + self.connect(self.actionAboutQt, SIGNAL("triggered()"), QApplication.instance(), SLOT("aboutQt()")) + + # Quit Signal connection + self.connect(self.actionQuit, SIGNAL("triggered()"), self.quit) + + QTimer.singleShot(500, self.show_connection_dialog) + + def show_connection_dialog(self): + d = ConnectionDialog() + d.exec_() + + + def on_connection(self, status=STATUS.available): + if not self.connectorThread: + self.connectorThread = ConnectorThread(status) + self.connectorThread.start() + self.connect(self.connectorThread, SIGNAL("message"), self.BuddyList.message) + self.connect(self.connectorThread, SIGNAL("error"), self.error) + self.connect(self.connectorThread, SIGNAL("connected()"), self.connected) + self.connect(self.connectorThread, SIGNAL("disconnected()"), self.disconnect) + self.connect(self.connectorThread, SIGNAL("presence"), self.BuddyList.presence) + self.connect(self.connectorThread, SIGNAL("debug"), self.debug) + self.connect(self.connectorThread, SIGNAL("subscriptionRequest"), self.subscriptionRequest) + self.connect(self.connectorThread, SIGNAL("addBuddy"), self.addBuddy) + elif self.connectorThread.isConnected(): + self.connectorThread.changeStatus(status, self.statusEdit.text()) + self.statusEdit.clearFocus() + + def disconnect(self): + self.actionConnection.setEnabled(True) + self.actionDeconnection.setEnabled(False) + self.statusEdit.hide() + self.statusBox.setCurrentIndex(STATUS.unavailable.index) + if self.connectorThread: + self.connectorThread.disconnect() + self.connectorThread = None + self.BuddyList.clear() + QApplication.instance().quit() + + + def connected(self): + self.actionConnection.setEnabled(False) + self.actionDeconnection.setEnabled(True) + if self.statusBox.currentIndex() == STATUS.unavailable.index: + self.statusBox.setCurrentIndex(STATUS.available.index) + else: + self.connectorThread.changeStatus(self.statusBox.currentIndex(), self.statusEdit.text()) + self.statusEdit.show() + self.statusEdit.setFocus() + self.BuddyList.setConnection(self.connectorThread) + self.getRoster() + self.setAway() + self.setOffline() + + def error(self, title, content): + QMessageBox.critical(self, title, content, QMessageBox.Ok) + + def closeEvent(self, event): + self.quit() + + def quit(self): + self.disconnect() + sys.exit(0) + + def changeStatus(self, index=-1): + if index == -1: + index = self.statusBox.currentIndex() + if index == STATUS.unavailable.index: + self.statusEdit.hide() + self.disconnect() + else: + self.connection(index) + + def getRoster(self): + roster = self.connectorThread.getRoster() + for buddy in roster: + self.BuddyList.addItem(buddy) + self.connect(self.BuddyList, SIGNAL("itemDoubleClicked(QTreeWidgetItem *,int)"), self.sendMessage) + + def sendMessage(self, item, col): + if item and item.type() == QTreeWidgetItem.UserType+1: + item.sendMessage() + + def setAway(self, checked=-1): + if checked == -1: + checked = self.actionAway_buddies.isChecked() + self.BuddyList.setAway(not checked) + + def setOffline(self, checked=-1): + if checked == -1: + checked = self.actionOffline_buddies.isChecked() + self.BuddyList.setOffline(not checked) + + def subscriptionRequest(self, presence): + request = RosterRequest(self, self.connectorThread.jabber, presence) + request.show() + + def debug(self, message): + self.te.append(datetime.datetime.now().strftime("[%H:%M:%S]")+" : \n"+message) + + def swapConsole(self): + self.console.setWindowTitle("XML Console") + self.console.resize(QSize(1024, 500)) + self.console.show() + self.console.raise_() + + def addBuddy(self, item=None): + if self.connectorThread: + if item: + jid = item.jid + else: + jid = "" + newBuddy = AddBuddyDialog(self, self.connectorThread.jabber, self.BuddyList.groups.keys(), jid) + newBuddy.show() + + def addGroup(self): + newGroup = AddGroupDialog(self, self.BuddyList) + newGroup.show() if __name__ == "__main__": - app = QApplication(sys.argv) - window = MainWindow() - window.show() - sys.exit(app.exec_()) + app = QApplication(sys.argv) + window = MainWindow() + window.show() + sys.exit(app.exec_()) diff --git a/pytalk/ui/ConnectionDialog.py b/pytalk/ui/ConnectionDialog.py new file mode 100644 index 0000000..a0a21dc --- /dev/null +++ b/pytalk/ui/ConnectionDialog.py @@ -0,0 +1,134 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'ui_ConnectionDialog.ui' +# +# Created: Sun Jan 20 13:55:46 2008 +# by: PyQt4 UI code generator 4.3.1 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +class ConnectionDialog(QtGui.QDialog): + + def __init__(self, parent=None): + QtGui.QDialog.__init__(parent) + + #self.setObjectName("ConnectionDialog") + #ConnectionDialog.resize(QtCore.QSize(QtCore.QRect(0,0,289,277).size()).expandedTo(ConnectionDialog.minimumSizeHint())) + + self.vboxlayout = QtGui.QVBoxLayout(self) + self.vboxlayout.setObjectName("vboxlayout") + + self.groupBox = QtGui.QGroupBox(ConnectionDialog) + self.groupBox.setObjectName("groupBox") + + self.gridlayout = QtGui.QGridLayout(self.groupBox) + self.gridlayout.setObjectName("gridlayout") + + self.label = QtGui.QLabel(self.groupBox) + self.label.setObjectName("label") + self.gridlayout.addWidget(self.label,0,0,1,1) + + self.userID = QtGui.QLineEdit(self.groupBox) + self.userID.setObjectName("userID") + self.gridlayout.addWidget(self.userID,0,1,1,1) + + self.label_2 = QtGui.QLabel(self.groupBox) + self.label_2.setObjectName("label_2") + self.gridlayout.addWidget(self.label_2,1,0,1,1) + + self.password = QtGui.QLineEdit(self.groupBox) + self.password.setEchoMode(QtGui.QLineEdit.Password) + self.password.setObjectName("password") + self.gridlayout.addWidget(self.password,1,1,1,1) + self.vboxlayout.addWidget(self.groupBox) + + self.groupBox_2 = QtGui.QGroupBox(ConnectionDialog) + self.groupBox_2.setObjectName("groupBox_2") + + self.gridlayout1 = QtGui.QGridLayout(self.groupBox_2) + self.gridlayout1.setObjectName("gridlayout1") + + self.label_3 = QtGui.QLabel(self.groupBox_2) + self.label_3.setObjectName("label_3") + self.gridlayout1.addWidget(self.label_3,0,0,1,1) + + self.server = QtGui.QLineEdit(self.groupBox_2) + self.server.setObjectName("server") + self.gridlayout1.addWidget(self.server,0,1,1,2) + + self.label_4 = QtGui.QLabel(self.groupBox_2) + self.label_4.setObjectName("label_4") + self.gridlayout1.addWidget(self.label_4,1,0,1,1) + + self.port = QtGui.QLineEdit(self.groupBox_2) + self.port.setObjectName("port") + self.gridlayout1.addWidget(self.port,1,1,1,1) + + self.label_5 = QtGui.QLabel(self.groupBox_2) + self.label_5.setObjectName("label_5") + self.gridlayout1.addWidget(self.label_5,2,0,1,1) + + self.ressource = QtGui.QLineEdit(self.groupBox_2) + self.ressource.setObjectName("ressource") + self.gridlayout1.addWidget(self.ressource,2,1,1,2) + + self.useSSL = QtGui.QCheckBox(self.groupBox_2) + self.useSSL.setObjectName("useSSL") + self.gridlayout1.addWidget(self.useSSL,1,2,1,1) + self.vboxlayout.addWidget(self.groupBox_2) + + self.buttonBox = QtGui.QDialogButtonBox(ConnectionDialog) + self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Ok) + self.buttonBox.setObjectName("buttonBox") + self.vboxlayout.addWidget(self.buttonBox) + + self.retranslateUi(ConnectionDialog) + QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("accepted()"),ConnectionDialog.accept) + QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),ConnectionDialog.reject) + QtCore.QMetaObject.connectSlotsByName(ConnectionDialog) + self.connect(self, SIGNAL("accepted()"), self.saveSettings) + self.readSettings() + + def readSettings(self): + settings = QSettings("Trunat", "PyTalk") + settings.beginGroup("Connection") + self.userID.setText(settings.value("userID").toString()) + self.password.setText(settings.value("password").toString()) + self.server.setText(settings.value("server").toString()) + self.useSSL.setChecked(settings.value("useSSL", QVariant(True)).toBool()) + + if self.useSSL.isChecked(): + self.port.setText(settings.value("port", QVariant("5223")).toString()) + else: + self.port.setText(settings.value("port", QVariant("5222")).toString()) + + self.ressource.setText(settings.value("ressource", QVariant("PyTalk")).toString()) + settings.endGroup() + + def saveSettings(self): + settings = QSettings("Trunat", "PyTalk") + settings.beginGroup("Connection") + settings.setValue("userID", QVariant(self.userID.text())) + settings.setValue("password", QVariant(self.password.text())) + settings.setValue("server", QVariant(self.server.text())) + settings.setValue("port", QVariant(int(self.port.text()))) + settings.setValue("ressource", QVariant(self.ressource.text())) + settings.setValue("useSSL", QVariant(self.useSSL.isChecked())) + settings.endGroup() + self.emit(SIGNAL("configured()")) + + def setranslateUi(self, ConnectionDialog): + ConnectionDialog.setWindowTitle(QtGui.QApplication.translate("ConnectionDialog", "Connection Dialog", None, QtGui.QApplication.UnicodeUTF8)) + self.groupBox.setTitle(QtGui.QApplication.translate("ConnectionDialog", "Login\'s informations", None, QtGui.QApplication.UnicodeUTF8)) + self.label.setText(QtGui.QApplication.translate("ConnectionDialog", "Jabber ID:", None, QtGui.QApplication.UnicodeUTF8)) + self.label_2.setText(QtGui.QApplication.translate("ConnectionDialog", "Password:", None, QtGui.QApplication.UnicodeUTF8)) + self.groupBox_2.setTitle(QtGui.QApplication.translate("ConnectionDialog", "Server's informations", None, QtGui.QApplication.UnicodeUTF8)) + self.label_3.setText(QtGui.QApplication.translate("ConnectionDialog", "Server:", None, QtGui.QApplication.UnicodeUTF8)) + self.label_4.setText(QtGui.QApplication.translate("ConnectionDialog", "Port:", None, QtGui.QApplication.UnicodeUTF8)) + self.label_5.setText(QtGui.QApplication.translate("ConnectionDialog", "Ressource:", None, QtGui.QApplication.UnicodeUTF8)) + self.ressource.setText(QtGui.QApplication.translate("ConnectionDialog", "PyTalk", None, QtGui.QApplication.UnicodeUTF8)) + self.useSSL.setText(QtGui.QApplication.translate("ConnectionDialog", "Using SSL", None, QtGui.QApplication.UnicodeUTF8)) + diff --git a/pytalk/ui/MainWindow.py b/pytalk/ui/MainWindow.py new file mode 100644 index 0000000..693cfd3 --- /dev/null +++ b/pytalk/ui/MainWindow.py @@ -0,0 +1,145 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'ui_mainwindow.ui' +# +# Created: Thu Jan 24 11:09:31 2008 +# by: PyQt4 UI code generator 4.3.1 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,316,407).size()).expandedTo(MainWindow.minimumSizeHint())) + MainWindow.setWindowIcon(QtGui.QIcon("images/im-jabber.png")) + MainWindow.setUnifiedTitleAndToolBarOnMac(False) + + self.centralwidget = QtGui.QWidget(MainWindow) + self.centralwidget.setObjectName("centralwidget") + + self.vboxlayout = QtGui.QVBoxLayout(self.centralwidget) + self.vboxlayout.setObjectName("vboxlayout") + + self.statusBox = QtGui.QComboBox(self.centralwidget) + self.statusBox.setObjectName("statusBox") + self.vboxlayout.addWidget(self.statusBox) + + self.statusEdit = QtGui.QLineEdit(self.centralwidget) + self.statusEdit.setObjectName("statusEdit") + self.vboxlayout.addWidget(self.statusEdit) + MainWindow.setCentralWidget(self.centralwidget) + + self.menubar = QtGui.QMenuBar(MainWindow) + self.menubar.setGeometry(QtCore.QRect(0,0,316,29)) + self.menubar.setObjectName("menubar") + + self.menuContacts = QtGui.QMenu(self.menubar) + self.menuContacts.setObjectName("menuContacts") + + self.menuAffichage = QtGui.QMenu(self.menubar) + self.menuAffichage.setObjectName("menuAffichage") + + self.menuHelp = QtGui.QMenu(self.menubar) + self.menuHelp.setObjectName("menuHelp") + + self.menuBuddies = QtGui.QMenu(self.menubar) + self.menuBuddies.setObjectName("menuBuddies") + + self.menuTools = QtGui.QMenu(self.menubar) + self.menuTools.setObjectName("menuTools") + MainWindow.setMenuBar(self.menubar) + + self.actionConnection = QtGui.QAction(MainWindow) + self.actionConnection.setIcon(QtGui.QIcon("images/status/log-in.png")) + self.actionConnection.setObjectName("actionConnection") + + self.actionDeconnection = QtGui.QAction(MainWindow) + self.actionDeconnection.setEnabled(False) + self.actionDeconnection.setIcon(QtGui.QIcon("images/status/log-out.png")) + self.actionDeconnection.setObjectName("actionDeconnection") + + self.actionOffline_buddies = QtGui.QAction(MainWindow) + self.actionOffline_buddies.setCheckable(True) + self.actionOffline_buddies.setObjectName("actionOffline_buddies") + + self.actionAway_buddies = QtGui.QAction(MainWindow) + self.actionAway_buddies.setCheckable(True) + self.actionAway_buddies.setChecked(True) + self.actionAway_buddies.setObjectName("actionAway_buddies") + + self.actionAbout = QtGui.QAction(MainWindow) + self.actionAbout.setIcon(QtGui.QIcon("images/about.png")) + self.actionAbout.setObjectName("actionAbout") + + self.actionAboutQt = QtGui.QAction(MainWindow) + self.actionAboutQt.setIcon(QtGui.QIcon("images/qt4.png")) + self.actionAboutQt.setObjectName("actionAboutQt") + + self.actionQuit = QtGui.QAction(MainWindow) + self.actionQuit.setIcon(QtGui.QIcon("images/exit.png")) + self.actionQuit.setObjectName("actionQuit") + + self.actionAdd_a_buddy = QtGui.QAction(MainWindow) + self.actionAdd_a_buddy.setIcon(QtGui.QIcon("images/plus.png")) + self.actionAdd_a_buddy.setObjectName("actionAdd_a_buddy") + + self.actionAdd_a_group = QtGui.QAction(MainWindow) + self.actionAdd_a_group.setIcon(QtGui.QIcon("images/plus.png")) + self.actionAdd_a_group.setObjectName("actionAdd_a_group") + + self.actionPreferences = QtGui.QAction(MainWindow) + self.actionPreferences.setIcon(QtGui.QIcon("images/preferences.png")) + self.actionPreferences.setObjectName("actionPreferences") + + self.actionConsole = QtGui.QAction(MainWindow) + self.actionConsole.setObjectName("actionConsole") + self.menuContacts.addAction(self.actionConnection) + self.menuContacts.addAction(self.actionDeconnection) + self.menuContacts.addAction(self.actionQuit) + self.menuAffichage.addAction(self.actionOffline_buddies) + self.menuAffichage.addAction(self.actionAway_buddies) + self.menuHelp.addAction(self.actionAbout) + self.menuHelp.addAction(self.actionAboutQt) + self.menuBuddies.addAction(self.actionAdd_a_buddy) + self.menuBuddies.addAction(self.actionAdd_a_group) + self.menuTools.addAction(self.actionPreferences) + self.menuTools.addAction(self.actionConsole) + self.menubar.addAction(self.menuContacts.menuAction()) + self.menubar.addAction(self.menuBuddies.menuAction()) + self.menubar.addAction(self.menuAffichage.menuAction()) + self.menubar.addAction(self.menuTools.menuAction()) + self.menubar.addAction(self.menuHelp.menuAction()) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "PyTalk", None, QtGui.QApplication.UnicodeUTF8)) + self.statusBox.addItem(QtGui.QIcon("images/status/available.png"),QtGui.QApplication.translate("MainWindow", "Available", None, QtGui.QApplication.UnicodeUTF8)) + self.statusBox.addItem(QtGui.QIcon("images/status/chat.png"),QtGui.QApplication.translate("MainWindow", "Chat", None, QtGui.QApplication.UnicodeUTF8)) + self.statusBox.addItem(QtGui.QIcon("images/status/busy.png"),QtGui.QApplication.translate("MainWindow", "Do not disturb", None, QtGui.QApplication.UnicodeUTF8)) + self.statusBox.addItem(QtGui.QIcon("images/status/away.png"),QtGui.QApplication.translate("MainWindow", "Away", None, QtGui.QApplication.UnicodeUTF8)) + self.statusBox.addItem(QtGui.QIcon("images/status/extended-away.png"),QtGui.QApplication.translate("MainWindow", "Extended Away", None, QtGui.QApplication.UnicodeUTF8)) + self.statusBox.addItem(QtGui.QIcon("images/status/offline.png"),QtGui.QApplication.translate("MainWindow", "Offline", None, QtGui.QApplication.UnicodeUTF8)) + self.menuContacts.setTitle(QtGui.QApplication.translate("MainWindow", "Account", None, QtGui.QApplication.UnicodeUTF8)) + self.menuAffichage.setTitle(QtGui.QApplication.translate("MainWindow", "View", None, QtGui.QApplication.UnicodeUTF8)) + self.menuHelp.setTitle(QtGui.QApplication.translate("MainWindow", "Help", None, QtGui.QApplication.UnicodeUTF8)) + self.menuBuddies.setTitle(QtGui.QApplication.translate("MainWindow", "Buddies", None, QtGui.QApplication.UnicodeUTF8)) + self.menuTools.setTitle(QtGui.QApplication.translate("MainWindow", "Tools", None, QtGui.QApplication.UnicodeUTF8)) + self.actionConnection.setText(QtGui.QApplication.translate("MainWindow", "L&og in", None, QtGui.QApplication.UnicodeUTF8)) + self.actionConnection.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+O", None, QtGui.QApplication.UnicodeUTF8)) + self.actionDeconnection.setText(QtGui.QApplication.translate("MainWindow", "Log out", None, QtGui.QApplication.UnicodeUTF8)) + self.actionOffline_buddies.setText(QtGui.QApplication.translate("MainWindow", "Offline buddies", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAway_buddies.setText(QtGui.QApplication.translate("MainWindow", "Away buddies", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAbout.setText(QtGui.QApplication.translate("MainWindow", "About pyTalk", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAboutQt.setText(QtGui.QApplication.translate("MainWindow", "About Qt", None, QtGui.QApplication.UnicodeUTF8)) + self.actionQuit.setText(QtGui.QApplication.translate("MainWindow", "&Quit", None, QtGui.QApplication.UnicodeUTF8)) + self.actionQuit.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+Q", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAdd_a_buddy.setText(QtGui.QApplication.translate("MainWindow", "Add a buddy", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAdd_a_group.setText(QtGui.QApplication.translate("MainWindow", "Add a group", None, QtGui.QApplication.UnicodeUTF8)) + self.actionPreferences.setText(QtGui.QApplication.translate("MainWindow", "&Preferences", None, QtGui.QApplication.UnicodeUTF8)) + self.actionPreferences.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+P", None, QtGui.QApplication.UnicodeUTF8)) + self.actionConsole.setText(QtGui.QApplication.translate("MainWindow", "XML Console", None, QtGui.QApplication.UnicodeUTF8)) + diff --git a/pytalk/ui/ui_ConnectionDialog.py b/pytalk/ui/ui_ConnectionDialog.py index d247d88..3435787 100644 --- a/pytalk/ui/ui_ConnectionDialog.py +++ b/pytalk/ui/ui_ConnectionDialog.py @@ -87,7 +87,7 @@ def setupUi(self, ConnectionDialog): QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),ConnectionDialog.reject) QtCore.QMetaObject.connectSlotsByName(ConnectionDialog) - def retranslateUi(self, ConnectionDialog): + def rsetranslateUi(self, ConnectionDialog): ConnectionDialog.setWindowTitle(QtGui.QApplication.translate("ConnectionDialog", "Connection Dialog", None, QtGui.QApplication.UnicodeUTF8)) self.groupBox.setTitle(QtGui.QApplication.translate("ConnectionDialog", "Login\'s informations", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("ConnectionDialog", "Jabber ID:", None, QtGui.QApplication.UnicodeUTF8)) From 4b49d929771708e73de19b1d7493e178cb4de9fe Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Sun, 19 May 2013 18:00:53 +0100 Subject: [PATCH 2/4] connection --- .gitignore | 2 +- pytalk/BuddyItem.py | 114 +++++---- pytalk/BuddyList.py | 5 +- pytalk/ConnectorThread.py | 393 ++++++++++++++-------------- pytalk/jabber.py | 14 +- pytalk/pytalk.py | 12 +- pytalk/ui/ConnectionDialog.py | 63 ++--- pytalk/ui/MainWindow.py | 467 ++++++++++++++++++++++++---------- 8 files changed, 638 insertions(+), 432 deletions(-) diff --git a/.gitignore b/.gitignore index 65f4f5c..5166ef7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.pyc .project .pydevproject - +.settings diff --git a/pytalk/BuddyItem.py b/pytalk/BuddyItem.py index 0030057..33c7769 100644 --- a/pytalk/BuddyItem.py +++ b/pytalk/BuddyItem.py @@ -8,71 +8,73 @@ from jabber import STATUS_IMAGE class BuddyItem(QTreeWidgetItem): - """ - BuddyItem implements the view of a Buddy from the Roster - """ + """ + BuddyItem implements the view of a Buddy from the Roster + """ - dialog = None - msg = None + dialog = None + msg = None - def __init__(self, parent, jid, con): - QTreeWidgetItem.__init__(self, parent, [jid], QTreeWidgetItem.UserType+1) + def __init__(self, parent, jid, con): + QTreeWidgetItem.__init__(self, parent, [jid], QTreeWidgetItem.UserType+1) - # QTreeWidgetItem configuration - self.setFlags(Qt.ItemIsDragEnabled | Qt.ItemIsEnabled) # we can move a contact - self.parent = parent - self.jid = jid - self.name = jid - self.setStatus(STATUS.unavailable) - self.connectionThread = con - - def setStatus(self, status): - self.status = status - if self.status.index not in range(6): - self.status = STATUS.unavailable - settings = QSettings("Trunat", "PyTalk") - settings.beginGroup("preferences") - repStatus = settings.value("images_status", QVariant("images/status/")).toString() - fileStatus = settings.value(str(self.status), QVariant(STATUS_IMAGE[self.status.index])).toString() - settings.endGroup() - self.setIcon(0, QIcon(repStatus+fileStatus)) + # QTreeWidgetItem configuration + self.setFlags(Qt.ItemIsDragEnabled | Qt.ItemIsEnabled) # we can move a contact + self.parent = parent + self.jid = jid + self.name = jid + self.setStatus(STATUS.unavailable) + self.connectionThread = con + + def setStatus(self, status): + self.status = status + if self.status not in range(6): + self.status = STATUS.unavailable + settings = QSettings("Trunat", "PyTalk") + settings.beginGroup("preferences") + repStatus = settings.value("images_status", QVariant("images/status/")).toString() + fileStatus = settings.value(str(self.status), QVariant(STATUS_IMAGE[self.status])).toString() + settings.endGroup() + self.setIcon(0, QIcon(repStatus+fileStatus)) - def setName(self, name): - if name: - self.name = name - self.setText(0, name) + def setName(self, name): + if name: + self.name = name + self.setText(0, name) - def status(self): - return status + def DEAstatus(self): + return status - def isAway(self): - return (self.status == STATUS.away or self.status == STATUS.xa) + def isAway(self): + return (self.status == STATUS.away or self.status == STATUS.xa) - def isOffline(self): - if self.status == STATUS.unavailable: - return True - else: - return False + def isOffline(self): + if self.status == STATUS.unavailable: + return True + else: + return False - def createDialog(self): - if not self.dialog: - self.dialog = QDialog() - self.dialog.setWindowIcon(QIcon("images/mail.png")) + def createDialog(self): + if not self.dialog: + self.dialog = QDialog() + self.dialog.setWindowIcon(QIcon("images/mail.png")) - self.msg = MessageBox(self.dialog, self.connectionThread, self.jid, self.name) - layout = QVBoxLayout(self.dialog) - layout.addWidget(self.msg) - self.dialog.setLayout(layout) - self.dialog.setWindowTitle(self.dialog.tr("Chat with ") + self.name) - self.dialog.show() - self.dialog.raise_() + self.msg = MessageBox(self.dialog, self.connectionThread, self.jid, self.name) + layout = QVBoxLayout(self.dialog) + layout.addWidget(self.msg) + self.dialog.setLayout(layout) + self.dialog.setWindowTitle(self.dialog.tr("Chat with ") + self.name) + self.dialog.show() + self.dialog.raise_() - def receiveMessage(self, event): - self.createDialog() - self.msg.receiveMessage(event) + def receiveMessage(self, event): + print "recieveMessage" + self.createDialog() + self.msg.receiveMessage(event) - def sendMessage(self): - self.createDialog() + def sendMessage(self): + print "sendMessage" + self.createDialog() - def __str__(self): - return u'%s' % self.name + def __str__(self): + return u'%s' % self.name diff --git a/pytalk/BuddyList.py b/pytalk/BuddyList.py index 43b39e6..e940360 100644 --- a/pytalk/BuddyList.py +++ b/pytalk/BuddyList.py @@ -11,6 +11,7 @@ class BuddyList(QTreeWidget): def __init__(self, parent): QTreeWidget.__init__(self, parent) + self.connection = None # QTreeWidgetItem configuration self.header().hide() @@ -33,7 +34,7 @@ def __init__(self, parent): def setConnection(self, con): self.connection = con - def addItem(self, jid): + def add_item(self, jid): if self.connection: group = self.connection.getGroups(jid)[0] self.addGroup(group) @@ -43,7 +44,7 @@ def addItem(self, jid): self.groups[group].addChild(self.buddies[jid]) self.tree[group][jid] = self.buddies[jid] - def addGroup(self, group): + def add_group(self, group): if group: if group not in self.groups.keys(): self.groups[group] = BuddyGroup(group) diff --git a/pytalk/ConnectorThread.py b/pytalk/ConnectorThread.py index 7af57aa..3cb6738 100644 --- a/pytalk/ConnectorThread.py +++ b/pytalk/ConnectorThread.py @@ -10,200 +10,201 @@ from jabber import STATUS class ConnectorThread(QThread): - """ - ConnectorThread is the class which manage the connection between the - Jabber server and the PyTalk client. - """ - - def __init__(self, status): - "We initialise a new Thread and create the connection with the Jabber Server" - QThread.__init__(self) - self.status = status - - def run(self): - "We are running the thread and are reading and sending informations to the Jabber server" - - if self.connect(): - self.Terminated = False - self.emit(SIGNAL("connected()")) - else: - self.Terminated = True - - while not self.Terminated: - self.jabber.Process(1) - time.sleep(2.0) - sys.stderr.write('Thread correctly stopped'+unicode(self.Terminated)+'\n\n') - - def connect(self): - settings = QSettings("Trunat", "PyTalk") - settings.beginGroup("Connection") - - self.userID = settings.value("userID").toString().__str__() - self.password = settings.value("password").toString().__str__() - self.server = settings.value("server").toString().__str__() - self.useSSL = settings.value("useSSL", QVariant(True)).toBool() - - if self.useSSL: - self.port = settings.value("port", QVariant("5223")).toInt() - else: - self.port = settings.value("port", QVariant("5222")).toInt() - - self.port = int(self.port[0]) - - self.ressource = settings.value("ressource", QVariant("PyTalk")).toString().__str__() - - settings.endGroup() - - self.jid = xmpp.protocol.JID(self.userID.__str__()) - self.jabber = xmpp.Client(self.jid.getDomain(), debug=[]) - - if self.server: - server = (self.server, self.port) - else: - server = None - connection = self.jabber.connect(server) - - if not connection: - self.emit(SIGNAL("error"), self.tr("Connection Error"), self.tr("Could not connect")) - return False - sys.stderr.write('Connected with %s\n' % connection) - - auth = self.jabber.auth(self.jid.getNode(), self.password, self.ressource) - if not auth: - self.emit(SIGNAL("error"), self.tr("Authentication Error"), self.tr("Could not authenticate")) - return False - sys.stderr.write('Authenticate using %s\n' % auth) - - self.register_handlers() - self.jabber.sendInitPresence(requestRoster=1) - - return connection - - def disconnect(self): - "We stop to speak with the server and disconnect from it" - self.Terminated = True - if self.jabber.isConnected(): - self.jabber.disconnect() - - def register_handlers(self): - self.jabber.RegisterHandler('message', self.xmpp_message) - self.jabber.RegisterHandler("iq", self.handle_version, typ = "get", ns = xmpp.NS_VERSION) - self.jabber.RegisterHandler("iq", self.handle_disco_info, typ = "get", ns = xmpp.NS_DISCO_INFO) - self.jabber.RegisterHandler("iq", self.rosterChange, typ = "set", ns = xmpp.NS_ROSTER) - self.jabber.RegisterHandler("presence", self.subscriptionRequest, typ = "subscribe") - self.jabber.RegisterHandler("presence", self.addBuddy, typ = "suscribed") - self.jabber.RegisterHandler("presence", self.presence) - self.jabber.RegisterHandler("iq", self.request) - self.jabber.RegisterDisconnectHandler(lambda: self.emit(SIGNAL("connect()"))) - - def request(self, con, packet): - self.emit(SIGNAL("debug"), unicode(packet)+"\n\n") - - def xmpp_message(self, con, event): - self.emit(SIGNAL("debug"), unicode(event)+"\n\n") - type = event.getType() - if type: - if type in ['message', 'chat']: - message = event.getBody() - if message: - self.emit(SIGNAL("message"), event) - - def send_message(self, tojid, message): - m = xmpp.protocol.Message(to=tojid, body=message, typ='chat') - - self.emit(SIGNAL("debug"), unicode(m)+"\n\n") - self.jabber.send(m) - - def changeStatus(self, showId, status): - """Send a presence packet""" - p = xmpp.protocol.Presence() - p.setShow(STATUS[showId]) - if status: - p.setStatus(status) - if showId == STATUS.available: - p.setPriority(5) - self.jabber.send(p) - self.emit(SIGNAL("debug"), unicode(p)+"\n\n") - - def handle_version(self, con, iq): - """Respond to a version info request.""" - self.emit(SIGNAL("debug"), unicode(iq)+"\n") - reply = iq.buildReply('result') - #add and in accordance with XEP-0092 - reply.T.query.addChild(name="name", payload=settings.APPNAME) - reply.T.query.addChild(name="version", payload=settings.VERSION) - if platform.mac_ver()[0]: - plateforme = "Mac OS %s" % platform.mac_ver()[0] - elif platform.win32_ver()[0]: - plateforme = "Windows %s" % platform.win32_ver()[0] - else: - plateforme = "%s %s" % (platform.uname()[0], platform.uname()[2]) - reply.T.query.addChild(name="os", payload=plateforme) - - self.emit(SIGNAL("debug"), unicode(reply)+"\n") - self.jabber.send(reply) - - def handle_disco_info(self, con, iq): - self.emit(SIGNAL("debug"), unicode(iq)+"\n") - reply = iq.buildReply('result') - reply.T.query.addChild(name="feature", attrs={'var':'jabber:iq:version'}) - self.emit(SIGNAL("debug"), unicode(reply)+"\n") - self.jabber.send(reply) - - def getRoster(self): - self.roster = self.jabber.getRoster() - return self.roster.getItems() - - - def getGroups(self, jid): - if self.roster.getGroups(jid): - return self.roster.getGroups(jid) - else: - return ['Buddies'] - - def getName(self, jid): - return self.roster.getName(jid) - - def getStatus(self, jid): - pass - - def presence(self, con, presence): - # Somebody change his presence - # Usefull Informations : - # - typ is unavailable -> Contact gone offline - self.emit(SIGNAL("debug"), unicode(presence)+"\n") - jid = presence.getFrom().getStripped() - if presence.getType() == "unavailable": - self.emit(SIGNAL("presence"), jid, unicode(STATUS.unavailable)) - if not presence.getType(): - if not presence.getShow(): - self.emit(SIGNAL("presence"), jid, STATUS.available, presence.getStatus()) - else: - status = presence.getShow() - if status == "chat": - stat = STATUS.chat - elif status == "dnd": - stat = STATUS.dnd - elif status == "away": - stat= STATUS.away - elif status == "xa": - stat = STATUS.xa - else: - stat = STATUS.available - self.emit(SIGNAL("presence"), jid, stat, presence.getStatus()) - - - def subscriptionRequest(self, con, presence): - self.emit(SIGNAL("debug"), unicode(presence)+"\n") - self.emit(SIGNAL("subscriptionRequest"), presence) - - def addBuddy(self, con, presence): - self.emit(SIGNAL("debug"), unicode(presence)+"\n") - self.emit(SIGNAL("addBuddy"), presence) - - def rosterChange(self, con, iq): - self.emit(SIGNAL("rosterChange"), iq) - - def isConnected(self): - return self.jabber.isConnected() + """ + ConnectorThread is the class which manage the connection between the + Jabber server and the PyTalk client. + """ + + def __init__(self, status): + "We initialise a new Thread and create the connection with the Jabber Server" + QThread.__init__(self) + self.status = status + + def run(self): + "We are running the thread and are reading and sending informations to the Jabber server" + print "run" + if self.connect(): + self.Terminated = False + self.emit(SIGNAL("connected()")) + else: + self.Terminated = True + + while not self.Terminated: + self.jabber.Process(1) + time.sleep(2.0) + sys.stderr.write('Thread correctly stopped'+unicode(self.Terminated)+'\n\n') + + def connect(self): + settings = QSettings("Trunat", "PyTalk") + settings.beginGroup("Connection") + + self.userID = settings.value("userID").toString().__str__() + self.password = settings.value("password").toString().__str__() + self.server = settings.value("server").toString().__str__() + self.useSSL = settings.value("useSSL", QVariant(True)).toBool() + + if self.useSSL: + self.port = settings.value("port", QVariant("5223")).toInt() + else: + self.port = settings.value("port", QVariant("5222")).toInt() + + self.port = int(self.port[0]) + + self.ressource = settings.value("ressource", QVariant("PyTalk")).toString().__str__() + + settings.endGroup() + + self.jid = xmpp.protocol.JID(self.userID.__str__()) + self.jabber = xmpp.Client(self.jid.getDomain(), debug=[]) + + if self.server: + server = (self.server, self.port) + else: + server = None + connection = self.jabber.connect(server) + + if not connection: + self.emit(SIGNAL("error"), self.tr("Connection Error"), self.tr("Could not connect")) + return False + sys.stderr.write('Connected with %s\n' % connection) + + auth = self.jabber.auth(self.jid.getNode(), self.password, self.ressource) + if not auth: + self.emit(SIGNAL("error"), self.tr("Authentication Error"), self.tr("Could not authenticate")) + return False + sys.stderr.write('Authenticate using %s\n' % auth) + + self.register_handlers() + self.jabber.sendInitPresence(requestRoster=1) + + return connection + + def disconnect(self): + "We stop to speak with the server and disconnect from it" + self.Terminated = True + if self.jabber.isConnected(): + self.jabber.disconnect() + + def register_handlers(self): + self.jabber.RegisterHandler('message', self.xmpp_message) + self.jabber.RegisterHandler("iq", self.handle_version, typ = "get", ns = xmpp.NS_VERSION) + self.jabber.RegisterHandler("iq", self.handle_disco_info, typ = "get", ns = xmpp.NS_DISCO_INFO) + self.jabber.RegisterHandler("iq", self.rosterChange, typ = "set", ns = xmpp.NS_ROSTER) + self.jabber.RegisterHandler("presence", self.subscriptionRequest, typ = "subscribe") + self.jabber.RegisterHandler("presence", self.addBuddy, typ = "suscribed") + self.jabber.RegisterHandler("presence", self.presence) + self.jabber.RegisterHandler("iq", self.request) + self.jabber.RegisterDisconnectHandler(lambda: self.emit(SIGNAL("connect()"))) + + def request(self, con, packet): + self.emit(SIGNAL("debug"), unicode(packet)+"\n\n") + + def xmpp_message(self, con, event): + self.emit(SIGNAL("debug"), unicode(event)+"\n\n") + type = event.getType() + if type: + if type in ['message', 'chat']: + message = event.getBody() + if message: + self.emit(SIGNAL("message"), event) + + def send_message(self, tojid, message): + m = xmpp.protocol.Message(to=tojid, body=message, typ='chat') + + self.emit(SIGNAL("debug"), unicode(m)+"\n\n") + self.jabber.send(m) + + def set_status(self, showId, status): + """Send a presence packet""" + print "change_status", showId, status + p = xmpp.protocol.Presence() + p.setShow(STATUS_TEST[showId]) + if status: + p.setStatus(status) + if showId == STATUS.available: + p.setPriority(5) + self.jabber.send(p) + self.emit(SIGNAL("debug"), unicode(p)+"\n\n") + + def handle_version(self, con, iq): + """Respond to a version info request.""" + self.emit(SIGNAL("debug"), unicode(iq)+"\n") + reply = iq.buildReply('result') + #add and in accordance with XEP-0092 + reply.T.query.addChild(name="name", payload=settings.APPNAME) + reply.T.query.addChild(name="version", payload=settings.VERSION) + if platform.mac_ver()[0]: + plateforme = "Mac OS %s" % platform.mac_ver()[0] + elif platform.win32_ver()[0]: + plateforme = "Windows %s" % platform.win32_ver()[0] + else: + plateforme = "%s %s" % (platform.uname()[0], platform.uname()[2]) + reply.T.query.addChild(name="os", payload=plateforme) + + self.emit(SIGNAL("debug"), unicode(reply)+"\n") + self.jabber.send(reply) + + def handle_disco_info(self, con, iq): + self.emit(SIGNAL("debug"), unicode(iq)+"\n") + reply = iq.buildReply('result') + reply.T.query.addChild(name="feature", attrs={'var':'jabber:iq:version'}) + self.emit(SIGNAL("debug"), unicode(reply)+"\n") + self.jabber.send(reply) + + def getRoster(self): + self.roster = self.jabber.getRoster() + return self.roster.getItems() + + + def getGroups(self, jid): + if self.roster.getGroups(jid): + return self.roster.getGroups(jid) + else: + return ['Buddies'] + + def getName(self, jid): + return self.roster.getName(jid) + + def getStatus(self, jid): + pass + + def presence(self, con, presence): + # Somebody change his presence + # Usefull Informations : + # - typ is unavailable -> Contact gone offline + self.emit(SIGNAL("debug"), unicode(presence)+"\n") + jid = presence.getFrom().getStripped() + if presence.getType() == "unavailable": + self.emit(SIGNAL("presence"), jid, unicode(STATUS.unavailable)) + if not presence.getType(): + if not presence.getShow(): + self.emit(SIGNAL("presence"), jid, STATUS.available, presence.getStatus()) + else: + status = presence.getShow() + if status == "chat": + stat = STATUS.chat + elif status == "dnd": + stat = STATUS.dnd + elif status == "away": + stat= STATUS.away + elif status == "xa": + stat = STATUS.xa + else: + stat = STATUS.available + self.emit(SIGNAL("presence"), jid, stat, presence.getStatus()) + + + def subscriptionRequest(self, con, presence): + self.emit(SIGNAL("debug"), unicode(presence)+"\n") + self.emit(SIGNAL("subscriptionRequest"), presence) + + def addBuddy(self, con, presence): + self.emit(SIGNAL("debug"), unicode(presence)+"\n") + self.emit(SIGNAL("addBuddy"), presence) + + def rosterChange(self, con, iq): + self.emit(SIGNAL("rosterChange"), iq) + + def isConnected(self): + return self.jabber.isConnected() diff --git a/pytalk/jabber.py b/pytalk/jabber.py index 05b6172..50ee372 100644 --- a/pytalk/jabber.py +++ b/pytalk/jabber.py @@ -3,8 +3,18 @@ from enum import Enum def tr(string): - return QApplication.translate("Status", string, None, QApplication.UnicodeUTF8) + return QApplication.translate("Status", string, None, QApplication.UnicodeUTF8) -STATUS = Enum('available', 'chat', 'dnd', 'away', 'xa', 'unavailable', 'invisible') +class STATUS: + available = 0 + chat = 1 + dnd = 2 + away = 3 + xa = 4 + unavailable = 5 + invisible = 6 + +DEADSTATUS = Enum('available', 'chat', 'dnd', 'away', 'xa', 'unavailable', 'invisible') +STATUS_TEST = ['available', 'chat', 'dnd', 'away', 'xa', 'unavailable', 'invisible'] DISPLAY_STATUS = (tr('Available'), tr('Chat'), tr('Do not Disturb'), tr('Away'), tr('Unavailable'), tr('Offline'), tr('Invisible')) STATUS_IMAGE = ('available.png', 'chat.png', 'busy.png', 'away.png', 'extended-away.png', 'offline.png', 'offline.png') diff --git a/pytalk/pytalk.py b/pytalk/pytalk.py index 4bd54fd..2504ae0 100755 --- a/pytalk/pytalk.py +++ b/pytalk/pytalk.py @@ -23,10 +23,12 @@ from PyQt4.QtGui import * from PyQt4.QtCore import SIGNAL, SLOT, Qt, QSize, QTimer -from ui.ui_mainwindow import Ui_MainWindow -from AboutDialog import AboutDialog +from ui.MainWindow import MainWindow from ui.ConnectionDialog import ConnectionDialog + +from AboutDialog import AboutDialog + from ConnectorThread import ConnectorThread from MessageBox import MessageBox from BuddyList import BuddyList @@ -38,7 +40,7 @@ -class MainWindow(QMainWindow, Ui_MainWindow): +class DEDMainWindow(QMainWindow):# Ui_MainWindow): connectorThread = None def __init__(self, parent = None): @@ -97,7 +99,7 @@ def __init__(self, parent = None): QTimer.singleShot(500, self.show_connection_dialog) def show_connection_dialog(self): - d = ConnectionDialog() + d = ConnectionDialog(self) d.exec_() @@ -153,7 +155,7 @@ def quit(self): self.disconnect() sys.exit(0) - def changeStatus(self, index=-1): + def on_change_status(self, index=-1): if index == -1: index = self.statusBox.currentIndex() if index == STATUS.unavailable.index: diff --git a/pytalk/ui/ConnectionDialog.py b/pytalk/ui/ConnectionDialog.py index a0a21dc..43fd49d 100644 --- a/pytalk/ui/ConnectionDialog.py +++ b/pytalk/ui/ConnectionDialog.py @@ -8,26 +8,22 @@ # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui +from PyQt4.QtCore import SIGNAL, SLOT class ConnectionDialog(QtGui.QDialog): def __init__(self, parent=None): - QtGui.QDialog.__init__(parent) + QtGui.QDialog.__init__(self) #self.setObjectName("ConnectionDialog") #ConnectionDialog.resize(QtCore.QSize(QtCore.QRect(0,0,289,277).size()).expandedTo(ConnectionDialog.minimumSizeHint())) - self.vboxlayout = QtGui.QVBoxLayout(self) - self.vboxlayout.setObjectName("vboxlayout") - - self.groupBox = QtGui.QGroupBox(ConnectionDialog) - self.groupBox.setObjectName("groupBox") - + self.vboxlayout = QtGui.QVBoxLayout(self) + self.groupBox = QtGui.QGroupBox() + self.gridlayout = QtGui.QGridLayout(self.groupBox) - self.gridlayout.setObjectName("gridlayout") self.label = QtGui.QLabel(self.groupBox) - self.label.setObjectName("label") self.gridlayout.addWidget(self.label,0,0,1,1) self.userID = QtGui.QLineEdit(self.groupBox) @@ -44,7 +40,7 @@ def __init__(self, parent=None): self.gridlayout.addWidget(self.password,1,1,1,1) self.vboxlayout.addWidget(self.groupBox) - self.groupBox_2 = QtGui.QGroupBox(ConnectionDialog) + self.groupBox_2 = QtGui.QGroupBox() self.groupBox_2.setObjectName("groupBox_2") self.gridlayout1 = QtGui.QGridLayout(self.groupBox_2) @@ -79,49 +75,54 @@ def __init__(self, parent=None): self.gridlayout1.addWidget(self.useSSL,1,2,1,1) self.vboxlayout.addWidget(self.groupBox_2) - self.buttonBox = QtGui.QDialogButtonBox(ConnectionDialog) + self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") self.vboxlayout.addWidget(self.buttonBox) - self.retranslateUi(ConnectionDialog) - QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("accepted()"),ConnectionDialog.accept) - QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),ConnectionDialog.reject) - QtCore.QMetaObject.connectSlotsByName(ConnectionDialog) - self.connect(self, SIGNAL("accepted()"), self.saveSettings) + self.retranslateUi() + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.on_accept) + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject) + #QtCore.QMetaObject.connectSlotsByName() + #self.connect(self, SIGNAL("accepted()"), self.saveSettings) self.readSettings() + + + def on_accept(self): + self.saveSettings() + self.accept() def readSettings(self): - settings = QSettings("Trunat", "PyTalk") + settings = QtCore.QSettings("Trunat", "PyTalk") settings.beginGroup("Connection") self.userID.setText(settings.value("userID").toString()) self.password.setText(settings.value("password").toString()) self.server.setText(settings.value("server").toString()) - self.useSSL.setChecked(settings.value("useSSL", QVariant(True)).toBool()) + self.useSSL.setChecked(settings.value("useSSL", QtCore.QVariant(True)).toBool()) if self.useSSL.isChecked(): - self.port.setText(settings.value("port", QVariant("5223")).toString()) + self.port.setText(settings.value("port", QtCore.QVariant("5223")).toString()) else: - self.port.setText(settings.value("port", QVariant("5222")).toString()) + self.port.setText(settings.value("port", QtCore.QVariant("5222")).toString()) - self.ressource.setText(settings.value("ressource", QVariant("PyTalk")).toString()) + self.ressource.setText(settings.value("ressource", QtCore.QVariant("PyTalk")).toString()) settings.endGroup() def saveSettings(self): - settings = QSettings("Trunat", "PyTalk") + settings = QtCore.QSettings("Trunat", "PyTalk") settings.beginGroup("Connection") - settings.setValue("userID", QVariant(self.userID.text())) - settings.setValue("password", QVariant(self.password.text())) - settings.setValue("server", QVariant(self.server.text())) - settings.setValue("port", QVariant(int(self.port.text()))) - settings.setValue("ressource", QVariant(self.ressource.text())) - settings.setValue("useSSL", QVariant(self.useSSL.isChecked())) + settings.setValue("userID", QtCore.QVariant(self.userID.text())) + settings.setValue("password", QtCore.QVariant(self.password.text())) + settings.setValue("server", QtCore.QVariant(self.server.text())) + settings.setValue("port", QtCore.QVariant(int(self.port.text()))) + settings.setValue("ressource", QtCore.QVariant(self.ressource.text())) + settings.setValue("useSSL", QtCore.QVariant(self.useSSL.isChecked())) settings.endGroup() - self.emit(SIGNAL("configured()")) + self.emit( SIGNAL("configured()") ) - def setranslateUi(self, ConnectionDialog): - ConnectionDialog.setWindowTitle(QtGui.QApplication.translate("ConnectionDialog", "Connection Dialog", None, QtGui.QApplication.UnicodeUTF8)) + def retranslateUi(self): + self.setWindowTitle(QtGui.QApplication.translate("ConnectionDialog", "Connection Dialog", None, QtGui.QApplication.UnicodeUTF8)) self.groupBox.setTitle(QtGui.QApplication.translate("ConnectionDialog", "Login\'s informations", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("ConnectionDialog", "Jabber ID:", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("ConnectionDialog", "Password:", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/pytalk/ui/MainWindow.py b/pytalk/ui/MainWindow.py index 693cfd3..9e5d0c3 100644 --- a/pytalk/ui/MainWindow.py +++ b/pytalk/ui/MainWindow.py @@ -1,145 +1,334 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'ui_mainwindow.ui' -# -# Created: Thu Jan 24 11:09:31 2008 -# by: PyQt4 UI code generator 4.3.1 -# -# WARNING! All changes made in this file will be lost! +import sys +import datetime from PyQt4 import QtCore, QtGui +from PyQt4.QtCore import SIGNAL -class Ui_MainWindow(object): - def setupUi(self, MainWindow): - MainWindow.setObjectName("MainWindow") - MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,316,407).size()).expandedTo(MainWindow.minimumSizeHint())) - MainWindow.setWindowIcon(QtGui.QIcon("images/im-jabber.png")) - MainWindow.setUnifiedTitleAndToolBarOnMac(False) - - self.centralwidget = QtGui.QWidget(MainWindow) - self.centralwidget.setObjectName("centralwidget") - - self.vboxlayout = QtGui.QVBoxLayout(self.centralwidget) - self.vboxlayout.setObjectName("vboxlayout") - - self.statusBox = QtGui.QComboBox(self.centralwidget) - self.statusBox.setObjectName("statusBox") - self.vboxlayout.addWidget(self.statusBox) - - self.statusEdit = QtGui.QLineEdit(self.centralwidget) - self.statusEdit.setObjectName("statusEdit") - self.vboxlayout.addWidget(self.statusEdit) - MainWindow.setCentralWidget(self.centralwidget) - - self.menubar = QtGui.QMenuBar(MainWindow) - self.menubar.setGeometry(QtCore.QRect(0,0,316,29)) - self.menubar.setObjectName("menubar") - - self.menuContacts = QtGui.QMenu(self.menubar) - self.menuContacts.setObjectName("menuContacts") - - self.menuAffichage = QtGui.QMenu(self.menubar) - self.menuAffichage.setObjectName("menuAffichage") - - self.menuHelp = QtGui.QMenu(self.menubar) - self.menuHelp.setObjectName("menuHelp") - - self.menuBuddies = QtGui.QMenu(self.menubar) - self.menuBuddies.setObjectName("menuBuddies") - - self.menuTools = QtGui.QMenu(self.menubar) - self.menuTools.setObjectName("menuTools") - MainWindow.setMenuBar(self.menubar) - - self.actionConnection = QtGui.QAction(MainWindow) - self.actionConnection.setIcon(QtGui.QIcon("images/status/log-in.png")) - self.actionConnection.setObjectName("actionConnection") - - self.actionDeconnection = QtGui.QAction(MainWindow) - self.actionDeconnection.setEnabled(False) - self.actionDeconnection.setIcon(QtGui.QIcon("images/status/log-out.png")) - self.actionDeconnection.setObjectName("actionDeconnection") - - self.actionOffline_buddies = QtGui.QAction(MainWindow) - self.actionOffline_buddies.setCheckable(True) - self.actionOffline_buddies.setObjectName("actionOffline_buddies") - - self.actionAway_buddies = QtGui.QAction(MainWindow) - self.actionAway_buddies.setCheckable(True) - self.actionAway_buddies.setChecked(True) - self.actionAway_buddies.setObjectName("actionAway_buddies") - - self.actionAbout = QtGui.QAction(MainWindow) - self.actionAbout.setIcon(QtGui.QIcon("images/about.png")) - self.actionAbout.setObjectName("actionAbout") - - self.actionAboutQt = QtGui.QAction(MainWindow) - self.actionAboutQt.setIcon(QtGui.QIcon("images/qt4.png")) - self.actionAboutQt.setObjectName("actionAboutQt") - - self.actionQuit = QtGui.QAction(MainWindow) - self.actionQuit.setIcon(QtGui.QIcon("images/exit.png")) - self.actionQuit.setObjectName("actionQuit") - - self.actionAdd_a_buddy = QtGui.QAction(MainWindow) - self.actionAdd_a_buddy.setIcon(QtGui.QIcon("images/plus.png")) - self.actionAdd_a_buddy.setObjectName("actionAdd_a_buddy") - - self.actionAdd_a_group = QtGui.QAction(MainWindow) - self.actionAdd_a_group.setIcon(QtGui.QIcon("images/plus.png")) - self.actionAdd_a_group.setObjectName("actionAdd_a_group") - - self.actionPreferences = QtGui.QAction(MainWindow) - self.actionPreferences.setIcon(QtGui.QIcon("images/preferences.png")) - self.actionPreferences.setObjectName("actionPreferences") - - self.actionConsole = QtGui.QAction(MainWindow) - self.actionConsole.setObjectName("actionConsole") - self.menuContacts.addAction(self.actionConnection) - self.menuContacts.addAction(self.actionDeconnection) - self.menuContacts.addAction(self.actionQuit) - self.menuAffichage.addAction(self.actionOffline_buddies) - self.menuAffichage.addAction(self.actionAway_buddies) - self.menuHelp.addAction(self.actionAbout) - self.menuHelp.addAction(self.actionAboutQt) - self.menuBuddies.addAction(self.actionAdd_a_buddy) - self.menuBuddies.addAction(self.actionAdd_a_group) - self.menuTools.addAction(self.actionPreferences) - self.menuTools.addAction(self.actionConsole) - self.menubar.addAction(self.menuContacts.menuAction()) - self.menubar.addAction(self.menuBuddies.menuAction()) - self.menubar.addAction(self.menuAffichage.menuAction()) - self.menubar.addAction(self.menuTools.menuAction()) - self.menubar.addAction(self.menuHelp.menuAction()) - - self.retranslateUi(MainWindow) - QtCore.QMetaObject.connectSlotsByName(MainWindow) - - def retranslateUi(self, MainWindow): - MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "PyTalk", None, QtGui.QApplication.UnicodeUTF8)) - self.statusBox.addItem(QtGui.QIcon("images/status/available.png"),QtGui.QApplication.translate("MainWindow", "Available", None, QtGui.QApplication.UnicodeUTF8)) - self.statusBox.addItem(QtGui.QIcon("images/status/chat.png"),QtGui.QApplication.translate("MainWindow", "Chat", None, QtGui.QApplication.UnicodeUTF8)) - self.statusBox.addItem(QtGui.QIcon("images/status/busy.png"),QtGui.QApplication.translate("MainWindow", "Do not disturb", None, QtGui.QApplication.UnicodeUTF8)) - self.statusBox.addItem(QtGui.QIcon("images/status/away.png"),QtGui.QApplication.translate("MainWindow", "Away", None, QtGui.QApplication.UnicodeUTF8)) - self.statusBox.addItem(QtGui.QIcon("images/status/extended-away.png"),QtGui.QApplication.translate("MainWindow", "Extended Away", None, QtGui.QApplication.UnicodeUTF8)) - self.statusBox.addItem(QtGui.QIcon("images/status/offline.png"),QtGui.QApplication.translate("MainWindow", "Offline", None, QtGui.QApplication.UnicodeUTF8)) - self.menuContacts.setTitle(QtGui.QApplication.translate("MainWindow", "Account", None, QtGui.QApplication.UnicodeUTF8)) - self.menuAffichage.setTitle(QtGui.QApplication.translate("MainWindow", "View", None, QtGui.QApplication.UnicodeUTF8)) - self.menuHelp.setTitle(QtGui.QApplication.translate("MainWindow", "Help", None, QtGui.QApplication.UnicodeUTF8)) - self.menuBuddies.setTitle(QtGui.QApplication.translate("MainWindow", "Buddies", None, QtGui.QApplication.UnicodeUTF8)) - self.menuTools.setTitle(QtGui.QApplication.translate("MainWindow", "Tools", None, QtGui.QApplication.UnicodeUTF8)) - self.actionConnection.setText(QtGui.QApplication.translate("MainWindow", "L&og in", None, QtGui.QApplication.UnicodeUTF8)) - self.actionConnection.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+O", None, QtGui.QApplication.UnicodeUTF8)) - self.actionDeconnection.setText(QtGui.QApplication.translate("MainWindow", "Log out", None, QtGui.QApplication.UnicodeUTF8)) - self.actionOffline_buddies.setText(QtGui.QApplication.translate("MainWindow", "Offline buddies", None, QtGui.QApplication.UnicodeUTF8)) - self.actionAway_buddies.setText(QtGui.QApplication.translate("MainWindow", "Away buddies", None, QtGui.QApplication.UnicodeUTF8)) - self.actionAbout.setText(QtGui.QApplication.translate("MainWindow", "About pyTalk", None, QtGui.QApplication.UnicodeUTF8)) - self.actionAboutQt.setText(QtGui.QApplication.translate("MainWindow", "About Qt", None, QtGui.QApplication.UnicodeUTF8)) - self.actionQuit.setText(QtGui.QApplication.translate("MainWindow", "&Quit", None, QtGui.QApplication.UnicodeUTF8)) - self.actionQuit.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+Q", None, QtGui.QApplication.UnicodeUTF8)) - self.actionAdd_a_buddy.setText(QtGui.QApplication.translate("MainWindow", "Add a buddy", None, QtGui.QApplication.UnicodeUTF8)) - self.actionAdd_a_group.setText(QtGui.QApplication.translate("MainWindow", "Add a group", None, QtGui.QApplication.UnicodeUTF8)) - self.actionPreferences.setText(QtGui.QApplication.translate("MainWindow", "&Preferences", None, QtGui.QApplication.UnicodeUTF8)) - self.actionPreferences.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+P", None, QtGui.QApplication.UnicodeUTF8)) - self.actionConsole.setText(QtGui.QApplication.translate("MainWindow", "XML Console", None, QtGui.QApplication.UnicodeUTF8)) +from jabber import STATUS +from BuddyList import BuddyList + +from ui.ConnectionDialog import ConnectionDialog +from ConnectorThread import ConnectorThread + +class MainWindow(QtGui.QMainWindow): + + def __init__(self, parent=None): + QtGui.QMainWindow.__init__(self, parent) + + self.connectorThread = None + + self.setObjectName("MainWindow") + self.setMaximumWidth(300) + self.setMaximumHeight(600) + + #self.resize(QtCore.QSize(QtCore.QRect(0,0,316,407).size()).expandedTo(MainWindow.minimumSizeHint())) + self.setWindowIcon(QtGui.QIcon("images/im-jabber.png")) + self.setUnifiedTitleAndToolBarOnMac(False) + + ## Central Widget and Layout + self.centralwidget = QtGui.QWidget() + #self.centralwidget.setObjectName("centralwidget") + + self.vboxlayout = QtGui.QVBoxLayout(self.centralwidget) + #self.vboxlayout.setObjectName("vboxlayout") + + self.statusCombo = QtGui.QComboBox(self.centralwidget) + #self.statusBox.setObjectName("statusBox") + self.vboxlayout.addWidget(self.statusCombo) + + self.statusEdit = QtGui.QLineEdit(self.centralwidget) + #self.statusEdit.setObjectName("statusEdit") + self.vboxlayout.addWidget(self.statusEdit) + self.setCentralWidget(self.centralwidget) + + self.menubar = QtGui.QMenuBar() + self.menubar.setGeometry(QtCore.QRect(0,0,316,29)) + #self.menubar.setObjectName("menubar") + + self.menuContacts = QtGui.QMenu(self.menubar) + #self.menuContacts.setObjectName("menuContacts") + + self.menuAffichage = QtGui.QMenu(self.menubar) + #self.menuAffichage.setObjectName("menuAffichage") + + self.menuHelp = QtGui.QMenu(self.menubar) + self.menuHelp.setObjectName("menuHelp") + + self.menuBuddies = QtGui.QMenu(self.menubar) + self.menuBuddies.setObjectName("menuBuddies") + + self.menuTools = QtGui.QMenu(self.menubar) + self.menuTools.setObjectName("menuTools") + self.setMenuBar(self.menubar) + + self.actionConnection = QtGui.QAction(self) + self.actionConnection.setIcon(QtGui.QIcon("images/status/log-in.png")) + self.actionConnection.setObjectName("actionConnection") + + self.actionDeconnection = QtGui.QAction(self) + self.actionDeconnection.setEnabled(False) + self.actionDeconnection.setIcon(QtGui.QIcon("images/status/log-out.png")) + self.actionDeconnection.setObjectName("actionDeconnection") + + self.actionOffline_buddies = QtGui.QAction(self) + self.actionOffline_buddies.setCheckable(True) + self.actionOffline_buddies.setObjectName("actionOffline_buddies") + + self.actionAway_buddies = QtGui.QAction(self) + self.actionAway_buddies.setCheckable(True) + self.actionAway_buddies.setChecked(True) + self.actionAway_buddies.setObjectName("actionAway_buddies") + + self.actionAbout = QtGui.QAction(self) + self.actionAbout.setIcon(QtGui.QIcon("images/about.png")) + self.actionAbout.setObjectName("actionAbout") + + self.actionAboutQt = QtGui.QAction(self) + self.actionAboutQt.setIcon(QtGui.QIcon("images/qt4.png")) + self.actionAboutQt.setObjectName("actionAboutQt") + + self.actionQuit = QtGui.QAction(self) + self.actionQuit.setIcon(QtGui.QIcon("images/exit.png")) + self.actionQuit.setObjectName("actionQuit") + + self.actionAdd_a_buddy = QtGui.QAction(self) + self.actionAdd_a_buddy.setIcon(QtGui.QIcon("images/plus.png")) + self.actionAdd_a_buddy.setObjectName("actionAdd_a_buddy") + + self.actionAdd_a_group = QtGui.QAction(self) + self.actionAdd_a_group.setIcon(QtGui.QIcon("images/plus.png")) + self.actionAdd_a_group.setObjectName("actionAdd_a_group") + + self.actionPreferences = QtGui.QAction(self) + self.actionPreferences.setIcon(QtGui.QIcon("images/preferences.png")) + self.actionPreferences.setObjectName("actionPreferences") + + self.actionConsole = QtGui.QAction(self) + self.actionConsole.setObjectName("actionConsole") + self.menuContacts.addAction(self.actionConnection) + self.menuContacts.addAction(self.actionDeconnection) + self.menuContacts.addAction(self.actionQuit) + self.menuAffichage.addAction(self.actionOffline_buddies) + self.menuAffichage.addAction(self.actionAway_buddies) + self.menuHelp.addAction(self.actionAbout) + self.menuHelp.addAction(self.actionAboutQt) + self.menuBuddies.addAction(self.actionAdd_a_buddy) + self.menuBuddies.addAction(self.actionAdd_a_group) + self.menuTools.addAction(self.actionPreferences) + self.menuTools.addAction(self.actionConsole) + self.menubar.addAction(self.menuContacts.menuAction()) + self.menubar.addAction(self.menuBuddies.menuAction()) + self.menubar.addAction(self.menuAffichage.menuAction()) + self.menubar.addAction(self.menuTools.menuAction()) + self.menubar.addAction(self.menuHelp.menuAction()) + + self.console = QtGui.QDialog() + self.te = QtGui.QTextEdit(self.console) + self.te.setReadOnly(True) + vl = QtGui.QVBoxLayout() + vl.addWidget(self.te) + self.console.setLayout(vl) + + # Set status Offline + self.statusCombo.setCurrentIndex(5) + self.statusEdit.hide() + + # Set connect + self.connect(self.statusCombo, SIGNAL("currentIndexChanged(int)"), self.on_change_status) + self.connect(self.statusEdit, SIGNAL("returnPressed()"), self.on_change_status) + + # Set BuddyList + self.buddyList = BuddyList(self) + self.vboxlayout.insertWidget(0, self.buddyList) + self.connect(self.buddyList, SIGNAL("rename"), self.on_add_buddy) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(self) + + + + # Connection + """ + connection = ConnectionDialog(self) + self.connect(self.actionConnection, SIGNAL("triggered()"), connection, SLOT("exec()")) + self.connect(self.actionDeconnection, SIGNAL("triggered()"), self.disconnect) + self.connect(connection, SIGNAL("configured()"), self.on_connection) + """ + + # Contacts + self.connect(self.actionAdd_a_buddy, SIGNAL("triggered()"), self.on_add_buddy) + self.connect(self.actionAdd_a_group, SIGNAL("triggered()"), self.on_add_group) + + # View + self.connect(self.actionAway_buddies, SIGNAL("toogled()"), self.setAway) + self.connect(self.actionOffline_buddies, SIGNAL("toogled()"), self.setOffline) + self.connect(self.actionAway_buddies, SIGNAL("triggered()"), self.setAway) + self.connect(self.actionOffline_buddies, SIGNAL("triggered()"), self.setOffline) + + # Tools + self.connect(self.actionConsole, SIGNAL("triggered()"), self.swapConsole) + + # About Dialog + """ + about = AboutDialog(self) + self.connect(self.actionAbout, SIGNAL("triggered()"), about, SLOT("exec()")) + self.connect(self.actionAboutQt, SIGNAL("triggered()"), QApplication.instance(), SLOT("aboutQt()")) + """ + + # Quit Signal connection + self.connect(self.actionQuit, SIGNAL("triggered()"), self.quit) + + ## Show the Connection dialog after a few moments + QtCore.QTimer.singleShot(500, self.show_connection_dialog) + + def retranslateUi(self, MainWindow): + self.setWindowTitle(QtGui.QApplication.translate("MainWindow", "PyTalk", None, QtGui.QApplication.UnicodeUTF8)) + + self.statusCombo.addItem(QtGui.QIcon("images/status/available.png"),QtGui.QApplication.translate("MainWindow", "Available", None, QtGui.QApplication.UnicodeUTF8)) + self.statusCombo.addItem(QtGui.QIcon("images/status/chat.png"),QtGui.QApplication.translate("MainWindow", "Chat", None, QtGui.QApplication.UnicodeUTF8)) + self.statusCombo.addItem(QtGui.QIcon("images/status/busy.png"),QtGui.QApplication.translate("MainWindow", "Do not disturb", None, QtGui.QApplication.UnicodeUTF8)) + self.statusCombo.addItem(QtGui.QIcon("images/status/away.png"),QtGui.QApplication.translate("MainWindow", "Away", None, QtGui.QApplication.UnicodeUTF8)) + self.statusCombo.addItem(QtGui.QIcon("images/status/extended-away.png"),QtGui.QApplication.translate("MainWindow", "Extended Away", None, QtGui.QApplication.UnicodeUTF8)) + self.statusCombo.addItem(QtGui.QIcon("images/status/offline.png"),QtGui.QApplication.translate("MainWindow", "Offline", None, QtGui.QApplication.UnicodeUTF8)) + + self.menuContacts.setTitle(QtGui.QApplication.translate("MainWindow", "Account", None, QtGui.QApplication.UnicodeUTF8)) + self.menuAffichage.setTitle(QtGui.QApplication.translate("MainWindow", "View", None, QtGui.QApplication.UnicodeUTF8)) + self.menuHelp.setTitle(QtGui.QApplication.translate("MainWindow", "Help", None, QtGui.QApplication.UnicodeUTF8)) + self.menuBuddies.setTitle(QtGui.QApplication.translate("MainWindow", "Buddies", None, QtGui.QApplication.UnicodeUTF8)) + self.menuTools.setTitle(QtGui.QApplication.translate("MainWindow", "Tools", None, QtGui.QApplication.UnicodeUTF8)) + self.actionConnection.setText(QtGui.QApplication.translate("MainWindow", "L&og in", None, QtGui.QApplication.UnicodeUTF8)) + self.actionConnection.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+O", None, QtGui.QApplication.UnicodeUTF8)) + self.actionDeconnection.setText(QtGui.QApplication.translate("MainWindow", "Log out", None, QtGui.QApplication.UnicodeUTF8)) + self.actionOffline_buddies.setText(QtGui.QApplication.translate("MainWindow", "Offline buddies", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAway_buddies.setText(QtGui.QApplication.translate("MainWindow", "Away buddies", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAbout.setText(QtGui.QApplication.translate("MainWindow", "About pyTalk", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAboutQt.setText(QtGui.QApplication.translate("MainWindow", "About Qt", None, QtGui.QApplication.UnicodeUTF8)) + self.actionQuit.setText(QtGui.QApplication.translate("MainWindow", "&Quit", None, QtGui.QApplication.UnicodeUTF8)) + self.actionQuit.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+Q", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAdd_a_buddy.setText(QtGui.QApplication.translate("MainWindow", "Add a buddy", None, QtGui.QApplication.UnicodeUTF8)) + self.actionAdd_a_group.setText(QtGui.QApplication.translate("MainWindow", "Add a group", None, QtGui.QApplication.UnicodeUTF8)) + self.actionPreferences.setText(QtGui.QApplication.translate("MainWindow", "&Preferences", None, QtGui.QApplication.UnicodeUTF8)) + self.actionPreferences.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+P", None, QtGui.QApplication.UnicodeUTF8)) + self.actionConsole.setText(QtGui.QApplication.translate("MainWindow", "XML Console", None, QtGui.QApplication.UnicodeUTF8)) + + + + def show_connection_dialog(self): + d = ConnectionDialog(self) + if d.exec_(): + self.on_connection() + self.on_change_status(0) + #self.statusCombo.set + + def on_connection(self, status=STATUS.available): + if not self.connectorThread: + self.connectorThread = ConnectorThread(status) + self.connectorThread.start() + self.connect(self.connectorThread, SIGNAL("message"), self.buddyList.message) + self.connect(self.connectorThread, SIGNAL("error"), self.error) + self.connect(self.connectorThread, SIGNAL("connected()"), self.connected) + self.connect(self.connectorThread, SIGNAL("disconnected()"), self.disconnect) + self.connect(self.connectorThread, SIGNAL("presence"), self.buddyList.presence) + self.connect(self.connectorThread, SIGNAL("debug"), self.debug) + self.connect(self.connectorThread, SIGNAL("subscriptionRequest"), self.subscriptionRequest) + self.connect(self.connectorThread, SIGNAL("addBuddy"), self.on_add_buddy) + + elif self.connectorThread.isConnected(): + self.connectorThread.change_status(status, self.statusEdit.text()) + self.statusEdit.clearFocus() + + def disconnect(self): + self.actionConnection.setEnabled(True) + self.actionDeconnection.setEnabled(False) + self.statusEdit.hide() + self.statusBox.setCurrentIndex(STATUS.unavailable.index) + if self.connectorThread: + self.connectorThread.disconnect() + self.connectorThread = None + self.BuddyList.clear() + QtGui.QApplication.instance().quit() + + + def connected(self): + self.actionConnection.setEnabled(False) + self.actionDeconnection.setEnabled(True) + if self.statusCombo.currentIndex() == STATUS.unavailable: + self.statusCombo.setCurrentIndex(STATUS.available) + else: + self.connectorThread.set_status(self.statusCombo.currentIndex(), self.statusEdit.text()) + self.statusEdit.show() + self.statusEdit.setFocus() + self.BuddyList.setConnection(self.connectorThread) + self.getRoster() + self.setAway() + self.setOffline() + + def error(self, title, content): + QtGui.QMessageBox.critical(self, title, content, QtGui.QMessageBox.Ok) + + def closeEvent(self, event): + self.quit() + + def quit(self): + self.disconnect() + sys.exit(0) + + def on_change_status(self, index=-1): + print "on_status", index + if index == -1: + index = self.statusBox.currentIndex() + if index == STATUS.unavailable: + self.statusEdit.hide() + self.disconnect() + #else: + # self.connection(index) + + def getRoster(self): + roster = self.connectorThread.getRoster() + for buddy in roster: + self.buddyList.add_item(buddy) + self.connect(self.buddyList, SIGNAL("itemDoubleClicked(QTreeWidgetItem *,int)"), self.on_send_message) + + def on_send_message(self, item, col): + print "on_send_message", item, col + if item and item.type() == QtGui.QTreeWidgetItem.UserType+1: + item.sendMessage() + + def setAway(self, checked=-1): + if checked == -1: + checked = self.actionAway_buddies.isChecked() + self.BuddyList.setAway(not checked) + + def setOffline(self, checked=-1): + if checked == -1: + checked = self.actionOffline_buddies.isChecked() + self.BuddyList.setOffline(not checked) + + def subscriptionRequest(self, presence): + request = RosterRequest(self, self.connectorThread.jabber, presence) + request.show() + + def debug(self, message): + self.te.append(datetime.datetime.now().strftime("[%H:%M:%S]")+" : \n"+message) + + def swapConsole(self): + self.console.setWindowTitle("XML Console") + self.console.resize(QtCore.QSize(1024, 500)) + self.console.show() + self.console.raise_() + + def on_add_buddy(self, item=None): + if self.connectorThread: + if item: + jid = item.jid + else: + jid = "" + newBuddy = AddBuddyDialog(self, self.connectorThread.jabber, self.BuddyList.groups.keys(), jid) + newBuddy.show() + + def on_add_group(self): + newGroup = AddGroupDialog(self, self.BuddyList) + newGroup.show() From 2e1cffecdef22538b8e48e9c00e111f31023a9ad Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Sun, 19 May 2013 18:29:05 +0100 Subject: [PATCH 3/4] buddyList --- pytalk/BuddyList.py | 2 +- pytalk/ConnectorThread.py | 8 +++++--- pytalk/jabber.py | 2 +- pytalk/pytalk.py | 5 +++++ pytalk/ui/MainWindow.py | 24 ++++++++++++++++-------- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/pytalk/BuddyList.py b/pytalk/BuddyList.py index e940360..a43f0ea 100644 --- a/pytalk/BuddyList.py +++ b/pytalk/BuddyList.py @@ -37,7 +37,7 @@ def setConnection(self, con): def add_item(self, jid): if self.connection: group = self.connection.getGroups(jid)[0] - self.addGroup(group) + self.add_group(group) if jid not in self.buddies.keys(): self.buddies[jid] = BuddyItem(self.groups[group],jid, self.connection) self.buddies[jid].setName(self.connection.getName(jid)) diff --git a/pytalk/ConnectorThread.py b/pytalk/ConnectorThread.py index 3cb6738..0922e97 100644 --- a/pytalk/ConnectorThread.py +++ b/pytalk/ConnectorThread.py @@ -7,7 +7,7 @@ import platform from PyQt4.QtCore import QSettings, QVariant, QThread, SIGNAL from PyQt4.QtGui import QMessageBox -from jabber import STATUS +from jabber import STATUS, STATUS_TEXT class ConnectorThread(QThread): """ @@ -15,10 +15,12 @@ class ConnectorThread(QThread): Jabber server and the PyTalk client. """ - def __init__(self, status): + def __init__(self, status, debug=True): "We initialise a new Thread and create the connection with the Jabber Server" QThread.__init__(self) + self.status = status + self.debug = debug def run(self): "We are running the thread and are reading and sending informations to the Jabber server" @@ -118,7 +120,7 @@ def set_status(self, showId, status): """Send a presence packet""" print "change_status", showId, status p = xmpp.protocol.Presence() - p.setShow(STATUS_TEST[showId]) + p.setShow(STATUS_TEXT[showId]) if status: p.setStatus(status) if showId == STATUS.available: diff --git a/pytalk/jabber.py b/pytalk/jabber.py index 50ee372..0d3644f 100644 --- a/pytalk/jabber.py +++ b/pytalk/jabber.py @@ -15,6 +15,6 @@ class STATUS: invisible = 6 DEADSTATUS = Enum('available', 'chat', 'dnd', 'away', 'xa', 'unavailable', 'invisible') -STATUS_TEST = ['available', 'chat', 'dnd', 'away', 'xa', 'unavailable', 'invisible'] +STATUS_TEXT = ['available', 'chat', 'dnd', 'away', 'xa', 'unavailable', 'invisible'] DISPLAY_STATUS = (tr('Available'), tr('Chat'), tr('Do not Disturb'), tr('Away'), tr('Unavailable'), tr('Offline'), tr('Invisible')) STATUS_IMAGE = ('available.png', 'chat.png', 'busy.png', 'away.png', 'extended-away.png', 'offline.png', 'offline.png') diff --git a/pytalk/pytalk.py b/pytalk/pytalk.py index 2504ae0..48c461d 100755 --- a/pytalk/pytalk.py +++ b/pytalk/pytalk.py @@ -8,6 +8,7 @@ if not project_path in sys.path: sys.path.append(project_path) """ +import settings inc_paths = ["enum-0.4.3", "pydns-2.3.1", "xmpppy-CVS20080120"] @@ -212,6 +213,10 @@ def addGroup(self): if __name__ == "__main__": app = QApplication(sys.argv) + app.setOrganizationName( "GSTL" ); + app.setOrganizationDomain( "pytalk.trunat.fr" ); + app.setApplicationName( settings.APPNAME ); + app.setApplicationVersion( settings.VERSION ); window = MainWindow() window.show() sys.exit(app.exec_()) diff --git a/pytalk/ui/MainWindow.py b/pytalk/ui/MainWindow.py index 9e5d0c3..805ac2e 100644 --- a/pytalk/ui/MainWindow.py +++ b/pytalk/ui/MainWindow.py @@ -4,7 +4,7 @@ import datetime from PyQt4 import QtCore, QtGui -from PyQt4.QtCore import SIGNAL +from PyQt4.QtCore import SIGNAL, SLOT from jabber import STATUS @@ -28,6 +28,9 @@ def __init__(self, parent=None): self.setWindowIcon(QtGui.QIcon("images/im-jabber.png")) self.setUnifiedTitleAndToolBarOnMac(False) + toolbar = QtGui.QToolBar() + self.addToolBar(QtCore.Qt.TopToolBarArea, toolbar) + ## Central Widget and Layout self.centralwidget = QtGui.QWidget() #self.centralwidget.setObjectName("centralwidget") @@ -66,7 +69,6 @@ def __init__(self, parent=None): self.actionConnection = QtGui.QAction(self) self.actionConnection.setIcon(QtGui.QIcon("images/status/log-in.png")) - self.actionConnection.setObjectName("actionConnection") self.actionDeconnection = QtGui.QAction(self) self.actionDeconnection.setEnabled(False) @@ -108,8 +110,13 @@ def __init__(self, parent=None): self.actionConsole = QtGui.QAction(self) self.actionConsole.setObjectName("actionConsole") + self.menuContacts.addAction(self.actionConnection) + toolbar.addAction(self.actionConnection) + self.menuContacts.addAction(self.actionDeconnection) + toolbar.addAction(self.actionDeconnection) + self.menuContacts.addAction(self.actionQuit) self.menuAffichage.addAction(self.actionOffline_buddies) self.menuAffichage.addAction(self.actionAway_buddies) @@ -175,8 +182,9 @@ def __init__(self, parent=None): """ about = AboutDialog(self) self.connect(self.actionAbout, SIGNAL("triggered()"), about, SLOT("exec()")) - self.connect(self.actionAboutQt, SIGNAL("triggered()"), QApplication.instance(), SLOT("aboutQt()")) """ + self.connect(self.actionAboutQt, SIGNAL("triggered()"), QtGui.QApplication.instance(), SLOT("aboutQt()")) + # Quit Signal connection self.connect(self.actionQuit, SIGNAL("triggered()"), self.quit) @@ -248,7 +256,7 @@ def disconnect(self): if self.connectorThread: self.connectorThread.disconnect() self.connectorThread = None - self.BuddyList.clear() + self.buddyList.clear() QtGui.QApplication.instance().quit() @@ -261,7 +269,7 @@ def connected(self): self.connectorThread.set_status(self.statusCombo.currentIndex(), self.statusEdit.text()) self.statusEdit.show() self.statusEdit.setFocus() - self.BuddyList.setConnection(self.connectorThread) + self.buddyList.setConnection(self.connectorThread) self.getRoster() self.setAway() self.setOffline() @@ -300,12 +308,12 @@ def on_send_message(self, item, col): def setAway(self, checked=-1): if checked == -1: checked = self.actionAway_buddies.isChecked() - self.BuddyList.setAway(not checked) + self.buddyList.setAway(not checked) def setOffline(self, checked=-1): if checked == -1: checked = self.actionOffline_buddies.isChecked() - self.BuddyList.setOffline(not checked) + self.buddyList.setOffline(not checked) def subscriptionRequest(self, presence): request = RosterRequest(self, self.connectorThread.jabber, presence) @@ -326,7 +334,7 @@ def on_add_buddy(self, item=None): jid = item.jid else: jid = "" - newBuddy = AddBuddyDialog(self, self.connectorThread.jabber, self.BuddyList.groups.keys(), jid) + newBuddy = AddBuddyDialog(self, self.connectorThread.jabber, self.buddyList.groups.keys(), jid) newBuddy.show() def on_add_group(self): From 81f4e297b5b16f1b5fe8358ea216b5925f95021b Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Sun, 19 May 2013 18:43:49 +0100 Subject: [PATCH 4/4] status box --- pytalk/ui/MainWindow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytalk/ui/MainWindow.py b/pytalk/ui/MainWindow.py index 805ac2e..9a68fa3 100644 --- a/pytalk/ui/MainWindow.py +++ b/pytalk/ui/MainWindow.py @@ -252,7 +252,7 @@ def disconnect(self): self.actionConnection.setEnabled(True) self.actionDeconnection.setEnabled(False) self.statusEdit.hide() - self.statusBox.setCurrentIndex(STATUS.unavailable.index) + self.statusCombo.setCurrentIndex(STATUS.unavailable.index) if self.connectorThread: self.connectorThread.disconnect() self.connectorThread = None @@ -287,7 +287,7 @@ def quit(self): def on_change_status(self, index=-1): print "on_status", index if index == -1: - index = self.statusBox.currentIndex() + index = self.statusCombo.currentIndex() if index == STATUS.unavailable: self.statusEdit.hide() self.disconnect()