Class: Fliewr::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/fliewr/core.rb

Instance Method Summary collapse

Constructor Details

#initializeCore

Returns a new instance of Core.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fliewr/core.rb', line 9

def initialize
  $app = self
  $cfg = Ppds::Config.new 'fliewr'

  $gui = Fliewr::UI.new
  $gui.show_all

  $api = Ppds::Flickr.new

  start_timer
end

Instance Method Details

#ask_update(time_ahead = 0) ⇒ Object



40
41
42
# File 'lib/fliewr/core.rb', line 40

def ask_update(time_ahead = 0)
  @requires_update_at = timestamp + time_ahead
end

#human_time(time) ⇒ Object



55
56
57
58
59
# File 'lib/fliewr/core.rb', line 55

def human_time(time)
  seconds = time.modulo(SECONDS_PER_MINUTE)
  minutes = (time - seconds) / SECONDS_PER_MINUTE
  "%d:%02d" % [minutes, seconds]
end

#mainObject



61
62
63
# File 'lib/fliewr/core.rb', line 61

def main
  Gtk::main
end

#quitObject



65
66
67
68
69
# File 'lib/fliewr/core.rb', line 65

def quit
  Gtk::main_quit
ensure
  $cfg.save
end

#start_timerObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/fliewr/core.rb', line 44

def start_timer
  @@timeout = Gtk::timeout_add(1000) do
    sec_to_next_update = @requires_update_at.to_i - timestamp
    if sec_to_next_update < 0
      update
    else
      $gui.statusbar.push 0, "%s to update" % human_time(sec_to_next_update)
    end
  end
end

#timestampObject



36
37
38
# File 'lib/fliewr/core.rb', line 36

def timestamp
  Time.now.to_i
end

#updateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fliewr/core.rb', line 21

def update
  Gtk.timeout_remove(@@timeout) if @@timeout
  $gui.statusbar.push 0, "updating..."
  
  Thread.new do
    ask_update $cfg.get(:update_interval) * 60
    photos = $api.update $cfg.get(:max_photos)
    $gui.refresh_with photos
    @last_updated_at = timestamp
  end
  start_timer
rescue Exception => e
  Alert.new @nsid, e.message, e.backtrace
end