Mercurial > pidgin
changeset 14132:2c85b0f97dd0
[gaim-migrate @ 16774]
Add a new custom status dialog, and a corresponding entry in the status-selector in the buddylist.
But you cannot set any per-account status yet.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Tue, 15 Aug 2006 20:23:58 +0000 |
parents | db2311999862 |
children | 31d33e7bc0e6 |
files | console/gntblist.c console/gntstatus.c console/libgnt/gntcombobox.c |
diffstat | 3 files changed, 205 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/console/gntblist.c Tue Aug 15 18:05:14 2006 +0000 +++ b/console/gntblist.c Tue Aug 15 20:23:58 2006 +0000 @@ -45,6 +45,7 @@ STATUS_PRIMITIVE = 0, STATUS_SAVED_POPULAR, STATUS_SAVED_ALL, + STATUS_SAVED_NEW } StatusType; typedef struct @@ -1065,6 +1066,13 @@ gaim_savedstatus_get_title(iter->data)); } + /* New savedstatus */ + item = g_new0(StatusBoxItem, 1); + item->type = STATUS_SAVED_NEW; + items = g_list_prepend(items, item); + gnt_combo_box_add_data(GNT_COMBO_BOX(ggblist->status), item, + _("New...")); + /* More savedstatuses */ item = g_new0(StatusBoxItem, 1); item->type = STATUS_SAVED_ALL; @@ -1156,6 +1164,12 @@ gnt_box_give_focus_to_child(GNT_BOX(ggblist->window), ggblist->tree); gg_savedstatus_show_all(); } + else if (now->type == STATUS_SAVED_NEW) + { + savedstatus_changed(gaim_savedstatus_get_current(), NULL); + gnt_box_give_focus_to_child(GNT_BOX(ggblist->window), ggblist->tree); + gg_savedstatus_edit(NULL); + } else g_return_if_reached(); }
--- a/console/gntstatus.c Tue Aug 15 18:05:14 2006 +0000 +++ b/console/gntstatus.c Tue Aug 15 20:23:58 2006 +0000 @@ -1,10 +1,12 @@ #include <gnt.h> #include <gntbox.h> #include <gntbutton.h> +#include <gntcombobox.h> #include <gntentry.h> #include <gntlabel.h> #include <gnttree.h> +#include <notify.h> #include <request.h> #include "gntgaim.h" @@ -16,6 +18,18 @@ GntWidget *tree; } statuses; +typedef struct +{ + GaimSavedStatus *saved; + GntWidget *window; + GntWidget *title; + GntWidget *type; + GntWidget *message; + /* XXX: Stuff needed for per-account statuses */ +} EditStatus; + +static GList *edits; /* List of opened edit-status dialogs */ + static void reset_status_window(GntWidget *widget, gpointer null) { @@ -48,7 +62,18 @@ static void really_delete_status(GaimSavedStatus *saved) { - /* XXX: Close any modify dialog opened for the savedstatus */ + GList *iter; + + for (iter = edits; iter; iter = iter->next) + { + EditStatus *edit = iter->data; + if (edit->saved == saved) + { + gnt_widget_destroy(edit->window); + break; + } + } + if (statuses.tree) gnt_tree_remove(GNT_TREE(statuses.tree), saved); @@ -80,6 +105,14 @@ gaim_savedstatus_activate(gnt_tree_get_selection_data(GNT_TREE(statuses.tree))); } +static void +edit_savedstatus_cb(GntWidget *widget, gpointer null) +{ + g_return_if_fail(statuses.tree != NULL); + + gg_savedstatus_edit(gnt_tree_get_selection_data(GNT_TREE(statuses.tree))); +} + void gg_savedstatus_show_all() { GntWidget *window, *tree, *box, *button; @@ -114,9 +147,13 @@ button = gnt_button_new(_("Add")); gnt_box_add_widget(GNT_BOX(box), button); + g_signal_connect_swapped(G_OBJECT(button), "activate", + G_CALLBACK(gg_savedstatus_edit), NULL); button = gnt_button_new(_("Edit")); gnt_box_add_widget(GNT_BOX(box), button); + g_signal_connect(G_OBJECT(button), "activate", + G_CALLBACK(edit_savedstatus_cb), NULL); button = gnt_button_new(_("Delete")); gnt_box_add_widget(GNT_BOX(box), button); @@ -133,7 +170,159 @@ gnt_widget_show(window); } +static void +update_edit_list(GntWidget *widget, EditStatus *edit) +{ + edits = g_list_remove(edits, edit); + gaim_notify_close_with_handle(edit); + g_free(edit); +} + +static void +save_savedstatus_cb(GntWidget *button, EditStatus *edit) +{ + const char *title, *message; + GaimStatusPrimitive prim; + GaimSavedStatus *find; + + title = gnt_entry_get_text(GNT_ENTRY(edit->title)); + message = gnt_entry_get_text(GNT_ENTRY(edit->message)); + if (!message || !*message) + message = NULL; + + prim = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(edit->type))); + + if (!title || !*title) + { + gaim_notify_error(edit, _("Error"), _("Invalid title"), + _("Please enter a non-empty title for the status.")); + return; + } + + find = gaim_savedstatus_find(title); + if (find && find != edit->saved) + { + gaim_notify_error(edit, _("Error"), _("Duplicate title"), + _("Please enter a different title for the status.")); + return; + } + + if (edit->saved == NULL) + { + edit->saved = gaim_savedstatus_new(title, prim); + gaim_savedstatus_set_message(edit->saved, message); + if (statuses.tree) + gnt_tree_add_row_last(GNT_TREE(statuses.tree), edit->saved, + gnt_tree_create_row(GNT_TREE(statuses.tree), title, + gaim_primitive_get_name_from_type(prim), message), NULL); + } + else + { + gaim_savedstatus_set_title(edit->saved, title); + gaim_savedstatus_set_type(edit->saved, prim); + gaim_savedstatus_set_message(edit->saved, message); + if (statuses.tree) + { + gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 0, title); + gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 1, + gaim_primitive_get_name_from_type(prim)); + gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 2, message); + } + } + + if (g_object_get_data(G_OBJECT(button), "use")) + gaim_savedstatus_activate(edit->saved); + + gnt_widget_destroy(edit->window); +} + void gg_savedstatus_edit(GaimSavedStatus *saved) { + EditStatus *edit; + GntWidget *window, *box, *button, *entry, *combo, *label; + GaimStatusPrimitive prims[] = {GAIM_STATUS_AVAILABLE, GAIM_STATUS_AWAY, + GAIM_STATUS_INVISIBLE, GAIM_STATUS_OFFLINE, GAIM_STATUS_UNSET}, current; + int i; + + if (saved) + { + GList *iter; + for (iter = edits; iter; iter = iter->next) + { + edit = iter->data; + if (edit->saved == saved) + return; + } + } + + edit = g_new0(EditStatus, 1); + edit->saved = saved; + edit->window = window = gnt_vbox_new(FALSE); + gnt_box_set_toplevel(GNT_BOX(window), TRUE); + gnt_box_set_title(GNT_BOX(window), _("Edit Status")); + gnt_box_set_fill(GNT_BOX(window), TRUE); + gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_LEFT); + gnt_box_set_pad(GNT_BOX(window), 0); + + edits = g_list_append(edits, edit); + + /* Title */ + box = gnt_hbox_new(FALSE); + gnt_box_add_widget(GNT_BOX(window), box); + gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Title"))); + + edit->title = entry = gnt_entry_new(saved ? gaim_savedstatus_get_title(saved) : NULL); + gnt_box_add_widget(GNT_BOX(box), entry); + + /* Type */ + box = gnt_hbox_new(FALSE); + gnt_box_add_widget(GNT_BOX(window), box); + gnt_box_add_widget(GNT_BOX(box), label = gnt_label_new(_("Status"))); + gnt_widget_set_size(label, 0, 1); + + edit->type = combo = gnt_combo_box_new(); + gnt_box_add_widget(GNT_BOX(box), combo); + current = saved ? gaim_savedstatus_get_type(saved) : GAIM_STATUS_UNSET; + for (i = 0; prims[i] != GAIM_STATUS_UNSET; i++) + { + gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(prims[i]), + gaim_primitive_get_name_from_type(prims[i])); + if (prims[i] == current) + gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(current)); + } + + /* Message */ + box = gnt_hbox_new(FALSE); + gnt_box_add_widget(GNT_BOX(window), box); + gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message"))); + + edit->message = entry = gnt_entry_new(saved ? gaim_savedstatus_get_message(saved) : NULL); + gnt_box_add_widget(GNT_BOX(box), entry); + + /* The buttons */ + box = gnt_hbox_new(FALSE); + gnt_box_add_widget(GNT_BOX(window), box); + + /* Save */ + button = gnt_button_new(_("Save")); + gnt_box_add_widget(GNT_BOX(box), button); + g_object_set_data(G_OBJECT(button), "use", NULL); + g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_savedstatus_cb), edit); + + /* Save & Use */ + button = gnt_button_new(_("Save & Use")); + gnt_box_add_widget(GNT_BOX(box), button); + g_object_set_data(G_OBJECT(button), "use", GINT_TO_POINTER(TRUE)); + g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_savedstatus_cb), edit); + + /* Cancel */ + button = gnt_button_new(_("Cancel")); + gnt_box_add_widget(GNT_BOX(box), button); + g_signal_connect_swapped(G_OBJECT(button), "activate", + G_CALLBACK(gnt_widget_destroy), window); + + g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(update_edit_list), edit); + + gnt_widget_show(window); }
--- a/console/libgnt/gntcombobox.c Tue Aug 15 18:05:14 2006 +0000 +++ b/console/libgnt/gntcombobox.c Tue Aug 15 20:23:58 2006 +0000 @@ -79,7 +79,7 @@ GntWidget *dd = GNT_COMBO_BOX(widget)->dropdown; gnt_widget_size_request(dd); widget->priv.height = 3; /* For now, a combobox will have border */ - widget->priv.width = MIN(10, dd->priv.width + 4); + widget->priv.width = MAX(10, dd->priv.width + 4); } }