# Copyright (C) 2009 Lars Wirzenius # # 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 3 of the License, 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, see . # This is necessary for running under Python 2.5, which we need to # do on Debian, for now. from __future__ import with_statement import os import shutil import gtk import dimbola class ExportOriginal(dimbola.BackgroundJob): def __init__(self, mwc, photoid, dirname): self.dirname = dirname with mwc.db: folderid, basename, c, d = mwc.db.get_basic_photo_metadata(photoid) self.foldername = mwc.db.get_folder_name(folderid) self.basename = basename def run(self): status = dimbola.BackgroundStatus('start', 'Exporting %s' % self.basename) self.send_status(status) shutil.copy(os.path.join(self.foldername, self.basename), os.path.join(self.dirname, self.basename)) return dimbola.BackgroundStatus('stop', 'Exported %s' % self.basename) class ExportJpeg(dimbola.BackgroundJob): def __init__(self, mwc, photoid, dirname): self.dirname = dirname self.basename = 'foo' with mwc.db: self.preview = str(mwc.db.get_preview(photoid)) a, basename, c, rotate = mwc.db.get_basic_photo_metadata(photoid) self.basename = basename self.rotate = rotate def run(self): pixbuf = dimbola.image_data_to_pixbuf(self.preview) pixbuf = dimbola.rotate_pixbuf(pixbuf, self.rotate) basename, ext = os.path.splitext(self.basename) new_basename = basename + '.jpg' pixbuf.save(os.path.join(self.dirname, new_basename), "jpeg") return dimbola.BackgroundStatus('stop', 'Exported %s' % new_basename) class ExportFiles(dimbola.Plugin): '''Export selected files using background jobs.''' def __init__(self, mwc): self.mwc = mwc def enable(self): self.mwc.add_to_menu('file_menu', 'export_menuitem', 'Export selected photos') def disable(self): self.mwc.remove_from_menu('file_menu', 'export_menuitem') def on_export_menuitem_activate(self, menuitem): chooser = self.mwc.widgets['export_filechooser'] chooser.set_transient_for(self.mwc.widgets['window']) chooser.show() response = chooser.run() chooser.hide() if response == gtk.RESPONSE_OK: dirname = chooser.get_filenames()[0] origs = self.mwc.widgets['export_original_radiobutton'].get_active() selected = self.mwc.grid.model.selected for photoid in selected: if origs: job = ExportOriginal(self.mwc, photoid, dirname) else: job = ExportJpeg(self.mwc, photoid, dirname) self.mwc.add_bgjob(job) def export_menuitem_is_sensitive(self): return self.mwc.grid.model.selected