diff --git a/TODO b/TODO index 72a7929..d0913ce 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,5 @@ Bugs: -* heartbeat -- ping IRC occasionally so we pick up on send errors +* idle doesnt seem to work? * X and _ buttons move around all crazy like Features: diff --git a/convo.pyc b/convo.pyc index 9c49df2..c5603c4 100644 Binary files a/convo.pyc and b/convo.pyc differ diff --git a/dataobjs.pyc b/dataobjs.pyc index c5afea2..842d578 100644 Binary files a/dataobjs.pyc and b/dataobjs.pyc differ diff --git a/generic.pyc b/generic.pyc index c06f528..eb2a7f0 100644 Binary files a/generic.pyc and b/generic.pyc differ diff --git a/irc.py b/irc.py index 65b087b..2ab9dfe 100644 --- a/irc.py +++ b/irc.py @@ -11,9 +11,9 @@ from generic import PesterList logging.basicConfig(level=logging.INFO) -class PesterIRC(QtCore.QObject): +class PesterIRC(QtCore.QThread): def __init__(self, config, window): - QtCore.QObject.__init__(self) + QtCore.QThread.__init__(self) self.mainwindow = window self.config = config def IRCConnect(self): @@ -25,15 +25,41 @@ class PesterIRC(QtCore.QObject): self.conn = self.cli.connect() self.brokenConnection = False self.registeredIRC = False - def closeConnection(self): - if self.cli: - self.cli.close() - self.cli = None - def setConnectionBroken(self, broken=True): - self.brokenConnection = True + def run(self): + self.IRCConnect() + while 1: + try: + self.updateIRC() + except socket.error, se: + if self.registeredIRC: + self.stopIRC = None + else: + self.stopIRC = se + return + def setConnected(self): self.registeredIRC = True self.connected.emit() + def setConnectionBroken(self): + self.reconnectIRC() + #self.brokenConnection = True + @QtCore.pyqtSlot() + def updateIRC(self): + try: + res = self.conn.next() + except socket.timeout, se: + if self.registeredIRC: + return + else: + raise se + except socket.error, se: + raise se + except StopIteration: + pass + @QtCore.pyqtSlot() + def reconnectIRC(self): + self.cli.close() + @QtCore.pyqtSlot(PesterProfile) def getMood(self, *chums): self.cli.command_handler.getMood(*chums) @@ -163,12 +189,6 @@ class PesterIRC(QtCore.QObject): helpers.mode(self.cli, c, m, cmd) except socket.error: self.setConnectionBroken() - @QtCore.pyqtSlot() - def reconnectIRC(self): - self.setConnectionBroken() - - def updateIRC(self): - return self.conn.next() moodUpdated = QtCore.pyqtSignal(QtCore.QString, Mood) colorUpdated = QtCore.pyqtSignal(QtCore.QString, QtGui.QColor) diff --git a/irc.pyc b/irc.pyc index 72d93e6..6316cb7 100644 Binary files a/irc.pyc and b/irc.pyc differ diff --git a/memos.pyc b/memos.pyc index 653c3ad..9f5bc94 100644 Binary files a/memos.pyc and b/memos.pyc differ diff --git a/menus.pyc b/menus.pyc index 8ac4074..91ec0d4 100644 Binary files a/menus.pyc and b/menus.pyc differ diff --git a/mispeller.pyc b/mispeller.pyc index e86c8b3..86893fb 100644 Binary files a/mispeller.pyc and b/mispeller.pyc differ diff --git a/oyoyo/__init__.pyc b/oyoyo/__init__.pyc index f108745..952ac0c 100644 Binary files a/oyoyo/__init__.pyc and b/oyoyo/__init__.pyc differ diff --git a/oyoyo/client.py b/oyoyo/client.py index 7ab7368..f9db258 100644 --- a/oyoyo/client.py +++ b/oyoyo/client.py @@ -82,6 +82,7 @@ class IRCClient: ... """ self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + print "initalizing socket %d" % (self.socket.fileno()) self.nick = None self.real_name = None self.host = None @@ -200,16 +201,16 @@ class IRCClient: if self.socket: logging.info('closing socket') self.socket.close() - print se raise se else: if self.socket: logging.info('closing socket') self.socket.close() def close(self): + # with extreme prejudice if self.socket: - logging.info('closing socket') - self.socket.close() + logging.info('shutdown socket') + self.socket.shutdown(socket.SHUT_RDWR) class IRCApp: """ This class manages several IRCClient instances without the use of threads. diff --git a/oyoyo/client.pyc b/oyoyo/client.pyc index 0b9cca5..6a2701c 100644 Binary files a/oyoyo/client.pyc and b/oyoyo/client.pyc differ diff --git a/oyoyo/cmdhandler.pyc b/oyoyo/cmdhandler.pyc index 57d62ba..1e5a248 100644 Binary files a/oyoyo/cmdhandler.pyc and b/oyoyo/cmdhandler.pyc differ diff --git a/oyoyo/helpers.pyc b/oyoyo/helpers.pyc index 8a68fc5..d3283be 100644 Binary files a/oyoyo/helpers.pyc and b/oyoyo/helpers.pyc differ diff --git a/oyoyo/ircevents.pyc b/oyoyo/ircevents.pyc index 51fd341..f8955a6 100644 Binary files a/oyoyo/ircevents.pyc and b/oyoyo/ircevents.pyc differ diff --git a/oyoyo/parse.pyc b/oyoyo/parse.pyc index 79ddf44..d6fd479 100644 Binary files a/oyoyo/parse.pyc and b/oyoyo/parse.pyc differ diff --git a/parsetools.pyc b/parsetools.pyc index 97122b3..ded990b 100644 Binary files a/parsetools.pyc and b/parsetools.pyc differ diff --git a/pesterchum.py b/pesterchum.py index 7d20616..e917a0b 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -820,9 +820,6 @@ class PesterWindow(MovingWindow): if not self.config.defaultprofile(): self.changeProfile() - self.loadingscreen = LoadingScreen(self) - self.connect(self.loadingscreen, QtCore.SIGNAL('rejected()'), - self, QtCore.SLOT('close()')) def profile(self): return self.userprofile.chat @@ -1618,6 +1615,9 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot(QtCore.QString, QtCore.QString) def nickCollision(self, handle, tmphandle): self.mychumhandle.setText(tmphandle) + self.userprofile = userProfile(PesterProfile("pesterClient%d" % (random.randint(100,999)), QtGui.QColor("black"), Mood(0))) + self.changeTheme(self.userprofile.getTheme()) + if not hasattr(self, 'chooseprofile'): self.chooseprofile = None if not self.chooseprofile: @@ -1660,44 +1660,6 @@ class PesterWindow(MovingWindow): closeSignal = QtCore.pyqtSignal() reconnectIRC = QtCore.pyqtSignal() -class IRCThread(QtCore.QThread): - def __init__(self, ircobj): - QtCore.QThread.__init__(self) - self.irc = ircobj - def run(self): - irc = self.irc - irc.IRCConnect() - timer = QtCore.QTimer(self) - self.connect(timer, QtCore.SIGNAL('timeout()'), - self, QtCore.SLOT('updateIRC()')) - timer.start() - self.exec_() - @QtCore.pyqtSlot() - def updateIRC(self): - irc = self.irc - if irc.brokenConnection: - irc.brokenConnection = False - self.restartIRC.emit() - irc.closeConnection() - irc.IRCConnect() - try: - res = irc.updateIRC() - except socket.timeout, se: - if not irc.registeredIRC: - irc.closeConnection() - self.failedIRC.emit("Connection timed out") - except socket.error, se: - if irc.registeredIRC: - irc.setConnectionBroken() - else: - irc.closeConnection() - self.failedIRC.emit(str(se)) - except StopIteration: - pass - - restartIRC = QtCore.pyqtSignal() - failedIRC = QtCore.pyqtSignal(QtCore.QString) - class PesterTray(QtGui.QSystemTrayIcon): def __init__(self, icon, mainwindow, parent): QtGui.QSystemTrayIcon.__init__(self, icon, parent) @@ -1764,164 +1726,113 @@ class MainProgram(QtCore.QObject): QtCore.SLOT('mainWindowClosed()')) self.irc = PesterIRC(self.widget.config, self.widget) - self.connectWidgets(self.irc, self.widget) - self.ircapp = IRCThread(self.irc) - self.connect(self.ircapp, QtCore.SIGNAL('restartIRC()'), + self.connect(self.irc, QtCore.SIGNAL('finished()'), self, QtCore.SLOT('restartIRC()')) - self.connect(self.ircapp, QtCore.SIGNAL('failedIRC(QString)'), - self, QtCore.SLOT('failedIRC(QString)')) + self.connectWidgets(self.irc, self.widget) + widget2irc = [('sendMessage(QString, QString)', + 'sendMessage(QString, QString)'), + ('newConvoStarted(QString, bool)', + 'startConvo(QString, bool)'), + ('convoClosed(QString)', + 'endConvo(QString)'), + ('profileChanged()', + 'updateProfile()'), + ('moodRequest(PyQt_PyObject)', + 'getMood(PyQt_PyObject)'), + ('moodsRequest(PyQt_PyObject)', + 'getMoods(PyQt_PyObject)'), + ('moodUpdated()', 'updateMood()'), + ('mycolorUpdated()','updateColor()'), + ('blockedChum(QString)', 'blockedChum(QString)'), + ('unblockedChum(QString)', 'unblockedChum(QString)'), + ('requestNames(QString)','requestNames(QString)'), + ('requestChannelList()', 'requestChannelList()'), + ('joinChannel(QString)', 'joinChannel(QString)'), + ('leftChannel(QString)', 'leftChannel(QString)'), + ('kickUser(QString, QString)', + 'kickUser(QString, QString)'), + ('setChannelMode(QString, QString, QString)', + 'setChannelMode(QString, QString, QString)'), + ('reconnectIRC()', 'reconnectIRC()') + ] +# IRC --> Main window + irc2widget = [('connected()', 'connected()'), + ('moodUpdated(QString, PyQt_PyObject)', + 'updateMoodSlot(QString, PyQt_PyObject)'), + ('colorUpdated(QString, QColor)', + 'updateColorSlot(QString, QColor)'), + ('messageReceived(QString, QString)', + 'deliverMessage(QString, QString)'), + ('memoReceived(QString, QString, QString)', + 'deliverMemo(QString, QString, QString)'), + ('nickCollision(QString, QString)', + 'nickCollision(QString, QString)'), + ('namesReceived(QString, PyQt_PyObject)', + 'updateNames(QString, PyQt_PyObject)'), + ('userPresentUpdate(QString, QString, QString)', + 'userPresentUpdate(QString, QString, QString)'), + ('channelListReceived(PyQt_PyObject)', + 'updateChannelList(PyQt_PyObject)'), + ('timeCommand(QString, QString, QString)', + 'timeCommand(QString, QString, QString)') + ] def connectWidgets(self, irc, widget): - irc.connect(widget, QtCore.SIGNAL('sendMessage(QString, QString)'), - irc, QtCore.SLOT('sendMessage(QString, QString)')) - irc.connect(widget, - QtCore.SIGNAL('newConvoStarted(QString, bool)'), - irc, QtCore.SLOT('startConvo(QString, bool)')) - irc.connect(widget, - QtCore.SIGNAL('convoClosed(QString)'), - irc, QtCore.SLOT('endConvo(QString)')) - irc.connect(widget, - QtCore.SIGNAL('profileChanged()'), - irc, - QtCore.SLOT('updateProfile()')) - irc.connect(widget, - QtCore.SIGNAL('moodRequest(PyQt_PyObject)'), - irc, - QtCore.SLOT('getMood(PyQt_PyObject)')) - irc.connect(widget, - QtCore.SIGNAL('moodsRequest(PyQt_PyObject)'), - irc, - QtCore.SLOT('getMoods(PyQt_PyObject)')) - irc.connect(widget, - QtCore.SIGNAL('moodUpdated()'), - irc, - QtCore.SLOT('updateMood()')) - irc.connect(widget, - QtCore.SIGNAL('mycolorUpdated()'), - irc, - QtCore.SLOT('updateColor()')) - irc.connect(widget, - QtCore.SIGNAL('blockedChum(QString)'), - irc, - QtCore.SLOT('blockedChum(QString)')) - irc.connect(widget, - QtCore.SIGNAL('unblockedChum(QString)'), - irc, - QtCore.SLOT('unblockedChum(QString)')) - irc.connect(widget, - QtCore.SIGNAL('requestNames(QString)'), - irc, - QtCore.SLOT('requestNames(QString)')) - irc.connect(widget, - QtCore.SIGNAL('requestChannelList()'), - irc, - QtCore.SLOT('requestChannelList()')) - irc.connect(widget, - QtCore.SIGNAL('joinChannel(QString)'), - irc, - QtCore.SLOT('joinChannel(QString)')) - irc.connect(widget, - QtCore.SIGNAL('leftChannel(QString)'), - irc, - QtCore.SLOT('leftChannel(QString)')) - irc.connect(widget, - QtCore.SIGNAL('kickUser(QString, QString)'), - irc, - QtCore.SLOT('kickUser(QString, QString)')) - irc.connect(widget, - QtCore.SIGNAL('setChannelMode(QString, QString, QString)'), - irc, - QtCore.SLOT('setChannelMode(QString, QString, QString)')) - irc.connect(widget, - QtCore.SIGNAL('reconnectIRC()'), - irc, - QtCore.SLOT('reconnectIRC()')) + for c in self.widget2irc: + self.connect(widget, QtCore.SIGNAL(c[0]), + irc, QtCore.SLOT(c[1])) + for c in self.irc2widget: + self.connect(irc, QtCore.SIGNAL(c[0]), + widget, QtCore.SLOT(c[1])) + def disconnectWidgets(self, irc, widget): + for c in self.widget2irc: + self.disconnect(widget, QtCore.SIGNAL(c[0]), + irc, QtCore.SLOT(c[1])) + for c in self.irc2widget: + self.disconnect(irc, QtCore.SIGNAL(c[0]), + widget, QtCore.SLOT(c[1])) - # IRC --> Main window - irc.connect(irc, QtCore.SIGNAL('connected()'), - widget, QtCore.SLOT('connected()')) - irc.connect(irc, - QtCore.SIGNAL('moodUpdated(QString, PyQt_PyObject)'), - widget, - QtCore.SLOT('updateMoodSlot(QString, PyQt_PyObject)')) - irc.connect(irc, - QtCore.SIGNAL('colorUpdated(QString, QColor)'), - widget, - QtCore.SLOT('updateColorSlot(QString, QColor)')) - irc.connect(irc, - QtCore.SIGNAL('messageReceived(QString, QString)'), - widget, - QtCore.SLOT('deliverMessage(QString, QString)')) - irc.connect(irc, - QtCore.SIGNAL('memoReceived(QString, QString, QString)'), - widget, - QtCore.SLOT('deliverMemo(QString, QString, QString)')) - irc.connect(irc, - QtCore.SIGNAL('nickCollision(QString, QString)'), - widget, - QtCore.SLOT('nickCollision(QString, QString)')) - irc.connect(irc, - QtCore.SIGNAL('namesReceived(QString, PyQt_PyObject)'), - widget, - QtCore.SLOT('updateNames(QString, PyQt_PyObject)')) - irc.connect(irc, - QtCore.SIGNAL('userPresentUpdate(QString, QString, QString)'), - widget, - QtCore.SLOT('userPresentUpdate(QString, QString, QString)')) - irc.connect(irc, - QtCore.SIGNAL('channelListReceived(PyQt_PyObject)'), - widget, - QtCore.SLOT('updateChannelList(PyQt_PyObject)')) - irc.connect(irc, - QtCore.SIGNAL('timeCommand(QString, QString, QString)'), - widget, - QtCore.SLOT('timeCommand(QString, QString, QString)')) + def showLoading(self, widget, msg="CONN3CT1NG"): + self.widget.show() + self.widget.activateWindow() + widget.loadingscreen = LoadingScreen(widget) + widget.loadingscreen.loadinglabel.setText(msg) + self.connect(widget.loadingscreen, QtCore.SIGNAL('rejected()'), + widget, QtCore.SLOT('close()')) + self.connect(self.widget.loadingscreen, QtCore.SIGNAL('tryAgain()'), + self, QtCore.SLOT('tryAgain()')) + status = widget.loadingscreen.exec_() + if status == QtGui.QDialog.Rejected: + sys.exit(0) @QtCore.pyqtSlot() def tryAgain(self): - self.ircapp.quit() - print "Quit?" - + if self.loadingscreen: + self.loadingscreen.accept() + self.restartIRC() @QtCore.pyqtSlot() def restartIRC(self): - # tell ppl that we're restarting - self.widget.show() - self.widget.activateWindow() - self.widget.loadingscreen = LoadingScreen(self.widget) - self.connect(self.widget.loadingscreen, QtCore.SIGNAL('rejected()'), - self.widget, QtCore.SLOT('close()')) - self.connect(self.widget.loadingscreen, QtCore.SIGNAL('tryAgain()'), - self, QtCore.SLOT('tryAgain()')) - status = self.widget.loadingscreen.exec_() - if status == QtGui.QDialog.Rejected: - sys.exit(0) - @QtCore.pyqtSlot(QtCore.QString) - def failedIRC(self, reason): - self.widget.show() - self.widget.activateWindow() - if not self.widget.loadingscreen: - self.widget.loadingscreen = LoadingScreen(self.widget) - self.widget.loadingscreen.loadinglabel.setText("F41L3D: %s" % (reason)) - self.connect(self.widget.loadingscreen, QtCore.SIGNAL('rejected()'), - self.widget, QtCore.SLOT('close()')) - self.connect(self.widget.loadingscreen, QtCore.SIGNAL('tryAgain()'), - self, QtCore.SLOT('tryAgain()')) - status = self.widget.loadingscreen.exec_() - if status == QtGui.QDialog.Rejected: - sys.exit(0) + if self.irc: + self.disconnectWidgets(self.irc, self.widget) + self.disconnect(self.irc, QtCore.SIGNAL('finished()'), + self, QtCore.SLOT('restartIRC()')) + stop = self.irc.stopIRC + del self.irc else: - self.widget.loadingscreen.loadinglabel.setText("F41L3D: %s" % (reason)) + stop = None + if not stop: + self.irc = PesterIRC(self.widget.config, self.widget) + self.connect(self.irc, QtCore.SIGNAL('finished()'), + self, QtCore.SLOT('restartIRC()')) + self.connectWidgets(self.irc, self.widget) + self.irc.start() + self.showLoading(self.widget) + else: + self.showLoading(self.widget, "F41L3D: %s" % stop) def run(self): - self.ircapp.start() - self.widget.loadingscreen = LoadingScreen(self.widget) - self.connect(self.widget.loadingscreen, QtCore.SIGNAL('rejected()'), - self.widget, QtCore.SLOT('close()')) - self.connect(self.widget.loadingscreen, QtCore.SIGNAL('tryAgain()'), - self, QtCore.SLOT('tryAgain()')) - status = self.widget.loadingscreen.exec_() - if status == QtGui.QDialog.Rejected: - sys.exit(0) + self.irc.start() + self.showLoading(self.widget) sys.exit(self.app.exec_()) pesterchum = MainProgram()