|
GnuCash 2.4.99
|
00001 /* 00002 * qof-win32.c 00003 * 00004 * Copyright (C) 2007 Andreas Koehler <andi5.py@gmx.net> 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License as 00008 * published by the Free Software Foundation; either version 2 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, contact: 00018 * 00019 * Free Software Foundation Voice: +1-617-542-5942 00020 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00021 * Boston, MA 02110-1301, USA gnu@gnu.org 00022 */ 00023 00024 #include "config.h" 00025 00026 #include <glib.h> 00027 #include "gnc-date-p.h" 00028 #include "strptime.h" 00029 #include <windows.h> 00030 #include <stdlib.h> 00031 00032 static GHashTable *picture_to_format = NULL; 00033 G_LOCK_DEFINE_STATIC(picture_to_format); 00034 00035 gchar * 00036 qof_time_format_from_utf8(const gchar *utf8_format) 00037 { 00038 gunichar2 *utf16_format; 00039 gchar *retval; 00040 gsize count; 00041 00042 utf16_format = g_utf8_to_utf16(utf8_format, -1, NULL, NULL, NULL); 00043 if (!utf16_format) 00044 return NULL; 00045 00046 /* get number of resulting wide characters */ 00047 count = wcstombs(NULL, utf16_format, 0); 00048 if (count <= 0) 00049 return NULL; 00050 00051 /* malloc and convert */ 00052 retval = g_malloc((count + 1) * sizeof(gchar)); 00053 count = wcstombs(retval, utf16_format, count + 1); 00054 g_free(utf16_format); 00055 if (count <= 0) 00056 { 00057 g_free(retval); 00058 return NULL; 00059 } 00060 00061 return retval; 00062 } 00063 00064 gchar * 00065 qof_formatted_time_to_utf8(const gchar *locale_string) 00066 { 00067 gunichar2 *utf16_string; 00068 gchar *retval; 00069 gsize count; 00070 00071 /* get number of resulting wide characters */ 00072 count = mbstowcs(NULL, locale_string, 0); 00073 if (count <= 0) 00074 return NULL; 00075 00076 /* malloc and convert */ 00077 utf16_string = g_malloc((count + 1) * sizeof(gunichar2)); 00078 count = mbstowcs(utf16_string, locale_string, count + 1); 00079 if (count <= 0) 00080 { 00081 g_free(utf16_string); 00082 return NULL; 00083 } 00084 00085 retval = g_utf16_to_utf8(utf16_string, -1, NULL, NULL, NULL); 00086 g_free(utf16_string); 00087 00088 return retval; 00089 } 00090 00091 const char * 00092 qof_win32_get_time_format(QofWin32Picture picture) 00093 { 00094 gchar *locale_string, *format; 00095 gchar *tmp1, *tmp2; 00096 00097 switch (picture) 00098 { 00099 case QOF_WIN32_PICTURE_DATE: 00100 locale_string = get_win32_locale_string(LOCALE_SSHORTDATE); 00101 break; 00102 case QOF_WIN32_PICTURE_TIME: 00103 locale_string = get_win32_locale_string(LOCALE_STIMEFORMAT); 00104 break; 00105 case QOF_WIN32_PICTURE_DATETIME: 00106 tmp1 = get_win32_locale_string(LOCALE_SSHORTDATE); 00107 tmp2 = get_win32_locale_string(LOCALE_STIMEFORMAT); 00108 locale_string = g_strconcat(tmp1, " ", tmp2, NULL); 00109 g_free(tmp1); 00110 g_free(tmp2); 00111 break; 00112 default: 00113 g_assert_not_reached(); 00114 } 00115 00116 G_LOCK(picture_to_format); 00117 if (!picture_to_format) 00118 picture_to_format = g_hash_table_new_full(g_str_hash, g_str_equal, 00119 NULL, g_free); 00120 format = g_hash_table_lookup(picture_to_format, locale_string); 00121 if (!format) 00122 { 00123 format = translate_win32_picture(locale_string); 00124 g_hash_table_insert(picture_to_format, g_strdup(locale_string), format); 00125 } 00126 G_UNLOCK(picture_to_format); 00127 g_free(locale_string); 00128 00129 return format; 00130 }
1.7.4