4 * Finch is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
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.
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.
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
23 #include "conversation.h"
26 #include "eventloop.h"
33 #include "savedstatuses.h"
37 #include "whiteboard.h"
54 purple_debug_set_ui_ops(finch_debug_get_ui_ops());
57 static PurpleCoreUiOps core_ops
=
71 static PurpleCoreUiOps
*
77 /* Anything IO-related is directly copied from gtkpurple's source tree */
79 #define FINCH_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
80 #define FINCH_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
82 typedef struct _PurpleGntIOClosure
{
83 PurpleInputFunction function
;
89 static void purple_gnt_io_destroy(gpointer data
)
94 static gboolean
purple_gnt_io_invoke(GIOChannel
*source
, GIOCondition condition
, gpointer data
)
96 PurpleGntIOClosure
*closure
= data
;
97 PurpleInputCondition purple_cond
= 0;
99 if (condition
& FINCH_READ_COND
)
100 purple_cond
|= PURPLE_INPUT_READ
;
101 if (condition
& FINCH_WRITE_COND
)
102 purple_cond
|= PURPLE_INPUT_WRITE
;
105 purple_debug(PURPLE_DEBUG_MISC
, "gtk_eventloop",
106 "CLOSURE: callback for %d, fd is %d\n",
107 closure
->result
, g_io_channel_unix_get_fd(source
));
113 purple_debug_misc("gnt_eventloop",
114 "CLOSURE received GIOCondition of 0x%x, which does not"
115 " match 0x%x (READ) or 0x%x (WRITE)\n",
116 condition
, FINCH_READ_COND
, FINCH_WRITE_COND
);
123 closure
->function(closure
->data
, g_io_channel_unix_get_fd(source
),
129 static guint
gnt_input_add(gint fd
, PurpleInputCondition condition
, PurpleInputFunction function
,
132 PurpleGntIOClosure
*closure
= g_new0(PurpleGntIOClosure
, 1);
134 GIOCondition cond
= 0;
136 closure
->function
= function
;
137 closure
->data
= data
;
139 if (condition
& PURPLE_INPUT_READ
)
140 cond
|= FINCH_READ_COND
;
141 if (condition
& PURPLE_INPUT_WRITE
)
142 cond
|= FINCH_WRITE_COND
;
144 channel
= g_io_channel_unix_new(fd
);
145 closure
->result
= g_io_add_watch_full(channel
, G_PRIORITY_DEFAULT
, cond
,
146 purple_gnt_io_invoke
, closure
, purple_gnt_io_destroy
);
148 g_io_channel_unref(channel
);
149 return closure
->result
;
152 static PurpleEventLoopUiOps eventloop_ops
=
158 NULL
, /* input_get_error */
167 static PurpleEventLoopUiOps
*
168 gnt_eventloop_get_ui_ops(void)
170 return &eventloop_ops
;
173 /* This is mostly copied from gtkpurple's source tree */
175 show_usage(const char *name
, gboolean terse
)
180 text
= g_strdup_printf(_("%s. Try `%s -h' for more information.\n"), VERSION
, name
);
182 text
= g_strdup_printf(_("%s\n"
183 "Usage: %s [OPTION]...\n\n"
184 " -c, --config=DIR use DIR for config files\n"
185 " -d, --debug print debugging messages to stdout\n"
186 " -h, --help display this help and exit\n"
187 " -n, --nologin don't automatically login\n"
188 " -v, --version display the current version and exit\n"), VERSION
, name
);
191 purple_print_utf8_to_console(stdout
, text
);
196 init_libpurple(int argc
, char **argv
)
200 gboolean opt_help
= FALSE
;
201 gboolean opt_nologin
= FALSE
;
202 gboolean opt_version
= FALSE
;
203 char *opt_config_dir_arg
= NULL
;
204 char *opt_session_arg
= NULL
;
205 gboolean debug_enabled
= FALSE
;
207 struct option long_options
[] = {
208 {"config", required_argument
, NULL
, 'c'},
209 {"debug", no_argument
, NULL
, 'd'},
210 {"help", no_argument
, NULL
, 'h'},
211 {"nologin", no_argument
, NULL
, 'n'},
212 {"session", required_argument
, NULL
, 's'},
213 {"version", no_argument
, NULL
, 'v'},
217 #ifdef PURPLE_FATAL_ASSERTS
218 /* Make g_return_... functions fatal. */
219 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL
);
223 bindtextdomain(PACKAGE
, LOCALEDIR
);
224 bind_textdomain_codeset(PACKAGE
, "UTF-8");
228 #ifdef HAVE_SETLOCALE
229 setlocale(LC_ALL
, "");
232 /* scan command-line options */
234 while ((opt
= getopt_long(argc
, argv
,
240 long_options
, NULL
)) != -1) {
242 case 'c': /* config dir */
243 g_free(opt_config_dir_arg
);
244 opt_config_dir_arg
= g_strdup(optarg
);
246 case 'd': /* debug */
247 debug_enabled
= TRUE
;
252 case 'n': /* no autologin */
255 case 's': /* use existing session ID */
256 g_free(opt_session_arg
);
257 opt_session_arg
= g_strdup(optarg
);
259 case 'v': /* version */
262 case '?': /* show terse help */
264 show_usage(argv
[0], TRUE
);
270 /* show help message */
272 show_usage(argv
[0], FALSE
);
275 /* show version message */
277 printf("Finch %s\n", VERSION
);
281 /* set a user-specified config directory */
282 if (opt_config_dir_arg
!= NULL
) {
283 purple_util_set_user_dir(opt_config_dir_arg
);
284 g_free(opt_config_dir_arg
);
288 * We're done piddling around with command line arguments.
292 /* We don't want debug-messages to show up and corrupt the display */
293 purple_debug_set_enabled(debug_enabled
);
295 /* If we're using a custom configuration directory, we
296 * do NOT want to migrate, or weird things will happen. */
297 if (opt_config_dir_arg
== NULL
)
299 if (!purple_core_migrate())
301 char *old
= g_strconcat(purple_home_dir(),
302 G_DIR_SEPARATOR_S
".gaim", NULL
);
303 char *text
= g_strdup_printf(_(
304 "%s encountered errors migrating your settings "
305 "from %s to %s. Please investigate and complete the "
306 "migration by hand. Please report this error at http://developer.pidgin.im"), _("Finch"),
307 old
, purple_user_dir());
311 purple_print_utf8_to_console(stderr
, text
);
318 purple_core_set_ui_ops(gnt_core_get_ui_ops());
319 purple_eventloop_set_ui_ops(gnt_eventloop_get_ui_ops());
320 purple_idle_set_ui_ops(finch_idle_get_ui_ops());
322 path
= g_build_filename(purple_user_dir(), "plugins", NULL
);
323 purple_plugins_add_search_path(path
);
326 purple_plugins_add_search_path(LIBDIR
);
328 if (!purple_core_init(FINCH_UI
))
331 "Initialization of the Purple core failed. Dumping core.\n"
332 "Please report this!\n");
336 /* TODO: Move blist loading into purple_blist_init() */
337 purple_set_blist(purple_blist_new());
340 /* TODO: Move prefs loading into purple_prefs_init() */
342 purple_prefs_update_old();
343 finch_prefs_update_old();
345 /* load plugins we had when we quit */
346 purple_plugins_load_saved("/finch/plugins/loaded");
348 /* TODO: Move pounces loading into purple_pounces_init() */
349 purple_pounces_load();
353 /* Set all accounts to "offline" */
354 PurpleSavedStatus
*saved_status
;
356 /* If we've used this type+message before, lookup the transient status */
357 saved_status
= purple_savedstatus_find_transient_by_type_and_message(
358 PURPLE_STATUS_OFFLINE
, NULL
);
360 /* If this type+message is unique then create a new transient saved status */
361 if (saved_status
== NULL
)
362 saved_status
= purple_savedstatus_new(NULL
, PURPLE_STATUS_OFFLINE
);
364 /* Set the status for each account */
365 purple_savedstatus_activate(saved_status
);
369 /* Everything is good to go--sign on already */
370 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
371 purple_savedstatus_activate(purple_savedstatus_get_startup());
372 purple_accounts_restore_current_statuses();
378 int main(int argc
, char **argv
)
380 signal(SIGPIPE
, SIG_IGN
);
382 /* Initialize the libpurple stuff */
383 if (!init_libpurple(argc
, argv
))