Initial commit for utf8 everywhere.

This commit is contained in:
Arnavion
2012-11-03 10:24:25 -07:00
parent e0b1724158
commit 5d9264aff6
21 changed files with 374 additions and 723 deletions

View File

@@ -162,7 +162,6 @@ fe_args (int argc, char *argv[])
GError *error = NULL;
GOptionContext *context;
#ifdef WIN32
#define ARGBUF_SIZE 2048
char *buffer;
#endif
@@ -187,35 +186,26 @@ fe_args (int argc, char *argv[])
{
if (strstr (error->message, "--help-all") != NULL)
{
buffer = (char*) malloc (ARGBUF_SIZE);
if (snprintf (buffer, ARGBUF_SIZE, g_option_context_get_help (context, FALSE, NULL)))
{
gtk_init (&argc, &argv);
create_msg_dialog ("Long Help", buffer);
}
free (buffer);
buffer = g_strdup_printf (g_option_context_get_help (context, FALSE, NULL));
gtk_init (&argc, &argv);
create_msg_dialog ("Long Help", buffer);
g_free (buffer);
return 0;
}
else if (strstr (error->message, "--help") != NULL || strstr (error->message, "-?") != NULL)
{
buffer = (char*) malloc (ARGBUF_SIZE);
if (snprintf (buffer, ARGBUF_SIZE, g_option_context_get_help (context, TRUE, NULL)))
{
gtk_init (&argc, &argv);
create_msg_dialog ("Help", buffer);
}
free (buffer);
buffer = g_strdup_printf (g_option_context_get_help (context, TRUE, NULL));
gtk_init (&argc, &argv);
create_msg_dialog ("Help", buffer);
g_free (buffer);
return 0;
}
else
{
buffer = (char*) malloc (ARGBUF_SIZE);
if (snprintf (buffer, ARGBUF_SIZE, "%s\n", error->message))
{
gtk_init (&argc, &argv);
create_msg_dialog ("Error", buffer);
}
free (buffer);
buffer = g_strdup_printf ("%s\n", error->message);
gtk_init (&argc, &argv);
create_msg_dialog ("Error", buffer);
g_free (buffer);
return 1;
}
}
@@ -234,13 +224,10 @@ fe_args (int argc, char *argv[])
if (arg_show_version)
{
#ifdef WIN32
buffer = (char*) malloc (ARGBUF_SIZE);
if (snprintf (buffer, ARGBUF_SIZE, DISPLAY_NAME" "PACKAGE_VERSION"\n"))
{
gtk_init (&argc, &argv);
create_msg_dialog ("Version Information", buffer);
}
free (buffer);
buffer = g_strdup_printf (DISPLAY_NAME " " PACKAGE_VERSION "\n");
gtk_init (&argc, &argv);
create_msg_dialog ("Version Information", buffer);
g_free (buffer);
#else
printf (PACKAGE_TARNAME" "PACKAGE_VERSION"\n");
#endif
@@ -253,25 +240,20 @@ fe_args (int argc, char *argv[])
/* see the chdir() below */
char *sl, *exe = strdup (argv[0]);
sl = strrchr (exe, '\\');
buffer = (char*) malloc (ARGBUF_SIZE);
if (sl)
{
*sl = 0;
if (snprintf (buffer, ARGBUF_SIZE, "%s\\plugins\n", exe))
{
gtk_init (&argc, &argv);
create_msg_dialog ("Plugin Auto-load Directory", buffer);
}
buffer = g_strdup_printf ("%s\\plugins\n", exe);
gtk_init (&argc, &argv);
create_msg_dialog ("Plugin Auto-load Directory", buffer);
}
else
{
if (snprintf (buffer, ARGBUF_SIZE, ".\\plugins\n"))
{
gtk_init (&argc, &argv);
create_msg_dialog ("Plugin Auto-load Directory", buffer);
}
buffer = g_strdup(".\\plugins\n");
gtk_init (&argc, &argv);
create_msg_dialog ("Plugin Auto-load Directory", buffer);
}
free (buffer);
g_free (buffer);
#else
printf ("%s\n", HEXCHATLIBDIR"/plugins");
#endif
@@ -281,15 +263,12 @@ fe_args (int argc, char *argv[])
if (arg_show_config)
{
#ifdef WIN32
buffer = (char*) malloc (ARGBUF_SIZE);
if (snprintf (buffer, ARGBUF_SIZE, "%s\n", get_xdir_fs ()))
{
gtk_init (&argc, &argv);
create_msg_dialog ("User Config Directory", buffer);
}
free (buffer);
buffer = g_strdup_printf ("%s\n", get_xdir ());
gtk_init (&argc, &argv);
create_msg_dialog ("User Config Directory", buffer);
g_free (buffer);
#else
printf ("%s\n", get_xdir_fs ());
printf ("%s\n", get_xdir ());
#endif
return 0;
}
@@ -313,12 +292,14 @@ fe_args (int argc, char *argv[])
}
#endif
if (arg_cfgdir) /* we want filesystem encoding */
if (arg_cfgdir)
{
xdir_fs = strdup (arg_cfgdir);
if (xdir_fs[strlen (xdir_fs) - 1] == '/')
if (xdir)
g_free (xdir);
xdir = strdup (arg_cfgdir);
if (xdir[strlen (xdir) - 1] == '/')
{
xdir_fs[strlen (xdir_fs) - 1] = 0;
xdir[strlen (xdir) - 1] = 0;
}
g_free (arg_cfgdir);
}

