annotate MainWindow.py @ 113:04f8cf1558c1

Add a menu item to copy the selected article's link to the clipboard
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 29 Apr 2011 12:15:57 +0200
parents 863599e84269
children e9145e8dd698
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1
27
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
2 from AddFeed import AddFeed
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 19
diff changeset
3 from DisplayModel import DisplayModel
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
4 from Feed import Feed
55
0f9b3e57cff0 pull out FeedEntryItemDelegate into its own file
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 53
diff changeset
5 from FeedEntryItemDelegate import FeedEntryItemDelegate
91
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 90
diff changeset
6 from FeedEntryTableModel import FeedEntryTableModel
48
6e5219e05625 GUI for feed settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 47
diff changeset
7 from FeedSettings import FeedSettings
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
8 from Preferences import Preferences
42
0c0d1760b737 Rename Preferences to PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 40
diff changeset
9 from PreferencesDialog import PreferencesDialog
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 19
diff changeset
10 from PyQt4.QtCore import QUrl
113
04f8cf1558c1 Add a menu item to copy the selected article's link to the clipboard
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 107
diff changeset
11 from PyQt4.QtGui import QApplication
90
a1066e5a8f88 save pending changes when quitting the app
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 89
diff changeset
12 from PyQt4.QtGui import QMainWindow
a1066e5a8f88 save pending changes when quitting the app
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 89
diff changeset
13 from PyQt4.QtGui import QWidget
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 from Ui_MainWindow import Ui_MainWindow
71
228da10cc98b MainWindow relies on FeedList to get the feeds to display now. FeedList has two inner/private classes: one for returning all known feeds and one to return only feeds with unread entries.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
15 import FeedList
37
22214d79ed41 database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 33
diff changeset
16 import subprocess
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17
50
4b0d686493fb 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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 49
diff changeset
18 STATUS_MESSAGE_DISPLAY_MILLIS = 20000
4b0d686493fb 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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 49
diff changeset
19
90
a1066e5a8f88 save pending changes when quitting the app
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 89
diff changeset
20 class MainWindow(QMainWindow):
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
21 def __init__(self, session=None):
90
a1066e5a8f88 save pending changes when quitting the app
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 89
diff changeset
22 QWidget.__init__(self, None)
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
23 self.session = session
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
24 self.preferences = Preferences(session)
14
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
25 self.ui = Ui_MainWindow()
42a225be7e56 first version of the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
26 self.ui.setupUi(self)
27
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
27 self.updateFeedList()
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
28 self.initFeedEntryList()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
29
71
228da10cc98b MainWindow relies on FeedList to get the feeds to display now. FeedList has two inner/private classes: one for returning all known feeds and one to return only feeds with unread entries.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
30 def updateFeedList(self):
228da10cc98b MainWindow relies on FeedList to get the feeds to display now. FeedList has two inner/private classes: one for returning all known feeds and one to return only feeds with unread entries.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
31 self.allFeeds = FeedList.getFeeds(self.session)
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
32 feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString)
15
b1aeb98824c1 Add a list view displaying all feeds
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 14
diff changeset
33 self.ui.feedList.setModel(feedModel)
27
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
34 self.ui.feedList.update()
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
35
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
36 def initFeedEntryList(self):
97
11036eabbc46 use a smaller default row height
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 93
diff changeset
37 # setup the default row height. This must be called before a table model is set
11036eabbc46 use a smaller default row height
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 93
diff changeset
38 self.ui.feedEntryList.verticalHeader().setDefaultSectionSize(20)
11036eabbc46 use a smaller default row height
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 93
diff changeset
39
33
f371d02fa09d mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
40 self.ui.feedEntryList.setItemDelegate(FeedEntryItemDelegate())
91
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 90
diff changeset
41 self.ui.feedEntryList.setModel(FeedEntryTableModel([]))
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 90
diff changeset
42 self.ui.feedEntryList.horizontalHeader().setStretchLastSection(True)
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 27
diff changeset
43
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
44 def feedSelected(self, index):
19
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
45 self.selectedFeed = self.allFeeds[index.row()]
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
46 self.enableFeedRelatedWidgets()
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
47 self.setupFeedEntries()
53
8cca4585eb33 the feed settings menu item starts out disabled and gets enabled once a feed is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 50
diff changeset
48
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
49 def enableFeedRelatedWidgets(self):
53
8cca4585eb33 the feed settings menu item starts out disabled and gets enabled once a feed is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 50
diff changeset
50 self.ui.actionFeedSettings.setEnabled(True)
56
c82f5538733c add a menu item to mark all entries in a feed as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 55
diff changeset
51 self.ui.actionMarkFeedRead.setEnabled(True)
103
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
52 self.ui.actionDeleteFeed.setEnabled(True)
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
53
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
54 def setupFeedEntries(self):
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
55 hideReadEntries = self.preferences.hideReadFeedEntries()
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
56 self.feedEntries = self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries)
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
57 self.initFeedDisplayModel()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
58
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
59 def initFeedDisplayModel(self):
93
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
60 self.setupFeedTableModel()
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
61 self.ui.feedEntryList.update()
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
62 self.setupFeedTableHeaderWidths()
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
63 self.scrollFirstRowInFeedTableToVisible()
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
64
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
65 def setupFeedTableModel(self):
91
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 90
diff changeset
66 model = FeedEntryTableModel(self.feedEntries)
18
35225588b895 add a list view for displaying feed entries from the selected feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
67 self.ui.feedEntryList.setModel(model)
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
68 self.ui.feedEntryList.itemDelegate().entries = self.feedEntries
91
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 90
diff changeset
69
93
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
70 def setupFeedTableHeaderWidths(self):
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
71 width = self.ui.feedEntryList.width()
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
72 firstColumnWidth = int(width * 0.8)
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
73 self.ui.feedEntryList.setColumnWidth(0, firstColumnWidth)
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
74
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
75 def scrollFirstRowInFeedTableToVisible(self):
e030c6bd2d81 when selecting a feed, set the title column width to 80% of the total width
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
76 model = self.ui.feedEntryList.model()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
77 visibleIndex = model.createIndex(0, 0)
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
78 self.ui.feedEntryList.scrollTo(visibleIndex)
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
79
19
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
80 def feedEntrySelected(self, index):
39
0c2578196643 Disable the article menu by default, enable it when the first article is selected
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 37
diff changeset
81 self.ui.menuArticle.setEnabled(True)
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
82
19
6f7003fc6e6d display the summary of the selected feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 18
diff changeset
83 row = index.row()
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 60
diff changeset
84 self.selectedEntry = self.feedEntries[row]
60
d063e4814357 When clicking an entry, it's marked as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 59
diff changeset
85 self.selectedEntry.markRead()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
86
47
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
87 if self.selectedEntry.feed.auto_load_entry_link:
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
88 self.openLinkFromSelectedEntry()
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
89 else:
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
90 self.openSummaryFromSelectedEntry()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
91
104
4f87be5399ff double clicking a feed entry opens it in the external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 103
diff changeset
92 def feedEntryDoubleClicked(self, index):
4f87be5399ff double clicking a feed entry opens it in the external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 103
diff changeset
93 self.ui.menuArticle.setEnabled(True)
4f87be5399ff double clicking a feed entry opens it in the external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 103
diff changeset
94 self.openSelectedEntryInBrowser()
4f87be5399ff double clicking a feed entry opens it in the external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 103
diff changeset
95
47
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
96 def openSummaryFromSelectedEntry(self):
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
97 # TODO this is the wrong base url, figure out the correct one
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
98 baseUrl = QUrl(self.selectedEntry.link)
33
f371d02fa09d mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
99 self.ui.webView.setHtml(self.selectedEntry.summary, baseUrl)
47
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
100
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
101 def openLinkFromSelectedEntry(self):
77
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
102 if self.selectedEntry.feed.always_open_in_browser:
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
103 self.openSelectedEntryInBrowser()
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
104 else:
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
105 self.openSelectedEntryInWebView()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
106
77
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
107 def openSelectedEntryInWebView(self):
82
2dd6e6894772 update the status bar when opening a feed's rss url via WebView or external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 77
diff changeset
108 message = "Open %s ..." % (self.selectedEntry.title)
2dd6e6894772 update the status bar when opening a feed's rss url via WebView or external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 77
diff changeset
109 self._updateStatusBar(message)
47
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
110 url = QUrl(self.selectedEntry.link)
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
111 self.ui.webView.load(url)
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 42
diff changeset
112 self.ui.webView.show()
77
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
113
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
114 def openSelectedEntryInBrowser(self):
84
bacf42da9e36 update the status bar when an article is opened
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 82
diff changeset
115 message = "Open %s in external browser" % (self.selectedEntry.title)
82
2dd6e6894772 update the status bar when opening a feed's rss url via WebView or external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 77
diff changeset
116 self._updateStatusBar(message)
77
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
117 # TODO make browser configurable
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
118 browser = "/usr/local/bin/opera"
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
119 subprocess.Popen([browser, self.selectedEntry.link])
d292ab61ed6f Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 75
diff changeset
120
33
f371d02fa09d mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
121 def toggleReadOnSelectedEntry(self):
f371d02fa09d mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
122 self.selectedEntry.toggleRead()
f371d02fa09d mark unread feed entries bold. Add a menu item to toggle between read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
123 self.session.commit()
75
a8a4cf131a02 Properly update the feed entry list when marking an entry as read/unread
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 74
diff changeset
124 self.ui.feedEntryList.doItemsLayout()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
125
59
daa2731967fe Marking all articles in a feed as read doesn't toggle any more ... it marks all articles as read.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 56
diff changeset
126 def markSelectedFeedRead(self):
daa2731967fe Marking all articles in a feed as read doesn't toggle any more ... it marks all articles as read.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 56
diff changeset
127 self.selectedFeed.markAllEntriesRead()
56
c82f5538733c add a menu item to mark all entries in a feed as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 55
diff changeset
128 self.session.commit()
74
1e6f6ed38dd0 do a proper update when marking all feed entries as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 71
diff changeset
129 self.ui.feedEntryList.doItemsLayout()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
130
105
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
131 def markSelectedEntriesRead(self):
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
132 selectedIndexes = self.ui.feedEntryList.selectedIndexes()
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
133 for index in selectedIndexes:
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
134 # selectedIndexes returns one QModelIndex instance per row/column combo.
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
135 # We are only interested in the rows here so just operate on the first
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
136 # column
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
137 if index.column() == 0:
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
138 row = index.row()
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
139 # use selectedEntry here to ensure it has a valid state after all
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
140 # selected entries are marked read
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
141 self.selectedEntry = self.feedEntries[row]
107
863599e84269 do not toggle selected feed entries' read status, mark them as read for good
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 105
diff changeset
142 self.selectedEntry.markRead()
105
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
143 self.session.commit()
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
144 self.ui.feedEntryList.doItemsLayout()
d372b3ee7bd8 add marking the entire current selection as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 104
diff changeset
145
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 19
diff changeset
146 def addFeed(self):
27
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
147 addFeed = AddFeed(self.session)
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
148 success = addFeed.exec_()
50
4b0d686493fb 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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 49
diff changeset
149 if not success:
4b0d686493fb 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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 49
diff changeset
150 return
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
151
50
4b0d686493fb 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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 49
diff changeset
152 if addFeed.exception is not None:
4b0d686493fb 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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 49
diff changeset
153 message = "Error while adding feed: " + str(addFeed.exception)
82
2dd6e6894772 update the status bar when opening a feed's rss url via WebView or external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 77
diff changeset
154 self._updateStatusBar(message)
50
4b0d686493fb 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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 49
diff changeset
155 else:
4b0d686493fb 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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 49
diff changeset
156 self.session.commit()
27
bdd1296a4b8c implemented adding a feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 24
diff changeset
157 self.updateFeedList()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
158
103
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
159 def deleteFeed(self):
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
160 try:
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
161 self.session.delete(self.selectedFeed)
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
162 self.session.commit()
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
163 self.updateFeedList()
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
164 except Exception as exception:
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
165 message = "Error while deleting feed: " + str(exception)
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
166 self._updateStatusBar(message)
063581d8594e implement deleting a feed from the GUI
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 97
diff changeset
167
40
c858aab71e5b add preferences dialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 39
diff changeset
168 def showPreferences(self):
42
0c0d1760b737 Rename Preferences to PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 40
diff changeset
169 preferences = PreferencesDialog(self.session)
40
c858aab71e5b add preferences dialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 39
diff changeset
170 preferences.exec_()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
171
48
6e5219e05625 GUI for feed settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 47
diff changeset
172 def showFeedSettings(self):
6e5219e05625 GUI for feed settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 47
diff changeset
173 feedSettings = FeedSettings(self.session, self.selectedFeed)
6e5219e05625 GUI for feed settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 47
diff changeset
174 feedSettings.exec_()
89
2eddb44920d1 When selecting a new feed, scroll its first entry to visible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 84
diff changeset
175
82
2dd6e6894772 update the status bar when opening a feed's rss url via WebView or external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 77
diff changeset
176 def _updateStatusBar(self, message):
2dd6e6894772 update the status bar when opening a feed's rss url via WebView or external browser
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 77
diff changeset
177 self.ui.statusbar.showMessage(message, STATUS_MESSAGE_DISPLAY_MILLIS)
37
22214d79ed41 database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 33
diff changeset
178
90
a1066e5a8f88 save pending changes when quitting the app
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 89
diff changeset
179 def close(self):
a1066e5a8f88 save pending changes when quitting the app
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 89
diff changeset
180 # save all uncommitted state, just in case
a1066e5a8f88 save pending changes when quitting the app
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 89
diff changeset
181 self.session.commit()
a1066e5a8f88 save pending changes when quitting the app
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 89
diff changeset
182 QMainWindow.close(self)
113
04f8cf1558c1 Add a menu item to copy the selected article's link to the clipboard
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 107
diff changeset
183
04f8cf1558c1 Add a menu item to copy the selected article's link to the clipboard
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 107
diff changeset
184 def copyArticleURLToClipboard(self):
04f8cf1558c1 Add a menu item to copy the selected article's link to the clipboard
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 107
diff changeset
185 clipboard = QApplication.clipboard()
04f8cf1558c1 Add a menu item to copy the selected article's link to the clipboard
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 107
diff changeset
186 clipboard.setText(self.selectedEntry.link)