2
# -*- coding: utf-8 -*-
4
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3, or (at your option)
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, write to:
18
# The Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor
20
# Boston, MA 02110-1301, USA.
22
# In addition, as a special exception, the copyright holders give
23
# permission to link the code of portions of this program with the OpenSSL
25
# You must obey the GNU General Public License in all respects for all of
26
# the code used other than OpenSSL. If you modify file(s) with this
27
# exception, you may extend this exception to your version of the file(s),
28
# but you are not obligated to do so. If you do not wish to do so, delete
29
# this exception statement from your version. If you delete this exception
30
# statement from all source files in the program, then also delete it here.
36
from deluge.ui.client import sclient as proxy
37
from deluge.log import LOG as log
38
from deluge import component
41
from render import render, error_page
42
import page_decorators as deco
43
import lib.newforms_plus as forms
46
class OptionsForm(forms.Form):
47
download_location = forms.ServerFolder(_("Download Location"))
48
compact_allocation = forms.CheckBox(_("Compact Allocation"))
51
max_download_speed_per_torrent = forms.DelugeFloat(
52
_("Maximum Down Speed"))
53
max_upload_speed_per_torrent = forms.DelugeFloat(
54
_("Maximum Up Speed"))
55
max_connections_per_torrent = forms.DelugeInt(_("Maximum Connections"))
56
max_upload_slots_per_torrent = forms.DelugeInt(_("Maximum Upload Slots"))
58
prioritize_first_last_pieces = forms.CheckBox(
59
_('Prioritize first and last pieces'))
60
add_paused = forms.CheckBox(_('Add In Paused State'))
61
default_private = forms.CheckBox(_('Set Private Flag'))
63
def initial_data(self):
64
data = proxy.get_config()
65
log.debug("add:Init options with:%s" % data)
68
class AddForm(forms.Form):
69
url = forms.CharField(label=_("Url"), required=False,
70
widget=forms.TextInput(attrs={'size':60}))
71
torrent = forms.CharField(label=_("Upload torrent"), required=False,
72
widget=forms.FileInput(attrs={'size':60}))
73
#hash = forms.CharField(label=_("Hash"), required=False,
74
# widget=forms.TextInput(attrs={'size':60}))
75
#ret = forms.CheckBox(_('Add more'))
77
#choose_files = forms.CheckBox(_('Choose Files')) #BROKEN!
82
def add_page(self,error = None):
83
vars = web.input(url = None)
84
form_data = {'url':vars.url}
88
options_data = utils.get_newforms_data(OptionsForm)
89
log.debug("add:(error-state):Init options with:%s" % options_data)
90
return render.torrent_add(AddForm(form_data),OptionsForm(options_data), error)
94
return self.add_page()
104
vars = web.input(url = None, torrent = {},choose_files = False)
106
options_form = OptionsForm(utils.get_newforms_data(OptionsForm))
107
if not options_form.is_valid():
108
print self.add_page(error = _("Error in torrent options."))
110
options = options_form.cleaned_data
116
if vars.torrent.filename:
117
torrent_name = vars.torrent.filename
118
torrent_data = vars.torrent.file.read()
120
if vars.url and torrent_name:
121
#error_page(_("Choose an url or a torrent, not both."))
122
print self.add_page(error = _("Choose an url or a torrent, not both."))
126
proxy.add_torrent_url(vars.url,options)
127
log.debug("add-url:options :%s" % options)
128
self.redirect(vars.choose_files)
130
proxy.add_torrent_file_binary(vars.torrent.filename, torrent_data, options)
131
log.debug("add-file:options :%s" % options)
132
self.redirect(vars.choose_files)
134
print self.add_page(error = _("No data"))
137
def redirect(self,choose_files):
138
if choose_files: #redirect to file chooser
139
torrent_id = proxy.get_session_state()[-1] #HACK! no return-value for torrent_add_*
140
utils.seeother("/torrent/files/%s" % torrent_id)
147
component.get("PageManager").register_page("/torrent/add(.*)",torrent_add)
b'\\ No newline at end of file'