respect https prefix
[k8lowj.git] / src / friendgroupedit.c
blobf122ad5b35aad483776679c302c8a475806025c5
1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
3 */
4 #include "gtk-all.h"
5 #include "util-gtk.h"
7 #include <stdlib.h>
8 #include <string.h>
10 #include "liblj/editfriendgroups.h"
12 #include "conf.h"
13 #include "friendgroupedit.h"
14 #include "friends.h"
15 #include "network.h"
16 #include "util.h"
19 typedef struct {
20 GtkWidget *win;
21 GtkWidget *egroupname, *cpublic;
23 JamAccountLJ *account;
24 LJFriendGroup *editgroup;
26 int freegroup; /* index of first free group number. */
27 } friend_group_edit_dlg;
30 static gboolean editgroup_run (friend_group_edit_dlg *fged) {
31 NetContext *ctx;
32 LJEditFriendGroups *efg;
33 int groupid;
35 if (fged->editgroup) {
36 groupid = fged->editgroup->id;
37 } else {
38 groupid = fged->freegroup;
41 efg = lj_editfriendgroups_new(jam_account_lj_get_user(fged->account));
42 lj_editfriendgroups_add_edit(efg, groupid,
43 gtk_entry_get_text(GTK_ENTRY(fged->egroupname)),
44 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fged->cpublic)));
46 ctx = net_ctx_gtk_new(GTK_WINDOW(fged->win), _("Modifying Friend Group"));
47 if (!net_run_verb_ctx((LJVerb *)efg, ctx, NULL)) {
48 lj_editfriendgroups_free(efg);
49 net_ctx_gtk_free(ctx);
50 return FALSE;
53 if (fged->editgroup == NULL) {
54 /* we must create a new group */
55 fged->editgroup = lj_friendgroup_new();
56 fged->editgroup->id = fged->freegroup;
58 string_replace(&fged->editgroup->name, g_strdup(gtk_entry_get_text(GTK_ENTRY(fged->egroupname))));
59 fged->editgroup->ispublic = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fged->cpublic));
61 lj_editfriendgroups_free(efg);
62 net_ctx_gtk_free(ctx);
63 return TRUE;
67 static void entry_changed (GtkEntry *entry, GtkWidget *button) {
68 gtk_widget_set_sensitive(button, (strlen(gtk_entry_get_text(entry)) > 0));
72 LJFriendGroup *friend_group_edit_dlg_run (GtkWindow *parent, JamAccountLJ *acc, LJFriendGroup *fg, int freegroup) {
73 friend_group_edit_dlg fged_actual = { 0 };
74 friend_group_edit_dlg *fged = &fged_actual;
75 GtkWidget *table, *button, *label;
76 char *idstr;
77 int row = 0;
79 fged->account = acc;
80 fged->editgroup = fg;
81 fged->freegroup = freegroup;
83 fged->win = gtk_dialog_new_with_buttons(fg ? _("Edit Friend Group") : _("New Friend Group"), parent, GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
84 jam_win_set_size(GTK_WINDOW(fged->win), 200, 1);
86 table = jam_table_new((fg ? 3 : 2), 2);
88 if (fg) {
89 idstr = g_strdup_printf("%d", fg->id);
90 label = gtk_label_new(idstr);
91 g_free(idstr);
92 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
93 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
94 jam_table_label_content(GTK_TABLE(table), row++, _("Group ID:"), label);
97 fged->egroupname = gtk_entry_new();
98 jam_table_label_content(GTK_TABLE(table), row++, _("_Group Name:"), fged->egroupname);
100 fged->cpublic = gtk_check_button_new_with_mnemonic("_Public");
101 jam_table_fillrow(GTK_TABLE(table), row++, fged->cpublic);
103 jam_dialog_set_contents(GTK_DIALOG(fged->win), table);
105 button = gtk_dialog_add_button(GTK_DIALOG(fged->win), (fg ? " Change " : " Create "), GTK_RESPONSE_OK);
106 /* enable/disable the button based on name text */
107 g_signal_connect(G_OBJECT(fged->egroupname), "changed", G_CALLBACK(entry_changed), button);
109 /* fill in default values. */
110 if (fg) {
111 gtk_entry_set_text(GTK_ENTRY(fged->egroupname), fg->name);
112 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fged->cpublic), fg->ispublic);
113 } else {
114 gtk_entry_set_text(GTK_ENTRY(fged->egroupname), "");
115 /* emit the "changed" signal, anyway. */
118 while (gtk_dialog_run(GTK_DIALOG(fged->win)) == GTK_RESPONSE_OK) {
119 if (editgroup_run(fged)) {
120 gtk_widget_destroy(fged->win);
121 return fged->editgroup;
124 gtk_widget_destroy(fged->win);
125 return NULL;