[UI] Update UIs for new default piece priority

- libtorrent 1.1 changes default piece priorty to 4 so changes to
   the UIs are required. Some refactoring and improvements were made as well:

    - A new 'Low' priority introduced that is values 1-3.
    - 'Normal' priority is now value 4.
    - Removed 'Highest' with the addition of 'Low' and 'High' is now values 5-7.
    - Renamed 'Do not download' to 'Ignore' so it is more succinct.
    - Moved file priority constant to ui.common.
This commit is contained in:
Calum Lind 2016-12-01 18:46:50 +00:00
parent bb44411a50
commit a481c4d243
9 changed files with 130 additions and 140 deletions

View File

@ -56,21 +56,6 @@ TORRENT_STATE = [
'Moving' 'Moving'
] ]
FILE_PRIORITY = {
0: 'Do Not Download',
1: 'Normal Priority',
2: 'High Priority',
3: 'High Priority',
4: 'High Priority',
5: 'High Priority',
6: 'High Priority',
7: 'Highest Priority',
'Do Not Download': 0,
'Normal Priority': 1,
'High Priority': 5,
'Highest Priority': 7
}
def get_version(): def get_version():
""" """

View File

@ -24,7 +24,7 @@ from deluge.common import utf8_encoded
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# Dummy translation dicts so Torrent and Tracker states are available for Translators. # Dummy translation dicts so the text is available for Translators.
# #
# All entries in deluge.common.TORRENT_STATE should be added here. # All entries in deluge.common.TORRENT_STATE should be added here.
# #
@ -90,13 +90,28 @@ TORRENT_DATA_FIELD = {
'owner': {'name': _('Owner'), 'status': ['owner']} 'owner': {'name': _('Owner'), 'status': ['owner']}
} }
TRACKER_STATUS_TRANSLATION = [ TRACKER_STATUS_TRANSLATION = [
_('Error'), _('Error'),
_('Warning'), _('Warning'),
_('Announce OK'), _('Announce OK'),
_('Announce Sent') _('Announce Sent')
] ]
FILE_PRIORITY = {
0: 'Ignore',
1: 'Low',
2: 'Low',
3: 'Low',
4: 'Normal',
5: 'High',
6: 'High',
7: 'High',
_('Ignore'): 0,
_('Low'): 1,
_('Normal'): 4,
_('High'): 7,
}
del _ del _
DEFAULT_HOST = '127.0.0.1' DEFAULT_HOST = '127.0.0.1'

View File

@ -16,6 +16,7 @@ import deluge.common as common
import deluge.component as component import deluge.component as component
import deluge.ui.console.utils.colors as colors import deluge.ui.console.utils.colors as colors
from deluge.ui.client import client from deluge.ui.client import client
from deluge.ui.common import FILE_PRIORITY
from deluge.ui.console.utils import format_utils from deluge.ui.console.utils import format_utils
from . import BaseCommand from . import BaseCommand
@ -198,7 +199,7 @@ class Command(BaseCommand):
col_priority = ' {!info!}Priority: ' col_priority = ' {!info!}Priority: '
file_priority = common.FILE_PRIORITY[status['file_priorities'][index]].replace('Priority', '') file_priority = FILE_PRIORITY[status['file_priorities'][index]].replace('Priority', '')
if status['file_progress'][index] != 1.0: if status['file_progress'][index] != 1.0:
if file_priority == 'Do Not Download': if file_priority == 'Do Not Download':
col_priority += '{!error!}' col_priority += '{!error!}'

View File

