-
Notifications
You must be signed in to change notification settings - Fork 32
/
mailnag-config
executable file
·90 lines (68 loc) · 2.5 KB
/
mailnag-config
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
#!/usr/bin/env python3
#
# Copyright 2011 - 2019 Patrick Ulbrich <[email protected]>
#
# 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 2 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
import gi
gi.require_version('Gtk', '3.0')
import os
import subprocess
import logging
from gi.repository import Gtk
from Mailnag.common.utils import fix_cwd, init_logging
fix_cwd()
from Mailnag.common.i18n import _
from Mailnag.common.utils import set_procname, shutdown_existing_instance, get_data_file, get_data_paths
from Mailnag.common.dist_cfg import BIN_DIR
from Mailnag.configuration.configwindow import ConfigWindow
LOG_LEVEL = logging.DEBUG
class App(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self, application_id = 'com.github.pulp.Mailnag')
self.win = None
def do_startup(self):
Gtk.Application.do_startup(self)
# Add icons in alternative data paths (e.g. ./data/icons)
# to the icon search path in case Mailnag is launched
# from a local directory (without installing).
icon_theme = Gtk.IconTheme.get_default()
for path in get_data_paths():
icon_theme.append_search_path(os.path.join(path, "icons"))
def do_activate(self):
Gtk.Application.do_activate(self)
if not self.win:
self.win = ConfigWindow(self)
self.win.get_gtk_window().present()
def do_shutdown(self):
Gtk.Application.do_shutdown(self)
if self.win.get_daemon_enabled():
try:
# the launched daemon shuts down
# an already running daemon
print("Launching Mailnag daemon.")
subprocess.Popen(os.path.join(BIN_DIR, "mailnag"))
except:
print("ERROR: Failed to launch Mailnag daemon.")
else:
# shutdown running Mailnag daemon
shutdown_existing_instance(wait_for_completion = False)
def main():
set_procname("mailnag-config")
init_logging(enable_stdout = True, enable_syslog = False, log_level = LOG_LEVEL)
app = App()
app.run(None)
if __name__ == "__main__": main()