3
# This is a part of the external Ruby Interface for Cairo-Dock
5
# Author: Fabounet and Eduardo Mucelli Rezende Oliveira
6
# E-mail: fabounet@glx-dock.org, edumucelli@gmail.com or eduardom@dcc.ufmg.br
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# This applet monitors the battery through acpi module. It is possbile to show a dialog message
19
# containing the baterry status, charge, and temperature by left-clicking on the icon.
20
# Also, through the configuration panel it is possible to set the icon's label,
21
# show the % of carge as quick info, and activate an alert message to be shown when the charge is critically low.
28
attr_accessor :cConfFile, :cAppletName, :icon, :sub_icons, :config, :bus, :_cMenuIconId, :cParentAppName, :cBusPath
53
DIALOG_KEY_ESCAPE = -2
56
#~ self.cAppletName = File.basename(Dir.getwd)
57
#~ self.cConfFile = File.expand_path("~/.config/cairo-dock/current_theme/plug-ins/#{self.cAppletName}/#{self.cAppletName}.conf")
62
self._cMenuIconId = nil
63
self.cAppletName = $0[2,999]
64
self.cBusPath = ARGV[1]
65
self.cConfFile = ARGV[2]
66
self.cParentAppName = ARGV[3]
69
self._connect_to_dock()
77
puts ">>> applet '#{self.cAppletName}' terminated."
81
##################################
82
### callbacks on the main icon ###
83
##################################
90
puts ">>> on_middle_click"
91
### action on middle-click
95
self._cMenuIconId = nil
103
def _on_menu_select(iNumEntry)
104
if self._cMenuIconId == nil
105
self.on_menu_select(iNumEntry)
107
self.on_menu_select_sub_icon(iNumEntry, self._cMenuIconId)
111
def on_menu_select(iNumEntry)
112
### action on selecting an entry of our menu """
115
def on_scroll(bScrollUp)
119
def on_drop_data(cReceivedData)
120
### action on dropping something on our applet
123
def on_answer(answer)
124
### action on answering a dialog
127
def on_answer_dialog(button, answer)
128
### action on answering a dialog
131
def on_shortkey(cKey)
132
### action on pressing one of the shortkeys we bound beforehand
135
def on_change_focus(bIsActive)
136
### action when the window controlled by the applet takes or looses the focus
139
##################################
140
### callbacks on the sub-icons ###
141
##################################
142
def on_click_sub_icon(iState, cIconID)
143
### action on click on one of our sub-icons
146
def on_middle_click_sub_icon(cIconID)
147
### action on middle-click on one of our sub-icons
150
def on_scroll_sub_icon(bScrollUp, cIconID)
151
### action on scroll on one of our sub-icons
154
def _on_build_menu_sub_icon(cIconID)
155
self._cMenuIconId = cIconID
156
self.on_build_menu_sub_icon(cIconID)
159
def on_build_menu_sub_icon(cIconID)
160
### action on build menu on one of our sub-icons
163
def on_drop_data_sub_icon(cReceivedData, cIconID)
164
### action on drop data on one of our sub-icons
167
def on_menu_select_sub_icon(iNumEntry, cIconID)
168
### action on select entry in the menu on one of our sub-icons
172
###############################
173
### callbacks on the applet ###
174
###############################
177
### action when the applet is started
181
### action when the applet is terminated
190
### called when our applet is reloaded (config parameters have changed)
193
def _on_reload bConfigHasChanged
201
keyfile = ParseConfig.new(self.cConfFile)
202
self.get_config(keyfile)
205
def get_config keyfile
206
### get our parameters from the key-file
210
# get the icon object on the bus
211
self.bus = DBus::SessionBus.instance
212
#~ applet_path = "/org/cairodock/CairoDock/#{self.cAppletName}" # path where our object is stored on the bus
213
applet_service = bus.service("org.cairodock.CairoDock")
215
applet_object = applet_service.object(self.cBusPath)
216
applet_object.introspect
217
applet_object.default_iface = 'org.cairodock.CairoDock.applet'
219
puts ">>> object '#{self.cAppletName}' can't be found on the bus, exit.\nMake sure that the 'Dbus' plug-in is activated in Cairo-Dock"
222
self.icon = applet_object
224
# get the sub-icons object on the bus
225
applet_sub_icons_object = applet_service.object("#{self.cBusPath}/sub_icons")
226
applet_sub_icons_object.introspect
227
applet_sub_icons_object.default_iface = 'org.cairodock.CairoDock.subapplet'
228
self.sub_icons = applet_sub_icons_object
230
# now connect to the signals
231
self.icon.on_signal("on_click") do |iState|
234
self.icon.on_signal("on_middle_click") do
237
self.icon.on_signal("on_build_menu") do
240
self.icon.on_signal("on_menu_select") do |iNumEntry|
241
self._on_menu_select iNumEntry
243
self.icon.on_signal("on_scroll") do |bScrollUp|
244
self.on_scroll bScrollUp
246
self.icon.on_signal("on_drop_data") do |cReceivedData|
247
self.on_drop_data cReceivedData
249
self.icon.on_signal("on_answer") do |answer|
250
self.on_answer answer
252
self.icon.on_signal("on_answer_dialog") do |button, answer|
253
self.on_answer_dialog button, answer
255
self.icon.on_signal("on_shortkey") do |cKey|
256
self.on_shortkey cKey
258
self.icon.on_signal("on_change_focus") do |bIsActive|
259
self.on_change_focus bIsActive
262
self.icon.on_signal("on_stop_module") do
266
self.icon.on_signal("on_reload_module") do |bConfigHasChanged|
267
self._on_reload bConfigHasChanged
270
self.sub_icons.on_signal("on_click_sub_icon") do |iState, sub_icon_id|
271
self.on_click_sub_icon iState, sub_icon_id
274
self.sub_icons.on_signal("on_middle_click_sub_icon") do |sub_icon_id|
275
self.on_middle_click_sub_icon sub_icon_id
278
self.sub_icons.on_signal("on_scroll_sub_icon") do |bScrollUp, sub_icon_id|
279
self.on_scroll_sub_icon bScrollUp, sub_icon_id
282
self.sub_icons.on_signal("on_build_menu_sub_icon") do |sub_icon_id|
283
self._on_build_menu_sub_icon sub_icon_id
286
self.sub_icons.on_signal("on_drop_data_sub_icon") do |cReceivedData, sub_icon_id|
287
self.on_drop_data_sub_icon cReceivedData, sub_icon_id