~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-proposed

« back to all changes in this revision

Viewing changes to Dbus/interfaces/ruby/CDApplet.rb

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2011-04-20 20:46:51 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110420204651-ftnpzesj6uc7qeul
Tags: 2.3.0~1-0ubuntu1
* New Upstream Version (LP: #723995)
* Upstream short ChangeLog (since 2.3.0~0rc1):
 - Updated translations
 - Updated the integration of the new versions of kwin and compiz
    (Switcher, ShowDesktop, etc.)
 - Removed a lot of useless g_print
 - Updated a few plug-ins to fit with the new version of the API (gldit)
 - Fixed a few bugs
 - Updated MeMenu, MessagingMenu and Status-Notifier to works
    with the latest version of dbusmenu, etc.
* Switch to dpkg-source 3.0 (quilt) format
* debian/cairo-dock-plug-ins.install:
 - Added new files (interfaces for python, ruby, vala and mono)
* debian/control:
 - Added new dependences for new applets (sensors and zeitgeist)
    and new interfaces (python, valac, ruby and mono)
 - Updated the version of cairo-dock build-dependences
* debian/rules:
 - Added a new CMake flag to install python interface in debian/tmp
* Updated debian/watch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/ruby
 
2
 
 
3
# This is a part of the external Ruby Interface for Cairo-Dock
 
4
 
 
5
# Author: Fabounet and Eduardo Mucelli Rezende Oliveira
 
6
# E-mail: fabounet@glx-dock.org, edumucelli@gmail.com or eduardom@dcc.ufmg.br
 
7
#
 
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.
 
12
 
 
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.
 
17
 
 
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.
 
22
 
 
23
require 'rubygems'
 
24
require 'dbus'
 
25
require 'parseconfig'
 
26
 
 
27
class CDApplet
 
28
        attr_accessor :cConfFile, :cAppletName, :icon, :sub_icons, :config, :bus, :_cMenuIconId, :cParentAppName, :cBusPath
 
29
        
 
30
        BOTTOM = 0
 
31
        TOP    = 1
 
32
        RIGHT  = 2
 
33
        LEFT   = 3
 
34
        
 
35
        DOCK    = 0
 
36
        DESKLET = 1
 
37
        
 
38
        UPPER_LEFT  = 0
 
39
        LOWER_RIGHT = 1
 
40
        LOWER_LEFT  = 2
 
41
        UPPER_RIGHT = 3
 
42
        MIDDLE      = 4
 
43
        
 
44
        MENU_ENTRY        = 0
 
45
        MENU_SUB_MENU     = 1
 
46
        MENU_SEPARATOR    = 2
 
47
        MENU_CHECKBOX     = 3
 
48
        MENU_RADIO_BUTTON = 4
 
49
 
 
50
        MAIN_MENU_ID = 0
 
51
        
 
52
        DIALOG_KEY_ENTER = -1
 
53
        DIALOG_KEY_ESCAPE = -2
 
54
 
 
55
        def initialize
 
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")
 
58
                self.config = {}
 
59
                self.bus = nil
 
60
                self.icon = nil
 
61
                self.sub_icons = nil
 
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]
 
67
                
 
68
                self._get_config()
 
69
                self._connect_to_dock()
 
70
        end
 
71
        
 
72
        def run
 
73
                self.start()
 
74
                loop = DBus::Main.new
 
75
                loop << self.bus
 
76
                loop.run
 
77
                puts ">>> applet '#{self.cAppletName}' terminated."
 
78
                exit
 
79
        end
 
80
        
 
81
        ##################################
 
82
        ### callbacks on the main icon ###
 
83
        ##################################
 
84
        
 
85
        def on_click iState
 
86
                ### action on click
 
87
        end
 
88
        
 
89
        def on_middle_click
 
90
                puts ">>> on_middle_click"
 
91
                ### action on middle-click
 
92
        end
 
93
        
 
94
        def _on_build_menu
 
95
                self._cMenuIconId = nil
 
96
                self.on_build_menu()
 
97
        end
 
98
        
 
99
        def on_build_menu
 
100
                ### build our menu
 
101
        end
 
102
        
 
103
        def _on_menu_select(iNumEntry)
 
104
                if self._cMenuIconId == nil
 
105
                        self.on_menu_select(iNumEntry)
 
106
                else
 
107
                        self.on_menu_select_sub_icon(iNumEntry, self._cMenuIconId)
 
108
                end
 
109
        end
 
110
        
 
111
        def on_menu_select(iNumEntry)
 
112
                ### action on selecting an entry of our menu """
 
113
        end
 
114
        
 
115
        def on_scroll(bScrollUp)
 
116
                ### action on scroll
 
117
        end
 
118
 
 
119
        def on_drop_data(cReceivedData)
 
120
                ### action on dropping something on our applet
 
121
        end
 
122
        
 
123
        def on_answer(answer)
 
124
                ### action on answering a dialog
 
