示例#1
0
文件: strutil.c 项目: CTU-OSP/mc
void
str_init_strings (const char *termenc)
{
    codeset = termenc != NULL ? g_ascii_strup (termenc, -1) : g_strdup (str_detect_termencoding ());

    str_cnv_not_convert = g_iconv_open (codeset, codeset);
    if (str_cnv_not_convert == INVALID_CONV)
    {
        if (termenc != NULL)
        {
            g_free (codeset);
            codeset = g_strdup (str_detect_termencoding ());
            str_cnv_not_convert = g_iconv_open (codeset, codeset);
        }

        if (str_cnv_not_convert == INVALID_CONV)
        {
            g_free (codeset);
            codeset = g_strdup (DEFAULT_CHARSET);
            str_cnv_not_convert = g_iconv_open (codeset, codeset);
        }
    }

    str_cnv_to_term = str_cnv_not_convert;
    str_cnv_from_term = str_cnv_not_convert;

    str_choose_str_functions ();
}
示例#2
0
void
str_init_strings (const char *termenc)
{
    codeset = g_strdup ((termenc != NULL) ? termenc : str_detect_termencoding ());

    str_cnv_not_convert = g_iconv_open (codeset, codeset);
    if (str_cnv_not_convert == INVALID_CONV)
    {
        if (termenc != NULL)
        {
            g_free (codeset);
            codeset = g_strdup (str_detect_termencoding ());
            str_cnv_not_convert = g_iconv_open (codeset, codeset);
        }

        if (str_cnv_not_convert == INVALID_CONV)
        {
            g_free (codeset);
            codeset = g_strdup ("ascii");
            str_cnv_not_convert = g_iconv_open (codeset, codeset);
        }
    }

    str_cnv_to_term = str_cnv_not_convert;
    str_cnv_from_term = str_cnv_not_convert;

    str_choose_str_functions ();
}
示例#3
0
void
ISpellChecker::try_autodetect_charset(const char * const inEncoding)
{
	if (inEncoding && strlen(inEncoding))
		{
			m_translate_in = g_iconv_open(inEncoding, "UTF-8");
			m_translate_out = g_iconv_open("UTF-8", inEncoding);
		}
}
示例#4
0
char *
init_translation_table (int cpsource, int cpdisplay)
{
    int i;
    GIConv cd;

    /* Fill inpit <-> display tables */

    if (cpsource < 0 || cpdisplay < 0 || cpsource == cpdisplay)
    {
        for (i = 0; i <= 255; ++i)
        {
            conv_displ[i] = i;
            conv_input[i] = i;
            cp_source = cp_display;
        }
        return NULL;
    }

    for (i = 0; i <= 127; ++i)
    {
        conv_displ[i] = i;
        conv_input[i] = i;
    }
    cp_source = ((codepage_desc *) g_ptr_array_index (codepages, cpsource))->id;
    cp_display = ((codepage_desc *) g_ptr_array_index (codepages, cpdisplay))->id;

    /* display <- inpit table */

    cd = g_iconv_open (cp_display, cp_source);
    if (cd == INVALID_CONV)
        return g_strdup_printf (_("Cannot translate from %s to %s"), cp_source, cp_display);

    for (i = 128; i <= 255; ++i)
        conv_displ[i] = translate_character (cd, i);

    g_iconv_close (cd);

    /* inpit <- display table */

    cd = g_iconv_open (cp_source, cp_display);
    if (cd == INVALID_CONV)
        return g_strdup_printf (_("Cannot translate from %s to %s"), cp_display, cp_source);

    for (i = 128; i <= 255; ++i)
    {
        unsigned char ch;
        ch = translate_character (cd, i);
        conv_input[i] = (ch == UNKNCHAR) ? i : ch;
    }

    g_iconv_close (cd);

    return NULL;
}
示例#5
0
GIConv rlib_charencoder_new(const gchar *to_codeset, const gchar *from_codeset) {
#ifdef DISABLE_UTF8
	return (GIConv)-1;
#else
	return g_iconv_open(to_codeset, from_codeset);
#endif	
}
示例#6
0
文件: servlist.c 项目: PChat/PChat
/* check if a charset is known by Iconv */
int
servlist_check_encoding (char *charset)
{
	GIConv gic;
	char *c;

	c = strchr (charset, ' ');
	if (c)
		c[0] = 0;

	if (!g_ascii_strcasecmp (charset, "IRC")) /* special case */
	{
		if (c)
			c[0] = ' ';
		return TRUE;
	}

	gic = g_iconv_open (charset, "UTF-8");

	if (c)
		c[0] = ' ';

	if (gic != (GIConv)-1)
	{
		g_iconv_close (gic);
		return TRUE;
	}

	return FALSE;
}
示例#7
0
char *gnc_hbci_getremotename (const AB_TRANSACTION *h_trans)
{
    /* Description */
    char *othername = NULL;
    char *result;
    const GWEN_STRINGLIST *h_remotename = AB_Transaction_GetRemoteName (h_trans);
    struct cb_struct cb_object;

    cb_object.gnc_iconv_handler =
        g_iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding());
    g_assert(cb_object.gnc_iconv_handler != (GIConv)(-1));

    /* Get othername */
    cb_object.result = &othername;
    if (h_remotename)
        GWEN_StringList_ForEach (h_remotename,
                                 &gnc_list_string_cb,
                                 &cb_object);
    /*DEBUG("HBCI Description '%s'", h_descr);*/

    if (othername && (strlen (othername) > 0))
        result = g_strdup (othername);
    else
        result = NULL;

    g_iconv_close(cb_object.gnc_iconv_handler);
    g_free (othername);
    return result;
}
示例#8
0
文件: lib.c 项目: BrEacK/mc
gchar *
mc_search__recode_str (const char *str, gsize str_len,
                       const char *charset_from, const char *charset_to, gsize * bytes_written)
{
    gchar *ret;
    gsize bytes_read;
    GIConv conv;

    if (charset_from == NULL || charset_to == NULL || !strcmp (charset_to, charset_from))
    {
        *bytes_written = str_len;
        return g_strndup (str, str_len);
    }

    conv = g_iconv_open (charset_to, charset_from);
    if (conv == INVALID_CONV)
    {
        *bytes_written = str_len;
        return g_strndup (str, str_len);
    }

    ret = g_convert_with_iconv (str, str_len, conv, &bytes_read, bytes_written, NULL);
    g_iconv_close (conv);

    if (ret == NULL)
    {
        *bytes_written = str_len;
        return g_strndup (str, str_len);
    }

    return ret;
}
示例#9
0
文件: tty.c 项目: GarothLongint/mc
char *
mc_tty_normalize_from_utf8 (const char *str)
{
    GIConv conv;
    GString *buffer;
    const char *_system_codepage = str_detect_termencoding ();

    if (str_isutf8 (_system_codepage))
        return g_strdup (str);

    conv = g_iconv_open (_system_codepage, "UTF-8");
    if (conv == INVALID_CONV)
        return g_strdup (str);

    buffer = g_string_new ("");

    if (str_convert (conv, str, buffer) == ESTR_FAILURE)
    {
        g_string_free (buffer, TRUE);
        str_close_conv (conv);
        return g_strdup (str);
    }
    str_close_conv (conv);

    return g_string_free (buffer, FALSE);
}
static GIConv
_get_iconv (LocalIconvCode from, LocalIconvCode to)
{
  if (__iconvs[from][to] == (GIConv) - 1)
    __iconvs[from][to] = g_iconv_open (iconvtablename[to],
        iconvtablename[from]);
  return __iconvs[from][to];
}
示例#11
0
static gboolean iconv_supported(const char *to, const char *from)
{
    GIConv ic = g_iconv_open(to, from);
    if (ic == NULL || ic == (GIConv) -1)
        return FALSE;

    g_iconv_close(ic);
    return TRUE;
}
示例#12
0
static gboolean
check_locale (const char *locale)
{
	GIConv cd = g_iconv_open ("UTF-8", locale);
	if ((GIConv)-1 == cd)
		return FALSE;
	g_iconv_close (cd);
	return TRUE;
}
示例#13
0
/*
 * returns the number of bytes that represent the UTF8 encoding buffer
 * in the original encoding that the user specified.
 *
 * NOTE: this is slow, but we only call this for the remainder of our
 * buffer (e.g. the partial line at the end of our last chunk of read
 * data). Also, this is only invoked if the file uses an encoding.
 */
