mark PurpleImageClass as private
[pidgin-git.git] / libpurple / tests / test_ui.c
blob47acbbcc070072a2d3504815f0fb6f9f779ad26b
1 /*
2 * pidgin
4 * Pidgin 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
24 #include "purple.h"
26 #include <glib.h>
27 #include <glib/gprintf.h>
29 #include <signal.h>
30 #include <string.h>
31 #ifdef _WIN32
32 # include <conio.h>
33 #else
34 # include <unistd.h>
35 #endif
37 #include "test_ui.h"
39 /*** Conversation uiops ***/
40 static void
41 test_write_conv(PurpleConversation *conv, PurpleMessage *msg)
43 time_t mtime = purple_message_get_time(msg);
45 printf("(%s) %s %s: %s\n",
46 purple_conversation_get_name(conv),
47 purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime)),
48 purple_message_get_author_alias(msg),
49 purple_message_get_contents(msg));
52 static PurpleConversationUiOps test_conv_uiops = {
53 .write_conv = test_write_conv
56 static void
57 test_ui_init(void)
59 purple_conversations_set_ui_ops(&test_conv_uiops);
62 static PurpleCoreUiOps test_core_uiops = {
63 .ui_init = test_ui_init
66 void
67 test_ui_purple_init(void) {
68 #ifndef _WIN32
69 /* libpurple's built-in DNS resolution forks processes to perform
70 * blocking lookups without blocking the main process. It does not
71 * handle SIGCHLD itself, so if the UI does not you quickly get an army
72 * of zombie subprocesses marching around.
74 signal(SIGCHLD, SIG_IGN);
75 #endif
77 /* set the magic PURPLE_PLUGINS_SKIP environment variable */
78 g_setenv("PURPLE_PLUGINS_SKIP", "1", TRUE);
80 /* Set a custom user directory (optional) */
81 purple_util_set_user_dir(TEST_DATA_DIR);
83 /* We do not want any debugging for now to keep the noise to a minimum. */
84 purple_debug_set_enabled(FALSE);
86 /* Set the core-uiops, which is used to
87 * - initialize the ui specific preferences.
88 * - initialize the debug ui.
89 * - initialize the ui components for all the modules.
90 * - uninitialize the ui components for all the modules when the core terminates.
92 purple_core_set_ui_ops(&test_core_uiops);
94 /* Now that all the essential stuff has been set, let's try to init the core. It's
95 * necessary to provide a non-NULL name for the current ui to the core. This name
96 * is used by stuff that depends on this ui, for example the ui-specific plugins. */
97 if (!purple_core_init("test-ui")) {
98 /* Initializing the core failed. Terminate. */
99 fprintf(stderr,
100 "libpurple initialization failed. Dumping core.\n"
101 "Please report this!\n");
102 abort();
105 /* Set path to search for plugins. The core (libpurple) takes care of loading the
106 * core-plugins, which includes the in-tree protocols. So it is not essential to add
107 * any path here, but it might be desired, especially for ui-specific plugins. */
108 purple_plugins_add_search_path(TEST_DATA_DIR);
109 purple_plugins_refresh();
111 /* Load the preferences. */
112 purple_prefs_load();
114 /* Load the desired plugins. The client should save the list of loaded plugins in
115 * the preferences using purple_plugins_save_loaded(PLUGIN_SAVE_PREF) */
116 purple_plugins_load_saved(TEST_DATA_DIR);