diff options
Diffstat (limited to 'trunk/dimbola/plugins/remove_photos_plugin.py')
-rw-r--r-- | trunk/dimbola/plugins/remove_photos_plugin.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/trunk/dimbola/plugins/remove_photos_plugin.py b/trunk/dimbola/plugins/remove_photos_plugin.py new file mode 100644 index 0000000..36f46ee --- /dev/null +++ b/trunk/dimbola/plugins/remove_photos_plugin.py @@ -0,0 +1,71 @@ +# 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 gtk + +import dimbola + + +class RemovePhotos(dimbola.Plugin): + + '''Remove selected files from database, optional also disk.''' + + def __init__(self, mwc): + self.mwc = mwc + + def enable(self): + self.mwc.add_to_menu('photo_menu', 'remove_photo_menuitem', + 'Remove selected photos') + + def disable(self): + self.mwc.remove_from_menu('photo_menu', 'remove_photo_menuitem') + + def remove_photo_menuitem_is_sensitive(self): + return self.mwc.grid.model.selected + + def on_remove_photo_menuitem_activate(self, menuitem): + photoids = self.mwc.grid.model.selected + if not photoids: + return + dialog = self.mwc.widgets['remove_photos_dialog'] + dialog.set_transient_for(self.mwc.widgets['window']) + button = self.mwc.widgets['remove_photos_from_disk_checkbutton'] + button.set_active(False) + dialog.show() + response = dialog.run() + dialog.hide() + if response == gtk.RESPONSE_OK: + from_disk = button.get_active() + with self.mwc.db: + for photoid in photoids: + if from_disk: + (folderid, basename, + c, d) = self.mwc.db.get_basic_photo_metadata(photoid) + foldername = self.mwc.db.get_folder_name(folderid) + pathname = os.path.join(foldername, basename) + os.remove(pathname) + self.mwc.db.remove_photo(photoid) + old = self.mwc.grid.model.photoids + self.mwc.grid.model.photoids = [x for x in old if x not in photoids] + self.mwc.load_thumbnails_from_database() + |