Ejemplo n.º 1
0
static void
g_paste_settings_ui_stack_init (GPasteSettingsUiStack *self)
{
    GPasteSettingsUiStackPrivate *priv = g_paste_settings_ui_stack_get_instance_private (self);

    GError *error = NULL;
    priv->client = g_paste_client_new (&error);

    if (g_paste_settings_ui_check_connection_error (error))
        exit (EXIT_FAILURE);

    priv->settings = g_paste_settings_new ();
    priv->settings_signal = g_signal_connect (priv->settings,
                                              "changed",
                                              G_CALLBACK (g_paste_settings_ui_stack_settings_changed),
                                              priv);

    GStrv *actions = priv->actions = (GStrv *) g_malloc (3 * sizeof (GStrv));

    GStrv action = actions[0] = (GStrv) g_malloc (2 * sizeof (gchar *));
    action[0] = (gchar *) "switch";
    /* translators: This is the name of a multi-history management action */
    action[1] = _("Switch to");

    action = actions[1] = (GStrv) g_malloc (2 * sizeof (gchar *));
    action[0] = (gchar *) "delete";
    /* translators: This is the name of a multi-history management action */
    action[1] = _("Delete");

    actions[2] = NULL;
}
Ejemplo n.º 2
0
static void
backup_callback (const gchar *value,
                 gpointer     user_data)
{
    GPasteSettingsUiStackPrivate *priv = user_data;
    G_PASTE_CLEANUP_ERROR_FREE GError *error = NULL;

    g_paste_client_backup_history_sync (priv->client, value, &error);

    if (g_paste_settings_ui_check_connection_error (error))
        return;

    g_paste_settings_ui_stack_private_refill_histories (priv);
}
Ejemplo n.º 3
0
/**
 * g_paste_settings_ui_stack_new:
 *
 * Create a new instance of #GPasteSettingsUiStack
 *
 * Returns: (nullable): a newly allocated #GPasteSettingsUiStack
 *                      free it with g_object_unref
 */
G_PASTE_VISIBLE GPasteSettingsUiStack *
g_paste_settings_ui_stack_new (void)
{
    GPasteSettingsUiStack *self = G_PASTE_SETTINGS_UI_STACK (gtk_widget_new (G_PASTE_TYPE_SETTINGS_UI_STACK,
                                                                             "margin",      12,
                                                                             "homogeneous", TRUE,
                                                                             NULL));
    GPasteSettingsUiStackPrivate *priv = g_paste_settings_ui_stack_get_instance_private (self);

    if (g_paste_settings_ui_check_connection_error (priv->init_error))
    {
        g_object_unref (self);
        return NULL;
    }

    return self;
}
Ejemplo n.º 4
0
static void
g_paste_settings_ui_stack_private_refill_histories (GPasteSettingsUiStackPrivate *priv)
{
    G_PASTE_CLEANUP_ERROR_FREE GError *error = NULL;
    GStrv histories = g_paste_client_list_histories_sync (priv->client, &error);

    if (g_paste_settings_ui_check_connection_error (error))
        return;

    GtkComboBoxText *targets = priv->targets;

    gtk_combo_box_text_remove_all (targets);

    for (guint i = 0; histories[i]; ++i)
        gtk_combo_box_text_append (targets, histories[i], histories[i]);

    gtk_combo_box_set_active_id (GTK_COMBO_BOX (targets),
                                 g_paste_settings_get_history_name (priv->settings));
}
Ejemplo n.º 5
0
static void
targets_callback (const gchar *action,
                  const gchar *target,
                  gpointer     user_data)
{
    GPasteSettingsUiStackPrivate *priv = user_data;
    GPasteClient *client = priv->client;
    G_PASTE_CLEANUP_ERROR_FREE GError *error = NULL;

    if (!g_strcmp0 (action, "switch"))
        g_paste_client_switch_history_sync (client, target, &error);
    else if (!g_strcmp0 (action, "delete"))
        g_paste_client_delete_history_sync (client, target, &error);
    else
        fprintf (stderr, "unknown action: %s\n", action);

    if (g_paste_settings_ui_check_connection_error (error))
        return;

    g_paste_settings_ui_stack_private_refill_histories (priv);
}