Mercurial > pidgin.yaz
annotate finch/finch.c @ 16668:64ce75d3efd4
merge of '3e6c08926429636e5eadf17843abfe92b855e24b'
and '5b88699a08a051f63111f06a71fb6735fac2a568'
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 29 Apr 2007 19:48:14 +0000 |
parents | ac0d07c7fd90 |
children | 30829e806dae |
rev | line source |
---|---|
15823 | 1 /** |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
2 * finch |
15823 | 3 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
4 * Finch is the legal property of its developers, whose names are too numerous |
15823 | 5 * to list here. Please refer to the COPYRIGHT file distributed with this |
6 * source distribution. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #include "account.h" | |
23 #include "conversation.h" | |
24 #include "core.h" | |
25 #include "debug.h" | |
26 #include "eventloop.h" | |
27 #include "ft.h" | |
28 #include "log.h" | |
29 #include "notify.h" | |
30 #include "prefs.h" | |
31 #include "prpl.h" | |
32 #include "pounce.h" | |
33 #include "savedstatuses.h" | |
34 #include "sound.h" | |
35 #include "status.h" | |
36 #include "util.h" | |
37 #include "whiteboard.h" | |
38 | |
39 #include "gntdebug.h" | |
40 #include "finch.h" | |
41 #include "gntprefs.h" | |
42 #include "gntui.h" | |
43 #include "gntidle.h" | |
44 | |
45 #define _GNU_SOURCE | |
46 #include <getopt.h> | |
47 | |
48 #include "config.h" | |
49 | |
50 static void | |
51 debug_init() | |
52 { | |
53 finch_debug_init(); | |
54 purple_debug_set_ui_ops(finch_debug_get_ui_ops()); | |
55 } | |
56 | |
57 static PurpleCoreUiOps core_ops = | |
58 { | |
59 finch_prefs_init, | |
60 debug_init, | |
61 gnt_ui_init, | |
62 gnt_ui_uninit | |
63 }; | |
64 | |
65 static PurpleCoreUiOps * | |
66 gnt_core_get_ui_ops() | |
67 { | |
68 return &core_ops; | |
69 } | |
70 | |
71 /* Anything IO-related is directly copied from gtkpurple's source tree */ | |
72 | |
73 #define FINCH_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) | |
74 #define FINCH_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) | |
75 | |
76 typedef struct _PurpleGntIOClosure { | |
77 PurpleInputFunction function; | |
78 guint result; | |
79 gpointer data; | |
80 | |
81 } PurpleGntIOClosure; | |
82 | |
83 static void purple_gnt_io_destroy(gpointer data) | |
84 { | |
85 g_free(data); | |
86 } | |
87 | |
88 static gboolean purple_gnt_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data) | |
89 { | |
90 PurpleGntIOClosure *closure = data; | |
91 PurpleInputCondition purple_cond = 0; | |
92 | |
93 if (condition & FINCH_READ_COND) | |
94 purple_cond |= PURPLE_INPUT_READ; | |
95 if (condition & FINCH_WRITE_COND) | |
96 purple_cond |= PURPLE_INPUT_WRITE; | |
97 | |
98 #if 0 | |
99 purple_debug(PURPLE_DEBUG_MISC, "gtk_eventloop", | |
100 "CLOSURE: callback for %d, fd is %d\n", | |
101 closure->result, g_io_channel_unix_get_fd(source)); | |
102 #endif | |
103 | |
104 #ifdef _WIN32 | |
105 if(! purple_cond) { | |
106 #if DEBUG | |
107 purple_debug_misc("gnt_eventloop", | |
108 "CLOSURE received GIOCondition of 0x%x, which does not" | |
109 " match 0x%x (READ) or 0x%x (WRITE)\n", | |
110 condition, FINCH_READ_COND, FINCH_WRITE_COND); | |
111 #endif /* DEBUG */ | |
112 | |
113 return TRUE; | |
114 } | |
115 #endif /* _WIN32 */ | |
116 | |
117 closure->function(closure->data, g_io_channel_unix_get_fd(source), | |
118 purple_cond); | |
119 | |
120 return TRUE; | |
121 } | |
122 | |
123 static guint gnt_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, | |
124 gpointer data) | |
125 { | |
126 PurpleGntIOClosure *closure = g_new0(PurpleGntIOClosure, 1); | |
127 GIOChannel *channel; | |
128 GIOCondition cond = 0; | |
129 | |
130 closure->function = function; | |
131 closure->data = data; | |
132 | |
133 if (condition & PURPLE_INPUT_READ) | |
134 cond |= FINCH_READ_COND; | |
135 if (condition & PURPLE_INPUT_WRITE) | |
136 cond |= FINCH_WRITE_COND; | |
137 | |
138 channel = g_io_channel_unix_new(fd); | |
139 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, | |
140 purple_gnt_io_invoke, closure, purple_gnt_io_destroy); | |
141 | |
142 g_io_channel_unref(channel); | |
143 return closure->result; | |
144 } | |
145 | |
146 static PurpleEventLoopUiOps eventloop_ops = | |
147 { | |
148 g_timeout_add, | |
149 g_source_remove, | |
150 gnt_input_add, | |
151 g_source_remove, | |
152 NULL /* input_get_error */ | |
153 }; | |
154 | |
155 static PurpleEventLoopUiOps * | |
156 gnt_eventloop_get_ui_ops(void) | |
157 { | |
158 return &eventloop_ops; | |
159 } | |
160 | |
161 /* This is mostly copied from gtkpurple's source tree */ | |
162 static void | |
163 show_usage(const char *name, gboolean terse) | |
164 { | |
165 char *text; | |
166 | |
167 if (terse) { | |
168 text = g_strdup_printf(_("%s. Try `%s -h' for more information.\n"), VERSION, name); | |
169 } else { | |
170 text = g_strdup_printf(_("%s\n" | |
171 "Usage: %s [OPTION]...\n\n" | |
172 " -c, --config=DIR use DIR for config files\n" | |
173 " -d, --debug print debugging messages to stdout\n" | |
174 " -h, --help display this help and exit\n" | |
175 " -n, --nologin don't automatically login\n" | |
176 " -v, --version display the current version and exit\n"), VERSION, name); | |
177 } | |
178 | |
179 purple_print_utf8_to_console(stdout, text); | |
180 g_free(text); | |
181 } | |
182 | |
183 static int | |
184 init_libpurple(int argc, char **argv) | |
185 { | |
186 char *path; | |
187 int opt; | |
188 gboolean opt_help = FALSE; | |
189 gboolean opt_nologin = FALSE; | |
190 gboolean opt_version = FALSE; | |
191 char *opt_config_dir_arg = NULL; | |
192 char *opt_session_arg = NULL; | |
193 gboolean debug_enabled = FALSE; | |
194 | |
195 struct option long_options[] = { | |
196 {"config", required_argument, NULL, 'c'}, | |
197 {"debug", no_argument, NULL, 'd'}, | |
198 {"help", no_argument, NULL, 'h'}, | |
199 {"nologin", no_argument, NULL, 'n'}, | |
200 {"session", required_argument, NULL, 's'}, | |
201 {"version", no_argument, NULL, 'v'}, | |
202 {0, 0, 0, 0} | |
203 }; | |
204 | |
16533
2da3e5a69ebc
Add the fatal asserts enabling code to Finch. I'm uneasy about putting this in libpurple, because then a fatal-asserts-enabled libpurple would kill any UI that had a glib debug error, which might not even be in libpurple. I'm not sure we want that, though it may not matter since this is for debugging only.
Richard Laager <rlaager@wiktel.com>
parents:
16483
diff
changeset
|
205 #ifdef PURPLE_FATAL_ASSERTS |
2da3e5a69ebc
Add the fatal asserts enabling code to Finch. I'm uneasy about putting this in libpurple, because then a fatal-asserts-enabled libpurple would kill any UI that had a glib debug error, which might not even be in libpurple. I'm not sure we want that, though it may not matter since this is for debugging only.
Richard Laager <rlaager@wiktel.com>
parents:
16483
diff
changeset
|
206 /* Make g_return_... functions fatal. */ |
2da3e5a69ebc
Add the fatal asserts enabling code to Finch. I'm uneasy about putting this in libpurple, because then a fatal-asserts-enabled libpurple would kill any UI that had a glib debug error, which might not even be in libpurple. I'm not sure we want that, though it may not matter since this is for debugging only.
Richard Laager <rlaager@wiktel.com>
parents:
16483
diff
changeset
|
207 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); |
2da3e5a69ebc
Add the fatal asserts enabling code to Finch. I'm uneasy about putting this in libpurple, because then a fatal-asserts-enabled libpurple would kill any UI that had a glib debug error, which might not even be in libpurple. I'm not sure we want that, though it may not matter since this is for debugging only.
Richard Laager <rlaager@wiktel.com>
parents:
16483
diff
changeset
|
208 #endif |
2da3e5a69ebc
Add the fatal asserts enabling code to Finch. I'm uneasy about putting this in libpurple, because then a fatal-asserts-enabled libpurple would kill any UI that had a glib debug error, which might not even be in libpurple. I'm not sure we want that, though it may not matter since this is for debugging only.
Richard Laager <rlaager@wiktel.com>
parents:
16483
diff
changeset
|
209 |
15823 | 210 #ifdef ENABLE_NLS |
211 bindtextdomain(PACKAGE, LOCALEDIR); | |
212 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
213 textdomain(PACKAGE); | |
214 #endif | |
215 | |
216 #ifdef HAVE_SETLOCALE | |
217 setlocale(LC_ALL, ""); | |
218 #endif | |
219 | |
220 /* scan command-line options */ | |
221 opterr = 1; | |
222 while ((opt = getopt_long(argc, argv, | |
223 #ifndef _WIN32 | |
224 "c:dhn::s:v", | |
225 #else | |
226 "c:dhn::v", | |
227 #endif | |
228 long_options, NULL)) != -1) { | |
229 switch (opt) { | |
230 case 'c': /* config dir */ | |
231 g_free(opt_config_dir_arg); | |
232 opt_config_dir_arg = g_strdup(optarg); | |
233 break; | |
234 case 'd': /* debug */ | |
235 debug_enabled = TRUE; | |
236 break; | |
237 case 'h': /* help */ | |
238 opt_help = TRUE; | |
239 break; | |
240 case 'n': /* no autologin */ | |
241 opt_nologin = TRUE; | |
242 break; | |
243 case 's': /* use existing session ID */ | |
244 g_free(opt_session_arg); | |
245 opt_session_arg = g_strdup(optarg); | |
246 break; | |
247 case 'v': /* version */ | |
248 opt_version = TRUE; | |
249 break; | |
250 case '?': /* show terse help */ | |
251 default: | |
252 show_usage(argv[0], TRUE); | |
253 return 0; | |
254 break; | |
255 } | |
256 } | |
257 | |
258 /* show help message */ | |
259 if (opt_help) { | |
260 show_usage(argv[0], FALSE); | |
261 return 0; | |
262 } | |
263 /* show version message */ | |
264 if (opt_version) { | |
16081 | 265 printf("Finch %s\n", VERSION); |
15823 | 266 return 0; |
267 } | |
268 | |
269 /* set a user-specified config directory */ | |
270 if (opt_config_dir_arg != NULL) { | |
271 purple_util_set_user_dir(opt_config_dir_arg); | |
272 g_free(opt_config_dir_arg); | |
273 } | |
274 | |
275 /* | |
276 * We're done piddling around with command line arguments. | |
277 * Fire up this baby. | |
278 */ | |
279 | |
16380
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
280 /* We don't want debug-messages to show up and corrupt the display */ |
15823 | 281 purple_debug_set_enabled(debug_enabled); |
282 | |
16380
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
283 /* If we're using a custom configuration directory, we |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
284 * do NOT want to migrate, or weird things will happen. */ |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
285 if (opt_config_dir_arg == NULL) |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
286 { |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
287 if (!purple_core_migrate()) |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
288 { |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
289 char *old = g_strconcat(purple_home_dir(), |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
290 G_DIR_SEPARATOR_S ".gaim", NULL); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
291 char *text = g_strdup_printf(_( |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
292 "%s encountered errors migrating your settings " |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
293 "from %s to %s. Please investigate and complete the " |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
294 "migration by hand."), _("Finch"), |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
295 old, purple_user_dir()); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
296 |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
297 g_free(old); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
298 |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
299 purple_print_utf8_to_console(stderr, text); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
300 g_free(text); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
301 |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
302 return 0; |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
303 } |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
304 } |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
305 |
15823 | 306 purple_core_set_ui_ops(gnt_core_get_ui_ops()); |
307 purple_eventloop_set_ui_ops(gnt_eventloop_get_ui_ops()); | |
308 purple_idle_set_ui_ops(finch_idle_get_ui_ops()); | |
309 | |
310 path = g_build_filename(purple_user_dir(), "plugins", NULL); | |
311 purple_plugins_add_search_path(path); | |
312 g_free(path); | |
313 | |
314 purple_plugins_add_search_path(LIBDIR); | |
315 | |
316 if (!purple_core_init(FINCH_UI)) | |
317 { | |
318 fprintf(stderr, | |
319 "Initialization of the Purple core failed. Dumping core.\n" | |
320 "Please report this!\n"); | |
321 abort(); | |
322 } | |
323 | |
324 /* TODO: Move blist loading into purple_blist_init() */ | |
325 purple_set_blist(purple_blist_new()); | |
326 purple_blist_load(); | |
327 | |
328 /* TODO: Move prefs loading into purple_prefs_init() */ | |
329 purple_prefs_load(); | |
330 purple_prefs_update_old(); | |
16573
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16533
diff
changeset
|
331 finch_prefs_update_old(); |
15823 | 332 |
333 /* load plugins we had when we quit */ | |
16427
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16098
diff
changeset
|
334 purple_plugins_load_saved("/finch/plugins/loaded"); |
15823 | 335 |
336 /* TODO: Move pounces loading into purple_pounces_init() */ | |
337 purple_pounces_load(); | |
338 | |
339 if (opt_nologin) | |
340 { | |
341 /* Set all accounts to "offline" */ | |
342 PurpleSavedStatus *saved_status; | |
343 | |
344 /* If we've used this type+message before, lookup the transient status */ | |
345 saved_status = purple_savedstatus_find_transient_by_type_and_message( | |
346 PURPLE_STATUS_OFFLINE, NULL); | |
347 | |
348 /* If this type+message is unique then create a new transient saved status */ | |
349 if (saved_status == NULL) | |
350 saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE); | |
351 | |
352 /* Set the status for each account */ | |
353 purple_savedstatus_activate(saved_status); | |
354 } | |
355 else | |
356 { | |
357 /* Everything is good to go--sign on already */ | |
16427
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16098
diff
changeset
|
358 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status")) |
15823 | 359 purple_savedstatus_activate(purple_savedstatus_get_startup()); |
360 purple_accounts_restore_current_statuses(); | |
361 } | |
362 | |
363 return 1; | |
364 } | |
365 | |
366 int main(int argc, char **argv) | |
367 { | |
368 signal(SIGPIPE, SIG_IGN); | |
369 | |
370 /* Initialize the libpurple stuff */ | |
371 if (!init_libpurple(argc, argv)) | |
372 return 0; | |
373 | |
374 purple_blist_show(); | |
375 gnt_main(); | |
376 | |
377 #ifdef STANDALONE | |
378 purple_core_quit(); | |
379 #endif | |
380 | |
381 return 0; | |
382 } | |
383 |