View File

@@ -1019,8 +1019,8 @@ key_load_kbs (char *filename)
free (ibuf);
ibuf = malloc (1024);
snprintf (ibuf, 1024,
_("Unknown keyname %s in key bindings config file\nLoad aborted, please fix %s/keybindings.conf\n"),
buf, get_xdir_utf8 ());
_("Unknown keyname %s in key bindings config file\nLoad aborted, please fix %s" G_DIR_SEPARATOR_S "keybindings.conf\n"),
buf, get_xdir ());
fe_message (ibuf, FE_MSG_ERROR);
free (ibuf);
return 2;
@@ -1057,8 +1057,8 @@ key_load_kbs (char *filename)
free (ibuf);
ibuf = malloc (1024);
snprintf (ibuf, 1024,
_("Unknown action %s in key bindings config file\nLoad aborted, Please fix %s/keybindings\n"),
buf, get_xdir_utf8 ());
_("Unknown action %s in key bindings config file\nLoad aborted, Please fix %s" G_DIR_SEPARATOR_S "keybindings\n"),
buf, get_xdir ());
fe_message (ibuf, FE_MSG_ERROR);
free (ibuf);
return 3;
@@ -1078,8 +1078,8 @@ key_load_kbs (char *filename)
free (ibuf);
ibuf = malloc (1024);
snprintf (ibuf, 1024,
_("Expecting Data line (beginning Dx{:|!}) but got:\n%s\n\nLoad aborted, Please fix %s/keybindings\n"),
buf, get_xdir_utf8 ());
_("Expecting Data line (beginning Dx{:|!}) but got:\n%s\n\nLoad aborted, Please fix %s" G_DIR_SEPARATOR_S "keybindings\n"),
buf, get_xdir ());
fe_message (ibuf, FE_MSG_ERROR);
free (ibuf);
return 4;
@@ -1148,8 +1148,8 @@ key_load_kbs (char *filename)
abort ();*/
snprintf (ibuf, 1024,
_("Key bindings config file is corrupt, load aborted\n"
"Please fix %s/keybindings.conf\n"),
get_xdir_utf8 ());
"Please fix %s" G_DIR_SEPARATOR_S "keybindings.conf\n"),
get_xdir ());
fe_message (ibuf, FE_MSG_ERROR);
free (ibuf);
return 5;

View File

