1 | /*
|
---|
2 | Script: deluge-ui.js
|
---|
3 | The core ui module that builds up the ui layout and controls the polling
|
---|
4 | of the server.
|
---|
5 |
|
---|
6 | Copyright:
|
---|
7 | (C) Damien Churchill 2009 <damoxc@gmail.com>
|
---|
8 | This program is free software; you can redistribute it and/or modify
|
---|
9 | it under the terms of the GNU General Public License as published by
|
---|
10 | the Free Software Foundation; either version 3, or (at your option)
|
---|
11 | any later version.
|
---|
12 |
|
---|
13 | This program is distributed in the hope that it will be useful,
|
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | GNU General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License
|
---|
19 | along with this program. If not, write to:
|
---|
20 | The Free Software Foundation, Inc.,
|
---|
21 | 51 Franklin Street, Fifth Floor
|
---|
22 | Boston, MA 02110-1301, USA.
|
---|
23 | */
|
---|
24 |
|
---|
25 | Deluge.UI = {
|
---|
26 |
|
---|
27 | cookies: new Ext.state.CookieProvider(),
|
---|
28 |
|
---|
29 | errorCount: 0,
|
---|
30 |
|
---|
31 | initialize: function() {
|
---|
32 | Ext.state.Manager.setProvider(this.cookies);
|
---|
33 | this.MainPanel = new Ext.Panel({
|
---|
34 | id: 'mainPanel',
|
---|
35 | iconCls: 'x-deluge-main-panel',
|
---|
36 | title: 'Deluge',
|
---|
37 | layout: 'border',
|
---|
38 | tbar: Deluge.Toolbar,
|
---|
39 | items: [
|
---|
40 | Deluge.Sidebar,
|
---|
41 | Deluge.Details,
|
---|
42 | Deluge.Torrents
|
---|
43 | ],
|
---|
44 | bbar: Deluge.Statusbar
|
---|
45 | });
|
---|
46 |
|
---|
47 | this.Viewport = new Ext.Viewport({
|
---|
48 | layout: 'fit',
|
---|
49 | items: [this.MainPanel]
|
---|
50 | });
|
---|
51 |
|
---|
52 | Deluge.Login.show();
|
---|
53 |
|
---|
54 | Deluge.Events.on("connect", this.onConnect, this);
|
---|
55 | Deluge.Events.on("disconnect", this.onDisconnect, this);
|
---|
56 | Deluge.Client = new Ext.ux.util.RpcClient({url: '/json'});
|
---|
57 | this.update = this.update.bind(this);
|
---|
58 | },
|
---|
59 |
|
---|
60 | update: function() {
|
---|
61 | var filters = Deluge.Sidebar.getFilters();
|
---|
62 | Deluge.Client.web.update_ui(Deluge.Keys.Grid, filters, {
|
---|
63 | success: this.onUpdate,
|
---|
64 | failure: this.onUpdateError,
|
---|
65 | scope: this
|
---|
66 | });
|
---|
67 | Deluge.Details.update();
|
---|
68 | Deluge.Client.web.connected({
|
---|
69 | success: this.onConnectedCheck,
|
---|
70 | scope: this
|
---|
71 | });
|
---|
72 | },
|
---|
73 |
|
---|
74 | onConnectedCheck: function(connected) {
|
---|
75 | if (!connected) {
|
---|
76 | Deluge.Events.fire('disconnect');
|
---|
77 | }
|
---|
78 | },
|
---|
79 |
|
---|
80 | onUpdateError: function(error) {
|
---|
81 | if (this.errorCount == 2) {
|
---|
82 | Ext.MessageBox.show({
|
---|
83 | title: 'Lost Connection',
|
---|
84 | msg: 'The connection to the webserver has been lost!',
|
---|
85 | buttons: Ext.MessageBox.OK,
|
---|
86 | icon: Ext.MessageBox.ERROR
|
---|
87 | });
|
---|
88 | }
|
---|
89 | this.errorCount++;
|
---|
90 | },
|
---|
91 |
|
---|
92 | onUpdate: function(data) {
|
---|
93 | var torrents = [];
|
---|
94 | for (var torrentId in data['torrents']) {
|
---|
95 | var torrent = data['torrents'][torrentId];
|
---|
96 | torrents.push([torrent.queue,
|
---|
97 | torrent.name,
|
---|
98 | torrent.total_size,
|
---|
99 | torrent.state,
|
---|
100 | torrent.progress,
|
---|
101 | torrent.num_seeds,
|
---|
102 | torrent.total_seeds,
|
---|
103 | torrent.num_peers,
|
---|
104 | torrent.total_peers,
|
---|
105 | torrent.download_payload_rate,
|
---|
106 | torrent.upload_payload_rate,
|
---|
107 | torrent.eta,
|
---|
108 | torrent.ratio,
|
---|
109 | torrent.distributed_copies,
|
---|
110 | torrent.time_added,
|
---|
111 | torrent.tracker_host,
|
---|
112 | torrentId
|
---|
113 | ]);
|
---|
114 | }
|
---|
115 | Deluge.Torrents.getStore().loadData(torrents);
|
---|
116 | Deluge.Statusbar.update(data['stats']);
|
---|
117 | Deluge.Sidebar.update(data['filters']);
|
---|
118 | this.errorCount = 0;
|
---|
119 | },
|
---|
120 |
|
---|
121 | /*
|
---|
122 | Property: run
|
---|
123 | Start the Deluge UI polling the server to get the updated torrent
|
---|
124 | information.
|
---|
125 |
|
---|
126 | Example:
|
---|
127 | Deluge.UI.onConnect();
|
---|
128 | */
|
---|
129 | onConnect: function() {
|
---|
130 | if (!this.running) {
|
---|
131 | this.running = setInterval(this.update, 2000);
|
---|
132 | this.update();
|
---|
133 | }
|
---|
134 | },
|
---|
135 |
|
---|
136 | onDisconnect: function() {
|
---|
137 | this.stop();
|
---|
138 | },
|
---|
139 |
|
---|
140 | /*
|
---|
141 | Property: stop
|
---|
142 | Stop the Deluge UI polling the server to get the updated torrent
|
---|
143 | information.
|
---|
144 |
|
---|
145 | Example:
|
---|
146 | Deluge.UI.stop();
|
---|
147 | */
|
---|
148 | stop: function() {
|
---|
149 | if (this.running) {
|
---|
150 | clearInterval(this.running);
|
---|
151 | this.running = false;
|
---|
152 | Deluge.Torrents.getStore().loadData([]);
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | Ext.onReady(function(e) {
|
---|
158 | Deluge.UI.initialize();
|
---|
159 | });
|
---|