From ede8627b77ef32136369d24737eb0b42b80c5811 Mon Sep 17 00:00:00 2001 From: Alex Dedul Date: Sun, 15 Jul 2007 16:53:54 +0000 Subject: [PATCH] Added core.prioritize_files(). --- src/core.py | 4 ++++ src/deluge_core.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/core.py b/src/core.py index 2df250b4e..e727061bd 100644 --- a/src/core.py +++ b/src/core.py @@ -600,6 +600,10 @@ class Manager: except AttributeError: return None + # Priorities functions + def prioritize_files(self, unique_ID, priorities): + deluge_core.prioritize_files(unique_ID, priorities) + # Called when a session starts, to apply existing filters def apply_all_file_filters(self): for unique_ID in self.unique_IDs.keys(): diff --git a/src/deluge_core.cpp b/src/deluge_core.cpp index db60a477f..9a7e9e350 100644 --- a/src/deluge_core.cpp +++ b/src/deluge_core.cpp @@ -1443,6 +1443,34 @@ static PyObject *torrent_set_flp(PyObject *self, PyObject *args) return Py_None; } + +static PyObject *torrent_prioritize_files(PyObject *self, PyObject *args) +{ + python_long unique_ID; + PyObject *priorities_list_object; + + if (!PyArg_ParseTuple(args, "iO", &unique_ID, &priorities_list_object)) + return NULL; + long index = get_index_from_unique_ID(unique_ID); + if (PyErr_Occurred()) + return NULL; + + torrent_t &t = M_torrents->at(index); + int num_files = t.handle.get_torrent_info().num_files(); + assert(PyList_Size(priorities_list_object) == num_files); + + std::vector priorities_vector(num_files); + + for (long i = 0; i < num_files; i++) { + priorities_vector.at(i) = + PyInt_AsLong(PyList_GetItem(priorities_list_object, i)); + } + + t.handle.prioritize_files(priorities_vector); + + return Py_None; +} + //==================== // Python Module data //==================== @@ -1490,6 +1518,7 @@ static PyMethodDef deluge_core_methods[] = {"get_trackers", torrent_get_trackers, METH_VARARGS, "."}, {"replace_trackers", torrent_replace_trackers, METH_VARARGS, "."}, {"set_flp", torrent_set_flp, METH_VARARGS, "."}, + {"prioritize_files", torrent_prioritize_files, METH_VARARGS, "."}, {NULL} };