Beispiel #1
0
class QtCategory(QtWidgets.QWidget, Ui_category):
    def __init__(self, owner):
        super(self.__class__, self).__init__(owner)
        Ui_category.__init__(self)
        self.setupUi(self)
        self.owner = weakref.ref(owner)
        self.bookList = QtBookList(self, self.__class__.__name__)
        self.bookList.InitBook()
        self.gridLayout_2.addWidget(self.bookList)
        self.bookList.doubleClicked.connect(self.OpenSearch)

    def SwitchCurrent(self):
        if self.bookList.count() <= 0:
            self.owner().loadingForm.show()
            self.owner().qtTask.AddHttpTask(
                lambda x: CateGoryMgr().UpdateCateGory(x),
                callBack=self.InitCateGoryBack)
        pass

    def InitCateGoryBack(self, msg):
        self.owner().loadingForm.close()
        if msg == Status.Ok:
            for index, info in enumerate(CateGoryMgr().idToCateGoryBase):
                url = info.thumb.get("fileServer")
                path = info.thumb.get("path")
                originalName = info.thumb.get("originalName")
                _id = info.id
                self.bookList.AddBookItem(_id, info.title, "", url, path,
                                          originalName)
            self.owner().searchForm.InitCheckBox()
        return

    def OpenSearch(self, modelIndex):
        index = modelIndex.row()
        item = self.bookList.item(index)
        widget = self.bookList.itemWidget(item)
        text = widget.label.text()
        self.owner().userForm.listWidget.setCurrentRow(1)
        self.owner().searchForm.searchEdit.setText("")
        self.owner().searchForm.OpenSearchCategories(text)
        pass
class QtHistory(QtWidgets.QWidget, Ui_History):
    def __init__(self, owner):
        super(self.__class__, self).__init__(owner)
        Ui_History.__init__(self)
        self.setupUi(self)
        self.owner = weakref.ref(owner)

        self.bookList = QtBookList(self, self.__class__.__name__, owner)
        self.bookList.InitBook(self.LoadNextPage)
        self.gridLayout_3.addWidget(self.bookList)
        self.pageNums = 20

        self.lineEdit.setValidator(QtIntLimit(1, 1, self))

        self.history = {}
        self.db = QSqlDatabase.addDatabase("QSQLITE", "history")
        self.db.setDatabaseName("history.db")
        self.bookList.InstallDel()

        if not self.db.open():
            Log.Warn(self.db.lastError().text())

        query = QSqlQuery(self.db)
        sql = """\
            create table if not exists history(\
            bookId varchar primary key,\
            name varchar,\
            epsId int, \
            picIndex int,\
            url varchar,\
            path varchar,\
            tick int\
            )\
            """
        suc = query.exec_(sql)
        if not suc:
            a = query.lastError().text()
            Log.Warn(a)
        self.LoadHistory()

    def SwitchCurrent(self):
        self.bookList.clear()
        self.bookList.page = 1
        self.bookList.pages = len(self.history) // self.pageNums + 1
        self.lineEdit.setValidator(QtIntLimit(1, self.bookList.pages, self))
        self.bookList.UpdateState()
        self.UpdatePageLabel()
        self.RefreshData(self.bookList.page)

    def GetHistory(self, bookId):
        return self.history.get(bookId)

    def DelHistory(self, bookId):
        query = QSqlQuery(self.db)
        sql = "delete from history where bookId='{}'".format(bookId)
        suc = query.exec_(sql)
        if not suc:
            Log.Warn(query.lastError().text())
        return

    def AddHistory(self, bookId, name, epsId, index, url, path):
        tick = int(time.time())
        info = self.history.get(bookId)
        if not info:
            info = QtHistoryData()
            self.history[bookId] = info
        info.bookId = bookId
        info.name = name
        info.epsId = epsId
        info.picIndex = index
        info.url = url
        info.path = path
        info.tick = tick

        query = QSqlQuery(self.db)


        sql = "INSERT INTO history(bookId, name, epsId, picIndex, url, path, tick) " \
              "VALUES ('{0}', '{1}', {2}, {3}, '{4}', '{5}', {6}) " \
              "ON CONFLICT(bookId) DO UPDATE SET name='{1}', epsId={2}, picIndex={3}, url = '{4}', path='{5}', tick={6}".\
            format(bookId, name, epsId, index, url, path, tick)
        suc = query.exec_(sql)
        if not suc:
            Log.Warn(query.lastError().text())
        return

    def LoadHistory(self):
        query = QSqlQuery(self.db)
        query.exec_(
            """
            select * from history
            """
        )
        while query.next():
            # bookId, name, epsId, index, url, path
            info = QtHistoryData()
            info.bookId = query.value(0)
            info.name = query.value(1)
            info.epsId = query.value(2)
            info.picIndex = query.value(3)
            info.url = query.value(4)
            info.path = query.value(5)
            info.tick = query.value(6)
            self.history[info.bookId] = info
        pass

    def JumpPage(self):
        page = int(self.lineEdit.text())
        if page > self.bookList.pages:
            return
        self.bookList.page = page
        self.bookList.clear()
        self.RefreshData(page)
        self.UpdatePageLabel()

    def OpenSearch(self, modelIndex):
        index = modelIndex.row()
        item = self.bookList.item(index)
        widget = self.bookList.itemWidget(item)
        text = widget.infoLabel.text()
        self.owner().userForm.listWidget.setCurrentRow(1)
        self.owner().searchForm.searchEdit.setText("")
        self.owner().searchForm.OpenSearchCategories(text)
        pass

    def LoadNextPage(self):
        self.bookList.page += 1
        self.RefreshData(self.bookList.page)
        self.UpdatePageLabel()

    def RefreshData(self, page):
        sortedList = list(self.history.values())
        sortedList.sort(key=lambda a: a.tick, reverse=True)
        self.bookList.UpdateState()
        start = (page-1) * self.pageNums
        end = start + self.pageNums
        for info in sortedList[start:end]:
            data = "上次读到第{}章".format(str(info.epsId+1))
            self.bookList.AddBookItem(info.bookId, info.name, data, info.url, info.path)

    def UpdatePageLabel(self):
        self.pages.setText("页:{}/{}".format(str(self.bookList.page), str(self.bookList.pages)))

    def DelCallBack(self, bookIds):
        for bookId in bookIds:
            if bookId not in self.history:
                continue
            self.history.pop(bookId)
            self.DelHistory(bookId)

        page = 1
        self.bookList.page = page
        self.bookList.clear()
        self.RefreshData(page)
        self.UpdatePageLabel()
        return
