Exemplo n.º 1
0
void XimServer::customContext(const char *custom, const char *val) {
    std::list<InputContext *>::iterator it;
    for (it = ic_list.begin(); it != ic_list.end(); ++it) {
	(*it)->customContext(custom, val);
	break;
    }

    // Updated global IM of XimServer
    if (!strcmp(custom, "custom-preserved-default-im-name") &&
	uim_scm_symbol_value_bool("custom-activate-default-im-name?"))
	set_im(++val);

#if HAVE_XFT_UTF8_STRING
    if (!strcmp(custom, "uim-xim-xft-font-name"))
	update_default_xftfont();
#endif

    if (!strcmp(custom, "bridge-show-input-state?") &&
	!uim_scm_symbol_value_bool("bridge-show-input-state?")) {
	Canddisp *disp = canddisp_singleton();
	disp->hide_caret_state();
    }

    if (!strcmp(custom, "candidate-window-position"))
	check_candwin_pos_type();

    if (!strcmp(custom, "candidate-window-style"))
	check_candwin_style();
}
Exemplo n.º 2
0
Arquivo: curl.c Projeto: NgoHuy/uim
static CURLcode
uim_curl_perform(CURL *curl)
{
  uim_bool use_proxy;
  char *ua;
  char *referer;
  char *http_proxy;
  CURLcode res;

  ua = uim_scm_symbol_value_str("uim-curl-user-agent");
  referer = uim_scm_symbol_value_str("uim-curl-referer");
  use_proxy = uim_scm_symbol_value_bool("uim-curl-use-proxy?");
  http_proxy = uim_scm_symbol_value_str("uim-curl-http-proxy");

  curl_easy_setopt(curl, CURLOPT_USERAGENT,
		   (ua != NULL) ? ua : "libcurl-agent/1.0");
  curl_easy_setopt(curl, CURLOPT_REFERER,
		   (referer != NULL) ? referer : "");
  if (use_proxy) {
    curl_easy_setopt(curl, CURLOPT_PROXY,
		     (http_proxy != NULL) ? http_proxy : "");
  }

  res = curl_easy_perform(curl);

  free(ua);
  free(referer);
  free(http_proxy);

  return res;
}
Exemplo n.º 3
0
void XimServer::reloadConfigs() {
#if 1
    uim_prop_reload_configs();
    reload_uim(0);
#else
    reload_uim(1);
#endif

    // Updated global IM of XimServer
    char *im = uim_scm_symbol_value_str("default-im-name");
    if (im)
	set_im(im);
    free(im);

#if HAVE_XFT_UTF8_STRING
    update_default_xftfont();
#endif

    if (!uim_scm_symbol_value_bool("bridge-show-input-state?")) {
	Canddisp *disp = canddisp_singleton();
	disp->hide_caret_state();
    }

    check_candwin_style();
    check_candwin_pos_type();
}
Exemplo n.º 4
0
void InputContext::update_prop_list(const char *str)
{
    char *buf;

    if (asprintf(&buf, "prop_list_update\ncharset=UTF-8\n%s", str) == -1) {
        free(buf);
        return;
    }
    uim_helper_send_message(lib_uim_fd, buf);
    free(buf);

#if 1
    // Show caret state indicator with this function instead of
    // InputContext::update_prop_label() to workaround the label
    // mismatch during IM switch caused from context-update-widgets.
    uim_bool show_caret_state =
	uim_scm_symbol_value_bool("bridge-show-input-state?");
    char *show_caret_with =
	uim_scm_c_symbol(uim_scm_symbol_value("bridge-show-with?"));
    uim_bool show_caret_mode = (strcmp(show_caret_with, "mode") == 0);
    uim_bool show_caret_mode_on = uim_scm_symbol_value_bool("bridge-show-input-state-mode-on?");

    if (show_caret_state == UIM_TRUE && !(show_caret_mode && !show_caret_mode_on)) {
	char *label;
	int timeout;
	Canddisp *disp = canddisp_singleton();

	if (strcmp(show_caret_with, "time") == 0)
	    timeout = static_cast<int>(uim_scm_symbol_value_int(
				    "bridge-show-input-state-time-length"));
	else
	    timeout = 0;

	label = get_caret_state_label_from_prop_list(str);
	disp->show_caret_state(label, timeout);
	free(label);
	mCaretStateShown = true;
    } else if (show_caret_mode && !show_caret_mode_on) {
	Canddisp *disp = canddisp_singleton();
	disp->hide_caret_state();
    }
    free(show_caret_with);
#endif
}
Exemplo n.º 5
0
static GtkWidget *
toolbar_new(gint type)
{
    GtkWidget *button;
    GtkWidget *hbox;
    GList *prop_buttons = NULL;
    GtkSizeGroup *sg;

    /*
     * Set uim-toolbar-save-default-im? #t in ~/.uim enable this if you'd like to
     * save default IM into ~/.uim.d/custom/custom-global.scm upon system global
     * IM switch.  However, using uim-custom consumes quite amount of memory, and
     * requires additional startup time.
     */
    if (uim_scm_symbol_value_bool("uim-toolbar-save-default-im?"))
        custom_enabled = (gboolean)uim_custom_enable();

    helper_toolbar_check_custom();
    init_icon();

    /* create widgets */
#if GTK_CHECK_VERSION(3, 2, 0)
    hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#else
    hbox = gtk_hbox_new(FALSE, 0);
#endif

    im_menu = gtk_menu_new();
    prop_menu = gtk_menu_new();
    right_click_menu = right_click_menu_create();
    sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);

    /* prop menu button */
    button = button_create(hbox, sg, "uim-icon", " x", type);

    gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);

    prop_buttons = g_list_append(prop_buttons, button);

    g_object_set_data(G_OBJECT(hbox), OBJECT_DATA_PROP_BUTTONS, prop_buttons);
    g_object_set_data(G_OBJECT(hbox), OBJECT_DATA_SIZE_GROUP, sg);
    g_object_set_data(G_OBJECT(hbox), OBJECT_DATA_TOOLBAR_TYPE,
                      GINT_TO_POINTER(type));

    uim_fd = -1;

    if (type != TYPE_ICON) {
        /* delay initialization until getting "embedded" signal */
        uim_toolbar_check_helper_connection(hbox);
        uim_helper_client_get_prop_list();
        uim_toolbar_get_im_list();
    }

    return hbox;
}
Exemplo n.º 6
0
void QUimHelperToolbar::addExecHelpButton()
{
    uim_bool isShowHelp = uim_scm_symbol_value_bool("toolbar-show-help-button?");
    if( isShowHelp == UIM_FALSE )
        return;

    QToolButton *helpButton = new QHelperToolbarButton( this );
    m_layout->addWidget( helpButton );
    if( !m_helpicon.isNull() )
        helpButton->setIcon( QIcon( m_helpicon ) );
    else
        helpButton->setText( "Help" );

    connect( helpButton, SIGNAL( clicked() ),
                      this, SLOT( slotExecHelp() ) );
    helpButton->setToolTip( _( "Help" ) );
    ++m_nr_exec_buttons;
}
Exemplo n.º 7
0
void QUimHelperToolbar::addExecHandwritingInputPadButton()
{
    uim_bool isShowHandwritingInputPad = uim_scm_symbol_value_bool("toolbar-show-handwriting-input-pad-button?");
    if( isShowHandwritingInputPad == UIM_FALSE )
        return;

    QToolButton *handwritingButton = new QHelperToolbarButton( this );
    m_layout->addWidget( handwritingButton );
    if( !m_handicon.isNull() )
        handwritingButton->setIcon( QIcon( m_handicon ) );
    else
        handwritingButton->setText( "Hand" );

    connect( handwritingButton, SIGNAL( clicked() ),
                      this, SLOT( slotExecHandwritingInputPad() ) );
    handwritingButton->setToolTip( _( "Handwriting input pad" ) );
    ++m_nr_exec_buttons;
}
Exemplo n.º 8
0
void QUimHelperToolbar::addExecDictButton()
{
    uim_bool isShowDict = uim_scm_symbol_value_bool("toolbar-show-dict-button?");
    if( isShowDict == UIM_FALSE )
        return;

    QToolButton *dictButton = new QHelperToolbarButton( this );
    m_layout->addWidget( dictButton );
    if( !m_dicticon.isNull() )
        dictButton->setIcon( QIcon( m_dicticon ) );
    else
        dictButton->setText( "Dic" );

    connect( dictButton, SIGNAL( clicked() ),
                      this, SLOT( slotExecDict() ) );
    dictButton->setToolTip( _( "Japanese dictionary editor" ) );
    ++m_nr_exec_buttons;
}
Exemplo n.º 9
0
void QUimHelperToolbar::addExecPrefButton()
{
    uim_bool isShowPref = uim_scm_symbol_value_bool("toolbar-show-pref-button?");
    if( isShowPref == UIM_FALSE )
        return;
    
    QToolButton * prefButton = new QHelperToolbarButton( this );
    m_layout->addWidget( prefButton );
    if( !m_preficon.isNull() )
        prefButton->setIcon( QIcon( m_preficon ) );
    else
        prefButton->setText( "Pref" );

    connect( prefButton, SIGNAL( clicked() ),
                      this, SLOT( slotExecPref() ) );
    prefButton->setToolTip( _( "Preference" ) );
    ++m_nr_exec_buttons;
}
Exemplo n.º 10
0
void QUimHelperToolbar::addExecImSwitcherButton()
{
    uim_bool isShowSwitcher = uim_scm_symbol_value_bool("toolbar-show-switcher-button?");
    if( isShowSwitcher == UIM_FALSE )
        return;

    QToolButton * swButton = new QHelperToolbarButton( this );
    m_layout->addWidget( swButton );
    if( !m_swicon.isNull() )
        swButton->setIcon( QIcon( m_swicon ) );
    else
        swButton->setText( "Sw" );

    connect( swButton, SIGNAL( clicked() ),
                      this, SLOT( slotExecImSwitcher() ) );
    swButton->setToolTip( _( "Switch input method" ) );
    ++m_nr_exec_buttons;
}
Exemplo n.º 11
0
Arquivo: gtk.c Projeto: NgoHuy/uim
static gboolean
check_dot_uim_file(void)
{
  GString *dot_uim;
  GtkWidget *dialog;
  const gchar *message =
    N_("The user customize file \"~/.uim\" is found.\n"
       "This file will override all conflicted settings set by\n"
       "this tool (stored in ~/.uim.d/customs/*.scm).\n"
       "Please check the file if you find your settings aren't applied.\n\n"
       "(To suppress this dialog, add following line to ~/.uim)\n"
       "(define uim-pref-suppress-dot-uim-warning-dialog? #t)");
  uim_bool suppress_dialog;

  suppress_dialog = uim_scm_symbol_value_bool("uim-pref-suppress-dot-uim-warning-dialog?");
  if (suppress_dialog) {
    return FALSE;
  }

  dot_uim = g_string_new(g_get_home_dir());
  g_string_append(dot_uim, "/.uim");

  if (!g_file_test(dot_uim->str, G_FILE_TEST_EXISTS)) {
    g_string_free(dot_uim, TRUE);
    return FALSE;
  }
  g_string_free(dot_uim, TRUE);

  dialog = gtk_message_dialog_new(NULL,
				  GTK_DIALOG_MODAL,
				  GTK_MESSAGE_WARNING,
				  GTK_BUTTONS_OK,
				  "%s", _(message));
  if (pref_window) {
    gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(pref_window));
    gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);
  }

  gtk_dialog_run(GTK_DIALOG(dialog));
  gtk_widget_destroy(GTK_WIDGET(dialog));

  return FALSE;
}
Exemplo n.º 12
0
void InputContext::update_prop_label(const char *str)
{
    char *buf;

    if (asprintf(&buf, "prop_label_update\ncharset=UTF-8\n%s", str) == -1) {
        free(buf);
        return;
    }
    uim_helper_send_message(lib_uim_fd, buf);
    free(buf);
#if 0    
    uim_bool show_caret_state = uim_scm_symbol_value_bool("bridge-show-input-state?");
    if (show_caret_state == UIM_TRUE) {
	int timeout = uim_scm_symbol_value_int("bridge-show-input-state-time-length");
	Canddisp *disp = canddisp_singleton();
	disp->show_caret_state(str, timeout);
	mCaretStateShown = true;
    }
#endif
}
Exemplo n.º 13
0
static void
helper_toolbar_prop_list_update(GtkWidget *widget, gchar **lines)
{
    GtkWidget *button = NULL;
    guint i;
    gchar **cols;
    gchar *charset;
    const gchar *indication_id, *iconic_label, *label, *tooltip_str;
    const gchar *action_id, *is_selected;
    GList *prop_buttons, *tool_buttons;
    GtkSizeGroup *sg;
    char *display_time;
    gboolean is_hidden;
    GtkWidget *toplevel;

    if (prop_menu_showing)
        return;

    charset = get_charset(lines[1]);

    prop_buttons = g_object_get_data(G_OBJECT(widget), OBJECT_DATA_PROP_BUTTONS);
    tool_buttons = g_object_get_data(G_OBJECT(widget), OBJECT_DATA_TOOL_BUTTONS);
    sg  = g_object_get_data(G_OBJECT(widget), OBJECT_DATA_SIZE_GROUP);

    if (prop_buttons) {
        g_list_foreach(prop_buttons, prop_button_destroy, NULL);
        g_list_free(prop_buttons);
        g_object_set_data(G_OBJECT(widget), OBJECT_DATA_PROP_BUTTONS, NULL);
    }

    if (tool_buttons) {
        g_list_foreach(tool_buttons, tool_button_destroy, NULL);
        g_list_free(tool_buttons);
        g_object_set_data(G_OBJECT(widget), OBJECT_DATA_TOOL_BUTTONS, NULL);
    }

    display_time
        = uim_scm_c_symbol( uim_scm_symbol_value( "toolbar-display-time" ) );
    is_hidden = strcmp(display_time, "mode");
    for (i = 0; lines[i] && strcmp("", lines[i]); i++) {
        gchar *utf8_str = convert_charset(charset, lines[i]);

        if (utf8_str != NULL) {
            cols = g_strsplit(utf8_str, "\t", 0);
            g_free(utf8_str);
        } else {
            cols = g_strsplit(lines[i], "\t", 0);
        }

        if (cols && cols[0]) {
            if (!strcmp("branch", cols[0]) && has_n_strs(cols, 4)) {
                indication_id = cols[1];
                iconic_label  = safe_gettext(cols[2]);
                tooltip_str   = safe_gettext(cols[3]);
                button = prop_button_create(widget,
                                            indication_id, iconic_label, tooltip_str);
                append_prop_button(widget, button);

                if (!is_hidden && (!strcmp(indication_id, "direct")
                                   || g_str_has_suffix(indication_id, "_direct"))) {
                    is_hidden = TRUE;
                }
            } else if (!strcmp("leaf", cols[0]) && has_n_strs(cols, 7)) {
                indication_id = cols[1];
                iconic_label  = safe_gettext(cols[2]);
                label         = safe_gettext(cols[3]);
                tooltip_str   = safe_gettext(cols[4]);
                action_id     = cols[5];
                is_selected   = cols[6];
                prop_button_append_menu(button,
                                        indication_id, label, tooltip_str, action_id,
                                        is_selected);
            }
            g_strfreev(cols);
        }
    }
    toplevel = gtk_widget_get_toplevel(widget);
    is_hidden = (is_hidden && strcmp(display_time, "always"));
#if GTK_CHECK_VERSION(2, 18, 0)
    if (gtk_widget_get_visible(toplevel) == is_hidden) {
#else
    if (GTK_WIDGET_VISIBLE(toplevel) == is_hidden) {
#endif
        if (is_hidden) {
            gtk_widget_hide(toplevel);
        } else {
            gint x = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(toplevel),
                                     "position_x"));
            gint y = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(toplevel),
                                     "position_y"));
            gtk_window_move(GTK_WINDOW(toplevel), x, y);
            gtk_widget_show(toplevel);
        }
    }

    /* create tool buttons */
    /* FIXME! command menu and buttons should be customizable. */
    for (i = 0; i < command_entry_len; i++) {
        GtkWidget *tool_button;
        GtkWidget *img;

        if (!command_entry[i].show_button)
            continue;

        tool_button = gtk_button_new();

        set_button_style(tool_button,
                         GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget),
                                         OBJECT_DATA_TOOLBAR_TYPE)));

        g_object_set_data(G_OBJECT(tool_button), OBJECT_DATA_BUTTON_TYPE,
                          GINT_TO_POINTER(BUTTON_TOOL));
        g_object_set_data(G_OBJECT(tool_button), OBJECT_DATA_COMMAND,
                          (gpointer)command_entry[i].command);
        if (command_entry[i].icon)
            img = gtk_image_new_from_stock(command_entry[i].icon,
                                           GTK_ICON_SIZE_MENU);
        else {
            img = gtk_label_new("");
            gtk_label_set_markup(GTK_LABEL(img), command_entry[i].label);
        }
        if (img)
            gtk_container_add(GTK_CONTAINER(tool_button), img);
        gtk_button_set_relief(GTK_BUTTON(tool_button), GTK_RELIEF_NONE);
        gtk_size_group_add_widget(sg, tool_button);
        g_signal_connect(G_OBJECT(tool_button), "button-press-event",
                         G_CALLBACK(button_pressed), widget);
        g_signal_connect(G_OBJECT(tool_button), "clicked",
                         G_CALLBACK(tool_button_clicked_cb), widget);

        /* tooltip */
        gtk_widget_set_tooltip_text(tool_button, _(command_entry[i].desc));

        append_tool_button(widget, tool_button);
    }

    gtk_widget_show_all(widget);
    g_free(charset);
}

