From d5e907193f0b29abb5a10f16c6e141183bbb3c4f Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Tue, 21 Apr 2009 11:48:02 +0800 Subject: Skeleton of a new presets dialog --- libempathy-gtk/Makefile.am | 2 + libempathy-gtk/empathy-status-preset-dialog.c | 83 +++++++++++++++++++++++++++ libempathy-gtk/empathy-status-preset-dialog.h | 63 ++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 libempathy-gtk/empathy-status-preset-dialog.c create mode 100644 libempathy-gtk/empathy-status-preset-dialog.h (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 6f3b99ba6..2d9b21b00 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -50,6 +50,7 @@ libempathy_gtk_la_SOURCES = \ empathy-smiley-manager.c \ empathy-spell.c \ empathy-spell-dialog.c \ + empathy-status-preset-dialog.c \ empathy-theme-boxes.c \ empathy-theme-irc.c \ empathy-theme-manager.c \ @@ -103,6 +104,7 @@ libempathy_gtk_headers = \ empathy-smiley-manager.h \ empathy-spell.h \ empathy-spell-dialog.h \ + empathy-status-preset-dialog.h \ empathy-theme-boxes.h \ empathy-theme-irc.h \ empathy-theme-manager.h \ diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c new file mode 100644 index 000000000..4c3cf2490 --- /dev/null +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -0,0 +1,83 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * empathy-status-preset-dialog.c + * + * EmpathyStatusPresetDialog - a dialog for adding and removing preset status + * messages. + * + * Copyright (C) 2009 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Davyd Madeley + */ + +#include "config.h" + +#include +#include + +#include + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include + +#include "empathy-status-preset-dialog.h" + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyStatusPresetDialog) + +G_DEFINE_TYPE (EmpathyStatusPresetDialog, empathy_status_preset_dialog, GTK_TYPE_DIALOG) + +typedef struct _EmpathyStatusPresetDialogPriv EmpathyStatusPresetDialogPriv; +struct _EmpathyStatusPresetDialogPriv +{ + int dum; /*dummy*/ +}; + +static void +empathy_status_preset_dialog_class_init (EmpathyStatusPresetDialogClass *class) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (class); + + g_type_class_add_private (gobject_class, + sizeof (EmpathyStatusPresetDialogPriv)); +} + +static void +empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = self->priv = + G_TYPE_INSTANCE_GET_PRIVATE (self, + EMPATHY_TYPE_STATUS_PRESET_DIALOG, + EmpathyStatusPresetDialogPriv); + + (void) priv; +} + +GtkWidget * +empathy_status_preset_dialog_new (GtkWindow *parent) +{ + GtkWidget *self = g_object_new (EMPATHY_TYPE_STATUS_PRESET_DIALOG, + NULL); + + if (parent) { + gtk_window_set_transient_for (GTK_WINDOW (self), parent); + } + + return self; +} diff --git a/libempathy-gtk/empathy-status-preset-dialog.h b/libempathy-gtk/empathy-status-preset-dialog.h new file mode 100644 index 000000000..e53c3d8ad --- /dev/null +++ b/libempathy-gtk/empathy-status-preset-dialog.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * empathy-status-preset-dialog.c + * + * EmpathyStatusPresetDialog - a dialog for adding and removing preset status + * messages. + * + * Copyright (C) 2009 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Davyd Madeley + */ + +#ifndef __EMPATHY_STATUS_PRESET_DIALOG_H__ +#define __EMPATHY_STATUS_PRESET_DIALOG_H__ + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_STATUS_PRESET_DIALOG (empathy_status_preset_dialog_get_type ()) +#define EMPATHY_STATUS_PRESET_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_STATUS_PRESET_DIALOG, EmpathyStatusPresetDialog)) +#define EMPATHY_STATUS_PRESET_DIALOG_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), EMPATHY_TYPE_STATUS_PRESET_DIALOG, EmpathyStatusPresetDialogClass)) +#define EMPATHY_IS_STATUS_PRESET_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_STATUS_PRESET_DIALOG)) +#define EMPATHY_IS_STATUS_PRESET_DIALOG_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), EMPATHY_TYPE_STATUS_PRESET_DIALOG)) +#define EMPATHY_STATUS_PRESET_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_STATUS_PRESET_DIALOG, EmpathyStatusPresetDialogClass)) + +typedef struct _EmpathyStatusPresetDialog EmpathyStatusPresetDialog; +typedef struct _EmpathyStatusPresetDialogClass EmpathyStatusPresetDialogClass; + +struct _EmpathyStatusPresetDialog +{ + GtkDialog parent; + + /*< private >*/ + gpointer priv; +}; + +struct _EmpathyStatusPresetDialogClass +{ + GtkDialogClass parent_class; +}; + +GType empathy_status_preset_dialog_get_type (void); +GtkWidget *empathy_status_preset_dialog_new (GtkWindow *parent); + +G_END_DECLS + +#endif -- cgit v1.2.3 From 3803226331340b213351cf3bf92c85485bfe66b3 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Tue, 21 Apr 2009 14:51:14 +0800 Subject: List presets in the treeview --- libempathy-gtk/Makefile.am | 1 + libempathy-gtk/empathy-status-preset-dialog.c | 128 ++++++++++++++++++++++++- libempathy-gtk/empathy-status-preset-dialog.ui | 84 ++++++++++++++++ 3 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 libempathy-gtk/empathy-status-preset-dialog.ui (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 2d9b21b00..7fb4579cf 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -131,6 +131,7 @@ ui_DATA = \ empathy-account-widget-groupwise.ui \ empathy-account-widget-aim.ui \ empathy-spell-dialog.ui \ + empathy-status-preset-dialog.ui \ empathy-log-window.ui \ empathy-chat.ui \ empathy-new-message-dialog.ui diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index 4c3cf2490..88b12db3e 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -30,21 +30,39 @@ #include #include +#include + +#include #include #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include +#include "empathy-ui-utils.h" #include "empathy-status-preset-dialog.h" #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyStatusPresetDialog) -G_DEFINE_TYPE (EmpathyStatusPresetDialog, empathy_status_preset_dialog, GTK_TYPE_DIALOG) +G_DEFINE_TYPE (EmpathyStatusPresetDialog, empathy_status_preset_dialog, GTK_TYPE_DIALOG); + +static McPresence states[] = { + MC_PRESENCE_AVAILABLE, + MC_PRESENCE_DO_NOT_DISTURB, + MC_PRESENCE_AWAY +}; typedef struct _EmpathyStatusPresetDialogPriv EmpathyStatusPresetDialogPriv; struct _EmpathyStatusPresetDialogPriv { - int dum; /*dummy*/ + GtkWidget *presets_treeview; +}; + +enum +{ + PRESETS_STORE_STATE, + PRESETS_STORE_ICON_NAME, + PRESETS_STORE_STATUS, + PRESETS_STORE_N_COLS }; static void @@ -58,6 +76,82 @@ empathy_status_preset_dialog_class_init (EmpathyStatusPresetDialogClass *class) sizeof (EmpathyStatusPresetDialogPriv)); } +static void +status_preset_dialog_setup_presets_update (EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + GtkListStore *store; + int i; + + store = GTK_LIST_STORE (gtk_tree_view_get_model ( + GTK_TREE_VIEW (priv->presets_treeview))); + + for (i = 0; i < G_N_ELEMENTS (states); i++) + { + GList *presets, *l; + const char *icon_name; + + presets = empathy_status_presets_get (states[i], -1); + icon_name = empathy_icon_name_for_presence (states[i]); + + for (l = presets; l; l = l->next) { + char *preset = (char *) l->data; + + gtk_list_store_insert_with_values (store, + NULL, -1, + PRESETS_STORE_STATE, states[i], + PRESETS_STORE_ICON_NAME, icon_name, + PRESETS_STORE_STATUS, preset, + -1); + } + + g_list_free (presets); + } +} + +static void +status_preset_dialog_setup_presets_treeview (EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + GtkWidget *treeview = priv->presets_treeview; + GtkListStore *store; + GtkTreeViewColumn *column; + GtkCellRenderer *renderer; + + store = gtk_list_store_new (PRESETS_STORE_N_COLS, + MC_TYPE_PRESENCE, /* PRESETS_STORE_STATE */ + G_TYPE_STRING, /* PRESETS_STORE_ICON_NAME */ + G_TYPE_STRING); /* PRESETS_STORE_STATUS */ + + gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), + GTK_TREE_MODEL (store)); + g_object_unref (store); + + status_preset_dialog_setup_presets_update (self); + + column = gtk_tree_view_column_new (); + gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); + + renderer = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_add_attribute (column, renderer, + "icon-name", PRESETS_STORE_ICON_NAME); + + renderer = gtk_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_tree_view_column_add_attribute (column, renderer, + "text", PRESETS_STORE_STATUS); +} + +static void +status_preset_dialog_preset_selection_changed (GtkTreeSelection *selection, + GtkWidget *remove_button) +{ + /* update the sensitivity of the Remove button */ + gtk_widget_set_sensitive (remove_button, + gtk_tree_selection_get_selected (selection, NULL, NULL)); +} + static void empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) { @@ -65,8 +159,36 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_STATUS_PRESET_DIALOG, EmpathyStatusPresetDialogPriv); + GtkBuilder *gui; + GtkWidget *toplevel_vbox, *remove_button; + char *filename; + + (void) priv; /* hack */ + + gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE); + gtk_dialog_add_button (GTK_DIALOG (self), + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); + + filename = empathy_file_lookup ("empathy-status-preset-dialog.ui", + "libempathy-gtk"); + gui = empathy_builder_get_file (filename, + "toplevel-vbox", &toplevel_vbox, + "presets-treeview", &priv->presets_treeview, + "remove-button", &remove_button, + NULL); + g_free (filename); + + status_preset_dialog_setup_presets_treeview (self); + g_signal_connect (gtk_tree_view_get_selection ( + GTK_TREE_VIEW (priv->presets_treeview)), + "changed", + G_CALLBACK (status_preset_dialog_preset_selection_changed), + remove_button); + + gtk_box_pack_start(GTK_BOX (GTK_DIALOG (self)->vbox), toplevel_vbox, + TRUE, TRUE, 0); - (void) priv; + g_object_unref (gui); } GtkWidget * diff --git a/libempathy-gtk/empathy-status-preset-dialog.ui b/libempathy-gtk/empathy-status-preset-dialog.ui new file mode 100644 index 000000000..9bfae2cd4 --- /dev/null +++ b/libempathy-gtk/empathy-status-preset-dialog.ui @@ -0,0 +1,84 @@ + + + + + + True + 6 + vertical + 6 + + + True + True + never + etched-in + + + True + True + False + + + + + 0 + + + + + True + end + + + gtk-remove + True + False + True + True + True + + + False + False + 0 + + + + + False + 1 + + + + + True + 3 + + + True + + + 0 + + + + + gtk-add + True + True + True + True + + + 1 + + + + + False + 2 + + + + -- cgit v1.2.3 From e3b6bd0deedd3353ecde9cc50ec3fb90d9656ec4 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Tue, 21 Apr 2009 16:21:55 +0800 Subject: Make [Remove] work --- libempathy-gtk/empathy-status-preset-dialog.c | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index 88b12db3e..cf28352eb 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -86,6 +86,8 @@ status_preset_dialog_setup_presets_update (EmpathyStatusPresetDialog *self) store = GTK_LIST_STORE (gtk_tree_view_get_model ( GTK_TREE_VIEW (priv->presets_treeview))); + gtk_list_store_clear (store); + for (i = 0; i < G_N_ELEMENTS (states); i++) { GList *presets, *l; @@ -152,6 +154,36 @@ status_preset_dialog_preset_selection_changed (GtkTreeSelection *selection, gtk_tree_selection_get_selected (selection, NULL, NULL)); } +static void +status_preset_dialog_preset_remove (GtkWidget *button, + EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + McPresence state; + char *status; + + selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (priv->presets_treeview)); + + g_return_if_fail (gtk_tree_selection_get_selected (selection, + &model, &iter)); + + gtk_tree_model_get (model, &iter, + PRESETS_STORE_STATE, &state, + PRESETS_STORE_STATUS, &status, + -1); + + DEBUG ("REMOVE PRESET (%i, %s)\n", state, status); + empathy_status_presets_remove (state, status); + + g_free (status); + + status_preset_dialog_setup_presets_update (self); +} + static void empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) { @@ -184,6 +216,9 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) "changed", G_CALLBACK (status_preset_dialog_preset_selection_changed), remove_button); + empathy_builder_connect (gui, self, + "remove-button", "clicked", status_preset_dialog_preset_remove, + NULL); gtk_box_pack_start(GTK_BOX (GTK_DIALOG (self)->vbox), toplevel_vbox, TRUE, TRUE, 0); -- cgit v1.2.3 From cf70c333979664fc8298b842e4d1d42df69a0dab Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Wed, 22 Apr 2009 09:37:33 +0800 Subject: Make [Add] work --- libempathy-gtk/empathy-status-preset-dialog.c | 155 ++++++++++++++++++++++++- libempathy-gtk/empathy-status-preset-dialog.ui | 1 + 2 files changed, 150 insertions(+), 6 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index cf28352eb..ecb794b44 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -55,6 +55,11 @@ typedef struct _EmpathyStatusPresetDialogPriv EmpathyStatusPresetDialogPriv; struct _EmpathyStatusPresetDialogPriv { GtkWidget *presets_treeview; + GtkWidget *add_combobox; + GtkWidget *add_button; + + McPresence selected_state; + gboolean add_combo_changed; }; enum @@ -65,6 +70,15 @@ enum PRESETS_STORE_N_COLS }; +enum +{ + ADD_COMBO_STATE, + ADD_COMBO_ICON_NAME, + ADD_COMBO_STATUS, + ADD_COMBO_DEFAULT_TEXT, + ADD_COMBO_N_COLS +}; + static void empathy_status_preset_dialog_class_init (EmpathyStatusPresetDialogClass *class) { @@ -88,8 +102,7 @@ status_preset_dialog_setup_presets_update (EmpathyStatusPresetDialog *self) gtk_list_store_clear (store); - for (i = 0; i < G_N_ELEMENTS (states); i++) - { + for (i = 0; i < G_N_ELEMENTS (states); i++) { GList *presets, *l; const char *icon_name; @@ -111,6 +124,64 @@ status_preset_dialog_setup_presets_update (EmpathyStatusPresetDialog *self) } } +static void +status_preset_add_combo_reset (EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + + gtk_combo_box_set_active (GTK_COMBO_BOX (priv->add_combobox), 0); +} + +static void +status_preset_dialog_setup_add_combobox (EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + GtkWidget *combobox = priv->add_combobox; + GtkListStore *store; + GtkCellRenderer *renderer; + int i; + + store = gtk_list_store_new (ADD_COMBO_N_COLS, + MC_TYPE_PRESENCE, /* ADD_COMBO_STATE */ + G_TYPE_STRING, /* ADD_COMBO_ICON_NAME */ + G_TYPE_STRING, /* ADD_COMBO_STATUS */ + G_TYPE_STRING); /* ADD_COMBO_DEFAULT_TEXT */ + + gtk_combo_box_set_model (GTK_COMBO_BOX (combobox), + GTK_TREE_MODEL (store)); + g_object_unref (store); + + gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (combobox), + ADD_COMBO_DEFAULT_TEXT); + + for (i = 0; i < G_N_ELEMENTS (states); i++) { + gtk_list_store_insert_with_values (store, NULL, -1, + ADD_COMBO_STATE, states[i], + ADD_COMBO_ICON_NAME, empathy_icon_name_for_presence (states[i]), + ADD_COMBO_STATUS, empathy_presence_get_default_message (states[i]), + ADD_COMBO_DEFAULT_TEXT, _("Enter Custom Message"), + -1); + } + + gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox)); + + renderer = gtk_cell_renderer_pixbuf_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox), renderer, + "icon-name", ADD_COMBO_ICON_NAME); + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox), renderer, + "text", ADD_COMBO_STATUS); + g_object_set (renderer, + "style", PANGO_STYLE_ITALIC, + "foreground", "Gray", /* FIXME - theme */ + NULL); + + status_preset_add_combo_reset (self); +} + static void status_preset_dialog_setup_presets_treeview (EmpathyStatusPresetDialog *self) { @@ -155,7 +226,7 @@ status_preset_dialog_preset_selection_changed (GtkTreeSelection *selection, } static void -status_preset_dialog_preset_remove (GtkWidget *button, +status_preset_dialog_preset_remove (GtkButton *button, EmpathyStatusPresetDialog *self) { EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); @@ -184,6 +255,68 @@ status_preset_dialog_preset_remove (GtkWidget *button, status_preset_dialog_setup_presets_update (self); } +static void +status_preset_dialog_add_combo_changed (GtkComboBox *combo, + EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + GtkWidget *entry; + GtkTreeModel *model; + GtkTreeIter iter; + + model = gtk_combo_box_get_model (combo); + entry = gtk_bin_get_child (GTK_BIN (combo)); + + if (gtk_combo_box_get_active_iter (combo, &iter)) { + char *icon_name; + GdkColor colour; + + gtk_tree_model_get (model, &iter, + PRESETS_STORE_STATE, &priv->selected_state, + PRESETS_STORE_ICON_NAME, &icon_name, + -1); + + gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry), + GTK_ENTRY_ICON_PRIMARY, + icon_name); + + g_free (icon_name); + + gtk_widget_grab_focus (entry); + gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1); + + priv->add_combo_changed = FALSE; + gtk_widget_set_sensitive (priv->add_button, FALSE); + + gdk_color_parse ("Gray", &colour); /* FIXME - theme */ + gtk_widget_modify_text (entry, GTK_STATE_NORMAL, &colour); + } else { + priv->add_combo_changed = TRUE; + gtk_widget_set_sensitive (priv->add_button, TRUE); + gtk_widget_modify_text (entry, GTK_STATE_NORMAL, NULL); + } +} + +static void +status_preset_dialog_add_preset (GtkWidget *widget, + EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + GtkWidget *entry; + const char *status; + + g_return_if_fail (priv->add_combo_changed); + + entry = gtk_bin_get_child (GTK_BIN (priv->add_combobox)); + status = gtk_entry_get_text (GTK_ENTRY (entry)); + + DEBUG ("ADD PRESET (%i, %s)\n", priv->selected_state, status); + empathy_status_presets_set_last (priv->selected_state, status); + + status_preset_dialog_setup_presets_update (self); + status_preset_add_combo_reset (self); +} + static void empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) { @@ -195,8 +328,6 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) GtkWidget *toplevel_vbox, *remove_button; char *filename; - (void) priv; /* hack */ - gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE); gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); @@ -207,19 +338,31 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) "toplevel-vbox", &toplevel_vbox, "presets-treeview", &priv->presets_treeview, "remove-button", &remove_button, + "add-combobox", &priv->add_combobox, + "add-button", &priv->add_button, NULL); g_free (filename); - status_preset_dialog_setup_presets_treeview (self); g_signal_connect (gtk_tree_view_get_selection ( GTK_TREE_VIEW (priv->presets_treeview)), "changed", G_CALLBACK (status_preset_dialog_preset_selection_changed), remove_button); + + g_signal_connect (gtk_bin_get_child (GTK_BIN (priv->add_combobox)), + "activate", + G_CALLBACK (status_preset_dialog_add_preset), + self); + empathy_builder_connect (gui, self, "remove-button", "clicked", status_preset_dialog_preset_remove, + "add-combobox", "changed", status_preset_dialog_add_combo_changed, + "add-button", "clicked", status_preset_dialog_add_preset, NULL); + status_preset_dialog_setup_presets_treeview (self); + status_preset_dialog_setup_add_combobox (self); + gtk_box_pack_start(GTK_BOX (GTK_DIALOG (self)->vbox), toplevel_vbox, TRUE, TRUE, 0); diff --git a/libempathy-gtk/empathy-status-preset-dialog.ui b/libempathy-gtk/empathy-status-preset-dialog.ui index 9bfae2cd4..2a1ee4c18 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.ui +++ b/libempathy-gtk/empathy-status-preset-dialog.ui @@ -66,6 +66,7 @@ gtk-add True + False True True True -- cgit v1.2.3 From 155a17d3ddc4d173a57429faa2d59bba01d5ac5c Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Wed, 22 Apr 2009 10:05:10 +0800 Subject: Connect new dialog into presence chooser, remove old dialog --- libempathy-gtk/Makefile.am | 1 - libempathy-gtk/empathy-presence-chooser.c | 237 +------------------------- libempathy-gtk/empathy-presence-chooser.ui | 140 --------------- libempathy-gtk/empathy-status-preset-dialog.c | 2 + 4 files changed, 11 insertions(+), 369 deletions(-) delete mode 100644 libempathy-gtk/empathy-presence-chooser.ui (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 7fb4579cf..63bcf5ae3 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -119,7 +119,6 @@ uidir = $(datadir)/empathy ui_DATA = \ empathy-contact-widget.ui \ empathy-contact-dialogs.ui \ - empathy-presence-chooser.ui \ empathy-account-widget-generic.ui \ empathy-account-widget-jabber.ui \ empathy-account-widget-msn.ui \ diff --git a/libempathy-gtk/empathy-presence-chooser.c b/libempathy-gtk/empathy-presence-chooser.c index 8e9574bc5..d565cf387 100644 --- a/libempathy-gtk/empathy-presence-chooser.c +++ b/libempathy-gtk/empathy-presence-chooser.c @@ -46,6 +46,7 @@ #include "empathy-ui-utils.h" #include "empathy-images.h" #include "empathy-presence-chooser.h" +#include "empathy-status-preset-dialog.h" /* Flashing delay for icons (milliseconds). */ #define FLASH_TIMEOUT 500 @@ -95,16 +96,6 @@ typedef struct { guint flash_timeout_id; } EmpathyPresenceChooserPriv; -typedef struct { - GtkWidget *dialog; - GtkWidget *checkbutton_save; - GtkWidget *comboboxentry_message; - GtkWidget *entry_message; - GtkWidget *combobox_status; - GtkTreeModel *model_status; -} CustomMessageDialog; - -static CustomMessageDialog *message_dialog = NULL; /* States to be listed in the menu. * Each state has a boolean telling if it can have custom message */ static guint states[] = {MC_PRESENCE_AVAILABLE, TRUE, @@ -130,7 +121,6 @@ static void presence_chooser_set_state (McPresence const gchar *status); static void presence_chooser_custom_activate_cb (GtkWidget *item, gpointer user_data); -static void presence_chooser_dialog_show (GtkWindow *parent); G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX_ENTRY); @@ -576,7 +566,7 @@ presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data) } if (type == ENTRY_TYPE_EDIT_CUSTOM) { - GtkWidget *window; + GtkWidget *window, *dialog; presence_chooser_reset_status (EMPATHY_PRESENCE_CHOOSER (self)); @@ -586,7 +576,9 @@ presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data) window = NULL; } - presence_chooser_dialog_show (GTK_WINDOW (window)); + dialog = empathy_status_preset_dialog_new (GTK_WINDOW (window)); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); } else if (type == ENTRY_TYPE_CUSTOM) { gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry), @@ -1058,220 +1050,9 @@ static void presence_chooser_custom_activate_cb (GtkWidget *item, gpointer user_data) { - presence_chooser_dialog_show (NULL); -} - -static McPresence -presence_chooser_dialog_get_selected (CustomMessageDialog *dialog) -{ - GtkTreeModel *model; - GtkTreeIter iter; - McPresence presence = LAST_MC_PRESENCE; - - model = gtk_combo_box_get_model (GTK_COMBO_BOX (dialog->combobox_status)); - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->combobox_status), &iter)) { - gtk_tree_model_get (model, &iter, - COL_PRESENCE, &presence, - -1); - } - - return presence; -} - -static void -presence_chooser_dialog_status_changed_cb (GtkWidget *widget, - CustomMessageDialog *dialog) -{ - GtkListStore *store; - GtkTreeIter iter; - McPresence presence = LAST_MC_PRESENCE; - GList *messages, *l; - - presence = presence_chooser_dialog_get_selected (dialog); - - store = gtk_list_store_new (1, G_TYPE_STRING); - messages = empathy_status_presets_get (presence, -1); - for (l = messages; l; l = l->next) { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, l->data, -1); - } - - gtk_entry_set_text (GTK_ENTRY (dialog->entry_message), - messages ? messages->data : ""); - - g_list_free (messages); - - gtk_combo_box_set_model (GTK_COMBO_BOX (dialog->comboboxentry_message), - GTK_TREE_MODEL (store)); - - g_object_unref (store); -} - -static void -presence_chooser_dialog_message_changed_cb (GtkWidget *widget, - CustomMessageDialog *dialog) -{ - McPresence presence; - GList *messages, *l; - const gchar *text; - gboolean found = FALSE; - - presence = presence_chooser_dialog_get_selected (dialog); - text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message)); - - messages = empathy_status_presets_get (presence, -1); - for (l = messages; l; l = l->next) { - if (!tp_strdiff (text, l->data)) { - found = TRUE; - break; - } - } - g_list_free (messages); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_save), - found); -} - -static void -presence_chooser_dialog_save_toggled_cb (GtkWidget *widget, - CustomMessageDialog *dialog) -{ - gboolean active; - McPresence state; - const gchar *text; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_save)); - state = presence_chooser_dialog_get_selected (dialog); - text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message)); - - if (active) { - empathy_status_presets_set_last (state, text); - } else { - empathy_status_presets_remove (state, text); - } -} - -static void -presence_chooser_dialog_setup (CustomMessageDialog *dialog) -{ - GtkListStore *store; - GtkCellRenderer *renderer; - GtkTreeIter iter; - guint i; - - store = gtk_list_store_new (COL_COUNT, - G_TYPE_STRING, /* Icon name */ - G_TYPE_STRING, /* Label */ - MC_TYPE_PRESENCE); /* Presence */ - gtk_combo_box_set_model (GTK_COMBO_BOX (dialog->combobox_status), - GTK_TREE_MODEL (store)); - - renderer = gtk_cell_renderer_pixbuf_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, FALSE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, - "icon-name", COL_ICON, - NULL); - g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL); - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, - "text", COL_LABEL, - NULL); - - for (i = 0; i < G_N_ELEMENTS (states); i += 2) { - if (!states[i+1]) { - continue; - } - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COL_ICON, empathy_icon_name_for_presence (states[i]), - COL_LABEL, empathy_presence_get_default_message (states[i]), - COL_PRESENCE, states[i], - -1); - } - - gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_status), 0); -} - -static void -presence_chooser_dialog_response_cb (GtkWidget *widget, - gint response, - CustomMessageDialog *dialog) -{ - if (response == GTK_RESPONSE_APPLY) { - McPresence state; - const gchar *text; - - state = presence_chooser_dialog_get_selected (dialog); - text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message)); + GtkWidget *dialog; - presence_chooser_set_state (state, text); - } - - gtk_widget_destroy (widget); + dialog = empathy_status_preset_dialog_new (NULL); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); } - -static void -presence_chooser_dialog_destroy_cb (GtkWidget *widget, - CustomMessageDialog *dialog) -{ - - g_free (dialog); - message_dialog = NULL; -} - -static void -presence_chooser_dialog_show (GtkWindow *parent) -{ - GtkBuilder *gui; - gchar *filename; - - if (message_dialog) { - gtk_window_present (GTK_WINDOW (message_dialog->dialog)); - return; - } - - message_dialog = g_new0 (CustomMessageDialog, 1); - - filename = empathy_file_lookup ("empathy-presence-chooser.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "custom_message_dialog", &message_dialog->dialog, - "checkbutton_save", &message_dialog->checkbutton_save, - "comboboxentry_message", &message_dialog->comboboxentry_message, - "combobox_status", &message_dialog->combobox_status, - NULL); - g_free (filename); - - empathy_builder_connect (gui, message_dialog, - "custom_message_dialog", "destroy", presence_chooser_dialog_destroy_cb, - "custom_message_dialog", "response", presence_chooser_dialog_response_cb, - "combobox_status", "changed", presence_chooser_dialog_status_changed_cb, - "checkbutton_save", "toggled", presence_chooser_dialog_save_toggled_cb, - NULL); - - g_object_unref (gui); - - /* Setup the message combobox */ - message_dialog->entry_message = GTK_BIN (message_dialog->comboboxentry_message)->child; - gtk_entry_set_activates_default (GTK_ENTRY (message_dialog->entry_message), TRUE); - gtk_entry_set_width_chars (GTK_ENTRY (message_dialog->entry_message), 25); - g_signal_connect (message_dialog->entry_message, "changed", - G_CALLBACK (presence_chooser_dialog_message_changed_cb), - message_dialog); - - presence_chooser_dialog_setup (message_dialog); - - gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (message_dialog->comboboxentry_message), 0); - - if (parent) { - gtk_window_set_transient_for ( - GTK_WINDOW (message_dialog->dialog), - parent); - } - - gtk_widget_show_all (message_dialog->dialog); -} - diff --git a/libempathy-gtk/empathy-presence-chooser.ui b/libempathy-gtk/empathy-presence-chooser.ui deleted file mode 100644 index 6e0a155d0..000000000 --- a/libempathy-gtk/empathy-presence-chooser.ui +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - True - 5 - Custom message - False - dialog - False - - - True - - - True - 5 - 3 - 2 - 6 - 6 - - - True - - - 1 - 2 - GTK_FILL - GTK_FILL - - - - - True - - - 1 - 2 - 1 - 2 - GTK_FILL - GTK_FILL - - - - - Save message - True - True - False - True - True - - - 2 - 2 - 3 - - - - - - True - 0 - Message: - - - 1 - 2 - GTK_FILL - - - - - - True - 0 - Status: - - - GTK_FILL - - - - - - 1 - - - - - True - end - - - gtk-cancel - True - True - True - False - True - - - False - False - 0 - - - - - gtk-apply - True - True - True - False - True - - - False - False - 1 - - - - - False - end - 0 - - - - - - closebutton1 - button1 - - - diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index ecb794b44..a428667e9 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -328,6 +328,8 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) GtkWidget *toplevel_vbox, *remove_button; char *filename; + gtk_window_set_title (GTK_WINDOW (self), + _("Edit Custom Messages")); gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE); gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); -- cgit v1.2.3 From 673bbbcbaf80c3ae640e329419fd0d29e3bd738d Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Wed, 22 Apr 2009 10:52:19 +0800 Subject: Add some labels to the UI --- libempathy-gtk/empathy-status-preset-dialog.ui | 37 +++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.ui b/libempathy-gtk/empathy-status-preset-dialog.ui index 2a1ee4c18..ead8ab85d 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.ui +++ b/libempathy-gtk/empathy-status-preset-dialog.ui @@ -7,6 +7,21 @@ 6 vertical 6 + + + True + 0 + Saved Presets + add-combobox + + + + + + False + 0 + + True @@ -22,7 +37,7 @@ - 0 + 1 @@ -47,7 +62,23 @@ False - 1 + 2 + + + + + True + 0 + Add _New Preset + True + add-combobox + + + + + + False + 3 @@ -78,7 +109,7 @@ False - 2 + 4 -- cgit v1.2.3 From 6f3fd3de6db0fae7071f8665a62fe0ba092590e9 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Wed, 22 Apr 2009 17:28:03 +0800 Subject: Fix up Add Preset combo focusing --- libempathy-gtk/empathy-status-preset-dialog.c | 101 +++++++++++++++++++++----- 1 file changed, 84 insertions(+), 17 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index a428667e9..22cba1a53 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -54,6 +54,8 @@ static McPresence states[] = { typedef struct _EmpathyStatusPresetDialogPriv EmpathyStatusPresetDialogPriv; struct _EmpathyStatusPresetDialogPriv { + int block_add_combo_changed; + GtkWidget *presets_treeview; GtkWidget *add_combobox; GtkWidget *add_button; @@ -159,7 +161,7 @@ status_preset_dialog_setup_add_combobox (EmpathyStatusPresetDialog *self) ADD_COMBO_STATE, states[i], ADD_COMBO_ICON_NAME, empathy_icon_name_for_presence (states[i]), ADD_COMBO_STATUS, empathy_presence_get_default_message (states[i]), - ADD_COMBO_DEFAULT_TEXT, _("Enter Custom Message"), + ADD_COMBO_DEFAULT_TEXT, "", -1); } @@ -255,6 +257,36 @@ status_preset_dialog_preset_remove (GtkButton *button, status_preset_dialog_setup_presets_update (self); } +static void +status_preset_dialog_set_add_combo_changed (EmpathyStatusPresetDialog *self, + gboolean state, + gboolean reset_text) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + GtkWidget *entry; + + entry = gtk_bin_get_child (GTK_BIN (priv->add_combobox)); + + priv->add_combo_changed = state; + gtk_widget_set_sensitive (priv->add_button, state); + + if (state) { + gtk_widget_modify_text (entry, GTK_STATE_NORMAL, NULL); + } else { + GdkColor colour; + + gdk_color_parse ("Gray", &colour); /* FIXME - theme */ + gtk_widget_modify_text (entry, GTK_STATE_NORMAL, &colour); + + if (reset_text) { + priv->block_add_combo_changed++; + gtk_entry_set_text (GTK_ENTRY (entry), + _("Enter Custom Message")); + priv->block_add_combo_changed--; + } + } +} + static void status_preset_dialog_add_combo_changed (GtkComboBox *combo, EmpathyStatusPresetDialog *self) @@ -264,12 +296,13 @@ status_preset_dialog_add_combo_changed (GtkComboBox *combo, GtkTreeModel *model; GtkTreeIter iter; + if (priv->block_add_combo_changed) return; + model = gtk_combo_box_get_model (combo); entry = gtk_bin_get_child (GTK_BIN (combo)); if (gtk_combo_box_get_active_iter (combo, &iter)) { char *icon_name; - GdkColor colour; gtk_tree_model_get (model, &iter, PRESETS_STORE_STATE, &priv->selected_state, @@ -282,18 +315,13 @@ status_preset_dialog_add_combo_changed (GtkComboBox *combo, g_free (icon_name); - gtk_widget_grab_focus (entry); - gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1); - - priv->add_combo_changed = FALSE; - gtk_widget_set_sensitive (priv->add_button, FALSE); - - gdk_color_parse ("Gray", &colour); /* FIXME - theme */ - gtk_widget_modify_text (entry, GTK_STATE_NORMAL, &colour); + status_preset_dialog_set_add_combo_changed (self, FALSE, TRUE); } else { - priv->add_combo_changed = TRUE; - gtk_widget_set_sensitive (priv->add_button, TRUE); - gtk_widget_modify_text (entry, GTK_STATE_NORMAL, NULL); + const char *status; + + status = gtk_entry_get_text (GTK_ENTRY (entry)); + status_preset_dialog_set_add_combo_changed (self, + strlen (status) > 0, FALSE); } } @@ -317,6 +345,40 @@ status_preset_dialog_add_preset (GtkWidget *widget, status_preset_add_combo_reset (self); } +static gboolean +status_preset_dialog_add_combo_press_event (GtkWidget *widget, + GdkEventButton *event, + EmpathyStatusPresetDialog *self) +{ + if (!GTK_WIDGET_HAS_FOCUS (widget)) { + /* if the widget isn't focused, focus it and select the text */ + gtk_widget_grab_focus (widget); + gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1); + + return TRUE; + } + + return FALSE; +} + +static gboolean +status_preset_dialog_add_combo_focus_out (GtkWidget *widget, + GdkEventFocus *event, + EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + const char *status; + + gtk_editable_set_position (GTK_EDITABLE (widget), 0); + + status = gtk_entry_get_text (GTK_ENTRY (widget)); + status_preset_dialog_set_add_combo_changed (self, + priv->add_combo_changed && strlen (status) > 0, + TRUE); + + return FALSE; +} + static void empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) { @@ -325,7 +387,7 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) EMPATHY_TYPE_STATUS_PRESET_DIALOG, EmpathyStatusPresetDialogPriv); GtkBuilder *gui; - GtkWidget *toplevel_vbox, *remove_button; + GtkWidget *toplevel_vbox, *remove_button, *entry; char *filename; gtk_window_set_title (GTK_WINDOW (self), @@ -351,9 +413,14 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) G_CALLBACK (status_preset_dialog_preset_selection_changed), remove_button); - g_signal_connect (gtk_bin_get_child (GTK_BIN (priv->add_combobox)), - "activate", - G_CALLBACK (status_preset_dialog_add_preset), + entry = gtk_bin_get_child (GTK_BIN (priv->add_combobox)); + g_signal_connect (entry, "activate", + G_CALLBACK (status_preset_dialog_add_preset), self); + g_signal_connect (entry, "button-press-event", + G_CALLBACK (status_preset_dialog_add_combo_press_event), + self); + g_signal_connect (entry, "focus-out-event", + G_CALLBACK (status_preset_dialog_add_combo_focus_out), self); empathy_builder_connect (gui, self, -- cgit v1.2.3 From 93cc6d738d5fc2a91b257c568dd08687368fe637 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Wed, 22 Apr 2009 17:34:23 +0800 Subject: Don't reset the state to Available when you click [Add] --- libempathy-gtk/empathy-status-preset-dialog.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index 22cba1a53..085332f35 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -60,7 +60,7 @@ struct _EmpathyStatusPresetDialogPriv GtkWidget *add_combobox; GtkWidget *add_button; - McPresence selected_state; + GtkTreeIter selected_iter; gboolean add_combo_changed; }; @@ -131,7 +131,8 @@ status_preset_add_combo_reset (EmpathyStatusPresetDialog *self) { EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->add_combobox), 0); + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->add_combobox), + &priv->selected_iter); } static void @@ -181,7 +182,7 @@ status_preset_dialog_setup_add_combobox (EmpathyStatusPresetDialog *self) "foreground", "Gray", /* FIXME - theme */ NULL); - status_preset_add_combo_reset (self); + gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); } static void @@ -304,8 +305,8 @@ status_preset_dialog_add_combo_changed (GtkComboBox *combo, if (gtk_combo_box_get_active_iter (combo, &iter)) { char *icon_name; + priv->selected_iter = iter; gtk_tree_model_get (model, &iter, - PRESETS_STORE_STATE, &priv->selected_state, PRESETS_STORE_ICON_NAME, &icon_name, -1); @@ -330,16 +331,23 @@ status_preset_dialog_add_preset (GtkWidget *widget, EmpathyStatusPresetDialog *self) { EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + GtkTreeModel *model; GtkWidget *entry; + McPresence state; const char *status; g_return_if_fail (priv->add_combo_changed); + model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->add_combobox)); entry = gtk_bin_get_child (GTK_BIN (priv->add_combobox)); + status = gtk_entry_get_text (GTK_ENTRY (entry)); + gtk_tree_model_get (model, &priv->selected_iter, + PRESETS_STORE_STATE, &state, + -1); - DEBUG ("ADD PRESET (%i, %s)\n", priv->selected_state, status); - empathy_status_presets_set_last (priv->selected_state, status); + DEBUG ("ADD PRESET (%i, %s)\n", state, status); + empathy_status_presets_set_last (state, status); status_preset_dialog_setup_presets_update (self); status_preset_add_combo_reset (self); -- cgit v1.2.3 From 40b9a5d3b177c458555342a90a56934a40564f59 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Thu, 23 Apr 2009 15:29:57 +0800 Subject: Fix function naming --- libempathy-gtk/empathy-status-preset-dialog.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index 085332f35..76ae06d40 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -93,7 +93,7 @@ empathy_status_preset_dialog_class_init (EmpathyStatusPresetDialogClass *class) } static void -status_preset_dialog_setup_presets_update (EmpathyStatusPresetDialog *self) +status_preset_dialog_presets_update (EmpathyStatusPresetDialog *self) { EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); GtkListStore *store; @@ -203,7 +203,7 @@ status_preset_dialog_setup_presets_treeview (EmpathyStatusPresetDialog *self) GTK_TREE_MODEL (store)); g_object_unref (store); - status_preset_dialog_setup_presets_update (self); + status_preset_dialog_presets_update (self); column = gtk_tree_view_column_new (); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); @@ -255,7 +255,7 @@ status_preset_dialog_preset_remove (GtkButton *button, g_free (status); - status_preset_dialog_setup_presets_update (self); + status_preset_dialog_presets_update (self); } static void @@ -349,7 +349,7 @@ status_preset_dialog_add_preset (GtkWidget *widget, DEBUG ("ADD PRESET (%i, %s)\n", state, status); empathy_status_presets_set_last (state, status); - status_preset_dialog_setup_presets_update (self); + status_preset_dialog_presets_update (self); status_preset_add_combo_reset (self); } -- cgit v1.2.3 From a41c75aceabdee7a14e54f5314d4cafc8eab9020 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Thu, 23 Apr 2009 15:49:42 +0800 Subject: Make it possible to edit a status message by double-clicking on it --- libempathy-gtk/empathy-status-preset-dialog.c | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index 76ae06d40..4913e4b86 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -185,6 +185,53 @@ status_preset_dialog_setup_add_combobox (EmpathyStatusPresetDialog *self) gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); } +static void +status_preset_dialog_status_edited (GtkCellRendererText *renderer, + char *path_str, + char *new_status, + EmpathyStatusPresetDialog *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + McPresence state; + char *old_status; + gboolean valid; + + if (strlen (new_status) == 0) { + /* status is empty, ignore */ + return; + } + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->presets_treeview)); + path = gtk_tree_path_new_from_string (path_str); + valid = gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_path_free (path); + + if (!valid) return; + + gtk_tree_model_get (model, &iter, + PRESETS_STORE_STATE, &state, + PRESETS_STORE_STATUS, &old_status, + -1); + + if (!strcmp (old_status, new_status)) { + /* statuses are the same */ + g_free (old_status); + return; + } + + DEBUG ("EDITED STATUS (%s) -> (%s)\n", old_status, new_status); + + empathy_status_presets_remove (state, old_status); + empathy_status_presets_set_last (state, new_status); + + g_free (old_status); + + status_preset_dialog_presets_update (self); +} + static void status_preset_dialog_setup_presets_treeview (EmpathyStatusPresetDialog *self) { @@ -217,6 +264,11 @@ status_preset_dialog_setup_presets_treeview (EmpathyStatusPresetDialog *self) gtk_tree_view_column_pack_start (column, renderer, TRUE); gtk_tree_view_column_add_attribute (column, renderer, "text", PRESETS_STORE_STATUS); + g_object_set (renderer, + "editable", TRUE, + NULL); + g_signal_connect (renderer, "edited", + G_CALLBACK (status_preset_dialog_status_edited), self); } static void -- cgit v1.2.3 From 88e713991752dfccebc37309571384165d557d6c Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Thu, 23 Apr 2009 19:20:44 +0800 Subject: gtk-doc entry --- libempathy-gtk/empathy-status-preset-dialog.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index 4913e4b86..562b9e4d9 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -498,6 +498,15 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) g_object_unref (gui); } +/** + * empathy_status_preset_dialog_new: + * @parent: the parent window of this dialog (or NULL) + * + * Creates a new #EmpathyStatusPresetDialog that allows the user to + * add/remove/edit their saved status messages. + * + * Returns: the newly constructed dialog. + */ GtkWidget * empathy_status_preset_dialog_new (GtkWindow *parent) { -- cgit v1.2.3 From 7a94f85d284baebdd3bbc0607205d3ced82748a2 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Thu, 23 Apr 2009 19:30:48 +0800 Subject: Sort presets alphabetically in the list --- libempathy-gtk/empathy-presence-chooser.c | 3 ++- libempathy-gtk/empathy-status-preset-dialog.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-presence-chooser.c b/libempathy-gtk/empathy-presence-chooser.c index d565cf387..d97abea0c 100644 --- a/libempathy-gtk/empathy-presence-chooser.c +++ b/libempathy-gtk/empathy-presence-chooser.c @@ -170,7 +170,8 @@ presence_chooser_create_model (EmpathyPresenceChooser *self) if (states[i+1]) { /* Set custom messages if wanted */ - list = empathy_status_presets_get (states[i], 5); + list = empathy_status_presets_get (states[i], -1); + list = g_list_sort (list, (GCompareFunc) g_utf8_collate); for (l = list; l; l = l->next) { gtk_list_store_insert_with_values (store, NULL, -1, diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index 562b9e4d9..d8416a585 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -108,8 +108,9 @@ status_preset_dialog_presets_update (EmpathyStatusPresetDialog *self) GList *presets, *l; const char *icon_name; - presets = empathy_status_presets_get (states[i], -1); icon_name = empathy_icon_name_for_presence (states[i]); + presets = empathy_status_presets_get (states[i], -1); + presets = g_list_sort (presets, (GCompareFunc) g_utf8_collate); for (l = presets; l; l = l->next) { char *preset = (char *) l->data; -- cgit v1.2.3 From e1a592f9b27d98b4bf6c8f05fb2c524a177f185e Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Thu, 23 Apr 2009 19:33:42 +0800 Subject: Add a comment for cassidy ;-) --- libempathy-gtk/empathy-status-preset-dialog.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index d8416a585..0fe577d97 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -54,6 +54,7 @@ static McPresence states[] = { typedef struct _EmpathyStatusPresetDialogPriv EmpathyStatusPresetDialogPriv; struct _EmpathyStatusPresetDialogPriv { + /* block status_preset_dialog_add_combo_changed() when > 0 */ int block_add_combo_changed; GtkWidget *presets_treeview; -- cgit v1.2.3 From 5b4b6de8f4bc1484184ee469e1c976e1e7d96034 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Thu, 23 Apr 2009 19:47:52 +0800 Subject: Preserve the status message across combo box changes --- libempathy-gtk/empathy-status-preset-dialog.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index 0fe577d97..f7171e4ef 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -63,6 +63,7 @@ struct _EmpathyStatusPresetDialogPriv GtkTreeIter selected_iter; gboolean add_combo_changed; + char *saved_status; }; enum @@ -82,12 +83,23 @@ enum ADD_COMBO_N_COLS }; +static void +empathy_status_preset_dialog_finalize (GObject *self) +{ + EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self); + + g_free (priv->saved_status); + + G_OBJECT_CLASS (empathy_status_preset_dialog_parent_class)->finalize (self); +} + static void empathy_status_preset_dialog_class_init (EmpathyStatusPresetDialogClass *class) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (class); + gobject_class->finalize = empathy_status_preset_dialog_finalize; g_type_class_add_private (gobject_class, sizeof (EmpathyStatusPresetDialogPriv)); @@ -371,12 +383,17 @@ status_preset_dialog_add_combo_changed (GtkComboBox *combo, g_free (icon_name); status_preset_dialog_set_add_combo_changed (self, FALSE, TRUE); + if (priv->saved_status && strlen (priv->saved_status) > 0) { + gtk_entry_set_text (GTK_ENTRY (entry), + priv->saved_status); + } } else { - const char *status; + g_free (priv->saved_status); + priv->saved_status = g_strdup ( + gtk_entry_get_text (GTK_ENTRY (entry))); - status = gtk_entry_get_text (GTK_ENTRY (entry)); status_preset_dialog_set_add_combo_changed (self, - strlen (status) > 0, FALSE); + strlen (priv->saved_status) > 0, FALSE); } } -- cgit v1.2.3 From 2315303fa0d4cf3532a9a1e63e7bb118b386c48c Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Thu, 23 Apr 2009 20:00:48 +0800 Subject: Rest of gtk-doc --- libempathy-gtk/empathy-status-preset-dialog.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index f7171e4ef..734ac356a 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -24,6 +24,15 @@ * * Authors: Davyd Madeley */ +/** + * SECTION:empathy-status-preset-dialog + * @title: EmpathyStatusPresetDialog + * @short_description: a dialog for editing the saved status messages + * @include: libempathy-gtk/empathy-status-preset-dialog.h + * + * #EmpathyStatusPresetDialog is a dialog allowing the user to add/remove/edit + * their saved status messages. + */ #include "config.h" -- cgit v1.2.3