comparison src/gaim-remote.c @ 7724:613b20c69d2c

[gaim-migrate @ 8369] this didn't cause me any problems yesterday, and it compiles, and bug fixing is a good thing. "Some month ago I introduced translatable texts for "gaim --help" and "gaim-remote --help". Unfortunately the output of the translated text is often unreadable. The problem is, that Gaim's *.po files have the UTF-8 locale (because this is the default charset for GTK+ 2.0). But the users may have configured other locales. For instance my SuSE Linux 9.0 system is configured with LANG=de_DE@euro. "euro" is ISO-8859-1 (Western character set, 8 Bit, with the Euro currency symbol). Lots of UTF-8 characters are unreadable if they are displayed in a 8 Bit charset without conversion. Only the 7 Bit chars are displayed right. There are two possible solutions: 1) Make the console texts untranslatable. This isn't very clever. 2) Convert the texts from UTF-8 to user's locale. I choose the second solution. The conversion cannot be made during the translation, because gettext does not allow a mix of different character sets in one po-file. My patch converts the console strings from UTF-8 to users locale. Normally this works right, because most users have a locale which is compatible with their language. The case where a user uses a language (for instance German: LANG=de_DE) with an incompatible character set (for instance the 7Bit charset LC_CTYPE=C) is also handled. The user then sees a warning and the original UTF-8 message. At first I tried to make a new UTF-8 function in src/util.c. But the function is needed 5 times in src/gaim-remote.c and 2 times in src/main.c. gaim-remote is not linked against util.o. Also there are a lot of dependencies from util.o to other files, so I will introduce a lot of trouble to link gaim-remote against util.o. So I only wrote a function in src/gaim-remote.c and used the UTF-8 conversion inline in src/main.c." --Bjoern Voigt committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 03 Dec 2003 13:21:55 +0000
parents 0dfe02111e20
children fa6395637e2c
comparison
equal deleted inserted replaced
7723:9235eecc9f74 7724:613b20c69d2c
26 #include <getopt.h> 26 #include <getopt.h>
27 #include <locale.h> 27 #include <locale.h>
28 28
29 #include <gaim-remote/remote.h> 29 #include <gaim-remote/remote.h>
30 30
31 /* writes a message 'text' to screen
32 * message tries to convert 'text' from utf-8 to user's locale and
33 * uses the original message 'text' as a fallback
34 *
35 * if channel is 1, the message is printed to stdout
36 * if channel is 2, the message is printed to stderr
37 */
38 void message(char *text,int channel)
39 {
40 char *text_conv=NULL,*text_output;
41 GError *error=NULL;
42
43 text_conv=g_locale_from_utf8(text,-1,NULL,NULL,&error);
44
45 if(!text_conv) {
46 g_warning("%s\n", error->message);
47 g_error_free(error);
48 }
49
50 text_output=(text_conv ? text_conv : text);
51
52 switch(channel) {
53 case 1: puts(text_output); break;
54 case 2: fputs(text_output, stderr); break;
55 default: break;
56 }
57
58 if(text_conv)
59 g_free(text_conv);
60 }
61
31 void show_remote_usage(char *name) 62 void show_remote_usage(char *name)
32 { 63 {
33 printf(_("Usage: %s command [OPTIONS] [URI]\n\n" 64 char *text=NULL;
65
66 text=g_strdup_printf(_("Usage: %s command [OPTIONS] [URI]\n\n"
34 67
35 " COMMANDS:\n" 68 " COMMANDS:\n"
36 " uri Handle AIM: URI\n" 69 " uri Handle AIM: URI\n"
37 " quit Close running copy of Gaim\n\n" 70 " quit Close running copy of Gaim\n\n"
38 71
39 " OPTIONS:\n" 72 " OPTIONS:\n"
40 " -h, --help [commmand] Show help for command\n"), name); 73 " -h, --help [commmand] Show help for command\n"), name);
74
75 message(text,1);
76 g_free(text);
77
41 return; 78 return;
42 } 79 }
43 80
44 /*To be implemented: 81 /*To be implemented:
45 " info Show information about connected accounts\n" 82 " info Show information about connected accounts\n"
128 return 1; 165 return 1;
129 166
130 return 0; 167 return 0;
131 } 168 }
132 169
133
134 int command_uri() { 170 int command_uri() {
135 int fd = 0; 171 int fd = 0;
136 GaimRemotePacket *p = NULL; 172 GaimRemotePacket *p = NULL;
137 fd = gaim_remote_session_connect(0); 173 fd = gaim_remote_session_connect(0);
138 if (fd<0) { 174 if (fd<0) {
139 fprintf(stderr, _("Gaim not running (on session 0)\n")); 175 message(_("Gaim not running (on session 0)\n"),2);
140 return 1; 176 return 1;
141 } 177 }
142 p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI); 178 p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI);
143 gaim_remote_packet_append_string(p, opts.uri); 179 gaim_remote_packet_append_string(p, opts.uri);
144 gaim_remote_session_send_packet(fd, p); 180 gaim_remote_session_send_packet(fd, p);
150 int command_quit() { 186 int command_quit() {
151 int fd = 0; 187 int fd = 0;
152 GaimRemotePacket *p = NULL; 188 GaimRemotePacket *p = NULL;
153 fd = gaim_remote_session_connect(0); 189 fd = gaim_remote_session_connect(0);
154 if (fd<0) { 190 if (fd<0) {
155 fprintf(stderr, _("Gaim not running (on session 0)\n")); 191 message(_("Gaim not running (on session 0)\n"),2);
156 return 1; 192 return 1;
157 } 193 }
158 p = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_QUIT); 194 p = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_QUIT);
159 gaim_remote_session_send_packet(fd, p); 195 gaim_remote_session_send_packet(fd, p);
160 close(fd); 196 close(fd);
161 gaim_remote_packet_free(p); 197 gaim_remote_packet_free(p);
162 return 0; 198 return 0;
163 } 199 }
164 200
165 void show_longhelp_uri( char *name, char *command){ 201 void show_longhelp_uri( char *name, char *command)
202 {
166 if(!strcmp(command, "uri")) { 203 if(!strcmp(command, "uri")) {
167 printf (_("\n" 204 message(_("\n"
168 "Using AIM: URIs:\n" 205 "Using AIM: URIs:\n"
169 "Sending an IM to a screenname:\n" 206 "Sending an IM to a screenname:\n"
170 " gaim-remote uri 'aim:goim?screenname=Penguin&message=hello+world'\n" 207 " gaim-remote uri 'aim:goim?screenname=Penguin&message=hello+world'\n"
171 "In this case, 'Penguin' is the screenname we wish to IM, and 'hello world'\n" 208 "In this case, 'Penguin' is the screenname we wish to IM, and 'hello world'\n"
172 "is the message to be sent. '+' must be used in place of spaces.\n" 209 "is the message to be sent. '+' must be used in place of spaces.\n"
173 "Please note the quoting used above - if you run this from a shell the '&'\n" 210 "Please note the quoting used above - if you run this from a shell the '&'\n"
174 "needs to be escaped, or the command will stop at that point.\n" 211 "needs to be escaped, or the command will stop at that point.\n"
175 "Also,the following will just open a conversation window to a screenname,\n" 212 "Also,the following will just open a conversation window to a screenname,\n"
176 "with no message:\n" 213 "with no message:\n"
177 " gaim-remote uri aim:goim?screenname=Penguin\n\n" 214 " gaim-remote uri 'aim:goim?screenname=Penguin'\n\n"
178 "Joining a chat:\n" 215 "Joining a chat:\n"
179 " gaim-remote uri aim:gochat?roomname=PenguinLounge\n" 216 " gaim-remote uri 'aim:gochat?roomname=PenguinLounge'\n"
180 "...joins the 'PenguinLounge' chat room.\n\n" 217 "...joins the 'PenguinLounge' chat room.\n\n"
181 "Adding a buddy to your buddy list:\n" 218 "Adding a buddy to your buddy list:\n"
182 " gaim-remote uri aim:addbuddy?screenname=Penguin\n" 219 " gaim-remote uri 'aim:addbuddy?screenname=Penguin'\n"
183 "...prompts you to add 'Penguin' to your buddy list.\n") 220 "...prompts you to add 'Penguin' to your buddy list.\n"), 1);
184 );
185 } 221 }
186 else if(!strcmp(command, "quit")) { 222 else if(!strcmp(command, "quit")) {
187 printf (_("\nClose running copy of Gaim\n")); 223 message(_("\nClose running copy of Gaim\n"), 1);
188 } 224 }
189 else { 225 else {
190 show_remote_usage(name); 226 show_remote_usage(name);
191 } 227 }
192 } 228 }