finch: Mark unused variable.
[pidgin-git.git] / finch / libfinch.c
blobd9fc30d18d1857f97b0a0c6f1617fed8be87f990
1 /*
2 * finch
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
6 * source distribution.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include <internal.h>
24 #include <locale.h>
25 #include "finch.h"
27 #include "account.h"
28 #include "conversation.h"
29 #include "core.h"
30 #include "debug.h"
31 #include "glibcompat.h"
32 #include "log.h"
33 #include "notify.h"
34 #include "options.h"
35 #include "plugins.h"
36 #include "protocol.h"
37 #include "pounce.h"
38 #include "savedstatuses.h"
39 #include "sound.h"
40 #include "status.h"
41 #include "util.h"
42 #include "whiteboard.h"
43 #include "xfer.h"
45 #include "gntdebug.h"
46 #include "gntprefs.h"
47 #include "gntui.h"
48 #include "gntidle.h"
50 #include "config.h"
51 #include "package_revision.h"
53 static void
54 debug_init(void)
56 FinchDebugUi *ui = finch_debug_ui_new();
57 purple_debug_set_ui(PURPLE_DEBUG_UI(ui));
60 static GHashTable *ui_info = NULL;
61 static GHashTable *finch_ui_get_info(void)
63 if (ui_info == NULL) {
64 ui_info = g_hash_table_new(g_str_hash, g_str_equal);
66 g_hash_table_insert(ui_info, "name", (char*)_("Finch"));
67 g_hash_table_insert(ui_info, "version", VERSION);
68 g_hash_table_insert(ui_info, "website", "https://pidgin.im");
69 g_hash_table_insert(ui_info, "dev_website", "https://developer.pidgin.im");
70 g_hash_table_insert(ui_info, "client_type", "console");
73 * This is the client key for "Finch." Please don't use this
74 * key for other applications. You can not specify a client
75 * key, in which case the default "libpurple" key will be used
77 g_hash_table_insert(ui_info, "prpl-aim-clientkey", "ma18nmEklXMR7Cj_");
80 * This is the client key for "Pidgin." It is owned by the AIM
81 * account "markdoliner." Please don't use this key for other
82 * applications. You can either not specify a client key, in
83 * which case the default "libpurple" key will be used, or you
84 * can try to register your own at the AIM or ICQ web sites
85 * (although this functionality was removed at some point, it's
86 * possible it has been re-added). AOL's old key management
87 * page is http://developer.aim.com/manageKeys.jsp
89 * We used to have a Finch-specific devId/clientkey
90 * (ma19sqWV9ymU6UYc), but it stopped working, so we switched
91 * to this one.
93 g_hash_table_insert(ui_info, "prpl-icq-clientkey", "ma1cSASNCKFtrdv9");
96 * This is the distid for Finch, given to us by AOL. Please
97 * don't use this for other applications. You can just not
98 * specify a distid and libpurple will use a default.
100 g_hash_table_insert(ui_info, "prpl-aim-distid", GINT_TO_POINTER(1718));
101 g_hash_table_insert(ui_info, "prpl-icq-distid", GINT_TO_POINTER(1552));
104 return ui_info;
107 static void
108 finch_quit(void)
110 finch_ui_uninit();
111 if (ui_info)
112 g_hash_table_destroy(ui_info);
115 static PurpleCoreUiOps core_ops =
117 finch_prefs_init,
118 debug_init,
119 finch_ui_init,
120 finch_quit,
121 finch_ui_get_info,
123 /* padding */
124 NULL,
125 NULL,
126 NULL,
127 NULL
130 static PurpleCoreUiOps *
131 gnt_core_get_ui_ops(void)
133 return &core_ops;
136 static int
137 init_libpurple(int argc, char **argv)
139 char *path;
140 gboolean opt_nologin = FALSE;
141 gboolean opt_version = FALSE;
142 char *opt_config_dir_arg = NULL;
143 gboolean debug_enabled = FALSE;
144 GOptionContext *context;
145 gchar **args;
146 GError *error = NULL;
148 GOptionEntry option_entries[] = {
149 {"config", 'c', 0,
150 G_OPTION_ARG_FILENAME, &opt_config_dir_arg,
151 _("use DIR for config files"), _("DIR")},
152 {"nologin", 'n', 0,
153 G_OPTION_ARG_NONE, &opt_nologin,
154 _("don't automatically login"), NULL},
155 {"version", 'v', 0,
156 G_OPTION_ARG_NONE, &opt_version,
157 _("display the current version and exit"), NULL},
158 {NULL}
161 bindtextdomain(PACKAGE, PURPLE_LOCALEDIR);
162 bind_textdomain_codeset(PACKAGE, "UTF-8");
163 textdomain(PACKAGE);
165 setlocale(LC_ALL, "");
167 context = g_option_context_new(NULL);
168 g_option_context_set_summary(context, DISPLAY_VERSION);
169 g_option_context_add_main_entries(context, option_entries, PACKAGE);
171 g_option_context_add_group(context, purple_get_option_group());
172 g_option_context_add_group(context, gplugin_get_option_group());
174 #ifdef G_OS_WIN32
175 /* Handle Unicode filenames on Windows. See GOptionContext docs. */
176 args = g_win32_get_command_line();
177 #else
178 args = g_strdupv(argv);
179 #endif
181 if (!g_option_context_parse_strv(context, &args, &error)) {
182 g_strfreev(args);
183 g_printerr(_("%s: %s\nTry `%s -h' for more information.\n"),
184 DISPLAY_VERSION, error->message, argv[0]);
185 g_clear_error(&error);
186 return 1;
189 g_strfreev(args);
191 /* show version message */
192 if (opt_version) {
193 /* Translators may want to transliterate the name.
194 It is not to be translated. */
195 printf("%s %s (%s)\n", _("Finch"), DISPLAY_VERSION, REVISION);
196 return 0;
199 /* set a user-specified config directory */
200 if (opt_config_dir_arg != NULL) {
201 if (g_path_is_absolute(opt_config_dir_arg)) {
202 purple_util_set_user_dir(opt_config_dir_arg);
203 } else {
204 /* Make an absolute (if not canonical) path */
205 char *cwd = g_get_current_dir();
206 char *path = g_build_path(G_DIR_SEPARATOR_S, cwd, opt_config_dir_arg, NULL);
207 purple_util_set_user_dir(path);
208 g_free(path);
209 g_free(cwd);
212 g_free(opt_config_dir_arg);
216 * We're done piddling around with command line arguments.
217 * Fire up this baby.
220 /* We don't want debug-messages to show up and corrupt the display */
221 purple_debug_set_enabled(debug_enabled);
223 purple_core_set_ui_ops(gnt_core_get_ui_ops());
224 purple_idle_set_ui_ops(finch_idle_get_ui_ops());
226 if (!purple_core_init(FINCH_UI))
228 fprintf(stderr,
229 "Initialization of the Purple core failed. Dumping core.\n"
230 "Please report this!\n");
231 abort();
234 path = g_build_filename(purple_user_dir(), "plugins", NULL);
235 if (g_mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0 && errno != EEXIST)
236 fprintf(stderr, "Couldn't create plugins dir\n");
237 purple_plugins_add_search_path(path);
238 g_free(path);
240 purple_plugins_add_search_path(FINCH_LIBDIR);
241 purple_plugins_refresh();
243 /* TODO: should this be moved into finch_prefs_init() ? */
244 finch_prefs_update_old();
246 /* load plugins we had when we quit */
247 purple_plugins_load_saved("/finch/plugins/loaded");
249 if (opt_nologin)
251 /* Set all accounts to "offline" */
252 PurpleSavedStatus *saved_status;
254 /* If we've used this type+message before, lookup the transient status */
255 saved_status = purple_savedstatus_find_transient_by_type_and_message(
256 PURPLE_STATUS_OFFLINE, NULL);
258 /* If this type+message is unique then create a new transient saved status */
259 if (saved_status == NULL)
260 saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE);
262 /* Set the status for each account */
263 purple_savedstatus_activate(saved_status);
265 else
267 /* Everything is good to go--sign on already */
268 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
269 purple_savedstatus_activate(purple_savedstatus_get_startup());
270 purple_accounts_restore_current_statuses();
273 return 1;
276 gboolean finch_start(int *argc, char ***argv)
278 /* Initialize the libpurple stuff */
279 if (!init_libpurple(*argc, *argv))
280 return FALSE;
282 purple_blist_show();
283 return TRUE;