@ -12,9 +12,10 @@ from __future__ import division
import logging import logging
import deluge.component as component import deluge.component as component
from deluge.common import FILE_PRIORITY, fsize from deluge.common import fsize
from deluge.decorators import overrides from deluge.decorators import overrides
from deluge.ui.client import client from deluge.ui.client import client
from deluge.ui.common import FILE_PRIORITY
from deluge.ui.console.modes.basemode import BaseMode from deluge.ui.console.modes.basemode import BaseMode
from deluge.ui.console.modes.torrentlist.torrentactions import ACTION, torrent_actions_popup from deluge.ui.console.modes.torrentlist.torrentactions import ACTION, torrent_actions_popup
from deluge.ui.console.utils import curses_util as util from deluge.ui.console.utils import curses_util as util
@ -308,16 +309,19 @@ class TorrentDetail(BaseMode, PopupsHandler):
bg = 'black' bg = 'black'
attr = '' attr = ''
if fl[6] == -2: priority_fg_color = {
pass # Mixed -2: 'white', # Mixed
elif fl[6] == 0: 0: 'red', # Ignore
fg = 'red' # Do Not Download 1: 'yellow', # Low
elif fl[6] == 1: 2: 'yellow',
pass # Normal 3: 'yellow',
elif fl[6] <= 6: 4: 'white', # Normal
fg = 'yellow' # High 5: 'green',
elif fl[6] == 7: 6: 'green',
fg = 'green' # Highest 7: 'green' # High
}
fg = priority_fg_color[fl[6]]
if idx >= self.file_off: if idx >= self.file_off:
# set fg/bg colors based on whether the file is selected/marked or not # set fg/bg colors based on whether the file is selected/marked or not
@ -581,13 +585,14 @@ class TorrentDetail(BaseMode, PopupsHandler):
if self.marked: if self.marked:
popup = SelectablePopup(self, 'Set File Priority', popup_func, border_off_north=1) popup = SelectablePopup(self, 'Set File Priority', popup_func, border_off_north=1)
popup.add_line('do_not_download', '_Do Not Download', popup.add_line('ignore_priority', '_Ignore',
cb_arg=FILE_PRIORITY['Do Not Download'], foreground='red') cb_arg=FILE_PRIORITY['Ignore'], foreground='red')
popup.add_line('normal_priority', '_Normal Priority', cb_arg=FILE_PRIORITY['Normal Priority']) popup.add_line('low_priority', '_Low Priority',
cb_arg=FILE_PRIORITY['Low Priority'], foreground='yellow')
popup.add_line('normal_priority', '_Normal Priority',
cb_arg=FILE_PRIORITY['Normal Priority'])
popup.add_line('high_priority', '_High Priority', popup.add_line('high_priority', '_High Priority',
cb_arg=FILE_PRIORITY['High Priority'], foreground='yellow') cb_arg=FILE_PRIORITY['High Priority'], foreground='green')
popup.add_line('highest_priority', 'H_ighest Priority',
cb_arg=FILE_PRIORITY['Highest Priority'], foreground='green')
popup._selected = 1 popup._selected = 1
self.push_popup(popup) self.push_popup(popup)

View File

