~cairo-dock-team/cairo-dock-plug-ins/plug-ins

« back to all changes in this revision

Viewing changes to Dbus/data/cairo-dock-launcher-API-daemon.py.in

  • Committer: Matthieu Baerts
  • Date: 2012-11-07 17:44:38 UTC
  • Revision ID: matttbe@gmail.com-20121107174438-0ll51mtsvmsglk5k
DBus: remaned cairo-dock-unity-bridge to cairo-dock-launcher-API-daemon
This script is not really a bridge but it replaces the Unity Launcher API daemon.
Unity is not required, if an application supports the Unity Launcher API, the dock should act as "Unity's dock".
 + Added an option to not launch it at startup

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
                        bus.watch_name_owner(self.dbus_name, self.on_name_owner_changed)
60
60
        
61
61
        def on_name_owner_changed(self,connection_name):
62
 
                print("Unity-Bridge: launcher bus name changed:",connection_name)
 
62
                print("Launcher-API-Daemon: launcher bus name changed:",connection_name)
63
63
                if len(connection_name) == 0:  # no more distant app -> reset the launcher and its icon.
64
 
                        print("Unity-Bridge: -> the launcher "+ str (self.dbus_name) +" is no longer connected to its app.")
 
64
                        print("Launcher-API-Daemon: -> the launcher "+ str (self.dbus_name) +" is no longer connected to its app.")
65
65
                        if self.has_count and self.count_visible:
66
66
                                self.dock.iface.SetQuickInfo('', self.id)
67
67
                                self.has_count = False
83
83
                        self.dbus_name = None
84
84
                        
85
85
        def set_count(self, x):
86
 
                print('Unity-Bridge: set_count (%d)'%x)
 
86
                print('Launcher-API-Daemon: set_count (%d)'%x)
87
87
                self.count = x
88
88
                self.has_count = True
89
89
                if self.count_visible:
90
90
                        self.dock.iface.SetQuickInfo(str(self.count), self.id)
91
91
        
92
92
        def set_count_visible(self, x):
93
 
                print('Unity-Bridge: set_count_visible (%d)'%x)
 
93
                print('Launcher-API-Daemon: set_count_visible (%d)'%x)
94
94
                self.count_visible = x
95
95
                if self.has_count:
96
96
                        if x:
99
99
                                self.dock.iface.SetQuickInfo('', self.id)
100
100
        
101
101
        def set_progress(self, x):
102
 
                print('Unity-Bridge: set_progress (%.2f)'%x)
 
102
                print('Launcher-API-Daemon: set_progress (%.2f)'%x)
103
103
                self.progress = x
104
104
                self.has_progress = True
105
105
                self.dock.iface.SetProgress (x, self.id)
106
106
        
107
107
        def set_progress_visible(self, x):
108
 
                print('Unity-Bridge: set_progress_visible (%d)'%x)
 
108
                print('Launcher-API-Daemon: set_progress_visible (%d)'%x)
109
109
                self.progress_visible = x
110
110
                if not x:
111
111
                        self.dock.iface.SetProgress (-1, self.id)
113
113
                        self.dock.iface.SetProgress (self.progress, self.id)
114
114
        
115
115
        def set_urgent(self, x):
116
 
                print('Unity-Bridge: set_urgent (%d)'%x)
 
116
                print('Launcher-API-Daemon: set_urgent (%d)'%x)
117
117
                self.urgent = x
118
118
                self.dock.iface.DemandsAttention(x, 'default', self.id)
119
119
        
120
120
        def set_menu(self, menu_path):
121
 
                print('Unity-Bridge: set_menu (%s)'%menu_path)
 
121
                print('Launcher-API-Daemon: set_menu (%s)'%menu_path)
122
122
                self.menu_path = menu_path
123
123
                self.dock.iface.SetMenu(self.dbus_name, menu_path, self.id)
124
124
        
125
125
        def set_emblem(self, x):
126
 
                print('Unity-Bridge: set_emblem (%s)'%x)
 
126
                print('Launcher-API-Daemon: set_emblem (%s)'%x)
127
127
                self.emblem = x
128
128
                self.has_emblem = True
129
129
                if self.emblem_visible:
130
130
                        self.dock.iface.SetEmblem(self.emblem, CairoDock.EMBLEM_TOP_RIGHT, self.id)
131
131
        
132
132
        def set_emblem_visible(self, x):
133
 
                print('Unity-Bridge: set_emblem_visible (%d)'%x)
 
133
                print('Launcher-API-Daemon: set_emblem_visible (%d)'%x)
134
134
                self.emblem_visible = x
135
135
                if self.has_emblem:
136
136
                        if x:
150
150
                try: 
151
151
                        self.bus = dbus.SessionBus()
152
152
                except Exception as exception:
153
 
                        print('Unity-Bridge: Could not open dbus. Uncaught exception.')
 
153
                        print('Launcher-API-Daemon: Could not open dbus. Uncaught exception.')
154
154
                        return
155
155
                
156
156
                bus_name = dbus.service.BusName (self.bus_name_str, self.bus)
157
 
                print("Unity-Bridge: registered as Unity:",bus_name)
 
157
                print("Launcher-API-Daemon: registered as Unity:",bus_name)
158
158
                
159
159
                self.bus.add_signal_receiver (self.on_launcher_entry_signal, dbus_interface=self.bus_iface_str, member_keyword='member', sender_keyword='sender')
160
160
                
165
165
        
166
166
        def on_launcher_entry_signal(self, val1=None, val2=None, member=None, sender=None):  # application://evolution.desktop, dictionnary (sv)
167
167
                if (member == 'Update'):
168
 
                        print('Unity-Bridge: Update',val1)
 
168
                        print('Launcher-API-Daemon: Update',val1)
169
169
                        
170
170
                        launcher = None
171
171
                        if val1 in self.launchers:
208
208
                                launcher.set_emblem_visible (emblem_visible)
209
209
                        
210
210
                elif (member == 'Query'):
211
 
                        print('Unity-Bridge:   query',val2,'for',val1)
 
211
                        print('Launcher-API-Daemon:   query',val2,'for',val1)
212
212
                else:
213
 
                        print('Unity-Bridge: unknown signal')
 
213
                        print('Launcher-API-Daemon: unknown signal')
214
214
                
215
215
if __name__ == '__main__':
216
216
        # check that we don't run twice (ex.: from a 2nd cairo-dock instance)
217
217
        # we could detect it from the bus, but then we couldn't detect the following case: Unity launcher + Cairo-Dock
218
218
        # we want: ps ux | grep " + filename + " | grep python | grep -v " + pid_str)
219
219
        ps_str = popen("ps -u $USER -wwo pid,cmd").read().splitlines() # only users' processes with all lines
220
 
        filename = sys.argv[0] # /usr/lib/cairo-dock/cairo-dock-unity-bridge
 
220
        filename = sys.argv[0] # /usr/lib/cairo-dock/cairo-dock-launcher-API-daemon
221
221
        pid_str = str (getpid()) # we check if previous processes are running, we exclude this process
222
222
        for line in ps_str:
223
223
                line_split = line.split()
224
224
                line_cmd = ' '.join(line_split[1:])
225
225
                line_pid = line_split[0]
226
226
                if "python" in line_cmd and filename in line_cmd and not pid_str in line_pid:
227
 
                        print('Cairo-Dock - Unity bridge is already running (' + line_pid + ')')
 
227
                        print('Cairo-Dock - Launcher API Daemon is already running (' + line_pid + ')')
228
228
                        sys.exit(1)
229
229
        
230
230
        ULWatcher()