mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
refactoring based on new SoftwarePackage definition
This commit is contained in:
@@ -26,7 +26,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
exact_name_matches, contains_name_matches, others = [], [], []
|
||||
|
||||
for app in apps:
|
||||
lower_name = app.base_data.name.lower()
|
||||
lower_name = app.name.lower()
|
||||
|
||||
if word == lower_name:
|
||||
exact_name_matches.append(app)
|
||||
@@ -37,7 +37,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
res = []
|
||||
for app_list in (exact_name_matches, contains_name_matches, others):
|
||||
app_list.sort(key=lambda a: a.base_data.name.lower())
|
||||
app_list.sort(key=lambda a: a.name.lower())
|
||||
res.extend(app_list)
|
||||
|
||||
return res
|
||||
|
||||
@@ -51,7 +51,7 @@ class AsyncDiskCacheLoader(Thread, DiskCacheLoader):
|
||||
cache = self.cache_map.get(pkg.__class__)\
|
||||
|
||||
if cache:
|
||||
cache.add_non_existing(pkg.base_data.id, cached_data)
|
||||
cache.add_non_existing(pkg.id, cached_data)
|
||||
|
||||
|
||||
class DefaultDiskCacheLoaderFactory(DiskCacheLoaderFactory):
|
||||
|
||||
@@ -157,12 +157,12 @@ class AppsTable(QTableWidget):
|
||||
if app_v.status == PackageViewStatus.LOADING and app_v.model.status == PackageStatus.READY:
|
||||
|
||||
if self.download_icons:
|
||||
self.network_man.get(QNetworkRequest(QUrl(app_v.model.base_data.icon_url)))
|
||||
self.network_man.get(QNetworkRequest(QUrl(app_v.model.icon_url)))
|
||||
|
||||
app_name = self.item(idx, 0).text()
|
||||
|
||||
if not app_name or app_name == '...':
|
||||
self.item(idx, 0).setText(app_v.model.base_data.name)
|
||||
self.item(idx, 0).setText(app_v.model.name)
|
||||
|
||||
self._set_col_version(idx, app_v)
|
||||
self._set_col_description(idx, app_v)
|
||||
@@ -213,7 +213,7 @@ class AppsTable(QTableWidget):
|
||||
self.icon_cache.add(icon_url, icon_data)
|
||||
|
||||
for idx, app in enumerate(self.window.pkgs):
|
||||
if app.model.base_data.icon_url == icon_url:
|
||||
if app.model.icon_url == icon_url:
|
||||
col_name = self.item(idx, 0)
|
||||
col_name.setIcon(icon_data['icon'])
|
||||
|
||||
@@ -295,14 +295,14 @@ class AppsTable(QTableWidget):
|
||||
self.setCellWidget(idx, 3, col_type)
|
||||
|
||||
def _set_col_version(self, idx: int, app_v: PackageView):
|
||||
label_version = QLabel(app_v.model.base_data.version if app_v.model.base_data.version else '?')
|
||||
label_version = QLabel(app_v.model.version if app_v.model.version else '?')
|
||||
label_version.setAlignment(Qt.AlignCenter)
|
||||
|
||||
col_version = QWidget()
|
||||
col_version.setLayout(QHBoxLayout())
|
||||
col_version.layout().addWidget(label_version)
|
||||
|
||||
if app_v.model.base_data.version:
|
||||
if app_v.model.version:
|
||||
tooltip = self.i18n['version.installed'] if app_v.model.installed else self.i18n['version']
|
||||
else:
|
||||
tooltip = self.i18n['version.unknown']
|
||||
@@ -311,16 +311,16 @@ class AppsTable(QTableWidget):
|
||||
label_version.setStyleSheet("color: #20A435; font-weight: bold")
|
||||
tooltip = self.i18n['version.installed_outdated']
|
||||
|
||||
if app_v.model.installed and app_v.model.base_data.version and app_v.model.base_data.latest_version and app_v.model.base_data.version < app_v.model.base_data.latest_version:
|
||||
tooltip = '{}. {}: {}'.format(tooltip, self.i18n['version.latest'], app_v.model.base_data.latest_version)
|
||||
label_version.setText(label_version.text() + ' > {}'.format(app_v.model.base_data.latest_version))
|
||||
if app_v.model.installed and app_v.model.version and app_v.model.latest_version and app_v.model.version < app_v.model.latest_version:
|
||||
tooltip = '{}. {}: {}'.format(tooltip, self.i18n['version.latest'], app_v.model.latest_version)
|
||||
label_version.setText(label_version.text() + ' > {}'.format(app_v.model.latest_version))
|
||||
|
||||
col_version.setToolTip(tooltip)
|
||||
self.setCellWidget(idx, 1, col_version)
|
||||
|
||||
def _set_col_name(self, idx: int, app_v: PackageView):
|
||||
col = QTableWidgetItem()
|
||||
col.setText(app_v.model.base_data.name if app_v.model.base_data.name else '...')
|
||||
col.setText(app_v.model.name if app_v.model.name else '...')
|
||||
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
|
||||
col.setToolTip(self.i18n['app.name'].lower())
|
||||
|
||||
@@ -330,12 +330,12 @@ class AppsTable(QTableWidget):
|
||||
pixmap = QPixmap()
|
||||
pixmap.loadFromData(icon_bytes)
|
||||
icon = QIcon(pixmap)
|
||||
self.icon_cache.add_non_existing(app_v.model.base_data.icon_url, {'icon': icon, 'bytes': icon_bytes})
|
||||
self.icon_cache.add_non_existing(app_v.model.icon_url, {'icon': icon, 'bytes': icon_bytes})
|
||||
|
||||
elif not app_v.model.base_data.icon_url:
|
||||
elif not app_v.model.icon_url:
|
||||
icon = QIcon(app_v.model.get_default_icon_path())
|
||||
else:
|
||||
icon_data = self.icon_cache.get(app_v.model.base_data.icon_url)
|
||||
icon_data = self.icon_cache.get(app_v.model.icon_url)
|
||||
icon = icon_data['icon'] if icon_data else QIcon(app_v.model.get_default_icon_path())
|
||||
|
||||
col.setIcon(icon)
|
||||
@@ -345,8 +345,8 @@ class AppsTable(QTableWidget):
|
||||
col = QTableWidgetItem()
|
||||
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
|
||||
|
||||
if app_v.model.base_data.description is not None or not app_v.model.is_application() or app_v.model.status == PackageStatus.READY:
|
||||
desc = app_v.model.base_data.description
|
||||
if app_v.model.description is not None or not app_v.model.is_application() or app_v.model.status == PackageStatus.READY:
|
||||
desc = app_v.model.description
|
||||
else:
|
||||
desc = '...'
|
||||
|
||||
@@ -355,8 +355,8 @@ class AppsTable(QTableWidget):
|
||||
|
||||
col.setText(desc)
|
||||
|
||||
if app_v.model.base_data.description:
|
||||
col.setToolTip(app_v.model.base_data.description)
|
||||
if app_v.model.description:
|
||||
col.setToolTip(app_v.model.description)
|
||||
|
||||
self.setItem(idx, 2, col)
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ def apply_filters(pkgv: PackageView, filters: dict, info: dict):
|
||||
hidden = not pkgv.model.update
|
||||
|
||||
if not hidden and filters['name']:
|
||||
hidden = filters['name'] not in pkgv.model.base_data.name.lower()
|
||||
hidden = filters['name'] not in pkgv.model.name.lower()
|
||||
|
||||
if not hidden and (not filters['display_limit'] or len(info['pkgs_displayed']) < filters['display_limit']):
|
||||
info['pkgs_displayed'].append(pkgv)
|
||||
|
||||
@@ -13,7 +13,7 @@ class HistoryDialog(QDialog):
|
||||
def __init__(self, history: PackageHistory, icon_cache: MemoryCache, locale_keys: dict):
|
||||
super(HistoryDialog, self).__init__()
|
||||
|
||||
self.setWindowTitle('{} - {} '.format(locale_keys['popup.history.title'], history.pkg.base_data.name))
|
||||
self.setWindowTitle('{} - {} '.format(locale_keys['popup.history.title'], history.pkg.name))
|
||||
|
||||
layout = QVBoxLayout()
|
||||
self.setLayout(layout)
|
||||
@@ -54,7 +54,7 @@ class HistoryDialog(QDialog):
|
||||
new_width = reduce(operator.add, [table_history.columnWidth(i) for i in range(table_history.columnCount())])
|
||||
self.resize(new_width, table_history.height())
|
||||
|
||||
icon_data = icon_cache.get(history.pkg.base_data.icon_url)
|
||||
icon_data = icon_cache.get(history.pkg.icon_url)
|
||||
|
||||
if icon_data and icon_data.get('icon'):
|
||||
self.setWindowIcon(icon_data.get('icon'))
|
||||
|
||||
@@ -13,7 +13,7 @@ class InfoDialog(QDialog):
|
||||
|
||||
def __init__(self, app: dict, icon_cache: MemoryCache, locale_keys: dict, screen_size: QSize()):
|
||||
super(InfoDialog, self).__init__()
|
||||
self.setWindowTitle(app['__app__'].model.base_data.name)
|
||||
self.setWindowTitle(app['__app__'].model.name)
|
||||
self.screen_size = screen_size
|
||||
self.i18n = locale_keys
|
||||
layout = QVBoxLayout()
|
||||
@@ -39,7 +39,7 @@ class InfoDialog(QDialog):
|
||||
|
||||
layout.addWidget(self.gbox_info)
|
||||
|
||||
icon_data = icon_cache.get(app['__app__'].model.base_data.icon_url)
|
||||
icon_data = icon_cache.get(app['__app__'].model.icon_url)
|
||||
|
||||
if icon_data and icon_data.get('icon'):
|
||||
self.setWindowIcon(icon_data.get('icon'))
|
||||
|
||||
@@ -81,7 +81,7 @@ class UpdateSelectedApps(AsyncAction):
|
||||
if self.apps_to_update:
|
||||
updated, updated_types = 0, set()
|
||||
for app in self.apps_to_update:
|
||||
self.change_status('{} {}...'.format(self.locale_keys['manage_window.status.upgrading'], app.model.base_data.name))
|
||||
self.change_status('{} {}...'.format(self.locale_keys['manage_window.status.upgrading'], app.model.name))
|
||||
success = bool(self.manager.update(app.model, self.root_password, self))
|
||||
|
||||
if not success:
|
||||
@@ -114,7 +114,7 @@ class RefreshApps(AsyncAction):
|
||||
if self.pkg_types:
|
||||
refreshed_types.add(ins.__class__)
|
||||
|
||||
if self.app and ins.get_type() == self.app.model.get_type() and ins.base_data.id == self.app.model.base_data.id:
|
||||
if self.app and ins.get_type() == self.app.model.get_type() and ins.id == self.app.model.id:
|
||||
idx_found = idx
|
||||
app_found = ins
|
||||
break
|
||||
@@ -145,7 +145,7 @@ class UninstallApp(AsyncAction):
|
||||
success = self.manager.uninstall(self.app.model, self.root_password, self)
|
||||
|
||||
if success:
|
||||
self.icon_cache.delete(self.app.model.base_data.icon_url)
|
||||
self.icon_cache.delete(self.app.model.icon_url)
|
||||
self.manager.clean_cache_for(self.app.model)
|
||||
|
||||
self.notify_finished(self.app if success else None)
|
||||
@@ -249,7 +249,7 @@ class InstallApp(AsyncAction):
|
||||
self.pkg.model.installed = True
|
||||
|
||||
if self.pkg.model.supports_disk_cache():
|
||||
icon_data = self.icon_cache.get(self.pkg.model.base_data.icon_url)
|
||||
icon_data = self.icon_cache.get(self.pkg.model.icon_url)
|
||||
self.manager.cache_to_disk(app=self.pkg.model,
|
||||
icon_bytes=icon_data.get('bytes') if icon_data else None,
|
||||
only_icon=False)
|
||||
|
||||
@@ -16,4 +16,4 @@ class PackageView:
|
||||
self.status = PackageViewStatus.LOADING
|
||||
|
||||
def __repr__(self):
|
||||
return '{} ( {} )'.format(self.model.base_data.name, self.model.get_type())
|
||||
return '{} ( {} )'.format(self.model.name, self.model.get_type())
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import operator
|
||||
import time
|
||||
from functools import reduce
|
||||
from typing import List, Type, Set
|
||||
|
||||
@@ -408,14 +407,14 @@ class ManageWindow(QWidget):
|
||||
return
|
||||
|
||||
self._handle_console_option(True)
|
||||
self._begin_action('{} {}'.format(self.i18n['manage_window.status.uninstalling'], app.model.base_data.name))
|
||||
self._begin_action('{} {}'.format(self.i18n['manage_window.status.uninstalling'], app.model.name))
|
||||
|
||||
self.thread_uninstall.app = app
|
||||
self.thread_uninstall.root_password = pwd
|
||||
self.thread_uninstall.start()
|
||||
|
||||
def run_app(self, app: PackageView):
|
||||
self._begin_action(self.i18n['manage_window.status.running_app'].format(app.model.base_data.name))
|
||||
self._begin_action(self.i18n['manage_window.status.running_app'].format(app.model.name))
|
||||
self.thread_run_app.app = app
|
||||
self.thread_run_app.start()
|
||||
|
||||
@@ -430,7 +429,7 @@ class ManageWindow(QWidget):
|
||||
return
|
||||
|
||||
self._handle_console_option(True)
|
||||
self._begin_action('{} {}'.format(self.i18n['manage_window.status.refreshing_app'], app.model.base_data.name))
|
||||
self._begin_action('{} {}'.format(self.i18n['manage_window.status.refreshing_app'], app.model.name))
|
||||
|
||||
self.thread_refresh_app.app = app
|
||||
self.thread_refresh_app.root_password = pwd
|
||||
@@ -441,12 +440,12 @@ class ManageWindow(QWidget):
|
||||
|
||||
if pkgv:
|
||||
if self._can_notify_user():
|
||||
util.notify_user('{} ({}) {}'.format(pkgv.model.base_data.name, pkgv.model.get_type(), self.i18n['uninstalled']))
|
||||
util.notify_user('{} ({}) {}'.format(pkgv.model.name, pkgv.model.get_type(), self.i18n['uninstalled']))
|
||||
|
||||
self.refresh_apps(pkg_types={pkgv.model.__class__})
|
||||
else:
|
||||
if self._can_notify_user():
|
||||
util.notify_user('{}: {}'.format(pkgv.model.base_data.name, self.i18n['notification.uninstall.failed']))
|
||||
util.notify_user('{}: {}'.format(pkgv.model.name, self.i18n['notification.uninstall.failed']))
|
||||
|
||||
self.checkbox_console.setChecked(True)
|
||||
|
||||
@@ -812,7 +811,7 @@ class ManageWindow(QWidget):
|
||||
return
|
||||
|
||||
self._handle_console_option(True)
|
||||
self._begin_action('{} {}'.format(self.i18n['manage_window.status.downgrading'], pkgv.model.base_data.name))
|
||||
self._begin_action('{} {}'.format(self.i18n['manage_window.status.downgrading'], pkgv.model.name))
|
||||
|
||||
self.thread_downgrade.app = pkgv
|
||||
self.thread_downgrade.root_password = pwd
|
||||
@@ -878,7 +877,7 @@ class ManageWindow(QWidget):
|
||||
return
|
||||
|
||||
self._handle_console_option(True)
|
||||
self._begin_action('{} {}'.format(self.i18n['manage_window.status.installing'], pkg.model.base_data.name))
|
||||
self._begin_action('{} {}'.format(self.i18n['manage_window.status.installing'], pkg.model.name))
|
||||
|
||||
self.thread_install.pkg = pkg
|
||||
self.thread_install.root_password = pwd
|
||||
@@ -890,12 +889,12 @@ class ManageWindow(QWidget):
|
||||
|
||||
if pkgv:
|
||||
if self._can_notify_user():
|
||||
util.notify_user(msg='{} ({}) {}'.format(pkgv.model.base_data.name, pkgv.model.get_type(), self.i18n['installed']))
|
||||
util.notify_user(msg='{} ({}) {}'.format(pkgv.model.name, pkgv.model.get_type(), self.i18n['installed']))
|
||||
|
||||
self.refresh_apps(top_app=pkgv, pkg_types={pkgv.model.__class__})
|
||||
else:
|
||||
if self._can_notify_user():
|
||||
util.notify_user('{}: {}'.format(pkgv.model.base_data.name, self.i18n['notification.install.failed']))
|
||||
util.notify_user('{}: {}'.format(pkgv.model.name, self.i18n['notification.install.failed']))
|
||||
|
||||
self.checkbox_console.setChecked(True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user