@ -18,8 +18,9 @@ from gobject import TYPE_UINT64
from gtk.gdk import ACTION_DEFAULT, ACTION_MOVE, BUTTON1_MASK, keyval_name # pylint: disable=ungrouped-imports from gtk.gdk import ACTION_DEFAULT, ACTION_MOVE, BUTTON1_MASK, keyval_name # pylint: disable=ungrouped-imports
import deluge.component as component import deluge.component as component
from deluge.common import FILE_PRIORITY, open_file, show_file from deluge.common import open_file, show_file
from deluge.ui.client import client from deluge.ui.client import client
from deluge.ui.common import FILE_PRIORITY
from deluge.ui.gtkui.common import (listview_replace_treestore, load_pickled_state_file, reparent_iter, from deluge.ui.gtkui.common import (listview_replace_treestore, load_pickled_state_file, reparent_iter,
save_pickled_state_file) save_pickled_state_file)
from deluge.ui.gtkui.torrentdetails import Tab from deluge.ui.gtkui.torrentdetails import Tab
@ -27,24 +28,12 @@ from deluge.ui.gtkui.torrentview_data_funcs import cell_data_size
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
CELL_PRIORITY_ICONS = {
def _(message): 'Ignore': gtk.STOCK_NO,
return message 'Low': gtk.STOCK_GO_DOWN,
'Normal': gtk.STOCK_OK,
'High': gtk.STOCK_GO_UP
TRANSLATE = {
'Do Not Download': _('Do Not Download'),
'Normal Priority': _('Normal Priority'),
'High Priority': _('High Priority'),
'Highest Priority': _('Highest Priority'),
} }
del _
def _t(text):
if text in TRANSLATE:
text = TRANSLATE[text]
return _(text)
def cell_priority(column, cell, model, row, data): def cell_priority(column, cell, model, row, data):
@ -53,7 +42,7 @@ def cell_priority(column, cell, model, row, data):
cell.set_property('text', '') cell.set_property('text', '')
return return
priority = model.get_value(row, data) priority = model.get_value(row, data)
cell.set_property('text', _t(FILE_PRIORITY[priority])) cell.set_property('text', _(FILE_PRIORITY[priority]))
def cell_priority_icon(column, cell, model, row, data): def cell_priority_icon(column, cell, model, row, data):
@ -62,14 +51,7 @@ def cell_priority_icon(column, cell, model, row, data):
cell.set_property('stock-id', None) cell.set_property('stock-id', None)
return return
priority = model.get_value(row, data) priority = model.get_value(row, data)
if FILE_PRIORITY[priority] == 'Do Not Download': cell.set_property('stock-id', CELL_PRIORITY_ICONS[FILE_PRIORITY[priority]])
cell.set_property('stock-id', gtk.STOCK_NO)
elif FILE_PRIORITY[priority] == 'Normal Priority':
cell.set_property('stock-id', gtk.STOCK_YES)
elif FILE_PRIORITY[priority] == 'High Priority':
cell.set_property('stock-id', gtk.STOCK_GO_UP)
elif FILE_PRIORITY[priority] == 'Highest Priority':
cell.set_property('stock-id', gtk.STOCK_GOTO_TOP)
def cell_filename(column, cell, model, row, data): def cell_filename(column, cell, model, row, data):
@ -175,10 +157,10 @@ class FilesTab(Tab):
self.file_menu = main_builder.get_object('menu_file_tab') self.file_menu = main_builder.get_object('menu_file_tab')
self.file_menu_priority_items = [ self.file_menu_priority_items = [
main_builder.get_object('menuitem_donotdownload'), main_builder.get_object('menuitem_ignore'),
main_builder.get_object('menuitem_low'),
main_builder.get_object('menuitem_normal'), main_builder.get_object('menuitem_normal'),
main_builder.get_object('menuitem_high'), main_builder.get_object('menuitem_high'),
main_builder.get_object('menuitem_highest'),
main_builder.get_object('menuitem_priority_sep') main_builder.get_object('menuitem_priority_sep')
] ]
@ -202,10 +184,10 @@ class FilesTab(Tab):
component.get('MainWindow').connect_signals({ component.get('MainWindow').connect_signals({
'on_menuitem_open_file_activate': self._on_menuitem_open_file_activate, 'on_menuitem_open_file_activate': self._on_menuitem_open_file_activate,
'on_menuitem_show_file_activate': self._on_menuitem_show_file_activate, 'on_menuitem_show_file_activate': self._on_menuitem_show_file_activate,
'on_menuitem_donotdownload_activate': self._on_menuitem_donotdownload_activate, 'on_menuitem_ignore_activate': self._on_menuitem_ignore_activate,
'on_menuitem_low_activate': self._on_menuitem_low_activate,
'on_menuitem_normal_activate': self._on_menuitem_normal_activate, 'on_menuitem_normal_activate': self._on_menuitem_normal_activate,
'on_menuitem_high_activate': self._on_menuitem_high_activate, 'on_menuitem_high_activate': self._on_menuitem_high_activate,
'on_menuitem_highest_activate': self._on_menuitem_highest_activate,
'on_menuitem_expand_all_activate': self._on_menuitem_expand_all_activate 'on_menuitem_expand_all_activate': self._on_menuitem_expand_all_activate
}) })
@ -543,25 +525,21 @@ class FilesTab(Tab):
log.debug('priorities: %s', priorities) log.debug('priorities: %s', priorities)
client.core.set_torrent_options([self.torrent_id], {'file_priorities': priorities}) client.core.set_torrent_options([self.torrent_id], {'file_priorities': priorities})
def _on_menuitem_donotdownload_activate(self, menuitem): def _on_menuitem_ignore_activate(self, menuitem):
self._set_file_priorities_on_user_change( self._set_file_priorities_on_user_change(
self.get_selected_files(), self.get_selected_files(), FILE_PRIORITY['Ignore'])
FILE_PRIORITY['Do Not Download'])
def _on_menuitem_low_activate(self, menuitem):
self._set_file_priorities_on_user_change(
self.get_selected_files(), FILE_PRIORITY['Low'])
def _on_menuitem_normal_activate(self, menuitem): def _on_menuitem_normal_activate(self, menuitem):
self._set_file_priorities_on_user_change( self._set_file_priorities_on_user_change(
self.get_selected_files(), self.get_selected_files(), FILE_PRIORITY['Normal'])
FILE_PRIORITY['Normal Priority'])
def _on_menuitem_high_activate(self, menuitem): def _on_menuitem_high_activate(self, menuitem):
self._set_file_priorities_on_user_change( self._set_file_priorities_on_user_change(
self.get_selected_files(), self.get_selected_files(), FILE_PRIORITY['High'])
FILE_PRIORITY['High Priority'])
def _on_menuitem_highest_activate(self, menuitem):
self._set_file_priorities_on_user_change(
self.get_selected_files(),
FILE_PRIORITY['Highest Priority'])
def _on_menuitem_expand_all_activate(self, menuitem): def _on_menuitem_expand_all_activate(self, menuitem):
self.listview.expand_all() self.listview.expand_all()