@@ -186,192 +186,6 @@ gtkutil_file_req_response (GtkWidget *dialog, gint res, struct file_req *freq)
}
}
#if 0 /* native file dialogs */
#ifdef WIN32
static int
win32_openfile (char *file_buf, int file_buf_len, char *title_text, char *filter,
int multiple)
{
OPENFILENAME o;
memset (&o, 0, sizeof (o));
o.lStructSize = sizeof (o);
o.lpstrFilter = filter;
o.lpstrFile = file_buf;
o.nMaxFile = file_buf_len;
o.lpstrTitle = title_text;
o.Flags = 0x02000000 | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_LONGNAMES | OFN_NONETWORKBUTTON;
if (multiple)
{
o.Flags |= OFN_ALLOWMULTISELECT;
}
return GetOpenFileName (&o);
}
static int
win32_savefile (char *file_buf, int file_buf_len, char *title_text, char *filter,
int multiple)
{
/* we need the filter to get the default filename. it is from fe-gtk.c (fe_confirm);
* but that filter is actually the whole filename, so apply an empty filter and all good.
* in win32_thread2 we copy the filter ( = the filename) after the last dir into our
* LPTSTR file buffer to make it actually work. the docs for this amazingly retard api:
*
* http://msdn.microsoft.com/en-us/library/ms646839%28VS.85%29.aspx
*/
OPENFILENAME o;
memset (&o, 0, sizeof (o));
o.lStructSize = sizeof (o);
o.lpstrFilter = "All files\0*.*\0\0";
o.lpstrFile = file_buf;
o.nMaxFile = file_buf_len;
o.lpstrTitle = title_text;
o.Flags = 0x02000000 | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_LONGNAMES | OFN_NONETWORKBUTTON;
if (multiple)
{
o.Flags |= OFN_ALLOWMULTISELECT;
}
return GetSaveFileName (&o);
}
static void *
win32_thread (struct file_req *freq)
{
char buf[1024 + 32];
char file[1024];
memset (file, 0, sizeof (file));
safe_strcpy (file, last_dir, sizeof (file));
if (win32_openfile (file, sizeof (file), freq->title, freq->filter, freq->multiple))
{
if (freq->multiple)
{
char *f = file;
if (f[strlen (f) + 1] == 0) /* only selected one file */
{
snprintf (buf, sizeof (buf), "1\n%s\n", file);
write (freq->th->pipe_fd[1], buf, strlen (buf));
} else
{
f += strlen (f) + 1; /* skip first, it's only the dir */
while (f[0])
{
snprintf (buf, sizeof (buf), "1\n%s\\%s\n", /*dir!*/file, f);
write (freq->th->pipe_fd[1], buf, strlen (buf));
f += strlen (f) + 1;
}
}
} else
{
snprintf (buf, sizeof (buf), "1\n%s\n", file);
write (freq->th->pipe_fd[1], buf, strlen (buf));
}
}
write (freq->th->pipe_fd[1], "0\n", 2);
Sleep (2000);
return NULL;
}
static void *
win32_thread2 (struct file_req *freq)
{
char buf[1024 + 32];
char file[1024];
memset (file, 0, sizeof (file));
safe_strcpy (file, last_dir, sizeof (file));
safe_strcpy (file, freq->filter, sizeof (file));
if (win32_savefile (file, sizeof (file), freq->title, NULL, freq->multiple))
{
if (freq->multiple)
{
char *f = file;
if (f[strlen (f) + 1] == 0) /* only selected one file */
{
snprintf (buf, sizeof (buf), "1\n%s\n", file);
write (freq->th->pipe_fd[1], buf, strlen (buf));
} else
{
f += strlen (f) + 1; /* skip first, it's only the dir */
while (f[0])
{
snprintf (buf, sizeof (buf), "1\n%s\\%s\n", /*dir!*/file, f);
write (freq->th->pipe_fd[1], buf, strlen (buf));
f += strlen (f) + 1;
}
}
} else
{
snprintf (buf, sizeof (buf), "1\n%s\n", file);
write (freq->th->pipe_fd[1], buf, strlen (buf));
}
}
write (freq->th->pipe_fd[1], "0\n", 2);
Sleep (2000);
return NULL;
}
static gboolean
win32_close_pipe (int fd)
{
close (fd);
return 0;
}
static gboolean
win32_read_thread (GIOChannel *source, GIOCondition cond, struct file_req *freq)
{
char buf[512];
char *file;
waitline2 (source, buf, sizeof buf);
switch (buf[0])
{
case '0': /* filedialog has closed */
freq->callback (freq->userdata, NULL);
break;
case '1': /* got a filename! */
waitline2 (source, buf, sizeof buf);
file = g_filename_to_utf8 (buf, -1, 0, 0, 0);
freq->callback (freq->userdata, file);
g_free (file);
return TRUE;
}
/* it doesn't work to close them here, because of the weird
way giowin32 works. We must _return_ before closing them */
g_timeout_add(3000, (GSourceFunc)win32_close_pipe, freq->th->pipe_fd[0]);
g_timeout_add(2000, (GSourceFunc)win32_close_pipe, freq->th->pipe_fd[1]);
g_free (freq->title);
free (freq->th);
free (freq);
return FALSE;
}
#endif
#endif /* native file dialogs */
void
gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, char *extensions,
int flags)
@@ -467,7 +281,7 @@ gtkutil_file_req (const char *title, void *callback, void *userdata, char *filte
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir);
if (flags & FRF_ADDFOLDER)
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
get_xdir_fs (), NULL);
get_xdir (), NULL);
if (flags & FRF_CHOOSEFOLDER)
{
gtk_file_chooser_set_action (GTK_FILE_CHOOSER (dialog), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
@@ -491,7 +305,7 @@ gtkutil_file_req (const char *title, void *callback, void *userdata, char *filte
/* by default, open the config folder */
else
{
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), get_xdir_fs ());
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), get_xdir ());
}
}