static gsize
log_proto_text_server_get_raw_size_of_buffer(LogProtoTextServer *self, const guchar *buffer, gsize buffer_len)
{
  gchar *out;
  const guchar *in;
  gsize avail_out, avail_in;
  gint ret;

  if (self->reverse_convert == ((GIConv) -1) && !self->convert_scale)
    {
      /* try to speed up raw size calculation by recognizing the most
       * prominent character encodings and in the case the encoding
       * uses fixed size characters set that in self->convert_scale,
       * which in turn will speed up the reversal of the UTF8 buffer
       * size to raw buffer sizes.
       */
      self->convert_scale = log_proto_get_char_size_for_fixed_encoding(self->super.super.options->encoding);
      if (self->convert_scale == 0)
        {
          /* this encoding is not known, do the conversion for real :( */
          self->reverse_convert = g_iconv_open(self->super.super.options->encoding, "utf-8");
        }
    }

  if (self->convert_scale)
    return g_utf8_strlen((gchar *) buffer, buffer_len) * self->convert_scale;

  if (self->reverse_buffer_len < buffer_len * 6)
    {
      /* we free and malloc, since we never need the data still in reverse buffer */
      g_free(self->reverse_buffer);
      self->reverse_buffer_len = buffer_len * 6;
      self->reverse_buffer = g_malloc(buffer_len * 6);
    }

  avail_out = self->reverse_buffer_len;
  out = self->reverse_buffer;

  avail_in = buffer_len;
  in = buffer;

  ret = g_iconv(self->reverse_convert, (gchar **) &in, &avail_in, &out, &avail_out);
  if (ret == (gsize) -1)
    {
      /* oops, we cannot reverse that we ourselves converted to UTF-8,
       * this is simply impossible, but never say never */
      msg_error("Internal error, couldn't reverse the internal UTF8 string to the original encoding",
                evt_tag_printf("buffer", "%.*s", (gint) buffer_len, buffer),
                NULL);
      return 0;
    }
  else
    {
      return self->reverse_buffer_len - avail_out;
    }
}
gboolean TextCodecGtk::isEncodingAvailable(const gchar* encName)
{
    GIConv tester;
    // test decoding
    tester = g_iconv_open(m_internalEncodingName, encName);
    if (tester == reinterpret_cast<GIConv>(-1)) {
        return false;
    } else {
        g_iconv_close(tester);
        // test encoding
        tester = g_iconv_open(encName, m_internalEncodingName);
        if (tester == reinterpret_cast<GIConv>(-1)) {
            return false;
        } else {
            g_iconv_close(tester);
            return true;
        }
    }
}
static bool isEncodingAvailable(const gchar* encodingName)
{
    GIConv tester;
    // test decoding
    tester = g_iconv_open(internalEncodingName, encodingName);
    if (tester == reinterpret_cast<GIConv>(-1)) {
        return false;
    } else {
        g_iconv_close(tester);
        // test encoding
        tester = g_iconv_open(encodingName, internalEncodingName);
        if (tester == reinterpret_cast<GIConv>(-1)) {
            return false;
        } else {
            g_iconv_close(tester);
            return true;
        }
    }
}
示例#16
0
void
sylk_file_open (GOFileOpener const *fo,
		GOIOContext	*io_context,
                WorkbookView	*wb_view,
		GsfInput	*input)
{
	SylkReader state;
	char const *input_name;
	char *name = NULL;
	int i;
	GnmLocale *locale;

	memset (&state, 0, sizeof (state));
	state.io_context = io_context;
	state.input	 = (GsfInputTextline *) gsf_input_textline_new (input);
	state.converter  = g_iconv_open ("UTF-8", "ISO-8859-1");
	state.finished	 = FALSE;
	state.line_no	 = 0;

	state.pp.wb = wb_view_get_workbook (wb_view);

	if (NULL == (input_name = gsf_input_name (input)) ||
	    NULL == (name = g_path_get_basename (input_name)) ||
	    '\0' == *name) {
		g_free (name);
		name = g_strdup ("Sheet");
	}

	state.pp.sheet = sheet_new (state.pp.wb, name, 256, 65536);
	workbook_sheet_attach (state.pp.wb, state.pp.sheet);
	g_free (name);

	state.pp.eval.col = state.pp.eval.row = 1;
	state.convs = gnm_conventions_xls_r1c1;

	state.formats	= g_ptr_array_new ();
	state.fonts	= g_ptr_array_new ();

	locale = gnm_push_C_locale ();
	sylk_parse_sheet (&state);
	gnm_pop_C_locale (locale);
	workbook_set_saveinfo (state.pp.wb, GO_FILE_FL_AUTO,
		go_file_saver_for_id ("Gnumeric_sylk:sylk"));

	for (i = state.fonts->len ; i-- > 0 ; )
		gnm_style_unref (g_ptr_array_index (state.fonts, i));
	g_ptr_array_free (state.fonts, TRUE);

	for (i = state.formats->len ; i-- > 0 ; )
		go_format_unref (g_ptr_array_index (state.formats, i));
	g_ptr_array_free (state.formats, TRUE);

	gsf_iconv_close (state.converter);
	g_object_unref (G_OBJECT (state.input));
}
static tvbuff_t * dissect_cbs_data(guint8 sms_encoding, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint16 offset )
{
   tvbuff_t * tvb_out = NULL;
   guint8		out_len;
   int			length = tvb_length(tvb) - offset;
   gchar *utf8_text = NULL;
   static unsigned char msgbuf[1024];
   guint8 * input_string = tvb_get_ephemeral_string(tvb, offset, length);
   GIConv cd;
   GError *l_conv_error = NULL;

   switch(sms_encoding){
     case SMS_ENCODING_7BIT:
     case SMS_ENCODING_7BIT_LANG:
     out_len = gsm_sms_char_7bit_unpack(0, length, sizeof(msgbuf),
                                        input_string,
                                        msgbuf);
     msgbuf[out_len] = '\0';
     utf8_text = gsm_sms_chars_to_utf8(msgbuf, out_len);
     tvb_out = tvb_new_child_real_data(tvb, utf8_text, out_len, out_len);
     add_new_data_source(pinfo, tvb_out, "unpacked 7 bit data");
     break;

     case SMS_ENCODING_8BIT:
     tvb_out = tvb_new_subset(tvb, offset, length, length);
     break;

     case SMS_ENCODING_UCS2:
     case SMS_ENCODING_UCS2_LANG:
     if ((cd = g_iconv_open("UTF-8","UCS-2BE")) != (GIConv) -1)
     {
         utf8_text = g_convert_with_iconv(input_string, length, cd, NULL, NULL, &l_conv_error);
         if(!l_conv_error)
         {
            tvb_out = tvb_new_subset(tvb, offset, length, length);
         }
         else
         proto_tree_add_text(tree, tvb, offset, length, "CBS String: g_convert_with_iconv FAILED");

         g_free(utf8_text);
         g_iconv_close(cd);
     }
     else
     {
            proto_tree_add_text(tree, tvb, offset, length, "CBS String: g_iconv_open FAILED contact wireshark");
     }
     break;

      default:
         proto_tree_add_text(tree, tvb, offset, length, "Unhandled encoding %d of CBS String", sms_encoding);
     break;
   }
   return tvb_out;
}
void proto_reg_handoff_minecraft(void)
{
    static int Initialized=FALSE;

    /* register with wireshark to dissect udp packets on port 25565 */
    if (!Initialized) {
        minecraft_handle = new_create_dissector_handle(dissect_minecraft, proto_minecraft);
        dissector_add_uint("tcp.port", 25565, minecraft_handle);
        ucs2_iconv = g_iconv_open( "UTF-8//TRANSLIT", "UCS-2BE" );

        Initialized = TRUE;
    }
}
tvbuff_t * dissect_cbs_data(guint8 sms_encoding, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint16 offset )
{
   tvbuff_t * tvb_out = NULL;
   int			length = tvb_length(tvb) - offset;
   gchar *utf8_text = NULL, *utf8_out;
   guint8 * input_string;
   GIConv cd;
   GError *l_conv_error = NULL;

   switch(sms_encoding){
     case SMS_ENCODING_7BIT:
     case SMS_ENCODING_7BIT_LANG:
     utf8_text = tvb_get_ts_23_038_7bits_string(wmem_packet_scope(), tvb, offset<<3, (length*8)/7);
     utf8_out = g_strdup(utf8_text);
     tvb_out = tvb_new_child_real_data(tvb, utf8_out, (guint)strlen(utf8_out), (guint)strlen(utf8_out));
     tvb_set_free_cb(tvb_out, g_free);
     add_new_data_source(pinfo, tvb_out, "unpacked 7 bit data");
     break;

     case SMS_ENCODING_8BIT:
     tvb_out = tvb_new_subset(tvb, offset, length, length);
     break;

     case SMS_ENCODING_UCS2:
     case SMS_ENCODING_UCS2_LANG:
     input_string = tvb_get_string(wmem_packet_scope(), tvb, offset, length);
     if ((cd = g_iconv_open("UTF-8","UCS-2BE")) != (GIConv) -1)
     {
         utf8_text = g_convert_with_iconv(input_string, length, cd, NULL, NULL, &l_conv_error);
         if(!l_conv_error)
         {
            tvb_out = tvb_new_subset(tvb, offset, length, length);
         }
         else
         proto_tree_add_text(tree, tvb, offset, length, "CBS String: g_convert_with_iconv FAILED");

         g_free(utf8_text);
         g_iconv_close(cd);
     }
     else
     {
            proto_tree_add_text(tree, tvb, offset, length, "CBS String: g_iconv_open FAILED contact wireshark");
     }
     break;

      default:
         proto_tree_add_text(tree, tvb, offset, length, "Unhandled encoding %d of CBS String", sms_encoding);
     break;
   }
   return tvb_out;
}
示例#20
0
gboolean
log_proto_server_options_set_encoding(LogProtoServerOptions *self, const gchar *encoding)
{
  GIConv convert;

  g_free(self->encoding);
  self->encoding = g_strdup(encoding);

  /* validate encoding */
  convert = g_iconv_open("utf8", encoding);
  if (convert == (GIConv) -1)
    return FALSE;
  g_iconv_close(convert);
  return TRUE;
}
static gboolean
is_valid_encoding(const char* encoding)
{
    GIConv cd;

    if (encoding == NULL || encoding[0] == '\0')
	return FALSE;

    cd = g_iconv_open("UTF-8", encoding);
    if (cd == (GIConv)-1) {
        return FALSE;
    }
    g_iconv_close(cd);

    return TRUE;
}
void
log_proto_buffered_server_init(LogProtoBufferedServer *self, LogTransport *transport, const LogProtoServerOptions *options)
{
  log_proto_server_init(&self->super, transport, options);
  self->super.prepare = log_proto_buffered_server_prepare;
  self->super.fetch = log_proto_buffered_server_fetch;
  self->super.queued = log_proto_buffered_server_queued;
  self->super.free_fn = log_proto_buffered_server_free_method;
  self->super.transport = transport;
  self->super.restart_with_state = log_proto_buffered_server_restart_with_state;
  self->convert = (GIConv) -1;
  self->read_data = log_proto_buffered_server_read_data_method;
  self->io_status = G_IO_STATUS_NORMAL;
  if (options->encoding)
    self->convert = g_iconv_open("utf-8", options->encoding);
  self->stream_based = TRUE;
}
示例#23
0
static void
gxi_add_encoding (GncXmlImportData *data, gpointer encoding_ptr)
{
    GIConv iconv;
    const gchar *message;
    gchar *enc_string;
    GtkListStore *store;
    GtkTreeIter iter;

    enc_string = g_ascii_strup (
                     g_quark_to_string (GPOINTER_TO_UINT (encoding_ptr)), -1);
    encoding_ptr = GUINT_TO_POINTER (g_quark_from_string (enc_string));

    if (g_list_find (data->encodings, encoding_ptr))
    {
        message = _("This encoding has been added to the list already.");
        gnc_error_dialog (data->encodings_dialog, "%s", message);
        return;
    }

    /* test whether we like this encoding */
    iconv = g_iconv_open ("UTF-8", enc_string);
    if (iconv == (GIConv) - 1)
    {
        g_iconv_close (iconv);
        g_free (enc_string);
        message = _("This is an invalid encoding.");
        gnc_error_dialog (data->encodings_dialog, "%s", message);
        return;
    }
    g_iconv_close (iconv);

    /* add to the list */
    data->encodings = g_list_append (data->encodings, encoding_ptr);
    store = GTK_LIST_STORE (gtk_tree_view_get_model (data->selected_encs_view));
    gtk_list_store_append (store, &iter);
    gtk_list_store_set (store, &iter, ENC_COL_STRING, enc_string,
                        ENC_COL_QUARK, encoding_ptr, -1);

    g_free (enc_string);

    if (!data->encodings->next)
        gtk_dialog_set_response_sensitive (GTK_DIALOG (data->encodings_dialog),
                                           GTK_RESPONSE_OK, TRUE);
}
示例#24
0
文件: args.c 项目: idispatch/mc
static gchar *
mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_message_str,
                                     const gchar * help_str)
{
    GString *buffer;
    GIConv conv;
    gchar *full_help_str;

    buffer = g_string_new ("");
    conv = g_iconv_open (charset, "UTF-8");
    full_help_str = g_strdup_printf ("%s\n\n%s\n", error_message_str, help_str);

    str_convert (conv, full_help_str, buffer);

    g_free (full_help_str);
    g_iconv_close (conv);

    return g_string_free (buffer, FALSE);
}
示例#25
0
文件: dif.c 项目: GNOME/gnumeric
static DifInputContext *
dif_input_context_new (GOIOContext *io_context, Workbook *wb, GsfInput *input)
{
	DifInputContext *ctxt = NULL;

	ctxt = g_new (DifInputContext, 1);
	ctxt->io_context     = io_context;

	ctxt->input	     = (GsfInputTextline *) gsf_input_textline_new (input);

	ctxt->line_no        = 1;
	ctxt->line           = NULL;
	ctxt->sheet          = workbook_sheet_add (wb, -1, GNM_DEFAULT_COLS, GNM_DEFAULT_ROWS);
	ctxt->converter      = g_iconv_open ("UTF-8", "ISO-8859-1");

	go_io_progress_message (io_context, _("Reading file..."));

	return ctxt;
}
示例#26
0
/* check if a charset is known by Iconv */
bool servlist_check_encoding(std::string charset)
{
	auto space = charset.find_first_of(' ');
	if (space != std::string::npos)
		charset.resize(space);

	if (!g_ascii_strcasecmp (charset.c_str(), "IRC")) /* special case */
	{
		return true;
	}

	auto gic = g_iconv_open (charset.c_str(), "UTF-8");

	if (gic != (GIConv)-1)
	{
		g_iconv_close (gic);
		return true;
	}

	return false;
}
示例#27
0
文件: text.c 项目: Cynede/hexchat
/**
 * Replaces any invalid UTF-8 in the given text with the unicode replacement character.
 */