125
        end
 
126
 
 
127
        def on_answer_dialog(button, answer)
 
128
                ### action on answering a dialog
 
129
        end
 
130
 
 
131
        def on_shortkey(cKey)
 
132
                ### action on pressing one of the shortkeys we bound beforehand
 
133
        end
 
134
        
 
135
        def on_change_focus(bIsActive)
 
136
                ### action when the window controlled by the applet takes or looses the focus
 
137
        end
 
138
        
 
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
 
144
        end
 
145
        
 
146
        def on_middle_click_sub_icon(cIconID)
 
147
                ### action on middle-click on one of our sub-icons
 
148
        end
 
149
        
 
150
        def on_scroll_sub_icon(bScrollUp, cIconID)
 
151
                ### action on scroll on one of our sub-icons
 
152
        end
 
153
        
 
154
        def _on_build_menu_sub_icon(cIconID)
 
155
                self._cMenuIconId = cIconID
 
156
                self.on_build_menu_sub_icon(cIconID)
 
157
        end
 
158
        
 
159
        def on_build_menu_sub_icon(cIconID)
 
160
                ### action on build menu on one of our sub-icons
 
161
        end
 
162
        
 
163
        def on_drop_data_sub_icon(cReceivedData, cIconID)
 
164
                ### action on drop data on one of our sub-icons
 
165
        end
 
166
        
 
167
        def on_menu_select_sub_icon(iNumEntry, cIconID)
 
168
                ### action on select entry in the menu on one of our sub-icons
 
169
        end
 
170
        
 
171
        
 
172
        ###############################
 
173
        ### callbacks on the applet ###
 
174
        ###############################
 
175
        
 
176
        def start
 
177
                ### action when the applet is started
 
178
        end
 
179
        
 
180
        def stop
 
181
                ### action when the applet is terminated
 
182
        end
 
183
        
 
184
        def _on_stop
 
185
                self.stop()
 
186
                exit
 
187
        end
 
188
        
 
189
        def reload
 
190
                ### called when our applet is reloaded (config parameters have changed)
 
191
        end
 
192
        
 
193
        def _on_reload bConfigHasChanged
 
194
                if bConfigHasChanged
 
195
                        self._get_config()
 
196
                        self.reload()
 
197
                end
 
198
        end
 
199
        
 
200
        def _get_config
 
201
                keyfile = ParseConfig.new(self.cConfFile)
 
202
                self.get_config(keyfile)
 
203
        end
 
204
        
 
205
        def get_config keyfile
 
206
                ### get our parameters from the key-file
 
207
        end
 
208
        
 
209
        def _connect_to_dock
 
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")
 
214
                begin
 
215
                        applet_object = applet_service.object(self.cBusPath)
 
216
                        applet_object.introspect
 
217
                        applet_object.default_iface = 'org.cairodock.CairoDock.applet'
 
218
                rescue
 
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"
 
220
                        exit
 
221
                end
 
222
                self.icon = applet_object
 
223
                
 
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
 
229
                
 
230
                # now connect to the signals
 
231
                self.icon.on_signal("on_click") do |iState|
 
232
                        self.on_click iState
 
233
                end
 
234
                self.icon.on_signal("on_middle_click") do
 
235
                        self.on_middle_click
 
236
                end
 
237
                self.icon.on_signal("on_build_menu") do
 
238
                        self._on_build_menu
 
239
                end
 
240
                self.icon.on_signal("on_menu_select") do |iNumEntry|
 
241
                        self._on_menu_select iNumEntry
 
242
                end
 
243
                self.icon.on_signal("on_scroll") do |bScrollUp|
 
244
                        self.on_scroll bScrollUp
 
245
                end
 
246
                self.icon.on_signal("on_drop_data") do |cReceivedData|
 
247
                        self.on_drop_data cReceivedData
 
248
                end
 
249
                self.icon.on_signal("on_answer") do |answer|
 
250
                        self.on_answer answer
 
251
                end
 
252
                self.icon.on_signal("on_answer_dialog") do |button, answer|
 
253
                        self.on_answer_dialog button, answer
 
254
                end
 
255
                self.icon.on_signal("on_shortkey") do |cKey|
 
256
                        self.on_shortkey cKey
 
257
                end
 
258
                self.icon.on_signal("on_change_focus") do |bIsActive|
 
259
                        self.on_change_focus bIsActive
 
260
                end
 
261
                
 
262
                self.icon.on_signal("on_stop_module") do
 
263
                        self._on_stop
 
264
                end
 
265
                
 
266
                self.icon.on_signal("on_reload_module") do |bConfigHasChanged|
 
267
                        self._on_reload bConfigHasChanged
 
268
                end
 
269
                
 
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
 
272
                end
 
273
                
 
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
 
276
                end
 
277
                
 
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
 
280
                end
 
281
                
 
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
 
284
                end
 
285
                
 
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
 
288
                end
 
289
                
 
290
        end
 
291
end