2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
User interface for charset selection.
|
2002-08-27 09:27:11 +04:00
|
|
|
|
|
|
|
Copyright (C) 2001 Walery Studennikov <despair@sama.ru>
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2011-2024
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2002-08-27 09:27:11 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
Written by:
|
|
|
|
Walery Studennikov <despair@sama.ru>, 2001
|
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander 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 3 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
2002-08-27 09:27:11 +04:00
|
|
|
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
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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
|
|
|
#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"
|
2010-11-12 11:03:57 +03:00
|
|
|
#include "lib/widget.h"
|
2010-11-18 11:31:09 +03:00
|
|
|
#include "lib/charsets.h"
|
2010-11-10 22:45:56 +03:00
|
|
|
|
2012-10-19 13:08:54 +04:00
|
|
|
#include "setup.h"
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
#include "selcodepage.h"
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
#define ENTRY_LEN 30
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/*** forward declarations (file scope functions) *************************************************/
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
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
|
|
|
{
|
2023-03-18 09:45:24 +03:00
|
|
|
Listbox *listbox;
|
2010-10-21 11:34:27 +04:00
|
|
|
size_t i;
|
|
|
|
int listbox_result;
|
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 */
|
2023-03-18 09:45:24 +03:00
|
|
|
listbox =
|
|
|
|
listbox_window_centered_new (center_y, center_x, codepages->len + 1, ENTRY_LEN + 2,
|
|
|
|
_("Choose codepage"), "[Codepages Translation]");
|
2001-05-31 05:27:20 +04:00
|
|
|
|
|
|
|
if (!seldisplay)
|
2015-10-04 15:14:16 +03:00
|
|
|
LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"), NULL, FALSE);
|
2001-05-31 05:27:20 +04:00
|
|
|
|
|
|
|
/* insert all the items found */
|
2010-11-10 14:09:42 +03:00
|
|
|
for (i = 0; i < codepages->len; i++)
|
|
|
|
{
|
2024-03-31 19:12:40 +03:00
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = ((codepage_desc *) g_ptr_array_index (codepages, i))->name;
|
2010-11-10 14:09:42 +03:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i), name);
|
2015-10-04 15:14:16 +03:00
|
|
|
LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL, FALSE);
|
2001-05-31 05:27:20 +04:00
|
|
|
}
|
2024-03-31 19:12:40 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (seldisplay)
|
|
|
|
{
|
2024-03-31 19:12:40 +03:00
|
|
|
unsigned char hotkey;
|
|
|
|
|
|
|
|
hotkey = get_hotkey (codepages->len);
|
2010-11-10 14:09:42 +03:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "%c %s", hotkey, _("Other 8 bit"));
|
2015-10-04 15:14:16 +03:00
|
|
|
LISTBOX_APPEND_TEXT (listbox, hotkey, buffer, NULL, FALSE);
|
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 */
|
2024-03-31 19:12:40 +03:00
|
|
|
i = seldisplay
|
2010-11-10 14:09:42 +03:00
|
|
|
? ((current_charset < 0) ? codepages->len : (size_t) current_charset)
|
|
|
|
: ((size_t) current_charset + 1);
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2023-04-15 14:56:07 +03:00
|
|
|
listbox_set_current (listbox->list, i);
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2023-03-18 09:45:24 +03:00
|
|
|
listbox_result = listbox_run (listbox);
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (listbox_result < 0)
|
|
|
|
/* Cancel dialog */
|
|
|
|
return SELECT_CHARSET_CANCEL;
|
2024-03-31 19:12:40 +03:00
|
|
|
|
|
|
|
/* some charset has been selected */
|
|
|
|
if (seldisplay)
|
|
|
|
/* charset list is finished with "Other 8 bit" item */
|
2024-06-01 21:12:14 +03:00
|
|
|
return (listbox_result >=
|
|
|
|
(int) codepages->len) ? SELECT_CHARSET_OTHER_8BIT : listbox_result;
|
2024-03-31 19:12:40 +03:00
|
|
|
|
|
|
|
/* charset list is began with "- < No translation >" item */
|
|
|
|
return (listbox_result - 1);
|
2001-05-31 05:27:20 +04:00
|
|
|
}
|
2001-06-06 02:28:11 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/** Set codepage */
|
2009-06-14 19:05:57 +04:00
|
|
|
gboolean
|
2010-02-05 14:02:47 +03:00
|
|
|
do_set_codepage (int codepage)
|
2001-06-06 02:28:11 +04:00
|
|
|
{
|
2010-03-31 14:02:45 +04:00
|
|
|
char *errmsg;
|
|
|
|
gboolean ret;
|
2009-06-14 19:05:57 +04:00
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.source_codepage = codepage;
|
2010-02-05 14:02:47 +03:00
|
|
|
errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ?
|
2011-10-15 14:56:47 +04:00
|
|
|
mc_global.display_codepage : mc_global.source_codepage,
|
|
|
|
mc_global.display_codepage);
|
2010-03-31 14:02:45 +04:00
|
|
|
ret = errmsg == NULL;
|
2009-06-14 19:05:57 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
|
|
|
g_free (errmsg);
|
2010-03-31 14:02:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2001-06-11 16:11:06 +04:00
|
|
|
}
|
2001-06-06 02:28:11 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-02-05 14:02:47 +03:00
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/** Show menu selecting codepage */
|
2010-02-05 14:02:47 +03:00
|
|
|
gboolean
|
|
|
|
do_select_codepage (void)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = select_charset (-1, -1, default_source_codepage, FALSE);
|
|
|
|
if (r == SELECT_CHARSET_CANCEL)
|
2010-11-10 14:09:42 +03:00
|
|
|
return FALSE;
|
2010-02-05 14:02:47 +03:00
|
|
|
|
|
|
|
default_source_codepage = r;
|
|
|
|
return do_set_codepage (default_source_codepage);
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|