Browse Source

Add option to rename torrent from WebUI

Addresses #6815.
adaptive-webui-19844
Thomas Piccirello 8 years ago committed by Vladimir Golovnev (qlassez)
parent
commit
798c230634
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 22
      src/webui/webapplication.cpp
  2. 1
      src/webui/webapplication.h
  3. 1
      src/webui/webui.qrc
  4. 1
      src/webui/www/private/index.html
  5. 63
      src/webui/www/public/rename.html
  6. 24
      src/webui/www/public/scripts/mocha-init.js
  7. 3
      src/webui/www/public/transferlist.html

22
src/webui/webapplication.cpp

@ -30,6 +30,8 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QTimer> #include <QTimer>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QRegularExpression>
#include <queue> #include <queue>
#include <vector> #include <vector>
@ -119,6 +121,7 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
ADD_ACTION(command, topPrio); ADD_ACTION(command, topPrio);
ADD_ACTION(command, bottomPrio); ADD_ACTION(command, bottomPrio);
ADD_ACTION(command, setLocation); ADD_ACTION(command, setLocation);
ADD_ACTION(command, rename);
ADD_ACTION(command, recheck); ADD_ACTION(command, recheck);
ADD_ACTION(command, setCategory); ADD_ACTION(command, setCategory);
ADD_ACTION(command, addCategory); 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() void WebApplication::action_command_recheck()
{ {
CHECK_URI(0); CHECK_URI(0);

1
src/webui/webapplication.h

@ -91,6 +91,7 @@ private:
void action_command_topPrio(); void action_command_topPrio();
void action_command_bottomPrio(); void action_command_bottomPrio();
void action_command_setLocation(); void action_command_setLocation();
void action_command_rename();
void action_command_recheck(); void action_command_recheck();
void action_command_setCategory(); void action_command_setCategory();
void action_command_addCategory(); void action_command_addCategory();

1
src/webui/webui.qrc

@ -42,5 +42,6 @@
<file>www/public/uploadlimit.html</file> <file>www/public/uploadlimit.html</file>
<file>www/public/newcategory.html</file> <file>www/public/newcategory.html</file>
<file>www/public/setlocation.html</file> <file>www/public/setlocation.html</file>
<file>www/public/rename.html</file>
</qresource> </qresource>
</RCC> </RCC>

1
src/webui/www/private/index.html

@ -109,6 +109,7 @@
<li class="separator"><a href="#Delete"><img src="theme/list-remove" alt="QBT_TR(Delete)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Delete)QBT_TR[CONTEXT=TransferListWidget]</a></li> <li class="separator"><a href="#Delete"><img src="theme/list-remove" alt="QBT_TR(Delete)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Delete)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li class="separator"> <li class="separator">
<a href="#SetLocation"><img src="theme/inode-directory" alt="QBT_TR(Set location...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Set location...)QBT_TR[CONTEXT=TransferListWidget]</a> <a href="#SetLocation"><img src="theme/inode-directory" alt="QBT_TR(Set location...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Set location...)QBT_TR[CONTEXT=TransferListWidget]</a>
<a href="#Rename"><img src="theme/edit-rename" alt="QBT_TR(Rename...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Rename...)QBT_TR[CONTEXT=TransferListWidget]</a>
</li> </li>
<li> <li>
<a href="#Category" class="arrow-right"><img src="theme/view-categories" alt="QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]</a> <a href="#Category" class="arrow-right"><img src="theme/view-categories" alt="QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]</a>

63
src/webui/www/public/rename.html

@ -0,0 +1,63 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>QBT_TR(Rename)QBT_TR[CONTEXT=TransferListWidget]</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/misc.js"></script>
<script type="text/javascript">
var renameKeyboardEvents = new Keyboard({
defaultEventType: 'keydown',
events: {
'enter': function (event) {
$('renameButton').click();
event.preventDefault();
}
}
});
renameKeyboardEvents.activate();
window.addEvent('domready', function() {
var name = new URI().getData('name');
// set text field to current value
if (name)
$('rename').value = escapeHtml(name);
$('rename').focus();
$('renameButton').addEvent('click', function(e) {
new Event(e).stop();
// check field
var name = $('rename').value.trim();
if (name === null || name === "")
return false;
var hash = new URI().getData('hash');
if (hash) {
new Request({
url: 'command/rename',
method: 'post',
data: {
hash: hash,
name: name
},
onComplete: function () {
window.parent.closeWindows();
}
}).send();
}
});
});
</script>
</head>
<body>
<div style="padding: 10px 10px 0px 10px;">
<p style="font-weight: bold;">QBT_TR(New name)QBT_TR[CONTEXT=TransferListWidget]:</p>
<input type="text" id="rename" value="" maxlength="100" style="width: 220px;"/>
<div style="text-align: center; padding-top: 10px;">
<input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="renameButton"/>
</div>
</div>
</body>
</html>

24
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 () { torrentNewCategoryFN = function () {
var hashes = torrentsTable.selectedRowsIds(); var hashes = torrentsTable.selectedRowsIds();
if (hashes.length) { if (hashes.length) {

3
src/webui/www/public/transferlist.html

@ -40,6 +40,9 @@
setLocationFN(); setLocationFN();
}, },
Rename : function(element, ref) {
renameFN();
},
prioTop : function (element, ref) { prioTop : function (element, ref) {
setPriorityFN('topPrio'); setPriorityFN('topPrio');
}, },

Loading…
Cancel
Save