2002-08-27 09:27:11 +04:00
|
|
|
/* User interface for charset selection.
|
|
|
|
|
|
|
|
Copyright (C) 2001 Walery Studennikov <despair@sama.ru>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-08-27 09:27:11 +04:00
|
|
|
*/
|
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file selcodepage.c
|
2009-02-06 17:46:15 +03:00
|
|
|
* \brief Source: user %interface for charset %selection
|
2009-02-05 21:28:18 +03:00
|
|
|
*/
|
|
|
|
|
2001-06-01 03:56:27 +04:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-05-31 05:27:20 +04:00
|
|
|
#ifdef HAVE_CHARSET
|
2005-02-08 12:04:03 +03:00
|
|
|
|
2001-05-31 05:27:20 +04:00
|
|
|
#include <stdio.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <stdlib.h>
|
2001-09-07 21:52:19 +04:00
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2001-06-06 02:28:11 +04:00
|
|
|
#include "dialog.h"
|
2001-05-31 05:27:20 +04:00
|
|
|
#include "widget.h"
|
|
|
|
#include "wtools.h"
|
|
|
|
#include "charsets.h"
|
2001-07-31 09:54:39 +04:00
|
|
|
#include "selcodepage.h"
|
2001-06-06 02:28:11 +04:00
|
|
|
#include "main.h"
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2009-10-14 13:27:41 +04:00
|
|
|
#define ENTRY_LEN 30
|
2001-05-31 05:27:20 +04:00
|
|
|
|
|
|
|
/* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
|
|
|
|
int source_codepage = -1;
|
|
|
|
int display_codepage = -1;
|
|
|
|
|
2002-10-07 10:17:13 +04:00
|
|
|
static unsigned char
|
|
|
|
get_hotkey (int n)
|
2001-05-31 05:27:20 +04:00
|
|
|
{
|
|
|
|
return (n <= 9) ? '0' + n : 'a' + n - 10;
|
|
|
|
}
|
|
|
|
|
2009-06-14 19:05:57 +04:00
|
|
|
/* Return value:
|
|
|
|
* -2 (SELECT_CHARSET_CANCEL) : Cancel
|
|
|
|
* -1 (SELECT_CHARSET_OTHER_8BIT) : "Other 8 bit" if seldisplay == TRUE
|
|
|
|
* -1 (SELECT_CHARSET_NO_TRANSLATE) : "No translation" if seldisplay == FALSE
|
|
|
|
* >= 0 : charset number
|
|
|
|
*/
|
2002-10-07 10:17:13 +04:00
|
|
|
int
|
2009-10-14 13:27:41 +04:00
|
|
|
select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay)
|
2001-05-31 05:27:20 +04:00
|
|
|
{
|
2009-06-14 19:05:57 +04:00
|
|
|
int i;
|
2002-08-27 17:23:29 +04:00
|
|
|
char buffer[255];
|
2002-10-07 10:17:13 +04:00
|
|
|
|
2001-05-31 05:27:20 +04:00
|
|
|
/* Create listbox */
|
2009-10-14 13:27:41 +04:00
|
|
|
Listbox *listbox = create_listbox_window_centered (center_y, center_x,
|
|
|
|
n_codepages + 1, ENTRY_LEN + 2,
|
2009-06-14 19:05:57 +04:00
|
|
|
_("Choose codepage"),
|
2002-10-07 10:17:13 +04:00
|
|
|
"[Codepages Translation]");
|
2001-05-31 05:27:20 +04:00
|
|
|
|
|
|
|
if (!seldisplay)
|
2002-10-07 10:17:13 +04:00
|
|
|
LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"),
|
|
|
|
NULL);
|
2001-05-31 05:27:20 +04:00
|
|
|
|
|
|
|
/* insert all the items found */
|
|
|
|
for (i = 0; i < n_codepages; i++) {
|
2002-08-27 17:23:29 +04:00
|
|
|
char *name = codepages[i].name;
|
2009-02-06 01:49:00 +03:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i),
|
2002-10-07 10:17:13 +04:00
|
|
|
name);
|
|
|
|
LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL);
|
2001-05-31 05:27:20 +04:00
|
|
|
}
|
|
|
|
if (seldisplay) {
|
2009-02-06 01:49:00 +03:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "%c %s",
|
2002-10-07 10:17:13 +04:00
|
|
|
get_hotkey (n_codepages), _("Other 8 bit"));
|
|
|
|
LISTBOX_APPEND_TEXT (listbox, get_hotkey (n_codepages), buffer,
|
|
|
|
NULL);
|
2001-05-31 05:27:20 +04:00
|
|
|
}
|
2002-10-07 10:17:13 +04:00
|
|
|
|
2001-05-31 05:27:20 +04:00
|
|
|
/* Select the default entry */
|
|
|
|
i = (seldisplay)
|
2002-10-07 10:17:13 +04:00
|
|
|
? ((current_charset < 0) ? n_codepages : current_charset)
|
|
|
|
: (current_charset + 1);
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2009-12-28 19:10:42 +03:00
|
|
|
listbox_select_entry (listbox->list, i);
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2002-10-07 10:17:13 +04:00
|
|
|
i = run_listbox (listbox);
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2009-06-14 19:05:57 +04:00
|
|
|
if (i < 0) {
|
|
|
|
/* Cancel dialog */
|
|
|
|
return SELECT_CHARSET_CANCEL;
|
|
|
|
} else {
|
|
|
|
/* some charset has been selected */
|
|
|
|
if (seldisplay) {
|
|
|
|
/* charset list is finished with "Other 8 bit" item */
|
|
|
|
return (i >= n_codepages) ? SELECT_CHARSET_OTHER_8BIT : i;
|
|
|
|
} else {
|
|
|
|
/* charset list is began with "- < No translation >" item */
|
|
|
|
return (i - 1);
|
|
|
|
}
|
|
|
|
}
|
2001-05-31 05:27:20 +04:00
|
|
|
}
|
2001-06-06 02:28:11 +04:00
|
|
|
|
2009-06-14 19:05:57 +04:00
|
|
|
gboolean
|
2002-10-07 10:17:13 +04:00
|
|
|
do_select_codepage (void)
|
2001-06-06 02:28:11 +04:00
|
|
|
{
|
2009-06-14 19:05:57 +04:00
|
|
|
const char *errmsg = NULL;
|
2009-04-09 11:57:40 +04:00
|
|
|
int r;
|
2001-06-08 02:36:45 +04:00
|
|
|
|
2009-10-14 13:27:41 +04:00
|
|
|
r = select_charset (-1, -1, source_codepage, FALSE);
|
2009-06-14 19:05:57 +04:00
|
|
|
if (r == SELECT_CHARSET_CANCEL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
source_codepage = r;
|
2009-04-09 11:57:40 +04:00
|
|
|
|
2009-06-14 19:05:57 +04:00
|
|
|
errmsg = init_translation_table (r == SELECT_CHARSET_NO_TRANSLATE ?
|
|
|
|
display_codepage : source_codepage,
|
|
|
|
display_codepage);
|
|
|
|
if (errmsg != NULL)
|
2009-04-09 11:57:40 +04:00
|
|
|
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
2009-06-14 19:05:57 +04:00
|
|
|
|
|
|
|
return (errmsg == NULL);
|
2001-06-11 16:11:06 +04:00
|
|
|
}
|
2001-06-06 02:28:11 +04:00
|
|
|
|
2002-10-07 10:17:13 +04:00
|
|
|
#endif /* HAVE_CHARSET */
|