Beispiel #3
0
class QtFavorite(QtWidgets.QWidget, Ui_favorite):
    def __init__(self, owner):
        super(self.__class__, self).__init__(owner)
        Ui_favorite.__init__(self)
        self.setupUi(self)
        self.owner = weakref.ref(owner)

        self.dealCount = 0
        self.dirty = False

        self.bookList = QtBookList(self, self.__class__.__name__)
        self.bookList.InitBook(self.LoadNextPage)
        self.gridLayout_3.addWidget(self.bookList)
        self.bookList.doubleClicked.connect(self.OpenBookInfo)
        self.bookList.setContextMenuPolicy(Qt.CustomContextMenu)
        self.bookList.customContextMenuRequested.connect(self.SelectMenu)

        self.popMenu = QMenu(self.bookList)
        action = self.popMenu.addAction("打开")
        action.triggered.connect(self.OpenBookInfoHandler)
        action = self.popMenu.addAction("复制")
        action.triggered.connect(self.CopyHandler)
        action = self.popMenu.addAction("刪除")
        action.triggered.connect(self.DelHandler)
        action = self.popMenu.addAction("下载")
        action.triggered.connect(self.DownloadHandler)

        self.lineEdit.setValidator(QtIntLimit(1, 1, self))
        self.sortList = ["da", "dd"]

    def SwitchCurrent(self):
        self.RefreshDataFocus()

    def RefreshDataFocus(self):
        User().category.clear()
        self.bookList.UpdatePage(1, 1)
        self.bookList.UpdateState()
        self.bookList.clear()
        self.RefreshData()

    def RefreshData(self):
        if not User().category.get(self.bookList.page):
            self.LoadPage(self.bookList.page)
        else:
            self.UpdatePagesBack(Status.Ok)

    def UpdatePagesBack(self, st):
        self.owner().loadingForm.close()
        self.bookList.UpdateState()
        if st == Status.Ok:
            pageNums = User().pages
            page = User().page
            self.nums.setText("收藏数:{}".format(str(User().total)))
            self.pages.setText("页:{}/{}".format(str(page), str(pageNums)))
            self.bookList.UpdatePage(page, pageNums)
            self.lineEdit.setValidator(QtIntLimit(1, pageNums, self))
            for index, info in enumerate(User().category.get(
                    self.bookList.page)):
                url = info.thumb.get("fileServer")
                path = info.thumb.get("path")
                originalName = info.thumb.get("originalName")
                data = "完本," if info.finished else ""
                data += "{}E/{}P".format(str(info.epsCount),
                                         str(info.pagesCount))
                self.bookList.AddBookItem(info.id, info.title, data, url, path,
                                          originalName)

    def SelectMenu(self, pos):
        index = self.bookList.indexAt(pos)
        if index.isValid():
            self.popMenu.exec_(QCursor.pos())
        pass

    def CopyHandler(self):
        selected = self.bookList.selectedItems()
        if not selected:
            return

        data = ''
        for item in selected:
            widget = self.bookList.itemWidget(item)
            data += widget.GetTitle() + str("\r\n")
        clipboard = QApplication.clipboard()
        data = data.strip("\r\n")
        clipboard.setText(data)
        pass

    def DelHandler(self):
        bookIds = set()
        selected = self.bookList.selectedItems()
        for item in selected:
            widget = self.bookList.itemWidget(item)
            bookIds.add(widget.GetId())
        if not bookIds:
            return
        self.DelAndFavorites(bookIds)

    def DelAndFavorites(self, bookIds):
        self.owner().loadingForm.show()

        self.dealCount = len(bookIds)
        for bookId in bookIds:
            self.owner().qtTask.AddHttpTask(
                lambda x: User().AddAndDelFavorites(bookId, x),
                self.DelAndFavoritesBack)
        pass

    def DelAndFavoritesBack(self, msg):
        self.dealCount -= 1
        if self.dealCount <= 0:
            self.owner().loadingForm.close()
            self.RefreshDataFocus()

    def DownloadHandler(self):
        selected = self.bookList.selectedItems()
        for item in selected:
            widget = self.bookList.itemWidget(item)
            self.owner().epsInfoForm.OpenEpsInfo(widget.GetId())
        pass

    def OpenBookInfoHandler(self):
        selected = self.bookList.selectedItems()
        for item in selected:
            widget = self.bookList.itemWidget(item)
            self.owner().bookInfoForm.OpenBook(widget.GetId())
            return

    def OpenBookInfo(self, modelIndex):
        index = modelIndex.row()
        item = self.bookList.item(index)
        if not item:
            return
        widget = self.bookList.itemWidget(item)
        if not widget:
            return
        bookId = widget.id
        if not bookId:
            return
        self.owner().bookInfoForm.OpenBook(bookId)

    def LoadNextPage(self):
        self.LoadPage(self.bookList.page + 1)

    def LoadPage(self, page):
        sortKey = self.sortList[self.comboBox.currentIndex()]
        self.owner().qtTask.AddHttpTask(
            lambda x: User().UpdateFavorites(page, sortKey, x),
            self.UpdatePagesBack)
        self.owner().loadingForm.show()

    def JumpPage(self):
        page = int(self.lineEdit.text())
        if page > self.bookList.pages:
            return
        self.bookList.page = page
        self.bookList.clear()
        self.LoadPage(page)
