diff options
Diffstat (limited to 'raphodo/thumbnaildisplay.py')
-rw-r--r-- | raphodo/thumbnaildisplay.py | 129 |
1 files changed, 86 insertions, 43 deletions
diff --git a/raphodo/thumbnaildisplay.py b/raphodo/thumbnaildisplay.py index bce2781..ddfb526 100644 --- a/raphodo/thumbnaildisplay.py +++ b/raphodo/thumbnaildisplay.py @@ -30,6 +30,7 @@ import shlex import logging from timeit import timeit from typing import Optional, Dict, List, Set, Tuple, Sequence +import locale from gettext import gettext as _ @@ -46,23 +47,26 @@ from PyQt5.QtGui import (QPixmap, QImage, QPainter, QColor, QBrush, QFontMetrics QGuiApplication, QPen, QMouseEvent, QFont) from raphodo.rpdfile import RPDFile, FileTypeCounter, ALL_USER_VISIBLE_EXTENSIONS, MUST_CACHE_VIDEOS -from raphodo.interprocess import (PublishPullPipelineManager, GenerateThumbnailsArguments, Device, - GenerateThumbnailsResults) -from raphodo.constants import (DownloadStatus, Downloaded, FileType, DownloadingFileTypes, - ThumbnailSize, ThumbnailCacheStatus, Roles, DeviceType, CustomColors, - Show, Sort, ThumbnailBackgroundName, Desktop, DeviceState, - extensionColor, FadeSteps, FadeMilliseconds, PaleGray, DarkGray, - DoubleDarkGray) +from raphodo.interprocess import GenerateThumbnailsArguments, Device, GenerateThumbnailsResults +from raphodo.constants import ( + DownloadStatus, Downloaded, FileType, DownloadingFileTypes, ThumbnailSize, + ThumbnailCacheStatus, Roles, DeviceType, CustomColors, Show, Sort, ThumbnailBackgroundName, + Desktop, DeviceState, extensionColor, FadeSteps, FadeMilliseconds, PaleGray, DarkGray, + DoubleDarkGray +) from raphodo.storage import get_program_cache_directory, get_desktop, validate_download_folder -from raphodo.utilities import (CacheDirs, make_internationalized_list, format_size_for_user, runs) +from raphodo.utilities import ( + CacheDirs, make_internationalized_list, format_size_for_user, runs, arrow_locale +) from raphodo.thumbnailer import Thumbnailer from raphodo.rpdsql import ThumbnailRowsSQL, ThumbnailRow from raphodo.viewutils import ThumbnailDataForProximity from raphodo.proximity import TemporalProximityState -DownloadFiles = namedtuple('DownloadFiles', 'files, download_types, download_stats, ' - 'camera_access_needed') +DownloadFiles = namedtuple( + 'DownloadFiles', 'files, download_types, download_stats, camera_access_needed' +) MarkedSummary = namedtuple('MarkedSummary', 'marked size_photos_marked size_videos_marked') @@ -152,6 +156,8 @@ class ThumbnailListModel(QAbstractListModel): # Connect to the signal that is emitted when a thumbnailing operation is # terminated by us, not merely finished self.thumbnailer.workerStopped.connect(self.thumbnailWorkerStopped) + self.arrow_locale = arrow_locale() + logging.debug("Setting arrow locale to %s", self.arrow_locale) def initialize(self) -> None: # uid: QPixmap @@ -423,56 +429,65 @@ class ThumbnailListModel(QAbstractListModel): ctime = arrow.get(rpd_file.ctime) humanized_ctime = _( - 'Taken on %(date_time)s (%(human_readable)s)' % dict( - date_time=ctime.to('local').naive.strftime('%c'), - human_readable=ctime.humanize())) + 'Taken on %(date_time)s (%(human_readable)s)' + ) % dict( + date_time=ctime.to('local').naive.strftime('%c'), + human_readable=ctime.humanize(locale=self.arrow_locale) + ) humanized_mtime = _( - 'Modified on %(date_time)s (%(human_readable)s)' % dict( + 'Modified on %(date_time)s (%(human_readable)s)' + ) % dict( date_time=mtime.to('local').naive.strftime('%c'), - human_readable=mtime.humanize())) + human_readable=mtime.humanize(locale=self.arrow_locale) + ) humanized_file_time = '{}<br>{}'.format(humanized_ctime, humanized_mtime) else: humanized_file_time = _( - '%(date_time)s (%(human_readable)s)' % dict( + '%(date_time)s (%(human_readable)s)' + ) % dict( date_time=mtime.to('local').naive.strftime('%c'), - human_readable=mtime.humanize())) + human_readable=mtime.humanize(locale=self.arrow_locale) + ) humanized_file_time = humanized_file_time.replace(' ', ' ') if not device_name: - msg = '<b>{}</b><br>{}<br>{}'.format(rpd_file.name, - humanized_file_time, size) + msg = '<b>{}</b><br>{}<br>{}'.format(rpd_file.name, humanized_file_time, size) else: - msg = '<b>{}</b><br>{}<br>{}<br>{}'.format(rpd_file.name, device_name, - humanized_file_time, size) + msg = '<b>{}</b><br>{}<br>{}<br>{}'.format( + rpd_file.name, device_name, humanized_file_time, size + ) if rpd_file.camera_memory_card_identifiers: - cards = _('Memory cards: %s') % make_internationalized_list( - rpd_file.camera_memory_card_identifiers) + if len(rpd_file.camera_memory_card_identifiers) > 1: + cards = _('Memory cards: %s') % make_internationalized_list( + rpd_file.camera_memory_card_identifiers + ) + else: + cards = _('Memory card: %s') % rpd_file.camera_memory_card_identifiers[0] msg += '<br>' + cards if rpd_file.status in Downloaded: path = rpd_file.download_path + os.sep downloaded_as = _('Downloaded as:') - msg += '<br><br><i>%(downloaded_as)s</i><br>%(filename)s<br>' \ - '%(path)s' % dict(filename=rpd_file.download_name, path=path, - downloaded_as=downloaded_as) + msg += '<br><br><i>%(downloaded_as)s</i><br>%(filename)s<br>%(path)s' % dict( + filename=rpd_file.download_name, path=path, downloaded_as=downloaded_as + ) if rpd_file.previously_downloaded(): - prev_datetime = arrow.get(rpd_file.prev_datetime, - tzlocal()) - prev_date = _('%(date_time)s (%(human_readable)s)' % dict( + prev_datetime = arrow.get(rpd_file.prev_datetime, tzlocal()) + prev_date = _('%(date_time)s (%(human_readable)s)') % dict( date_time=prev_datetime.naive.strftime('%c'), - human_readable=prev_datetime.humanize())) + human_readable=prev_datetime.humanize(locale=self.arrow_locale) + ) path, prev_file_name = os.path.split(rpd_file.prev_full_name) path += os.sep - msg += _('<br><br>Previous download:<br>%(filename)s<br>%(path)s<br>%(' - 'date)s') % {'date': prev_date, - 'filename': prev_file_name, - 'path': path} + msg += _( + '<br><br>Previous download:<br>%(filename)s<br>%(path)s<br>%(date)s' + ) % dict(date=prev_date, filename=prev_file_name, path=path) return msg def setData(self, index: QModelIndex, value, role: int) -> bool: @@ -767,10 +782,14 @@ class ThumbnailListModel(QAbstractListModel): need_video_cache_dir = False if device.device_type == DeviceType.camera: - need_video_cache_dir = self.tsql.any_files_of_type(scan_id, FileType.video) - - gen_args = (scan_id, rpd_files, device.name(), self.rapidApp.prefs.proximity_seconds, - cache_dirs, need_video_cache_dir, device.camera_model, device.camera_port) + need_video_cache_dir = device.entire_video_required or \ + self.tsql.any_files_of_type(scan_id, FileType.video) + + gen_args = ( + scan_id, rpd_files, device.name(), self.rapidApp.prefs.proximity_seconds, + cache_dirs, need_video_cache_dir, device.camera_model, device.camera_port, + device.entire_video_required + ) self.thumbnailer.generateThumbnails(*gen_args) def resetThumbnailTracking(self): @@ -1026,9 +1045,12 @@ class ThumbnailListModel(QAbstractListModel): else: download_types = None - return DownloadFiles(files=files, download_types=download_types, - download_stats=download_stats, - camera_access_needed=camera_access_needed) + return DownloadFiles( + files=files, + download_types=download_types, + download_stats=download_stats, + camera_access_needed=camera_access_needed + ) def sendToDaemonThumbnailer(self, rpd_file: RPDFile) -> bool: """ @@ -1485,6 +1507,26 @@ class ThumbnailListModel(QAbstractListModel): return self.tsql.get_count(marked=True) != self.getDisplayedCount(marked=True) + def getFileDownloadsCompleted(self) -> FileTypeCounter: + """ + :return: counter for how many photos and videos have their downloads completed + whether successfully or not + """ + + return FileTypeCounter( + { + FileType.photo: self.tsql.get_count(downloaded=True, file_type=FileType.photo), + FileType.video: self.tsql.get_count(downloaded=True, file_type=FileType.video) + } + ) + + def anyCompletedDownloads(self) -> bool: + """ + :return: True if any files have been downloaded (including failures) + """ + + return self.tsql.any_files_download_completed() + def jobCodeNeeded(self) -> bool: """ :return: True if any files checked for download do not have job codes @@ -1916,8 +1958,9 @@ class ThumbnailDelegate(QStyledItemDelegate): if not active_camera: disable_kde = index.data(Roles.mtp) and get_desktop() == Desktop.kde - self.openInFileBrowserAct.setEnabled(not (disable_kde or active_camera) and - have_file_manager) + self.openInFileBrowserAct.setEnabled( + not (disable_kde or active_camera) and have_file_manager + ) self.contextMenu.popup(globalPos) return False if event.button() != Qt.LeftButton or not self.getCheckBoxRect( |