# HG changeset patch # User Dirk Olmes # Date 1274063455 -7200 # Node ID 4b0d686493fbedfae2cb7f0a22b97f0f850042e6 # Parent 6eba4168fd548c9aea97909aa05c4543e03b1cef better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed. diff -r 6eba4168fd54 -r 4b0d686493fb AddFeed.py --- a/AddFeed.py Mon May 17 03:52:13 2010 +0200 +++ b/AddFeed.py Mon May 17 04:30:55 2010 +0200 @@ -4,15 +4,21 @@ import FeedUpdater class AddFeed(QtGui.QDialog): - def __init__(self, session=None): + def __init__(self, session): QtGui.QWidget.__init__(self, None) self.session = session + self.exception = None self.ui = Ui_AddFeed() self.ui.setupUi(self) self.ui.url.setFocus() def accept(self): - self.createFeed() + try: + self.createFeed() + self.session.commit() + except AttributeError as ae: + self.exception = ae + self.session.rollback() QtGui.QDialog.accept(self) def createFeed(self): diff -r 6eba4168fd54 -r 4b0d686493fb FeedUpdater.py --- a/FeedUpdater.py Mon May 17 03:52:13 2010 +0200 +++ b/FeedUpdater.py Mon May 17 04:30:55 2010 +0200 @@ -25,10 +25,8 @@ title = result["feed"].title newFeed = Feed(title, url) session.add(newFeed) - session.commit() FeedUpdater(session, newFeed).update() - session.commit() class FeedUpdater(object): def __init__(self, session, feed): diff -r 6eba4168fd54 -r 4b0d686493fb MainWindow.py --- a/MainWindow.py Mon May 17 03:52:13 2010 +0200 +++ b/MainWindow.py Mon May 17 04:30:55 2010 +0200 @@ -11,6 +11,8 @@ from Ui_MainWindow import Ui_MainWindow import subprocess +STATUS_MESSAGE_DISPLAY_MILLIS = 20000 + class MainWindow(QtGui.QMainWindow): def __init__(self, session=None): QtGui.QWidget.__init__(self, None) @@ -66,7 +68,14 @@ def addFeed(self): addFeed = AddFeed(self.session) success = addFeed.exec_() - if success: + if not success: + return + + if addFeed.exception is not None: + message = "Error while adding feed: " + str(addFeed.exception) + self.ui.statusbar.showMessage(message, STATUS_MESSAGE_DISPLAY_MILLIS) + else: + self.session.commit() self.updateFeedList() def openSelectedEntryInBrowser(self):