comparison console/gntgaim.c @ 13850:0e1e59770cb0

[gaim-migrate @ 16308] This is my first commit here. So don't yell at me if things get borked. Also, I haven't looked at the auto-thingies yet. So don't puke at the Makefiles. Files in console/libgnt/ are for the 'Gaim/GObjectified Ncurses Toolkit' library. Files in console/ uses libgaim and libgnt. Currently, only the buddylist-ui is 'functional', ie. the buddy-list updates when someone logs on or logs off. It still needs a lot of work. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 22 Jun 2006 08:33:54 +0000
parents
children d95e5e0e29b9
comparison
equal deleted inserted replaced
13849:8d1c55309e3c 13850:0e1e59770cb0
1 #include "account.h"
2 #include "conversation.h"
3 #include "core.h"
4 #include "debug.h"
5 #include "eventloop.h"
6 #include "ft.h"
7 #include "log.h"
8 #include "notify.h"
9 #include "prefs.h"
10 #include "prpl.h"
11 #include "pounce.h"
12 #include "savedstatuses.h"
13 #include "sound.h"
14 #include "status.h"
15 #include "util.h"
16 #include "whiteboard.h"
17
18 #include "gntgaim.h"
19
20 /* Anything IO-related is directly copied from gtkgaim's source tree */
21
22 static GaimCoreUiOps core_ops =
23 {
24 NULL, /*gaim_gtk_prefs_init,*/
25 NULL, /*debug_init,*/
26 NULL, /*gaim_gtk_ui_init,*/
27 NULL, /*gaim_gtk_quit*/
28 };
29
30 static GaimCoreUiOps *
31 gnt_core_get_ui_ops()
32 {
33 return &core_ops;
34 }
35
36 #define GAIM_GTK_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
37 #define GAIM_GTK_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
38
39 typedef struct _GaimGtkIOClosure {
40 GaimInputFunction function;
41 guint result;
42 gpointer data;
43
44 } GaimGtkIOClosure;
45
46 static void gaim_gtk_io_destroy(gpointer data)
47 {
48 g_free(data);
49 }
50
51 static gboolean gaim_gtk_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
52 {
53 GaimGtkIOClosure *closure = data;
54 GaimInputCondition gaim_cond = 0;
55
56 if (condition & GAIM_GTK_READ_COND)
57 gaim_cond |= GAIM_INPUT_READ;
58 if (condition & GAIM_GTK_WRITE_COND)
59 gaim_cond |= GAIM_INPUT_WRITE;
60
61 #if 0
62 gaim_debug(GAIM_DEBUG_MISC, "gtk_eventloop",
63 "CLOSURE: callback for %d, fd is %d\n",
64 closure->result, g_io_channel_unix_get_fd(source));
65 #endif
66
67 #ifdef _WIN32
68 if(! gaim_cond) {
69 #if DEBUG
70 gaim_debug(GAIM_DEBUG_MISC, "gtk_eventloop",
71 "CLOSURE received GIOCondition of 0x%x, which does not"
72 " match 0x%x (READ) or 0x%x (WRITE)\n",
73 condition, GAIM_GTK_READ_COND, GAIM_GTK_WRITE_COND);
74 #endif /* DEBUG */
75
76 return TRUE;
77 }
78 #endif /* _WIN32 */
79
80 closure->function(closure->data, g_io_channel_unix_get_fd(source),
81 gaim_cond);
82
83 return TRUE;
84 }
85
86 static guint gnt_input_add(gint fd, GaimInputCondition condition, GaimInputFunction function,
87 gpointer data)
88 {
89 GaimGtkIOClosure *closure = g_new0(GaimGtkIOClosure, 1);
90 GIOChannel *channel;
91 GIOCondition cond = 0;
92
93 closure->function = function;
94 closure->data = data;
95
96 if (condition & GAIM_INPUT_READ)
97 cond |= GAIM_GTK_READ_COND;
98 if (condition & GAIM_INPUT_WRITE)
99 cond |= GAIM_GTK_WRITE_COND;
100
101 channel = g_io_channel_unix_new(fd);
102 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
103 gaim_gtk_io_invoke, closure, gaim_gtk_io_destroy);
104
105 #if 0
106 gaim_debug(GAIM_DEBUG_MISC, "gtk_eventloop",
107 "CLOSURE: adding input watcher %d for fd %d\n",
108 closure->result, fd);
109 #endif
110
111 g_io_channel_unref(channel);
112 return closure->result;
113 }
114
115 static GaimEventLoopUiOps eventloop_ops =
116 {
117 g_timeout_add,
118 (guint (*)(guint))g_source_remove,
119 gnt_input_add,
120 (guint (*)(guint))g_source_remove
121 };
122
123 GaimEventLoopUiOps *
124 gnt_eventloop_get_ui_ops(void)
125 {
126 return &eventloop_ops;
127 }
128
129 /* This is mostly copied from gtkgaim's source tree */
130 static void
131 init_libgaim()
132 {
133 char *path;
134
135 gaim_debug_set_enabled(FALSE);
136
137 gaim_core_set_ui_ops(gnt_core_get_ui_ops());
138 gaim_eventloop_set_ui_ops(gnt_eventloop_get_ui_ops());
139
140 gaim_util_set_user_dir("/tmp/tmp/"); /* XXX: */
141
142 path = g_build_filename(gaim_user_dir(), "plugins", NULL);
143 gaim_plugins_add_search_path(path);
144 g_free(path);
145 gaim_plugins_add_search_path("/usr/local/lib/gaim"); /* XXX: */
146
147 if (!gaim_core_init(GAIM_GNT_UI))
148 {
149 fprintf(stderr, "OOPSSS!!\n");
150 abort();
151 }
152
153 /* TODO: Move blist loading into gaim_blist_init() */
154 gaim_set_blist(gaim_blist_new());
155 gaim_blist_load();
156
157 /* TODO: Move prefs loading into gaim_prefs_init() */
158 gaim_prefs_load();
159 gaim_prefs_update_old();
160
161 /* load plugins we had when we quit */
162 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded");
163
164 /* TODO: Move pounces loading into gaim_pounces_init() */
165 gaim_pounces_load();
166
167 }
168
169 int main(int argc, char **argv)
170 {
171 GMainLoop *loop;
172
173 /* Initialize the libgaim stuff */
174 init_libgaim();
175
176 /* Connect to the signals */
177
178 /* Enable the accounts and restore the status */
179 gaim_accounts_restore_current_statuses();
180
181 /* Main loop */
182 g_thread_init(NULL);
183 loop = g_main_loop_new(NULL, TRUE);
184 g_thread_create((GThreadFunc)g_main_loop_run, loop, FALSE, NULL);
185
186 /* Initialize the UI */
187 init_gnt_ui();
188
189 gaim_core_quit();
190
191 return 0;
192 }
193