Skip to content

Commit

Permalink
added register filebot button to preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Laharah committed Jan 26, 2019
1 parent a8b388e commit c8c416d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
# FilebotTool: FileBot Integration for Deluge
*requires [Filebot](http://www.filebot.net/)*

**Version 1.2.3**
**Version 1.2.4**

##### [Download Latest Release](https://github.com/Laharah/deluge-FilebotTool/releases/latest)

Expand Down
4 changes: 2 additions & 2 deletions filebottool/core.py
Expand Up @@ -913,7 +913,7 @@ def activate_filebot_license(self, data):
license_file.write(data)
license_file.close()
try:
result = yield threads.deferToThread(pyfilebot.license(license_file.name))
result = yield threads.deferToThread(pyfilebot.license, license_file.name)
except pyfilebot.FilebotLicenseError as error:
log.error("Error during licensing", exc_info=True)
result = "{0}: {1}".format(error.__class__.__name__, error.message)
Expand All @@ -922,4 +922,4 @@ def activate_filebot_license(self, data):
finally:
license_file.unlink(license_file.name)
del license_file
defer.retunValue(result)
defer.returnValue(result)
39 changes: 39 additions & 0 deletions filebottool/data/config.glade
Expand Up @@ -305,8 +305,47 @@
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="license_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip" translatable="yes">Select a license file that FileBot Should Use</property>
<signal name="clicked" handler="on_license_button_clicked"/>
<child>
<widget class="GtkHBox" id="hbox4">
<property name="visible">True</property>
<child>
<widget class="GtkImage" id="fb_icon">
<property name="visible">True</property>
<property name="stock">gtk-missing-image</property>
</widget>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="register_filebot_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Register FileBot</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
Expand Down
64 changes: 64 additions & 0 deletions filebottool/gtkui/config_ui.py
Expand Up @@ -2,6 +2,7 @@


import gtk
import os
import time
import webbrowser

Expand Down Expand Up @@ -34,6 +35,10 @@ def __init__(self, settings=None):
self.config_page = self.glade.get_widget("prefs_box")
self.pref_dialog = component.get("Preferences").pref_dialog

fb_icon = self.glade.get_widget("fb_icon")
image = get_resource("fb_icon16.png")
fb_icon.set_from_file(image)

model = gtk.ListStore(str)
view = self.glade.get_widget('saved_handlers_listview')
renderer = gtk.CellRendererText()
Expand Down Expand Up @@ -76,6 +81,7 @@ def text_edited(widget, path, text):
"on_add_rule": self.on_add_rule,
"on_auto_sort_help_clicked": self.on_auto_sort_help_clicked,
"on_debug_button_clicked": self.on_debug_button_clicked,
"on_license_button_clicked": self.on_license_button_clicked,
})
self.gather_time = None
if settings:
Expand Down Expand Up @@ -183,6 +189,64 @@ def on_debug_button_clicked(self, button):
dialog.display_text("Filebot Debug Info", info)
button.set_sensitive(True)

@defer.inlineCallbacks
def on_license_button_clicked(self, button):
log.debug("License button clicked.")
chooser = gtk.FileChooserDialog(_("Choose your FileBot license file"),
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,
gtk.RESPONSE_OK))

chooser.set_transient_for(self.pref_dialog)
chooser.set_property("skip-taskbar-hint", True)
chooser.set_local_only(False)

file_filter = gtk.FileFilter()
file_filter.set_name(_("FileBot license files"))
file_filter.add_pattern("*." + "psm")
chooser.add_filter(file_filter)
file_filter = gtk.FileFilter()
file_filter.set_name(_("All files"))
file_filter.add_pattern("*")
chooser.add_filter(file_filter)

# Run the dialog
response = chooser.run()

if response == gtk.RESPONSE_OK:
license = chooser.get_filenames()[0]
else:
chooser.destroy()
return
chooser.destroy()

# License file should definetly be under 10K
size = os.stat(license).st_size
if size > 10*1000:
e = user_messenger.InfoDialog("Error", "License file is too big.")
e.resize(220, 125)
e.run_async()
defer.returnValue()

with open(license, 'rb') as l:
license_data = l.read()
log.debug("Sending license data to server.")
result = yield client.filebottool.activate_filebot_license(license_data)
log.debug("Recieved reply from server: %s", result)
if result.startswith("FilebotLicenseError: "):
title = "Error with License File"
msg = result[21:]
else:
title = "Success!"
msg = result

dialog = user_messenger.InfoDialog(title, msg)
dialog.resize(220, 125)
dialog.run_async()




#########
# Section: Utilities
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -42,7 +42,7 @@
__plugin_name__ = "FileBotTool"
__author__ = "laharah"
__author_email__ = "laharah+fbt@gmail.com"
__version__ = "1.2.3"
__version__ = "1.2.4"
__url__ = "https://github.com/Laharah/deluge-FileBotTool"
__license__ = "GPLv3"
__description__ = "Integrates FileBot functionality to Deluge"
Expand Down

0 comments on commit c8c416d

Please sign in to comment.