1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
9 #include "liblj/livejournal.h"
20 static gint
mood_tree_compare (gconstpointer a
, gconstpointer b
) {
21 const MoodTree
*mta
= a
, *mtb
= b
;
22 return g_ascii_strcasecmp(mta
->mood
->name
, mtb
->mood
->name
);
26 static void mood_tree_free (MoodTree
*mt
) {
27 g_slist_foreach(mt
->children
, (GFunc
) mood_tree_free
, NULL
);
28 g_slist_free(mt
->children
);
33 static MoodTree
*build_mood_tree (LJServer
*server
) {
34 GSList
*moodsleft
, *cur
;
35 GHashTable
*moodtrees
;
36 LJMood nullmood
= { 0 };
39 moodtrees
= g_hash_table_new(g_int_hash
, g_int_equal
);
40 moodsleft
= g_slist_copy(server
->moods
);
42 mtbase
= g_new0(MoodTree
, 1);
43 mtbase
->mood
= &nullmood
;
44 g_hash_table_insert(moodtrees
, &mtbase
->mood
->id
, mtbase
);
48 MoodTree
*mtparent
= NULL
, *mtnew
;
50 /* find mood that has a parent in the tree. */
51 for (cur
= moodsleft
; cur
; last
= cur
, cur
= cur
->next
) {
53 mtparent
= g_hash_table_lookup(moodtrees
, &mood
->parentid
);
59 mood
= moodsleft
->data
;
60 g_warning("nowhere to attach mood %d (%s) to %d?\n", mood
->id
, mood
->name
, mood
->parentid
);
64 if (last
) last
->next
= cur
->next
; else moodsleft
= cur
->next
;
67 mtnew
= g_new0(MoodTree
, 1);
69 mtparent
->children
= g_slist_insert_sorted(mtparent
->children
, mtnew
, mood_tree_compare
);
70 g_hash_table_insert(moodtrees
, &mtnew
->mood
->id
, mtnew
);
73 g_hash_table_destroy(moodtrees
);
79 static void populate_mood_list (GtkTreeStore
*store
, MoodTree
*mtbase
, GtkTreeIter
*parent
) {
83 for (l
= mtbase
->children
; l
; l
= l
->next
) {
85 gtk_tree_store_insert(store
, &iter
, parent
, -1);
86 gtk_tree_store_set(store
, &iter
, 0, mt
->mood
->name
, 1, mt
->mood
->id
, -1);
87 populate_mood_list(store
, mt
, &iter
);
92 static GtkWidget
*make_mood_picker (MoodTree
*mt
) {
95 GtkTreeViewColumn
*column
;
96 GtkCellRenderer
*renderer
;
98 store
= gtk_tree_store_new(2, G_TYPE_STRING
, G_TYPE_INT
);
99 populate_mood_list(store
, mt
, NULL
);
101 tree
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
));
102 g_object_unref(G_OBJECT(store
));
104 renderer
= gtk_cell_renderer_text_new();
105 column
= gtk_tree_view_column_new_with_attributes(_("Mood"), renderer
, "text", 0, NULL
);
106 gtk_tree_view_append_column(GTK_TREE_VIEW(tree
), column
);
108 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree
), FALSE
);
109 gtk_tree_view_expand_all(GTK_TREE_VIEW(tree
));
115 gboolean
mood_picker_run (GtkWindow
*parent
, JamHostLJ
*host
, int *moodid
, char *moodtext
) {
116 GtkWidget
*dlg
, *vbox
, *hbox
;
117 GtkWidget
*textentry
, *textpicker
, *scroll
;
120 mt
= NULL
; // XXX blogger build_mood_tree(host->server);
121 build_mood_tree(NULL
);
123 dlg
= gtk_dialog_new_with_buttons(_("Current Mood"), parent
, GTK_DIALOG_MODAL
, GTK_STOCK_OK
, GTK_RESPONSE_OK
, GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
, NULL
);
125 vbox
= gtk_vbox_new(FALSE
, 6);
126 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 6);
128 hbox
= gtk_hbox_new(FALSE
, 6);
129 gtk_box_pack_start(GTK_BOX(hbox
), gtk_label_new_with_mnemonic(_("Mood _Text:")), FALSE
, FALSE
, 0);
132 vbox
= gtk_vbox_new(FALSE
, 6);
133 textentry
= gtk_entry_new();
134 gtk_box_pack_start(GTK_BOX(vbox
), textentry
, FALSE
, FALSE
, 0);
136 textpicker
= make_mood_picker(mt
);
137 scroll
= scroll_wrap(textpicker
);
138 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll
), GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
);
139 gtk_box_pack_start(GTK_BOX(vbox
), scroll
, TRUE
, TRUE
, 0);
141 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 0);
143 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, TRUE
, TRUE
, 0);
145 hbox
= gtk_hbox_new(FALSE
, 6);
146 gtk_box_pack_start(GTK_BOX(hbox
), gtk_label_new_with_mnemonic(_("Mood _Icon:")), FALSE
, FALSE
, 0);
148 GtkWidget
*vbox
, *check
;
149 vbox
= gtk_vbox_new(FALSE
, 6);
150 check
= gtk_check_button_new_with_mnemonic(_("_Match Text"));
151 gtk_box_pack_start(GTK_BOX(vbox
), check
, FALSE
, FALSE
, 0);
152 /*iconpicker = make_mood_picker(mt);
153 scroll = scroll_wrap(iconpicker);
154 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
155 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
156 gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0); */
158 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 0);
160 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, TRUE
, TRUE
, 0);
162 gtk_widget_show_all(vbox
);
163 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg
)->vbox
), vbox
, TRUE
, TRUE
, 0);
165 gtk_dialog_run(GTK_DIALOG(dlg
));
166 gtk_widget_destroy(dlg
);