From 33cb6f4b3292f259fc8c6c82d3a068c1b3065799 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 11 Jan 2017 03:00:03 -0800 Subject: [PATCH] time-plugin: Port to WindowActivatable --- plugins/Makefile.am | 6 +- plugins/time/xed-time-plugin.c | 1397 +++++++++++++++----------------- plugins/time/xed-time-plugin.h | 33 +- 3 files changed, 685 insertions(+), 751 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index abc91a9..d46447c 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -3,14 +3,16 @@ DIST_SUBDIRS = \ filebrowser \ modelines \ sort \ - spell + spell \ + time SUBDIRS = \ docinfo \ filebrowser \ modelines \ sort \ - spell + spell \ + time if ENABLE_ENCHANT SUBDIRS += spell diff --git a/plugins/time/xed-time-plugin.c b/plugins/time/xed-time-plugin.c index f308c31..604e6b9 100644 --- a/plugins/time/xed-time-plugin.c +++ b/plugins/time/xed-time-plugin.c @@ -16,8 +16,6 @@ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ */ /* @@ -38,434 +36,383 @@ #include #include -#include #include -#include -#include #include +#include +#include #include #include #define XED_TIME_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_TIME_PLUGIN, \ - XedTimePluginPrivate)) + XED_TYPE_TIME_PLUGIN, \ + XedTimePluginPrivate)) #define MENU_PATH "/MenuBar/EditMenu/EditOps_4" /* GSettings keys */ -#define TIME_SCHEMA "org.x.editor.plugins.time" -#define PROMPT_TYPE_KEY "prompt-type" -#define SELECTED_FORMAT_KEY "selected-format" -#define CUSTOM_FORMAT_KEY "custom-format" +#define TIME_SCHEMA "org.x.editor.plugins.time" +#define PROMPT_TYPE_KEY "prompt-type" +#define SELECTED_FORMAT_KEY "selected-format" +#define CUSTOM_FORMAT_KEY "custom-format" #define DEFAULT_CUSTOM_FORMAT "%d/%m/%Y %H:%M:%S" static const gchar *formats[] = { - "%c", - "%x", - "%X", - "%x %X", - "%Y-%m-%d %H:%M:%S", - "%a %b %d %H:%M:%S %Z %Y", - "%a %b %d %H:%M:%S %Y", - "%a %d %b %Y %H:%M:%S %Z", - "%a %d %b %Y %H:%M:%S", - "%d/%m/%Y", - "%d/%m/%y", - "%D", - "%A %d %B %Y", - "%A %B %d %Y", - "%Y-%m-%d", - "%d %B %Y", - "%B %d, %Y", - "%A %b %d", - "%H:%M:%S", - "%H:%M", - "%I:%M:%S %p", - "%I:%M %p", - "%H.%M.%S", - "%H.%M", - "%I.%M.%S %p", - "%I.%M %p", - "%d/%m/%Y %H:%M:%S", - "%d/%m/%y %H:%M:%S", + "%c", + "%x", + "%X", + "%x %X", + "%Y-%m-%d %H:%M:%S", + "%a %b %d %H:%M:%S %Z %Y", + "%a %b %d %H:%M:%S %Y", + "%a %d %b %Y %H:%M:%S %Z", + "%a %d %b %Y %H:%M:%S", + "%d/%m/%Y", + "%d/%m/%y", + "%D", + "%A %d %B %Y", + "%A %B %d %Y", + "%Y-%m-%d", + "%d %B %Y", + "%B %d, %Y", + "%A %b %d", + "%H:%M:%S", + "%H:%M", + "%I:%M:%S %p", + "%I:%M %p", + "%H.%M.%S", + "%H.%M", + "%I.%M.%S %p", + "%I.%M %p", + "%d/%m/%Y %H:%M:%S", + "%d/%m/%y %H:%M:%S", #if __GLIBC__ >= 2 - "%a, %d %b %Y %H:%M:%S %z", + "%a, %d %b %Y %H:%M:%S %z", #endif - NULL + NULL }; enum { - COLUMN_FORMATS = 0, - COLUMN_INDEX, - NUM_COLUMNS + COLUMN_FORMATS = 0, + COLUMN_INDEX, + NUM_COLUMNS }; -typedef struct _TimeConfigureDialog TimeConfigureDialog; - -struct _TimeConfigureDialog +typedef enum { - GtkWidget *content; + PROMPT_SELECTED_FORMAT = 0, /* Popup dialog with list preselected */ + PROMPT_CUSTOM_FORMAT, /* Popup dialog with entry preselected */ + USE_SELECTED_FORMAT, /* Use selected format directly */ + USE_CUSTOM_FORMAT /* Use custom format directly */ +} XedTimePluginPromptType; - GtkWidget *list; +typedef struct _TimeConfigureWidget TimeConfigureWidget; - /* Radio buttons to indicate what should be done */ - GtkWidget *prompt; - GtkWidget *use_list; - GtkWidget *custom; +struct _TimeConfigureWidget +{ + GtkWidget *content; - GtkWidget *custom_entry; - GtkWidget *custom_format_example; + GtkWidget *list; - GSettings *settings; + /* Radio buttons to indicate what should be done */ + GtkWidget *prompt; + GtkWidget *use_list; + GtkWidget *custom; + + GtkWidget *custom_entry; + GtkWidget *custom_format_example; + + GSettings *settings; }; typedef struct _ChooseFormatDialog ChooseFormatDialog; struct _ChooseFormatDialog { - GtkWidget *dialog; + GtkWidget *dialog; - GtkWidget *list; + GtkWidget *list; - /* Radio buttons to indicate what should be done */ - GtkWidget *use_list; - GtkWidget *custom; + /* Radio buttons to indicate what should be done */ + GtkWidget *use_list; + GtkWidget *custom; - GtkWidget *custom_entry; - GtkWidget *custom_format_example; + GtkWidget *custom_entry; + GtkWidget *custom_format_example; - /* Info needed for the response handler */ - GtkTextBuffer *buffer; + /* Info needed for the response handler */ + GtkTextBuffer *buffer; GSettings *settings; }; -typedef enum -{ - PROMPT_SELECTED_FORMAT = 0, /* Popup dialog with list preselected */ - PROMPT_CUSTOM_FORMAT, /* Popup dialog with entry preselected */ - USE_SELECTED_FORMAT, /* Use selected format directly */ - USE_CUSTOM_FORMAT /* Use custom format directly */ -} XedTimePluginPromptType; - struct _XedTimePluginPrivate { - GtkWidget *window; + XedWindow *window; GSettings *settings; - GtkActionGroup *action_group; - guint ui_id; + GtkActionGroup *action_group; + guint ui_id; }; enum { PROP_0, - PROP_OBJECT + PROP_WINDOW }; -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTimePlugin, xed_time_plugin, PEAS_TYPE_EXTENSION_BASE, 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, + xed_window_activatable_iface_init) G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, peas_gtk_configurable_iface_init)) -static void time_cb (GtkAction *action, XedTimePlugin *plugin); +static void time_cb (GtkAction *action, + XedTimePlugin *plugin); static const GtkActionEntry action_entries[] = { - { - "InsertDateAndTime", - NULL, - N_("In_sert Date and Time..."), - NULL, - N_("Insert current date and time at the cursor position"), - G_CALLBACK (time_cb) - }, + { + "InsertDateAndTime", + NULL, + N_("In_sert Date and Time..."), + NULL, + N_("Insert current date and time at the cursor position"), + G_CALLBACK (time_cb) + }, }; static void xed_time_plugin_init (XedTimePlugin *plugin) { - xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin initializing"); + xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin initializing"); - plugin->priv = XED_TIME_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = XED_TIME_PLUGIN_GET_PRIVATE (plugin); - plugin->priv->settings = g_settings_new (TIME_SCHEMA); + plugin->priv->settings = g_settings_new (TIME_SCHEMA); } static void xed_time_plugin_finalize (GObject *object) { - XedTimePlugin *plugin = XED_TIME_PLUGIN (object); + XedTimePlugin *plugin = XED_TIME_PLUGIN (object); - xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin finalizing"); + xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin finalizing"); - g_object_unref (G_OBJECT (plugin->priv->settings)); + g_object_unref (G_OBJECT (plugin->priv->settings)); - G_OBJECT_CLASS (xed_time_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_time_plugin_parent_class)->finalize (object); } static void xed_time_plugin_dispose (GObject *object) { - XedTimePlugin *plugin = XED_TIME_PLUGIN (object); + XedTimePlugin *plugin = XED_TIME_PLUGIN (object); xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin disposing"); - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } + g_clear_object (&plugin->priv->window); + g_clear_object (&plugin->priv->action_group); - if (plugin->priv->action_group) - { - g_object_unref (plugin->priv->action_group); - plugin->priv->action_group = NULL; - } - - G_OBJECT_CLASS (xed_time_plugin_parent_class)->dispose (object); + G_OBJECT_CLASS (xed_time_plugin_parent_class)->dispose (object); } static void -update_ui (XedTimePluginPrivate *data) +update_ui (XedTimePlugin *plugin) { - XedWindow *window; - XedView *view; - GtkAction *action; + XedView *view; + GtkAction *action; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - window = XED_WINDOW (data->window); - view = xed_window_get_active_view (window); + view = xed_window_get_active_view (plugin->priv->window); - xed_debug_message (DEBUG_PLUGINS, "View: %p", view); + xed_debug_message (DEBUG_PLUGINS, "View: %p", view); - action = gtk_action_group_get_action (data->action_group, - "InsertDateAndTime"); - gtk_action_set_sensitive (action, - (view != NULL) && - gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); + action = gtk_action_group_get_action (plugin->priv->action_group, "InsertDateAndTime"); + gtk_action_set_sensitive (action, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); } static void -xed_time_plugin_activate (PeasActivatable *activatable) +xed_time_plugin_activate (XedWindowActivatable *activatable) { - XedTimePlugin *plugin; - XedTimePluginPrivate *data; - XedWindow *window; - GtkUIManager *manager; + XedTimePluginPrivate *priv; + GtkUIManager *manager; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - plugin = XED_TIME_PLUGIN (activatable); - data = plugin->priv; - window = XED_WINDOW (data->window); + priv = XED_TIME_PLUGIN (activatable)->priv; + manager = xed_window_get_ui_manager (priv->window); - manager = xed_window_get_ui_manager (window); + priv->action_group = gtk_action_group_new ("XedTimePluginActions"); + gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (priv->action_group, action_entries, G_N_ELEMENTS (action_entries), activatable); - data->action_group = gtk_action_group_new ("XedTimePluginActions"); - gtk_action_group_set_translation_domain (data->action_group, - GETTEXT_PACKAGE); - gtk_action_group_add_actions (data->action_group, - action_entries, - G_N_ELEMENTS (action_entries), - plugin); + gtk_ui_manager_insert_action_group (manager, priv->action_group, -1); - gtk_ui_manager_insert_action_group (manager, data->action_group, -1); + priv->ui_id = gtk_ui_manager_new_merge_id (manager); - data->ui_id = gtk_ui_manager_new_merge_id (manager); + gtk_ui_manager_add_ui (manager, + priv->ui_id, + MENU_PATH, + "InsertDateAndTime", + "InsertDateAndTime", + GTK_UI_MANAGER_MENUITEM, + FALSE); - gtk_ui_manager_add_ui (manager, - data->ui_id, - MENU_PATH, - "InsertDateAndTime", - "InsertDateAndTime", - GTK_UI_MANAGER_MENUITEM, - FALSE); - - update_ui (data); + update_ui (XED_TIME_PLUGIN (activatable)); } static void -xed_time_plugin_deactivate (PeasActivatable *activatable) +xed_time_plugin_deactivate (XedWindowActivatable *activatable) { - XedTimePluginPrivate *data; - XedWindow *window; - GtkUIManager *manager; + XedTimePluginPrivate *priv; + GtkUIManager *manager; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - data = XED_TIME_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); + priv = XED_TIME_PLUGIN (activatable)->priv; + manager = xed_window_get_ui_manager (priv->window); - manager = xed_window_get_ui_manager (window); - - gtk_ui_manager_remove_ui (manager, data->ui_id); - gtk_ui_manager_remove_action_group (manager, data->action_group); + gtk_ui_manager_remove_ui (manager, priv->ui_id); + gtk_ui_manager_remove_action_group (manager, priv->action_group); } static void -xed_time_plugin_update_state (PeasActivatable *activatable) +xed_time_plugin_update_state (XedWindowActivatable *activatable) { - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - update_ui (XED_TIME_PLUGIN (activatable)->priv); -} - -/* whether we should prompt the user or use the specified format */ -static XedTimePluginPromptType -get_prompt_type (XedTimePlugin *plugin) -{ - XedTimePluginPromptType prompt_type; - - prompt_type = g_settings_get_enum (plugin->priv->settings, - PROMPT_TYPE_KEY); - - return prompt_type; -} - -static void -set_prompt_type (GSettings *settings, - XedTimePluginPromptType prompt_type) -{ - if (!g_settings_is_writable (settings, - PROMPT_TYPE_KEY)) - { - return; - } - - g_settings_set_enum (settings, - PROMPT_TYPE_KEY, - prompt_type); + update_ui (XED_TIME_PLUGIN (activatable)); } /* The selected format in the list */ static gchar * get_selected_format (XedTimePlugin *plugin) { - gchar *sel_format; + gchar *sel_format; - sel_format = g_settings_get_string (plugin->priv->settings, - SELECTED_FORMAT_KEY); + sel_format = g_settings_get_string (plugin->priv->settings, SELECTED_FORMAT_KEY); - return sel_format ? sel_format : g_strdup (formats [0]); + return sel_format ? sel_format : g_strdup (formats [0]); } -static void -set_selected_format (GSettings *settings, - const gchar *format) -{ - g_return_if_fail (format != NULL); +// static void +// set_selected_format (XedTimePlugin *plugin, +// const gchar *format) +// { +// g_return_if_fail (format != NULL); - if (!g_settings_is_writable (settings, - SELECTED_FORMAT_KEY)) - { - return; - } +// if (!g_settings_is_writable (plugin->priv->settings, SELECTED_FORMAT_KEY)) +// { +// return; +// } - g_settings_set_string (settings, - SELECTED_FORMAT_KEY, - format); -} +// g_settings_set_string (settings, SELECTED_FORMAT_KEY, format); +// } /* the custom format in the entry */ static gchar * get_custom_format (XedTimePlugin *plugin) { - gchar *format; + gchar *format; - format = g_settings_get_string (plugin->priv->settings, - CUSTOM_FORMAT_KEY); + format = g_settings_get_string (plugin->priv->settings, CUSTOM_FORMAT_KEY); - return format ? format : g_strdup (DEFAULT_CUSTOM_FORMAT); + return format ? format : g_strdup (DEFAULT_CUSTOM_FORMAT); } -static void -set_custom_format (GSettings *settings, - const gchar *format) -{ - g_return_if_fail (format != NULL); +// static void +// set_custom_format (XedTimePlugin *plugin, +// const gchar *format) +// { +// g_return_if_fail (format != NULL); - if (!g_settings_is_writable (settings, - CUSTOM_FORMAT_KEY)) - return; +// if (!g_settings_is_writable (plugin->priv->settings, CUSTOM_FORMAT_KEY)) +// { +// return; +// } - g_settings_set_string (settings, - CUSTOM_FORMAT_KEY, - format); -} +// g_settings_set_string (plugin->priv->settings, CUSTOM_FORMAT_KEY, format); +// } static gchar * get_time (const gchar* format) { - gchar *out = NULL; - gchar *out_utf8 = NULL; - time_t clock; - struct tm *now; - size_t out_length = 0; - gchar *locale_format; + gchar *out = NULL; + gchar *out_utf8 = NULL; + time_t clock; + struct tm *now; + size_t out_length = 0; + gchar *locale_format; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - g_return_val_if_fail (format != NULL, NULL); + g_return_val_if_fail (format != NULL, NULL); - if (strlen (format) == 0) - return g_strdup (" "); + if (strlen (format) == 0) + { + return g_strdup (" "); + } - locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL); - if (locale_format == NULL) - return g_strdup (" "); + locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL); + if (locale_format == NULL) + { + return g_strdup (" "); + } - clock = time (NULL); - now = localtime (&clock); + clock = time (NULL); + now = localtime (&clock); - do - { - out_length += 255; - out = g_realloc (out, out_length); - } - while (strftime (out, out_length, locale_format, now) == 0); + do + { + out_length += 255; + out = g_realloc (out, out_length); + } + while (strftime (out, out_length, locale_format, now) == 0); - g_free (locale_format); + g_free (locale_format); - if (g_utf8_validate (out, -1, NULL)) - { - out_utf8 = out; - } - else - { - out_utf8 = g_locale_to_utf8 (out, -1, NULL, NULL, NULL); - g_free (out); + if (g_utf8_validate (out, -1, NULL)) + { + out_utf8 = out; + } + else + { + out_utf8 = g_locale_to_utf8 (out, -1, NULL, NULL, NULL); + g_free (out); - if (out_utf8 == NULL) - out_utf8 = g_strdup (" "); - } + if (out_utf8 == NULL) + { + out_utf8 = g_strdup (" "); + } + } - return out_utf8; + return out_utf8; } static void -configure_dialog_destroyed (GtkWidget *widget, +configure_widget_destroyed (GtkWidget *widget, gpointer data) { - TimeConfigureDialog *dialog = (TimeConfigureDialog *) data; + TimeConfigureWidget *conf_widget = (TimeConfigureWidget *) data; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - g_object_unref (dialog->settings); - g_slice_free (TimeConfigureDialog, data); + g_object_unref (conf_widget->settings); + g_slice_free (TimeConfigureWidget, data); + + xed_debug_message (DEBUG_PLUGINS, "END"); } static void @@ -474,648 +421,648 @@ choose_format_dialog_destroyed (GtkWidget *widget, { xed_debug (DEBUG_PLUGINS); - g_slice_free (ChooseFormatDialog, data); + g_slice_free (ChooseFormatDialog, data); + + xed_debug_message (DEBUG_PLUGINS, "END"); } static GtkTreeModel * -create_model (GtkWidget *listview, - const gchar *sel_format, - XedTimePlugin *plugin) +create_model (GtkWidget *listview, + const gchar *sel_format, + XedTimePlugin *plugin) { - gint i = 0; - GtkListStore *store; - GtkTreeSelection *selection; - GtkTreeIter iter; + gint i = 0; + GtkListStore *store; + GtkTreeSelection *selection; + GtkTreeIter iter; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - /* create list store */ - store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT); + /* create list store */ + store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT); - /* Set tree view model*/ - gtk_tree_view_set_model (GTK_TREE_VIEW (listview), - GTK_TREE_MODEL (store)); - g_object_unref (G_OBJECT (store)); + /* Set tree view model*/ + gtk_tree_view_set_model (GTK_TREE_VIEW (listview), GTK_TREE_MODEL (store)); + g_object_unref (G_OBJECT (store)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (listview)); - g_return_val_if_fail (selection != NULL, GTK_TREE_MODEL (store)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (listview)); + g_return_val_if_fail (selection != NULL, GTK_TREE_MODEL (store)); - /* there should always be one line selected */ - gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); + /* there should always be one line selected */ + gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); - /* add data to the list store */ - while (formats[i] != NULL) - { - gchar *str; + /* add data to the list store */ + while (formats[i] != NULL) + { + gchar *str; - str = get_time (formats[i]); + str = get_time (formats[i]); - xed_debug_message (DEBUG_PLUGINS, "%d : %s", i, str); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COLUMN_FORMATS, str, - COLUMN_INDEX, i, - -1); - g_free (str); + xed_debug_message (DEBUG_PLUGINS, "%d : %s", i, str); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, COLUMN_FORMATS, str, COLUMN_INDEX, i, -1); + g_free (str); - if (sel_format && strcmp (formats[i], sel_format) == 0) - gtk_tree_selection_select_iter (selection, &iter); + if (sel_format && strcmp (formats[i], sel_format) == 0) + { + gtk_tree_selection_select_iter (selection, &iter); + } - ++i; - } + ++i; + } - /* fall back to select the first iter */ - if (!gtk_tree_selection_get_selected (selection, NULL, NULL)) - { - gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); - gtk_tree_selection_select_iter (selection, &iter); - } + /* fall back to select the first iter */ + if (!gtk_tree_selection_get_selected (selection, NULL, NULL)) + { + gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); + gtk_tree_selection_select_iter (selection, &iter); + } - return GTK_TREE_MODEL (store); + return GTK_TREE_MODEL (store); } static void scroll_to_selected (GtkTreeView *tree_view) { - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - model = gtk_tree_view_get_model (tree_view); - g_return_if_fail (model != NULL); + model = gtk_tree_view_get_model (tree_view); + g_return_if_fail (model != NULL); - /* Scroll to selected */ - selection = gtk_tree_view_get_selection (tree_view); - g_return_if_fail (selection != NULL); + /* Scroll to selected */ + selection = gtk_tree_view_get_selection (tree_view); + g_return_if_fail (selection != NULL); - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - { - GtkTreePath* path; + if (gtk_tree_selection_get_selected (selection, NULL, &iter)) + { + GtkTreePath* path; - path = gtk_tree_model_get_path (model, &iter); - g_return_if_fail (path != NULL); + path = gtk_tree_model_get_path (model, &iter); + g_return_if_fail (path != NULL); - gtk_tree_view_scroll_to_cell (tree_view, - path, NULL, TRUE, 1.0, 0.0); - gtk_tree_path_free (path); - } + gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 1.0, 0.0); + gtk_tree_path_free (path); + } } static void -create_formats_list (GtkWidget *listview, - const gchar *sel_format, - XedTimePlugin *plugin) +create_formats_list (GtkWidget *listview, + const gchar *sel_format, + XedTimePlugin *plugin) { - GtkTreeViewColumn *column; - GtkCellRenderer *cell; + GtkTreeViewColumn *column; + GtkCellRenderer *cell; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - g_return_if_fail (listview != NULL); - g_return_if_fail (sel_format != NULL); + g_return_if_fail (listview != NULL); + g_return_if_fail (sel_format != NULL); - /* the Available formats column */ - cell = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ( - _("Available formats"), - cell, - "text", COLUMN_FORMATS, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (listview), column); + /* the Available formats column */ + cell = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes (_("Available formats"), + cell, + "text", COLUMN_FORMATS, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (listview), column); - /* Create model, it also add model to the tree view */ - create_model (listview, sel_format, plugin); + /* Create model, it also add model to the tree view */ + create_model (listview, sel_format, plugin); - g_signal_connect (listview, - "realize", - G_CALLBACK (scroll_to_selected), - NULL); + g_signal_connect (listview, "realize", + G_CALLBACK (scroll_to_selected), NULL); - gtk_widget_show (listview); + gtk_widget_show (listview); } static void updated_custom_format_example (GtkEntry *format_entry, - GtkLabel *format_example) + GtkLabel *format_example) { - const gchar *format; - gchar *time; - gchar *str; - gchar *escaped_time; + const gchar *format; + gchar *time; + gchar *str; + gchar *escaped_time; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - g_return_if_fail (GTK_IS_ENTRY (format_entry)); - g_return_if_fail (GTK_IS_LABEL (format_example)); + g_return_if_fail (GTK_IS_ENTRY (format_entry)); + g_return_if_fail (GTK_IS_LABEL (format_example)); - format = gtk_entry_get_text (format_entry); + format = gtk_entry_get_text (format_entry); - time = get_time (format); - escaped_time = g_markup_escape_text (time, -1); + time = get_time (format); + escaped_time = g_markup_escape_text (time, -1); - str = g_strdup_printf ("%s", escaped_time); + str = g_strdup_printf ("%s", escaped_time); - gtk_label_set_markup (format_example, str); + gtk_label_set_markup (format_example, str); - g_free (escaped_time); - g_free (time); - g_free (str); + g_free (escaped_time); + g_free (time); + g_free (str); } static void -choose_format_dialog_button_toggled (GtkToggleButton *button, - ChooseFormatDialog *dialog) +choose_format_dialog_button_toggled (GtkToggleButton *button, + ChooseFormatDialog *dialog) { - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom))) - { - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, TRUE); - gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom))) + { + gtk_widget_set_sensitive (dialog->list, FALSE); + gtk_widget_set_sensitive (dialog->custom_entry, TRUE); + gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + } - return; - } - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) - { - gtk_widget_set_sensitive (dialog->list, TRUE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - - return; - } + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) + { + gtk_widget_set_sensitive (dialog->list, TRUE); + gtk_widget_set_sensitive (dialog->custom_entry, FALSE); + gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + } + else + { + g_return_if_reached (); + } } static void -configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *dialog) +configure_widget_button_toggled (GtkToggleButton *button, + TimeConfigureWidget *conf_widget) { - xed_debug (DEBUG_PLUGINS); + XedTimePluginPromptType prompt_type; - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom))) - { - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, TRUE); - gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + xed_debug (DEBUG_PLUGINS); - set_prompt_type (dialog->settings, USE_CUSTOM_FORMAT); - return; - } + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->custom))) + { + gtk_widget_set_sensitive (conf_widget->list, FALSE); + gtk_widget_set_sensitive (conf_widget->custom_entry, TRUE); + gtk_widget_set_sensitive (conf_widget->custom_format_example, TRUE); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) - { - gtk_widget_set_sensitive (dialog->list, TRUE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + prompt_type = USE_CUSTOM_FORMAT; + } - set_prompt_type (dialog->settings, USE_SELECTED_FORMAT); - return; - } + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->use_list))) + { + gtk_widget_set_sensitive (conf_widget->list, TRUE); + gtk_widget_set_sensitive (conf_widget->custom_entry, FALSE); + gtk_widget_set_sensitive (conf_widget->custom_format_example, FALSE); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->prompt))) - { - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + prompt_type = USE_SELECTED_FORMAT; + } - set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); - return; - } + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->prompt))) + { + gtk_widget_set_sensitive (conf_widget->list, FALSE); + gtk_widget_set_sensitive (conf_widget->custom_entry, FALSE); + gtk_widget_set_sensitive (conf_widget->custom_format_example, FALSE); + + prompt_type = PROMPT_SELECTED_FORMAT; + } + else + { + g_return_if_reached (); + } + + g_settings_set_enum (conf_widget->settings, PROMPT_TYPE_KEY, prompt_type); } static gint get_format_from_list (GtkWidget *listview) { - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (listview)); - g_return_val_if_fail (model != NULL, 0); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (listview)); + g_return_val_if_fail (model != NULL, 0); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (listview)); - g_return_val_if_fail (selection != NULL, 0); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (listview)); + g_return_val_if_fail (selection != NULL, 0); - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - { - gint selected_value; + if (gtk_tree_selection_get_selected (selection, NULL, &iter)) + { + gint selected_value; - gtk_tree_model_get (model, &iter, COLUMN_INDEX, &selected_value, -1); + gtk_tree_model_get (model, &iter, COLUMN_INDEX, &selected_value, -1); - xed_debug_message (DEBUG_PLUGINS, "Sel value: %d", selected_value); + xed_debug_message (DEBUG_PLUGINS, "Sel value: %d", selected_value); - return selected_value; - } + return selected_value; + } - g_return_val_if_reached (0); + g_return_val_if_reached (0); } +// static void +// configure_dialog_selection_changed (GtkTreeSelection *selection, +// TimeConfigureDialog *dialog) +// { +// gint sel_format; + +// sel_format = get_format_from_list (dialog->list); +// set_selected_format (dialog->settings, formats[sel_format]); +// } + static void -configure_dialog_selection_changed (GtkTreeSelection *selection, - TimeConfigureDialog *dialog) +on_configure_widget_selection_changed (GtkTreeSelection *selection, + TimeConfigureWidget *conf_widget) { gint sel_format; - sel_format = get_format_from_list (dialog->list); - set_selected_format (dialog->settings, formats[sel_format]); + sel_format = get_format_from_list (conf_widget->list); + g_settings_set_string (conf_widget->settings, SELECTED_FORMAT_KEY, formats[sel_format]); } -static TimeConfigureDialog * -get_configure_dialog (XedTimePlugin *plugin) +static TimeConfigureWidget * +get_configure_widget (XedTimePlugin *plugin) { - TimeConfigureDialog *dialog = NULL; + TimeConfigureWidget *widget = NULL; GtkTreeSelection *selection; - gchar *data_dir; - gchar *ui_file; - GtkWidget *content; - GtkWidget *viewport; - XedTimePluginPromptType prompt_type; - gchar *sf, *cf; - GtkWidget *error_widget; - gboolean ret; - gchar *root_objects[] = { - "time_dialog_content", - NULL - }; + gchar *data_dir; + gchar *ui_file; + GtkWidget *viewport; + XedTimePluginPromptType prompt_type; + gchar *sf; + GtkWidget *error_widget; + gboolean ret; + gchar *root_objects[] = { + "time_dialog_content", + NULL + }; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - dialog = g_slice_new (TimeConfigureDialog); - dialog->settings = g_object_ref (plugin->priv->settings); + widget = g_slice_new (TimeConfigureWidget); + widget->settings = g_object_ref (plugin->priv->settings); - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); - ui_file = g_build_filename (data_dir, "xed-time-setup-dialog.ui", NULL); - ret = xed_utils_get_ui_objects (ui_file, - root_objects, - &error_widget, - "time_dialog_content", &dialog->content, - "formats_viewport", &viewport, - "formats_tree", &dialog->list, - "always_prompt", &dialog->prompt, - "never_prompt", &dialog->use_list, - "use_custom", &dialog->custom, - "custom_entry", &dialog->custom_entry, - "custom_format_example", &dialog->custom_format_example, - NULL); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + ui_file = g_build_filename (data_dir, "xed-time-setup-dialog.ui", NULL); + ret = xed_utils_get_ui_objects (ui_file, + root_objects, + &error_widget, + "time_dialog_content", &widget->content, + "formats_viewport", &viewport, + "formats_tree", &widget->list, + "always_prompt", &widget->prompt, + "never_prompt", &widget->use_list, + "use_custom", &widget->custom, + "custom_entry", &widget->custom_entry, + "custom_format_example", &widget->custom_format_example, + NULL); - g_free (data_dir); - g_free (ui_file); + g_free (data_dir); + g_free (ui_file); - if (!ret) - { - return NULL; - } + if (!ret) + { + return NULL; + } - sf = get_selected_format (plugin); - create_formats_list (dialog->list, sf, plugin); - g_free (sf); + sf = get_selected_format (plugin); + create_formats_list (widget->list, sf, plugin); + g_free (sf); - prompt_type = get_prompt_type (plugin); + prompt_type = g_settings_get_enum (plugin->priv->settings, PROMPT_TYPE_KEY); - g_settings_bind (dialog->settings, CUSTOM_FORMAT_KEY, - dialog->custom_entry, "text", + g_settings_bind (widget->settings, CUSTOM_FORMAT_KEY, + widget->custom_entry, "text", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); - if (prompt_type == USE_CUSTOM_FORMAT) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->custom), TRUE); + if (prompt_type == USE_CUSTOM_FORMAT) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->custom), TRUE); - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, TRUE); - gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); - } - else if (prompt_type == USE_SELECTED_FORMAT) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->use_list), TRUE); + gtk_widget_set_sensitive (widget->list, FALSE); + gtk_widget_set_sensitive (widget->custom_entry, TRUE); + gtk_widget_set_sensitive (widget->custom_format_example, TRUE); + } + else if (prompt_type == USE_SELECTED_FORMAT) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->use_list), TRUE); - gtk_widget_set_sensitive (dialog->list, TRUE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - } - else - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->prompt), TRUE); + gtk_widget_set_sensitive (widget->list, TRUE); + gtk_widget_set_sensitive (widget->custom_entry, FALSE); + gtk_widget_set_sensitive (widget->custom_format_example, FALSE); + } + else + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->prompt), TRUE); - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - } + gtk_widget_set_sensitive (widget->list, FALSE); + gtk_widget_set_sensitive (widget->custom_entry, FALSE); + gtk_widget_set_sensitive (widget->custom_format_example, FALSE); + } - updated_custom_format_example (GTK_ENTRY (dialog->custom_entry), - GTK_LABEL (dialog->custom_format_example)); + updated_custom_format_example (GTK_ENTRY (widget->custom_entry), GTK_LABEL (widget->custom_format_example)); - /* setup a window of a sane size. */ - gtk_widget_set_size_request (GTK_WIDGET (viewport), 10, 200); + /* setup a window of a sane size. */ + gtk_widget_set_size_request (GTK_WIDGET (viewport), 10, 200); - g_signal_connect (dialog->custom, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->prompt, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->use_list, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->content, "destroy", G_CALLBACK (configure_dialog_destroyed), dialog); - g_signal_connect (dialog->custom_entry, "changed", G_CALLBACK (updated_custom_format_example), dialog->custom_format_example); + g_signal_connect (widget->custom, "toggled", + G_CALLBACK (configure_widget_button_toggled), widget); + g_signal_connect (widget->prompt, "toggled", + G_CALLBACK (configure_widget_button_toggled), widget); + g_signal_connect (widget->use_list, "toggled", + G_CALLBACK (configure_widget_button_toggled), widget); + g_signal_connect (widget->content, "destroy", + G_CALLBACK (configure_widget_destroyed), widget); + g_signal_connect (widget->custom_entry, "changed", + G_CALLBACK (updated_custom_format_example), widget->custom_format_example); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list)); - g_signal_connect (selection, "changed", G_CALLBACK (configure_dialog_selection_changed), dialog); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget->list)); + g_signal_connect (selection, "changed", + G_CALLBACK (on_configure_widget_selection_changed), widget); - return dialog; + return widget; } static void real_insert_time (GtkTextBuffer *buffer, - const gchar *the_time) + const gchar *the_time) { - xed_debug_message (DEBUG_PLUGINS, "Insert: %s", the_time); + xed_debug_message (DEBUG_PLUGINS, "Insert: %s", the_time); - gtk_text_buffer_begin_user_action (buffer); + gtk_text_buffer_begin_user_action (buffer); - gtk_text_buffer_insert_at_cursor (buffer, the_time, -1); - gtk_text_buffer_insert_at_cursor (buffer, " ", -1); + gtk_text_buffer_insert_at_cursor (buffer, the_time, -1); + gtk_text_buffer_insert_at_cursor (buffer, " ", -1); - gtk_text_buffer_end_user_action (buffer); + gtk_text_buffer_end_user_action (buffer); } static void choose_format_dialog_row_activated (GtkTreeView *list, - GtkTreePath *path, - GtkTreeViewColumn *column, - ChooseFormatDialog *dialog) + GtkTreePath *path, + GtkTreeViewColumn *column, + ChooseFormatDialog *dialog) { - gint sel_format; - gchar *the_time; + gint sel_format; + gchar *the_time; - sel_format = get_format_from_list (dialog->list); - the_time = get_time (formats[sel_format]); + sel_format = get_format_from_list (dialog->list); + the_time = get_time (formats[sel_format]); - set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->settings, formats[sel_format]); + g_settings_set_enum (dialog->settings, PROMPT_TYPE_KEY, PROMPT_SELECTED_FORMAT); + g_settings_set_string (dialog->settings, SELECTED_FORMAT_KEY, formats[sel_format]); - g_return_if_fail (the_time != NULL); + g_return_if_fail (the_time != NULL); - real_insert_time (dialog->buffer, the_time); + real_insert_time (dialog->buffer, the_time); - g_free (the_time); + g_free (the_time); } static ChooseFormatDialog * -get_choose_format_dialog (GtkWindow *parent, - XedTimePluginPromptType prompt_type, - XedTimePlugin *plugin) +get_choose_format_dialog (GtkWindow *parent, + XedTimePluginPromptType prompt_type, + XedTimePlugin *plugin) { - ChooseFormatDialog *dialog; - gchar *data_dir; - gchar *ui_file; - GtkWidget *error_widget; - gboolean ret; - gchar *sf, *cf; - GtkWindowGroup *wg = NULL; + ChooseFormatDialog *dialog; + gchar *data_dir; + gchar *ui_file; + GtkWidget *error_widget; + gboolean ret; + gchar *sf, *cf; + GtkWindowGroup *wg = NULL; - if (parent != NULL) - wg = gtk_window_get_group (parent); + if (parent != NULL) + { + wg = gtk_window_get_group (parent); + } - dialog = g_slice_new (ChooseFormatDialog); + dialog = g_slice_new (ChooseFormatDialog); dialog->settings = plugin->priv->settings; - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); - ui_file = g_build_filename (data_dir, "xed-time-dialog.ui", NULL); - ret = xed_utils_get_ui_objects (ui_file, - NULL, - &error_widget, - "choose_format_dialog", &dialog->dialog, - "choice_list", &dialog->list, - "use_sel_format_radiobutton", &dialog->use_list, - "use_custom_radiobutton", &dialog->custom, - "custom_entry", &dialog->custom_entry, - "custom_format_example", &dialog->custom_format_example, - NULL); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + ui_file = g_build_filename (data_dir, "xed-time-dialog.ui", NULL); + ret = xed_utils_get_ui_objects (ui_file, + NULL, + &error_widget, + "choose_format_dialog", &dialog->dialog, + "choice_list", &dialog->list, + "use_sel_format_radiobutton", &dialog->use_list, + "use_custom_radiobutton", &dialog->custom, + "custom_entry", &dialog->custom_entry, + "custom_format_example", &dialog->custom_format_example, + NULL); - g_free (data_dir); - g_free (ui_file); + g_free (data_dir); + g_free (ui_file); - if (!ret) - { - GtkWidget *err_dialog; + if (!ret) + { + GtkWidget *err_dialog; - err_dialog = gtk_dialog_new_with_buttons (NULL, - parent, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, - NULL); + err_dialog = gtk_dialog_new_with_buttons (NULL, + parent, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); - if (wg != NULL) - gtk_window_group_add_window (wg, GTK_WINDOW (err_dialog)); + if (wg != NULL) + { + gtk_window_group_add_window (wg, GTK_WINDOW (err_dialog)); + } - gtk_window_set_resizable (GTK_WINDOW (err_dialog), FALSE); - gtk_dialog_set_default_response (GTK_DIALOG (err_dialog), GTK_RESPONSE_OK); + gtk_window_set_resizable (GTK_WINDOW (err_dialog), FALSE); + gtk_dialog_set_default_response (GTK_DIALOG (err_dialog), GTK_RESPONSE_OK); - gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (err_dialog))), - error_widget); + gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (err_dialog))), error_widget); - g_signal_connect (G_OBJECT (err_dialog), - "response", - G_CALLBACK (gtk_widget_destroy), - NULL); + g_signal_connect (G_OBJECT (err_dialog), "response", + G_CALLBACK (gtk_widget_destroy), NULL); - gtk_widget_show_all (err_dialog); + gtk_widget_show_all (err_dialog); - return NULL; - } + return NULL; + } - gtk_window_group_add_window (wg, - GTK_WINDOW (dialog->dialog)); - gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), parent); - gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); + gtk_window_group_add_window (wg, GTK_WINDOW (dialog->dialog)); + gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), parent); + gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); - sf = get_selected_format (plugin); - create_formats_list (dialog->list, sf, plugin); - g_free (sf); + sf = get_selected_format (plugin); + create_formats_list (dialog->list, sf, plugin); + g_free (sf); - cf = get_custom_format (plugin); - gtk_entry_set_text (GTK_ENTRY(dialog->custom_entry), cf); - g_free (cf); + cf = get_custom_format (plugin); + gtk_entry_set_text (GTK_ENTRY (dialog->custom_entry), cf); + g_free (cf); - updated_custom_format_example (GTK_ENTRY (dialog->custom_entry), - GTK_LABEL (dialog->custom_format_example)); + updated_custom_format_example (GTK_ENTRY (dialog->custom_entry), + GTK_LABEL (dialog->custom_format_example)); - if (prompt_type == PROMPT_CUSTOM_FORMAT) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->custom), TRUE); + if (prompt_type == PROMPT_CUSTOM_FORMAT) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->custom), TRUE); - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, TRUE); - gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); - } - else if (prompt_type == PROMPT_SELECTED_FORMAT) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->use_list), TRUE); + gtk_widget_set_sensitive (dialog->list, FALSE); + gtk_widget_set_sensitive (dialog->custom_entry, TRUE); + gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + } + else if (prompt_type == PROMPT_SELECTED_FORMAT) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->use_list), TRUE); - gtk_widget_set_sensitive (dialog->list, TRUE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - } - else - { - g_return_val_if_reached (NULL); - } + gtk_widget_set_sensitive (dialog->list, TRUE); + gtk_widget_set_sensitive (dialog->custom_entry, FALSE); + gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + } + else + { + g_return_val_if_reached (NULL); + } - /* setup a window of a sane size. */ - gtk_widget_set_size_request (dialog->list, 10, 200); + /* setup a window of a sane size. */ + gtk_widget_set_size_request (dialog->list, 10, 200); - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); + gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK); - g_signal_connect (dialog->custom, - "toggled", - G_CALLBACK (choose_format_dialog_button_toggled), - dialog); - g_signal_connect (dialog->use_list, - "toggled", - G_CALLBACK (choose_format_dialog_button_toggled), - dialog); - g_signal_connect (dialog->dialog, - "destroy", - G_CALLBACK (choose_format_dialog_destroyed), - dialog); - g_signal_connect (dialog->custom_entry, - "changed", - G_CALLBACK (updated_custom_format_example), - dialog->custom_format_example); - g_signal_connect (dialog->list, - "row_activated", - G_CALLBACK (choose_format_dialog_row_activated), - dialog); + g_signal_connect (dialog->custom, "toggled", + G_CALLBACK (choose_format_dialog_button_toggled), dialog); + g_signal_connect (dialog->use_list, "toggled", + G_CALLBACK (choose_format_dialog_button_toggled), dialog); + g_signal_connect (dialog->dialog, "destroy", + G_CALLBACK (choose_format_dialog_destroyed), dialog); + g_signal_connect (dialog->custom_entry, "changed", + G_CALLBACK (updated_custom_format_example), dialog->custom_format_example); + g_signal_connect (dialog->list, "row_activated", + G_CALLBACK (choose_format_dialog_row_activated), dialog); - gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); + gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); - return dialog; + return dialog; } static void choose_format_dialog_response_cb (GtkWidget *widget, - gint response, - ChooseFormatDialog *dialog) + gint response, + ChooseFormatDialog *dialog) { - switch (response) - { - case GTK_RESPONSE_HELP: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); - xed_help_display (GTK_WINDOW (widget), - NULL, - "xed-insert-date-time-plugin"); - break; - } - case GTK_RESPONSE_OK: - { - gchar *the_time; + switch (response) + { + case GTK_RESPONSE_HELP: + { + xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); + xed_help_display (GTK_WINDOW (widget), NULL, "xed-insert-date-time-plugin"); + break; + } + case GTK_RESPONSE_OK: + { + gchar *the_time; - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); + xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); - /* Get the user's chosen format */ - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) - { - gint sel_format; + /* Get the user's chosen format */ + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) + { + gint sel_format; - sel_format = get_format_from_list (dialog->list); - the_time = get_time (formats[sel_format]); + sel_format = get_format_from_list (dialog->list); + the_time = get_time (formats[sel_format]); - set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->settings, formats[sel_format]); - } - else - { - const gchar *format; + g_settings_set_enum (dialog->settings, PROMPT_TYPE_KEY, PROMPT_SELECTED_FORMAT); + g_settings_set_string (dialog->settings, SELECTED_FORMAT_KEY, formats[sel_format]); + } + else + { + const gchar *format; - format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry)); - the_time = get_time (format); + format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry)); + the_time = get_time (format); - set_prompt_type (dialog->settings, PROMPT_CUSTOM_FORMAT); - set_custom_format (dialog->settings, format); - } + g_settings_set_enum (dialog->settings, PROMPT_TYPE_KEY, PROMPT_CUSTOM_FORMAT); + g_settings_set_string (dialog->settings, CUSTOM_FORMAT_KEY, format); + } - g_return_if_fail (the_time != NULL); + g_return_if_fail (the_time != NULL); - real_insert_time (dialog->buffer, the_time); - g_free (the_time); + real_insert_time (dialog->buffer, the_time); + g_free (the_time); - gtk_widget_destroy (dialog->dialog); - break; - } - case GTK_RESPONSE_CANCEL: - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); - gtk_widget_destroy (dialog->dialog); - } + gtk_widget_destroy (dialog->dialog); + break; + } + case GTK_RESPONSE_CANCEL: + xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); + gtk_widget_destroy (dialog->dialog); + } } static void time_cb (GtkAction *action, - XedTimePlugin *plugin) + XedTimePlugin *plugin) { - XedWindow *window; - GtkTextBuffer *buffer; - gchar *the_time = NULL; - XedTimePluginPromptType prompt_type; + XedTimePluginPrivate *priv; + GtkTextBuffer *buffer; + gchar *the_time = NULL; + XedTimePluginPromptType prompt_type; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - window = XED_WINDOW (plugin->priv->window); - buffer = GTK_TEXT_BUFFER (xed_window_get_active_document (window)); - g_return_if_fail (buffer != NULL); + priv = plugin->priv; - prompt_type = get_prompt_type (plugin); + buffer = GTK_TEXT_BUFFER (xed_window_get_active_document (priv->window)); + g_return_if_fail (buffer != NULL); - if (prompt_type == USE_CUSTOM_FORMAT) + prompt_type = g_settings_get_enum (plugin->priv->settings, PROMPT_TYPE_KEY); + + if (prompt_type == USE_CUSTOM_FORMAT) + { + gchar *cf = get_custom_format (plugin); + the_time = get_time (cf); + g_free (cf); + } + else if (prompt_type == USE_SELECTED_FORMAT) + { + gchar *sf = get_selected_format (plugin); + the_time = get_time (sf); + g_free (sf); + } + else + { + ChooseFormatDialog *dialog; + + dialog = get_choose_format_dialog (GTK_WINDOW (priv->window), prompt_type, plugin); + if (dialog != NULL) { - gchar *cf = get_custom_format (plugin); - the_time = get_time (cf); - g_free (cf); - } - else if (prompt_type == USE_SELECTED_FORMAT) - { - gchar *sf = get_selected_format (plugin); - the_time = get_time (sf); - g_free (sf); - } - else - { - ChooseFormatDialog *dialog; + dialog->buffer = buffer; + dialog->settings = priv->settings; - dialog = get_choose_format_dialog (GTK_WINDOW (window), - prompt_type, - plugin); - if (dialog != NULL) - { - dialog->buffer = buffer; - dialog->settings = plugin->priv->settings; + g_signal_connect (dialog->dialog, "response", + G_CALLBACK (choose_format_dialog_response_cb), dialog); - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (choose_format_dialog_response_cb), - dialog); + gtk_widget_show (GTK_WIDGET (dialog->dialog)); + } - gtk_widget_show (GTK_WIDGET (dialog->dialog)); - } + return; + } - return; - } + g_return_if_fail (the_time != NULL); - g_return_if_fail (the_time != NULL); + real_insert_time (buffer, the_time); - real_insert_time (buffer, the_time); - - g_free (the_time); + g_free (the_time); } static GtkWidget * xed_time_plugin_create_configure_widget (PeasGtkConfigurable *configurable) { - TimeConfigureDialog *dialog; + TimeConfigureWidget *widget; - dialog = get_configure_dialog (XED_TIME_PLUGIN (configurable)); + widget = get_configure_widget (XED_TIME_PLUGIN (configurable)); - return dialog->content; + return widget->content; } static void @@ -1128,8 +1075,8 @@ xed_time_plugin_set_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_WINDOW: + plugin->priv->window = XED_WINDOW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1147,7 +1094,7 @@ xed_time_plugin_get_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: + case PROP_WINDOW: g_value_set_object (value, plugin->priv->window); break; default: @@ -1159,16 +1106,16 @@ xed_time_plugin_get_property (GObject *object, static void xed_time_plugin_class_init (XedTimePluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_time_plugin_finalize; + object_class->finalize = xed_time_plugin_finalize; object_class->dispose = xed_time_plugin_dispose; object_class->set_property = xed_time_plugin_set_property; object_class->get_property = xed_time_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + g_object_class_override_property (object_class, PROP_WINDOW, "window"); - g_type_class_add_private (object_class, sizeof (XedTimePluginPrivate)); + g_type_class_add_private (object_class, sizeof (XedTimePluginPrivate)); } static void @@ -1178,7 +1125,7 @@ xed_time_plugin_class_finalize (XedTimePluginClass *klass) } static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) { iface->activate = xed_time_plugin_activate; iface->deactivate = xed_time_plugin_deactivate; @@ -1197,7 +1144,7 @@ peas_register_types (PeasObjectModule *module) xed_time_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + XED_TYPE_WINDOW_ACTIVATABLE, XED_TYPE_TIME_PLUGIN); peas_object_module_register_extension_type (module, diff --git a/plugins/time/xed-time-plugin.h b/plugins/time/xed-time-plugin.h index 436ed05..1019ce9 100644 --- a/plugins/time/xed-time-plugin.h +++ b/plugins/time/xed-time-plugin.h @@ -30,23 +30,16 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ -#define XED_TYPE_TIME_PLUGIN (xed_time_plugin_get_type ()) -#define XED_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TIME_PLUGIN, XedTimePlugin)) -#define XED_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) -#define XED_IS_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TIME_PLUGIN)) -#define XED_IS_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TIME_PLUGIN)) +#define XED_TYPE_TIME_PLUGIN (xed_time_plugin_get_type ()) +#define XED_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TIME_PLUGIN, XedTimePlugin)) +#define XED_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) +#define XED_IS_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TIME_PLUGIN)) +#define XED_IS_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TIME_PLUGIN)) #define XED_TIME_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) -/* Private structure type */ -typedef struct _XedTimePluginPrivate XedTimePluginPrivate; - -/* - * Main object structure - */ -typedef struct _XedTimePlugin XedTimePlugin; +typedef struct _XedTimePlugin XedTimePlugin; +typedef struct _XedTimePluginPrivate XedTimePluginPrivate; +typedef struct _XedTimePluginClass XedTimePluginClass; struct _XedTimePlugin { @@ -56,20 +49,12 @@ struct _XedTimePlugin XedTimePluginPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedTimePluginClass XedTimePluginClass; - struct _XedTimePluginClass { PeasExtensionBaseClass parent_class; }; -/* - * Public methods - */ -GType xed_time_plugin_get_type (void) G_GNUC_CONST; +GType xed_time_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);