aboutsummaryrefslogtreecommitdiff
path: root/data/usr/bin/ayatana-webmail-settings
blob: f000a9e8864719704ac6249eb0cbc17bfdc4a041 (plain)
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Ayatana Webmail, Show the settings dialog
# Authors: Robert Tari <robert@tari.in>
# License: GNU GPL 3 or higher; http://www.gnu.org/licenses/gpl.html

import sys
import dbus
import subprocess
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
from ayatanawebmail.common import isRunning

oLoop = None

if __name__ == '__main__':

    if isRunning('-settings') == 1:

        DBusGMainLoop(set_as_default=True)
        oSessionBus = dbus.SessionBus()

        if isRunning():

            try:

                oSession = oSessionBus.get_object('org.ayatana.webmail', '/org/ayatana/webmail')
                oInterface = dbus.Interface(oSession, 'org.ayatana.webmail')

                oInterface.settings(reply_handler=lambda: oLoop.quit(), error_handler=lambda o: oLoop.quit())

                oLoop = GLib.MainLoop()
                oLoop.run()

            except dbus.DBusException as oDBusException:

                print(oDBusException)
                sys.exit(1)

            sys.exit(0)

        else:

            subprocess.Popen(['ayatana-webmail'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

    sys.exit(1)