From 24b094a04a754ddd6405a274f93c536fa5612105 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Fri, 21 Jun 2019 09:09:12 +0300 Subject: [PATCH] [WebUI] Handle torrent add failures Closes #2253. --- CHANGELOG.md | 4 ++++ deluge/ui/web/js/deluge-all/add/AddWindow.js | 23 ++++++++++++++++++++ deluge/ui/web/js/deluge-all/add/UrlWindow.js | 14 ++++++++++++ deluge/ui/web/js/deluge-all/add/Window.js | 2 +- docs/source/changelog.md | 2 +- 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58e0a882c..d4555df06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 2.0.4 (WIP) +### WebUI + +- Handle torrent add failures + ### Documentation - Add How-to guides about services. diff --git a/deluge/ui/web/js/deluge-all/add/AddWindow.js b/deluge/ui/web/js/deluge-all/add/AddWindow.js index 89803f3bf..a9db791f1 100644 --- a/deluge/ui/web/js/deluge-all/add/AddWindow.js +++ b/deluge/ui/web/js/deluge-all/add/AddWindow.js @@ -235,6 +235,7 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { this.url = new Deluge.add.UrlWindow(); this.url.on('beforeadd', this.onTorrentBeforeAdd, this); this.url.on('add', this.onTorrentAdd, this); + this.url.on('addfailed', this.onTorrentAddFailed, this); } this.optionsPanel.form.getDefaults(); @@ -258,6 +259,7 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { url: deluge.config.base + 'upload', waitMsg: _('Uploading your torrent...'), success: this.onUploadSuccess, + failure: this.onUploadFailure, scope: this, torrentIds: torrentIds, }); @@ -283,6 +285,19 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { this.fileUploadForm.reset(); }, + onUploadFailure: function(form, action) { + this.hide(); + Ext.MessageBox.show({ + title: _('Error'), + msg: _('Failed to upload torrent'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error', + }); + this.fireEvent('addfailed', this.torrentId); + }, + onGotInfo: function(info, obj, response, request) { info.filename = request.options.filename; torrentId = request.options.torrentId; @@ -315,6 +330,14 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { } }, + onTorrentAddFailed: function(torrentId) { + var store = this.list.getStore(); + var torrentRecord = store.getById(torrentId); + if (torrentRecord) { + store.remove(torrentRecord); + } + }, + onUrl: function(button, event) { this.url.show(); }, diff --git a/deluge/ui/web/js/deluge-all/add/UrlWindow.js b/deluge/ui/web/js/deluge-all/add/UrlWindow.js index d3a9a697c..88988bd04 100644 --- a/deluge/ui/web/js/deluge-all/add/UrlWindow.js +++ b/deluge/ui/web/js/deluge-all/add/UrlWindow.js @@ -72,6 +72,7 @@ Deluge.add.UrlWindow = Ext.extend(Deluge.add.Window, { } else { deluge.client.web.download_torrent_from_url(url, cookies, { success: this.onDownload, + failure: this.onDownloadFailed, scope: this, torrentId: torrentId, }); @@ -85,12 +86,25 @@ Deluge.add.UrlWindow = Ext.extend(Deluge.add.Window, { onDownload: function(filename, obj, resp, req) { deluge.client.web.get_torrent_info(filename, { success: this.onGotInfo, + failure: this.onDownloadFailed, scope: this, filename: filename, torrentId: req.options.torrentId, }); }, + onDownloadFailed: function(obj, resp, req) { + Ext.MessageBox.show({ + title: _('Error'), + msg: _('Failed to download torrent'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error', + }); + this.fireEvent('addfailed', req.options.torrentId); + }, + onGotInfo: function(info, obj, response, request) { info['filename'] = request.options.filename; this.fireEvent('add', request.options.torrentId, info); diff --git a/deluge/ui/web/js/deluge-all/add/Window.js b/deluge/ui/web/js/deluge-all/add/Window.js index 206b3eece..d2d576982 100644 --- a/deluge/ui/web/js/deluge-all/add/Window.js +++ b/deluge/ui/web/js/deluge-all/add/Window.js @@ -17,7 +17,7 @@ Ext.ns('Deluge.add'); Deluge.add.Window = Ext.extend(Ext.Window, { initComponent: function() { Deluge.add.Window.superclass.initComponent.call(this); - this.addEvents('beforeadd', 'add'); + this.addEvents('beforeadd', 'add', 'addfailed'); }, /** diff --git a/docs/source/changelog.md b/docs/source/changelog.md index 699cc9e7b..03cb73106 120000 --- a/docs/source/changelog.md +++ b/docs/source/changelog.md @@ -1 +1 @@ -../../CHANGELOG.md \ No newline at end of file +../../CHANGELOG.md