add "desired ratio" option on per torrent basis

This commit is contained in:
Marcos Pinto 2007-06-16 07:00:55 +00:00
parent df63d91a46
commit 39e7d25c1e
4 changed files with 96 additions and 1 deletions

View File

@ -117,5 +117,55 @@
</child>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem3">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Desired Ratio</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="menu2">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkMenuItem" id="menuitem4">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">0</property>
<property name="use_underline">True</property>
<signal name="activate" handler="set_ratio0"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem9">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">1</property>
<property name="use_underline">True</property>
<signal name="activate" handler="set_ratio1"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem10">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">2</property>
<property name="use_underline">True</property>
<signal name="activate" handler="set_ratio2"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem11">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">3</property>
<property name="use_underline">True</property>
<signal name="activate" handler="set_ratio3"/>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -568,6 +568,10 @@ class Manager:
self.unique_IDs[unique_ID].user_paused = new_value
self.apply_queue()
def set_ratio(self, unique_ID, num):
print("setting the ratio core")
deluge_core.set_ratio(unique_ID, num)
def is_user_paused(self, unique_ID):
return self.unique_IDs[unique_ID].user_paused

View File

@ -1290,6 +1290,22 @@ static PyObject *torrent_pe_settings(PyObject *self, PyObject *args)
return Py_None;
}
static PyObject *torrent_set_ratio(PyObject *self, PyObject *args)
{
python_long unique_ID, num;
if (!PyArg_ParseTuple(args, "ii", &unique_ID, &num))
return NULL;
long index = get_index_from_unique_ID(unique_ID);
if (PyErr_Occurred())
return NULL;
M_torrents->at(index).handle.set_ratio(num);
Py_INCREF(Py_None); return Py_None;
}
//====================
// Python Module data
//====================
@ -1331,6 +1347,7 @@ static PyMethodDef deluge_core_methods[] =
{"use_upnp", torrent_use_upnp, METH_VARARGS, "."},
{"use_natpmp", torrent_use_natpmp, METH_VARARGS, "."},
{"use_utpex", torrent_use_utpex, METH_VARARGS, "."},
{"set_ratio", torrent_set_ratio, METH_VARARGS, "."},
{NULL}
};

View File

@ -263,6 +263,10 @@ class DelugeGTK:
"queue_down": self.q_torrent_down,
"queue_bottom": self.q_to_bottom,
"queue_top": self.q_to_top,
"set_ratio0": self.set_ratio_0,
"set_ratio1": self.set_ratio_1,
"set_ratio2": self.set_ratio_2,
"set_ratio3": self.set_ratio_3,
})
self.torrent_menu.connect("focus", self.torrent_menu_focus)
# UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share
@ -415,6 +419,26 @@ class DelugeGTK:
except KeyError:
pass
def set_ratio_0(self, widget):
unique_ids = self.get_selected_torrent_rows()
for uid in unique_ids:
self.manager.set_ratio(uid, 0)
def set_ratio_1(self, widget):
unique_ids = self.get_selected_torrent_rows()
for uid in unique_ids:
self.manager.set_ratio(uid, 1)
def set_ratio_2(self, widget):
unique_ids = self.get_selected_torrent_rows()
for uid in unique_ids:
self.manager.set_ratio(uid, 2)
def set_ratio_3(self, widget):
unique_ids = self.get_selected_torrent_rows()
for uid in unique_ids:
self.manager.set_ratio(uid, 3)
def torrent_menu_focus(self, widget, direction):
menuitem = self.torrent_glade.get_widget("menu_pause")
# Check if we are selecting multiple torrents