~ubuntu-branches/ubuntu/precise/uim/precise

« back to all changes in this revision

Viewing changes to helper/im-switcher-gtk.c

  • Committer: Package Import Robot
  • Author(s): Ilya Barygin
  • Date: 2011-12-18 16:35:38 UTC
  • mfrom: (1.1.13) (15.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20111218163538-8ktir39z2mjpii8z
Tags: 1:1.7.1-3ubuntu1
* Merge from Debian testing (LP: #818199).
* Remaining changes:
  - debian/uim-qt.install: Fix plugin path for multiarch location.
* Dropped changes:
  - uim-applet-gnome removal (GNOME 3 applet is available)
  - 19_as-needed_compile_fix.dpatch (accepted into Debian package)
* translations.patch: add several files to POTFILE.in to prevent
  intltool-update failure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
  Copyright (c) 2004-2009 uim Project http://code.google.com/p/uim/
 
3
  Copyright (c) 2004-2011 uim Project http://code.google.com/p/uim/
4
4
 
5
5
  All rights reserved.
6
6
 
43
43
 
44
44
#include <uim/uim.h>
45
45
#include <uim/uim-helper.h>
 
46
#include <uim/uim-custom.h>
 
47
#include <uim/uim-scm.h>
46
48
#include "uim/gettext.h"
47
49
 
48
50
 
50
52
static int uim_fd; /* file descriptor to connect helper message bus */
51
53
static gchar *im_list_str_old; /* To compare new im_list_str */
52
54
static GtkWidget *switcher_tree_view;
 
55
static int custom_enabled;
53
56
 
54
57
static gboolean
55
58
reload_im_list(GtkWindow *window, gpointer user_data);
193
196
{
194
197
  GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(switcher_tree_view));
195
198
  GtkTreeModel *model;
196
 
  GtkTreeStore *store;
197
199
  GtkTreeIter iter;
198
200
  gchar *str_data;
199
201
  if (gtk_tree_selection_get_selected (sel, &model, &iter) == TRUE) {
200
 
    store = GTK_TREE_STORE(model);
201
202
    gtk_tree_model_get (model, &iter,
202
203
                        NAME_COLUMN, &str_data,
203
204
                        -1);
236
237
}
237
238
 
238
239
static void
 
240
save_default_im()
 
241
{
 
242
  if (custom_enabled) {
 
243
    gchar *im_name = get_selected_im_name();
 
244
 
 
245
    uim_scm_callf("custom-set-value!",
 
246
                  "yy",
 
247
                  "custom-preserved-default-im-name",
 
248
                  im_name);
 
249
    uim_custom_save_custom("custom-preserved-default-im-name");
 
250
    g_free(im_name);
 
251
  }
 
252
}
 
253
 
 
254
static void
239
255
change_input_method(GtkButton *button, gpointer user_data)
240
256
{
241
257
  switch (coverage) {
242
258
  case IMSW_COVERAGE_WHOLE_DESKTOP:
243
259
    send_message_im_change("im_change_whole_desktop\n");
 
260
    save_default_im();
244
261
    break;
245
262
  case IMSW_COVERAGE_THIS_APPLICATION_ONLY:
246
263
    send_message_im_change("im_change_this_application_only\n");
249
266
    send_message_im_change("im_change_this_text_area_only\n");
250
267
    break;
251
268
  }
 
269
}
 
270
 
 
271
static void
 
272
change_input_method_and_quit(GtkButton *button, gpointer user_data)
 
273
{
 
274
  change_input_method(button, user_data);
252
275
  gtk_main_quit();
253
276
}
254
277
 
283
306
  column = gtk_tree_view_column_new_with_attributes(_("InputMethodName"),
284
307
                                                    renderer,
285
308
                                                    "text", NAME_COLUMN,
286
 
                                                    NULL);
 
309
                                                    (const gchar *)NULL);
287
310
  gtk_tree_view_column_set_sort_column_id(column, 0);
288
311
  gtk_tree_view_append_column(GTK_TREE_VIEW(switcher_tree_view), column);
289
312
 
292
315
  column = gtk_tree_view_column_new_with_attributes(_("Language"),
293
316
                                                    renderer,
294
317
                                                    "text", LANG_COLUMN,
295
 
                                                    NULL);
 
318
                                                    (const gchar *)NULL);
296
319
  gtk_tree_view_column_set_sort_column_id(column, 1);
