2007-06-25 09:58:32 +00:00
|
|
|
# Copyright (C) 2007 - Andrew Resch <andrewresch@gmail.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-06-12 08:13:16 +00:00
|
|
|
|
2007-06-25 09:58:32 +00:00
|
|
|
### Initialization ###
|
2007-06-12 08:13:16 +00:00
|
|
|
|
2007-11-22 00:02:06 +00:00
|
|
|
plugin_name = "Torrent Creator"
|
2007-06-25 09:58:32 +00:00
|
|
|
plugin_author = "Andrew Resch"
|
2007-06-12 08:13:16 +00:00
|
|
|
plugin_version = "0.1"
|
2007-06-25 09:58:32 +00:00
|
|
|
plugin_description = _("A torrent creator plugin")
|
2007-06-12 08:13:16 +00:00
|
|
|
|
|
|
|
def deluge_init(deluge_path):
|
|
|
|
global path
|
|
|
|
path = deluge_path
|
|
|
|
|
|
|
|
def enable(core, interface):
|
|
|
|
global path
|
2007-06-25 09:58:32 +00:00
|
|
|
return TorrentCreator(path, core, interface)
|
|
|
|
|
|
|
|
### The Plugin ###
|
|
|
|
|
|
|
|
import deluge
|
|
|
|
import gtk, gtk.glade
|
2007-12-14 01:19:39 +00:00
|
|
|
import os.path
|
2007-06-25 09:58:32 +00:00
|
|
|
|
|
|
|
class TorrentCreator:
|
|
|
|
|
|
|
|
def __init__(self, path, core, interface):
|
2007-06-26 01:17:15 +00:00
|
|
|
print "Loading TorrentCreator plugin..."
|
2007-06-25 09:58:32 +00:00
|
|
|
self.path = path
|
|
|
|
self.core = core
|
|
|
|
self.interface = interface
|
|
|
|
self.glade = None
|
|
|
|
|
|
|
|
# Add 'New Torrent' menu item to the File menu
|
|
|
|
self.menuitem_image = gtk.Image()
|
|
|
|
self.menuitem_image.set_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU)
|
|
|
|
|
2007-06-27 05:45:18 +00:00
|
|
|
self.menuitem = gtk.ImageMenuItem(_("_New Torrent"))
|
2007-06-25 09:58:32 +00:00
|
|
|
self.menuitem.set_image(self.menuitem_image)
|
|
|
|
self.menuitem.connect("activate", self.new_torrent_clicked)
|
|
|
|
self.interface.wtree.get_widget("menu_file").get_submenu().prepend(self.menuitem)
|
|
|
|
self.menuitem.show_all()
|
|
|
|
|
|
|
|
# Add a 'New Torrent' button to the toolbar
|
|
|
|
self.toolbutton_image = gtk.Image()
|
|
|
|
self.toolbutton_image.set_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU)
|
|
|
|
|
|
|
|
self.toolbutton = gtk.ToolButton(self.toolbutton_image, _("New Torrent"))
|
2007-06-26 22:56:43 +00:00
|
|
|
self.toolbutton_tip = gtk.Tooltips()
|
2007-06-27 05:45:18 +00:00
|
|
|
self.toolbutton.set_tooltip(self.toolbutton_tip, _("Create New Torrent"))
|
2007-06-25 09:58:32 +00:00
|
|
|
self.toolbutton.connect("clicked", self.new_torrent_clicked)
|
|
|
|
self.interface.wtree.get_widget("tb_left").insert(self.toolbutton, 0)
|
|
|
|
self.toolbutton.show_all()
|
|
|
|
|
2007-06-26 01:17:15 +00:00
|
|
|
def destroy(self, data=None):
|
2007-06-25 09:58:32 +00:00
|
|
|
self.dialog.hide()
|
2007-06-26 01:17:15 +00:00
|
|
|
self.dialog.destroy()
|
2007-06-25 09:58:32 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def unload(self):
|
2007-06-26 01:17:15 +00:00
|
|
|
print "Unloading TorrentCreator plugin..."
|
|
|
|
self.interface.wtree.get_widget("menu_file").get_submenu().remove(self.menuitem)
|
|
|
|
self.interface.wtree.get_widget("tb_left").remove(self.toolbutton)
|
|
|
|
|
2007-06-25 09:58:32 +00:00
|
|
|
|
|
|
|
def new_torrent_clicked(self, widget, data=None):
|
|
|
|
# Show the torrent creator dialog
|
2007-12-14 01:19:39 +00:00
|
|
|
self.glade = gtk.glade.XML(os.path.join(self.path, "torrentcreator.glade"))
|
2007-06-25 09:58:32 +00:00
|
|
|
|
|
|
|
self.dialog = self.glade.get_widget("torrentcreator")
|
2007-10-26 03:19:30 +00:00
|
|
|
self.glade.get_widget("piece_size_combobox").set_active(3)
|
2007-06-25 23:11:16 +00:00
|
|
|
self.glade.get_widget("torrent_chooserbutton").connect("clicked", self.torrent_chooserbutton_clicked)
|
2007-06-26 01:17:15 +00:00
|
|
|
self.glade.get_widget("ok_button").connect("clicked", self.create_torrent)
|
|
|
|
self.glade.get_widget("close_button").connect("clicked", self.destroy)
|
2007-06-25 09:58:32 +00:00
|
|
|
self.dialog.show_all()
|
|
|
|
response = self.dialog.run()
|
|
|
|
|
2007-06-26 01:17:15 +00:00
|
|
|
if response == 0:
|
|
|
|
self.destroy()
|
|
|
|
|
2007-06-25 09:58:32 +00:00
|
|
|
return
|
2007-06-25 23:11:16 +00:00
|
|
|
|
|
|
|
def torrent_chooserbutton_clicked(self, widget):
|
2007-07-16 23:17:53 +00:00
|
|
|
filechooser = gtk.FileChooserDialog(title=_("Save file as..."),
|
|
|
|
parent=None, action=gtk.FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_OK, gtk.RESPONSE_OK), backend=None)
|
2007-06-25 23:11:16 +00:00
|
|
|
response = filechooser.run()
|
|
|
|
# Update the torrentfile entry widget if a file was selected.
|
|
|
|
if response == gtk.RESPONSE_OK:
|
2007-07-16 23:17:53 +00:00
|
|
|
torrent = filechooser.get_filename()
|
|
|
|
if not torrent.endswith(".torrent"):
|
|
|
|
torrent += ".torrent"
|
|
|
|
self.glade.get_widget("torrentfile_entry").set_text(torrent)
|
2007-06-25 09:58:32 +00:00
|
|
|
|
2007-06-25 23:11:16 +00:00
|
|
|
filechooser.destroy()
|
|
|
|
|
2007-06-26 01:17:15 +00:00
|
|
|
def create_torrent(self, widget):
|
2007-06-25 09:58:32 +00:00
|
|
|
# Create a torrent from the information provided in the torrentcreator dialog
|
|
|
|
if self.glade.get_widget("folder_radiobutton").get_active():
|
|
|
|
source = self.glade.get_widget("folder_chooserbutton").get_filename()
|
|
|
|
else:
|
|
|
|
source = self.glade.get_widget("file_chooserbutton").get_filename()
|
2007-06-26 01:17:15 +00:00
|
|
|
|
|
|
|
if source == "" or source == None:
|
|
|
|
deluge.dialogs.show_popup_warning(self.dialog, _("You must select a source for the torrent."))
|
|
|
|
return False
|
2007-06-25 09:58:32 +00:00
|
|
|
|
2007-06-25 23:11:16 +00:00
|
|
|
torrent = self.glade.get_widget("torrentfile_entry").get_text()
|
2007-06-25 09:58:32 +00:00
|
|
|
|
2007-06-26 01:17:15 +00:00
|
|
|
if torrent == "" or torrent == None:
|
|
|
|
# Send alert to the user that we need a torrent filename to save to
|
|
|
|
deluge.dialogs.show_popup_warning(self.dialog, _("You must select a file to save the torrent as."))
|
|
|
|
return False
|
2007-07-16 23:17:53 +00:00
|
|
|
|
2007-06-25 09:58:32 +00:00
|
|
|
piece_size = self.glade.get_widget("piece_size_combobox")
|
2007-06-26 01:17:15 +00:00
|
|
|
piece_size = int(piece_size.get_model().get_value(piece_size.get_active_iter(), 0).split(" ")[0])
|
2007-06-25 09:58:32 +00:00
|
|
|
|
|
|
|
trackers = self.glade.get_widget("trackers_textview").get_buffer()
|
|
|
|
(start, end) = trackers.get_bounds()
|
|
|
|
trackers = trackers.get_text(start, end).strip()
|
2007-12-02 22:36:02 +00:00
|
|
|
|
|
|
|
webseeds = self.glade.get_widget("webseeds_textview").get_buffer()
|
|
|
|
(start, end) = webseeds.get_bounds()
|
|
|
|
webseeds = webseeds.get_text(start, end).strip()
|
2007-06-26 01:17:15 +00:00
|
|
|
|
2007-06-25 09:58:32 +00:00
|
|
|
comments = self.glade.get_widget("comments_textview").get_buffer()
|
|
|
|
(start, end) = comments.get_bounds()
|
|
|
|
comments = comments.get_text(start, end).strip()
|
|
|
|
|
|
|
|
author = self.glade.get_widget("author_entry").get_text()
|
|
|
|
|
2007-06-26 01:17:15 +00:00
|
|
|
if author == "" or author == None:
|
|
|
|
author = _("Deluge")
|
|
|
|
|
|
|
|
add_torrent = self.glade.get_widget("add_torrent_checkbox").get_active()
|
2007-09-05 17:35:44 +00:00
|
|
|
set_private = self.glade.get_widget("chk_set_priv").get_active()
|
2007-06-26 01:17:15 +00:00
|
|
|
# Destroy the dialog.. we don't need it anymore
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
# Create the torrent and add it to the queue if necessary
|
2007-07-16 23:17:53 +00:00
|
|
|
if self.core.create_torrent(torrent, source, trackers, comments,
|
2007-12-02 22:36:02 +00:00
|
|
|
piece_size, author, set_private, webseeds) == 1:
|
2007-06-26 01:17:15 +00:00
|
|
|
# Torrent was created successfully
|
|
|
|
if add_torrent:
|
|
|
|
# We need to add this torrent to the queue
|
2007-07-16 03:23:36 +00:00
|
|
|
self.interface.interactive_add_torrent(torrent)
|
2007-06-26 01:17:15 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|