/usr/lib/ruby/2.3.0/CDApplet.rb is in cairo-dock-plug-ins-dbus-interface-ruby 3.4.1-0ubuntu7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 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 | #!/usr/bin/ruby
# This is a part of the external Ruby Interface for Cairo-Dock
# Author: Fabounet and Eduardo Mucelli Rezende Oliveira
# E-mail: fabounet@glx-dock.org, edumucelli@gmail.com or eduardom@dcc.ufmg.br
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# This applet monitors the battery through acpi module. It is possbile to show a dialog message
# containing the baterry status, charge, and temperature by left-clicking on the icon.
# Also, through the configuration panel it is possible to set the icon's label,
# show the % of carge as quick info, and activate an alert message to be shown when the charge is critically low.
require 'rubygems'
gem 'ruby-dbus'
require 'dbus'
require 'parseconfig'
class CDApplet
attr_accessor :cConfFile, :cAppletName, :icon, :sub_icons, :config, :bus, :_cMenuIconId, :cParentAppName, :cBusPath, :cRootDataDir, :cShareDataDir
BOTTOM = 0
TOP = 1
RIGHT = 2
LEFT = 3
DOCK = 0
DESKLET = 1
EMBLEM_TOP_LEFT = 0
EMBLEM_BOTTOM_RIGHT = 1
EMBLEM_BOTTOM_LEFT = 2
EMBLEM_TOP_RIGHT = 3
EMBLEM_MIDDLE = 4
EMBLEM_BOTTOM = 5
EMBLEM_TOP = 6
EMBLEM_RIGHT = 7
EMBLEM_LEFT = 8
EMBLEM_PERSISTENT = 0
EMBLEM_PRINT = 9
MENU_ENTRY = 0
MENU_SUB_MENU = 1
MENU_SEPARATOR = 2
MENU_CHECKBOX = 3
MENU_RADIO_BUTTON = 4
MAIN_MENU_ID = 0
DIALOG_KEY_ENTER = -1
DIALOG_KEY_ESCAPE = -2
def initialize
self.config = {}
self.bus = nil
self.icon = nil
self.sub_icons = nil
self._cMenuIconId = nil
self.cAppletName = $0[2,999]
self.cBusPath = ARGV[1]
self.cConfFile = ARGV[2]
self.cRootDataDir = ARGV[3]
self.cParentAppName = ARGV[4]
self.cShareDataDir = Dir.getwd
self._get_config()
self._connect_to_dock()
end
def run
self.start()
loop = DBus::Main.new
loop << self.bus
loop.run
puts ">>> applet '#{self.cAppletName}' terminated."
exit
end
##################################
### callbacks on the main icon ###
##################################
def on_click iState
### action on click
end
def on_middle_click
puts ">>> on_middle_click"
### action on middle-click
end
def _on_build_menu
self._cMenuIconId = nil
self.on_build_menu()
end
def on_build_menu
### build our menu
end
def _on_menu_select(iNumEntry)
if self._cMenuIconId == nil
self.on_menu_select(iNumEntry)
else
self.on_menu_select_sub_icon(iNumEntry, self._cMenuIconId)
end
end
def on_menu_select(iNumEntry)
### action on selecting an entry of our menu """
end
def on_scroll(bScrollUp)
### action on scroll
end
def on_drop_data(cReceivedData)
### action on dropping something on our applet
end
def on_answer(answer)
### action on answering a dialog
end
def on_answer_dialog(button, answer)
### action on answering a dialog
end
def on_shortkey(cKey)
### action on pressing one of the shortkeys we bound beforehand
end
def on_change_focus(bIsActive)
### action when the window controlled by the applet takes or looses the focus
end
##################################
### callbacks on the sub-icons ###
##################################
def on_click_sub_icon(iState, cIconID)
### action on click on one of our sub-icons
end
def on_middle_click_sub_icon(cIconID)
### action on middle-click on one of our sub-icons
end
def on_scroll_sub_icon(bScrollUp, cIconID)
### action on scroll on one of our sub-icons
end
def _on_build_menu_sub_icon(cIconID)
self._cMenuIconId = cIconID
self.on_build_menu_sub_icon(cIconID)
end
def on_build_menu_sub_icon(cIconID)
### action on build menu on one of our sub-icons
end
def on_drop_data_sub_icon(cReceivedData, cIconID)
### action on drop data on one of our sub-icons
end
def on_menu_select_sub_icon(iNumEntry, cIconID)
### action on select entry in the menu on one of our sub-icons
end
###############################
### callbacks on the applet ###
###############################
def start
### action when the applet is started
end
def stop
### action when the applet is terminated
end
def _on_stop
self.stop()
exit
end
def reload
### called when our applet is reloaded (config parameters have changed)
end
def _on_reload bConfigHasChanged
if bConfigHasChanged
self._get_config()
self.reload()
end
end
def _get_config
keyfile = ParseConfig.new(self.cConfFile)
self.get_config(keyfile)
end
def get_config keyfile
### get our parameters from the key-file
end
def _connect_to_dock
# get the icon object on the bus
self.bus = DBus::SessionBus.instance
#~ applet_path = "/org/cairodock/CairoDock/#{self.cAppletName}" # path where our object is stored on the bus
applet_service = bus.service("org.cairodock.CairoDock")
begin
applet_object = applet_service.object(self.cBusPath)
applet_object.introspect
applet_object.default_iface = 'org.cairodock.CairoDock.applet'
rescue
puts ">>> object '#{self.cAppletName}' can't be found on the bus, exit.\nMake sure that the 'Dbus' plug-in is activated in Cairo-Dock"
exit
end
self.icon = applet_object
# get the sub-icons object on the bus
applet_sub_icons_object = applet_service.object("#{self.cBusPath}/sub_icons")
applet_sub_icons_object.introspect
applet_sub_icons_object.default_iface = 'org.cairodock.CairoDock.subapplet'
self.sub_icons = applet_sub_icons_object
# now connect to the signals
self.icon.on_signal("on_click") do |iState|
self.on_click iState
end
self.icon.on_signal("on_middle_click") do
self.on_middle_click
end
self.icon.on_signal("on_build_menu") do
self._on_build_menu
end
self.icon.on_signal("on_menu_select") do |iNumEntry|
self._on_menu_select iNumEntry
end
self.icon.on_signal("on_scroll") do |bScrollUp|
self.on_scroll bScrollUp
end
self.icon.on_signal("on_drop_data") do |cReceivedData|
self.on_drop_data cReceivedData
end
self.icon.on_signal("on_answer") do |answer|
self.on_answer answer
end
self.icon.on_signal("on_answer_dialog") do |button, answer|
self.on_answer_dialog button, answer
end
self.icon.on_signal("on_shortkey") do |cKey|
self.on_shortkey cKey
end
self.icon.on_signal("on_change_focus") do |bIsActive|
self.on_change_focus bIsActive
end
self.icon.on_signal("on_stop_module") do
self._on_stop
end
self.icon.on_signal("on_reload_module") do |bConfigHasChanged|
self._on_reload bConfigHasChanged
end
self.sub_icons.on_signal("on_click_sub_icon") do |iState, sub_icon_id|
self.on_click_sub_icon iState, sub_icon_id
end
self.sub_icons.on_signal("on_middle_click_sub_icon") do |sub_icon_id|
self.on_middle_click_sub_icon sub_icon_id
end
self.sub_icons.on_signal("on_scroll_sub_icon") do |bScrollUp, sub_icon_id|
self.on_scroll_sub_icon bScrollUp, sub_icon_id
end
self.sub_icons.on_signal("on_build_menu_sub_icon") do |sub_icon_id|
self._on_build_menu_sub_icon sub_icon_id
end
self.sub_icons.on_signal("on_drop_data_sub_icon") do |cReceivedData, sub_icon_id|
self.on_drop_data_sub_icon cReceivedData, sub_icon_id
end
end
end
|