# Path: vise/config.py
# @lru_cache()
# def misc_config(key, default=None):
#     u = load_config(user=True).get(key) or load_config(user=False).get(key)
#     if not u or u == 'default':
#         u = default
#     return u
# 
# Path: vise/constants.py
# DOWNLOADS_URL = 'vise:downloads'
# 
# Path: vise/constants.py
# STATUS_BAR_HEIGHT = 24
# 
# Path: vise/resources.py
# def get_data(name):
#     return get_data_as_file(name).read()
# 
# @lru_cache(maxsize=512)
# def get_icon(name):
#     if not name.startswith('images/'):
#         name = 'images/' + name
#     return QIcon(get_data_as_path(name))
# 
# Path: vise/utils.py
# def icon_data_for_filename(fname, size=64):
#     ''' Return the file type icon (as bytes) for the given filename '''
#     raw = b''
#     if fname:
#         if not hasattr(icon_data_for_filename, 'md'):
#             icon_data_for_filename.md = QMimeDatabase()
#         for mt in icon_data_for_filename.md.mimeTypesForFileName(fname):
#             icname = mt.iconName()
#             if icname:
#                 ic = QIcon.fromTheme(icname)
#                 if not ic.isNull():
#                     raw = icon_to_data(ic)
#                     if raw:
#                         break
#     return raw
# 
# def open_local_file(path):
#     QDesktopServices.openUrl(QUrl.fromLocalFile(path))
# 
# def safe_disconnect(signal):
#     try:
#         signal.disconnect()
#     except TypeError:
#         pass  # signal was not connected


import mimetypes
import os
import tempfile
import weakref
from binascii import hexlify, unhexlify
from functools import lru_cache
from gettext import gettext as _
from itertools import count
from time import monotonic
from PyQt6 import sip
from PyQt6.QtCore import QByteArray, QObject, Qt, QTimer, QUrl, pyqtSignal
from PyQt6.QtGui import QPainter, QPalette
from PyQt6.QtWebEngineCore import QWebEngineDownloadRequest
from PyQt6.QtWidgets import QApplication, QWidget
from .config import misc_config
from .constants import DOWNLOADS_URL as DU
from .constants import STATUS_BAR_HEIGHT
from .resources import get_data, get_icon
from .utils import icon_data_for_filename, open_local_file, safe_disconnect
            from .actions import show_downloads
    from .main import run_app
            pass
    return get_download_dir.ans


DOWNLOADS_URL = QUrl(DU)
DOWNLOAD_ICON_NAME = 'download.svg'
save_page_path_map = {}


@lru_cache(maxsize=150)
def filename_icon_data(encoded_file_name):
    return QByteArray(icon_data_for_filename(unhexlify(encoded_file_name).decode('utf-8'), size=64) or get_data('images/blank.png'))


class Indicator(QWidget):  # {{{

    downloads_tooltip = _(
        'Click to see ongoing downloads')
    no_downloads_tooltip = _(
        'No active downloads\nClick to see downloads')

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.setCursor(Qt.CursorShape.PointingHandCursor)
        self.setToolTip(self.no_downloads_tooltip)
        pal = (parent or QApplication.instance()).palette()
        self.dark = pal.color(QPalette.ColorRole.Text)
        self.light = pal.color(QPalette.ColorRole.Base)
        self.update()
        self.setMinimumWidth(STATUS_BAR_HEIGHT - 4)

# Path: vise/config.py
# @lru_cache()
# def misc_config(key, default=None):
#     u = load_config(user=True).get(key) or load_config(user=False).get(key)
#     if not u or u == 'default':
#         u = default
#     return u
# 
# Path: vise/constants.py
# DOWNLOADS_URL = 'vise:downloads'
# 
# Path: vise/constants.py
# STATUS_BAR_HEIGHT = 24
# 
# Path: vise/resources.py
# def get_data(name):
#     return get_data_as_file(name).read()
# 
# @lru_cache(maxsize=512)
# def get_icon(name):
#     if not name.startswith('images/'):
#         name = 'images/' + name
#     return QIcon(get_data_as_path(name))
# 
# Path: vise/utils.py
# def icon_data_for_filename(fname, size=64):
#     ''' Return the file type icon (as bytes) for the given filename '''
#     raw = b''
#     if fname:
#         if not hasattr(icon_data_for_filename, 'md'):
#             icon_data_for_filename.md = QMimeDatabase()
#         for mt in icon_data_for_filename.md.mimeTypesForFileName(fname):
#             icname = mt.iconName()
#             if icname:
#                 ic = QIcon.fromTheme(icname)
#                 if not ic.isNull():
#                     raw = icon_to_data(ic)
#                     if raw:
#                         break
#     return raw
# 
# def open_local_file(path):
#     QDesktopServices.openUrl(QUrl.fromLocalFile(path))
# 
# def safe_disconnect(signal):
#     try:
#         signal.disconnect()
#     except TypeError:
#         pass  # signal was not connected


# Path: vise/downloads.py
import mimetypes
import os
import tempfile
import weakref
from binascii import hexlify, unhexlify
from functools import lru_cache
from gettext import gettext as _
from itertools import count
from time import monotonic
from PyQt6 import sip
from PyQt6.QtCore import QByteArray, QObject, Qt, QTimer, QUrl, pyqtSignal
from PyQt6.QtGui import QPainter, QPalette
from PyQt6.QtWebEngineCore import QWebEngineDownloadRequest
from PyQt6.QtWidgets import QApplication, QWidget
from .config import misc_config
from .constants import DOWNLOADS_URL as DU
from .constants import STATUS_BAR_HEIGHT
from .resources import get_data, get_icon
from .utils import icon_data_for_filename, open_local_file, safe_disconnect
            from .actions import show_downloads
    from .main import run_app

            pass
    return get_download_dir.ans


DOWNLOADS_URL = QUrl(DU)
DOWNLOAD_ICON_NAME = 'download.svg'
save_page_path_map = {}


@lru_cache(maxsize=150)
def filename_icon_data(encoded_file_name):
    return QByteArray(icon_data_for_filename(unhexlify(encoded_file_name).decode('utf-8'), size=64) or get_data('images/blank.png'))


class Indicator(QWidget):  # {{{

    downloads_tooltip = _(
        'Click to see ongoing downloads')
    no_downloads_tooltip = _(
        'No active downloads\nClick to see downloads')

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.setCursor(Qt.CursorShape.PointingHandCursor)
        self.setToolTip(self.no_downloads_tooltip)
        pal = (parent or QApplication.instance()).palette()
        self.dark = pal.color(QPalette.ColorRole.Text)
        self.light = pal.color(QPalette.ColorRole.Base)
        self.update()
        self.setMinimumWidth(STATUS_BAR_HEIGHT - 4)

        self.setMinimumHeight(STATUS_BAR_HEIGHT - 4)