static void
helper_toolbar_check_custom()
{
    guint i;

    for (i = 0; i < command_entry_len; i++)
        command_entry[i].show_button =
            uim_scm_symbol_value_bool(command_entry[i].custom_button_show_symbol);

    with_dark_bg =
        uim_scm_symbol_value_bool("toolbar-icon-for-dark-background?");
}
Exemplo n.º 14
0
Arquivo: main.cpp Projeto: dai-vdr/uim
int
main(int argc, char **argv)
{
    const char *locale;

    printf("uim <-> XIM bridge. Supporting multiple locales.\n");

    get_runtime_env();

    parse_args(argc, argv);

    if (g_option_mask & OPT_ON_DEMAND_SYNC)
	printf("Using on-demand-synchronous XIM event flow (not safe for Tcl/TK)\n");
    else
	printf("Using full-synchronous XIM event flow\n");

    signal(SIGPIPE, SIG_IGN);
    signal(SIGUSR1, reload_uim);

    check_helper_connection();

    XimServer::gDpy = XOpenDisplay(NULL);
    if (!XimServer::gDpy) {
	printf("failed to open display!\n");
	return 1;
    }
    if (!pretrans_register()) {
	printf("pretrans_register failed\n");
	return 1;
    }

    get_uim_info();
    print_uim_info();

    locale = setlocale(LC_CTYPE, "");
    if (!locale)
	locale = setlocale(LC_CTYPE, "C");

    check_default_engine(locale);
    init_supported_locales();
    init_modifier_keys();

    std::list<UIMInfo>::iterator it;
    bool res = false;

    // First, setup conversion engine selected by cmdline option or
    // "default-im-name" on ~/.uim.
    for (it = uim_info.begin(); it != uim_info.end(); ++it) {
	if (strcmp(it->name, default_engine) == 0) {
	    XimServer *xs = new XimServer(it->name, it->lang);
	    res = xs->setupConnection(true);
	    if (res)
		printf("XMODIFIERS=@im=uim registered, selecting %s (%s) as default conversion engine\n", it->name, it->lang);
	    else
		delete xs;
	    break;
	}
    }

    if (!res) {
	printf("aborting...\n");
	return 1;
    }

    connection_setup();
    error_handler_setup();
    if (pretrans_setup() == -1)
	return 0;

#if HAVE_XFT_UTF8_STRING
    if (uim_scm_symbol_value_bool("uim-xim-use-xft-font?"))
	init_default_xftfont(); // setup Xft fonts for Ov/Rw preedit
#endif
    check_candwin_style();
    check_candwin_pos_type();

    // Handle pending events to prevent hang just after startup
    check_pending_xevent();

    main_loop();
    return 0;
}