Beispiel #4
0
class QtSearch(QtWidgets.QWidget, Ui_search):
    def __init__(self, owner):
        super(self.__class__, self).__init__(owner)
        Ui_search.__init__(self)
        self.setupUi(self)
        self.owner = weakref.ref(owner)
        self.index = 1
        self.data = ""
        self.bookList = QtBookList(self, self.__class__.__name__, owner)
        self.bookList.InitBook(self.LoadNextPage)

        self.bookLayout.addWidget(self.bookList)
        self.bookList.doubleClicked.connect(self.OpenSearch)
        self.categories = ""
        self.jumpLine.setValidator(QtIntLimit(1, 1, self))

        self.categoryList = QtCategoryList(self)
        layouy = QtWidgets.QHBoxLayout()
        layouy.addWidget(QLabel("屏蔽:"))
        layouy.addWidget(self.categoryList)
        self.bookLayout.addLayout(layouy, 1, 0)
        for name in ["耽美", "偽娘", "禁書", "扶她", "重口", "生肉", "純愛", "WEBTOON"]:
            self.categoryList.AddItem(name)
        self.categoryList.itemClicked.connect(self.ClickCategoryListItem)

        self.keywordList = QtCategoryList(self)
        layouy = QtWidgets.QHBoxLayout()
        layouy.addWidget(QLabel("大家都在搜:"))
        layouy.addWidget(self.keywordList)
        self.bookLayout.addLayout(layouy, 2, 0)
        self.keywordList.itemClicked.connect(self.ClickKeywordListItem)

    def SwitchCurrent(self):
        pass

    def InitCheckBox(self):
        # TODO 分类标签有点问题 暂时不显示
        return
        size = len(CateGoryMgr().idToCateGoryBase)
        hBoxLayout = QtWidgets.QHBoxLayout(self)
        a = QCheckBox("全部分类", self.groupBox)
        hBoxLayout.addWidget(a)

        for index, info in enumerate(CateGoryMgr().idToCateGoryBase, 2):
            if index % 9 == 0:
                self.comboBoxLayout.addLayout(hBoxLayout)
                hBoxLayout = QtWidgets.QHBoxLayout(self)
            a = QCheckBox(info.title, self.groupBox)
            hBoxLayout.addWidget(a)
        self.comboBoxLayout.addLayout(hBoxLayout)
        return

    def Search(self, categories=None):
        data = self.searchEdit.text()
        self.data = data
        if len(data) == len("5822a6e3ad7ede654696e482"):
            self.owner().bookInfoForm.OpenBook(data)
            return
        if not data:
            return
        if not categories:
            self.categories = []
        else:
            pass
        self.categories = ""
        self.bookList.clear()
        self.bookList.UpdatePage(1, 1)
        self.bookList.UpdateState()
        self.searchEdit.setPlaceholderText("")
        self.SendSearch(self.data, 1)

    def SendSearch(self, data, page):
        self.owner().loadingForm.show()
        self.index = 1
        sort = ["dd", "da", "ld", "vd"]
        sortId = sort[self.comboBox.currentIndex()]
        self.owner().qtTask.AddHttpTask(lambda x: Server().Send(req.AdvancedSearchReq(page, [], data, sortId), bakParam=x), self.SendSearchBack)

    def OpenSearchCategories(self, categories):
        self.bookList.clear()
        self.categories = categories
        self.searchEdit.setPlaceholderText(categories)
        self.bookList.UpdatePage(1, 1)
        self.bookList.UpdateState()
        self.SendSearchCategories(1)

    def SendSearchCategories(self, page):
        self.owner().loadingForm.show()
        # TODO 搜索和分类检索不太一样,切页时会有点问题
        sort = ["dd", "da", "ld", "vd"]
        sortId = sort[self.comboBox.currentIndex()]
        self.owner().qtTask.AddHttpTask(
            lambda x: Server().Send(req.CategoriesSearchReq(page, self.categories, sortId), bakParam=x),
            self.SendSearchBack)

    def InitKeyWord(self):
        self.owner().qtTask.AddHttpTask(
            lambda x: Server().Send(req.GetKeywords(), bakParam=x), self.SendKeywordBack)

    def SendSearchBack(self, raw):
        self.owner().loadingForm.close()
        try:
            self.bookList.UpdateState()
            data = json.loads(raw)
            if data.get("code") == 200:
                info = data.get("data").get("comics")
                page = int(info.get("page"))
                pages = int(info.get("pages"))
                self.bookList.UpdatePage(page, pages)
                self.jumpLine.setValidator(QtIntLimit(1, pages, self))
                pageText = "页:" + str(self.bookList.page) + "/" + str(self.bookList.pages)
                self.label.setText(pageText)
                for v in info.get("docs", []):
                    title = v.get("title", "")
                    _id = v.get("_id")
                    url = v.get("thumb", {}).get("fileServer")
                    path = v.get("thumb", {}).get("path")
                    originalName = v.get("thumb", {}).get("originalName")
                    info2 = "完本," if v.get("finished") else ""
                    info2 += "{}E/{}P".format(str(v.get("epsCount")), str(v.get("pagesCount")))
                    param = ",".join(v.get("categories"))
                    self.bookList.AddBookItem(_id, title, info2, url, path, param)
                self.CheckCategoryShowItem()
            else:
                # QtWidgets.QMessageBox.information(self, '未搜索到结果', "未搜索到结果", QtWidgets.QMessageBox.Yes)
                self.owner().msgForm.ShowError("未搜索到结果")
        except Exception as es:
            Log.Error(es)
        pass

    def SendKeywordBack(self, raw):
        try:
            data = json.loads(raw)
            if data.get("code") == 200:
                self.keywordList.clear()
                for keyword in data.get('data', {}).get("keywords", []):
                    self.keywordList.AddItem(keyword)
                pass
            else:
                pass
        except Exception as es:
            Log.Error(es)
        pass

    def OpenSearch(self, modelIndex):
        index = modelIndex.row()
        item = self.bookList.item(index)
        if not item:
            return
        widget = self.bookList.itemWidget(item)
        if not widget:
            return
        bookId = widget.id
        if not bookId:
            return
        self.owner().bookInfoForm.OpenBook(bookId)

    def JumpPage(self):
        page = int(self.jumpLine.text())
        if page > self.bookList.pages:
            return
        self.bookList.page = page
        self.bookList.clear()
        if not self.categories:
            self.SendSearch(self.data, page)
        else:
            self.SendSearchCategories(page)
        return

    def LoadNextPage(self):
        if not self.categories:
            self.SendSearch(self.data, self.bookList.page + 1)
        else:
            self.SendSearchCategories(self.bookList.page + 1)
        return

    def ChangeSort(self, pos):
        self.bookList.page = 1
        self.bookList.clear()
        if not self.categories:
            self.SendSearch(self.data, 1)
        else:
            self.SendSearchCategories(1)

    def ClickCategoryListItem(self, item):
        isClick = self.categoryList.ClickItem(item)
        data = item.text()
        if isClick:
            self.owner().msgForm.ShowMsg("屏蔽" + data)
        else:
            self.owner().msgForm.ShowMsg("取消屏蔽" + data)
        self.CheckCategoryShowItem()

    def CheckCategoryShowItem(self):
        data = self.categoryList.GetAllSelectItem()
        for i in range(self.bookList.count()):
            item = self.bookList.item(i)
            widget = self.bookList.itemWidget(item)
            isHidden = False
            for name in data:
                if name in widget.param:
                    item.setHidden(True)
                    isHidden = True
                    break
            if not isHidden:
                item.setHidden(False)

    def ClickKeywordListItem(self, item):
        data = item.text()
        self.searchEdit.setText(data)
        self.Search()
