diff options
Diffstat (limited to 'trunk/dimbola/plugins/export_plugin.py')
-rw-r--r-- | trunk/dimbola/plugins/export_plugin.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/trunk/dimbola/plugins/export_plugin.py b/trunk/dimbola/plugins/export_plugin.py new file mode 100644 index 0000000..d76187c --- /dev/null +++ b/trunk/dimbola/plugins/export_plugin.py @@ -0,0 +1,101 @@ +# Copyright (C) 2009 Lars Wirzenius <liw@liw.fi> +# +# 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 <http://www.gnu.org/licenses/>. + + +# 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 + |