source-dialog: separate local & remote source handling

This commit is contained in:
Georges Basile Stavracas Neto
2015-05-25 12:31:07 -04:00
committed by Erick Pérez Castellanos
parent f724a6aaf6
commit 9d222e47fc
2 changed files with 69 additions and 5 deletions
+1
View File
@@ -134,6 +134,7 @@
<property name="show_border">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<signal name="switch_page" handler="notebook_page_switched" object="GcalSourceDialog" swapped="no" />
<child>
<object class="GtkGrid" id="web_source_grid">
<property name="visible">True</property>
+68 -5
View File
@@ -39,6 +39,8 @@ typedef struct
/* flags */
GcalSourceDialogMode mode;
ESource *source;
ESource *local_source;
ESource *remote_source;
ESource *old_default_source;
GBinding *title_bind;
@@ -72,6 +74,11 @@ static void name_entry_text_changed (GObject *ob
GParamSpec *pspec,
gpointer user_data);
static void notebook_page_switched (GtkWidget *notebook,
GtkWidget *page,
guint page_num,
gpointer user_data);
static void response_signal (GtkDialog *dialog,
gint response_id,
gpointer user_data);
@@ -198,6 +205,33 @@ name_entry_text_changed (GObject *object,
e_source_set_display_name (priv->source, gtk_entry_get_text (GTK_ENTRY (priv->name_entry)));
}
/**
* notebook_page_switched:
*
* Validates the current state of
* the dialog according to the current
* page.
*
* Returns:
*/
static void
notebook_page_switched (GtkWidget *notebook,
GtkWidget *page,
guint page_num,
gpointer user_data)
{
GcalSourceDialogPrivate *priv = GCAL_SOURCE_DIALOG (user_data)->priv;
if (page_num == 0)
{
gtk_widget_set_sensitive (priv->add_button, (priv->remote_source != NULL));
}
else
{
gtk_widget_set_sensitive (priv->add_button, (priv->local_source != NULL));
}
}
/**
* response_signal:
*
@@ -214,17 +248,45 @@ response_signal (GtkDialog *dialog,
GcalSourceDialogPrivate *priv = GCAL_SOURCE_DIALOG (dialog)->priv;
/* save the source */
if (priv->mode == GCAL_SOURCE_DIALOG_MODE_EDIT ||
(priv->mode == GCAL_SOURCE_DIALOG_MODE_CREATE && response_id == GTK_RESPONSE_APPLY))
if (priv->mode == GCAL_SOURCE_DIALOG_MODE_EDIT)
{
gcal_manager_save_source (priv->manager, priv->source);
}
/* commit the new source */
if (priv->mode == GCAL_SOURCE_DIALOG_MODE_CREATE && response_id == GTK_RESPONSE_APPLY)
{
ESource *current_source, *other_source;
gint page;
page = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
current_source = (page == 0 ? priv->remote_source : priv->local_source);
other_source = (page == 1 ? priv->remote_source : priv->local_source);
/* save the current page's source */
if (current_source != NULL)
gcal_manager_save_source (priv->manager, current_source);
/* destory the leftover source */
if (other_source != NULL)
g_object_unref (other_source);
}
/* Destroy the source when the operation is cancelled */
if (priv->mode == GCAL_SOURCE_DIALOG_MODE_CREATE && response_id == GTK_RESPONSE_CANCEL)
{
g_object_unref (priv->source);
priv->source = NULL;
if (priv->local_source != NULL)
{
g_object_unref (priv->local_source);
priv->local_source = NULL;
}
if (priv->remote_source != NULL)
{
g_object_unref (priv->remote_source);
priv->remote_source = NULL;
}
}
}
@@ -291,7 +353,7 @@ select_calendar_file (GtkButton *button,
e_source_set_display_name (source, g_file_get_basename (file));
/* Set the private source so it saves at closing */
priv->source = source;
priv->local_source = source;
/* Update buttons */
gtk_button_set_label (GTK_BUTTON (priv->select_file_button), g_file_get_basename (file));
@@ -396,6 +458,7 @@ gcal_source_dialog_class_init (GcalSourceDialogClass *klass)
gtk_widget_class_bind_template_callback (widget_class, default_check_toggled);
gtk_widget_class_bind_template_callback (widget_class, description_label_link_activated);
gtk_widget_class_bind_template_callback (widget_class, name_entry_text_changed);
gtk_widget_class_bind_template_callback (widget_class, notebook_page_switched);
gtk_widget_class_bind_template_callback (widget_class, response_signal);
gtk_widget_class_bind_template_callback (widget_class, select_calendar_file);
}