1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
12 #include "liblj/editfriendgroups.h"
16 #include "friendgroupedit.h"
23 GtkWidget
*egroupname
, *cpublic
;
25 JamAccountLJ
*account
;
26 LJFriendGroup
*editgroup
;
28 int freegroup
; /* index of first free group number. */
29 } friend_group_edit_dlg
;
32 editgroup_run(friend_group_edit_dlg
*fged
) {
34 LJEditFriendGroups
*efg
;
37 if (fged
->editgroup
) {
38 groupid
= fged
->editgroup
->id
;
40 groupid
= fged
->freegroup
;
43 efg
= lj_editfriendgroups_new(jam_account_lj_get_user(fged
->account
));
44 lj_editfriendgroups_add_edit(efg
, groupid
,
45 gtk_entry_get_text(GTK_ENTRY(fged
->egroupname
)),
46 gtk_toggle_button_get_active(
47 GTK_TOGGLE_BUTTON(fged
->cpublic
)));
49 ctx
= net_ctx_gtk_new(GTK_WINDOW(fged
->win
), _("Modifying Friend Group"));
50 if (!net_run_verb_ctx((LJVerb
*)efg
, ctx
, NULL
)) {
51 lj_editfriendgroups_free(efg
);
52 net_ctx_gtk_free(ctx
);
56 if (fged
->editgroup
== NULL
) {
57 /* we must create a new group */
58 fged
->editgroup
= lj_friendgroup_new();
59 fged
->editgroup
->id
= fged
->freegroup
;
61 string_replace(&fged
->editgroup
->name
,
62 g_strdup(gtk_entry_get_text(GTK_ENTRY(fged
->egroupname
))));
63 fged
->editgroup
->ispublic
=
64 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fged
->cpublic
));
66 lj_editfriendgroups_free(efg
);
67 net_ctx_gtk_free(ctx
);
72 entry_changed(GtkEntry
*entry
, GtkWidget
* button
) {
73 gtk_widget_set_sensitive(button
,
74 (strlen(gtk_entry_get_text(entry
)) > 0));
78 friend_group_edit_dlg_run(GtkWindow
*parent
, JamAccountLJ
*acc
, LJFriendGroup
*fg
, int freegroup
) {
79 friend_group_edit_dlg fged_actual
= {0};
80 friend_group_edit_dlg
*fged
= &fged_actual
;
81 GtkWidget
*table
, *button
, *label
;
87 fged
->freegroup
= freegroup
;
89 fged
->win
= gtk_dialog_new_with_buttons(
90 fg
? _("Edit Friend Group") : _("New Friend Group"),
91 parent
, GTK_DIALOG_MODAL
,
92 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
94 jam_win_set_size(GTK_WINDOW(fged
->win
), 200, 1);
96 table
= jam_table_new(fg
? 3 : 2, 2);
99 idstr
= g_strdup_printf("%d", fg
->id
);
100 label
= gtk_label_new(idstr
);
102 gtk_label_set_selectable(GTK_LABEL(label
), TRUE
);
103 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
104 jam_table_label_content(GTK_TABLE(table
), row
++, _("Group ID:"), label
);
107 fged
->egroupname
= gtk_entry_new();
108 jam_table_label_content(GTK_TABLE(table
), row
++, _("_Group Name:"), fged
->egroupname
);
110 fged
->cpublic
= gtk_check_button_new_with_mnemonic("_Public");
111 jam_table_fillrow(GTK_TABLE(table
), row
++, fged
->cpublic
);
113 jam_dialog_set_contents(GTK_DIALOG(fged
->win
), table
);
115 button
= gtk_dialog_add_button(GTK_DIALOG(fged
->win
),
116 fg
? " Change " : " Create ", GTK_RESPONSE_OK
);
117 /* enable/disable the button based on name text */
118 g_signal_connect(G_OBJECT(fged
->egroupname
), "changed",
119 G_CALLBACK(entry_changed
), button
);
121 /* fill in default values. */
123 gtk_entry_set_text(GTK_ENTRY(fged
->egroupname
), fg
->name
);
124 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fged
->cpublic
), fg
->ispublic
);
126 gtk_entry_set_text(GTK_ENTRY(fged
->egroupname
), "");
127 /* emit the "changed" signal, anyway. */
130 while (gtk_dialog_run(GTK_DIALOG(fged
->win
)) == GTK_RESPONSE_OK
) {
131 if (editgroup_run(fged
)) {
132 gtk_widget_destroy(fged
->win
);
133 return fged
->editgroup
;
136 gtk_widget_destroy(fged
->win
);