~darkxst/gnome-control-center/lp1479907

« back to all changes in this revision

Viewing changes to debian/patches/ubuntu-region-packagekit.patch

  • Committer: Tim Lunn
  • Date: 2015-09-11 05:41:19 UTC
  • Revision ID: tim@feathertop.org-20150911054119-sycws24dml95oy6a
add the patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From: Tim Lunn <tim@feathertop.org>
 
2
Date: Fri, 11 Sep 2015 13:43:40 +1000
 
3
Subject: Provide an api for the installation of language packs
 
4
 
 
5
This adds cc_common_language_maybe_install() which uses
 
6
PackageKit WhatProvides locale() to locate and install
 
7
language packs for the selected language
 
8
---
 
9
 
 
10
diff --git a/panels/common/cc-common-language.c b/panels/common/cc-common-language.c
 
11
index f447698..a5b3e6c 100644
 
12
--- a/panels/common/cc-common-language.c
 
13
+++ b/panels/common/cc-common-language.c
 
14
@@ -425,3 +425,235 @@ cc_common_language_add_user_languages (GtkTreeModel *model)
 
15
         g_hash_table_destroy (user_langs);
 
16
 }
 
17
 
 
18
+typedef struct {
 
19
+        gchar *lang;
 
20
+        guint xid;
 
21
+        GDBusProxy *pk_proxy, *pk_transaction_proxy;
 
22
+        GPtrArray *array;
 
23
+} PkTransactionData;
 
24
+
 
25
+static void
 
26
+on_pk_what_provides_ready (GObject      *source,
 
27
+                           GAsyncResult *res,
 
28
+                           PkTransactionData *pk_data)
 
29
+{
 
30
+  GError     *error;
 
31
+  GVariant   *result;
 
32
+
 
33
+  error = NULL;
 
34
+  result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, &error);
 
35
+  if (result == NULL)
 
36
+    {
 
37
+      g_debug ("Error getting PackageKit updates list: %s", error->message);
 
38
+      g_error_free (error);
 
39
+      return;
 
40
+    }
 
41
+}
 
42
+
 
43
+static void
 
44
+cc_common_language_install (guint xid, gchar **packages) {
 
45
+
 
46
+  GDBusProxy *proxy = NULL;
 
47
+  GError *error = NULL;
 
48
+  GVariant *retval;
 
49
+
 
50
+  /* get a session bus proxy */
 
51
+  proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
 
52
+                 G_DBUS_PROXY_FLAGS_NONE, NULL,
 
53
+                 "org.freedesktop.PackageKit",
 
54
+                 "/org/freedesktop/PackageKit",
 
55
+                 "org.freedesktop.PackageKit.Modify",
 
56
+                 NULL, &error);
 
57
+  if (proxy == NULL) {
 
58
+    g_debug ("failed: %s", error->message);
 
59
+    g_error_free (error);
 
60
+    goto out;
 
61
+  }
 
62
+
 
63
+  /* issue the sync request */
 
64
+  retval = g_dbus_proxy_call_sync (proxy,
 
65
+                                   "InstallPackageNames",
 
66
+                                   g_variant_new ("(u^a&ss)",
 
67
+                                      xid,
 
68
+                                      packages,
 
69
+                                      "hide-finished"),
 
70
+                                   G_DBUS_CALL_FLAGS_NONE,
 
71
+                                   -1, /* timeout */
 
72
+                                   NULL, /* cancellable */
 
73
+                                   &error);
 
74
+  if (retval == NULL) {
 
75
+    g_debug ("failed: %s", error->message);
 
76
+    g_error_free (error);
 
77
+    goto out;
 
78
+  }
 
79
+  g_object_unref (retval);
 
80
+
 
81
+out:
 
82
+  if (proxy != NULL)
 
83
+    g_object_unref (proxy);
 
84
+  return;
 
85
+}
 
86
+
 
87
+static void
 
88
+on_pk_transaction_signal (GDBusProxy *proxy,
 
89
+                          char *sender_name,
 
90
+                          char *signal_name,
 
91
+                          GVariant *parameters,
 
92
+                          PkTransactionData *pk_data)
 