View File

@ -29,7 +29,7 @@
<object class="GtkImage" id="image5"> <object class="GtkImage" id="image5">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="stock">gtk-goto-top</property> <property name="stock">gtk-go-down</property>
<property name="icon-size">1</property> <property name="icon-size">1</property>
</object> </object>
<object class="GtkMenu" id="menu_file_tab"> <object class="GtkMenu" id="menu_file_tab">
@ -82,15 +82,27 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkImageMenuItem" id="menuitem_donotdownload"> <object class="GtkImageMenuItem" id="menuitem_ignore">
<property name="label" translatable="yes">_Do Not Download</property> <property name="label" translatable="yes">_Ignore</property>
<property name="use_action_appearance">False</property> <property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="image">image2</property> <property name="image">image2</property>
<property name="use_stock">False</property> <property name="use_stock">False</property>
<signal name="activate" handler="on_menuitem_donotdownload_activate" swapped="no"/> <signal name="activate" handler="on_menuitem_ignore_activate" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menuitem_low">
<property name="label" translatable="yes">_Low Priority</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="image">image5</property>
<property name="use_stock">False</property>
<signal name="activate" handler="on_menuitem_low_activate" swapped="no"/>
</object> </object>
</child> </child>
<child> <child>
@ -114,19 +126,7 @@
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="image">image4</property> <property name="image">image4</property>
<property name="use_stock">False</property> <property name="use_stock">False</property>
<signal name="activate" handler="on_menuitem_high_activate" swapped="no"/> <signal name="activate" handler="on_menuitem_normal_activate" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menuitem_highest">
<property name="label" translatable="yes">Hi_ghest Priority</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="image">image5</property>
<property name="use_stock">False</property>
<signal name="activate" handler="on_menuitem_highest_activate" swapped="no"/>
</object> </object>
</child> </child>
</object> </object>

View File

