Mercurial > pidgin
annotate finch/finch.c @ 18303:5c6f019e48f8
Generate doxy-help files for libgnt. And make it actually work.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 27 Jun 2007 04:15:36 +0000 |
parents | b8572b937c09 |
children | 5aae8608e1c6 477dd067bdc1 |
rev | line source |
---|---|
15822 | 1 /** |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
2 * finch |
15822 | 3 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
4 * Finch is the legal property of its developers, whose names are too numerous |
15822 | 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 */ | |
18210
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18013
diff
changeset
|
22 #include "finch.h" |
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18013
diff
changeset
|
23 |
15822 | 24 #include "account.h" |
25 #include "conversation.h" | |
26 #include "core.h" | |
27 #include "debug.h" | |
28 #include "eventloop.h" | |
29 #include "ft.h" | |
30 #include "log.h" | |
31 #include "notify.h" | |
32 #include "prefs.h" | |
33 #include "prpl.h" | |
34 #include "pounce.h" | |
35 #include "savedstatuses.h" | |
36 #include "sound.h" | |
37 #include "status.h" | |
38 #include "util.h" | |
39 #include "whiteboard.h" | |
40 | |
41 #include "gntdebug.h" | |
42 #include "gntprefs.h" | |
43 #include "gntui.h" | |
44 #include "gntidle.h" | |
45 | |
46 #define _GNU_SOURCE | |
47 #include <getopt.h> | |
48 | |
49 #include "config.h" | |
50 | |
51 static void | |
52 debug_init() | |
53 { | |
54 finch_debug_init(); | |
55 purple_debug_set_ui_ops(finch_debug_get_ui_ops()); | |
56 } | |
57 | |
58 static PurpleCoreUiOps core_ops = | |
59 { | |
60 finch_prefs_init, | |
61 debug_init, | |
62 gnt_ui_init, | |
16669
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
63 gnt_ui_uninit, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
64 |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
65 /* padding */ |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
66 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
67 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
68 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
69 NULL |
15822 | 70 }; |
71 | |
72 static PurpleCoreUiOps * | |
73 gnt_core_get_ui_ops() | |
74 { | |
75 return &core_ops; | |
76 } | |
77 | |
78 /* Anything IO-related is directly copied from gtkpurple's source tree */ | |
79 | |
80 #define FINCH_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) | |
81 #define FINCH_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) | |
82 | |
83 typedef struct _PurpleGntIOClosure { | |
84 PurpleInputFunction function; | |
85 guint result; | |
86 gpointer data; | |
87 | |
88 } PurpleGntIOClosure; | |
89 | |
90 static void purple_gnt_io_destroy(gpointer data) | |
91 { | |
92 g_free(data); | |
93 } | |
94 | |
95 static gboolean purple_gnt_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data) | |
96 { | |
97 PurpleGntIOClosure *closure = data; | |
98 PurpleInputCondition purple_cond = 0; | |
99 | |
100 if (condition & FINCH_READ_COND) | |
101 purple_cond |= PURPLE_INPUT_READ; | |
102 if (condition & FINCH_WRITE_COND) | |
103 purple_cond |= PURPLE_INPUT_WRITE; | |
104 | |
105 #if 0 | |
106 purple_debug(PURPLE_DEBUG_MISC, "gtk_eventloop", | |
107 "CLOSURE: callback for %d, fd is %d\n", | |
108 closure->result, g_io_channel_unix_get_fd(source)); | |
109 #endif | |
110 | |
111 #ifdef _WIN32 | |
112 if(! purple_cond) { | |
113 #if DEBUG | |
114 purple_debug_misc("gnt_eventloop", | |
115 "CLOSURE received GIOCondition of 0x%x, which does not" | |
116 " match 0x%x (READ) or 0x%x (WRITE)\n", | |
117 condition, FINCH_READ_COND, FINCH_WRITE_COND); | |
118 #endif /* DEBUG */ | |
119 | |
120 return TRUE; | |
121 } | |
122 #endif /* _WIN32 */ | |
123 | |
124 closure->function(closure->data, g_io_channel_unix_get_fd(source), | |
125 purple_cond); | |
126 | |
127 return TRUE; | |
128 } | |
129 | |
130 static guint gnt_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, | |
131 gpointer data) | |
132 { | |
133 PurpleGntIOClosure *closure = g_new0(PurpleGntIOClosure, 1); | |
134 GIOChannel *channel; | |
135 GIOCondition cond = 0; | |
136 | |
137 closure->function = function; | |
138 closure->data = data; | |
139 | |
140 if (condition & PURPLE_INPUT_READ) | |
141 cond |= FINCH_READ_COND; | |
142 if (condition & PURPLE_INPUT_WRITE) | |
143 cond |= FINCH_WRITE_COND; | |
144 | |
145 channel = g_io_channel_unix_new(fd); | |
146 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, | |
147 purple_gnt_io_invoke, closure, purple_gnt_io_destroy); | |
148 | |
149 g_io_channel_unref(channel); | |
150 return closure->result; | |
151 } | |
152 | |
153 static PurpleEventLoopUiOps eventloop_ops = | |
154 { | |
155 g_timeout_add, | |
156 g_source_remove, | |
157 gnt_input_add, | |
158 g_source_remove, | |
16669
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
159 NULL, /* input_get_error */ |
18013
58e82c3b697e
It's GLIB_CHECK_VERSION, not GLIB_VERSION_CHECK.
Richard Laager <rlaager@wiktel.com>
parents:
18009
diff
changeset
|
160 #if GLIB_CHECK_VERSION(2,14,0) |
18009
9ffa9af32854
Wire in g_timeout_add_seconds for Finch and nullclient as well.
Richard Laager <rlaager@wiktel.com>
parents:
17049
diff
changeset
|
161 g_timeout_add_seconds, |
9ffa9af32854
Wire in g_timeout_add_seconds for Finch and nullclient as well.
Richard Laager <rlaager@wiktel.com>
parents:
17049
diff
changeset
|
162 #else |
9ffa9af32854
Wire in g_timeout_add_seconds for Finch and nullclient as well.
Richard Laager <rlaager@wiktel.com>
parents:
17049
diff
changeset
|
163 NULL, |
9ffa9af32854
Wire in g_timeout_add_seconds for Finch and nullclient as well.
Richard Laager <rlaager@wiktel.com>
parents:
17049
diff
changeset
|
164 #endif |
16669
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
165 |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
166 /* padding */ |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
167 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
168 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16565
diff
changeset
|
169 NULL |
15822 | 170 }; |
171 | |
172 static PurpleEventLoopUiOps * | |
173 gnt_eventloop_get_ui_ops(void) | |
174 { | |
175 return &eventloop_ops; | |
176 } | |
177 | |
178 /* This is mostly copied from gtkpurple's source tree */ | |
179 static void | |
180 show_usage(const char *name, gboolean terse) | |
181 { | |
182 char *text; | |
183 | |
184 if (terse) { | |
185 text = g_strdup_printf(_("%s. Try `%s -h' for more information.\n"), VERSION, name); | |
186 } else { | |
187 text = g_strdup_printf(_("%s\n" | |
188 "Usage: %s [OPTION]...\n\n" | |
189 " -c, --config=DIR use DIR for config files\n" | |
190 " -d, --debug print debugging messages to stdout\n" | |
191 " -h, --help display this help and exit\n" | |
192 " -n, --nologin don't automatically login\n" | |
193 " -v, --version display the current version and exit\n"), VERSION, name); | |
194 } | |
195 | |
196 purple_print_utf8_to_console(stdout, text); | |
197 g_free(text); | |
198 } | |
199 | |
200 static int | |
201 init_libpurple(int argc, char **argv) | |
202 { | |
203 char *path; | |
204 int opt; | |
205 gboolean opt_help = FALSE; | |
206 gboolean opt_nologin = FALSE; | |
207 gboolean opt_version = FALSE; | |
208 char *opt_config_dir_arg = NULL; | |
209 char *opt_session_arg = NULL; | |
210 gboolean debug_enabled = FALSE; | |
211 | |
212 struct option long_options[] = { | |
213 {"config", required_argument, NULL, 'c'}, | |
214 {"debug", no_argument, NULL, 'd'}, | |
215 {"help", no_argument, NULL, 'h'}, | |
216 {"nologin", no_argument, NULL, 'n'}, | |
217 {"session", required_argument, NULL, 's'}, | |
218 {"version", no_argument, NULL, 'v'}, | |
219 {0, 0, 0, 0} | |
220 }; | |
221 | |
222 #ifdef ENABLE_NLS | |
223 bindtextdomain(PACKAGE, LOCALEDIR); | |
224 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
225 textdomain(PACKAGE); | |
226 #endif | |
227 | |
228 #ifdef HAVE_SETLOCALE | |
229 setlocale(LC_ALL, ""); | |
230 #endif | |
231 | |
232 /* scan command-line options */ | |
233 opterr = 1; | |
234 while ((opt = getopt_long(argc, argv, | |
235 #ifndef _WIN32 | |
236 "c:dhn::s:v", | |
237 #else | |
238 "c:dhn::v", | |
239 #endif | |
240 long_options, NULL)) != -1) { | |
241 switch (opt) { | |
242 case 'c': /* config dir */ | |
243 g_free(opt_config_dir_arg); | |
244 opt_config_dir_arg = g_strdup(optarg); | |
245 break; | |
246 case 'd': /* debug */ | |
247 debug_enabled = TRUE; | |
248 break; | |
249 case 'h': /* help */ | |
250 opt_help = TRUE; | |
251 break; | |
252 case 'n': /* no autologin */ | |
253 opt_nologin = TRUE; | |
254 break; | |
255 case 's': /* use existing session ID */ | |
256 g_free(opt_session_arg); | |
257 opt_session_arg = g_strdup(optarg); | |
258 break; | |
259 case 'v': /* version */ | |
260 opt_version = TRUE; | |
261 break; | |
262 case '?': /* show terse help */ | |
263 default: | |
264 show_usage(argv[0], TRUE); | |
265 return 0; | |
266 break; | |
267 } | |
268 } | |
269 | |
270 /* show help message */ | |
271 if (opt_help) { | |
272 show_usage(argv[0], FALSE); | |
273 return 0; | |
274 } | |
275 /* show version message */ | |
276 if (opt_version) { | |
16943
816759ae9644
Clarify the comments on the names for translators.
Richard Laager <rlaager@wiktel.com>
parents:
16931
diff
changeset
|
277 /* Translators may want to transliterate the name. |
816759ae9644
Clarify the comments on the names for translators.
Richard Laager <rlaager@wiktel.com>
parents:
16931
diff
changeset
|
278 It is not to be translated. */ |
16931
dd768c576ab2
disapproval of revision 'e9933d653551beb8b5f477dcf2c6bd1f3d239c55'
Richard Laager <rlaager@wiktel.com>
parents:
16929
diff
changeset
|
279 printf("%s %s\n", _("Finch"), VERSION); |
15822 | 280 return 0; |
281 } | |
282 | |
283 /* set a user-specified config directory */ | |
284 if (opt_config_dir_arg != NULL) { | |
285 purple_util_set_user_dir(opt_config_dir_arg); | |
286 g_free(opt_config_dir_arg); | |
287 } | |
288 | |
289 /* | |
290 * We're done piddling around with command line arguments. | |
291 * Fire up this baby. | |
292 */ | |
293 | |
16380
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
294 /* We don't want debug-messages to show up and corrupt the display */ |
15822 | 295 purple_debug_set_enabled(debug_enabled); |
296 | |
16380
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
297 /* 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
|
298 * 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
|
299 if (opt_config_dir_arg == NULL) |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
300 { |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
301 if (!purple_core_migrate()) |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
302 { |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
303 char *old = g_strconcat(purple_home_dir(), |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
304 G_DIR_SEPARATOR_S ".gaim", NULL); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
305 char *text = g_strdup_printf(_( |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
306 "%s encountered errors migrating your settings " |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
307 "from %s to %s. Please investigate and complete the " |
16931
dd768c576ab2
disapproval of revision 'e9933d653551beb8b5f477dcf2c6bd1f3d239c55'
Richard Laager <rlaager@wiktel.com>
parents:
16929
diff
changeset
|
308 "migration by hand. Please report this error at http://developer.pidgin.im"), _("Finch"), |
16380
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
309 old, purple_user_dir()); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
310 |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
311 g_free(old); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
312 |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
313 purple_print_utf8_to_console(stderr, text); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
314 g_free(text); |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
315 |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
316 return 0; |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
317 } |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
318 } |
6c97924af83b
Call the migrate code from Finch.
Richard Laager <rlaager@wiktel.com>
parents:
16098
diff
changeset
|
319 |
15822 | 320 purple_core_set_ui_ops(gnt_core_get_ui_ops()); |
321 purple_eventloop_set_ui_ops(gnt_eventloop_get_ui_ops()); | |
322 purple_idle_set_ui_ops(finch_idle_get_ui_ops()); | |
323 | |
324 path = g_build_filename(purple_user_dir(), "plugins", NULL); | |
325 purple_plugins_add_search_path(path); | |
326 g_free(path); | |
327 | |
328 purple_plugins_add_search_path(LIBDIR); | |
329 | |
330 if (!purple_core_init(FINCH_UI)) | |
331 { | |
332 fprintf(stderr, | |
333 "Initialization of the Purple core failed. Dumping core.\n" | |
334 "Please report this!\n"); | |
335 abort(); | |
336 } | |
337 | |
338 /* TODO: Move blist loading into purple_blist_init() */ | |
339 purple_set_blist(purple_blist_new()); | |
340 purple_blist_load(); | |
341 | |
342 /* TODO: Move prefs loading into purple_prefs_init() */ | |
343 purple_prefs_load(); | |
344 purple_prefs_update_old(); | |
16565
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16525
diff
changeset
|
345 finch_prefs_update_old(); |
15822 | 346 |
347 /* load plugins we had when we quit */ | |
16424
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
|
348 purple_plugins_load_saved("/finch/plugins/loaded"); |
15822 | 349 |
350 /* TODO: Move pounces loading into purple_pounces_init() */ | |
351 purple_pounces_load(); | |
352 | |
353 if (opt_nologin) | |
354 { | |
355 /* Set all accounts to "offline" */ | |
356 PurpleSavedStatus *saved_status; | |
357 | |
358 /* If we've used this type+message before, lookup the transient status */ | |
359 saved_status = purple_savedstatus_find_transient_by_type_and_message( | |
360 PURPLE_STATUS_OFFLINE, NULL); | |
361 | |
362 /* If this type+message is unique then create a new transient saved status */ | |
363 if (saved_status == NULL) | |
364 saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE); | |
365 | |
366 /* Set the status for each account */ | |
367 purple_savedstatus_activate(saved_status); | |
368 } | |
369 else | |
370 { | |
371 /* Everything is good to go--sign on already */ | |
16424
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
|
372 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status")) |
15822 | 373 purple_savedstatus_activate(purple_savedstatus_get_startup()); |
374 purple_accounts_restore_current_statuses(); | |
375 } | |
376 | |
377 return 1; | |
378 } | |
379 | |
380 int main(int argc, char **argv) | |
381 { | |
382 signal(SIGPIPE, SIG_IGN); | |
383 | |
384 /* Initialize the libpurple stuff */ | |
385 if (!init_libpurple(argc, argv)) | |
386 return 0; | |
387 | |
388 purple_blist_show(); | |
389 gnt_main(); | |
390 | |
391 #ifdef STANDALONE | |
392 purple_core_quit(); | |
393 #endif | |
394 | |
395 return 0; | |
396 } | |
397 |