Class: Fliewr::UI
- Inherits:
-
Gtk::Window
- Object
- Gtk::Window
- Fliewr::UI
- Defined in:
- lib/fliewr/ui.rb
Instance Attribute Summary collapse
-
#logo ⇒ Object
Returns the value of attribute logo.
-
#statusbar ⇒ Object
Returns the value of attribute statusbar.
-
#theme_base ⇒ Object
Returns the value of attribute theme_base.
-
#theme_error ⇒ Object
Returns the value of attribute theme_error.
-
#theme_item ⇒ Object
Returns the value of attribute theme_item.
-
#theme_style ⇒ Object
Returns the value of attribute theme_style.
Instance Method Summary collapse
- #dateupload(date_and_time) ⇒ Object
-
#initialize ⇒ UI
constructor
A new instance of UI.
- #maximize ⇒ Object
- #minimize ⇒ Object
- #open_in_external_browser(uri) ⇒ Object
- #open_in_gecko(html) ⇒ Object
- #photolink(*args) ⇒ Object
- #photopreview(*args) ⇒ Object
- #quit ⇒ Object
- #refresh_with(data) ⇒ Object
- #remember_size_position ⇒ Object
- #templatize(data) ⇒ Object
- #user_profile_link(id = @nsid) ⇒ Object
- #userpic(farm, server, owner) ⇒ Object
- #visit_user_profile ⇒ Object
Constructor Details
#initialize ⇒ UI
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.logo = Gdk::Pixbuf.new filename, 128, 128 self.set_title 'Fliewr' self.set_icon self.logo 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 |, 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. = Gtk::Statusbar.new self..set_has_resize_grip false = Gtk::Toolbar.new .icon_size = Gtk::IconSize::MENU icon = Gtk::Image.new Gtk::Stock::HOME, Gtk::IconSize::MENU = Gtk::ToolButton.new icon, 'Flickr' .set_important true .signal_connect(:clicked) do || visit_user_profile end .insert 0, icon = Gtk::Image.new Gtk::Stock::REFRESH, Gtk::IconSize::MENU = Gtk::ToolButton.new icon, 'Refresh' .set_important true .set_can_default true .set_can_focus true .signal_connect(:clicked) do || $app.ask_update end .insert 1, self.set_default self.set_focus icon = Gtk::Image.new Gtk::Stock::PREFERENCES, Gtk::IconSize::MENU = Gtk::ToolButton.new icon, 'Settings' .signal_connect(:clicked) do || Fliewr::SettingsDialog.new end .insert 2, separator = Gtk::SeparatorToolItem.new separator.set_draw false separator. true .insert 3, separator icon = Gtk::Image.new Gtk::Stock::QUIT, Gtk::IconSize::MENU = Gtk::ToolButton.new icon, 'Quit' .signal_connect(:clicked) do || $app.quit end .insert 4, @browser = Gtk::MozEmbed.new @browser.signal_connect(:open_uri) do |, uri| open_in_external_browser(uri) end vbox = Gtk::VBox.new false, 4 vbox.pack_start , false vbox.pack_start @browser vbox.pack_start self., false self.add vbox end |
Instance Attribute Details
#logo ⇒ Object
Returns the value of attribute logo.
13 14 15 |
# File 'lib/fliewr/ui.rb', line 13 def logo @logo end |
#statusbar ⇒ Object
Returns the value of attribute statusbar.
13 14 15 |
# File 'lib/fliewr/ui.rb', line 13 def @statusbar end |
#theme_base ⇒ Object
Returns the value of attribute theme_base.
13 14 15 |
# File 'lib/fliewr/ui.rb', line 13 def theme_base @theme_base end |
#theme_error ⇒ Object
Returns the value of attribute theme_error.
13 14 15 |
# File 'lib/fliewr/ui.rb', line 13 def theme_error @theme_error end |
#theme_item ⇒ Object
Returns the value of attribute theme_item.
13 14 15 |
# File 'lib/fliewr/ui.rb', line 13 def theme_item @theme_item end |
#theme_style ⇒ Object
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 |
#maximize ⇒ Object
118 119 120 121 |
# File 'lib/fliewr/ui.rb', line 118 def maximize self.show self.present end |
#minimize ⇒ Object
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 |
#photolink(*args) ⇒ Object
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 |
#quit ⇒ Object
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_position ⇒ Object
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), user_profile_link(data.owner), data.username, userpic(data.iconfarm, data.iconserver, data.owner), data.title, dateupload(data.dateupload) ] end |
#user_profile_link(id = @nsid) ⇒ Object
154 155 156 |
# File 'lib/fliewr/ui.rb', line 154 def user_profile_link(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_profile ⇒ Object
167 168 169 |
# File 'lib/fliewr/ui.rb', line 167 def visit_user_profile open_in_external_browser user_profile_link end |