/usr/lib/python2.7/dist-packages/mcomix/file_chooser_library_dialog.py is in mcomix 1.00-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | """file_chooser_library_dialog.py - Custom FileChooserDialog implementations."""
import os
import gtk
from mcomix.preferences import prefs
from mcomix import file_chooser_base_dialog
_library_filechooser_dialog = None
class _LibraryFileChooserDialog(file_chooser_base_dialog._BaseFileChooserDialog):
"""The filechooser dialog used when adding books to the library."""
def __init__(self, library):
file_chooser_base_dialog._BaseFileChooserDialog.__init__(self)
self.set_transient_for(library)
self.set_title(_('Add books'))
self._library = library
self.filechooser.set_select_multiple(True)
self.filechooser.connect('current_folder_changed',
self._set_collection_name)
self._collection_button = gtk.CheckButton(
_('Add to this collection:'),
False)
self._collection_button.set_active(
prefs['auto add books into collections'])
self._comboentry = gtk.combo_box_entry_new_text()
self._comboentry.child.set_activates_default(True)
for collection in self._library.backend.get_all_collections():
name = self._library.backend.get_collection_name(collection)
self._comboentry.append_text(name)
collection_box = gtk.HBox(False, 6)
collection_box.pack_start(self._collection_button, False, False)
collection_box.pack_start(self._comboentry, True, True)
collection_box.show_all()
self.filechooser.set_extra_widget(collection_box)
# Remove 'All files' filter from base class
filters = self.filechooser.list_filters()
self.filechooser.remove_filter(filters[0])
self.filechooser.set_filter(filters[1])
try:
# When setting this to the first filter ("All files"), this
# fails on some GTK+ versions and sets the filter to "blank".
# The effect is the same though (i.e. display all files), and
# there is no solution that I know of, so we'll have to live
# with it. It only happens the second time a dialog is created
# though, which is very strange.
self.filechooser.set_filter(filters[
prefs['last filter in library filechooser']])
except Exception:
self.filechooser.set_filter(filters[0])
# Remove default buttons and add buttons that make more sense
for widget in self.get_action_area().get_children():
self.get_action_area().remove(widget)
self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
self.add_button(gtk.STOCK_ADD, gtk.RESPONSE_OK)
self.set_default_response(gtk.RESPONSE_OK)
def should_open_recursive(self):
return True
def _set_collection_name(self, *args):
"""Set the text in the ComboBoxEntry to the name of the current
directory.
"""
name = os.path.basename(self.filechooser.get_current_folder())
self._comboentry.child.set_text(name)
def files_chosen(self, paths):
if paths:
paths = [ path.decode('utf-8') for path in paths ]
if self._collection_button.get_active():
prefs['auto add books into collections'] = True
collection_name = self._comboentry.get_active_text().decode('utf-8')
if not collection_name: # No empty-string names.
collection_name = None
else:
prefs['auto add books into collections'] = False
collection_name = None
try: # For some reason this fails sometimes (GTK+ bug?)
filter_index = self.filechooser.list_filters().index(
self.filechooser.get_filter())
prefs['last filter in library filechooser'] = filter_index
except Exception:
pass
close_library_filechooser_dialog()
self._library.add_books(paths, collection_name)
else:
close_library_filechooser_dialog()
def open_library_filechooser_dialog(library):
"""Open the library filechooser dialog."""
global _library_filechooser_dialog
if _library_filechooser_dialog is None:
_library_filechooser_dialog = _LibraryFileChooserDialog(library)
else:
_library_filechooser_dialog.present()
def close_library_filechooser_dialog(*args):
"""Close the library filechooser dialog."""
global _library_filechooser_dialog
if _library_filechooser_dialog is not None:
_library_filechooser_dialog.destroy()
_library_filechooser_dialog = None
# vim: expandtab:sw=4:ts=4
|