93
+{
 
94
+  if (g_strcmp0 (signal_name, "Package") == 0) {
 
95
+    gchar *package, *unused;
 
96
+    guint32 status;
 
97
+    gchar **split;
 
98
+
 
99
+    g_variant_get (parameters, "(u&s&s)", &status, &package, &unused);
 
100
+
 
101
+    if (status == 2) { /*PK_INFO_ENUM_AVAILABLE*/
 
102
+      split = g_strsplit(package, ";", -1);
 
103
+      g_ptr_array_add (pk_data->array, g_strdup (split[0]));
 
104
+
 
105
+      g_strfreev(split);
 
106
+    }
 
107
+  } else if (!g_strcmp0 (signal_name, "Finished")) {
 
108
+    char **lang;
 
109
+
 
110
+    g_ptr_array_add (pk_data->array, NULL);
 
111
+
 
112
+    lang = (char **) g_ptr_array_free (pk_data->array, FALSE);
 
113
+    /* Now install all packages returned by the previous call */
 
114
+    if (lang[0] != NULL)
 
115
+      cc_common_language_install(pk_data->xid, lang);
 
116
+
 
117
+    g_strfreev(lang);
 
118
+
 
119
+  } else if (g_strcmp0 (signal_name, "Destroy") == 0) {
 
120
+      g_free (pk_data->lang);
 
121
+      g_clear_object (&pk_data->pk_transaction_proxy);
 
122
+      g_clear_object (&pk_data->pk_proxy);
 
123
+  }
 
124
+}
 
125
+
 
126
+static void
 
127
+on_pk_get_tid_ready (GObject      *source,
 
128
+                     GAsyncResult *res,
 
129
+                     PkTransactionData *pk_data)
 
130
+
 
131
+{
 
132
+  GError     *error;
 
133
+  GVariant   *result;
 
134
+  char       *tid;
 
135
+
 
136
+  const gchar * provides_args[] = { g_strdup_printf ("locale(%s)",pk_data->lang), NULL };
 
137
+  error = NULL;
 
138
+  result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, &error);
 
139
+  if (result == NULL)
 
140
+    {
 
141
+      if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN) == FALSE)
 
142
+        g_debug ("Error getting PackageKit transaction ID: %s", error->message);
 
143
+        g_error_free (error);
 
144
+      return;
 
145
+    }
 
146
+
 
147
+  g_variant_get (result, "(o)", &tid);
 
148
+
 
149
+  pk_data->pk_transaction_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
 
150
+                                                                 G_DBUS_PROXY_FLAGS_NONE,
 
151
+                                                                 NULL,
 
152
+                                                                 "org.freedesktop.PackageKit",
 
153
+                                                                 tid,
 
154
+                                                                 "org.freedesktop.PackageKit.Transaction",
 
155
+                                                                 NULL,
 
156
+                                                                 NULL);
 
157
+  g_free (tid);
 
158
+  g_variant_unref (result);
 
159
+
 
160
+  if (pk_data->pk_transaction_proxy == NULL)
 
161
+    {
 
162
+      g_debug ("Unable to get PackageKit transaction proxy object");
 
163
+      return;
 
164
+    }
 
165
+
 
166
+  g_signal_connect (pk_data->pk_transaction_proxy,
 
167
+                    "g-signal",
 
168
+                    G_CALLBACK (on_pk_transaction_signal),
 
169
+                    pk_data);
 
170
+
 
171
+  g_dbus_proxy_call (pk_data->pk_transaction_proxy,
 
172
+                     "WhatProvides",
 
173
+                     /* TODO need to get enums from libpackagekit-glib2 */
 
174
+                     g_variant_new ("(tu^a&s)",
 
175
+                                    1, /*PK_FILTER_ENUM_NONE*/
 
176
+                                    11, /*PK_PROVIDES_ENUM_LANGUAGE_SUPPORT*/
 
177
+                                    provides_args),
 
178
+                     G_DBUS_CALL_FLAGS_NONE,
 
179
+                     -1,
 
180
+                     NULL,
 
181
+                     (GAsyncReadyCallback) on_pk_what_provides_ready,
 
182
+                     pk_data);
 
