From 0739eb9dec99b029945235f6ee4170c26cb13901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 21 Apr 2018 13:48:08 +0200 Subject: [PATCH] HistoryManager: Init configpaths only in standalone mode --- gajim/history_manager.py | 50 +++++++++++++++++++++++---------------- launch-history-manager.py | 4 ++++ 2 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 launch-history-manager.py diff --git a/gajim/history_manager.py b/gajim/history_manager.py index 4020d278a..cc0725337 100644 --- a/gajim/history_manager.py +++ b/gajim/history_manager.py @@ -7,6 +7,7 @@ ## Copyright (C) 2006-2014 Yann Leboulanger ## Copyright (C) 2007 Stephan Erb ## Copyright (C) 2008 Jonathan Schleifer +## Copyright (C) 2018 Philipp Hörist ## ## This file is part of Gajim. ## @@ -30,18 +31,37 @@ import os import sys +import time +import getopt +import sqlite3 +from enum import IntEnum, unique + import gi gi.require_version('Gtk', '3.0') +gi.require_version('GLib', '2.0') +gi.require_version('Gdk', '3.0') +gi.require_version('Gio', '2.0') from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GLib -import time +from gi.repository import Gio -import getopt from gajim.common import i18n -def parseOpts(): - config_path = None + +def is_standalone(): + # Determine if we are in standalone mode + if Gio.Application.get_default() is None: + return True + if __name__ == '__main__': + return True + return False + + +if is_standalone(): + # Standalone Mode + # Must be done before importing app + from gajim.common import configpaths try: shortargs = 'hvsc:l:p:' @@ -61,23 +81,16 @@ def parseOpts(): '\n -c, --config-path ' + _('Choose folder for logfile') + '\n') sys.exit() elif o in ('-c', '--config-path'): - config_path = a - return config_path + configpaths.set_config_root(a) -config_path = parseOpts() -del parseOpts + configpaths.init() -from gajim.common import configpaths -configpaths.set_config_root(config_path) -configpaths.init() -del config_path from gajim.common import app from gajim import gtkgui_helpers from gajim.common.logger import LOG_DB_PATH, JIDConstant, KindConstant from gajim.common import helpers from gajim import dialogs -from enum import IntEnum, unique @unique class Column(IntEnum): @@ -87,9 +100,6 @@ class Column(IntEnum): NICKNAME = 5 -import sqlite3 as sqlite - - class HistoryManager: def __init__(self): pixs = [] @@ -120,7 +130,7 @@ class HistoryManager: self.jids_already_in = [] # holds jids that we already have in DB self.AT_LEAST_ONE_DELETION_DONE = False - self.con = sqlite.connect(LOG_DB_PATH, timeout=20.0, + self.con = sqlite3.connect(LOG_DB_PATH, timeout=20.0, isolation_level='IMMEDIATE') self.cur = self.con.cursor() @@ -226,18 +236,18 @@ class HistoryManager: def on_history_manager_window_delete_event(self, widget, event): if not self.AT_LEAST_ONE_DELETION_DONE: - if __name__ == '__main__': + if is_standalone(): Gtk.main_quit() return def on_yes(clicked): self.cur.execute('VACUUM') self.con.commit() - if __name__ == '__main__': + if is_standalone(): Gtk.main_quit() def on_no(): - if __name__ == '__main__': + if is_standalone(): Gtk.main_quit() dialog = dialogs.YesNoDialog( diff --git a/launch-history-manager.py b/launch-history-manager.py new file mode 100644 index 000000000..28c314d0f --- /dev/null +++ b/launch-history-manager.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 + +from gajim import history_manager +history_manager.main()