def build_accounts_menu(): menubar = app.app.get_menubar() # Accounts Submenu menu_position = 1 if app.prefers_app_menu(): menu_position = 0 acc_menu = menubar.get_item_link(menu_position, 'submenu') acc_menu.remove_all() accounts_list = sorted(app.contacts.get_accounts()) if not accounts_list: modify_account_item = Gio.MenuItem.new(_('_Add Account…'), 'app.accounts::') acc_menu.append_item(modify_account_item) return if len(accounts_list) > 1: modify_account_item = Gio.MenuItem.new(_('_Modify Accounts…'), 'app.accounts::') acc_menu.append_item(modify_account_item) for acc in accounts_list: label = escape_mnemonic(app.get_account_label(acc)) acc_menu.append_submenu( label, get_account_menu(acc)) else: acc_menu = get_account_menu(accounts_list[0]) modify_account_item = Gio.MenuItem.new(_('_Modify Account…'), 'app.accounts::') acc_menu.insert_item(0, modify_account_item) menubar.remove(menu_position) menubar.insert_submenu(menu_position, _('Accounts'), acc_menu)
def _startup(self, _application): # Create and initialize Application Paths & Databases app.detect_dependencies() configpaths.create_paths() try: app.logger = logger.Logger() caps_cache.initialize(app.logger) except exceptions.DatabaseMalformed as error: dlg = Gtk.MessageDialog(transient_for=None, destroy_with_parent=True, modal=True, message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, text=_('Database Error')) dlg.format_secondary_text(str(error)) dlg.run() dlg.destroy() sys.exit() from gajim.gtk.util import load_user_iconsets load_user_iconsets() # Set Application Menu app.app = self from gajim.gtk.util import get_builder builder = get_builder('application_menu.ui') menubar = builder.get_object("menubar") appmenu = builder.get_object("appmenu") if app.prefers_app_menu(): self.set_app_menu(appmenu) else: # Add it to the menubar instead menubar.prepend_submenu('Gajim', appmenu) self.set_menubar(menubar)
def _startup(self, application): # Create and initialize Application Paths & Databases app.detect_dependencies() configpaths.create_paths() try: app.logger = logger.Logger() caps_cache.initialize(app.logger) except exceptions.DatabaseMalformed as error: dlg = Gtk.MessageDialog( None, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Database Error')) dlg.format_secondary_text(str(error)) dlg.run() dlg.destroy() sys.exit() # Set Application Menu app.app = self from gajim import gtkgui_helpers builder = gtkgui_helpers.get_gtk_builder('application_menu.ui') menubar = builder.get_object("menubar") appmenu = builder.get_object("appmenu") if app.prefers_app_menu(): self.set_app_menu(appmenu) else: # Add it to the menubar instead menubar.prepend_submenu('Gajim', appmenu) self.set_menubar(menubar)
def build_bookmark_menu(account): menubar = app.app.get_menubar() bookmark_menu = get_bookmarks_menu(account) if not bookmark_menu: return menu_position = 1 if app.prefers_app_menu(): menu_position = 0 # Accounts Submenu acc_menu = menubar.get_item_link(menu_position, 'submenu') # We have more than one Account active if acc_menu.get_item_link(0, 'submenu'): for i in range(acc_menu.get_n_items()): label = acc_menu.get_item_attribute_value(i, 'label') account_label = escape_mnemonic( app.config.get_per('accounts', account, 'account_label')) if label.get_string() in (account_label, account): menu = acc_menu.get_item_link(i, 'submenu') else: # We have only one Account active menu = acc_menu label = menu.get_item_attribute_value(1, 'label').get_string() menu.remove(1) menu.insert_submenu(1, label, bookmark_menu)
def build_accounts_menu(): menubar = app.app.get_menubar() # Accounts Submenu menu_position = 1 if app.prefers_app_menu(): menu_position = 0 acc_menu = menubar.get_item_link(menu_position, 'submenu') acc_menu.remove_all() accounts_list = sorted(app.contacts.get_accounts()) if not accounts_list: no_accounts = _('No Accounts available') acc_menu.append_item(Gio.MenuItem.new(no_accounts, None)) return if len(accounts_list) > 1: for acc in accounts_list: label = escape_mnemonic( app.config.get_per('accounts', acc, 'account_label')) acc_menu.append_submenu(label or acc, get_account_menu(acc)) else: acc_menu = get_account_menu(accounts_list[0]) menubar.remove(menu_position) menubar.insert_submenu(menu_position, _('Accounts'), acc_menu)
def _startup(self, application): from gajim 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 gajim.common import configpaths configpaths.gajimpaths.init(self.config_path, self.profile, self.profile_separation) from gajim.common import app from gajim.common import check_paths from gajim.common import exceptions from gajim.common import logger from gajim.common import caps_cache try: app.logger = logger.Logger() caps_cache.initialize(app.logger) check_paths.check_and_possibly_create_paths() except exceptions.DatabaseMalformed as error: dlg = Gtk.MessageDialog( None, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Database Error')) dlg.format_secondary_text(str(error)) dlg.run() dlg.destroy() sys.exit() if os.name == 'nt': import gettext # needed for docutils sys.path.append('.') APP = 'gajim' DIR = '../po' lang = locale.getdefaultlocale()[0] 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') 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) # Set Application Menu app.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) menubar = builder.get_object("menubar") appmenu = builder.get_object("appmenu") if app.prefers_app_menu(): self.set_app_menu(appmenu) else: # Add it to the menubar instead menubar.prepend_submenu('Gajim', appmenu) self.set_menubar(menubar)