diff --git a/README.md b/README.md index bbc7caa83..405658817 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ pgrep -af hamster ###### Ubuntu (tested in 19.04 and 18.04) ```bash -sudo apt install gettext intltool gconf2 gir1.2-gconf-2.0 python3-gi-cairo python3-distutils python3-dbus python3-xdg +sudo apt install gettext intltool python3-gi-cairo python3-distutils python3-dbus python3-xdg # and for documentation sudo apt install gnome-doc-utils yelp ``` @@ -70,7 +70,7 @@ sudo zypper install gnome-doc-utils xml2po yelp *RPM-based instructions below should be updated for python3 (issue [#369](https://github.com/projecthamster/hamster/issues/369)).* -`yum install gettext intltool gnome-python2-gconf dbus-python` +`yum install gettext intltool dbus-python` If the hamster help pages are not accessible ("unable to open `help:hamster-time-tracker`"), then a [Mallard](https://en.wikipedia.org/wiki/Mallard_(documentation))-capable help reader is required, diff --git a/data/apps.hamster-time-tracker.gschema.xml.in b/data/apps.hamster-time-tracker.gschema.xml.in new file mode 100644 index 000000000..48b57b333 --- /dev/null +++ b/data/apps.hamster-time-tracker.gschema.xml.in @@ -0,0 +1,88 @@ + + + + true + Stop tracking on idle + + Stop tracking current activity when computer becomes idle + + + + + false + Stop tracking on shutdown + + Stop tracking current activity on shutdown + + + + + 27 + Remind of current task every x minutes + + Remind of current task every specified amount of minutes. + Set to 0 or greater than 120 to disable reminder. + + + + + false + Also remind when no activity is set + + Also remind every notify_interval minutes if no activity + has been started. + + + + + 330 + At what time does the day start (defaults to 5:30AM) + + Activities will be counted as to bedescription to yesterday if + the current time is less than the specified day start; and + today, if it is over the time. + Activities that span two days, will tip over to the side + where the largest part of the activity is. + + + + + [] + Should workspace switch trigger activity switch + + List of enabled tracking methods. "name" will enable + switching activities by name defined in workspace_mapping. + "memory" will enable switching to the last activity when + returning to a previous workspace. + + + + + [] + Switch activity on workspace change + + If switching by name is enabled, this list sets the activity + names that should be switched to, workspaces represented by + the index of item. + + + + + "" + Show / hide Time Tracker Window + Keyboard summarycut for showing / hiding the Time Tracker window. + + + + "hamster-time-tracker toggle" + Toggle hamster application window action + Command for toggling visibility of the hamster application window. + + + + "Toggle hamster application window" + Toggle hamster application window + Toggle visibility of the hamster application window. + + + diff --git a/data/hamster-time-tracker.schemas.in b/data/hamster-time-tracker.schemas.in deleted file mode 100644 index a7dc2f78c..000000000 --- a/data/hamster-time-tracker.schemas.in +++ /dev/null @@ -1,143 +0,0 @@ - - - - /schemas/apps/hamster-time-tracker/enable_timeout - /apps/hamster-time-tracker/enable_timeout - hamster-time-tracker - bool - true - - Stop tracking on idle - - Stop tracking current activity when computer becomes idle - - - - - /schemas/apps/hamster-time-tracker/stop_on_shutdown - /apps/hamster-time-tracker/stop_on_shutdown - hamster-time-tracker - bool - false - - Stop tracking on shutdown - - Stop tracking current activity on shutdown - - - - - /schemas/apps/hamster-time-tracker/notify_interval - /apps/hamster-time-tracker/notify_interval - hamster-time-tracker - int - 27 - - Remind of current task every x minutes - - Remind of current task every specified amount of minutes. - Set to 0 or greater than 120 to disable reminder. - - - - - /schemas/apps/hamster-time-tracker/notify_on_idle - /apps/hamster-time-tracker/notify_on_idle - hamster-time-tracker - bool - false - - Also remind when no activity is set - - Also remind every notify_interval minutes if no activity - has been started. - - - - - /schemas/apps/hamster-time-tracker/day_start_minutes - /apps/hamster-time-tracker/day_start_minutes - hamster-time-tracker - int - 330 - - At what time does the day start (defaults to 5:30AM) - - Activities will be counted as to belong to yesterday if - the current time is less than the specified day start; and - today, if it is over the time. - Activities that span two days, will tip over to the side - where the largest part of the activity is. - - - - - /schemas/apps/hamster-time-tracker/workspace_tracking - /apps/hamster-time-tracker/workspace_tracking - hamster-time-tracker - list - string - [] - - Should workspace switch trigger activity switch - - List of enabled tracking methods. "name" will enable - switching activities by name defined in workspace_mapping. - "memory" will enable switching to the last activity when - returning to a previous workspace. - - - - - /schemas/apps/hamster-time-tracker/workspace_mapping - /apps/hamster-time-tracker/workspace_mapping - hamster-time-tracker - list - string - [] - - Switch activity on workspace change - - If switching by name is enabled, this list sets the activity - names that should be switched to, workspaces represented by - the index of item. - - - - - - - /schemas/desktop/gnome/keybindings/hamster-time-tracker/activate_hamster_window - /desktop/gnome/keybindings/hamster-time-tracker/activate_hamster_window - hamster-time-tracker - string - - - Show / hide Time Tracker Window - Keyboard shortcut for showing / hiding the Time Tracker window. - - - - /schemas/desktop/gnome/keybindings/hamster-time-tracker/action - /desktop/gnome/keybindings/hamster-time-tracker/action - hamster-time-tracker - string - hamster-time-tracker toggle - - Toggle hamster application window action - Command for toggling visibility of the hamster application window. - - - - /schemas/desktop/gnome/keybindings/hamster-time-tracker/name - /desktop/gnome/keybindings/hamster-time-tracker/name - hamster-time-tracker - string - Toggle hamster application window - - Toggle hamster application window - Toggle visibility of the hamster application window. - - - - diff --git a/data/wscript_build b/data/wscript_build index e07abfbee..cbadf6983 100644 --- a/data/wscript_build +++ b/data/wscript_build @@ -27,8 +27,8 @@ bld.add_group() # process .in files with intl_tool bld(features = 'intltool_in', - source = 'hamster-time-tracker.schemas.in', - target = 'hamster-time-tracker.schemas', + source = 'apps.hamster-time-tracker.gschema.xml.in', + target = 'apps.hamster-time-tracker.gschema.xml', install_path = bld.env.schemas_destination, podir = '../po', flags = ['-s', '-u']) diff --git a/src/hamster/idle.py b/src/hamster/idle.py index 5d70e019d..2974bbab3 100644 --- a/src/hamster/idle.py +++ b/src/hamster/idle.py @@ -26,8 +26,7 @@ from dbus.lowlevel import Message -gi.require_version('GConf', '2.0') -from gi.repository import GConf as gconf +from gi.repository import Gio as gio from gi.repository import GObject as gobject class DbusIdleListener(gobject.GObject): @@ -37,7 +36,7 @@ class DbusIdleListener(gobject.GObject): Monitors org.gnome.ScreenSaver for idleness. There are two types, implicit (due to inactivity) and explicit (lock screen), that need to be handled differently. An implicit idle state should subtract the - time-to-become-idle (as specified in the gconf) from the last activity, + time-to-become-idle (as specified in GSettings) from the last activity, but an explicit idle state should not. The signals are inspected for the "ActiveChanged" and "Lock" @@ -102,8 +101,8 @@ def bus_inspector(self, bus, message): else: delay_key = "/desktop/gnome/session/idle_delay" - client = gconf.Client.get_default() - self.timeout_minutes = client.get_int(delay_key) + settings = gio.Settings() + self.timeout_minutes = client.get_value(delay_key) else: self.screen_locked = False diff --git a/src/hamster/lib/configuration.py b/src/hamster/lib/configuration.py index 1ab045ae0..f7d4f1dcb 100644 --- a/src/hamster/lib/configuration.py +++ b/src/hamster/lib/configuration.py @@ -18,7 +18,6 @@ # along with Project Hamster. If not, see . """ -gconf part of this code copied from Gimmie (c) Alex Gravely via Conduit (c) John Stowers, 2006 License: GPLv2 """ @@ -34,8 +33,7 @@ from gi.repository import Gtk as gtk import gi -gi.require_version('GConf', '2.0') -from gi.repository import GConf as gconf +from gi.repository import Gio as gio class Controller(gobject.GObject): @@ -191,154 +189,55 @@ def get_prefs_class(): dialogs = Dialogs() -class GConfStore(gobject.GObject, Singleton): +class GSettingsStore(gobject.GObject, Singleton): """ - Settings implementation which stores settings in GConf + Settings implementation which stores settings in GSettings Snatched from the conduit project (http://live.gnome.org/Conduit) """ - GCONF_DIR = "/apps/hamster-time-tracker/" - VALID_KEY_TYPES = (bool, str, int, list, tuple) - DEFAULTS = { - 'enable_timeout' : False, # Should hamster stop tracking on idle - 'stop_on_shutdown' : False, # Should hamster stop tracking on shutdown - 'notify_on_idle' : False, # Remind also if no activity is set - 'notify_interval' : 27, # Remind of current activity every X minutes - 'day_start_minutes' : 5 * 60 + 30, # At what time does the day start (5:30AM) - 'overview_window_box' : [], # X, Y, W, H - 'overview_window_maximized' : False, # Is overview window maximized - 'standalone_window_box' : [], # X, Y, W, H - 'standalone_window_maximized' : False, # Is overview window maximized - 'activities_source' : "", # Source of TODO items ("", "evo", "gtg") - 'last_report_folder' : "~", # Path to directory where the last report was saved - } __gsignals__ = { - "conf-changed": (gobject.SignalFlags.RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)) + "changed": (gobject.SignalFlags.RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)) } + def __init__(self): gobject.GObject.__init__(self) - self._client = gconf.Client.get_default() - self._client.add_dir(self.GCONF_DIR[:-1], gconf.ClientPreloadType.PRELOAD_RECURSIVE) + self._settings = gio.Settings('apps.HamsterTimeTracker') self._notifications = [] - def _fix_key(self, key): - """ - Appends the GCONF_PREFIX to the key if needed - - @param key: The key to check - @type key: C{string} - @returns: The fixed key - @rtype: C{string} - """ - if not key.startswith(self.GCONF_DIR): - return self.GCONF_DIR + key - else: - return key - - def _key_changed(self, client, cnxn_id, entry, data=None): + def _key_changed(self, client, key, data=None): """ - Callback when a gconf key changes + Callback when a GSettings key changes """ - key = self._fix_key(entry.key)[len(self.GCONF_DIR):] - value = self._get_value(entry.value, self.DEFAULTS[key]) - + value = self._settings.get(key) self.emit('conf-changed', key, value) - - def _get_value(self, value, default): - """calls appropriate gconf function by the default value""" - vtype = type(default) - - if vtype is bool: - return value.get_bool() - elif vtype is str: - return value.get_string() - elif vtype is int: - return value.get_int() - elif vtype in (list, tuple): - l = [] - for i in value.get_list(): - l.append(i.get_string()) - return l - - return None - def get(self, key, default=None): """ Returns the value of the key or the default value if the key is - not yet in gconf + not yet in GSettings """ - #function arguments override defaults - if default is None: - default = self.DEFAULTS.get(key, None) - vtype = type(default) - - #we now have a valid key and type - if default is None: - logger.warn("Unknown key: %s, must specify default value" % key) - return None - - if vtype not in self.VALID_KEY_TYPES: - logger.warn("Invalid key type: %s" % vtype) - return None - - #for gconf refer to the full key path - key = self._fix_key(key) - - if key not in self._notifications: - self._client.notify_add(key, self._key_changed, None) - self._notifications.append(key) - - value = self._client.get(key) + value = self._settings.get(key) if value is None: - self.set(key, default) - return default - - value = self._get_value(value, default) - if value is not None: - return value + logger.warn("Unknown GSettings key: %s" % key) - logger.warn("Unknown gconf key: %s" % key) - return None + return value def set(self, key, value): """ - Sets the key value in gconf and connects adds a signal + Sets the key value in GSettings and connects adds a signal which is fired if the key changes """ logger.debug("Settings %s -> %s" % (key, value)) - if key in self.DEFAULTS: - vtype = type(self.DEFAULTS[key]) - else: - vtype = type(value) - - if vtype not in self.VALID_KEY_TYPES: - logger.warn("Invalid key type: %s" % vtype) - return False - - #for gconf refer to the full key path - key = self._fix_key(key) - - if vtype is bool: - self._client.set_bool(key, value) - elif vtype is str: - self._client.set_string(key, value) - elif vtype is int: - self._client.set_int(key, value) - elif vtype in (list, tuple): - #Save every value as a string - strvalues = [str(i) for i in value] - #self._client.set_list(key, gconf.VALUE_STRING, strvalues) - + self._settings.set(key, value) return True @property def day_start(self): """Start of the hamster day.""" - day_start_minutes = self.get("day_start_minutes") + day_start_minutes = self.get("day-start-minutes") hours, minutes = divmod(day_start_minutes, 60) return dt.time(hours, minutes) -conf = GConfStore() +conf = GSettingsStore() diff --git a/wscript b/wscript index 49a40f08e..88d6ecea1 100644 --- a/wscript +++ b/wscript @@ -23,16 +23,13 @@ def configure(conf): conf.env.GETTEXT_PACKAGE = "hamster-time-tracker" conf.env.PACKAGE = "hamster-time-tracker" - # gconf_dir is defined in options - conf.env.schemas_destination = '{}/schemas'.format(conf.options.gconf_dir) + # gsettings_schema_dir is defined in options + conf.env.schemas_destination = '${DATADIR}/glib-2.0/schemas' conf.recurse("help") def options(opt): - opt.add_option('--gconf-dir', action='store', default='/etc/gconf', dest='gconf_dir', - help='gconf base directory [default: /etc/gconf]') - # the waf default value is /usr/local, which causes issues (e.g. #309) # opt.parser.set_defaults(prefix='/usr') did not update the help string, # hence need to replace the whole option @@ -94,14 +91,10 @@ def build(bld): assert action in ("install", "uninstall") if ctx.cmd == action: - schemas_file = "{}/hamster-time-tracker.schemas".format(ctx.env.schemas_destination) - cmd = 'GCONF_CONFIG_SOURCE=$(gconftool-2 --get-default-source) gconftool-2 --makefile-{}-rule {} 1> /dev/null'.format(action, schemas_file) - err = ctx.exec_command(cmd) - if err: - Logs.warn('The following command failed:\n{}'.format(cmd)) - else: - Logs.pprint('YELLOW', 'Successfully {}ed gconf schemas'.format(action)) - + schemas_file = "{}/apps.hamster-time-tracker.gschema.xml".format(ctx.env.schemas_destination) + bld.install_files(schemas_file, 'data/apps.hamster-time-tracker.gschema.xml') + cmd = 'glib-compile-schemas {}'.format(ctx.env.schemas_destination) + bld(rule=cmd, always=True) def update_icon_cache(ctx): """Update the gtk icon cache."""