2018-04-25 19:09:12 +02:00
|
|
|
# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim 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.
|
|
|
|
#
|
|
|
|
# Gajim 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 Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2005-11-13 15:55:52 +01:00
|
|
|
|
2017-02-11 21:25:43 +01:00
|
|
|
import os
|
2018-04-25 19:09:12 +02:00
|
|
|
import sys
|
2017-02-11 21:25:43 +01:00
|
|
|
import signal
|
2018-04-25 19:09:12 +02:00
|
|
|
import platform
|
|
|
|
from ctypes import CDLL, byref, create_string_buffer
|
|
|
|
from ctypes.util import find_library
|
|
|
|
from distutils.version import LooseVersion as V
|
2018-02-14 21:11:25 +01:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
# Install _() in namespace
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import i18n
|
2017-02-11 21:25:43 +01:00
|
|
|
|
2019-03-16 16:21:53 +01:00
|
|
|
_MIN_NBXMPP_VER = "0.6.10"
|
2018-04-25 19:09:12 +02:00
|
|
|
_MIN_GTK_VER = "3.22.0"
|
2017-02-11 21:25:43 +01:00
|
|
|
|
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
def _check_required_deps():
|
|
|
|
try:
|
|
|
|
import nbxmpp
|
|
|
|
except ImportError:
|
|
|
|
print('Gajim needs python-nbxmpp to run. Quitting…')
|
|
|
|
sys.exit(1)
|
2017-02-11 21:25:43 +01:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
if V(nbxmpp.__version__) < V(_MIN_NBXMPP_VER):
|
|
|
|
print('Gajim needs python-nbxmpp >= %s to run. '
|
|
|
|
'Quitting...' % _MIN_NBXMPP_VER)
|
|
|
|
sys.exit(1)
|
2017-02-11 21:25:43 +01:00
|
|
|
|
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
def _init_gui(gui):
|
|
|
|
if gui == 'GTK':
|
|
|
|
_init_gtk()
|
2017-01-26 21:34:54 +01:00
|
|
|
|
2017-02-11 21:25:43 +01:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
def _init_gtk():
|
|
|
|
import gi
|
|
|
|
gi.require_version('GLib', '2.0')
|
|
|
|
gi.require_version('Gio', '2.0')
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
gi.require_version('Gdk', '3.0')
|
|
|
|
gi.require_version('GObject', '2.0')
|
|
|
|
gi.require_version('Pango', '1.0')
|
2017-11-25 15:33:54 +01:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
from gi.repository import Gtk
|
|
|
|
gtk_ver = '%s.%s.%s' % (Gtk.get_major_version(),
|
|
|
|
Gtk.get_minor_version(),
|
|
|
|
Gtk.get_micro_version())
|
|
|
|
if V(gtk_ver) < V(_MIN_GTK_VER):
|
|
|
|
print('Gajim needs GTK+ >= %s to run. '
|
|
|
|
'Quitting...' % _MIN_GTK_VER)
|
|
|
|
sys.exit(1)
|
2017-02-11 21:25:43 +01:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
from gajim import gtkexcepthook
|
|
|
|
gtkexcepthook.init()
|
2017-07-21 12:34:38 +02:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
i18n.initialize_direction_mark()
|
2018-02-03 09:36:21 +01:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
from gajim.application import GajimApplication
|
2018-02-13 19:18:40 +01:00
|
|
|
|
2018-10-20 09:55:48 +02:00
|
|
|
# Fix bug in 3.24.1 with flickering tooltips
|
|
|
|
if sys.platform in ('darwin', 'win32'):
|
|
|
|
settings = Gtk.Settings.get_default()
|
|
|
|
settings.set_property('gtk-cursor-theme-size', 16)
|
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
application = GajimApplication()
|
2018-05-17 20:57:21 +02:00
|
|
|
_install_sginal_handlers(application)
|
2018-04-25 19:09:12 +02:00
|
|
|
application.run(sys.argv)
|
2018-03-17 17:11:07 +01:00
|
|
|
|
2018-02-03 09:36:21 +01:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
def _set_proc_title():
|
|
|
|
sysname = platform.system()
|
|
|
|
if sysname in ('Linux', 'FreeBSD', 'OpenBSD', 'NetBSD'):
|
|
|
|
libc = CDLL(find_library('c'))
|
2018-02-03 09:36:21 +01:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
# The constant defined in <linux/prctl.h> which is used to set the name
|
|
|
|
# of the process.
|
|
|
|
PR_SET_NAME = 15
|
2018-02-03 09:36:21 +01:00
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
if sysname == 'Linux':
|
|
|
|
proc_name = b'gajim'
|
|
|
|
buff = create_string_buffer(len(proc_name)+1)
|
|
|
|
buff.value = proc_name
|
|
|
|
libc.prctl(PR_SET_NAME, byref(buff), 0, 0, 0)
|
|
|
|
elif sysname in ('FreeBSD', 'OpenBSD', 'NetBSD'):
|
|
|
|
libc.setproctitle('gajim')
|
2018-04-21 12:44:10 +02:00
|
|
|
|
|
|
|
|
2018-05-17 20:57:21 +02:00
|
|
|
def _install_sginal_handlers(application):
|
2018-04-25 19:09:12 +02:00
|
|
|
def sigint_cb(num, stack):
|
|
|
|
print('SIGINT/SIGTERM received')
|
|
|
|
application.quit()
|
|
|
|
# ^C exits the application normally
|
|
|
|
signal.signal(signal.SIGINT, sigint_cb)
|
|
|
|
signal.signal(signal.SIGTERM, sigint_cb)
|
2018-05-17 20:57:21 +02:00
|
|
|
if os.name != 'nt':
|
|
|
|
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
2017-01-26 21:34:54 +01:00
|
|
|
|
2016-12-22 19:48:48 +01:00
|
|
|
|
2018-01-13 22:07:25 +01:00
|
|
|
def main():
|
|
|
|
if sys.platform != 'win32':
|
|
|
|
if os.geteuid() == 0:
|
|
|
|
sys.exit("You must not launch gajim as root, it is insecure.")
|
|
|
|
|
2018-04-25 19:09:12 +02:00
|
|
|
_check_required_deps()
|
|
|
|
_set_proc_title()
|
|
|
|
_init_gui('GTK')
|