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.
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.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(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 |, 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.
14 15 16 |
# File 'lib/fliewr/ui.rb', line 14 def logo @logo end |
#statusbar ⇒ Object
Returns the value of attribute statusbar.
14 15 16 |
# File 'lib/fliewr/ui.rb', line 14 def @statusbar end |
#theme_base ⇒ Object
Returns the value of attribute theme_base.
14 15 16 |
# File 'lib/fliewr/ui.rb', line 14 def theme_base @theme_base end |
#theme_error ⇒ Object
Returns the value of attribute theme_error.
14 15 16 |
# File 'lib/fliewr/ui.rb', line 14 def theme_error @theme_error end |
#theme_item ⇒ Object
Returns the value of attribute theme_item.
14 15 16 |
# File 'lib/fliewr/ui.rb', line 14 def theme_item @theme_item end |
#theme_style ⇒ Object
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 |
#maximize ⇒ Object
119 120 121 122 |
# File 'lib/fliewr/ui.rb', line 119 def maximize self.show self.present end |
#minimize ⇒ Object
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 |
#photolink(*args) ⇒ Object
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 |
#quit ⇒ Object
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_position ⇒ Object
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), 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
155 156 157 |
# File 'lib/fliewr/ui.rb', line 155 def user_profile_link(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_profile ⇒ Object
168 169 170 |
# File 'lib/fliewr/ui.rb', line 168 def visit_user_profile open_in_external_browser user_profile_link end |