297
320
  gtk_tree_view_append_column(GTK_TREE_VIEW(switcher_tree_view), column);
298
321
 
301
324
  column = gtk_tree_view_column_new_with_attributes(_("Description"),
302
325
                                                    renderer,
303
326
                                                    "text", DESC_COLUMN,
304
 
                                                    NULL);
 
327
                                                    (const gchar *)NULL);
305
328
  gtk_tree_view_column_set_sort_column_id(column, 2);
306
329
  gtk_tree_view_append_column(GTK_TREE_VIEW(switcher_tree_view), column);
307
330
 
385
408
  gtk_button_box_set_layout(GTK_BUTTON_BOX(setting_button_box), GTK_BUTTONBOX_END);
386
409
  gtk_box_set_spacing(GTK_BOX(setting_button_box), 8);
387
410
 
 
411
  /* Apply button */
 
412
  button = gtk_button_new_from_stock(GTK_STOCK_APPLY);
 
413
  g_signal_connect(G_OBJECT(button), "clicked",
 
414
                   G_CALLBACK(change_input_method), NULL);
 
415
  gtk_box_pack_start(GTK_BOX(setting_button_box), button, TRUE, TRUE, 2);
 
416
 
388
417
  /* Cancel button */
389
 
  button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
 
418
  button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
390
419
  g_signal_connect(G_OBJECT(button), "clicked",
391
420
                   G_CALLBACK(gtk_main_quit), NULL);
392
421
  gtk_box_pack_start(GTK_BOX(setting_button_box), button, TRUE, TRUE, 2);
394
423
  /* OK button */
395
424
  button = gtk_button_new_from_stock(GTK_STOCK_OK);
396
425
  g_signal_connect(G_OBJECT(button), "clicked",
397
 
                   G_CALLBACK(change_input_method), NULL);
 
426
                   G_CALLBACK(change_input_method_and_quit), NULL);
398
427
  gtk_box_pack_start(GTK_BOX(setting_button_box), button, TRUE, TRUE, 2);
399
428
 
400
429
  gtk_box_pack_start(GTK_BOX(vbox3), setting_button_box, FALSE, FALSE, 8);
430
459
{
431
460
  if (g_str_has_prefix(sent_str, "im_list") == TRUE) {
432
461
    parse_helper_str_im_list(sent_str);
 
462
  } else if (g_str_has_prefix(sent_str, "im_switcher_start") == TRUE) {
 
463
    uim_helper_send_message(uim_fd, "im_switcher_quit\n"); 
 
464
  } else if (g_str_has_prefix(sent_str, "im_switcher_quit") == TRUE) {
 
465
    gtk_main_quit();
433
466
  }
434
467
}
435
468
 
537
570
{
538
571
  gint result;
539
572
  setlocale(LC_ALL, "");
540
 
  gtk_set_locale();
541
573
  bindtextdomain( PACKAGE, LOCALEDIR );
542
574
  textdomain( PACKAGE );
543
575
  bind_textdomain_codeset( PACKAGE, "UTF-8");
544
576
  parse_arg(argc, argv);
545
577
 
 
578
  /* connect to uim helper message bus */
 
579
  uim_fd = -1;
 
580
  check_helper_connection();
 
581
 
 
582
  /* To check if another uim-im-switcher exists */
 
583
  uim_helper_send_message(uim_fd, "im_switcher_start\n"); 
 
584
 
 
585
  /* To load input method list */
 
586
  uim_helper_send_message(uim_fd, "im_list_get\n");
 
587
 
546
588
  gtk_init(&argc, &argv);
547
589
 
 
590
  if (uim_init() < 0) {
 
591
    fprintf(stderr, "uim_init() failed.\n");
 
592
    exit(EXIT_FAILURE);
 
593
  }
 
594
  custom_enabled = uim_custom_enable();
 
595
 
548
596
  result = create_switcher();
549
597
 
550
598
  if (result == -1) {
552
600
    exit(EXIT_FAILURE);
553
601
  }
554
602
 
555
 
  /* connect to uim helper message bus */
556
 
  uim_fd = -1;
557
 
  check_helper_connection();
558
 
 
559
 
  /* To load input method list */
560
 
  uim_helper_send_message(uim_fd, "im_list_get\n");
561
 
 
562
603
  load_configration(NULL);
563
604
  gtk_main ();
564
605
  return 0;