1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
13 add_menu_item(GtkMenuShell
*ms
, const gchar
*id
, const gchar
*text
) {
17 hbox
= gtk_hbox_new(FALSE
, 3);
18 gtk_box_pack_start(GTK_BOX(hbox
),
19 gtk_image_new_from_stock(id
, GTK_ICON_SIZE_MENU
),
21 gtk_box_pack_start(GTK_BOX(hbox
),
22 gtk_label_new(text
), FALSE
, FALSE
, 0);
24 item
= gtk_menu_item_new();
25 gtk_container_add(GTK_CONTAINER(item
), hbox
);
26 gtk_menu_shell_append(ms
, item
);
31 make_usertype_omenu() {
32 GtkWidget
*omenu
, *menu
;
34 menu
= gtk_menu_new();
35 add_menu_item(GTK_MENU_SHELL(menu
), "logjam-ljuser", _("LJR User"));
36 add_menu_item(GTK_MENU_SHELL(menu
), "logjam-ljcomm", _("LJR Community"));
37 add_menu_item(GTK_MENU_SHELL(menu
), "logjam-ljuser", _("User"));
38 add_menu_item(GTK_MENU_SHELL(menu
), "logjam-ljcomm", _("Community"));
40 omenu
= gtk_option_menu_new();
41 gtk_option_menu_set_menu(GTK_OPTION_MENU(omenu
), menu
);
46 link_journal_dialog_run(GtkWindow
*win
, JamDoc
*doc
) {
48 GtkWidget
*vbox
, *hbox
, *entry
, *omenu
;
49 GtkSizeGroup
*sizegroup
;
50 GtkTextBuffer
*buffer
;
51 GtkTextIter start
, end
;
52 char *username
= NULL
;
54 gboolean selection
= FALSE
;
56 buffer
= jam_doc_get_text_buffer(doc
);
57 if (gtk_text_buffer_get_selection_bounds(buffer
, &start
, &end
)) {
58 username
= gtk_text_buffer_get_text(buffer
, &start
, &end
, FALSE
);
62 dlg
= gtk_dialog_new_with_buttons(_("Insert lj user / lj community Tag"),
63 win
, GTK_DIALOG_MODAL
,
64 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
65 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
67 gtk_dialog_set_default_response(GTK_DIALOG(dlg
), GTK_RESPONSE_OK
);
68 vbox
= gtk_vbox_new(FALSE
, 5);
69 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 10);
71 sizegroup
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
73 entry
= gtk_entry_new();
74 gtk_entry_set_activates_default(GTK_ENTRY(entry
), TRUE
);
76 gtk_entry_set_text(GTK_ENTRY(entry
), username
);
79 hbox
= labelled_box_new_sg(_("_Username:"), entry
, sizegroup
);
80 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
82 omenu
= make_usertype_omenu();
83 hbox
= labelled_box_new_sg(_("User _Type:"), omenu
, sizegroup
);
84 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
86 jam_dialog_set_contents(GTK_DIALOG(dlg
), vbox
);
88 if (gtk_dialog_run(GTK_DIALOG(dlg
)) != GTK_RESPONSE_OK
) {
89 gtk_widget_destroy(dlg
);
92 username
= gtk_editable_get_chars(GTK_EDITABLE(entry
), 0, -1);
93 usertype
= gtk_option_menu_get_history(GTK_OPTION_MENU(omenu
));
94 gtk_widget_destroy(dlg
);
95 if (username
[0] == 0) {
101 gtk_text_buffer_delete(buffer
, &start
, &end
);
103 gtk_text_buffer_get_iter_at_mark(buffer
, &start
,
104 gtk_text_buffer_get_insert(buffer
));
106 if (usertype
> 1) gtk_text_buffer_insert(buffer
, &start
, "<lj ", -1);
107 else gtk_text_buffer_insert(buffer
, &start
, "<ljr ", -1);
109 gtk_text_buffer_insert(buffer
, &start
, "user=\"", -1);
111 gtk_text_buffer_insert(buffer
, &start
, "comm=\"", -1);
112 xml_escape(&username
);
113 gtk_text_buffer_insert(buffer
, &start
, username
, -1);
115 gtk_text_buffer_insert(buffer
, &start
, "\" />", -1);