comparison src/dialogs.c @ 9285:7a8aa87164ae

[gaim-migrate @ 10088] Ok I'm done. This started out as shx's patch to make add/remove buddy/buddies take GaimBuddy and GaimGroup's in various places. I think his diff was like 2000 lines and mine is like 5000. I tried to clean up blist.c a bit and make it more uniform. There are some more g_return_if_fail() checks. Removed some code that was deprecated--it's probably been long enough. Removed some #include <multi.h>'s. Make blist.xml saving happen on a timer, like prefs.xml and accounts.xml. Sorry if this doesn't merge cleanly with whatever you're doing. People should really test this a lot. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 15 Jun 2004 02:37:27 +0000
parents 67e20c25d41e
children a88c8ca91518
comparison
equal deleted inserted replaced
9284:fe0291162312 9285:7a8aa87164ae
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 #include "gtkinternal.h" 22 #include "gtkinternal.h"
23 23
24 #include "debug.h" 24 #include "debug.h"
25 #include "log.h"
26 #include "multi.h"
27 #include "notify.h" 25 #include "notify.h"
28 #include "prefs.h" 26 #include "prefs.h"
29 #include "prpl.h" 27 #include "prpl.h"
30 #include "request.h" 28 #include "request.h"
31 #include "status.h" 29 #include "status.h"
32 #include "util.h" 30 #include "util.h"
33 31
34 #include "gtkblist.h"
35 #include "gtkconv.h"
36 #include "gtkimhtml.h" 32 #include "gtkimhtml.h"
37 #include "gtkimhtmltoolbar.h" 33 #include "gtkimhtmltoolbar.h"
38 #include "gtkprefs.h" 34 #include "gtklog.h"
39 #include "gtkutils.h" 35 #include "gtkutils.h"
40 #include "gtklog.h"
41 #include "stock.h" 36 #include "stock.h"
42 37
43 #include "ui.h" 38 #include "ui.h"
44 39
45 /* XXX */ 40 /* XXX */
198 193
199 static void 194 static void
200 do_remove_chat(GaimChat *chat) 195 do_remove_chat(GaimChat *chat)
201 { 196 {
202 gaim_blist_remove_chat(chat); 197 gaim_blist_remove_chat(chat);
203 gaim_blist_save();
204 } 198 }
205 199
206 static void 200 static void
207 do_remove_buddy(GaimBuddy *b) 201 do_remove_buddy(GaimBuddy *buddy)
208 { 202 {
209 GaimGroup *g; 203 GaimGroup *group;
210 GaimConversation *c; 204 GaimConversation *conv;
211 gchar *name; 205 gchar *name;
212 GaimAccount *account; 206 GaimAccount *account;
213 207
214 if (!b) 208 if (!buddy)
215 return; 209 return;
216 210
217 g = gaim_find_buddys_group(b); 211 group = gaim_find_buddys_group(buddy);
218 name = g_strdup(b->name); /* b->name is a crasher after remove_buddy */ 212 name = g_strdup(buddy->name); /* b->name is a crasher after remove_buddy */
219 account = b->account; 213 account = buddy->account;
220 214
221 gaim_debug(GAIM_DEBUG_INFO, "blist", 215 gaim_debug(GAIM_DEBUG_INFO, "blist",
222 "Removing '%s' from buddy list.\n", b->name); 216 "Removing '%s' from buddy list.\n", buddy->name);
223 serv_remove_buddy(b->account->gc, name, g->name); 217 /* XXX - Should remove from blist first... then call serv_remove_buddy()? */
224 gaim_blist_remove_buddy(b); 218 serv_remove_buddy(buddy->account->gc, buddy, group);
225 gaim_blist_save(); 219 gaim_blist_remove_buddy(buddy);
226 220
227 c = gaim_find_conversation_with_account(name, account); 221 conv = gaim_find_conversation_with_account(name, account);
228 222
229 if (c != NULL) 223 if (conv != NULL)
230 gaim_conversation_update(c, GAIM_CONV_UPDATE_REMOVE); 224 gaim_conversation_update(conv, GAIM_CONV_UPDATE_REMOVE);
231 225
232 g_free(name); 226 g_free(name);
233 } 227 }
234 228
235 static void do_remove_contact(GaimContact *c) 229 static void do_remove_contact(GaimContact *contact)
236 { 230 {
237 GaimBlistNode *bnode, *cnode; 231 GaimBlistNode *bnode, *cnode;
238 GaimGroup *g; 232 GaimGroup *group;
239 233
240 if(!c) 234 if (!contact)
241 return; 235 return;
242 236
243 cnode = (GaimBlistNode *)c; 237 cnode = (GaimBlistNode *)contact;
244 g = (GaimGroup*)cnode->parent; 238 group = (GaimGroup*)cnode->parent;
245 for(bnode = cnode->child; bnode; bnode = bnode->next) { 239 for (bnode = cnode->child; bnode; bnode = bnode->next) {
246 GaimBuddy *b = (GaimBuddy*)bnode; 240 GaimBuddy *buddy = (GaimBuddy*)bnode;
247 if(b->account->gc) 241 if (gaim_account_is_connected(buddy->account))
248 serv_remove_buddy(b->account->gc, b->name, g->name); 242 serv_remove_buddy(buddy->account->gc, buddy, group);
249 } 243 }
250 gaim_blist_remove_contact(c); 244 gaim_blist_remove_contact(contact);
251 } 245 }
252 246
253 void do_remove_group(GaimGroup *g) 247 void do_remove_group(GaimGroup *group)
254 { 248 {
255 GaimBlistNode *cnode, *bnode; 249 GaimBlistNode *cnode, *bnode;
256 250
257 cnode = ((GaimBlistNode*)g)->child; 251 cnode = ((GaimBlistNode*)group)->child;
258 252
259 while(cnode) { 253 while (cnode) {
260 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { 254 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) {
261 bnode = cnode->child; 255 bnode = cnode->child;
262 cnode = cnode->next; 256 cnode = cnode->next;
263 while(bnode) { 257 while (bnode) {
264 GaimBuddy *b; 258 GaimBuddy *buddy;
265 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { 259 if (GAIM_BLIST_NODE_IS_BUDDY(bnode)) {
266 GaimConversation *c; 260 GaimConversation *conv;
267 b = (GaimBuddy*)bnode; 261 buddy = (GaimBuddy*)bnode;
268 bnode = bnode->next; 262 bnode = bnode->next;
269 c = gaim_find_conversation_with_account(b->name, b->account); 263 conv = gaim_find_conversation_with_account(buddy->name, buddy->account);
270 if(gaim_account_is_connected(b->account)) { 264 if (gaim_account_is_connected(buddy->account)) {
271 serv_remove_buddy(b->account->gc, b->name, g->name); 265 serv_remove_buddy(buddy->account->gc, buddy, group);
272 gaim_blist_remove_buddy(b); 266 gaim_blist_remove_buddy(buddy);
273 if(c) 267 if (conv)
274 gaim_conversation_update(c, 268 gaim_conversation_update(conv,
275 GAIM_CONV_UPDATE_REMOVE); 269 GAIM_CONV_UPDATE_REMOVE);
276 } 270 }
277 } else { 271 } else {
278 bnode = bnode->next; 272 bnode = bnode->next;
279 } 273 }
280 } 274 }
281 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { 275 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode)) {
282 GaimChat *chat = (GaimChat *)cnode; 276 GaimChat *chat = (GaimChat *)cnode;
283 cnode = cnode->next; 277 cnode = cnode->next;
284 if(gaim_account_is_connected(chat->account)) 278 if (gaim_account_is_connected(chat->account))
285 gaim_blist_remove_chat(chat); 279 gaim_blist_remove_chat(chat);
286 } else { 280 } else {
287 cnode = cnode->next; 281 cnode = cnode->next;
288 } 282 }
289 } 283 }
290 284
291 gaim_blist_remove_group(g); 285 gaim_blist_remove_group(group);
292 gaim_blist_save(); 286 }
293 } 287
294 288 void show_confirm_del(GaimBuddy *buddy)
295 void show_confirm_del(GaimBuddy *b)
296 { 289 {
297 char *text; 290 char *text;
298 if (!b) 291
292 if (!buddy)
299 return; 293 return;
300 294
301 text = g_strdup_printf(_("You are about to remove %s from your buddy list. Do you want to continue?"), b->name); 295 text = g_strdup_printf(_("You are about to remove %s from your buddy list. Do you want to continue?"), buddy->name);
302 296
303 gaim_request_action(NULL, NULL, _("Remove Buddy"), text, -1, b, 2, 297 gaim_request_action(NULL, NULL, _("Remove Buddy"), text, -1, buddy, 2,
304 _("Remove Buddy"), G_CALLBACK(do_remove_buddy), 298 _("Remove Buddy"), G_CALLBACK(do_remove_buddy),
305 _("Cancel"), NULL); 299 _("Cancel"), NULL);
306 300
307 g_free(text); 301 g_free(text);
308 } 302 }
318 312
319 g_free(name); 313 g_free(name);
320 g_free(text); 314 g_free(text);
321 } 315 }
322 316
323 void show_confirm_del_group(GaimGroup *g) 317 void show_confirm_del_group(GaimGroup *group)
324 { 318 {
325 char *text = g_strdup_printf(_("You are about to remove the group %s and all its members from your buddy list. Do you want to continue?"), 319 char *text = g_strdup_printf(_("You are about to remove the group %s and all its members from your buddy list. Do you want to continue?"),
326 g->name); 320 group->name);
327 321
328 gaim_request_action(NULL, NULL, _("Remove Group"), text, -1, g, 2, 322 gaim_request_action(NULL, NULL, _("Remove Group"), text, -1, group, 2,
329 _("Remove Group"), G_CALLBACK(do_remove_group), 323 _("Remove Group"), G_CALLBACK(do_remove_group),
330 _("Cancel"), NULL); 324 _("Cancel"), NULL);
331 325
332 g_free(text); 326 g_free(text);
333 } 327 }
334 328
335 void show_confirm_del_contact(GaimContact *c) 329 void show_confirm_del_contact(GaimContact *contact)
336 { 330 {
337 GaimBuddy *b = gaim_contact_get_priority_buddy(c); 331 GaimBuddy *buddy = gaim_contact_get_priority_buddy(contact);
338 332
339 if(!b) 333 if (!buddy)
340 return; 334 return;
341 335
342 if(((GaimBlistNode*)c)->child == (GaimBlistNode*)b && 336 if (((GaimBlistNode*)contact)->child == (GaimBlistNode*)buddy &&
343 !((GaimBlistNode*)b)->next) { 337 !((GaimBlistNode*)buddy)->next) {
344 show_confirm_del(b); 338 show_confirm_del(buddy);
345 } else { 339 } else {
346 char *text = g_strdup_printf(_("You are about to remove the contact containing %s and %d other buddies from your buddy list. Do you want to continue?"), 340 char *text = g_strdup_printf(_("You are about to remove the contact containing %s and %d other buddies from your buddy list. Do you want to continue?"),
347 b->name, c->totalsize - 1); 341 buddy->name, contact->totalsize - 1);
348 342
349 gaim_request_action(NULL, NULL, _("Remove Contact"), text, -1, c, 2, 343 gaim_request_action(NULL, NULL, _("Remove Contact"), text, -1, contact, 2,
350 _("Remove Contact"), G_CALLBACK(do_remove_contact), 344 _("Remove Contact"), G_CALLBACK(do_remove_contact),
351 _("Cancel"), NULL); 345 _("Cancel"), NULL);
352 346
353 g_free(text); 347 g_free(text);
354 } 348 }
357 static gboolean show_ee_dialog(const char *ee) 351 static gboolean show_ee_dialog(const char *ee)
358 { 352 {
359 GtkWidget *window; 353 GtkWidget *window;
360 GtkWidget *hbox; 354 GtkWidget *hbox;
361 GtkWidget *label; 355 GtkWidget *label;
362 GaimGtkBuddyList *gtkblist;
363 GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_COOL, GTK_ICON_SIZE_DIALOG); 356 GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_COOL, GTK_ICON_SIZE_DIALOG);
364 gchar *norm = gaim_strreplace(ee, "rocksmyworld", ""); 357 gchar *norm = gaim_strreplace(ee, "rocksmyworld", "");
365
366 gtkblist = GAIM_GTK_BLIST(gaim_get_blist());
367 358
368 label = gtk_label_new(NULL); 359 label = gtk_label_new(NULL);
369 if (!strcmp(norm, "zilding")) 360 if (!strcmp(norm, "zilding"))
370 gtk_label_set_markup(GTK_LABEL(label), 361 gtk_label_set_markup(GTK_LABEL(label),
371 "<span weight=\"bold\" size=\"large\" foreground=\"purple\">Amazing! Simply Amazing!</span>"); 362 "<span weight=\"bold\" size=\"large\" foreground=\"purple\">Amazing! Simply Amazing!</span>");
396 g_free(norm); 387 g_free(norm);
397 388
398 if (strlen(gtk_label_get_label(GTK_LABEL(label))) <= 0) 389 if (strlen(gtk_label_get_label(GTK_LABEL(label))) <= 0)
399 return FALSE; 390 return FALSE;
400 391
401 window = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, GTK_WINDOW(gtkblist->window), 0, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); 392 window = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, NULL, 0, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
402 gtk_dialog_set_default_response (GTK_DIALOG(window), GTK_RESPONSE_OK); 393 gtk_dialog_set_default_response (GTK_DIALOG(window), GTK_RESPONSE_OK);
403 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(gtk_widget_destroy), NULL); 394 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(gtk_widget_destroy), NULL);
404 395
405 gtk_container_set_border_width (GTK_CONTAINER(window), 6); 396 gtk_container_set_border_width (GTK_CONTAINER(window), 6);
406 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); 397 gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
803 794
804 static void 795 static void
805 alias_chat_cb(GaimChat *chat, const char *new_alias) 796 alias_chat_cb(GaimChat *chat, const char *new_alias)
806 { 797 {
807 gaim_blist_alias_chat(chat, new_alias); 798 gaim_blist_alias_chat(chat, new_alias);
808 gaim_blist_save();
809 } 799 }
810 800
811 void 801 void
812 alias_dialog_blist_chat(GaimChat *chat) 802 alias_dialog_blist_chat(GaimChat *chat)
813 { 803 {
820 810
821 static void 811 static void
822 alias_contact_cb(GaimContact *contact, const char *new_alias) 812 alias_contact_cb(GaimContact *contact, const char *new_alias)
823 { 813 {
824 gaim_contact_set_alias(contact, new_alias); 814 gaim_contact_set_alias(contact, new_alias);
825 gaim_blist_save();
826 } 815 }
827 816
828 void 817 void
829 alias_dialog_contact(GaimContact *contact) 818 alias_dialog_contact(GaimContact *contact)
830 { 819 {
838 static void 827 static void
839 alias_buddy_cb(GaimBuddy *buddy, const char *alias) 828 alias_buddy_cb(GaimBuddy *buddy, const char *alias)
840 { 829 {
841 gaim_blist_alias_buddy(buddy, (alias != NULL && *alias != '\0') ? alias : NULL); 830 gaim_blist_alias_buddy(buddy, (alias != NULL && *alias != '\0') ? alias : NULL);
842 serv_alias_buddy(buddy); 831 serv_alias_buddy(buddy);
843 gaim_blist_save();
844 } 832 }
845 833
846 void 834 void
847 alias_dialog_bud(GaimBuddy *b) 835 alias_dialog_bud(GaimBuddy *b)
848 { 836 {