diff options
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/Makefile.am | 1 | ||||
-rw-r--r-- | libempathy-gtk/empathy-status-preset-dialog.c | 128 | ||||
-rw-r--r-- | libempathy-gtk/empathy-status-preset-dialog.ui | 84 |
3 files changed, 210 insertions, 3 deletions
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 <glib/gi18n-lib.h> #include <gtk/gtk.h> +#include <libmissioncontrol/mc-enum-types.h> + +#include <libempathy/empathy-utils.h> #include <libempathy/empathy-status-presets.h> #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include <libempathy/empathy-debug.h> +#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 @@ -59,14 +77,118 @@ empathy_status_preset_dialog_class_init (EmpathyStatusPresetDialogClass *class) } 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) { EmpathyStatusPresetDialogPriv *priv = self->priv = 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 @@ +<?xml version="1.0"?> +<interface> + <requires lib="gtk+" version="2.16"/> + <!-- interface-naming-policy project-wide --> + <object class="GtkVBox" id="toplevel-vbox"> + <property name="visible">True</property> + <property name="border_width">6</property> + <property name="orientation">vertical</property> + <property name="spacing">6</property> + <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">0</property> + </packing> + </child> + <child> + <object class="GtkHButtonBox" id="hbuttonbox1"> + <property name="visible">True</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="remove-button"> + <property name="label" translatable="yes">gtk-remove</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> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox1"> + <property name="visible">True</property> + <property name="spacing">3</property> + <child> + <object class="GtkComboBoxEntry" id="add-combobox"> + <property name="visible">True</property> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="add-button"> + <property name="label" translatable="yes">gtk-add</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">2</property> + </packing> + </child> + </object> +</interface> |