Beispiel #5
0
class QtFavorite(QtWidgets.QWidget, Ui_favorite, QtBookListMenu):
    def __init__(self, owner):
        super(self.__class__, self).__init__(owner)
        Ui_favorite.__init__(self)

        self.setupUi(self)
        self.owner = weakref.ref(owner)

        self.dealCount = 0
        self.dirty = False

        self.bookList = QtBookList(self, self.__class__.__name__)
        QtBookListMenu.__init__(self)
        self.bookList.InitBook(self.LoadNextPage)
        self.gridLayout_3.addWidget(self.bookList)

        self.lineEdit.setValidator(QtIntLimit(1, 1, self))
        self.sortList = ["dd", "da"]

    def SwitchCurrent(self):
        self.RefreshDataFocus()

    def RefreshDataFocus(self):
        User().category.clear()
        self.bookList.UpdatePage(1, 1)
        self.bookList.UpdateState()
        self.bookList.clear()
        self.RefreshData()

    def RefreshData(self):
        if not User().category.get(self.bookList.page):
            self.LoadPage(self.bookList.page)
        else:
            self.UpdatePagesBack(Status.Ok)

    def UpdatePagesBack(self, st):
        self.owner().loadingForm.close()
        self.bookList.UpdateState()
        if st == Status.Ok:
            pageNums = User().pages
            page = User().page
            self.nums.setText("收藏数:{}".format(str(User().total)))
            self.pages.setText("页:{}/{}".format(str(page), str(pageNums)))
            self.bookList.UpdatePage(page, pageNums)
            self.lineEdit.setValidator(QtIntLimit(1, pageNums, self))
            for index, info in enumerate(User().category.get(
                    self.bookList.page)):
                url = info.thumb.get("fileServer")
                path = info.thumb.get("path")
                originalName = info.thumb.get("originalName")
                data = "完本," if info.finished else ""
                data += "{}E/{}P".format(str(info.epsCount),
                                         str(info.pagesCount))
                self.bookList.AddBookItem(info.id, info.title, data, url, path,
                                          originalName)

    def DelCallBack(self, bookIds):
        self.owner().loadingForm.show()

        self.dealCount = len(bookIds)
        for bookId in bookIds:
            self.owner().qtTask.AddHttpTask(
                lambda x: User().AddAndDelFavorites(bookId, x),
                self.DelAndFavoritesBack)
        pass

    def DelAndFavoritesBack(self, msg):
        self.dealCount -= 1
        if self.dealCount <= 0:
            self.owner().loadingForm.close()
            self.RefreshDataFocus()

    def LoadNextPage(self):
        self.LoadPage(self.bookList.page + 1)

    def LoadPage(self, page):
        sortKey = self.sortList[self.comboBox.currentIndex()]
        self.owner().qtTask.AddHttpTask(
            lambda x: User().UpdateFavorites(page, sortKey, x),
            self.UpdatePagesBack)
        self.owner().loadingForm.show()

    def JumpPage(self):
        page = int(self.lineEdit.text())
        if page > self.bookList.pages:
            return
        self.bookList.page = page
        self.bookList.clear()
        self.LoadPage(page)