comparison console/gntconv.c @ 14010:7573bd40a190

[gaim-migrate @ 16602] Allow plugins to be loaded and unloaded. Remember the window positions and sizes. All turning on/off shadow from ~/.gntrc (off by default). committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 31 Jul 2006 23:19:12 +0000
parents d9fab56e6011
children 735c4e927eb8
comparison
equal deleted inserted replaced
14009:1e283c3566ab 14010:7573bd40a190
1 #include <string.h> 1 #include <string.h>
2 2
3 #include <cmds.h> 3 #include <cmds.h>
4 #include <prefs.h>
4 #include <util.h> 5 #include <util.h>
5 6
6 #include "gntgaim.h" 7 #include "gntgaim.h"
7 #include "gntblist.h" 8 #include "gntblist.h"
8 #include "gntconv.h" 9 #include "gntconv.h"
9 10
10 #include "gnt.h" 11 #include "gnt.h"
11 #include "gntbox.h" 12 #include "gntbox.h"
12 #include "gntentry.h" 13 #include "gntentry.h"
13 #include "gnttextview.h" 14 #include "gnttextview.h"
15
16 #define PREF_ROOT "/gaim/gnt/conversations"
14 17
15 GHashTable *ggconvs; 18 GHashTable *ggconvs;
16 19
17 typedef struct _GGConv GGConv; 20 typedef struct _GGConv GGConv;
18 typedef struct _GGConvChat GGConvChat; 21 typedef struct _GGConvChat GGConvChat;
140 ggconv->window = NULL; 143 ggconv->window = NULL;
141 gaim_conversation_destroy(ggconv->conv); 144 gaim_conversation_destroy(ggconv->conv);
142 } 145 }
143 146
144 static void 147 static void
148 size_changed_cb(GntWidget *w, int width, int height)
149 {
150 gaim_prefs_set_int(PREF_ROOT "/size/width", width);
151 gaim_prefs_set_int(PREF_ROOT "/size/height", height);
152 }
153
154 static void
155 save_position_cb(GntWidget *w, int x, int y)
156 {
157 gaim_prefs_set_int(PREF_ROOT "/position/x", x);
158 gaim_prefs_set_int(PREF_ROOT "/position/y", y);
159 }
160
161 static void
145 gg_create_conversation(GaimConversation *conv) 162 gg_create_conversation(GaimConversation *conv)
146 { 163 {
147 GGConv *ggc = g_hash_table_lookup(ggconvs, conv); 164 GGConv *ggc = g_hash_table_lookup(ggconvs, conv);
148 char *title; 165 char *title;
149 GaimConversationType type; 166 GaimConversationType type;
150 int x, width;
151 167
152 if (ggc) 168 if (ggc)
153 return; 169 return;
154
155 gg_blist_get_position(&x, NULL);
156 gg_blist_get_size(&width, NULL);
157 170
158 ggc = g_new0(GGConv, 1); 171 ggc = g_new0(GGConv, 1);
159 g_hash_table_insert(ggconvs, conv, ggc); 172 g_hash_table_insert(ggconvs, conv, ggc);
160 173
161 ggc->conv = conv; 174 ggc->conv = conv;
170 gnt_widget_set_name(ggc->window, title); 183 gnt_widget_set_name(ggc->window, title);
171 184
172 ggc->tv = gnt_text_view_new(); 185 ggc->tv = gnt_text_view_new();
173 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->tv); 186 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->tv);
174 gnt_widget_set_name(ggc->tv, "conversation-window-textview"); 187 gnt_widget_set_name(ggc->tv, "conversation-window-textview");
175 gnt_widget_set_size(ggc->tv, getmaxx(stdscr) - 3 - x - width, getmaxy(stdscr) - 5); 188 gnt_widget_set_size(ggc->tv, gaim_prefs_get_int(PREF_ROOT "/size/width"),
189 gaim_prefs_get_int(PREF_ROOT "/size/height"));
176 190
177 ggc->entry = gnt_entry_new(NULL); 191 ggc->entry = gnt_entry_new(NULL);
178 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry); 192 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry);
179 gnt_widget_set_name(ggc->entry, "conversation-window-entry"); 193 gnt_widget_set_name(ggc->entry, "conversation-window-entry");
180 194
181 g_signal_connect(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc); 195 g_signal_connect(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc);
182 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc); 196 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc);
183 197
184 /* XXX: I am assuming the buddylist is on the leftmost corner. 198 gnt_widget_set_position(ggc->window, gaim_prefs_get_int(PREF_ROOT "/position/x"),
185 * That may not always be correct, since the windows can be moved. 199 gaim_prefs_get_int(PREF_ROOT "/position/y"));
186 * It might be an option to remember the position of conv. windows. */
187 gnt_widget_set_position(ggc->window, x + width, 0);
188 gnt_widget_show(ggc->window); 200 gnt_widget_show(ggc->window);
201
202 g_signal_connect(G_OBJECT(ggc->tv), "size_changed", G_CALLBACK(size_changed_cb), NULL);
203 g_signal_connect(G_OBJECT(ggc->window), "position_set", G_CALLBACK(save_position_cb), NULL);
189 204
190 g_free(title); 205 g_free(title);
191 } 206 }
192 207
193 static void 208 static void
463 478
464 void gg_conversation_init() 479 void gg_conversation_init()
465 { 480 {
466 ggconvs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_ggconv); 481 ggconvs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_ggconv);
467 482
468 /* Xerox */ 483 gaim_prefs_add_none(PREF_ROOT);
484 gaim_prefs_add_none(PREF_ROOT "/size");
485 gaim_prefs_add_int(PREF_ROOT "/size/width", 70);
486 gaim_prefs_add_int(PREF_ROOT "/size/height", 20);
487 gaim_prefs_add_none(PREF_ROOT "/position");
488 gaim_prefs_add_int(PREF_ROOT "/position/x", 0);
489 gaim_prefs_add_int(PREF_ROOT "/position/y", 0);
490
491 /* Xerox the commands */
469 gaim_cmd_register("say", "S", GAIM_CMD_P_DEFAULT, 492 gaim_cmd_register("say", "S", GAIM_CMD_P_DEFAULT,
470 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, 493 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
471 say_command_cb, _("say &lt;message&gt;: Send a message normally as if you weren't using a command."), NULL); 494 say_command_cb, _("say &lt;message&gt;: Send a message normally as if you weren't using a command."), NULL);
472 gaim_cmd_register("me", "S", GAIM_CMD_P_DEFAULT, 495 gaim_cmd_register("me", "S", GAIM_CMD_P_DEFAULT,
473 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, 496 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,