gchar *
text_fixup_invalid_utf8 (const gchar* text, gssize len, gsize *len_out)
{
#if GLIB_CHECK_VERSION (2, 52, 0)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
	gchar *result = g_utf8_make_valid (text, len);
G_GNUC_END_IGNORE_DEPRECATIONS
	if (len_out)
	{
		*len_out = strlen (result);
	}
	return result;
#else
	static GIConv utf8_fixup_converter = NULL;
	if (utf8_fixup_converter == NULL)
	{
		utf8_fixup_converter = g_iconv_open ("UTF-8", "UTF-8");
	}

	return text_convert_invalid (text, len, utf8_fixup_converter, unicode_fallback_string, len_out);
#endif
}
示例#28
0
/* check if a charset is known by Iconv */
int
servlist_check_encoding (char *charset)
{
    GIConv gic;
    char *c;

    c = strchr (charset, ' ');
    if (c)
        c[0] = 0;

    gic = g_iconv_open (charset, "UTF-8");

    if (c)
        c[0] = ' ';

    if (gic != (GIConv)-1)
    {
        g_iconv_close (gic);
        return TRUE;
    }

    return FALSE;
}
static void
hildon_touch_selector_entry_init (HildonTouchSelectorEntry *self)
{
  HildonTouchSelectorEntryPrivate *priv;
  GtkEntryCompletion *completion;
  HildonGtkInputMode input_mode;

  priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (self);

  priv->converter = g_iconv_open ("ascii//translit", "utf-8");

  priv->entry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT);
  gtk_entry_set_activates_default (GTK_ENTRY (priv->entry), TRUE);
  input_mode = hildon_gtk_entry_get_input_mode (GTK_ENTRY (priv->entry));

  /* Disable unsupported input modes. */
  input_mode &= ~HILDON_GTK_INPUT_MODE_MULTILINE;
  input_mode &= ~HILDON_GTK_INPUT_MODE_INVISIBLE;
  input_mode &= ~HILDON_GTK_INPUT_MODE_DICTIONARY;

  hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry), input_mode);

  completion = gtk_entry_completion_new ();
  gtk_entry_completion_set_inline_completion (completion, TRUE);
  gtk_entry_completion_set_popup_completion (completion, FALSE);
  gtk_entry_set_completion (GTK_ENTRY (priv->entry), completion);
  g_object_unref (completion);

  gtk_widget_show (priv->entry);
  g_signal_connect (G_OBJECT (priv->entry), "changed",
                    G_CALLBACK (entry_on_text_changed), self);
  priv->signal_id = g_signal_connect (G_OBJECT (self), "changed",
                                      G_CALLBACK (hildon_touch_selector_entry_changed), NULL);

  hildon_touch_selector_set_print_func (HILDON_TOUCH_SELECTOR (self), hildon_touch_selector_entry_print_func);
  gtk_box_pack_start (GTK_BOX (self), priv->entry, FALSE, FALSE, 0);
}
示例#30
0
char* iofunctions_decode_text (gchar* text) {
    GError* err = NULL;
    gchar* result = 0;
    gsize read = 0, written = 0;

    if (! (result = g_locale_to_utf8 (text, -1, &read, &written, &err))) {
        g_error_free (err);
        slog (L_ERROR, "failed to convert text from default locale, trying "
                "ISO-8859-1\n");
        gsize in_size = strlen (text), out_size = in_size * 2;
        gchar* out = (gchar*)g_malloc (out_size);
        gchar* process = out;
        /* TODO: replace these calls to the non-raw glib functions */
        GIConv cd = g_iconv_open ("UTF-8//IGNORE", "ISO−8859-1");

        if (-1 == g_iconv (cd, &text, &in_size, &process, &out_size)) {
            slog (L_G_ERROR, _("Can not convert text to UTF-8!\n"));
            g_free (out);
            out = NULL;
        }
        result = out;
    }
    return result;
}