#!/usr/bin/python3
from gi.repository import Gio
import sys
UBUNTU_VOLUME_SETTINGS = "com.ubuntu.sound"
UBUNTU_VOLUME_AMPLIFIED_KEY = "allow-amplified-volume"
GNOME_VOLUME_SETTINGS = "org.gnome.desktop.sound"
GNOME_VOLUME_AMPLIFIED_KEY = "allow-volume-above-100-percent"
if __name__ == "__main__":
source = Gio.SettingsSchemaSource.get_default()
# Old and new keys installed
if (source.lookup(UBUNTU_VOLUME_SETTINGS, True) is None or
source.lookup(GNOME_VOLUME_SETTINGS, True) is None):
print("Missing ubuntu or gnome volume key: no migration needed")
sys.exit(0)
src_settings = Gio.Settings.new(UBUNTU_VOLUME_SETTINGS)
dst_settings = Gio.Settings.new(GNOME_VOLUME_SETTINGS)
if not dst_settings.is_writable(GNOME_VOLUME_AMPLIFIED_KEY):
print("Can't migrate amplification key to GNOME one as they are not writable")
sys.exit(0)
volume_is_amplified = src_settings.get_boolean(UBUNTU_VOLUME_AMPLIFIED_KEY)
dst_settings.set_boolean(GNOME_VOLUME_AMPLIFIED_KEY, volume_is_amplified)
dst_settings.sync()