source-dialog: move credentials prompter to builder UI file
Save us some lines.
This commit is contained in:
committed by
Erick Pérez Castellanos
parent
fda5684371
commit
70ecba33ff
@@ -921,4 +921,119 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</template>
|
</template>
|
||||||
|
<object class="GtkDialog" id="credentials_dialog">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="type_hint">dialog</property>
|
||||||
|
<property name="transient_for">GcalSourceDialog</property>
|
||||||
|
<child internal-child="vbox">
|
||||||
|
<object class="GtkBox" id="credentials-dialog-vbox1">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">0</property>
|
||||||
|
<property name="border_width">0</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid" id="credentials_grid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="border_width">12</property>
|
||||||
|
<property name="row_spacing">6</property>
|
||||||
|
<property name="column_spacing">12</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="credentials_user_dim_label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">User</property>
|
||||||
|
<property name="xalign">1</property>
|
||||||
|
<style>
|
||||||
|
<class name="dim-label"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="credentials_password_dim_label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Password</property>
|
||||||
|
<property name="xalign">1</property>
|
||||||
|
<style>
|
||||||
|
<class name="dim-label"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkEntry" id="credentials_user_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<signal name="activate" handler="credential_entry_activate" object="credentials_dialog" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkEntry" id="credentials_password_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="visibility">False</property>
|
||||||
|
<signal name="activate" handler="credential_entry_activate" object="credentials_dialog" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child type="titlebar">
|
||||||
|
<object class="GtkHeaderBar" id="credentials_headerbar">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="title">Enter your credentials</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="credentials_cancel_button">
|
||||||
|
<property name="label" translatable="yes">Cancel</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<signal name="clicked" handler="credential_button_clicked" object="GcalSourceDialog" swapped="no" />
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="credentials_connect_button">
|
||||||
|
<property name="label" translatable="yes">Connect</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<signal name="clicked" handler="credential_button_clicked" object="GcalSourceDialog" swapped="no" />
|
||||||
|
<style>
|
||||||
|
<class name="suggested-action"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
|||||||
+39
-59
@@ -59,6 +59,13 @@ typedef struct
|
|||||||
GtkWidget *web_sources_listbox;
|
GtkWidget *web_sources_listbox;
|
||||||
GtkWidget *web_sources_revealer;
|
GtkWidget *web_sources_revealer;
|
||||||
|
|
||||||
|
/* credentials dialog */
|
||||||
|
GtkWidget *credentials_cancel_button;
|
||||||
|
GtkWidget *credentials_connect_button;
|
||||||
|
GtkWidget *credentials_dialog;
|
||||||
|
GtkWidget *credentials_password_entry;
|
||||||
|
GtkWidget *credentials_user_entry;
|
||||||
|
|
||||||
gint calendar_address_id;
|
gint calendar_address_id;
|
||||||
gint validate_url_resource_id;
|
gint validate_url_resource_id;
|
||||||
gint notification_timeout_id;
|
gint notification_timeout_id;
|
||||||
@@ -1228,6 +1235,18 @@ out:
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
credential_button_clicked (GtkWidget *button,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GcalSourceDialogPrivate *priv = GCAL_SOURCE_DIALOG(user_data)->priv;
|
||||||
|
|
||||||
|
if (button == priv->credentials_cancel_button)
|
||||||
|
gtk_dialog_response (GTK_DIALOG (priv->credentials_dialog), GTK_RESPONSE_CANCEL);
|
||||||
|
else
|
||||||
|
gtk_dialog_response (GTK_DIALOG (priv->credentials_dialog), GTK_RESPONSE_OK);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
credential_entry_activate (GtkEntry *entry,
|
credential_entry_activate (GtkEntry *entry,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
@@ -1240,72 +1259,26 @@ prompt_credentials (GcalSourceDialog *dialog,
|
|||||||
gchar **username,
|
gchar **username,
|
||||||
gchar **password)
|
gchar **password)
|
||||||
{
|
{
|
||||||
GtkWidget *password_entry;
|
GcalSourceDialogPrivate *priv = dialog->priv;
|
||||||
GtkWidget *prompt_dialog;
|
|
||||||
GtkWidget *name_entry;
|
|
||||||
GtkWidget *grid, *label;
|
|
||||||
GtkWidget *button;
|
|
||||||
gint response;
|
gint response;
|
||||||
|
|
||||||
// Name entry
|
// Cleanup last credentials
|
||||||
name_entry = gtk_entry_new ();
|
gtk_entry_set_text (GTK_ENTRY (priv->credentials_password_entry), "");
|
||||||
gtk_widget_set_hexpand (name_entry, TRUE);
|
gtk_entry_set_text (GTK_ENTRY (priv->credentials_user_entry), "");
|
||||||
|
|
||||||
// Password entry
|
|
||||||
password_entry = g_object_new (GTK_TYPE_ENTRY,
|
|
||||||
"visibility", FALSE,
|
|
||||||
"hexpand", TRUE,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
prompt_dialog = gtk_dialog_new_with_buttons (_("Enter your username and password"), GTK_WINDOW (dialog),
|
|
||||||
GTK_DIALOG_MODAL | GTK_DIALOG_USE_HEADER_BAR,
|
|
||||||
_("Cancel"), GTK_RESPONSE_CANCEL,
|
|
||||||
_("Connect"), GTK_RESPONSE_OK, NULL);
|
|
||||||
|
|
||||||
// Set the "Connect" button style
|
|
||||||
button = gtk_dialog_get_widget_for_response (GTK_DIALOG (prompt_dialog), GTK_RESPONSE_OK);
|
|
||||||
gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action");
|
|
||||||
|
|
||||||
// Add some labels
|
|
||||||
grid = gtk_grid_new ();
|
|
||||||
g_object_set (grid,
|
|
||||||
"border-width", 12,
|
|
||||||
"column-spacing", 12,
|
|
||||||
"row-spacing", 6,
|
|
||||||
"expand", TRUE,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
label = gtk_label_new (_("User"));
|
|
||||||
gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
|
|
||||||
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
|
||||||
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
|
|
||||||
|
|
||||||
label = gtk_label_new (_("Password"));
|
|
||||||
gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
|
|
||||||
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
|
||||||
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
|
|
||||||
|
|
||||||
// Add entries
|
|
||||||
gtk_grid_attach (GTK_GRID (grid), name_entry, 1, 0, 1, 1);
|
|
||||||
gtk_grid_attach (GTK_GRID (grid), password_entry, 1, 1, 1, 1);
|
|
||||||
|
|
||||||
// Insert into the dialog
|
|
||||||
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (prompt_dialog))), grid);
|
|
||||||
gtk_widget_show_all (grid);
|
|
||||||
|
|
||||||
g_signal_connect (name_entry, "activate", G_CALLBACK (credential_entry_activate), prompt_dialog);
|
|
||||||
g_signal_connect (password_entry, "activate", G_CALLBACK (credential_entry_activate), prompt_dialog);
|
|
||||||
|
|
||||||
// Show the dialog, then destroy it
|
// Show the dialog, then destroy it
|
||||||
response = gtk_dialog_run (GTK_DIALOG (prompt_dialog));
|
response = gtk_dialog_run (GTK_DIALOG (priv->credentials_dialog));
|
||||||
|
|
||||||
if (username)
|
if (response == GTK_RESPONSE_OK)
|
||||||
*username = g_strdup (gtk_entry_get_text (GTK_ENTRY (name_entry)));
|
{
|
||||||
|
if (username)
|
||||||
|
*username = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->credentials_user_entry)));
|
||||||
|
|
||||||
if (password)
|
if (password)
|
||||||
*password = g_strdup (gtk_entry_get_text (GTK_ENTRY (password_entry)));
|
*password = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->credentials_password_entry)));
|
||||||
|
}
|
||||||
|
|
||||||
gtk_widget_destroy (prompt_dialog);
|
gtk_widget_hide (priv->credentials_dialog);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -1741,6 +1714,11 @@ gcal_source_dialog_class_init (GcalSourceDialogClass *klass)
|
|||||||
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, calendar_visible_check);
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, calendar_visible_check);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, calendars_listbox);
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, calendars_listbox);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, cancel_button);
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, cancel_button);
|
||||||
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, credentials_cancel_button);
|
||||||
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, credentials_connect_button);
|
||||||
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, credentials_dialog);
|
||||||
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, credentials_password_entry);
|
||||||
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, credentials_user_entry);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, default_check);
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, default_check);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, edit_grid);
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, edit_grid);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, headerbar);
|
gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, headerbar);
|
||||||
@@ -1764,6 +1742,8 @@ gcal_source_dialog_class_init (GcalSourceDialogClass *klass)
|
|||||||
gtk_widget_class_bind_template_callback (widget_class, calendar_listbox_row_activated);
|
gtk_widget_class_bind_template_callback (widget_class, calendar_listbox_row_activated);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, calendar_visible_check_toggled);
|
gtk_widget_class_bind_template_callback (widget_class, calendar_visible_check_toggled);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, cancel_button_clicked);
|
gtk_widget_class_bind_template_callback (widget_class, cancel_button_clicked);
|
||||||
|
gtk_widget_class_bind_template_callback (widget_class, credential_button_clicked);
|
||||||
|
gtk_widget_class_bind_template_callback (widget_class, credential_entry_activate);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, color_set);
|
gtk_widget_class_bind_template_callback (widget_class, color_set);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, default_check_toggled);
|
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, description_label_link_activated);
|
||||||
|
|||||||
Reference in New Issue
Block a user