comparison src/gtknotify.c @ 8338:354bba6ad254

[gaim-migrate @ 9062] I added titles to the notify formatted dialog, and I also cleaned up a bunch of code from patches and stuff... standardized on a style. Call me a code Nazi. I don't care :) committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 25 Feb 2004 22:03:54 +0000
parents 65ae6930b45a
children 7787485141ca
comparison
equal deleted inserted replaced
8337:65ae6930b45a 8338:354bba6ad254
84 GtkWidget *label; 84 GtkWidget *label;
85 GtkWidget *img = NULL; 85 GtkWidget *img = NULL;
86 char label_text[2048]; 86 char label_text[2048];
87 const char *icon_name = NULL; 87 const char *icon_name = NULL;
88 88
89 switch (type) { 89 switch (type)
90 {
90 case GAIM_NOTIFY_MSG_ERROR: 91 case GAIM_NOTIFY_MSG_ERROR:
91 icon_name = GAIM_STOCK_DIALOG_ERROR; 92 icon_name = GAIM_STOCK_DIALOG_ERROR;
92 break; 93 break;
93 94
94 case GAIM_NOTIFY_MSG_WARNING: 95 case GAIM_NOTIFY_MSG_WARNING:
102 default: 103 default:
103 icon_name = NULL; 104 icon_name = NULL;
104 break; 105 break;
105 } 106 }
106 107
107 if (icon_name != NULL) { 108 if (icon_name != NULL)
109 {
108 img = gtk_image_new_from_stock(icon_name, GTK_ICON_SIZE_DIALOG); 110 img = gtk_image_new_from_stock(icon_name, GTK_ICON_SIZE_DIALOG);
109 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); 111 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
110 } 112 }
111 113
112 dialog = gtk_dialog_new_with_buttons(title ? title : GAIM_ALERT_TITLE, 114 dialog = gtk_dialog_new_with_buttons(title ? title : GAIM_ALERT_TITLE,
113 NULL, 0, GTK_STOCK_OK, 115 NULL, 0, GTK_STOCK_OK,
114 GTK_RESPONSE_ACCEPT, NULL); 116 GTK_RESPONSE_ACCEPT, NULL);
117
115 g_signal_connect(G_OBJECT(dialog), "response", 118 g_signal_connect(G_OBJECT(dialog), "response",
116 G_CALLBACK(message_response_cb), dialog); 119 G_CALLBACK(message_response_cb), dialog);
117 120
118 gtk_container_set_border_width(GTK_CONTAINER(dialog), 6); 121 gtk_container_set_border_width(GTK_CONTAINER(dialog), 6);
119 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); 122 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
207 vbox = gtk_vbox_new(FALSE, 12); 210 vbox = gtk_vbox_new(FALSE, 12);
208 211
209 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); 212 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
210 213
211 /* Descriptive label */ 214 /* Descriptive label */
212 detail_text = g_strdup_printf( 215 detail_text = g_strdup_printf(ngettext("%s has %d new message.",
213 ngettext("%s has %d new message.", "%s has %d new messages.", (int) count), 216 "%s has %d new messages.",
214 *tos, (int) count); 217 (int)count),
215 218 *tos, (int)count);
216 if (count == 1) { 219
220 if (count == 1)
221 {
217 char *from_text = NULL, *subject_text = NULL; 222 char *from_text = NULL, *subject_text = NULL;
218 223
219 if (froms != NULL) { 224 if (froms != NULL)
225 {
220 from_text = g_strdup_printf( 226 from_text = g_strdup_printf(
221 _("<span weight=\"bold\">From:</span> %s\n"), *froms); 227 _("<span weight=\"bold\">From:</span> %s\n"), *froms);
222 } 228 }
223 229
224 if (subjects != NULL) { 230 if (subjects != NULL)
231 {
225 subject_text = g_strdup_printf( 232 subject_text = g_strdup_printf(
226 _("<span weight=\"bold\">Subject:</span> %s\n"), *subjects); 233 _("<span weight=\"bold\">Subject:</span> %s\n"), *subjects);
227 } 234 }
228 235
229 label_text = g_strdup_printf( 236 label_text = g_strdup_printf(
238 g_free(from_text); 245 g_free(from_text);
239 246
240 if (subject_text != NULL) 247 if (subject_text != NULL)
241 g_free(subject_text); 248 g_free(subject_text);
242 } 249 }
243 else { 250 else
251 {
244 label_text = g_strdup_printf( 252 label_text = g_strdup_printf(
245 _("<span weight=\"bold\" size=\"larger\">You have mail!</span>" 253 _("<span weight=\"bold\" size=\"larger\">You have mail!</span>"
246 "\n\n%s"), detail_text); 254 "\n\n%s"), detail_text);
247 } 255 }
248 256
291 int options = 0; 299 int options = 0;
292 char label_text[2048]; 300 char label_text[2048];
293 char *linked_text; 301 char *linked_text;
294 302
295 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 303 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
304 gtk_window_set_title(GTK_WINDOW(title), title);
296 gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); 305 gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
297 gtk_container_set_border_width(GTK_CONTAINER(window), 12); 306 gtk_container_set_border_width(GTK_CONTAINER(window), 12);
298 307
299 g_signal_connect(G_OBJECT(window), "delete_event", 308 g_signal_connect(G_OBJECT(window), "delete_event",
300 G_CALLBACK(formatted_close_cb), NULL); 309 G_CALLBACK(formatted_close_cb), NULL);
304 gtk_container_add(GTK_CONTAINER(window), vbox); 313 gtk_container_add(GTK_CONTAINER(window), vbox);
305 gtk_widget_show(vbox); 314 gtk_widget_show(vbox);
306 315
307 /* Setup the descriptive label */ 316 /* Setup the descriptive label */
308 g_snprintf(label_text, sizeof(label_text), 317 g_snprintf(label_text, sizeof(label_text),
309 "<span weight=\"bold\" size=\"larger\">%s</span>%s%s", 318 "<span weight=\"bold\" size=\"larger\">%s</span>%s%s",
310 primary, 319 primary,
311 (secondary ? "\n" : ""), 320 (secondary ? "\n" : ""),
312 (secondary ? secondary : "")); 321 (secondary ? secondary : ""));
313 322
314 label = gtk_label_new(NULL); 323 label = gtk_label_new(NULL);
315 324
316 gtk_label_set_markup(GTK_LABEL(label), label_text); 325 gtk_label_set_markup(GTK_LABEL(label), label_text);
317 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); 326 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
340 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); 349 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
341 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); 350 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
342 gtk_widget_show(button); 351 gtk_widget_show(button);
343 352
344 g_signal_connect_swapped(G_OBJECT(button), "clicked", 353 g_signal_connect_swapped(G_OBJECT(button), "clicked",
345 G_CALLBACK(formatted_close_cb), window); 354 G_CALLBACK(formatted_close_cb), window);
346 g_signal_connect(G_OBJECT(window), "key_press_event", 355 g_signal_connect(G_OBJECT(window), "key_press_event",
347 G_CALLBACK(formatted_input_cb), NULL); 356 G_CALLBACK(formatted_input_cb), NULL);
348 357
349 358
350 /* Add the text to the gtkimhtml */ 359 /* Add the text to the gtkimhtml */
351 if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_colors")) 360 if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_colors"))
352 options ^= GTK_IMHTML_NO_COLOURS; 361 options ^= GTK_IMHTML_NO_COLOURS;
361 options ^= GTK_IMHTML_NO_TITLE; 370 options ^= GTK_IMHTML_NO_TITLE;
362 options ^= GTK_IMHTML_NO_NEWLINE; 371 options ^= GTK_IMHTML_NO_NEWLINE;
363 options ^= GTK_IMHTML_NO_SCROLL; 372 options ^= GTK_IMHTML_NO_SCROLL;
364 373
365 gaim_gtk_find_images(text, &images); 374 gaim_gtk_find_images(text, &images);
366 if(gaim_prefs_get_bool("/gaim/gtk/conversations/show_urls_as_links")){ 375
376 if (gaim_prefs_get_bool("/gaim/gtk/conversations/show_urls_as_links"))
377 {
367 linked_text = gaim_markup_linkify(text); 378 linked_text = gaim_markup_linkify(text);
368 gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), linked_text, 379 gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), linked_text,
369 options, images); 380 options, images);
370 g_free(linked_text); 381 g_free(linked_text);
371 } else 382 }
372 gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), text, options, images); 383 else
373 384 {
374 if (images) { 385 gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), text,
386 options, images);
387 }
388
389 if (images)
390 {
375 GSList *tmp; 391 GSList *tmp;
376 392
377 for (tmp = images; tmp; tmp = tmp->next) { 393 for (tmp = images; tmp; tmp = tmp->next)
394 {
378 GdkPixbuf *pixbuf = tmp->data; 395 GdkPixbuf *pixbuf = tmp->data;
379 if(pixbuf) 396
397 if (pixbuf != NULL)
380 g_object_unref(pixbuf); 398 g_object_unref(pixbuf);
381 } 399 }
382 400
383 g_slist_free(images); 401 g_slist_free(images);
384 } 402 }
390 } 408 }
391 409
392 static void 410 static void
393 gaim_gtk_close_notify(GaimNotifyType type, void *ui_handle) 411 gaim_gtk_close_notify(GaimNotifyType type, void *ui_handle)
394 { 412 {
395 if (type == GAIM_NOTIFY_EMAIL || type == GAIM_NOTIFY_EMAILS) { 413 if (type == GAIM_NOTIFY_EMAIL || type == GAIM_NOTIFY_EMAILS)
414 {
396 GaimNotifyMailData *data = (GaimNotifyMailData *)ui_handle; 415 GaimNotifyMailData *data = (GaimNotifyMailData *)ui_handle;
397 416
398 gtk_widget_destroy(data->dialog); 417 gtk_widget_destroy(data->dialog);
399 418
400 g_free(data->url); 419 g_free(data->url);
404 gtk_widget_destroy(GTK_WIDGET(ui_handle)); 423 gtk_widget_destroy(GTK_WIDGET(ui_handle));
405 } 424 }
406 425
407 #ifndef _WIN32 426 #ifndef _WIN32
408 static gint 427 static gint
409 uri_command(const char *command, const gboolean sync) 428 uri_command(const char *command, gboolean sync)
410 { 429 {
411 GError *error = NULL; 430 GError *error = NULL;
412 gint ret = 0; 431 gint ret = 0;
413 432
414 gaim_debug_misc("gtknotify", "Executing %s\n", command); 433 gaim_debug_misc("gtknotify", "Executing %s\n", command);
415 434
416 if (!gaim_program_is_valid(command)) { 435 if (!gaim_program_is_valid(command))
417 gchar *tmp = g_strdup_printf(_("The browser command \"%s\" is invalid."), 436 {
418 command); 437 gchar *tmp;
438
439 tmp = g_strdup_printf(_("The browser command \"%s\" is invalid."),
440 command);
441
419 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp); 442 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
420 443
421 g_free(tmp); 444 g_free(tmp);
422 445
423 } else if (sync) { 446 }
447 else if (sync)
448 {
424 gint status; 449 gint status;
425 450
426 if (!g_spawn_command_line_sync(command, NULL, NULL, &status, &error)) { 451 if (!g_spawn_command_line_sync(command, NULL, NULL, &status, &error))
452 {
427 char *tmp = g_strdup_printf(_("Error launching \"%s\": %s"), 453 char *tmp = g_strdup_printf(_("Error launching \"%s\": %s"),
428 command, error->message); 454 command, error->message);
429 455
430 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp); 456 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
431 457
432 g_free(tmp); 458 g_free(tmp);
433 g_error_free(error); 459 g_error_free(error);
434 } else { 460 }
461 else
435 ret = status; 462 ret = status;
436 } 463 }
437 464 else
438 } else { 465 {
439 if (!g_spawn_command_line_async(command, &error)) { 466 if (!g_spawn_command_line_async(command, &error))
467 {
440 char *tmp = g_strdup_printf(_("Error launching \"%s\": %s"), 468 char *tmp = g_strdup_printf(_("Error launching \"%s\": %s"),
441 command, error->message); 469 command, error->message);
442 470
443 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp); 471 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
444 472
447 } 475 }
448 } 476 }
449 477
450 return ret; 478 return ret;
451 } 479 }
452 #endif 480 #endif /* _WIN32 */
453 481
454 static void * 482 static void *
455 gaim_gtk_notify_uri(const char *uri) 483 gaim_gtk_notify_uri(const char *uri)
456 { 484 {
457 #ifndef _WIN32 485 #ifndef _WIN32
461 int place; 489 int place;
462 490
463 web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser"); 491 web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser");
464 place = gaim_prefs_get_int("/gaim/gtk/browsers/place"); 492 place = gaim_prefs_get_int("/gaim/gtk/browsers/place");
465 493
466 if (!strcmp(web_browser, "netscape")) { 494 if (!strcmp(web_browser, "netscape"))
495 {
467 command = g_strdup_printf("netscape \"%s\"", uri); 496 command = g_strdup_printf("netscape \"%s\"", uri);
497
468 if (place == GAIM_BROWSER_NEW_WINDOW) 498 if (place == GAIM_BROWSER_NEW_WINDOW)
469 remote_command = g_strdup_printf("netscape -remote \"openURL(\"%s\",new-window)\"", uri); 499 {
500 remote_command = g_strdup_printf("netscape -remote "
501 "\"openURL(\"%s\",new-window)\"",
502 uri);
503 }
470 else if (place == GAIM_BROWSER_CURRENT) 504 else if (place == GAIM_BROWSER_CURRENT)
471 remote_command = g_strdup_printf("netscape -remote \"openURL(\"%s\")\"", uri); 505 {
472 506 remote_command = g_strdup_printf("netscape -remote "
473 } else if (!strcmp(web_browser, "opera")) { 507 "\"openURL(\"%s\")\"", uri);
508 }
509 }
510 else if (!strcmp(web_browser, "opera"))
511 {
474 if (place == GAIM_BROWSER_NEW_WINDOW) 512 if (place == GAIM_BROWSER_NEW_WINDOW)
475 command = g_strdup_printf("opera -newwindow \"%s\"", uri); 513 command = g_strdup_printf("opera -newwindow \"%s\"", uri);
476 else if (place == GAIM_BROWSER_NEW_TAB) 514 else if (place == GAIM_BROWSER_NEW_TAB)
477 command = g_strdup_printf("opera -newpage \"%s\"", uri); 515 command = g_strdup_printf("opera -newpage \"%s\"", uri);
478 else if (place == GAIM_BROWSER_CURRENT) { 516 else if (place == GAIM_BROWSER_CURRENT)
479 remote_command = g_strdup_printf("opera -remote \"openURL(\"%s\")\"", uri); 517 {
518 remote_command = g_strdup_printf("opera -remote "
519 "\"openURL(\"%s\")\"", uri);
480 command = g_strdup_printf("opera \"%s\"", uri); 520 command = g_strdup_printf("opera \"%s\"", uri);
481 } else 521 }
522 else
482 command = g_strdup_printf("opera \"%s\"", uri); 523 command = g_strdup_printf("opera \"%s\"", uri);
483 524
484 } else if (!strcmp(web_browser, "kfmclient")) { 525 }
526 else if (!strcmp(web_browser, "kfmclient"))
527 {
485 command = g_strdup_printf("kfmclient openURL \"%s\"", uri); 528 command = g_strdup_printf("kfmclient openURL \"%s\"", uri);
486 /* does Konqueror have options to open in new tab and/or current window? */ 529 /*
487 530 * Does Konqueror have options to open in new tab
488 } else if (!strcmp(web_browser, "galeon")) { 531 * and/or current window?
532 */
533 }
534 else if (!strcmp(web_browser, "galeon"))
535 {
489 if (place == GAIM_BROWSER_NEW_WINDOW) 536 if (place == GAIM_BROWSER_NEW_WINDOW)
490 command = g_strdup_printf("galeon -w \"%s\"", uri); 537 command = g_strdup_printf("galeon -w \"%s\"", uri);
491 else if (place == GAIM_BROWSER_NEW_TAB) 538 else if (place == GAIM_BROWSER_NEW_TAB)
492 command = g_strdup_printf("galeon -n \"%s\"", uri); 539 command = g_strdup_printf("galeon -n \"%s\"", uri);
493 else 540 else
494 command = g_strdup_printf("galeon \"%s\"", uri); 541 command = g_strdup_printf("galeon \"%s\"", uri);
495 542 }
496 } else if (!strcmp(web_browser, "mozilla") || 543 else if (!strcmp(web_browser, "mozilla") ||
497 !strcmp(web_browser, "mozilla-firebird") || 544 !strcmp(web_browser, "mozilla-firebird") ||
498 !strcmp(web_browser, "firefox")) { 545 !strcmp(web_browser, "firefox"))
546 {
499 command = g_strdup_printf("%s \"%s\"", web_browser, uri); 547 command = g_strdup_printf("%s \"%s\"", web_browser, uri);
548
500 if (place == GAIM_BROWSER_NEW_WINDOW) 549 if (place == GAIM_BROWSER_NEW_WINDOW)
501 remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\",new-window)\"", web_browser, uri); 550 {
551 remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\","
552 "new-window)\"",
553 web_browser, uri);
554 }
502 else if (place == GAIM_BROWSER_NEW_TAB) 555 else if (place == GAIM_BROWSER_NEW_TAB)
503 remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\",new-tab)\"", web_browser, uri); 556 {
557 remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\","
558 "new-tab)\"",
559 web_browser, uri);
560 }
504 else if (place == GAIM_BROWSER_CURRENT) 561 else if (place == GAIM_BROWSER_CURRENT)
505 remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\")\"", web_browser, uri); 562 {
506 563 remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\")\"",
507 } else if (!strcmp(web_browser, "custom")) { 564 web_browser, uri);
565 }
566 }
567 else if (!strcmp(web_browser, "custom"))
568 {
508 const char *web_command; 569 const char *web_command;
509 570
510 web_command = gaim_prefs_get_string("/gaim/gtk/browsers/command"); 571 web_command = gaim_prefs_get_string("/gaim/gtk/browsers/command");
511 572
512 if (web_command == NULL || *web_command == '\0') { 573 if (web_command == NULL || *web_command == '\0')
574 {
513 gaim_notify_error(NULL, NULL, _("Unable to open URL"), 575 gaim_notify_error(NULL, NULL, _("Unable to open URL"),
514 _("The 'Manual' browser command has been " 576 _("The 'Manual' browser command has been "
515 "chosen, but no command has been set.")); 577 "chosen, but no command has been set."));
516 return NULL; 578 return NULL;
517 } 579 }
518 580
519 if (strstr(web_command, "%s")) 581 if (strstr(web_command, "%s"))
520 command = gaim_strreplace(web_command, "%s", uri); 582 command = gaim_strreplace(web_command, "%s", uri);
521 else { 583 else
584 {
522 /* 585 /*
523 * There is no "%s" in the browser command. Assume the user 586 * There is no "%s" in the browser command. Assume the user
524 * wanted the URL tacked on to the end of the command. 587 * wanted the URL tacked on to the end of the command.
525 */ 588 */
526 command = g_strdup_printf("%s %s", web_command, uri); 589 command = g_strdup_printf("%s %s", web_command, uri);
527 } 590 }
528 } 591 }
529 592
530 if (remote_command != NULL) { 593 if (remote_command != NULL)
594 {
531 /* try the remote command first */ 595 /* try the remote command first */
532 if (uri_command(remote_command, TRUE) != 0) 596 if (uri_command(remote_command, TRUE) != 0)
533 uri_command(command, FALSE); 597 uri_command(command, FALSE);
598
534 g_free(remote_command); 599 g_free(remote_command);
535 } else { 600
601 }
602 else
536 uri_command(command, FALSE); 603 uri_command(command, FALSE);
537 }
538 604
539 g_free(command); 605 g_free(command);
540 606
541 #else 607 #else /* !_WIN32 */
542 ShellExecute(NULL, NULL, uri, NULL, ".\\", 0); 608 ShellExecute(NULL, NULL, uri, NULL, ".\\", 0);
543 #endif 609 #endif /* !_WIN32 */
544 610
545 return NULL; 611 return NULL;
546 } 612 }
547 613
548 static GaimNotifyUiOps ops = 614 static GaimNotifyUiOps ops =