Class: Fliewr::UI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUI

Returns a new instance of UI.



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
# File 'lib/fliewr/ui.rb', line 15

def initialize
  super Gtk::Window::TOPLEVEL

  filename = File.join(Fliewr::IMAGE_ROOT, 'fliewr.svg')
  self. = Gdk::Pixbuf.new filename, 128, 128

  self.set_title 'Fliewr'
  self.set_icon self.
  self.set_width_request 278
  self.set_height_request 400
  self.set_allow_shrink false
  self.set_default_width $cfg.get(:window_width).to_i
  self.set_default_height $cfg.get(:window_height).to_i
  self.move $cfg.get(:window_x_pos).to_i, $cfg.get(:window_y_pos).to_i

  theme = $cfg.get(:theme) || 'default'
  theme_root = File.join(APP_ROOT,'..','data','themes',theme)
  self.theme_base  = File.open(File.join(theme_root,'theme.html'), "r") { |f| f.read }
  self.theme_item  = File.open(File.join(theme_root,'item.html'), "r") { |f| f.read }
  self.theme_error = File.open(File.join(theme_root,'error.html'), "r") { |f| f.read }
  self.theme_style = File.open(File.join(theme_root,'style.css'), "r") { |f| f.read }

  self.signal_connect(:destroy) { quit }
  self.signal_connect(:delete_event) { minimize }
  self.signal_connect(:check_resize) { remember_size_position }
  self.signal_connect(:window_state_event) do |widget, event|
    case event.event_type
    when Gdk::Event::WINDOW_STATE
      minimize if event.changed_mask.iconified? and event.new_window_state.iconified?
    end
  end

  self.statusbar = Gtk::Statusbar.new
  self.statusbar.set_has_resize_grip false

  toolbar = Gtk::Toolbar.new
  toolbar.icon_size = Gtk::IconSize::MENU

  icon = Gtk::Image.new Gtk::Stock::HOME, Gtk::IconSize::MENU
  button = Gtk::ToolButton.new icon, 'Flickr'
  button.set_important true
  button.signal_connect(:clicked) do |widget|
    
  end
  toolbar.insert 0, button

  icon = Gtk::Image.new Gtk::Stock::REFRESH, Gtk::IconSize::MENU
  button = Gtk::ToolButton.new icon, 'Refresh'
  button.set_important true
  button.set_can_default true
  button.set_can_focus true
  button.signal_connect(:clicked) do |widget|
    $app.ask_update
  end
  toolbar.insert 1, button
  self.set_default button
  self.set_focus button

  icon = Gtk::Image.new Gtk::Stock::PREFERENCES, Gtk::IconSize::MENU
  button = Gtk::ToolButton.new icon, 'Settings'
  button.signal_connect(:clicked) do |widget|
    Fliewr::SettingsDialog.new
  end
  toolbar.insert 2, button

  separator = Gtk::SeparatorToolItem.new
  separator.set_draw false
  separator.set_expand true
  toolbar.insert 3, separator

  icon = Gtk::Image.new Gtk::Stock::QUIT, Gtk::IconSize::MENU
  button = Gtk::ToolButton.new icon, 'Quit'
  button.signal_connect(:clicked) do |widget|
    $app.quit
  end
  toolbar.insert 4, button

  @browser = Gtk::MozEmbed.new
  @browser.signal_connect(:open_uri) do |widget, uri|
    open_in_external_browser(uri)
  end

  vbox = Gtk::VBox.new false, 4
  vbox.pack_start toolbar, false
  vbox.pack_start @browser
  vbox.pack_start self.statusbar, false
  self.add vbox
end

Instance Attribute Details

#logoObject

Returns the value of attribute logo.



13
14
15
# File 'lib/fliewr/ui.rb', line 13

def 
  @logo
end

#statusbarObject

Returns the value of attribute statusbar.



13
14
15
# File 'lib/fliewr/ui.rb', line 13