@ -346,7 +346,7 @@ dl.singleline dd {
} }
/* Filepriority styles */ /* Filepriority styles */
.x-no-download, .x-normal-download, .x-high-download, .x-highest-download, .x-mixed-download { .x-no-download, .x-low-download, .x-normal-download, .x-high-download, .x-mixed-download {
padding-left: 20px; padding-left: 20px;
background-repeat: no-repeat; background-repeat: no-repeat;
line-height: 16px; line-height: 16px;
@ -356,6 +356,10 @@ dl.singleline dd {
background-image: url(../icons/no_download.png); background-image: url(../icons/no_download.png);
} }
.x-low-download {
background-image: url(../icons/low.png);
}
.x-normal-download { .x-normal-download {
background-image: url(../icons/normal.png); background-image: url(../icons/normal.png);
} }
@ -364,10 +368,6 @@ dl.singleline dd {
background-image: url(../icons/high.png); background-image: url(../icons/high.png);
} }
.x-highest-download {
background-image: url(../icons/highest.png);
}
.x-mixed-download { .x-mixed-download {
/*background-image: url(../icons/mixed.png);*/ /*background-image: url(../icons/mixed.png);*/
} }
@ -485,6 +485,10 @@ dl.singleline dd {
background-image: url('../icons/no_download.png') !important; background-image: url('../icons/no_download.png') !important;
} }
.icon-low {
background-image: url('../icons/low.png') !important;
}
.icon-normal { .icon-normal {
background-image: url('../icons/normal.png') !important; background-image: url('../icons/normal.png') !important;
} }
@ -492,7 +496,3 @@ dl.singleline dd {
.icon-high { .icon-high {
background-image: url('../icons/high.png') !important; background-image: url('../icons/high.png') !important;
} }
.icon-highest {
background-image: url('../icons/highest.png') !important;
}

View File

@ -1,6 +1,6 @@
/*! /*!
* Deluge.js * Deluge.js
* *
* Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com>
* *
* This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with * This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
@ -41,7 +41,7 @@ Ext.apply(Ext, {
} }
return equal; return equal;
}, },
keys: function(obj) { keys: function(obj) {
var keys = []; var keys = [];
for (var i in obj) if (obj.hasOwnProperty(i)) for (var i in obj) if (obj.hasOwnProperty(i))
@ -60,7 +60,7 @@ Ext.apply(Ext, {
} }
return values; return values;
}, },
splat: function(obj) { splat: function(obj) {
var type = Ext.type(obj); var type = Ext.type(obj);
return (type) ? ((type != 'array') ? [obj] : obj) : []; return (type) ? ((type != 'array') ? [obj] : obj) : [];
@ -75,7 +75,7 @@ Ext.apply(Deluge, {
// private // private
pluginStore: {}, pluginStore: {},
// private // private
progressTpl: '<div class="x-progress-wrap x-progress-renderered">' + progressTpl: '<div class="x-progress-wrap x-progress-renderered">' +
'<div class="x-progress-inner">' + '<div class="x-progress-inner">' +
@ -90,7 +90,7 @@ Ext.apply(Deluge, {
'</div>' + '</div>' +
'</div>', '</div>',
/** /**
* A method to create a progress bar that can be used by renderers * A method to create a progress bar that can be used by renderers
* to display a bar within a grid or tree. * to display a bar within a grid or tree.
@ -131,36 +131,42 @@ Ext.apply(Deluge, {
registerPlugin: function(name, plugin) { registerPlugin: function(name, plugin) {
Deluge.pluginStore[name] = plugin; Deluge.pluginStore[name] = plugin;
} }
}); });
// Setup a space for plugins to insert themselves // Setup a space for plugins to insert themselves
deluge.plugins = {}; deluge.plugins = {};
// Hinting for gettext_gen.py // Hinting for gettext_gen.py
// _('Do Not Download') // _('Ignore')
// _('Normal Priority') // _('Low')
// _('High Priority') // _('Normal')
// _('Highest Priority') // _('High')
FILE_PRIORITY = { FILE_PRIORITY = {
0: 'Ignore',
1: 'Low',
2: 'Low',
3: 'Low',
4: 'Normal',
5: 'High',
6: 'High',
7: 'High',
9: 'Mixed', 9: 'Mixed',
0: 'Do Not Download', 'Ignore': 0,
1: 'Normal Priority', 'Low': 1,
2: 'High Priority', 'Normal': 4,
5: 'High Priority', 'High': 7,
7: 'Highest Priority', 'Mixed': 9
'Mixed': 9,
'Do Not Download': 0,
'Normal Priority': 1,
'High Priority': 5,
'Highest Priority': 7
} }
FILE_PRIORITY_CSS = { FILE_PRIORITY_CSS = {
9: 'x-mixed-download',
0: 'x-no-download', 0: 'x-no-download',
1: 'x-normal-download', 1: 'x-low-download',
2: 'x-high-download', 2: 'x-low-download',
3: 'x-low-download',
4: 'x-normal-download',
5: 'x-high-download', 5: 'x-high-download',
7: 'x-highest-download' 6: 'x-high-download',
7: 'x-high-download',
9: 'x-mixed-download'
} }

View File

@ -301,24 +301,24 @@ deluge.menus.filePriorities = new Ext.menu.Menu({
text: _('Expand All'), text: _('Expand All'),
iconCls: 'icon-expand-all' iconCls: 'icon-expand-all'
}, '-', { }, '-', {
id: 'no_download', id: 'ignore',
text: _('Do Not Download'), text: _('Ignore'),
iconCls: 'icon-do-not-download', iconCls: 'icon-do-not-download',
filePriority: FILE_PRIORITY['Do Not Download'] filePriority: FILE_PRIORITY['Ignore']
}, {
id: 'low',
text: _('Low'),
iconCls: 'icon-low',
filePriority: FILE_PRIORITY['Low']
}, { }, {
id: 'normal', id: 'normal',
text: _('Normal Priority'), text: _('Normal'),
iconCls: 'icon-normal', iconCls: 'icon-normal',
filePriority: FILE_PRIORITY['Normal Priority'] filePriority: FILE_PRIORITY['Normal']
}, { }, {
id: 'high', id: 'high',
text: _('High Priority'), text: _('High'),
iconCls: 'icon-high', iconCls: 'icon-high',
filePriority: FILE_PRIORITY['High Priority'] filePriority: FILE_PRIORITY['High']
}, {
id: 'highest',
text: _('Highest Priority'),
iconCls: 'icon-highest',
filePriority: FILE_PRIORITY['Highest Priority']
}] }]
}); });