aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2011-06-24 21:28:23 +0800
committerWill Thompson <will.thompson@collabora.co.uk>2011-06-24 21:28:31 +0800
commit3e22c794dd4568a69c08ce80cc12e03eb27f836c (patch)
tree8a703ec635a48d2682eb292ca694a98d120dab4a
parentea70cf03674e4c844e27062b4b13c306aae39d40 (diff)
parent896aa85c871372227e96906420659e38d091f2ac (diff)
downloadgsoc2013-empathy-3e22c794dd4568a69c08ce80cc12e03eb27f836c.tar
gsoc2013-empathy-3e22c794dd4568a69c08ce80cc12e03eb27f836c.tar.gz
gsoc2013-empathy-3e22c794dd4568a69c08ce80cc12e03eb27f836c.tar.bz2
gsoc2013-empathy-3e22c794dd4568a69c08ce80cc12e03eb27f836c.tar.lz
gsoc2013-empathy-3e22c794dd4568a69c08ce80cc12e03eb27f836c.tar.xz
gsoc2013-empathy-3e22c794dd4568a69c08ce80cc12e03eb27f836c.tar.zst
gsoc2013-empathy-3e22c794dd4568a69c08ce80cc12e03eb27f836c.zip
Merge branch 'status-dialog'
Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
-rw-r--r--libempathy-gtk/empathy-presence-chooser.c3
-rw-r--r--libempathy-gtk/empathy-status-preset-dialog.c295
-rw-r--r--libempathy-gtk/empathy-status-preset-dialog.ui136
-rw-r--r--tests/interactive/test-empathy-status-preset-dialog.c9
4 files changed, 75 insertions, 368 deletions
diff --git a/libempathy-gtk/empathy-presence-chooser.c b/libempathy-gtk/empathy-presence-chooser.c
index 45dd9da9e..66d516c40 100644
--- a/libempathy-gtk/empathy-presence-chooser.c
+++ b/libempathy-gtk/empathy-presence-chooser.c
@@ -66,9 +66,6 @@
* Widget which extends #GtkComboBoxEntry to change presence.
*/
-/* Flashing delay for icons (milliseconds). */
-#define FLASH_TIMEOUT 500
-
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyPresenceChooser)
/* For custom message dialog */
diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c
index 2c36cb332..e68f080fb 100644
--- a/libempathy-gtk/empathy-status-preset-dialog.c
+++ b/libempathy-gtk/empathy-status-preset-dialog.c
@@ -65,8 +65,8 @@ struct _EmpathyStatusPresetDialogPriv
int block_add_combo_changed;
GtkWidget *presets_treeview;
- GtkWidget *add_combobox;
- GtkWidget *add_button;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *text_cell;
GtkTreeIter selected_iter;
gboolean add_combo_changed;
@@ -148,69 +148,6 @@ status_preset_dialog_presets_update (EmpathyStatusPresetDialog *self)
}
static void
-status_preset_add_combo_reset (EmpathyStatusPresetDialog *self)
-{
- EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self);
- GtkWidget *entry;
-
- entry = gtk_bin_get_child (GTK_BIN (priv->add_combobox));
- gtk_entry_set_text (GTK_ENTRY (entry), "");
-
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->add_combobox),
- &priv->selected_iter);
-}
-
-static void
-status_preset_dialog_setup_add_combobox (EmpathyStatusPresetDialog *self)
-{
- EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self);
- GtkWidget *combobox = priv->add_combobox;
- GtkListStore *store;
- GtkCellRenderer *renderer;
- guint i;
-
- store = gtk_list_store_new (ADD_COMBO_N_COLS,
- G_TYPE_UINT, /* 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_set_entry_text_column (GTK_COMBO_BOX (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, "",
- -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);
-
- 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,
@@ -278,6 +215,7 @@ status_preset_dialog_setup_presets_treeview (EmpathyStatusPresetDialog *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 ();
@@ -286,6 +224,7 @@ status_preset_dialog_setup_presets_treeview (EmpathyStatusPresetDialog *self)
"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);
@@ -304,27 +243,19 @@ status_preset_dialog_preset_selection_changed (GtkTreeSelection *selection,
{
/* 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;
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);
@@ -333,179 +264,19 @@ status_preset_dialog_preset_remove (GtkButton *button,
empathy_status_presets_remove (state, status);
g_free (status);
-
- status_preset_dialog_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_override_color (entry, 0, NULL);
- } else {
- GdkRGBA color;
-
- if (gdk_rgba_parse (&color, "Gray")) /* FIXME - theme */
- gtk_widget_override_color (entry, 0, &color);
-
- 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)
-{
- EmpathyStatusPresetDialogPriv *priv = GET_PRIV (self);
- GtkWidget *entry;
- 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;
-
- priv->selected_iter = iter;
- gtk_tree_model_get (model, &iter,
- 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);
-
- 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 {
- g_free (priv->saved_status);
- priv->saved_status = g_strdup (
- gtk_entry_get_text (GTK_ENTRY (entry)));
-
- status_preset_dialog_set_add_combo_changed (self,
- strlen (priv->saved_status) > 0, FALSE);
- }
-}
-
-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);
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkWidget *entry;
- TpConnectionPresenceType state, cstate;
- const char *status;
- char *cstatus;
- gboolean valid, match = FALSE;
-
- 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", state, status);
- empathy_status_presets_set_last (state, status);
+ GtkTreeSelection *selection;
+ 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);
-
- /* select the added status*/
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->presets_treeview));
- for (valid = gtk_tree_model_get_iter_first (model, &iter);
- valid;
- valid = gtk_tree_model_iter_next (model, &iter)) {
-
- gtk_tree_model_get (model, &iter,
- PRESETS_STORE_STATE, &cstate,
- PRESETS_STORE_STATUS, &cstatus,
- -1);
-
- match = (cstate == state) && (strcmp (cstatus, status) == 0);
-
- g_free (cstatus);
-
- if (match) {
- GtkTreePath *path;
-
- path = gtk_tree_model_get_path (model, &iter);
-
- gtk_tree_selection_select_iter (
- gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->presets_treeview)),
- &iter);
- gtk_tree_view_scroll_to_cell (
- GTK_TREE_VIEW (priv->presets_treeview),
- path, NULL,
- FALSE, 0., 0.);
- break;
- }
- }
-
- if (!match) g_warning ("No match");
-
- 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
@@ -516,49 +287,47 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self)
EMPATHY_TYPE_STATUS_PRESET_DIALOG,
EmpathyStatusPresetDialogPriv);
GtkBuilder *gui;
- GtkWidget *toplevel_vbox, *remove_button, *entry;
+ 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_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,
"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);
-
- 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);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
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_get_content_area (GTK_DIALOG (self))),
toplevel_vbox, TRUE, TRUE, 0);
diff --git a/libempathy-gtk/empathy-status-preset-dialog.ui b/libempathy-gtk/empathy-status-preset-dialog.ui
index 07d8f14b9..359a02f9e 100644
--- a/libempathy-gtk/empathy-status-preset-dialog.ui
+++ b/libempathy-gtk/empathy-status-preset-dialog.ui
@@ -2,118 +2,60 @@
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
- <object class="GtkVBox" id="toplevel-vbox">
- <property name="width_request">420</property>
- <property name="height_request">260</property>
- <property name="visible">True</property>
- <property name="border_width">6</property>
- <property name="orientation">vertical</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkLabel" id="label2">
+ <object class="GtkVBox" id="toplevel-vbox">
<property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Saved Status Messages</property>
- <property name="mnemonic_widget">add-combobox</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">never</property>
- <property name="shadow_type">etched-in</property>
- <child>
- <object class="GtkTreeView" id="presets-treeview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="headers_visible">False</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkHButtonBox" id="hbuttonbox1">
- <property name="visible">True</property>
- <property name="layout_style">end</property>
+ <property name="can_focus">False</property>
+ <property name="margin-left">5</property>
+ <property name="margin-right">5</property>
<child>
- <object class="GtkButton" id="remove-button">
- <property name="label">gtk-remove</property>
+ <object class="GtkScrolledWindow" id="presets-sw">
+ <property name="width_request">408</property>
+ <property name="height_request">252</property>
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
+ <property name="hscrollbar_policy">never</property>
+ <property name="shadow_type">etched-in</property>
+ <child>
+ <object class="GtkTreeView" id="presets-treeview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="headers_visible">False</property>
+ </object>
+ </child>
</object>
<packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Save _New Status Message</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">add-combobox</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">3</property>
- </packing>
- </child>
- <child>
- <object class="GtkHBox" id="hbox1">
- <property name="visible">True</property>
- <property name="spacing">3</property>
<child>
- <object class="GtkComboBox" id="add-combobox">
+ <object class="GtkToolbar" id="remove-toolbar">
<property name="visible">True</property>
- <property name="has-entry">True</property>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="add-button">
- <property name="label">gtk-add</property>
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_size">1</property>
+ <style>
+ <class name="inline-toolbar"/>
+ </style>
+ <child>
+ <object class="GtkToolButton" id="remove-button">
+ <property name="tooltip-text" translatable="yes">Remove</property>
+ <property name="visible">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-remove</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="position">4</property>
- </packing>
- </child>
- </object>
</interface>
diff --git a/tests/interactive/test-empathy-status-preset-dialog.c b/tests/interactive/test-empathy-status-preset-dialog.c
index 6602e4f28..e71852509 100644
--- a/tests/interactive/test-empathy-status-preset-dialog.c
+++ b/tests/interactive/test-empathy-status-preset-dialog.c
@@ -17,7 +17,9 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Authors: Davyd Madeley <davyd.madeley@collabora.co.uk>
+ * Authors:
+ * Danielle Madeley <danielle.madeley@collabora.co.uk>
+ * Will Thompson <will.thompson@collabora.co.uk>
*/
#include <config.h>
@@ -40,10 +42,7 @@ main (int argc, char **argv)
empathy_status_presets_get_all ();
dialog = empathy_status_preset_dialog_new (NULL);
-
- gtk_widget_show (dialog);
-
- gtk_main ();
+ gtk_dialog_run (GTK_DIALOG (dialog));
return 0;
}