Module: Alexandria::UI::Callbacks

Includes:
Logging
Defined in:
lib/alexandria/ui/callbacks.rb

Instance Method Summary collapse

Methods included from Logging

included, #log

Instance Method Details

#connect_signalsObject



283
284
285
286
287
288
289
290
291
292
293
# File 'lib/alexandria/ui/callbacks.rb', line 283

def connect_signals
  log.debug { "Adding actions to @actiongroup" }

  @actiongroup = Gtk::ActionGroup.new("actions")

  connect_standard_actions
  connect_providers_actions
  connect_toggle_actions
  connect_view_actions
  connect_arrange_icons_actions
end

#on_aboutObject



257
258
259
# File 'lib/alexandria/ui/callbacks.rb', line 257

def on_about(*)
  AboutDialog.new(@main_app).show
end

#on_acquireObject



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/alexandria/ui/callbacks.rb', line 116

def on_acquire(*)
  dialog =
    AcquireDialog.new(@main_app, selected_library) do |_books, library, is_new|
      if is_new
        append_library(library, true)
        setup_move_actions
      elsif selected_library != library
        select_library(library)
      end
    end
  dialog.show
end

#on_add_bookObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/alexandria/ui/callbacks.rb', line 32

def on_add_book(*)
  log.info { "on_add_book" }
  dialog = NewBookDialog.new(@main_app, selected_library) do |_books, library, is_new|
    if is_new
      append_library(library, true)
      setup_move_actions
    elsif selected_library != library
      select_library(library)
    end
  end
  dialog.show
end

#on_add_book_manualObject



45
46
47
48
49
50
51
# File 'lib/alexandria/ui/callbacks.rb', line 45

def on_add_book_manual(*)
  library = selected_library
  dialog = NewBookDialogManual.new(@main_app, library) do |_book|
    refresh_books
  end
  dialog.show
end

#on_clear_search_resultsObject



231
232
233
234
235
236
# File 'lib/alexandria/ui/callbacks.rb', line 231

def on_clear_search_results(*)
  @filter_entry.text = ""
  @iconview.freeze
  @filtered_model.refilter
  @iconview.unfreeze
end

#on_criterion_combobox_changed(widget) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/alexandria/ui/callbacks.rb', line 103

def on_criterion_combobox_changed(widget)
  log.debug { "changed" }
  @filter_books_mode = widget.active
  @filter_entry.text.strip!
  @iconview.freeze
  @filtered_model.refilter
  @iconview.unfreeze
end

#on_deleteObject



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/alexandria/ui/callbacks.rb', line 209

def on_delete(*)
  library = selected_library

  books = if selected_books.empty?
            nil
          else
            selected_books
          end
  # books = @library_listview.focus? ? nil : selected_books
  is_smart = library.is_a?(SmartLibrary)
  last_library = (@libraries.all_regular_libraries.length == 1)
  if books.nil? && !is_smart && last_library
    log.warn { "Attempted to delete last library, fix GUI" }
    return
  end
  if library.empty? || ReallyDeleteDialog.new(@main_app,
                                              library,
                                              books).ok?
    undoable_delete(library, books)
  end
end

#on_deselect_allObject



178
179
180
181
182
183
184
185
186
# File 'lib/alexandria/ui/callbacks.rb', line 178

def on_deselect_all(*)
  log.debug { "on_deselect_all" }
  case @notebook.page
  when 0
    @iconview.unselect_all
  when 1
    @listview.selection.unselect_all
  end
end

#on_exportObject



112
113
114
# File 'lib/alexandria/ui/callbacks.rb', line 112

def on_export(*)
  ExportDialog.new(@main_app, selected_library, library_sort_order).perform
end

#on_helpObject



253
254
255
# File 'lib/alexandria/ui/callbacks.rb', line 253

def on_help(*)
  Alexandria::UI.display_help(@main_app)
end

#on_importObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/alexandria/ui/callbacks.rb', line 53

def on_import(*)
  ImportDialog.new(@main_app).acquire do |library, bad_isbns, failed_isbns|
    unless bad_isbns.empty?
      log.debug { "bad_isbn" }
      message = _("The following lines are not valid ISBNs and were not imported:")
      BadIsbnsDialog.new(@main_app, message, bad_isbns).show
    end
    unless failed_isbns.nil? || failed_isbns.empty?
      log.debug { "failed lookup of #{failed_isbns.size} ISBNs" }
      message = _("Books could not be found for the following ISBNs:")
      BadIsbnsDialog.new(@main_app, message, failed_isbns).show
    end
    @libraries.add_library(library)
    append_library(library, true)
    setup_move_actions
  end
end

#on_newObject



14
15
16
17
18
19
20
21
# File 'lib/alexandria/ui/callbacks.rb', line 14

def on_new(*)
  name = Library.generate_new_name(@libraries.all_libraries)
  library = @libraries.library_store.load_library(name)
  @libraries.add_library(library)
  append_library(library, true)
  setup_move_actions
  library.add_observer(self)
end

#on_new_smartObject



23
24
25
26
27
28
29
30
# File 'lib/alexandria/ui/callbacks.rb', line 23

def on_new_smart(*)
  smart_library = NewSmartLibraryDialog.new(@main_app).acquire or return

  smart_library.refilter
  @libraries.add_library(smart_library)
  append_library(smart_library, true)
  smart_library.save
