~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to helper/dict-main-gtk.c

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2006-11-23 15:10:53 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061123151053-q42sk1lvks41xpfx
Tags: 1:1.2.1-9
uim-gtk2.0.postinst: Don't call update-gtk-immodules on purge.
(closes: Bug#398530)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
  Copyright (c) 2004 uim Project http://uim.freedesktop.org/
 
3
  Copyright (c) 2004-2006 uim Project http://uim.freedesktop.org/
4
4
 
5
5
  All rights reserved.
6
6
 
17
17
     may be used to endorse or promote products derived from this software
18
18
     without specific prior written permission.
19
19
 
20
 
  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 
20
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21
21
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
22
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
 
  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
23
  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24
24
  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
25
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
26
  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31
31
 
32
32
*/
33
33
 
 
34
#include <config.h>
 
35
 
34
36
#include <gtk/gtk.h>
35
37
 
36
38
#include <locale.h>
39
41
#include <errno.h>
40
42
#include <unistd.h>
41
43
 
42
 
#include <uim/uim.h>
43
 
#include <uim/uim-helper.h>
44
 
#include "uim/config.h"
45
 
#include "uim/gettext.h"
 
44
#include "uim.h"
 
45
#include "uim-helper.h"
 
46
#include "gettext.h"
46
47
 
47
48
#include "dict-word-win-gtk.h"
48
49
#include "dict-word-list-win-gtk.h"
 
50
#include "dict-word-list-view-gtk.h"
49
51
 
50
 
static int read_tag;
 
52
static unsigned int read_tag;
51
53
static int uim_fd;  /* file descriptor to connect helper message bus */
52
54
static int ae_mode; /* add mode or edit mode */
53
 
static int input_method;
 
55
static int g_startup_dictionary;
54
56
 
55
57
enum {
56
58
  MODE_EDIT,
58
60
  NR_MODE
59
61
};
60
62
 
61
 
/* should be implemeted as loadable module */
62
 
enum {
63
 
  IM_ANTHY,
64
 
  IM_CANNA,
65
 
  IM_SKK,
66
 
  IM_PRIME,
67
 
  NR_IM
68
 
};
69
 
 
70
63
static void
71
64
helper_disconnect_cb(void)
72
65
{
73
66
  uim_fd = -1;
74
 
  gdk_input_remove(read_tag);
 
67
  g_source_remove(read_tag);
75
68
}
76
69
 
77
 
static void
78
 
fd_read_cb(gpointer p, gint fd, GdkInputCondition c)
 
70
static gboolean
 
71
fd_read_cb(GIOChannel *channel, GIOCondition c, gpointer p)
79
72
{
80
73
  char *tmp;
81
 
  
 
74
  int fd = g_io_channel_unix_get_fd(channel);
 
75
 
82
76
  uim_helper_read_proc(fd);
83
77
  while ((tmp = uim_helper_get_message())) {
84
78
    /* parse_helper_str(tmp); */
85
79
    g_free(tmp);
86
80
    tmp = NULL;
87
81
  }
 
82
  return TRUE;
88
83
}
89
84
 
90
85
static void
91
86
check_helper_connection(void)
92
87
{
93
 
  if(uim_fd < 0) {
 
88
  if (uim_fd < 0) {
94
89
    uim_fd = uim_helper_init_client_fd(helper_disconnect_cb);
95
 
    if(uim_fd > 0)
96
 
      read_tag = gdk_input_add(uim_fd, (GdkInputCondition)GDK_INPUT_READ,
97
 
                               fd_read_cb, NULL);
 
90
    if (uim_fd > 0) {
 
91
      GIOChannel *channel;
 
92
      channel = g_io_channel_unix_new(uim_fd);
 
93
      read_tag = g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR,
 
94
                                fd_read_cb, NULL);
 
95
      g_io_channel_unref(channel);
 
96
    }
98
97
  }
99
98
}
100
99
 
108
107
static void
109
108
parse_arg(int argc, char *argv[])
110
109
{
111
 
  int ch, option_index;
 
110
  int ch;
112
111
 
113
112
  ae_mode = MODE_EDIT;
114
113
 
115
 
  while((ch = getopt(argc, argv, "aei:")) != -1)
 
114
  while ((ch = getopt(argc, argv, "aehi:")) != -1)
116
115
  {
117
 
    switch(ch) {
 
116
    switch (ch) {
118
117
    case 'a':
119
118
      ae_mode = MODE_ADD;
120
119
      break;
123
122
      break;
124
123
    case 'i':
125
124
      if (!strcmp(optarg, "anthy"))
126
 
        input_method = IM_ANTHY;
 
125
        g_startup_dictionary = DICT_ENUM_DICTIONARY_TYPE_ANTHY;
127
126
      else if (!strcmp(optarg, "canna"))
128
 
        input_method = IM_CANNA;
 
127
        g_startup_dictionary = DICT_ENUM_DICTIONARY_TYPE_CANNA;
129
128
      else if (!strcmp(optarg, "prime"))
130
 
        input_method = IM_PRIME;
 
129
        g_startup_dictionary = DICT_ENUM_DICTIONARY_TYPE_PRIME;
131
130
      else if (!strcmp(optarg, "skk"))
132
 
        input_method = IM_SKK;
 
131
        g_startup_dictionary = DICT_ENUM_DICTIONARY_TYPE_SKK;
133
132
      else
134
 
        input_method = IM_ANTHY;
 
133
        g_startup_dictionary = DICT_ENUM_DICTIONARY_TYPE_ANTHY;
 
134
      break;
 
135
    case 'h':
 
136
      fprintf(stderr, "Usage: uim-dict-gtk [OPTION...]\n");
 
137
      fprintf(stderr, "\n");
 
138
      fprintf(stderr, "Options:\n");
 
139
      fprintf(stderr, " -h            Show this help\n");
 
140
      fprintf(stderr, " -i [IM]       Open a dictionary for IM [anthy, canna]\n");
 
141
      fprintf(stderr, " -e            Start with editing mode (default)\n");
 
142
      fprintf(stderr, " -a            Start with adding mode\n");
 
143
      exit(1);
135
144
      break;
136
145
    default:
137
146
      ae_mode = MODE_EDIT;
138
 
      /* input_method = get_current_im(); */
 
147
      /* g_startup_dictionary = get_current_im(); */
139
148
    }
140
149
  }
141
150
 
149
158
  GtkWidget *window;
150
159
  uim_dict *dict;
151
160
 
152
 
  if(ae_mode == MODE_EDIT) {
153
 
    window = word_list_window_new();
 
161
  if (ae_mode == MODE_EDIT) {
 
162
    window = word_list_window_new(DICT_ENUM_DICTIONARY_TYPE_ANTHY);
 
163
    if (WORD_LIST_VIEW(WORD_LIST_WINDOW(window)->word_list)->dict == NULL)
 
164
      return NULL;
154
165
  } else {
155
166
    dict = uim_dict_open(N_("Anthy private dictionary"));
156
 
    window = word_window_new(WORD_WINDOW_MODE_ADD, dict);
157
 
    uim_dict_unref(dict);
158
 
  }
159
 
 
160
 
  gtk_widget_show(window);
161
 
 
162
 
  return window;
163
 
}
164
 
 
165
 
static void
166
 
window_destroy_cb(GtkWidget *widget, gpointer data)
 
167
    if (!dict)
 
168
      return NULL;
 
169
    window = word_window_new(WORD_WINDOW_MODE_ADD, dict);
 
170
  }
 
171
 
 
172
  gtk_widget_show(window);
 
173
 
 
174
  return window;
 
175
}
 
176
 
 
177
static GtkWidget *
 
178
create_window_canna(void)
 
179
{
 
180
  GtkWidget *window;
 
181
  uim_dict *dict;
 
182
 
 
183
  if (ae_mode == MODE_EDIT) {
 
184
    window = word_list_window_new(DICT_ENUM_DICTIONARY_TYPE_CANNA);
 
185
    if (WORD_LIST_VIEW(WORD_LIST_WINDOW(window)->word_list)->dict == NULL)
 
186
      return NULL;
 
187
  } else {
 
188
    dict = uim_dict_open(N_("Canna private dictionary"));
 
189
    if (!dict) {
 
190
            fprintf(stderr, "uim_dict_open() canna NULL\n");
 
191
      return NULL;
 
192
    }
 
193
    window = word_window_new(WORD_WINDOW_MODE_ADD, dict);
 
194
  }
 
195
 
 
196
  gtk_widget_show(window);
 
197
 
 
198
  return window;
 
199
}
 
200
 
 
201
 
 
202
void
 
203
dict_window_destroy_cb(GtkWidget *widget, gpointer data)
167
204
{
168
205
  gtk_main_quit();
169
206
}
173
210
{
174
211
  GtkWidget *window = NULL;
175
212
 
176
 
  switch(input_method) {
177
 
  case IM_ANTHY:
 
213
  switch (g_startup_dictionary) {
 
214
  case DICT_ENUM_DICTIONARY_TYPE_ANTHY:
178
215
    window = create_window_anthy();
179
216
    break;
180
 
  case IM_CANNA:
181
 
    /* window = create_window_canna(); */
182
 
    break;
183
 
  case IM_SKK:
 
217
  case DICT_ENUM_DICTIONARY_TYPE_CANNA:
 
218
    window = create_window_canna();
 
219
    break;
 
220
  case DICT_ENUM_DICTIONARY_TYPE_PRIME:
 
221
    /* create_window_prime();*/
 
222
    break;
 
223
  case DICT_ENUM_DICTIONARY_TYPE_SKK:
184
224
    /* create_window_skk();*/
185
225
    break;
186
 
  case IM_PRIME:
187
 
    /* create_window_prime();*/
188
 
    break;
189
226
  default:
190
227
    return -1;
191
228
  }
194
231
    return -1;
195
232
 
196
233
  g_signal_connect(G_OBJECT(window), "destroy",
197
 
                   G_CALLBACK(window_destroy_cb), NULL);
 
234
                   G_CALLBACK(dict_window_destroy_cb), NULL);
198
235
 
199
236
  return 0;
200
237
}
201
238
 
 
239
static void
 
240
setup_default_icon()
 
241
{
 
242
  GdkPixbuf *pixbuf;
 
243
 
 
244
  pixbuf = gdk_pixbuf_new_from_file(UIM_PIXMAPSDIR "/uim-dict.png", NULL);
 
245
  if (pixbuf) {
 
246
    GList *list;
 
247
 
 
248
    list = NULL;
 
249
    list = g_list_append(list, pixbuf);
 
250
    gtk_window_set_default_icon_list(list);
 
251
    g_list_free(list);
 
252
    g_object_unref(pixbuf);
 
253
  }
 
254
}
 
255
 
202
256
int
203
257
main(int argc, char *argv[])
204
 
{  
 
258
{
205
259
  gint result;
 
260
 
206
261
  setlocale(LC_ALL, "");
207
262
  gtk_set_locale();
208
263
  bindtextdomain(PACKAGE, LOCALEDIR);
209
264
  textdomain(PACKAGE);
210
 
  bind_textdomain_codeset(PACKAGE, "UTF-8"); 
 
265
  bind_textdomain_codeset(PACKAGE, "UTF-8");
211
266
  parse_arg(argc, argv);
212
267
 
213
268
  gtk_init(&argc, &argv);
 
269
  setup_default_icon();
214
270
 
215
271
  result = create_window();
216
272
 
217
 
  if(result == -1) {
 
273
  if (result == -1) {
218
274
    g_printerr(_("Error:%s\n"), get_error_msg());
219
 
    exit(-1);
 
275
    exit(EXIT_FAILURE);
220
276
  }
221
277
 
222
278
  /* connect to uim helper message bus */
223
279
  uim_fd = -1;
224
 
  check_helper_connection();  
 
280
  check_helper_connection();
225
281
 
226
282
  gtk_main ();
227
283