Permalink
Browse files

register webilder_desktop as a mime-type handler for wbz and wbp files.

  • Loading branch information...
1 parent 2de3d0d commit 1919fb8c38ab2a65afb431ab2e6e94d3741d1c42 @thesamet committed Jul 24, 2010
View
@@ -0,0 +1,2 @@
+application/x-webshots; /usr/bin/webilder_desktop '%s'; description=Webshots
+Archive
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
+ <mime-type type="application/x-webshots">
+ <comment>Webshots photo</comment>
+ <glob pattern="*.wbz"/>
+ <glob pattern="*.wbp"/>
+ </mime-type>
+</mime-info>
@@ -13,3 +13,4 @@ TryExec=webilder_desktop
Terminal=false
Icon=camera48.png
+MimeType=application/x-webshots;
@@ -18,6 +18,7 @@
from webilder.webshots import wbz
import sys, os, time, glob, gc
+import optparse
import gtk, gobject
import pkg_resources
@@ -338,9 +339,7 @@ def on_file_webshots_import_handle_activate(self, _event):
files = []
finally:
dlg.destroy()
-
- for afile in files:
- wbz_handler.handle_file(afile)
+ import_files(files)
def on_donate_handle_activate(self, _widget):
"""Donate menu item clicked."""
@@ -543,21 +542,60 @@ def configure():
config_dialog.ConfigDialog().run_dialog(config)
+def import_files(files):
+ success_count = 0
+ for afile in files:
+ try:
+ success_count += wbz_handler.handle_file(afile)
+ except (IOError, KeyError, ValueError), e:
+ mbox = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
+ buttons=gtk.BUTTONS_OK)
+ mbox.set_title(_("File import error."))
+ mbox.set_markup(_("Could not import '%s': %s") % (afile, e))
+ mbox.run()
+ mbox.destroy()
+
+ if success_count:
+ mbox = gtk.MessageDialog(type=gtk.MESSAGE_INFO,
+ buttons=gtk.BUTTONS_OK)
+ mbox.set_title(_("Import complete."))
+ mbox.set_markup(_("%d photos have been added to your collection.")
+ % success_count)
+ mbox.run()
+ mbox.destroy()
+
+
def main():
"""Command line entrypoint."""
+ parser = optparse.OptionParser()
+ parser.add_option(
+ '--configure', dest="configure", help="Open configuration dialog"
+ "and quit.", action="store_true", default=False)
+ parser.add_option(
+ '--download', dest="download", help="Download photos and quit.",
+ action="store_true", default=False)
+ options, args = parser.parse_args()
+
gtk.gdk.threads_init()
- if '--configure' in sys.argv:
+ if options.configure:
configure()
- elif '--download' in sys.argv:
+ return
+
+ if options.download:
download_dialog = DownloadDialog.DownloadProgressDialog(config)
main_window = download_dialog
download_dialog.top_widget.connect('destroy', gtk.main_quit)
download_dialog.show()
gtk.main()
- else:
- main_window = WebilderDesktopWindow()
- main_window.top_widget.connect("destroy", gtk.main_quit)
- gtk.main()
+ return
+
+ if args:
+ import_files(args)
+ return
+
+ main_window = WebilderDesktopWindow()
+ main_window.top_widget.connect("destroy", gtk.main_quit)
+ gtk.main()
if __name__ == "__main__":
main()
@@ -13,6 +13,7 @@ def handle_wbz(wbzfile):
"""Imports the given wbz filename."""
fileobj = wbz.open(wbzfile, 'r')
handle_image(fileobj)
+ return 1
def handle_image(img):
"""Handled a parsed wbz object."""
@@ -34,7 +35,7 @@ def handle_image(img):
def handle_wbp(wbpfile):
"""Imports the given wbp filename."""
wbpfile = wbp.open(wbpfile, 'r')
- return [handle_image(picture.image) for picture in wbpfile.pictures]
+ return len([handle_image(picture.image) for picture in wbpfile.pictures])
def handle_file(filename):
@@ -43,11 +44,11 @@ def handle_file(filename):
magic, = struct.unpack('=L', fileobj.read(4))
fileobj.close()
if magic == wbz.WBZ_ID:
- handle_wbz(filename)
+ return handle_wbz(filename)
elif magic == wbp.WBP_ID:
- handle_wbp(filename)
+ return handle_wbp(filename)
else:
- raise IOError, _("Unrecognized file type")
+ raise IOError("Unrecognized file type")
def main():
"""Command line interface to wbz_handler."""
@@ -57,9 +58,9 @@ def main():
Usage:
- wbz_handler filename.wbz
+ wbz_handler filename.wbz|filename.wbp
-Where filename.wbz is a Webshots archive.""")
+Where the argument is a Webshots wbz or wbp archive.""")
sys.exit(1)
handle_file(sys.argv[1])

0 comments on commit 1919fb8

Please sign in to comment.