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.



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

def initialize
  super Gtk::Window::TOPLEVEL

  filename = File.join(Fliewr::DATA_ROOT, 'pixmaps', '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(DATA_ROOT,'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.



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

def 
  @logo
end

#statusbarObject

Returns the value of attribute statusbar.



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

def statusbar
  @statusbar
end

#theme_baseObject

Returns the value of attribute theme_base.



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

def theme_base
  @theme_base
end

#theme_errorObject

Returns the value of attribute theme_error.



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

def theme_error
  @theme_error
end

#theme_itemObject

Returns the value of attribute theme_item.



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

def theme_item
  @theme_item
end

#theme_styleObject

Returns the value of attribute theme_style.



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

def theme_style
  @theme_style
end

Instance Method Details

#dateupload(date_and_time) ⇒ Object



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

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

#maximizeObject



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

def maximize
  self.show
  self.present
end

#minimizeObject



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

def minimize
  remember_size_position
  hide
end

#open_in_external_browser(uri) ⇒ Object



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

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

#open_in_gecko(html) ⇒ Object



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

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


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

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

#photopreview(*args) ⇒ Object



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

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

#quitObject



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

def quit
  $app.quit
end

#refresh_with(data) ⇒ Object



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

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

#remember_size_positionObject



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

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



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

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


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

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

#userpic(farm, server, owner) ⇒ Object



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

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



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

def 
  open_in_external_browser 
end