summaryrefslogtreecommitdiff
path: root/debian/patches/missing_files.patch
blob: 64ad9435e8d259b0b96782ba005e64ce3f921d21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
--- /dev/null
+++ b/keyman_config/get_info.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python3
+
+import os
+import threading
+from keyman_config.install_kmp import process_keyboard_data
+from keyman_config.kmpmetadata import parsemetadata
+
+class GetInfo(object):
+    """ Get information about kmp packages and keyboards
+    The run() method will be started and it will run in the background.
+    """
+
+    def __init__(self, kmp_list):
+        """ Constructor
+        :type kmp_list: list
+        :param kmp_list: List of keyboards to get info for
+        """
+        self.kmp_list = kmp_list
+
+        thread = threading.Thread(target=self.run, args=())
+        thread.daemon = True                            # Daemonize thread
+        thread.start()                                  # Start the execution
+
+    def run(self):
+        """ Method that gets info for installed kmp that were installed manually
+        rather then from the download window.
+        """
+        for kmp in self.kmp_list:
+            packageDir = os.path.join(kmp['areapath'], kmp['packageID'])
+            process_keyboard_data(kmp['packageID'], packageDir)
+            info, system, options, keyboards, files = parsemetadata(packageDir, "kmp.json")
+            if keyboards:
+                for kb in keyboards:
+                    if kb['id'] != kmp['packageID']:
+                        process_keyboard_data(kb['id'], packageDir)
\ No newline at end of file
--- /dev/null
+++ b/keyman_config/ibus_util.py
@@ -0,0 +1,99 @@
+#!/usr/bin/python3
+
+import gi
+import logging
+import subprocess
+
+gi.require_version('IBus', '1.0')
+from gi.repository import IBus, Gio
+
+def get_ibus_bus():
+    try:
+        for i in range(10000):
+            bus = IBus.Bus()
+            if bus.is_connected() and bus.is_global_engine_enabled():
+                return bus
+            bus.destroy()
+    except Exception as e:
+        logging.warning("Failed get bus")
+        logging.warning(e)
+    logging.warning("could not find connected IBus.Bus")
+    return None
+
+def install_to_ibus(bus, keyboard_id):
+    try:
+        # keyboard_id = "%s:%s" % (lang, kmx_file)
+        # logging.debug("getting bus")
+        # bus = IBus.Bus()
+        logging.debug("installing to ibus")
+        ibus_settings = Gio.Settings.new("org.freedesktop.ibus.general")
+        preload_engines = ibus_settings.get_strv("preload-engines")
+        logging.debug(preload_engines)
+        if keyboard_id not in preload_engines:
+            preload_engines.append(keyboard_id)
+        logging.debug(preload_engines)
+        ibus_settings.set_strv("preload-engines", preload_engines)
+        bus.preload_engines(preload_engines)
+    except Exception as e:
+        logging.warning("Failed to set up install %s to IBus", keyboard_id)
+        logging.warning(e)
+
+def uninstall_from_ibus(bus, keyboard_id):
+# need to uninstall for all installed langs
+    try:
+        # logging.debug("getting bus")
+        # bus = IBus.Bus()
+        ibus_settings = Gio.Settings.new("org.freedesktop.ibus.general")
+        preload_engines = ibus_settings.get_strv("preload-engines")
+        logging.debug(preload_engines)
+        if keyboard_id in preload_engines:
+            preload_engines.remove(keyboard_id)
+        logging.debug(preload_engines)
+        ibus_settings.set_strv("preload-engines", preload_engines)
+        bus.preload_engines(preload_engines)
+    except Exception as e:
+        logging.warning("Failed to uninstall keyboard %s", keyboard_id)
+        logging.warning(e)
+
+def restart_ibus_subp():
+    logging.info("restarting IBus by subprocess")
+    subprocess.run(["ibus", "restart"])
+
+def restart_ibus(bus=None):
+    try:
+        if not bus:
+            bus = get_ibus_bus()
+        logging.info("restarting IBus")
+        bus.exit(True)
+        bus.destroy()
+    except Exception as e:
+        logging.warning("Failed to restart IBus")
+        logging.warning(e)
+
+def bus_has_engine(bus, name):
+    engines = bus.get_engines_by_names([name])
+    return len(engines)
+
+def get_current_engine(bus):
+    try:
+        contextname = bus.current_input_context()
+        ic = IBus.InputContext.get_input_context(contextname, bus.get_connection())
+        engine = ic.get_engine()
+        if engine:
+            return engine.get_name()
+    except Exception as e:
+        logging.warning("Failed to get current engine")
+        logging.warning(e)
+
+
+def change_to_keyboard(bus, keyboard_id):
+    try:
+        contextname = bus.current_input_context()
+        ic = IBus.InputContext.get_input_context(contextname, bus.get_connection())
+        if bus_has_engine(bus, name) <= 0:
+            logging.warning("Could not find engine %s"%name)
+        else:
+            ic.set_engine(name)
+    except Exception as e:
+        logging.warning("Failed to change keyboard")
+        logging.warning(e)
--- a/keyman_config.egg-info/SOURCES.txt
+++ b/keyman_config.egg-info/SOURCES.txt
@@ -17,7 +17,9 @@
 keyman_config/check_mime_type.py
 keyman_config/convertico.py
 keyman_config/downloadkeyboard.py
+keyman_config/get_info.py
 keyman_config/get_kmp.py
+keyman_config/ibus_util.py
 keyman_config/install_kmp.py
 keyman_config/install_window.py
 keyman_config/keyboard_details.py
@@ -37,4 +39,4 @@
 keyman_config/icons/defaultpackage.gif
 keyman_config/icons/expand20.png
 keyman_config/icons/help20.png
-keyman_config/icons/icon_kmp.png
\ No newline at end of file
+keyman_config/icons/icon_kmp.png