def setUp(self): gajim.connections = {} gajim.contacts = contacts_module.LegacyContactsAPI() gajim.interface.roster = roster_window.RosterWindow() gajim.plugin_manager = plugins.PluginManager() gajim.logger = MockLogger() caps_cache.initialize(gajim.logger) for acc in contacts: gajim.connections[acc] = MockConnection(acc) gajim.interface.roster.fill_contacts_and_groups_dicts( contacts[acc], acc) gajim.interface.roster.add_account(acc) gajim.interface.roster.add_account_contacts(acc) self.assertEqual(0, len(notify.notifications))
def do_startup(self): Gtk.Application.do_startup(self) import gtkexcepthook gtkexcepthook.init() try: import nbxmpp except ImportError: print('Gajim needs python-nbxmpp to run. Quitting…') sys.exit(1) from distutils.version import LooseVersion as V if V(nbxmpp.__version__) < V(MIN_NBXMPP_VER): print('Gajim needs python-nbxmpp >= %s to run. ' 'Quitting…' % MIN_NBXMPP_VER) sys.exit(1) # Create and initialize Application Paths & Databases from common import configpaths configpaths.gajimpaths.init(self.config_path, self.profile, self.profile_separation) if hasattr(sys, 'frozen'): self.frozen_logging(configpaths.gajimpaths.config_root) from common import gajim from common import check_paths from common import exceptions from common import logger from common import caps_cache try: gajim.logger = logger.Logger() caps_cache.initialize(gajim.logger) check_paths.check_and_possibly_create_paths() except exceptions.DatabaseMalformed: dlg = Gtk.MessageDialog( None, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Database Error')) dlg.format_secondary_text( _('The database file (%s) cannot be read. Try to repair it ' '(see http://trac.gajim.org/wiki/DatabaseBackup) or remove it ' '(all history will be lost).') % gajim.gajimpaths['LOG_DB']) dlg.run() dlg.destroy() sys.exit() if os.name == 'nt': import gettext # needed for docutils sys.path.append('.') APP = 'gajim' DIR = '../po' lang, enc = locale.getdefaultlocale() os.environ['LANG'] = lang gettext.bindtextdomain(APP, DIR) gettext.textdomain(APP) gettext.install(APP, DIR) # This is for Windows translation which is currently not # working on GTK 3.18.9 # locale.setlocale(locale.LC_ALL, '') # import ctypes # import ctypes.util # libintl_path = ctypes.util.find_library('intl') # if libintl_path == None: # local_intl = os.path.join('gtk', 'bin', 'intl.dll') # if os.path.exists(local_intl): # libintl_path = local_intl # if libintl_path == None: # raise ImportError('intl.dll library not found') # libintl = ctypes.cdll.LoadLibrary(libintl_path) # libintl.bindtextdomain(APP, DIR) # libintl.bind_textdomain_codeset(APP, 'UTF-8') # plugins_locale_dir = os.path.join(common.configpaths.gajimpaths[ # 'PLUGINS_USER'], 'locale').encode(locale.getpreferredencoding()) # libintl.bindtextdomain('gajim_plugins', plugins_locale_dir) # libintl.bind_textdomain_codeset('gajim_plugins', 'UTF-8') if Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL: i18n.direction_mark = '\u200F' from ctypes import CDLL from ctypes.util import find_library import platform sysname = platform.system() if sysname in ('Linux', 'FreeBSD', 'OpenBSD', 'NetBSD'): libc = CDLL(find_library('c')) # The constant defined in <linux/prctl.h> which is used to set the name # of the process. PR_SET_NAME = 15 if sysname == 'Linux': libc.prctl(PR_SET_NAME, 'gajim') elif sysname in ('FreeBSD', 'OpenBSD', 'NetBSD'): libc.setproctitle('gajim') # Seed the OpenSSL pseudo random number generator from file and initialize if PYOPENSSL_PRNG_PRESENT: self.rng_seed = gajim.gajimpaths['RNG_SEED'] # Seed from file try: OpenSSL.rand.load_file(self.rng_seed) except TypeError: OpenSSL.rand.load_file(self.rng_seed.encode('utf-8')) crypto.add_entropy_sources_OpenSSL() try: OpenSSL.rand.write_file(self.rng_seed) except TypeError: OpenSSL.rand.write_file(self.rng_seed.encode('utf-8')) def sigint_cb(num, stack): print('SIGINT/SIGTERM received') self.quit() # ^C exits the application normally signal.signal(signal.SIGINT, sigint_cb) signal.signal(signal.SIGTERM, sigint_cb) print("Encodings: d:{}, fs:{}, p:{}".format( sys.getdefaultencoding(), sys.getfilesystemencoding(), locale.getpreferredencoding())) # Set Application Menu gajim.app = self path = os.path.join(configpaths.get('GUI'), 'application_menu.ui') builder = Gtk.Builder() builder.set_translation_domain(i18n.APP) builder.add_from_file(path) self.set_menubar(builder.get_object("menubar")) self.set_app_menu(builder.get_object("appmenu"))
def do_activate(self): # If a second instance starts do_activate() is called # We bringt the Roster window to the front, GTK exits afterwards. if self.interface: self.interface.roster.window.present() return Gtk.Application.do_activate(self) import gtkexcepthook gtkexcepthook.init() # Create and initialize Application Paths & Databases import common.configpaths common.configpaths.gajimpaths.init(self.config_path, self.profile, self.profile_separation) from common import gajim from common import check_paths from common import exceptions from common import logger from common import caps_cache try: gajim.logger = logger.Logger() caps_cache.initialize(gajim.logger) check_paths.check_and_possibly_create_paths() except exceptions.DatabaseMalformed: dlg = Gtk.MessageDialog( None, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Database Error')) dlg.format_secondary_text( _('The database file (%s) cannot be read. Try to repair it ' '(see http://trac.gajim.org/wiki/DatabaseBackup) or remove it ' '(all history will be lost).') % gajim.gajimpaths['LOG_DB']) dlg.run() dlg.destroy() sys.exit() if os.name == 'nt': import gettext # needed for docutils sys.path.append('.') APP = 'gajim' DIR = '../po' lang, enc = locale.getdefaultlocale() os.environ['LANG'] = lang gettext.bindtextdomain(APP, DIR) gettext.textdomain(APP) gettext.install(APP, DIR) # This is for Windows translation which is currently not # working on GTK 3.18.9 # locale.setlocale(locale.LC_ALL, '') # import ctypes # import ctypes.util # libintl_path = ctypes.util.find_library('intl') # if libintl_path == None: # local_intl = os.path.join('gtk', 'bin', 'intl.dll') # if os.path.exists(local_intl): # libintl_path = local_intl # if libintl_path == None: # raise ImportError('intl.dll library not found') # libintl = ctypes.cdll.LoadLibrary(libintl_path) # libintl.bindtextdomain(APP, DIR) # libintl.bind_textdomain_codeset(APP, 'UTF-8') # plugins_locale_dir = os.path.join(common.configpaths.gajimpaths[ # 'PLUGINS_USER'], 'locale').encode(locale.getpreferredencoding()) # libintl.bindtextdomain('gajim_plugins', plugins_locale_dir) # libintl.bind_textdomain_codeset('gajim_plugins', 'UTF-8') if Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL: i18n.direction_mark = '\u200F' from ctypes import CDLL from ctypes.util import find_library import platform sysname = platform.system() if sysname in ('Linux', 'FreeBSD', 'OpenBSD', 'NetBSD'): libc = CDLL(find_library('c')) # The constant defined in <linux/prctl.h> which is used to set the name # of the process. PR_SET_NAME = 15 if sysname == 'Linux': libc.prctl(PR_SET_NAME, 'gajim') elif sysname in ('FreeBSD', 'OpenBSD', 'NetBSD'): libc.setproctitle('gajim') # Seed the OpenSSL pseudo random number generator from file and initialize if PYOPENSSL_PRNG_PRESENT: self.rng_seed = gajim.gajimpaths['RNG_SEED'] # Seed from file try: OpenSSL.rand.load_file(self.rng_seed) except TypeError: OpenSSL.rand.load_file(self.rng_seed.encode('utf-8')) crypto.add_entropy_sources_OpenSSL() try: OpenSSL.rand.write_file(self.rng_seed) except TypeError: OpenSSL.rand.write_file(self.rng_seed.encode('utf-8')) def sigint_cb(num, stack): print('SIGINT/SIGTERM received') self.quit() # ^C exits the application normally signal.signal(signal.SIGINT, sigint_cb) signal.signal(signal.SIGTERM, sigint_cb) log.info("Encodings: d:%s, fs:%s, p:%s", sys.getdefaultencoding(), sys.getfilesystemencoding(), locale.getpreferredencoding()) from gui_interface import Interface self.interface = Interface() self.interface.run(self)
i18n.direction_mark = '\u200F' pritext = '' from common import exceptions try: from common import gajim except exceptions.DatabaseMalformed: pritext = _('Database Error') sectext = _('The database file (%s) cannot be read. Try to repair it (see ' 'http://trac.gajim.org/wiki/DatabaseBackup) or remove it (all history ' 'will be lost).') % common.logger.LOG_DB_PATH else: from common import logger gajim.logger = logger.Logger() from common import caps_cache caps_cache.initialize(gajim.logger) from common import dbus_support if dbus_support.supported: from music_track_listener import MusicTrackListener from ctypes import CDLL from ctypes.util import find_library import platform sysname = platform.system() if sysname in ('Linux', 'FreeBSD', 'OpenBSD', 'NetBSD'): libc = CDLL(find_library('c')) # The constant defined in <linux/prctl.h> which is used to set the name # of the process. PR_SET_NAME = 15