static gboolean prop_save_timeout (LdapFavoriteSelector *fsel) { TFavorites *bfav; TFavoritesAttributes fav; GError *error = NULL; gboolean allok; bfav = t_connection_get_favorites (fsel->priv->tcnc); memset (&fav, 0, sizeof (TFavoritesAttributes)); fav.id = fsel->priv->properties_id; fav.type = T_FAVORITES_LDAP_DN; fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (fsel->priv->properties_name)); fav.descr = (gchar*) gtk_entry_get_text (GTK_ENTRY (fsel->priv->properties_descr)); fav.contents = (gchar*) gtk_entry_get_text (GTK_ENTRY (fsel->priv->properties_name)); allok = t_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, fsel->priv->properties_position, &error); if (! allok) { ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) fsel), _("Could not add favorite: %s"), error && error->message ? error->message : _("No detail")); if (error) g_error_free (error); } fsel->priv->prop_save_timeout = 0; return FALSE; /* remove timeout */ }
static void sql_favorite_new_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *tconsole) { TFavorites *tfav; TFavoritesAttributes fav; GError *error = NULL; GdaSet *set; GtkWidget *dlg, *form; gint response; const GValue *cvalue; set = gda_set_new_inline (1, _("Favorite's name"), G_TYPE_STRING, _("Unnamed query")); dlg = gdaui_basic_form_new_in_dialog (set, (GtkWindow*) gtk_widget_get_toplevel (GTK_WIDGET (tconsole)), _("Name of the favorite to create"), _("Enter the name of the favorite to create")); form = g_object_get_data (G_OBJECT (dlg), "form"); g_signal_connect (form, "activated", G_CALLBACK (fav_form_name_activated_cb), dlg); response = gtk_dialog_run (GTK_DIALOG (dlg)); if (response == GTK_RESPONSE_REJECT) { g_object_unref (set); gtk_widget_destroy (dlg); return; } memset (&fav, 0, sizeof (fav)); fav.id = -1; fav.type = T_FAVORITES_QUERIES; fav.contents = query_editor_get_all_text (tconsole->priv->editor); cvalue = gda_set_get_holder_value (set, _("Favorite's name")); fav.name = (gchar*) g_value_get_string (cvalue); tfav = t_connection_get_favorites (tconsole->priv->tcnc); if (! t_favorites_add (tfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) { ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole), _("Could not add favorite: %s"), error && error->message ? error->message : _("No detail")); if (error) g_error_free (error); } else tconsole->priv->fav_id = fav.id; g_free (fav.contents); g_object_unref (set); gtk_widget_destroy (dlg); }
static gboolean tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path, GtkSelectionData *selection_data, QueryFavoriteSelector *tsel) { TFavorites *bfav; TFavoritesAttributes fav; GError *error = NULL; gint pos; gboolean retval = TRUE; gint id; bfav = t_connection_get_favorites (tsel->priv->tcnc); id = t_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data), &fav, NULL); if (id < 0) { memset (&fav, 0, sizeof (TFavoritesAttributes)); fav.id = -1; fav.type = T_FAVORITES_QUERIES; fav.name = _("Unnamed query"); fav.descr = NULL; fav.contents = (gchar*) gtk_selection_data_get_data (selection_data); } pos = atoi (path); /*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/ if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, pos, &error)) { ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel), _("Could not add favorite: %s"), error && error->message ? error->message : _("No detail")); if (error) g_error_free (error); retval = FALSE; } if (id >= 0) t_favorites_reset_attributes (&fav); return retval; }
/* * POPUP */ static void real_save_clicked_cb (GtkWidget *button, RelationsDiagram *diagram) { gchar *str; str = browser_canvas_serialize_items (BROWSER_CANVAS (diagram->priv->canvas)); GError *lerror = NULL; TFavorites *bfav; TFavoritesAttributes fav; memset (&fav, 0, sizeof (TFavoritesAttributes)); fav.id = diagram->priv->fav_id; fav.type = T_FAVORITES_DIAGRAMS; fav.name = gtk_editable_get_chars (GTK_EDITABLE (diagram->priv->name_entry), 0, -1); if (!*fav.name) { g_free (fav.name); fav.name = g_strdup (_("Diagram")); } fav.contents = str; gtk_widget_hide (diagram->priv->popup_container); bfav = t_connection_get_favorites (diagram->priv->tcnc); if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, G_MAXINT, &lerror)) { ui_show_error ((GtkWindow*) gtk_widget_get_toplevel (button), "<b>%s:</b>\n%s", _("Could not save diagram"), lerror && lerror->message ? lerror->message : _("No detail")); if (lerror) g_error_free (lerror); } relations_diagram_set_fav_id (diagram, fav.id, NULL); g_free (fav.name); g_free (str); }
static void sql_favorite_modify_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *tconsole) { TFavorites *tfav; TFavoritesAttributes fav; GError *error = NULL; memset (&fav, 0, sizeof (fav)); fav.id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (mitem), "favid")); fav.type = T_FAVORITES_QUERIES; fav.contents = query_editor_get_all_text (tconsole->priv->editor); fav.name = g_object_get_data (G_OBJECT (mitem), "favname"); tfav = t_connection_get_favorites (tconsole->priv->tcnc); if (! t_favorites_add (tfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) { ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole), _("Could not add favorite: %s"), error && error->message ? error->message : _("No detail")); if (error) g_error_free (error); } g_free (fav.contents); }
static gboolean prop_save_timeout (QueryFavoriteSelector *tsel) { TFavorites *bfav; TFavoritesAttributes fav; GError *error = NULL; gboolean allok, actiondel = TRUE; bfav = t_connection_get_favorites (tsel->priv->tcnc); memset (&fav, 0, sizeof (TFavoritesAttributes)); fav.id = tsel->priv->properties_id; fav.type = T_FAVORITES_QUERIES; fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name)); fav.descr = NULL; fav.contents = query_editor_get_all_text (QUERY_EDITOR (tsel->priv->properties_text)); allok = t_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, tsel->priv->properties_position, &error); if (! allok) { ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel), _("Could not add favorite: %s"), error && error->message ? error->message : _("No detail")); if (error) g_error_free (error); } g_free (fav.contents); if (allok && (fav.id >= 0)) { gboolean is_action; gint qid = fav.id; is_action = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tsel->priv->properties_action)); if (is_action) { fav.id = -1; fav.type = T_FAVORITES_ACTIONS; fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name)); fav.descr = NULL; fav.contents = g_strdup_printf ("QUERY%d", qid); allok = t_favorites_add (bfav, 0, &fav, -1, tsel->priv->properties_position, &error); if (! allok) { ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel), _("Could not add action: %s"), error && error->message ? error->message : _("No detail")); if (error) g_error_free (error); } else actiondel = FALSE; /*g_print ("ACTION_ADDED %d: %s\n", fav.id, fav.contents);*/ g_free (fav.contents); } } if (actiondel && (tsel->priv->properties_id >= 0)) { /* remove action */ gint id; gchar *tmp; tmp = g_strdup_printf ("QUERY%d", tsel->priv->properties_id); id = t_favorites_find (bfav, 0, tmp, &fav, NULL); if (id >= 0) { t_favorites_delete (bfav, 0, &fav, NULL); /*g_print ("ACTION_DELETED %d: %s\n", fav.id, tmp);*/ } g_free (tmp); } tsel->priv->prop_save_timeout = 0; return FALSE; /* remove timeout */ }