Class: Fliewr::SettingsDialog

Inherits:
Gtk::Dialog
  • Object
show all
Defined in:
lib/fliewr/ui.rb

Instance Method Summary collapse

Constructor Details

#initializeSettingsDialog

Returns a new instance of SettingsDialog.



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/fliewr/ui.rb', line 268

def initialize
  super "Settings", nil, Gtk::Dialog::MODAL,
    [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT],
    [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL]

  self.set_default_response Gtk::Dialog::RESPONSE_ACCEPT
  self.signal_connect :response do |dialog, response|
    case response
    when Gtk::Dialog::RESPONSE_ACCEPT
      if /\d\d\d\d\d\d\d\d@N\d\d/ =~ @nsid_entry.text
        $cfg.set :nsid, @nsid_entry.text
        $cfg.set :update_interval, @update_interval_spin.value
        $cfg.set :max_photos, @max_photos_spin.value
        $cfg.set :one_per_contact, @one_per_contact_toggle.active?
        $cfg.set :only_from_friends, @only_from_friends_toggle.active?
        $cfg.set :include_self, @include_self_toggle.active?
        $app.update
      else
        Alert.new "User ID has incorrect format"
      end
    when Gtk::Dialog::RESPONSE_CANCEL
      true
    end
  end
  hbox = Gtk::HBox.new false, 8
  hbox.set_border_width 8
  self.vbox.pack_start hbox, false, false, 0

  stock = Gtk::Image.new Gtk::Stock::PREFERENCES, Gtk::IconSize::DIALOG
  hbox.pack_start stock, false, false, 0

  table = Gtk::Table.new 3, 6
  table.set_row_spacings 4
  table.set_column_spacings 8
  hbox.pack_start table, true, true, 0

  @nsid_entry = Gtk::Entry.new
  @nsid_entry.width_chars = 13
  @nsid_entry.max_length = 12
  @nsid_entry.text = $cfg.get(:nsid)
  table.attach_defaults label('Your Flickr user ID'), 0, 1, 0, 1
  table.attach_defaults @nsid_entry, 1, 2, 0, 1
  table.attach_defaults button_with_click(:find, :find_nsid), 2, 3, 0, 1

  @update_interval_spin = Gtk::SpinButton.new(1, 100, 1)
  @update_interval_spin.value = $cfg.get(:update_interval).to_i
  table.attach_defaults label('Check new photos every'), 0, 1, 1, 2
  table.attach_defaults @update_interval_spin, 1, 2, 1, 2
  table.attach_defaults label('minutes'), 2, 3, 1, 2

  @max_photos_spin = Gtk::SpinButton.new(1, 50, 1)
  @max_photos_spin.value = $cfg.get(:max_photos).to_i
  table.attach_defaults label('Maximum photos to display'), 0, 1, 2, 3
  table.attach_defaults @max_photos_spin, 1, 2, 2, 3

  @one_per_contact_toggle = Gtk::CheckButton.new
  @one_per_contact_toggle.active = $cfg.get(:one_per_contact)
  table.attach_defaults label('Only one photo per contact'), 0, 1, 3, 4
  table.attach_defaults @one_per_contact_toggle, 1, 2, 3, 4

  @only_from_friends_toggle = Gtk::CheckButton.new
  @only_from_friends_toggle.active = $cfg.get(:only_from_friend)
  table.attach_defaults label('Only from friends and family'), 0, 1, 4, 5
  table.attach_defaults @only_from_friends_toggle, 1, 2, 4, 5

  @include_self_toggle = Gtk::CheckButton.new
  @include_self_toggle.active = $cfg.get(:include_self)
  table.attach_defaults label('Include your own photos'), 0, 1, 5, 6
  table.attach_defaults @include_self_toggle, 1, 2, 5, 6

  self.show_all
  self.run
  self.destroy
end

Instance Method Details

#button_with_click(stock_id, method_name) ⇒ Object



343
344
345
346
347
348
349
# File 'lib/fliewr/ui.rb', line 343

def button_with_click(stock_id, method_name)
  button = Gtk::Button.new icon(stock_id)
  button.signal_connect(:clicked) do |widget|
    self.method(method_name).call
  end
  button.show_all
end

#find_nsidObject



351
352
353
# File 'lib/fliewr/ui.rb', line 351

def find_nsid
  $gui.open_in_external_browser 'http://www.flickr.com/services/api/explore/?method=flickr.people.getInfo'
end

#icon(stock_id) ⇒ Object



355
356
357
# File 'lib/fliewr/ui.rb', line 355

def icon(stock_id)
  Gtk::Stock.const_get stock_id.to_s.upcase
end

#label(text) ⇒ Object



359
360
361
# File 'lib/fliewr/ui.rb', line 359

def label(text)
  Gtk::Label.new(text).set_alignment(0, 0.5)
end