Class: GloudApp::Tray

Inherits:
Object
  • Object
show all
Defined in:
lib/gloudapp.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &default) ⇒ Tray

Returns a new instance of Tray.



251
252
253
254
# File 'lib/gloudapp.rb', line 251

def initialize(options = {}, &default)
	@options = {:tooltip => 'GloudApp', :icon => GloudApp::Icon.normal_path}.merge(options)
	@options[:default] = default unless @options[:default].is_a?(Proc)
end

Instance Method Details

#add_action(title, options = {}, &proc) ⇒ Object



256
257
258
259
260
261
262
# File 'lib/gloudapp.rb', line 256

def add_action(title, options = {}, &proc)
	@actions ||= []
	options = {} unless options.is_a?(Hash)
	options[:action] = proc unless options[:action].is_a?(Proc)
	options[:title] = title unless options[:title].is_a?(String)
	@actions << options
end

#add_separatorObject



264
265
266
267
# File 'lib/gloudapp.rb', line 264

def add_separator()
	@actions ||= []
	@actions << {:separator => true}
end

#icon=(icon) ⇒ Object



303
304
305
306
307
308
309
# File 'lib/gloudapp.rb', line 303

def icon=(icon)
	@si.pixbuf = Gdk::Pixbuf.new(icon)
	if not @ai.nil?
		# this relies on direct local file paths which works though it shouldn't
		@ai.set_icon(icon)
	end
end

#message=(message) ⇒ Object



311
312
313
# File 'lib/gloudapp.rb', line 311

def message=(message)
	@si.tooltip = message.nil? ? @options[:tooltip] : message.to_s
end

#run!Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/gloudapp.rb', line 269

def run!
	@si = Gtk::StatusIcon.new
	@si.pixbuf = Gdk::Pixbuf.new(@options[:icon])
	@si.tooltip = @options[:tooltip]
	@si.signal_connect('activate') do
		run_action @options[:default]
	end

	create_menu
	@si.signal_connect('popup-menu') do |tray, button, time|
		if not @working
			@actions.each do |action|
				if action[:show].is_a?(Proc)
					action[:show].call(action[:item])
				end
			end
			self.icon = Icon.normal_path
			self.message = nil
			@menu.popup(nil, nil, button, time)
		end
	end
	
	begin
		require 'ruby-libappindicator'
		puts "Initialize AppIndicator..."
		# params: id, icon name, category
		@ai = AppIndicator::AppIndicator.new("gloudapp", GloudApp::Icon.normal_path, AppIndicator::Category::APPLICATION_STATUS);
		@ai.set_menu(@menu)
		@ai.set_status(AppIndicator::Status::ACTIVE)
	rescue LoadError
		puts "No AppIndicator support available."
	end
end