end

#on_preferencesObject



242
243
244
245
246
247
# File 'lib/alexandria/ui/callbacks.rb', line 242

def on_preferences(*)
  dialog = PreferencesDialog.new(@main_app) do
    @listview_manager.setup_listview_columns_visibility
  end
  dialog.show
end

#on_propertiesObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/alexandria/ui/callbacks.rb', line 129

def on_properties(*)
  if @library_listview.focus? || selected_books.empty?
    library = selected_library
    if library.is_a?(SmartLibrary)
      success = SmartLibraryPropertiesDialog.new(@main_app, library).acquire

      if success
        library.refilter
        refresh_books
      end
    end
  else
    books = selected_books
    if books.length == 1
      book = books.first
      dialog = BookPropertiesDialog.new(@main_app,
                                        selected_library,
                                        book)
      dialog.show
    end
  end
end

#on_quitObject



152
153
154
155
156
157
158
# File 'lib/alexandria/ui/callbacks.rb', line 152

def on_quit(*)
  save_preferences
  Gtk.main_quit
  # @libraries.really_save_all_books
  @libraries.really_delete_deleted_libraries
  @libraries.all_regular_libraries.each(&:really_delete_deleted_books)
end

#on_redoObject



164
165
166
# File 'lib/alexandria/ui/callbacks.rb', line 164

def on_redo(*)
  UndoManager.instance.redo!
end

#on_renameObject



202
203
204
205
206
207
# File 'lib/alexandria/ui/callbacks.rb', line 202

def on_rename(*)
  iter = @library_listview.selection.selected
  column = @library_listview.get_column(0)
  cell = column.cells.last
  @library_listview.set_cursor_on_cell(iter.path, column, cell, true)
end

#on_reverse_order(action) ⇒ Object



276
277
278
279
280
281
# File 'lib/alexandria/ui/callbacks.rb', line 276

def on_reverse_order(action)
  log.debug { "on_reverse_order" }
  Preferences.instance.reverse_icons = action.active?
  Preferences.instance.save!
  setup_books_iconview_sorting
end

#on_searchObject



238
239
240
# File 'lib/alexandria/ui/callbacks.rb', line 238

def on_search(*)
  @filter_entry.grab_focus
end

#on_select_allObject



168
169
170
171
172
173
174
175
176
# File 'lib/alexandria/ui/callbacks.rb', line 168

def on_select_all(*)
  log.debug { "on_select_all" }
  case @notebook.page
  when 0
    @iconview.select_all
  when 1
    @listview.selection.select_all
  end
end

#on_set_ratingObject



188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/alexandria/ui/callbacks.rb', line 188

def on_set_rating
  Book::VALID_RATINGS.map do |rating|
    proc do
      books = selected_books
      library = selected_library
      books.each do |book|
        log.debug { "set #{book.title} rating to #{rating}" }
        book.rating = rating
        library.save(book)
      end
    end
  end
end

#on_submit_bug_reportObject



249
250
251
# File 'lib/alexandria/ui/callbacks.rb', line 249

def on_submit_bug_report(*)
  open_web_browser(BUGREPORT_URL)
end

#on_toolbar_filter_entry_changed(_entry) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/alexandria/ui/callbacks.rb', line 95

def on_toolbar_filter_entry_changed(_entry)
  log.debug { "changed" }
  @filter_entry.text.strip!
  @iconview.freeze
  @filtered_model.refilter
  @iconview.unfreeze
end

#on_toolbar_view_as_changed(widget) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/alexandria/ui/callbacks.rb', line 79

def on_toolbar_view_as_changed(widget)
  log.debug { "changed" }
  action = case widget.active
           when 0
             @actiongroup["AsIcons"]
           when 1
             @actiongroup["AsList"]
           end
  action.active = true
end

#on_undoObject



160
161
162
# File 'lib/alexandria/ui/callbacks.rb', line 160

def on_undo(*)
  UndoManager.instance.undo!
end

#on_view_sidepane(action) ⇒ Object



261
262
263
264
# File 'lib/alexandria/ui/callbacks.rb', line 261

def on_view_sidepane(action)
  log.debug { "on_view_sidepane" }
  @paned.child1.visible = action.active?
end

#on_view_statusbar(action) ⇒ Object



271
272
273
274
# File 'lib/alexandria/ui/callbacks.rb', line 271

def on_view_statusbar(action)
  log.debug { "on_view_statusbar" }
  @appbar.visible = action.active?
end

#on_view_toolbar(action) ⇒ Object



266
267
268
269
# File 'lib/alexandria/ui/callbacks.rb', line 266

def on_view_toolbar(action)
  log.debug { "on_view_toolbar" }
  @toolbar.visible = action.active?
end

#on_window_destroy(_window) ⇒ Object



90
91
92
93
# File 'lib/alexandria/ui/callbacks.rb', line 90

def on_window_destroy(_window)
  log.debug { "destroy" }
  @actiongroup["Quit"].activate
end

#on_window_state_event(_window, event) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/alexandria/ui/callbacks.rb', line 71

def on_window_state_event(_window, event)
  log.debug { "window-state-event" }
  if event.is_a?(Gdk::EventWindowState)
    @maximized = event.new_window_state == :maximized
  end
  log.debug { "end window-state-event" }
end