Added indexes to download view.
This commit is contained in:
parent
658ab70e98
commit
91f7056649
@ -159,6 +159,7 @@ class DownloadItem(QObject):
|
|||||||
Attributes:
|
Attributes:
|
||||||
done: Whether the download is finished.
|
done: Whether the download is finished.
|
||||||
stats: A DownloadItemStats object.
|
stats: A DownloadItemStats object.
|
||||||
|
index: The index of the download in the view.
|
||||||
successful: Whether the download has completed sucessfully.
|
successful: Whether the download has completed sucessfully.
|
||||||
error_msg: The current error message, or None
|
error_msg: The current error message, or None
|
||||||
autoclose: Whether to close the associated file if the download is
|
autoclose: Whether to close the associated file if the download is
|
||||||
@ -206,6 +207,7 @@ class DownloadItem(QObject):
|
|||||||
self.done = False
|
self.done = False
|
||||||
self.stats = DownloadItemStats(self)
|
self.stats = DownloadItemStats(self)
|
||||||
self.stats.updated.connect(self.data_changed)
|
self.stats.updated.connect(self.data_changed)
|
||||||
|
self.index = 0
|
||||||
self.autoclose = True
|
self.autoclose = True
|
||||||
self.reply = None
|
self.reply = None
|
||||||
self._buffer = io.BytesIO()
|
self._buffer = io.BytesIO()
|
||||||
@ -238,8 +240,9 @@ class DownloadItem(QObject):
|
|||||||
else:
|
else:
|
||||||
errmsg = " - {}".format(self.error_msg)
|
errmsg = " - {}".format(self.error_msg)
|
||||||
if all(e is None for e in (perc, remaining, self.stats.total)):
|
if all(e is None for e in (perc, remaining, self.stats.total)):
|
||||||
return ('{name} [{speed:>10}|{down}]{errmsg}'.format(
|
return ('{index}: {name} [{speed:>10}|{down}]{errmsg}'.format(
|
||||||
name=self.basename, speed=speed, down=down, errmsg=errmsg))
|
index=self.index, name=self.basename, speed=speed,
|
||||||
|
down=down, errmsg=errmsg))
|
||||||
if perc is None:
|
if perc is None:
|
||||||
perc = '??'
|
perc = '??'
|
||||||
else:
|
else:
|
||||||
@ -250,14 +253,15 @@ class DownloadItem(QObject):
|
|||||||
remaining = utils.format_seconds(remaining)
|
remaining = utils.format_seconds(remaining)
|
||||||
total = utils.format_size(self.stats.total, suffix='B')
|
total = utils.format_size(self.stats.total, suffix='B')
|
||||||
if self.done:
|
if self.done:
|
||||||
return ('{name} [{perc:>2}%|{total}]{errmsg}'.format(
|
return ('{index}: {name} [{perc:>2}%|{total}]{errmsg}'.format(
|
||||||
name=self.basename, perc=perc, total=total,
|
index=self.index, name=self.basename, perc=perc,
|
||||||
errmsg=errmsg))
|
total=total, errmsg=errmsg))
|
||||||
else:
|
else:
|
||||||
return ('{name} [{speed:>10}|{remaining:>5}|{perc:>2}%|'
|
return ('{index}: {name} [{speed:>10}|{remaining:>5}|{perc:>2}%|'
|
||||||
'{down}/{total}]{errmsg}'.format(
|
'{down}/{total}]{errmsg}'.format(
|
||||||
name=self.basename, speed=speed, remaining=remaining,
|
index=self.index, name=self.basename, speed=speed,
|
||||||
perc=perc, down=down, total=total, errmsg=errmsg))
|
remaining=remaining, perc=perc, down=down,
|
||||||
|
total=total, errmsg=errmsg))
|
||||||
|
|
||||||
def _create_fileobj(self):
|
def _create_fileobj(self):
|
||||||
"""Creates a file object using the internal filename."""
|
"""Creates a file object using the internal filename."""
|
||||||
@ -707,6 +711,7 @@ class DownloadManager(QAbstractListModel):
|
|||||||
download.do_retry.connect(self.fetch)
|
download.do_retry.connect(self.fetch)
|
||||||
download.basename = suggested_filename
|
download.basename = suggested_filename
|
||||||
idx = len(self.downloads) + 1
|
idx = len(self.downloads) + 1
|
||||||
|
download.index = idx
|
||||||
self.beginInsertRows(QModelIndex(), idx, idx)
|
self.beginInsertRows(QModelIndex(), idx, idx)
|
||||||
self.downloads.append(download)
|
self.downloads.append(download)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
@ -862,6 +867,7 @@ class DownloadManager(QAbstractListModel):
|
|||||||
del self.downloads[idx]
|
del self.downloads[idx]
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
download.deleteLater()
|
download.deleteLater()
|
||||||
|
self.update_indexes()
|
||||||
|
|
||||||
def remove_items(self, downloads):
|
def remove_items(self, downloads):
|
||||||
"""Remove an iterable of downloads."""
|
"""Remove an iterable of downloads."""
|
||||||
@ -891,6 +897,12 @@ class DownloadManager(QAbstractListModel):
|
|||||||
download.deleteLater()
|
download.deleteLater()
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
|
|
||||||
|
def update_indexes(self):
|
||||||
|
"""Update indexes of all DownloadItems"""
|
||||||
|
for i, d in enumerate(self.downloads, 1):
|
||||||
|
if not d.index == i:
|
||||||
|
d.index = i
|
||||||
|
|
||||||
def headerData(self, section, orientation, role):
|
def headerData(self, section, orientation, role):
|
||||||
"""Simple constant header."""
|
"""Simple constant header."""
|
||||||
if (section == 0 and orientation == Qt.Horizontal and
|
if (section == 0 and orientation == Qt.Horizontal and
|
||||||
|
Loading…
Reference in New Issue
Block a user