Exemplo n.º 1
0
    def on_actionEdit_Feed_activated(self, b=None):
        if b is not None:
            return

        item = self.ui.feeds.currentItem()
        _id = None
        if item:
            fitem = item.parent()
            if not fitem:
                fitem = item
            _id = fitem._id

        feed = backend.Feed.get_by(xmlurl=_id)
        if not feed:  # No feed selected
            return

        if not self.feed_properties:
            from feedproperties import Feed_Properties

            self.feed_properties = Feed_Properties()
        self.ui.vsplitter.addWidget(self.feed_properties)

        # get feed and load data into the widget
        self.feed_properties.name.setText(backend.h2t(feed.name))
        self.feed_properties.url.setText(feed.url or "")
        self.feed_properties.xmlurl.setText(feed.xmlurl)

        self.feed_properties.show()
Exemplo n.º 2
0
    def showFeedPosts(self, item, feed):
        """Given a feed and an item, it shows the feed's posts as
        children of the item, and updates what the feed item shows"""
        if feed:
            unread_count = min(len(filter(lambda p: not p.read, feed.posts)), 100)
            item.setText(1, backend.h2t("%s (%d)" % (feed.name, unread_count)))

            items = {}
            for i in range(item.childCount()):
                items[item.child(i)._id] = item
            if self.showAllPosts:
                postList = feed.posts[:100]
            else:
                postList = (
                    backend.Post.query.filter_by(feed=feed, read=False).order_by(-backend.Post.date).limit(100).all()
                )
            for i, post in enumerate(postList):
                if i % 10 == 0:
                    QtCore.QCoreApplication.instance().processEvents()
                if post.read == False or self.showAllPosts:
                    # Should be visible

                    if post._id not in items:
                        # But it's not there
                        pitem = post.createItem(item)

        elif item._id == -1:
            self.updateRecentFeed()
        elif item._id == -2:
            self.updateStarredFeed()
Exemplo n.º 3
0
    def updateFeed(self, feed_id):
        # feed_id is a Feed.xmlurl, which is also item._id
        fitem = self.findFeedItem(feed_id)
        if fitem:
            feed = backend.Feed.get_by(xmlurl=feed_id)
            if fitem == self.feeds.currentItem():
                # It's the current item, needs to have its children displayed
                self.showFeedPosts(fitem, feed)

            else:
                # It's not the current item, just show the item count

                # This is the one to update
                unread_count = min(100, len(filter(lambda p: not p.read, feed.posts)))
                fitem.setText(1, backend.h2t("%s (%d)" % (feed.name, unread_count)))
                if unread_count:
                    fitem.setBackground(0, QtGui.QBrush(QtGui.QColor("lightgreen")))
                    fitem.setBackground(1, QtGui.QBrush(QtGui.QColor("lightgreen")))
                else:
                    fitem.setBackground(0, QtGui.QBrush(QtGui.QColor(200, 200, 200)))
                    fitem.setBackground(1, QtGui.QBrush(QtGui.QColor(200, 200, 200)))
                if (
                    (
                        self.ui.feeds.currentItem()
                        and (fitem in [self.ui.feeds.currentItem(), self.ui.feeds.currentItem().parent()])
                    )
                    or self.showAllFeeds
                    or unread_count
                ):
                    fitem.setHidden(False)
                else:
                    fitem.setHidden(True)
        else:
            # This is actually a new feed, so reload
            # feed list
            self.refreshFeeds()
Exemplo n.º 4
0
    def loadFeeds(self, expandedFeedId=None, currentItemId=None):
        """Creates all items for feeds and posts.

        If expandedFeedId is set, that feed's item will be expanded.
        if currentItemId is set, that item will be current (FIXME)

        """
        scrollTo = None
        feeds = backend.Feed.query.order_by("name").all()
        feeds.sort(cmp=lambda x, y: -cmp(x.name.lower(), y.name.lower()))
        self.ui.feeds.clear()
        self.feed_icon = QtGui.QIcon(":/icons/feed.svg")
        self.warning_icon = QtGui.QIcon(":/icons/warning.svg")
        self.error_icon = QtGui.QIcon(":/icons/error.svg")
        # Add "some recent"
        fitem = QtGui.QTreeWidgetItem(["", "Recent", "BB"])
        fitem.setBackground(0, QtGui.QBrush(QtGui.QColor("lightgreen")))
        fitem.setIcon(0, self.feed_icon)
        fitem.setBackground(1, QtGui.QBrush(QtGui.QColor("lightgreen")))
        fitem._id = -1
        self.ui.feeds.addTopLevelItem(fitem)
        if expandedFeedId == -1:
            fitem.setExpanded(True)
            scrollTo = fitem

        # for post in posts:
        # pitem = post.createItem(fitem)

        # posts = backend.Post.query.filter(backend.Post.star==True)
        fitem = QtGui.QTreeWidgetItem(["", "Starred", "BA"])
        fitem.setBackground(0, QtGui.QBrush(QtGui.QColor("lightgreen")))
        fitem.setIcon(0, self.feed_icon)
        fitem.setBackground(1, QtGui.QBrush(QtGui.QColor("lightgreen")))
        fitem._id = -2
        self.ui.feeds.addTopLevelItem(fitem)
        if expandedFeedId == -2:
            fitem.setExpanded(True)

        # for post in posts:
        # pitem=post.createItem(fitem)

        i = 0
        # FIXME: this does a lot of unnecesary work
        for feed in feeds:
            i += 1
            if i % 5 == 0:
                QtCore.QCoreApplication.instance().processEvents()
            unread_count = min(100, backend.Post.query.filter_by(feed=feed, read=False).count())
            tt = backend.h2t(feed.name)
            tt2 = "A%09d" % (i)
            fitem = QtGui.QTreeWidgetItem(["", "%s (%d)" % (tt, unread_count), tt2])
            if feed.bad_check_count > 5:
                fitem.setIcon(0, self.error_icon)
            elif feed.last_status == 301:
                fitem.setIcon(0, self.warning_icon)
            else:
                fitem.setIcon(0, self.feed_icon)
            if unread_count:
                fitem.setBackground(0, QtGui.QBrush(QtGui.QColor("lightgreen")))
                fitem.setBackground(1, QtGui.QBrush(QtGui.QColor("lightgreen")))
            else:
                fitem.setBackground(0, QtGui.QBrush(QtGui.QColor(200, 200, 200)))
                fitem.setBackground(1, QtGui.QBrush(QtGui.QColor(200, 200, 200)))

            fitem._id = feed.xmlurl
            self.ui.feeds.addTopLevelItem(fitem)
            if expandedFeedId == feed.xmlurl:
                fitem.setExpanded(True)
                scrollTo = fitem
            if fitem._id == expandedFeedId or self.showAllFeeds or unread_count:
                fitem.setHidden(False)
            else:
                fitem.setHidden(True)

        if scrollTo:
            self.ui.feeds.scrollToItem(scrollTo)