def feedDelete(self): db = ReaderDb() if self.page.treeWidget.hasFocus(): itemAll = self.page.treeWidget.selectedItems() if len(itemAll): for item in itemAll: if self.treeWidget.currentItem( ) == self.treeWidget.deletedFolder: db.execute( "update store set istrash=-1, iscache=0, isstore=0, entry_content='' where entry_url=?", (item.getEntryUrl(), )) else: db.execute( "update store set istrash=1, iscache=0, isstore=0 where entry_url=?", (item.getEntryUrl(), )) index = self.page.treeWidget.indexOfTopLevelItem(item) self.page.treeWidget.takeTopLevelItem(index) QApplication.processEvents() else: QMessageBox.warning(self, self.tr("Warning!"), self.tr("Selection has not done!")) elif self.treeWidget.hasFocus(): items = self.treeWidget.selectedItems() if len(items): if isinstance(items[0], FeedItem): box = QMessageBox.question( self, self.tr("Are you sure?"), self.tr("Do you want to delete the {} feed?").format( items[0].title)) if box == 16384: db.execute("delete from folders where feed_url=?", (items[0].feed_url, )) if isinstance(items[0]._parent, FolderItem): parent = items[0]._parent index = parent.indexOfChild(items[0]) parent.takeChild(index) else: index = self.treeWidget.indexOfTopLevelItem( items[0]) self.treeWidget.takeTopLevelItem(index) elif isinstance(items[0], FolderItem): db.execute("select * from folders where parent=?", (items[0].id, )) if db.cursor.fetchone(): QMessageBox.warning( self, self.tr("Warning!"), self.tr("Before, you empty for the directory!")) else: db.execute("delete from folders where id=?", (items[0].id, )) index = self.treeWidget.indexOfTopLevelItem(items[0]) self.treeWidget.takeTopLevelItem(index) else: QMessageBox.warning(self, self.tr("Warning!"), self.tr("Selection has not done!")) db.commit() db.close() self.syncSignal.emit()
def unreadFolderInit(self): db = ReaderDb() data = db.execute("select * from store where iscache=1") feedList = data.fetchall() db.close() self.unreadFolder.setForeground(0,QBrush(QColor(0,0,0,255))) if len(feedList) > 0: self.unreadFolder.setText(0, self.tr("({}) Unread").format(len(feedList))) self.unreadFolder.setForeground(0,QBrush(QColor(0,0,255))) return feedList
def storeFolderInit(self): db = ReaderDb() data = db.execute("select * from store where isstore=1") feedList = data.fetchall() db.close() self.storeFolder.setForeground(0,QBrush(QColor(0,0,0,255))) if len(feedList) > 0: self.storeFolder.setText(0, self.tr("({}) Stored").format(len(feedList))) self.storeFolder.setForeground(0,QBrush(QColor(0,0,255))) self.treeWidgetTitleSignal.emit(self.storeFolder.text(0)) return feedList
def deletedFolderInit(self): db = ReaderDb() data = db.execute("select * from store where istrash=1") feedList = data.fetchall() db.close() self.deletedFolder.setForeground(0,QBrush(QColor(0,0,0,255))) if len(feedList) > 0: self.deletedFolder.setText(0, self.tr("({}) Deleted").format(len(feedList))) self.deletedFolder.setForeground(0,QBrush(QColor(0,0,255))) self.deletedFolder.setIcon(0, QIcon(":/images/icons/trash_full.png")) return feedList
def feedInit(self): db = ReaderDb() data = db.execute("select * from store where iscache=1 and feed_url=?", (self.feed_url, )) feedList = data.fetchall() db.close() self.setForeground(0, QBrush(QColor(0, 0, 0, 255))) if len(feedList) > 0: self.setText(0, "({}) {}".format(len(feedList), self.title)) self.setForeground(0, QBrush(QColor(0, 0, 255))) return feedList
def saveInfo(self): db = ReaderDb() db.execute("select * from folders where type='folder' and title=?", (self.comboBox.currentText(), )) data = db.cursor.fetchone() if data: category = data["id"] else: category = 0 db.execute("update folders set parent=? where id=?", (category, self.item.id)) db.commit() db.close() self.parent.syncSignal.emit() self.parent.categorySync() self.accept()
def run(self): if not self.file == "": fileR = QFile(self.file) fileR.open(QIODevice.ReadOnly | QIODevice.Text) etree = cElementTree.XML(fileR.readAll()) feedList = etree.findall("feed") self.parent.progressBar.setMaximum(len(feedList)) db = ReaderDb() counter = 0 for feed in feedList: counter += 1 self.progress.emit(counter) db.execute("select * from folders where feed_url=?", (feed.text, )) if not db.cursor.fetchone(): try: self.parent.labelFeed.setStyleSheet( "color:green; font-weight:bold;") self.parent.labelFeed.setText( self.tr("{} adding...").format(feed.text)) fInfo = feedInfo(feed.text) fav = self.faviconUrl(fInfo["sitelink"]) db.execute( "insert into folders (title, type, feed_url, site_url, description, favicon) values (?, 'feed', ?, ?, ?, ?)", (fInfo["title"], fInfo["feedlink"], fInfo["sitelink"], fInfo["description"], self.getFavicon(fav))) db.commit() self.msleep(100) except AttributeError: self.parent.labelFeed.setStyleSheet( "color:red; font-weight:bold;") self.parent.labelFeed.setText( self.tr("{} unable to add.").format(feed.text)) self.msleep(500) else: self.parent.labelFeed.setStyleSheet( "color:blue; font-weight:bold;") self.parent.labelFeed.setText( self.tr("{} added.").format(feed.text)) self.msleep(500) db.close() fileR.close()
def feedAdd(self): data = feedInfo(self.lineEditURI.text()) db = ReaderDb() fav = self.faviconUrl(data["sitelink"]) db.execute("select id from folders where type='folder' and title=?", (self.comboBox.currentText(), )) folder = db.cursor.fetchone() if folder: category = folder["id"] else: category = 0 db.execute( "insert into folders (title, parent, type, feed_url, site_url, description, favicon) values (?, ?, 'feed', ?, ?, ?, ?)", (data["title"], category, data["feedlink"], data["sitelink"], data["description"], self.getFavicon(fav))) db.commit() db.close() self.feedAddFinished.emit(self.lineEditURI.text()) self.parent.syncSignal.emit() self.parent.categorySync() self.close()
def feedStore(self): itemAll = self.page.treeWidget.selectedItems() db = ReaderDb() if len(itemAll): if self.treeWidget.currentItem() != self.treeWidget.storeFolder: for item in itemAll: db.execute( "update store set istrash=0, iscache=0, isstore=1 where entry_url=?", (item.getEntryUrl(), )) index = self.page.treeWidget.indexOfTopLevelItem(item) self.page.treeWidget.takeTopLevelItem(index) QApplication.processEvents() else: QMessageBox.warning(self, self.tr("Warning!"), self.tr("These are already stored.")) else: QMessageBox.warning(self, self.tr("Warning!"), self.tr("Selection has not done!")) db.commit() db.close() self.syncSignal.emit()