View File

@@ -286,8 +286,8 @@ menu_quick_item (char *cmd, char *label, GtkWidget * menu, int flags,
img = gtk_image_new_from_file (icon);
else
{
/* try relative to ~/.xchat2 */
path = g_strdup_printf ("%s/%s", get_xdir_fs (), icon);
/* try relative to <xdir> */
path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s", get_xdir (), icon);
if (access (path, R_OK) == 0)
img = gtk_image_new_from_file (path);
else

View File

@@ -105,7 +105,7 @@ load_pixmap (const char *filename, const char *name, int has_inline)
gchar *path;
GdkPixbuf *pixbuf;
path = g_strdup_printf ("%s/icons/%s.png", get_xdir_utf8 (), filename);
path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "icons" G_DIR_SEPARATOR_S "%s.png", get_xdir (), filename);
pixbuf = gdk_pixbuf_new_from_file (path, 0);
g_free (path);

View File

@@ -147,30 +147,18 @@ plugingui_load_cb (session *sess, char *file)
void
plugingui_load (void)
{
/* let's do it the Perl way */
const char *xdir;
char *sub_dir;
xdir = get_xdir_utf8 ();
sub_dir = malloc (strlen (xdir) + 8);
strcpy (sub_dir, xdir);
strcat (sub_dir, "/addons");
sub_dir = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "addons", get_xdir());
gtkutil_file_req (_("Select a Plugin or Script to load"), plugingui_load_cb, current_sess,
#if 0 /* native file dialogs */
#ifdef WIN32
"Plugins and Scripts\0*.dll;*.lua;*.pl;*.py;*.tcl\0"
"All files\0*.*\0\0", 0);
#else
#endif
#endif /* native file dialogs */
#ifdef WIN32
sub_dir, "*.dll;*.lua;*.pl;*.py;*.tcl", FRF_ADDFOLDER|FRF_FILTERISINITIAL|FRF_EXTENSIONS);
#else
sub_dir, "*.so;*.lua;*.pl;*.py;*.tcl", FRF_ADDFOLDER|FRF_FILTERISINITIAL|FRF_EXTENSIONS);
#endif
free (sub_dir);
g_free (sub_dir);
}
static void

View File

@@ -1245,7 +1245,7 @@ setup_create_frame (GtkWidget **left, GtkWidget *box)
static void
open_data_cb (GtkWidget *button, gpointer data)
{
fe_open_url (get_xdir_utf8 ());
fe_open_url (get_xdir ());
}
static GtkWidget *
@@ -2135,8 +2135,8 @@ setup_apply_real (int new_pix, int do_ulist, int do_layout)
unslash (prefs.hex_dcc_dir);
unslash (prefs.hex_dcc_completed_dir);
mkdir_utf8 (prefs.hex_dcc_dir);
mkdir_utf8 (prefs.hex_dcc_completed_dir);
g_mkdir (prefs.hex_dcc_dir, 0700);
g_mkdir (prefs.hex_dcc_completed_dir, 0700);
if (new_pix)
{

View File

@@ -147,7 +147,7 @@ static void
url_button_save (void)
{
gtkutil_file_req (_("Select an output filename"),
url_save_callback, NULL, get_xdir_utf8 (), NULL, FRF_WRITE|FRF_FILTERISINITIAL);
url_save_callback, NULL, get_xdir (), NULL, FRF_WRITE|FRF_FILTERISINITIAL);
}
void