def statusbar
  @statusbar
end

#theme_baseObject

Returns the value of attribute theme_base.



13
14
15
# File 'lib/fliewr/ui.rb', line 13

def theme_base
  @theme_base
end

#theme_errorObject

Returns the value of attribute theme_error.



13
14
15
# File 'lib/fliewr/ui.rb', line 13

def theme_error
  @theme_error
end

#theme_itemObject

Returns the value of attribute theme_item.



13
14
15
# File 'lib/fliewr/ui.rb', line 13

def theme_item
  @theme_item
end

#theme_styleObject

Returns the value of attribute theme_style.



13
14
15
# File 'lib/fliewr/ui.rb', line 13

def theme_style
  @theme_style
end

Instance Method Details

#dateupload(date_and_time) ⇒ Object



163
164
165
# File 'lib/fliewr/ui.rb', line 163

def dateupload(date_and_time)
  Time.at(date_and_time.to_i)
end

#maximizeObject



118
119
120
121
# File 'lib/fliewr/ui.rb', line 118

def maximize
  self.show
  self.present
end

#minimizeObject



113
114
115
116
# File 'lib/fliewr/ui.rb', line 113

def minimize
  remember_size_position
  hide
end

#open_in_external_browser(uri) ⇒ Object



171
172
173
# File 'lib/fliewr/ui.rb', line 171

def open_in_external_browser(uri)
  Thread.new { system('xdg-open "%s"' % uri) }
end

#open_in_gecko(html) ⇒ Object



123
124
125
126
127
# File 'lib/fliewr/ui.rb', line 123

def open_in_gecko(html)
  @browser.open_stream "file:///", "text/html"
  @browser.append_data self.theme_base % [ self.theme_style, html ]
  @browser.close_stream
end


150
151
152
# File 'lib/fliewr/ui.rb', line 150

def photolink(*args)
  'http://www.flickr.com/photos/%s/%s' % args
end

#photopreview(*args) ⇒ Object



146
147
148
# File 'lib/fliewr/ui.rb', line 146

def photopreview(*args)
  'http://farm%s.static.flickr.com/%s/%s_%s_m.jpg' % args
end

#quitObject



175
176
177
# File 'lib/fliewr/ui.rb', line 175

def quit
  $app.quit
end

#refresh_with(data) ⇒ Object



129
130
131
132
# File 'lib/fliewr/ui.rb', line 129

def refresh_with(data)
  html = data.map { |d| templatize(d) }.join
  open_in_gecko html
end

#remember_size_positionObject



104
105
106
107
108
109
110
111
# File 'lib/fliewr/ui.rb', line 104

def remember_size_position
  x, y = self.position
  w, h = self.size
  $cfg.set :window_x_pos, x
  $cfg.set :window_y_pos, y
  $cfg.set :window_width, w
  $cfg.set :window_height, h
end

#templatize(data) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/fliewr/ui.rb', line 134

def templatize(data)
  self.theme_item % [
    photolink(data.owner,  data.id),
    photopreview(data.farm, data.server, data.id, data.secret),
    (data.owner),
    data.username,
    userpic(data.iconfarm, data.iconserver, data.owner),
    data.title,
    dateupload(data.dateupload)
  ]
end


154
155
156
# File 'lib/fliewr/ui.rb', line 154

def (id = @nsid)
  'http://www.flickr.com/people/%s' % id
end

#userpic(farm, server, owner) ⇒ Object



158
159
160
161
# File 'lib/fliewr/ui.rb', line 158

def userpic(farm, server, owner)
  return 'http://www.flickr.com/images/buddyicon.jpg' if farm.to_i == 0
  'http://farm%s.static.flickr.com/%s/buddyicons/%s.jpg' % [ farm, server, owner ]
end

#visit_user_profileObject



167
168
169
# File 'lib/fliewr/ui.rb', line 167

def 
  open_in_external_browser 
end