Mercurial > pidgin
comparison src/dialogs.c @ 4119:a6825994ab3a
[gaim-migrate @ 4336]
gtk1.2 code is a bad thing. 2 patches from javabsp.
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Mon, 23 Dec 2002 18:27:27 +0000 |
| parents | 02b415cbba3a |
| children | 26a18ba4d79f |
comparison
equal
deleted
inserted
replaced
| 4118:02b415cbba3a | 4119:a6825994ab3a |
|---|---|
| 260 char *name; | 260 char *name; |
| 261 GtkWidget *bbox; | 261 GtkWidget *bbox; |
| 262 GtkWidget *window; | 262 GtkWidget *window; |
| 263 GtkWidget *layout; | 263 GtkWidget *layout; |
| 264 }; | 264 }; |
| 265 | |
| 266 /* Wrapper to get all the text from a GtkTextView */ | |
| 267 gchar* gtk_text_view_get_text(GtkTextView *text, gboolean include_hidden_chars) | |
| 268 { | |
| 269 GtkTextBuffer *buffer; | |
| 270 GtkTextIter start, end; | |
| 271 | |
| 272 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); | |
| 273 gtk_text_buffer_get_start_iter(buffer, &start); | |
| 274 gtk_text_buffer_get_end_iter(buffer, &end); | |
| 275 | |
| 276 return gtk_text_buffer_get_text(buffer, &start, &end, include_hidden_chars); | |
| 277 } | |
| 265 | 278 |
| 266 /*------------------------------------------------------------------------*/ | 279 /*------------------------------------------------------------------------*/ |
| 267 /* Destroys */ | 280 /* Destroys */ |
| 268 /*------------------------------------------------------------------------*/ | 281 /*------------------------------------------------------------------------*/ |
| 269 | 282 |
| 1894 void do_save_info(GtkWidget *widget, struct set_info_dlg *b) | 1907 void do_save_info(GtkWidget *widget, struct set_info_dlg *b) |
| 1895 { | 1908 { |
| 1896 gchar *junk; | 1909 gchar *junk; |
| 1897 struct gaim_connection *gc; | 1910 struct gaim_connection *gc; |
| 1898 | 1911 |
| 1899 junk = gtk_editable_get_chars(GTK_EDITABLE(b->text), 0, -1); | 1912 junk = gtk_text_view_get_text(GTK_TEXT_VIEW(b->text), FALSE); |
| 1900 | 1913 |
| 1901 if (b->user) { | 1914 if (b->user) { |
| 1902 strncpy_withhtml(b->user->user_info, junk, sizeof b->user->user_info); | 1915 strncpy_withhtml(b->user->user_info, junk, sizeof b->user->user_info); |
| 1903 gc = b->user->gc; | 1916 gc = b->user->gc; |
| 1904 | 1917 |
| 2215 void show_set_info(struct gaim_connection *gc) | 2228 void show_set_info(struct gaim_connection *gc) |
| 2216 { | 2229 { |
| 2217 GtkWidget *buttons; | 2230 GtkWidget *buttons; |
| 2218 GtkWidget *label; | 2231 GtkWidget *label; |
| 2219 GtkWidget *vbox; | 2232 GtkWidget *vbox; |
| 2233 GtkTextBuffer *buffer; | |
| 2234 GtkWidget *frame; | |
| 2220 gchar *buf; | 2235 gchar *buf; |
| 2221 struct aim_user *tmp; | 2236 struct aim_user *tmp; |
| 2222 | 2237 |
| 2223 struct set_info_dlg *b = g_new0(struct set_info_dlg, 1); | 2238 struct set_info_dlg *b = g_new0(struct set_info_dlg, 1); |
| 2224 tmp = gc->user; | 2239 tmp = gc->user; |
| 2240 g_snprintf(buf, 256, "Changing info for %s:", tmp->username); | 2255 g_snprintf(buf, 256, "Changing info for %s:", tmp->username); |
| 2241 label = gtk_label_new(buf); | 2256 label = gtk_label_new(buf); |
| 2242 g_free(buf); | 2257 g_free(buf); |
| 2243 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5); | 2258 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5); |
| 2244 gtk_widget_show(label); | 2259 gtk_widget_show(label); |
| 2245 | 2260 |
| 2246 b->text = gtk_text_new(NULL, NULL); | 2261 frame = gtk_frame_new(NULL); |
| 2247 gtk_text_set_word_wrap(GTK_TEXT(b->text), TRUE); | 2262 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); |
| 2248 gtk_text_set_editable(GTK_TEXT(b->text), TRUE); | 2263 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); |
| 2249 gtk_widget_set_usize(b->text, 300, 200); | 2264 gtk_widget_show(frame); |
| 2265 | |
| 2266 b->text = gtk_text_view_new(); | |
| 2267 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(b->text), GTK_WRAP_WORD); | |
| 2268 gtk_widget_set_size_request(b->text, 300, 200); | |
| 2250 buf = g_malloc(strlen(tmp->user_info) + 1); | 2269 buf = g_malloc(strlen(tmp->user_info) + 1); |
| 2251 strncpy_nohtml(buf, tmp->user_info, strlen(tmp->user_info) + 1); | 2270 strncpy_nohtml(buf, tmp->user_info, strlen(tmp->user_info) + 1); |
| 2252 gtk_text_insert(GTK_TEXT(b->text), NULL, NULL, NULL, buf, -1); | 2271 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(b->text)); |
| 2272 gtk_text_buffer_set_text(buffer, buf, -1); | |
| 2253 g_free(buf); | 2273 g_free(buf); |
| 2254 gtk_box_pack_start(GTK_BOX(vbox), b->text, TRUE, TRUE, 0); | 2274 gtk_container_add(GTK_CONTAINER(frame), b->text); |
| 2255 gtk_widget_show(b->text); | 2275 gtk_widget_show(b->text); |
| 2256 gtk_window_set_focus(GTK_WINDOW(b->window), b->text); | 2276 gtk_window_set_focus(GTK_WINDOW(b->window), b->text); |
| 2257 | 2277 |
| 2258 buttons = gtk_hbox_new(FALSE, 5); | 2278 buttons = gtk_hbox_new(FALSE, 5); |
| 2259 gtk_box_pack_start(GTK_BOX(vbox), buttons, FALSE, FALSE, 0); | 2279 gtk_box_pack_start(GTK_BOX(vbox), buttons, FALSE, FALSE, 0); |
| 3355 /*------------------------------------------------------------------------*/ | 3375 /*------------------------------------------------------------------------*/ |
| 3356 | 3376 |
| 3357 static struct away_message *save_away_message(struct create_away *ca) | 3377 static struct away_message *save_away_message(struct create_away *ca) |
| 3358 { | 3378 { |
| 3359 struct away_message *am; | 3379 struct away_message *am; |
| 3360 guint text_len; | |
| 3361 gchar *away_message; | 3380 gchar *away_message; |
| 3362 | 3381 |
| 3363 if (!ca->mess) | 3382 if (!ca->mess) |
| 3364 am = g_new0(struct away_message, 1); | 3383 am = g_new0(struct away_message, 1); |
| 3365 else { | 3384 else { |
| 3366 am = ca->mess; | 3385 am = ca->mess; |
| 3367 } | 3386 } |
| 3368 | 3387 |
| 3388 | |
| 3369 g_snprintf(am->name, sizeof(am->name), "%s", gtk_entry_get_text(GTK_ENTRY(ca->entry))); | 3389 g_snprintf(am->name, sizeof(am->name), "%s", gtk_entry_get_text(GTK_ENTRY(ca->entry))); |
| 3370 text_len = gtk_text_get_length(GTK_TEXT(ca->text)); | 3390 away_message = gtk_text_view_get_text(GTK_TEXT_VIEW(ca->text), FALSE); |
| 3371 away_message = gtk_editable_get_chars(GTK_EDITABLE(ca->text), 0, text_len); | |
| 3372 | 3391 |
| 3373 g_snprintf(am->message, sizeof(am->message), "%s", away_message); | 3392 g_snprintf(am->message, sizeof(am->message), "%s", away_message); |
| 3374 g_free(away_message); | 3393 g_free(away_message); |
| 3375 | 3394 |
| 3376 if (!ca->mess) { | 3395 if (!ca->mess) { |
| 3393 _("Please give the message a title, or choose \"Make Away\" to use " | 3412 _("Please give the message a title, or choose \"Make Away\" to use " |
| 3394 "without saving."), GAIM_ERROR); | 3413 "without saving."), GAIM_ERROR); |
| 3395 return 0; | 3414 return 0; |
| 3396 } | 3415 } |
| 3397 | 3416 |
| 3398 if ((gtk_text_get_length(GTK_TEXT(ca->text)) == 0) && (type <= 1)) { | 3417 if (!gtk_text_view_get_text(GTK_TEXT_VIEW(ca->text), FALSE) && (type <= 1)) { |
| 3399 /* We shouldn't allow a blank message */ | 3418 /* We shouldn't allow a blank message */ |
| 3400 do_error_dialog(_("You cannot create an empty away message"), NULL, GAIM_ERROR); | 3419 do_error_dialog(_("You cannot create an empty away message"), NULL, GAIM_ERROR); |
| 3401 return 0; | 3420 return 0; |
| 3402 } | 3421 } |
| 3403 | 3422 |
| 3415 } | 3434 } |
| 3416 | 3435 |
| 3417 void use_away_mess(GtkWidget *widget, struct create_away *ca) | 3436 void use_away_mess(GtkWidget *widget, struct create_away *ca) |
| 3418 { | 3437 { |
| 3419 static struct away_message am; | 3438 static struct away_message am; |
| 3420 guint text_len; | |
| 3421 gchar *away_message; | 3439 gchar *away_message; |
| 3422 | 3440 |
| 3423 if (!check_away_mess(ca, 0)) | 3441 if (!check_away_mess(ca, 0)) |
| 3424 return; | 3442 return; |
| 3425 | 3443 |
| 3426 g_snprintf(am.name, sizeof(am.name), "%s", gtk_entry_get_text(GTK_ENTRY(ca->entry))); | 3444 g_snprintf(am.name, sizeof(am.name), "%s", gtk_entry_get_text(GTK_ENTRY(ca->entry))); |
| 3427 text_len = gtk_text_get_length(GTK_TEXT(ca->text)); | 3445 away_message = gtk_text_view_get_text(GTK_TEXT_VIEW(ca->text), FALSE); |
| 3428 if (text_len < 0) | |
| 3429 return; | |
| 3430 away_message = gtk_editable_get_chars(GTK_EDITABLE(ca->text), 0, text_len); | |
| 3431 | 3446 |
| 3432 g_snprintf(am.message, sizeof(am.message), "%s", away_message); | 3447 g_snprintf(am.message, sizeof(am.message), "%s", away_message); |
| 3433 g_free(away_message); | 3448 g_free(away_message); |
| 3434 | 3449 |
| 3435 do_away_message(NULL, &am); | 3450 do_away_message(NULL, &am); |
| 3456 GtkWidget *sw; | 3471 GtkWidget *sw; |
| 3457 GtkWidget *label; | 3472 GtkWidget *label; |
| 3458 GtkWidget *frame; | 3473 GtkWidget *frame; |
| 3459 GtkWidget *fbox; | 3474 GtkWidget *fbox; |
| 3460 GtkWidget *button; | 3475 GtkWidget *button; |
| 3476 GtkTextBuffer *buffer; | |
| 3461 | 3477 |
| 3462 struct create_away *ca = g_new0(struct create_away, 1); | 3478 struct create_away *ca = g_new0(struct create_away, 1); |
| 3463 | 3479 |
| 3464 /* Set up window */ | 3480 /* Set up window */ |
| 3465 GAIM_DIALOG(ca->window); | 3481 GAIM_DIALOG(ca->window); |
| 3495 ca->entry = gtk_entry_new(); | 3511 ca->entry = gtk_entry_new(); |
| 3496 gtk_box_pack_start(GTK_BOX(titlebox), ca->entry, TRUE, TRUE, 0); | 3512 gtk_box_pack_start(GTK_BOX(titlebox), ca->entry, TRUE, TRUE, 0); |
| 3497 gtk_widget_grab_focus(ca->entry); | 3513 gtk_widget_grab_focus(ca->entry); |
| 3498 gtk_widget_show(ca->entry); | 3514 gtk_widget_show(ca->entry); |
| 3499 | 3515 |
| 3500 sw = gtk_scrolled_window_new(NULL, NULL); | 3516 frame = gtk_frame_new(NULL); |
| 3501 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | 3517 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); |
| 3502 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | 3518 gtk_box_pack_start(GTK_BOX(fbox), frame, TRUE, TRUE, 0); |
| 3503 gtk_box_pack_start(GTK_BOX(fbox), sw, TRUE, TRUE, 0); | 3519 gtk_widget_show(frame); |
| 3504 gtk_widget_show(sw); | 3520 |
| 3505 | 3521 ca->text = gtk_text_view_new(); |
| 3506 ca->text = gtk_text_new(NULL, NULL); | 3522 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(ca->text), GTK_WRAP_WORD); |
| 3507 gtk_text_set_word_wrap(GTK_TEXT(ca->text), TRUE); | 3523 |
| 3508 gtk_text_set_editable(GTK_TEXT(ca->text), TRUE); | 3524 gtk_container_add(GTK_CONTAINER(frame), ca->text); |
| 3509 gtk_container_add(GTK_CONTAINER(sw), ca->text); | |
| 3510 gtk_widget_show(ca->text); | 3525 gtk_widget_show(ca->text); |
| 3511 | 3526 |
| 3512 | 3527 |
| 3513 if (dummy) { | 3528 if (dummy) { |
| 3514 struct away_message *amt; | 3529 struct away_message *amt; |
| 3515 GtkTreeIter iter; | 3530 GtkTreeIter iter; |
| 3516 int pos = 0; | 3531 int pos = 0; |
| 3517 GtkListStore *ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dummy))); | 3532 GtkListStore *ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dummy))); |
| 3518 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dummy)); | 3533 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dummy)); |
| 3519 GValue val = { 0, }; | 3534 GValue val = { 0, }; |
| 3535 GtkTextIter start; | |
| 3536 GtkTextBuffer *buffer; | |
| 3520 | 3537 |
| 3521 if (! gtk_tree_selection_get_selected (sel, (GtkTreeModel**)&ls, &iter)) | 3538 if (! gtk_tree_selection_get_selected (sel, (GtkTreeModel**)&ls, &iter)) |
| 3522 return; | 3539 return; |
| 3523 gtk_tree_model_get_value (GTK_TREE_MODEL(ls), &iter, 1, &val); | 3540 gtk_tree_model_get_value (GTK_TREE_MODEL(ls), &iter, 1, &val); |
| 3524 amt = g_value_get_pointer (&val); | 3541 amt = g_value_get_pointer (&val); |
| 3525 gtk_entry_set_text(GTK_ENTRY(ca->entry), amt->name); | 3542 gtk_entry_set_text(GTK_ENTRY(ca->entry), amt->name); |
| 3526 gtk_editable_insert_text(GTK_EDITABLE(ca->text), amt->message, | 3543 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ca->text)); |
| 3527 strlen(amt->message), &pos); | 3544 gtk_text_buffer_get_iter_at_offset(buffer, &start, pos); |
| 3545 gtk_text_buffer_insert(buffer, &start, amt->message, strlen(amt->message)); | |
| 3546 | |
| 3528 ca->mess = amt; | 3547 ca->mess = amt; |
| 3529 } | 3548 } |
| 3530 | 3549 |
| 3531 hbox = gtk_hbox_new(FALSE, 5); | 3550 hbox = gtk_hbox_new(FALSE, 5); |
| 3532 gtk_box_pack_start(GTK_BOX(tbox), hbox, FALSE, FALSE, 0); | 3551 gtk_box_pack_start(GTK_BOX(tbox), hbox, FALSE, FALSE, 0); |
