From 798c23063445a131bb76a6eed091937bff6aaad4 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Tue, 4 Jul 2017 05:54:43 -0400 Subject: [PATCH] Add option to rename torrent from WebUI Addresses #6815. --- src/webui/webapplication.cpp | 22 ++++++++ src/webui/webapplication.h | 1 + src/webui/webui.qrc | 1 + src/webui/www/private/index.html | 1 + src/webui/www/public/rename.html | 63 ++++++++++++++++++++++ src/webui/www/public/scripts/mocha-init.js | 24 +++++++++ src/webui/www/public/transferlist.html | 3 ++ 7 files changed, 115 insertions(+) create mode 100644 src/webui/www/public/rename.html diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index f9ff7927c..3c8a2079c 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -30,6 +30,8 @@ #include #include #include +#include + #include #include @@ -119,6 +121,7 @@ QMap > WebApplication::initialize ADD_ACTION(command, topPrio); ADD_ACTION(command, bottomPrio); ADD_ACTION(command, setLocation); + ADD_ACTION(command, rename); ADD_ACTION(command, recheck); ADD_ACTION(command, setCategory); ADD_ACTION(command, addCategory); @@ -800,6 +803,25 @@ void WebApplication::action_command_setLocation() } } +void WebApplication::action_command_rename() +{ + CHECK_URI(0); + CHECK_PARAMETERS("hash" << "name"); + + QString hash = request().posts["hash"]; + QString name = request().posts["name"].trimmed(); + + BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); + if (torrent && !name.isEmpty()) { + name.replace(QRegularExpression("\r?\n|\r"), " "); + qDebug() << "Renaming" << torrent->name() << "to" << name; + torrent->setName(name); + } + else { + status(400, "Incorrect torrent hash or name"); + } +} + void WebApplication::action_command_recheck() { CHECK_URI(0); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 5e58e18e3..3f39946e6 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -91,6 +91,7 @@ private: void action_command_topPrio(); void action_command_bottomPrio(); void action_command_setLocation(); + void action_command_rename(); void action_command_recheck(); void action_command_setCategory(); void action_command_addCategory(); diff --git a/src/webui/webui.qrc b/src/webui/webui.qrc index 0e1cbac2b..7af7dafef 100644 --- a/src/webui/webui.qrc +++ b/src/webui/webui.qrc @@ -42,5 +42,6 @@ www/public/uploadlimit.html www/public/newcategory.html www/public/setlocation.html + www/public/rename.html diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 150016cb9..9cfb2cc94 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -109,6 +109,7 @@
  • QBT_TR(Delete)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Delete)QBT_TR[CONTEXT=TransferListWidget]
  • QBT_TR(Set location...)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Set location...)QBT_TR[CONTEXT=TransferListWidget] + QBT_TR(Rename...)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Rename...)QBT_TR[CONTEXT=TransferListWidget]
  • QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget] diff --git a/src/webui/www/public/rename.html b/src/webui/www/public/rename.html new file mode 100644 index 000000000..692d11488 --- /dev/null +++ b/src/webui/www/public/rename.html @@ -0,0 +1,63 @@ + + + + + QBT_TR(Rename)QBT_TR[CONTEXT=TransferListWidget] + + + + + + + +
    +

    QBT_TR(New name)QBT_TR[CONTEXT=TransferListWidget]:

    + +
    + +
    +
    + + diff --git a/src/webui/www/public/scripts/mocha-init.js b/src/webui/www/public/scripts/mocha-init.js index bd956e8e8..0c9bb35c0 100644 --- a/src/webui/www/public/scripts/mocha-init.js +++ b/src/webui/www/public/scripts/mocha-init.js @@ -338,6 +338,30 @@ initializeWindows = function() { } }; + renameFN = function() { + var hashes = torrentsTable.selectedRowsIds(); + if (hashes.length == 1) { + var hash = hashes[0]; + var row = torrentsTable.rows[hash]; + if (row) { + var name = row.full_data.name; + new MochaUI.Window({ + id: 'renamePage', + title: "QBT_TR(Rename)QBT_TR[CONTEXT=TransferListWidget]", + loadMethod: 'iframe', + contentURL: 'rename.html?hash=' + hashes[0] + '&name=' + name, + scrollbars: false, + resizable: false, + maximizable: false, + paddingVertical: 0, + paddingHorizontal: 0, + width: 250, + height: 100 + }); + } + } + }; + torrentNewCategoryFN = function () { var hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { diff --git a/src/webui/www/public/transferlist.html b/src/webui/www/public/transferlist.html index d28150441..fd2f3ccc6 100644 --- a/src/webui/www/public/transferlist.html +++ b/src/webui/www/public/transferlist.html @@ -40,6 +40,9 @@ setLocationFN(); }, + Rename : function(element, ref) { + renameFN(); + }, prioTop : function (element, ref) { setPriorityFN('topPrio'); },