183
+}
 
184
+
 
185
+gboolean
 
186
+cc_common_language_maybe_install (guint xid, const gchar *lang)
 
187
+{
 
188
+        gchar *language_code, *territory_code, *territory_lang = NULL;
 
189
+        gchar **langs;
 
190
+        gboolean result = FALSE;
 
191
+        int i;
 
192
+        PkTransactionData *pk_data = NULL;
 
193
+
 
194
+        gnome_parse_locale (lang, &language_code, &territory_code, NULL, NULL);
 
195
+
 
196
+        /* If the language is already available, do nothing */
 
197
+        territory_lang = g_strdup_printf ("%s_%s", language_code, territory_code);
 
198
+
 
199
+        langs = cc_common_language_get_installed_languages();
 
200
+        for (i = 0; langs[i]; i++) {
 
201
+                if (g_strcmp0 (langs[i], territory_lang) ==0 ) {
 
202
+                       g_warning ("Language is already installed");
 
203
+                       result = TRUE;
 
204
+                       goto out;
 
205
+                }
 
206
+         }
 
207
+
 
208
+        g_warning ("Language %s not installed, trying to intall it", lang);
 
209
+
 
210
+        pk_data = g_new0 (PkTransactionData, 1);
 
211
+        pk_data->lang = g_strdup (lang);
 
212
+        pk_data->array = g_ptr_array_new ();
 
213
+        pk_data->xid = xid;
 
214
+
 
215
+        /* Now try to retrieve the list of packages needed to install this language */
 
216
+        pk_data->pk_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
 
217
+                                                           G_DBUS_PROXY_FLAGS_NONE,
 
218
+                                                           NULL,
 
219
+                                                           "org.freedesktop.PackageKit",
 
220
+                                                           "/org/freedesktop/PackageKit",
 
221
+                                                           "org.freedesktop.PackageKit",
 
222
+                                                           NULL,
 
223
+                                                           NULL);
 
224
+        if (pk_data->pk_proxy == NULL) {
 
225
+                /* if there's a PK error, ignore and assume the lang is available */
 
226
+                g_debug ("PackageKit not available, not installing language");
 
227
+                goto out;
 
228
+        }
 
229
+
 
230
+
 
231
+
 
232
+        /* Retrieve PK transaction */
 
233
+        g_dbus_proxy_call  (pk_data->pk_proxy,
 
234
+                            "CreateTransaction",
 
235
+                            NULL,
 
236
+                            G_DBUS_CALL_FLAGS_NONE,
 
237
+                            -1,
 
238
+                            NULL,
 
239
+                            (GAsyncReadyCallback) on_pk_get_tid_ready,
 
240
+                            pk_data);
 
241
+
 
242
+out:
 
243
+        g_free (language_code);
 
244
+        g_free (territory_code);
 
245
+        g_free (territory_lang);
 
246
+        g_strfreev (langs);
 
247
+
 
248
+        return result;
 
249
+}
 
250
diff --git a/panels/common/cc-common-language.h b/panels/common/cc-common-language.h
 
251
index 8ebd723..31ed19d 100644
 
252
--- a/panels/common/cc-common-language.h
 
253
+++ b/panels/common/cc-common-language.h
 
254
@@ -51,6 +51,8 @@ GHashTable *cc_common_language_get_initial_languages   (void);
 
255
 GHashTable *cc_common_language_get_user_languages      (void);
 
256
 GHashTable *cc_common_language_get_initial_regions     (const gchar *lang);
 
257
 
 
258
+gboolean cc_common_language_maybe_install           (guint32 xid,  const gchar *lang);
 
259
+
 
260
 void     cc_common_language_setup_list              (GtkWidget    *treeview,
 
261
                                                     GHashTable   *users,
 
262
                                                     GHashTable   *initial);
 
263
-- 
 
264
2.5.0
 
265