Skip to content

Commit

Permalink
Implement basic search
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed Aug 4, 2023
1 parent 2354bfe commit 595e2cb
Show file tree
Hide file tree
Showing 19 changed files with 1,704 additions and 527 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

Unreleased
- New: Search tab that provides a basic search function across your libraries
- New: Cards tab that gives an overview of your linked cards
- New: Display number of available holds in the Holds tab text
- New: Last used tab will be opened by default
Expand Down
2 changes: 2 additions & 0 deletions calibre-plugin/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
HoldsDialogMixin,
LoansDialogMixin,
MagazinesDialogMixin,
SearchDialogMixin,
)
from .utils import CARD_ICON, ICON_MAP, PluginIcons, svg_to_qicon

Expand Down Expand Up @@ -119,6 +120,7 @@ def apply_settings(self):


class OverdriveLibbyDialog(
SearchDialogMixin,
CardsDialogMixin,
MagazinesDialogMixin,
HoldsDialogMixin,
Expand Down
1 change: 1 addition & 0 deletions calibre-plugin/dialog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
from .holds import HoldsDialogMixin
from .loans import LoansDialogMixin
from .magazines import MagazinesDialogMixin
from .search import SearchDialogMixin
49 changes: 41 additions & 8 deletions calibre-plugin/dialog/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
# information
#
import json
from typing import Dict, List
from typing import Dict, List, Optional

from calibre.constants import DEBUG
from calibre.gui2 import error_dialog, info_dialog
from calibre.gui2.viewer.overlay import LoadingOverlay
from calibre.gui2.widgets2 import CenteredToolButton # available from calibre 5.33.0
from lxml import etree
from polyglot.io import PolyglotStringIO
from qt.core import (
QApplication,
Expand All @@ -23,6 +24,7 @@
QGridLayout,
QLabel,
QMenu,
QPixmapCache,
QStatusBar,
QTabWidget,
QThread,
Expand All @@ -39,7 +41,7 @@
from ..models import LibbyModel
from ..overdrive import OverDriveClient
from ..overdrive.errors import ClientConnectionError as OverDriveConnectionError
from ..utils import PluginIcons
from ..utils import PluginIcons, svg_to_pixmap
from ..workers import SyncDataWorker

# noinspection PyUnreachableCode
Expand Down Expand Up @@ -199,35 +201,41 @@ def tab_current_changed(self, index: int):
if index > -1:
PREFS[PreferenceKeys.LAST_SELECTED_TAB] = index

def view_in_libby_action_triggered(self, indices, model):
def view_in_libby_action_triggered(
self, indices, model: LibbyModel, card: Optional[Dict] = None
):
"""
Open title in Libby
:param indices:
:param model:
:param card:
:return:
"""
for index in indices:
data = index.data(Qt.UserRole)
library_key = model.get_card(data["cardId"])["advantageKey"]
library_key = (card or model.get_card(data["cardId"]))["advantageKey"]
QDesktopServices.openUrl(
QUrl(LibbyClient.libby_title_permalink(library_key, data["id"]))
)

def view_in_overdrive_action_triggered(self, indices, model: LibbyModel):
def view_in_overdrive_action_triggered(
self, indices, model: LibbyModel, card: Optional[Dict] = None
):
"""
Open title in library OverDrive site
:param indices:
:param model:
:param card:
:return:
"""
for index in indices:
data = index.data(Qt.UserRole)
card = model.get_card(data["cardId"]) or {}
if not card:
card_ = card or model.get_card(data["cardId"]) or {}
if not card_:
continue
library = model.get_library(model.get_website_id(card)) or {}
library = model.get_library(model.get_website_id(card_)) or {}
if not library:
continue

Expand Down Expand Up @@ -424,6 +432,31 @@ def display_debug(self, text, data):
show=True,
)

def get_card_pixmap(self, library, size=(40, 30)):
"""
Generate a card image for a library
:param library:
:param size:
:return:
"""
card_pixmap_cache_id = (
f'card_website_{library["websiteId"]}_{size[0]}x{size[1]}'
)
card_pixmap = QPixmapCache.find(card_pixmap_cache_id)
if not QPixmapCache.find(card_pixmap_cache_id):
svg_root = etree.fromstring(self.icons[PluginIcons.Card])
if not DEMO_MODE:
stop1 = svg_root.find('.//stop[@class="stop1"]', svg_root.nsmap)
stop1.attrib["stop-color"] = library["settings"]["primaryColor"]["hex"]
stop2 = svg_root.find('.//stop[@class="stop2"]', svg_root.nsmap)
stop2.attrib["stop-color"] = library["settings"]["secondaryColor"][
"hex"
]
card_pixmap = svg_to_pixmap(etree.tostring(svg_root), size=size)
QPixmapCache.insert(card_pixmap_cache_id, card_pixmap)
return card_pixmap

def unhandled_exception(self, err, msg=None):
"""
Use this to handle unexpected job/sync errors instead of letting calibre's main window do it,
Expand Down
21 changes: 1 addition & 20 deletions calibre-plugin/dialog/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from calibre.utils.config import tweaks
from calibre.utils.date import dt_as_local, format_date
from lxml import etree
from qt.core import (
QCursor,
QDesktopServices,
Expand All @@ -21,7 +20,6 @@
QMenu,
QMouseEvent,
QPalette,
QPixmapCache,
QProgressBar,
QPushButton,
QScrollArea,
Expand All @@ -43,7 +41,6 @@
obfuscate_date,
obfuscate_int,
obfuscate_name,
svg_to_pixmap,
)

# noinspection PyUnreachableCode
Expand Down Expand Up @@ -84,23 +81,7 @@ def __init__(self, card, library, tab, *args, **kwargs):

# Library Card Icon
library_card_lbl = QLabel(self)
# render pixmap
card_pixmap_cache_id = f'card_website_{library["websiteId"]}'
card_pixmap = QPixmapCache.find(card_pixmap_cache_id)
if not QPixmapCache.find(card_pixmap_cache_id):
svg_root = etree.fromstring(self.icons[PluginIcons.Card])
if not DEMO_MODE:
stop1 = svg_root.find('.//stop[@class="stop1"]', svg_root.nsmap)
stop1.attrib["stop-color"] = library["settings"]["primaryColor"]["hex"]
stop2 = svg_root.find('.//stop[@class="stop2"]', svg_root.nsmap)
stop2.attrib["stop-color"] = library["settings"]["secondaryColor"][
"hex"
]
card_pixmap = svg_to_pixmap(
etree.tostring(svg_root), size=(40, 30)
) # original size=(80, 60)
QPixmapCache.insert(card_pixmap_cache_id, card_pixmap)
library_card_lbl.setPixmap(card_pixmap)
library_card_lbl.setPixmap(self.tab.get_card_pixmap(library))
layout.addWidget(library_card_lbl, widget_row_pos, 0)

# Library Name
Expand Down
Loading

0 comments on commit 595e2cb

Please sign in to comment.