libpurple/tests/test_ui.c

changeset 38831
d260f3b61831
child 38832
7ad7854d8e60
equal deleted inserted replaced
38830:515b117f1d0f 38831:d260f3b61831
1 /*
2 * pidgin
3 *
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 *
22 */
23
24 #include "purple.h"
25
26 #include <glib.h>
27 #include <glib/gprintf.h>
28
29 #include <signal.h>
30 #include <string.h>
31 #ifdef _WIN32
32 # include <conio.h>
33 #else
34 # include <unistd.h>
35 #endif
36
37 #include "defines.h"
38
39 /*** Conversation uiops ***/
40 static void
41 test_write_conv(PurpleConversation *conv, PurpleMessage *msg)
42 {
43 time_t mtime = purple_message_get_time(msg);
44
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));
50 }
51
52 static PurpleConversationUiOps test_conv_uiops = {
53 .write_conv = test_write_conv
54 };
55
56 static void
57 test_ui_init(void)
58 {
59 purple_conversations_set_ui_ops(&test_conv_uiops);
60 }
61
62 static PurpleCoreUiOps test_core_uiops = {
63 .ui_init = test_ui_init
64 };
65
66 static void
67 init_libpurple(void) {
68 /* Set a custom user directory (optional) */
69 purple_util_set_user_dir(TEST_DATA_DIR);
70
71 /* We do not want any debugging for now to keep the noise to a minimum. */
72 purple_debug_set_enabled(FALSE);
73
74 /* Set the core-uiops, which is used to
75 * - initialize the ui specific preferences.
76 * - initialize the debug ui.
77 * - initialize the ui components for all the modules.
78 * - uninitialize the ui components for all the modules when the core terminates.
79 */
80 purple_core_set_ui_ops(&test_core_uiops);
81
82 /* Now that all the essential stuff has been set, let's try to init the core. It's
83 * necessary to provide a non-NULL name for the current ui to the core. This name
84 * is used by stuff that depends on this ui, for example the ui-specific plugins. */
85 if (!purple_core_init("test-ui")) {
86 /* Initializing the core failed. Terminate. */
87 fprintf(stderr,
88 "libpurple initialization failed. Dumping core.\n"
89 "Please report this!\n");
90 abort();
91 }
92
93 /* Set path to search for plugins. The core (libpurple) takes care of loading the
94 * core-plugins, which includes the in-tree protocols. So it is not essential to add
95 * any path here, but it might be desired, especially for ui-specific plugins. */
96 purple_plugins_add_search_path(TEST_DATA_DIR);
97 purple_plugins_refresh();
98
99 /* Load the preferences. */
100 purple_prefs_load();
101
102 /* Load the desired plugins. The client should save the list of loaded plugins in
103 * the preferences using purple_plugins_save_loaded(PLUGIN_SAVE_PREF) */
104 purple_plugins_load_saved(TEST_DATA_DIR);
105 }
106
107 gint
108 main(int argc, char *argv[]) {
109 GList *list, *iter;
110 int i, num;
111 GList *names = NULL;
112 const char *protocol = NULL;
113 char name[128];
114 char *password;
115 GMainLoop *loop = g_main_loop_new(NULL, FALSE);
116 PurpleAccount *account;
117 PurpleSavedStatus *status;
118 char *res;
119
120
121 #ifndef _WIN32
122 /* libpurple's built-in DNS resolution forks processes to perform
123 * blocking lookups without blocking the main process. It does not
124 * handle SIGCHLD itself, so if the UI does not you quickly get an army
125 * of zombie subprocesses marching around.
126 */
127 signal(SIGCHLD, SIG_IGN);
128 #endif
129
130 init_libpurple();
131
132 printf("libpurple initialized.\n");
133
134 g_main_loop_run(loop);
135
136 return 0;
137 }

mercurial