lib/grumblr/ui.rb in grumblr-2.3.1 vs lib/grumblr/ui.rb in grumblr-2.3.3

- old
+ new

@@ -1,10 +1,13 @@ require 'gtk2' +require 'open-uri' +require 'ftools' module Grumblr APP_NAME = 'Grumblr' + APP_MOTTO = 'a Tumblr companion' APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) DATA_ROOT = File.join(APP_ROOT, 'data') VERSION = File.open(File.join(APP_ROOT,'VERSION')) { |f| f.read } class UI < Gtk::Window @@ -14,15 +17,15 @@ def initialize super Gtk::Window::TOPLEVEL filename = File.join(Grumblr::DATA_ROOT, 'pixmaps', 'grumblr.svg') self.logo = Gdk::Pixbuf.new(filename, 128, 128) - + set_size_request 440, 340 set_border_width 0 set_allow_shrink false - set_title Grumblr::APP_NAME + set_title "#{Grumblr::APP_NAME} #{Grumblr::VERSION}" set_icon self.logo set_default_width $cfg.get(:window_width).to_i set_default_height $cfg.get(:window_height).to_i move $cfg.get(:window_x_pos).to_i, $cfg.get(:window_y_pos).to_i signal_connect(:destroy) { quit } @@ -138,15 +141,17 @@ filter = Gtk::FileFilter.new filter.set_name "Audio" filter.add_mime_type "audio/*" audio_data = file_chooser_button :audio_data, filter + @audio_externally_hosted_url = Gtk::LabeledEntry.new 'Externally Hosted MP3 URL' @audio_caption = Gtk::LabeledTextView.new 'Caption (optional)' page = Gtk::VBox.new false, 4 page.set_border_width 8 page.pack_start audio_data, false + page.pack_start @audio_externally_hosted_url, false page.pack_start scrollable(@audio_caption), true @notebook.add_page_with_tab page, 'Audio' end @@ -190,15 +195,29 @@ item.signal_connect(:clicked) do Thread.new { system('xdg-open "http://www.tumblr.com/tumblelog/%s"' % $app.blog.name) } end toolbar.insert 1, item - combo = Gtk::ComboBox.new + ### Blog selection combo + model = Gtk::ListStore.new(Gdk::Pixbuf, String) + combo = Gtk::ComboBox.new(model) + + renderer = Gtk::CellRendererPixbuf.new + renderer.width = 24 + combo.pack_start(renderer, false) + combo.set_attributes(renderer, :pixbuf => 0) + + renderer = Gtk::CellRendererText.new + combo.pack_start(renderer, true) + combo.set_attributes(renderer, :text => 1) + active_blog = $cfg.get(:active_blog) || nil active_blog_idx = nil $api.blogs.each_with_index do |blog, idx| - combo.append_text blog.title + iter = model.append + iter[0] = pixbuffer_from_url(blog.avatar_url) + iter[1] = blog.title active_blog_idx = idx if blog.name.eql?(active_blog) active_blog_idx = idx if active_blog_idx.nil? and blog.is_primary == "yes" end combo.signal_connect(:changed) do |widget| $app.blog = $api.blogs[widget.active] @@ -285,27 +304,33 @@ optional_data.delete_if { |x,y| y == "" or y.nil? } tags = @tags.get_value.gsub(/\s+/,',').split(',').uniq.sort - [''] data = { - :generator => 'Grumblr', :email => $cfg.get(:email), :password => $cfg.get(:password), :channel_id => $app.blog.name, - :group => $app.blog.name + '.tumblr.com', :type => message_type, + :generator => "#{Grumblr::APP_NAME} #{Grumblr::VERSION}", + :private => @private_button.active? ? 1 : 0, :tags => tags.join(','), :format => @format.active? ? 'markdown' : 'html', - :private => @private_button.active? ? 1 : 0 + :group => $app.blog.name + '.tumblr.com', + #:slug => , + #:state => , # published, draft, submission, queue + #:publish_on => , # e.g. publish-on=2010-01-01T13:34:00 + #:send-to-twitter => , # no, auto, "message" } data.merge! mandatory_data data.merge! concurent_data data.merge! optional_data data.update({:data => File.read(data['data'])}) if data.has_key?('data') and data['data'] != "" + dump(data) if DEBUG + $api.query 'write', data MessageDialog.new "Message posted", Gtk::Stock::DIALOG_INFO reset_form message_type rescue Exception MessageDialog.new $! @@ -360,10 +385,20 @@ scroll.set_policy Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC scroll.add widget scroll.show_all end + def pixbuffer_from_url(url) + cache_dir = File.expand_path(File.join('~', '.cache', Grumblr::APP_NAME.downcase)) + FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir) + file = File.join(cache_dir, File.basename(url)) + File.open(file, 'w') { |f| f.write(open(url).read) } unless File.exists?(file) + pb = Gdk::PixbufLoader.new + pb.set_size 16, 16 + pb.last_write(open(file) { |f| f.read }) + pb.pixbuf + end end class MessageDialog < Gtk::Dialog def initialize(text, stock = Gtk::Stock::DIALOG_ERROR) super "Attention!", $gui, Gtk::Dialog::MODAL @@ -455,12 +490,12 @@ end super self.logo = $gui.logo self.program_name = Grumblr::APP_NAME self.version = Grumblr::VERSION + self.comments = Grumblr::APP_MOTTO self.copyright = "Copyright (c)2009, Paul Philippov" - self.comments = "Tumblr companion for GNOME" self.license = "New BSD License.\nhttp://creativecommons.org/licenses/BSD/" self.website = "http://themactep.com/grumblr/" self.authors = ['Paul Philippov <themactep@gmail.com>'] self.run self.destroy @@ -468,11 +503,11 @@ end class StatusIcon < Gtk::StatusIcon def initialize super - self.file = File.join(Grumblr::DATA_ROOT, 'pixmaps', 'grumblr.svg') - self.tooltip = "Application Name Goes Here" + self.icon_name = 'grumblr' + self.tooltip = "#{Grumblr::APP_NAME} #{Grumblr::VERSION}" self.signal_connect(:activate) do if $gui.visible? $gui.minimize else $gui.move $cfg.get(:window_x_pos), $cfg.get(:window_y_pos)