*
* 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.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
*
- * Authors: Davyd Madeley <davyd.madeley@collabora.co.uk>
+ * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk>
+ */
+/**
+ * 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"
+#include "empathy-status-preset-dialog.h"
#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
+#include <tp-account-widgets/tpaw-builder.h>
-#include <libmissioncontrol/mc-enum-types.h>
-
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-status-presets.h>
+#include "empathy-status-presets.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
-
-#include "empathy-ui-utils.h"
-#include "empathy-status-preset-dialog.h"
+#include "empathy-debug.h"
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyStatusPresetDialog)
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
+static TpConnectionPresenceType states[] = {
+ TP_CONNECTION_PRESENCE_TYPE_AVAILABLE,
+ TP_CONNECTION_PRESENCE_TYPE_BUSY,
+ TP_CONNECTION_PRESENCE_TYPE_AWAY,
};
typedef struct _EmpathyStatusPresetDialogPriv EmpathyStatusPresetDialogPriv;
struct _EmpathyStatusPresetDialogPriv
{
+ /* block status_preset_dialog_add_combo_changed () when > 0 */
+ int block_add_combo_changed;
+
GtkWidget *presets_treeview;
- GtkWidget *add_combobox;
- GtkWidget *add_button;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *text_cell;
- McPresence selected_state;
+ GtkTreeIter selected_iter;
gboolean add_combo_changed;
+ char *saved_status;
};
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));
}
static void
-status_preset_dialog_setup_presets_update (EmpathyStatusPresetDialog *self)
+status_preset_dialog_presets_update (EmpathyStatusPresetDialog *self)
{
EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self);
GtkListStore *store;
- int i;
+ guint i;
store = GTK_LIST_STORE (gtk_tree_view_get_model (
GTK_TREE_VIEW (priv->presets_treeview)));
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;
}
static void
-status_preset_add_combo_reset (EmpathyStatusPresetDialog *self)
+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;
+ TpConnectionPresenceType state;
+ char *old_status;
+ gboolean valid;
- 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;
+ if (strlen (new_status) == 0) {
+ /* status is empty, ignore */
+ return;
+ }
- 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 */
+ 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);
- gtk_combo_box_set_model (GTK_COMBO_BOX (combobox),
- GTK_TREE_MODEL (store));
- g_object_unref (store);
+ if (!valid) return;
- gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (combobox),
- ADD_COMBO_DEFAULT_TEXT);
+ gtk_tree_model_get (model, &iter,
+ PRESETS_STORE_STATE, &state,
+ PRESETS_STORE_STATUS, &old_status,
+ -1);
- 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);
+ if (!strcmp (old_status, new_status)) {
+ /* statuses are the same */
+ g_free (old_status);
+ return;
}
- gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
+ DEBUG ("EDITED STATUS (%s) -> (%s)\n", old_status, new_status);
- 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);
+ empathy_status_presets_remove (state, old_status);
+ empathy_status_presets_set_last (state, new_status);
- 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);
+ g_free (old_status);
- status_preset_add_combo_reset (self);
+ status_preset_dialog_presets_update (self);
}
static void
GtkCellRenderer *renderer;
store = gtk_list_store_new (PRESETS_STORE_N_COLS,
- MC_TYPE_PRESENCE, /* PRESETS_STORE_STATE */
+ G_TYPE_UINT, /* PRESETS_STORE_STATE */
G_TYPE_STRING, /* PRESETS_STORE_ICON_NAME */
G_TYPE_STRING); /* PRESETS_STORE_STATUS */
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 ();
+ priv->column = column;
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
renderer = gtk_cell_renderer_pixbuf_new ();
"icon-name", PRESETS_STORE_ICON_NAME);
renderer = gtk_cell_renderer_text_new ();
+ priv->text_cell = renderer;
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_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+
+ g_signal_connect (renderer, "edited",
+ G_CALLBACK (status_preset_dialog_status_edited), self);
}
static void
{
/* update the sensitivity of the Remove button */
gtk_widget_set_sensitive (remove_button,
- gtk_tree_selection_get_selected (selection, NULL, NULL));
+ gtk_tree_selection_count_selected_rows (selection) != 0);
}
static void
-status_preset_dialog_preset_remove (GtkButton *button,
- EmpathyStatusPresetDialog *self)
+foreach_removed_status (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
{
- EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self);
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
- McPresence state;
+ TpConnectionPresenceType 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,
+ gtk_tree_model_get (model, iter,
PRESETS_STORE_STATE, &state,
PRESETS_STORE_STATUS, &status,
-1);
empathy_status_presets_remove (state, status);
g_free (status);
-
- 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)
+status_preset_dialog_preset_remove (GtkButton *button,
+ 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);
+ GtkTreeSelection *selection;
- status_preset_dialog_setup_presets_update (self);
- status_preset_add_combo_reset (self);
+ selection = gtk_tree_view_get_selection (
+ GTK_TREE_VIEW (priv->presets_treeview));
+ gtk_tree_selection_selected_foreach (selection, foreach_removed_status, NULL);
+ status_preset_dialog_presets_update (self);
}
static void
EMPATHY_TYPE_STATUS_PRESET_DIALOG,
EmpathyStatusPresetDialogPriv);
GtkBuilder *gui;
- GtkWidget *toplevel_vbox, *remove_button;
+ GtkWidget *toplevel_vbox, *presets_sw, *remove_toolbar, *remove_button;
+ GtkTreeSelection *selection;
char *filename;
+ GtkStyleContext *context;
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);
+ gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
filename = empathy_file_lookup ("empathy-status-preset-dialog.ui",
"libempathy-gtk");
- gui = empathy_builder_get_file (filename,
+ gui = tpaw_builder_get_file (filename,
"toplevel-vbox", &toplevel_vbox,
+ "presets-sw", &presets_sw,
"presets-treeview", &priv->presets_treeview,
+ "remove-toolbar", &remove_toolbar,
"remove-button", &remove_button,
- "add-combobox", &priv->add_combobox,
- "add-button", &priv->add_button,
NULL);
g_free (filename);
- g_signal_connect (gtk_tree_view_get_selection (
- GTK_TREE_VIEW (priv->presets_treeview)),
+ /* join the remove toolbar to the treeview */
+ context = gtk_widget_get_style_context (presets_sw);
+ gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
+ context = gtk_widget_get_style_context (remove_toolbar);
+ gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
+
+ selection = gtk_tree_view_get_selection (
+ GTK_TREE_VIEW (priv->presets_treeview));
+ g_signal_connect (selection,
"changed",
G_CALLBACK (status_preset_dialog_preset_selection_changed),
remove_button);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
- 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,
+ tpaw_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);
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))),
+ toplevel_vbox, TRUE, TRUE, 0);
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)
{