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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
|
/*
Copyright (c) 2004-2013 uim Project https://github.com/uim/uim
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of authors nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include <config.h>
#include <stdlib.h>
# include <gtk/gtk.h>
#if GTK_CHECK_VERSION(2, 90, 0)
# include <gdk/gdkkeysyms-compat.h>
#else
# include <gdk/gdkkeysyms.h>
#endif
#include "gettext.h"
#include "word.h"
#include "anthy.h"
#include "word-list-view-gtk.h"
#include "word-list-win-gtk.h"
#include "word-win-gtk.h"
static void word_list_window_class_init (WordListWindowClass *window);
static void word_list_window_init (WordListWindow *window);
static void word_list_window_dispose (GObject *object);
static void word_list_window_set_sensitive (WordListWindow *window);
/* call back functions for ui manager */
static void add_widget_cb (GtkUIManager *merge,
GtkWidget *widget,
GtkBox *box);
/* call back functions for actions */
static void file_exit_action_cb (GtkAction *action);
static void edit_add_word_action_cb (GtkAction *action,
WordListWindow *window);
static void edit_remove_word_action_cb (GtkAction *action,
WordListWindow *window);
static void edit_edit_word_action_cb (GtkAction *action,
WordListWindow *window);
static void popup_menu_action_cb (GtkAction *action,
WordListWindow *window);
static void help_about_action_cb (GtkAction *action,
WordListWindow *window);
static void activate_radio_action(GtkAction *action, GtkRadioAction *current,
gpointer data);
/* call back functions for WordListView */
static gboolean word_list_button_press_cb (GtkWidget *widget,
GdkEventButton *event,
WordListWindow *window);
static gboolean word_list_row_activated_cb(GtkWidget *widget,
GtkTreePath *path,
GtkTreeViewColumn *column,
WordListWindow *window);
static gboolean word_list_key_press_cb (GtkWidget *widget,
GdkEventKey *event,
WordListWindow *window);
static void word_list_selection_changed_cb (GtkTreeSelection *selection,
WordListWindow *window);
/* call back functions for WordWindow */
static void wordwin_response_cb (WordWindow *dialog,
WordListWindow *window);
static void dict_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static void dict_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
GtkWindowClass *parent_class = NULL;
GdkEventButton *current_button_event = NULL;
/* Main menu*/
GtkActionEntry menu_action_entries[] = {
{ "DictionaryMenu", NULL, N_("_Dictionary") },
{ "SelectMenu", NULL, N_("_Select") },
{ "EditMenu", NULL, N_("_Edit") },
{ "OptionMenu", NULL, N_("_Option") },
{ "HelpMenu", NULL, N_("_Help") },
{ "Quit", GTK_STOCK_QUIT, N_("_Quit"), "<control>Q",
N_("Quit uim-dict"), G_CALLBACK(file_exit_action_cb) },
{ "AddWord", GTK_STOCK_ADD, N_("A_dd..."), "<control>A",
N_("Add a new word"), G_CALLBACK(edit_add_word_action_cb) },
{ "RemoveWord", GTK_STOCK_REMOVE, N_("_Remove..."), "<control>D",
N_("Remove the selected word"), G_CALLBACK(edit_remove_word_action_cb) },
{ "EditWord", GTK_STOCK_DND, N_("_Edit..."), "<control>E",
N_("Edit the selected word"), G_CALLBACK(edit_edit_word_action_cb) },
{ "PopupMenu", NULL, N_("_Popup Menu"), NULL,
N_("Show popup menu"), G_CALLBACK(popup_menu_action_cb) },
{ "About", NULL, N_("_About"), NULL,
N_("About uim-dict"), G_CALLBACK(help_about_action_cb) },
};
static guint n_menu_action_entries = G_N_ELEMENTS(menu_action_entries);
static GtkRadioActionEntry dictionary_entries[] = {
{ "Anthy", NULL,
"_Anthy", NULL,
"Anthy private dictionary", DICT_ENUM_DICTIONARY_TYPE_ANTHY },
{ "Canna", NULL,
"_Canna", NULL,
"Canna private dictionary", DICT_ENUM_DICTIONARY_TYPE_CANNA },
};
static guint n_dictionary_entries = G_N_ELEMENTS(dictionary_entries);
#define ACTIVATE_ACTION(window, action_name) \
{ \
GtkAction *action; \
action = gtk_action_group_get_action((window)->action_group, (action_name)); \
if (action) { \
gtk_action_activate(action); \
} \
}
#define SET_ACTION_SENSITIVE(window, action_name, sensitive) \
{ \
GtkAction *action; \
action = gtk_action_group_get_action((window)->action_group, (action_name)); \
if (action) { \
g_object_set(action, \
"sensitive", (sensitive), \
NULL); \
} \
}
GType word_list_window_get_type(void) {
static GType type = 0;
if (type == 0) {
static const GTypeInfo info = {
sizeof(WordListWindowClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc)word_list_window_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(WordWindow),
0, /* n_preallocs */
(GInstanceInitFunc)word_list_window_init /* instance_init */
};
type = g_type_register_static(GTK_TYPE_WINDOW,
"WordListWindow", &info, 0);
}
return type;
}
GType
dict_enum_dictionary_type_get_type(void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
{ DICT_ENUM_DICTIONARY_TYPE_ANTHY, "DICT_ENUM_DICTIONARY_TYPE_ANTHY", "anthy" },
{ DICT_ENUM_DICTIONARY_TYPE_CANNA, "DICT_ENUM_DICTIONARY_TYPE_CANNA", "canna" },
{ DICT_ENUM_DICTIONARY_TYPE_SKK, "DICT_ENUM_DICTIONARY_TYPE_SKK", "skk" },
{ DICT_ENUM_DICTIONARY_TYPE_PRIME, "DICT_ENUM_DICTIONARY_TYPE_PRIME", "prime" },
{ DICT_ENUM_DICTIONARY_TYPE_UNKOWN, "DICT_ENUM_DICTIONARY_TYPE_UNKOWN", "unknown" },
{ 0, NULL, NULL }
};
etype = g_enum_register_static("DictEnumDictionaryType", values);
}
return etype;
}
static void
word_list_window_class_init (WordListWindowClass *klass)
{
GObjectClass *object_class;
parent_class = g_type_class_peek_parent(klass);
object_class = (GObjectClass *) klass;
object_class->dispose = word_list_window_dispose;
object_class->get_property = dict_get_property;
object_class->set_property = dict_set_property;
g_object_class_install_property(object_class,
PROP_DICTIONARY_TYPE,
g_param_spec_enum("dictionary-type",
_("dictionary type"),
_("dictionary type"),
DICT_TYPE_ENUM_DICTIONARY_TYPE,
DICT_ENUM_DICTIONARY_TYPE_ANTHY,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static gchar *
translate_func(const gchar *path, gpointer data)
{
return _(path);
}
static void
warn_dict_open()
{
GtkWidget *dialog;
const gchar *message;
message = N_("Couldn't open the dictionary.\n");
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_OK,
"%s", _(message));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
}
static void
word_list_window_init (WordListWindow *window)
{
GtkWidget *word_list, *vbox, *statusbar;
GtkUIManager *ui;
GtkActionGroup *actions;
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 600, 450);
gtk_window_set_title(GTK_WINDOW(window), _("Edit the dictionary"));
#if GTK_CHECK_VERSION(3, 2, 0)
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
#else
vbox = gtk_vbox_new(FALSE, 0);
#endif
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show(vbox);
window->action_group = actions = gtk_action_group_new("Actions");
#if ENABLE_NLS
gtk_action_group_set_translate_func(window->action_group,
translate_func, NULL, NULL);
#endif
gtk_action_group_add_actions(actions, menu_action_entries,
n_menu_action_entries, window);
gtk_action_group_add_radio_actions(actions, dictionary_entries,
n_dictionary_entries,
DICT_ENUM_DICTIONARY_TYPE_ANTHY,
G_CALLBACK(activate_radio_action),
window);
window->ui_manager = ui = gtk_ui_manager_new();
gtk_ui_manager_insert_action_group(ui, actions, 0);
g_signal_connect(ui, "add_widget",
G_CALLBACK(add_widget_cb),
vbox);
gtk_window_add_accel_group(GTK_WINDOW(window),
gtk_ui_manager_get_accel_group(ui));
gtk_ui_manager_add_ui_from_file(ui,
UIM_DATADIR "/helperdata/uim-dict-ui.xml",
NULL);
gtk_ui_manager_ensure_update(ui);
window->word_list = word_list = word_list_view_new();
word_list_view_set_visible_cclass_code_column(WORD_LIST_VIEW(word_list), TRUE);
word_list_view_set_visible_freq_column(WORD_LIST_VIEW(word_list), TRUE);
gtk_widget_show(word_list);
gtk_box_pack_start(GTK_BOX(vbox), word_list, TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN(window->word_list))),
"button-press-event",
G_CALLBACK(word_list_button_press_cb), window);
g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN(window->word_list))),
"row-activated",
G_CALLBACK(word_list_row_activated_cb), window);
g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN(window->word_list))),
"key-press-event",
G_CALLBACK(word_list_key_press_cb), window);
g_signal_connect(G_OBJECT(WORD_LIST_VIEW(window->word_list)->selection),
"changed",
G_CALLBACK(word_list_selection_changed_cb), window);
window->statusbar = statusbar = gtk_statusbar_new();
gtk_box_pack_start(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
gtk_widget_show(statusbar);
word_list_window_set_sensitive(window);
}
static void
word_list_window_dispose(GObject *object)
{
WordListWindow *window = WORD_LIST_WINDOW(object);
if (window->action_group) {
g_object_unref(window->action_group);
window->action_group = NULL;
}
if (window->ui_manager) {
g_object_unref(window->ui_manager);
window->ui_manager = NULL;
}
if (G_OBJECT_CLASS(parent_class)->dispose)
G_OBJECT_CLASS(parent_class)->dispose(object);
}
static void
dict_get_property(GObject *object, guint prop_id, GValue *value,
GParamSpec *pspec)
{
switch (prop_id) {
case PROP_DICTIONARY_TYPE:
g_value_set_enum(value, dict_get_dictionary_type(GTK_WIDGET(object)));
break;
default:
break;
}
}
static void
dict_set_property(GObject *object, guint prop_id, const GValue *value,
GParamSpec *pspec)
{
WordListWindow *window = WORD_LIST_WINDOW(object);
uim_dict *dict = NULL;
gchar message[128];
switch (prop_id) {
case PROP_DICTIONARY_TYPE:
window->dictionary_type = g_value_get_enum(value);
ACTIVATE_ACTION(window, dictionary_entries[window->dictionary_type].name);
switch (window->dictionary_type) {
case DICT_ENUM_DICTIONARY_TYPE_ANTHY:
dict = uim_dict_open(N_("Anthy private dictionary"));
break;
case DICT_ENUM_DICTIONARY_TYPE_CANNA:
word_list_view_set_visible_freq_column(WORD_LIST_VIEW(window->word_list), FALSE);
dict = uim_dict_open(N_("Canna private dictionary"));
break;
default:
break;
}
if (!dict) {
warn_dict_open();
break;
}
word_list_view_set_dict(WORD_LIST_VIEW(window->word_list), dict);
g_snprintf(message, sizeof(message), _("%s"), _(dict->identifier));
gtk_statusbar_push(GTK_STATUSBAR(window->statusbar), 0, _(dict->identifier));
break;
default:
break;
}
}
DictEnumDictionaryType
dict_get_dictionary_type(GtkWidget *window)
{
WordListWindow *w = (WordListWindow *)window;
return w->dictionary_type;
}
GtkWidget *word_list_window_new(int type)
{
return GTK_WIDGET(g_object_new(WORD_LIST_WINDOW_TYPE,
"dictionary-type", type, NULL));
}
static void
word_list_window_set_sensitive(WordListWindow *window)
{
gboolean selected;
WordListView *word_list;
GtkTreeSelection *selection;
word_list = WORD_LIST_VIEW(window->word_list);
selection = word_list->selection;
selected = gtk_tree_selection_get_selected(selection, NULL, NULL);
if (selected) {
SET_ACTION_SENSITIVE(window, "EditWord", TRUE);
SET_ACTION_SENSITIVE(window, "RemoveWord", TRUE);
} else {
SET_ACTION_SENSITIVE(window, "EditWord", FALSE);
SET_ACTION_SENSITIVE(window, "RemoveWord", FALSE);
}
}
/*
* call back functions for ui manager
*/
static void
add_widget_cb (GtkUIManager *merge, GtkWidget *widget, GtkBox *box)
{
gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
}
/*
* call back functions for actions
*/
static void
file_exit_action_cb(GtkAction *action)
{
gtk_main_quit();
}
static void
edit_add_word_action_cb(GtkAction *action, WordListWindow *window)
{
GtkWidget *w;
w = word_window_new(WORD_WINDOW_MODE_ADD,
WORD_LIST_VIEW(window->word_list)->dict);
gtk_grab_add(w);
gtk_window_set_transient_for(GTK_WINDOW(w), GTK_WINDOW(window));
gtk_window_set_position(GTK_WINDOW(w), GTK_WIN_POS_CENTER_ON_PARENT);
g_signal_connect(G_OBJECT(w), "word-added",
G_CALLBACK(wordwin_response_cb), window);
gtk_widget_show(w);
}
static void
remove_confirm_dialog_response_cb(GtkDialog *dialog, gint arg,
gboolean *ok)
{
g_return_if_fail(ok);
*ok = FALSE;
switch (arg)
{
case GTK_RESPONSE_OK:
*ok = TRUE;
break;
default:
break;
}
}
static void
edit_remove_word_action_cb(GtkAction *action, WordListWindow *window)
{
GtkWidget *dialog;
GList *node, *list;
gboolean ok = FALSE;
const gchar *message = _("Are you sure to remove seleted words?");
list = word_list_view_get_selected_data_list(WORD_LIST_VIEW(window->word_list));
if (!list) return;
if (!g_list_next(list))
message = _("Are you sure to remove the selected word?");
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_OK_CANCEL,
"%s", message);
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(window));
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);
g_signal_connect(G_OBJECT(dialog), "response",
G_CALLBACK(remove_confirm_dialog_response_cb), &ok);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
dialog = NULL;
if (!ok) return;
for (node = list; node; node = g_list_next(node)) {
uim_word *w = node->data;
int ret;
ret = uim_dict_remove_word(WORD_LIST_VIEW(window->word_list)->dict, w);
if (ret) {
word_list_view_refresh(WORD_LIST_VIEW(window->word_list));
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"%s", _("Word deletion succeeded."));
} else {
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"%s", _("Word deletion failed."));
}
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(window));
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
g_list_free(list);
}
static void
edit_edit_word_action_cb(GtkAction *action, WordListWindow *window)
{
GList *list;
list = word_list_view_get_selected_data_list(WORD_LIST_VIEW(window->word_list));
/* FIXME! it can edit only one word yet. */
if (list) {
GtkWidget *widget;
widget = word_window_new(WORD_WINDOW_MODE_EDIT,
WORD_LIST_VIEW(window->word_list)->dict);
gtk_grab_add(widget);
gtk_window_set_transient_for(GTK_WINDOW(widget), GTK_WINDOW(window));
gtk_window_set_position(GTK_WINDOW(widget), GTK_WIN_POS_CENTER_ON_PARENT);
word_window_set_word(WORD_WINDOW(widget), list->data);
g_signal_connect(G_OBJECT(widget), "word-added",
G_CALLBACK(wordwin_response_cb), window);
gtk_widget_show(widget);
}
g_list_free(list);
}
static void
popup_menu_action_cb(GtkAction *action, WordListWindow *window)
{
GtkWidget *popup_menu;
popup_menu = gtk_ui_manager_get_widget(window->ui_manager,
"/WordListPopup");
g_return_if_fail(popup_menu);
if (current_button_event) {
gtk_menu_popup(GTK_MENU(popup_menu),
NULL, NULL,
NULL, NULL,
current_button_event->button,
current_button_event->time);
} else {
gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL,
NULL, NULL, 0, GDK_CURRENT_TIME);
}
}
#if GTK_CHECK_VERSION(2, 6, 0) && !GTK_CHECK_VERSION(2, 18, 0)
static void
activate_url(GtkAboutDialog *about, const gchar *link, gpointer data)
{
/* g_print("show url %s\n", link); */
}
#endif
static void
help_about_action_cb(GtkAction *action, WordListWindow *window)
{
const gchar *name = N_("uim-dict");
#if GTK_CHECK_VERSION(2, 6, 0)
GdkPixbuf *pixbuf, *transparent;
const gchar *filename = UIM_PIXMAPSDIR "/uim-dict.png";
const gchar *authors[] = {
"Masahito Omote <omote@utyuuzin.net>",
"Takuro Ashie",
"Etsushi Kato",
NULL
};
const gchar *copyright = N_(
"Copyright (C) 2003-2004 Masahito Omote\n"
"Copyright (C) 2004-2013 uim Project\n"
"All rights reserved.");
transparent = NULL;
pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
if (pixbuf) {
transparent = gdk_pixbuf_add_alpha(pixbuf, TRUE, 0xff, 0xff, 0xff);
g_object_unref(pixbuf);
}
#if !GTK_CHECK_VERSION(2, 18, 0)
gtk_about_dialog_set_url_hook (activate_url, NULL, NULL);
#endif
gtk_show_about_dialog (GTK_WINDOW(window),
"name", name,
"version", VERSION,
"copyright", copyright,
"website", "https://github.com/uim/uim",
"authors", authors,
"logo", transparent,
NULL);
g_object_unref(transparent);
#else
GtkWidget *about_dialog, *label1;
const gchar *copyright = N_(
"Copyright 2003-2004 Masahito Omote <omote@utyuuzin.net>\n"
"Copyright 2004-2013 uim Project https://github.com/uim/uim\n"
"All rights reserved.");
gchar *about_name =
g_strdup_printf("<span size=\"20000\">%s %s </span>\n\n<span size=\"14000\">%s </span>\n", _(name), VERSION, _(copyright));
about_dialog = gtk_dialog_new_with_buttons(_("About uim-dict"), NULL,
GTK_DIALOG_MODAL,
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT, NULL);
gtk_container_set_border_width(GTK_CONTAINER(about_dialog), 8);
label1 = gtk_label_new(NULL);
gtk_widget_show(label1);
gtk_label_set_markup(GTK_LABEL(label1), about_name);
g_free(about_name);
gtk_box_pack_start(
GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(about_dialog))),
label1, FALSE, FALSE, 0);
gtk_window_set_transient_for(GTK_WINDOW(about_dialog),
GTK_WINDOW(window));
gtk_window_set_position(GTK_WINDOW(about_dialog),
GTK_WIN_POS_CENTER_ON_PARENT);
gtk_dialog_run(GTK_DIALOG(about_dialog));
gtk_widget_destroy(about_dialog);
#endif
}
static void
activate_radio_action(GtkAction *action, GtkRadioAction *current,
gpointer data)
{
WordListWindow *window;
gboolean active;
guint value;
window = WORD_LIST_WINDOW(data);
active = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(current));
value = gtk_radio_action_get_current_value(GTK_RADIO_ACTION(current));
if (active) {
if (value != window->dictionary_type) {
GtkWidget *newwin;
newwin = word_list_window_new(value);
/* quit */
if (WORD_LIST_VIEW(WORD_LIST_WINDOW(newwin)->word_list)->dict == NULL) {
gtk_main_quit();
}
g_signal_handlers_disconnect_by_func(G_OBJECT(window),
(gpointer)(uintptr_t)dict_window_destroy_cb,
NULL);
gtk_widget_destroy(GTK_WIDGET(window));
g_signal_connect(G_OBJECT(newwin), "destroy",
G_CALLBACK(dict_window_destroy_cb), NULL);
gtk_widget_show(newwin);
}
}
}
/*
* call back functions for WordListView
*/
static gboolean
word_list_button_press_cb(GtkWidget *widget, GdkEventButton *event,
WordListWindow *window)
{
if (event->button == 2 && event->type == GDK_BUTTON_PRESS) {
ACTIVATE_ACTION(window, "EditWord");
} else if (event->button == 3) {
current_button_event = event;
ACTIVATE_ACTION(window, "PopupMenu");
current_button_event = NULL;
}
return FALSE;
}
static gboolean
word_list_row_activated_cb(GtkWidget *widget, GtkTreePath *path,
GtkTreeViewColumn *column, WordListWindow *window)
{
ACTIVATE_ACTION(window, "EditWord");
return FALSE;
}
static gboolean
word_list_key_press_cb(GtkWidget *widget, GdkEventKey *event,
WordListWindow *window)
{
switch (event->keyval) {
case GDK_Delete:
case GDK_BackSpace:
ACTIVATE_ACTION(window, "RemoveWord");
break;
default:
break;
}
return FALSE;
}
static void
word_list_selection_changed_cb(GtkTreeSelection *selection,
WordListWindow *window)
{
word_list_window_set_sensitive(window);
}
/*
* call back functions for WordWindow
*/
static void
wordwin_response_cb(WordWindow *dialog, WordListWindow *window)
{
word_list_view_refresh(WORD_LIST_VIEW(window->word_list));
}
|