[libgda] GdaBrowser: favorite queries reordering correction



commit dc31ba087efb3e3e21481bc0d16f1f075c7b4f38
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Sep 22 21:03:24 2009 +0200

    GdaBrowser: favorite queries reordering correction

 tools/browser/browser-favorites.c                  |   25 +++++++++++++++++-
 tools/browser/browser-favorites.h                  |    2 +
 tools/browser/doc/gda-browser-sections.txt         |    1 +
 tools/browser/query-exec/query-favorite-selector.c |   28 ++++++++++++-------
 4 files changed, 45 insertions(+), 11 deletions(-)
---
diff --git a/tools/browser/browser-favorites.c b/tools/browser/browser-favorites.c
index f574b88..4898311 100644
--- a/tools/browser/browser-favorites.c
+++ b/tools/browser/browser-favorites.c
@@ -1037,6 +1037,29 @@ browser_favorites_delete (BrowserFavorites *bfav, guint session_id,
 }
 
 /**
+ * browser_favorites_find
+ * @bfav: a #BrowserFavorites
+ * @session_id: 0 for now
+ * @contents: the favorite's contents
+ * @out_fav: a #BrowserFavoritesAttributes to be filled with the favorite's attributes, or %NULL
+ * @error: a place to store errors, or %NULL
+ *
+ * Get all the information about a favorite from its id: fills the @out_fav
+ * pointed structure. Use browser_favorites_reset_attributes() to reset @out_fav's contents.
+ *
+ * Retuns: the requested's favorite ID, or -1 if not found
+ */
+gint
+browser_favorites_find (BrowserFavorites *bfav, guint session_id, const gchar *contents,
+			BrowserFavoritesAttributes *out_fav, GError **error)
+{
+	g_return_val_if_fail (BROWSER_IS_FAVORITES (bfav), -1);
+	g_return_val_if_fail (contents, -1);
+
+	return find_favorite (bfav, session_id, -1, contents, out_fav, error);
+}
+
+/**
  * browser_favorites_get
  * @bfav: a #BrowserFavorites
  * @fav_id: the favorite's ID
@@ -1044,7 +1067,7 @@ browser_favorites_delete (BrowserFavorites *bfav, guint session_id,
  * @error: a place to store errors, or %NULL
  *
  * Get all the information about a favorite from its id: fills the @out_fav
- * pointed structure.
+ * pointed structure. Use browser_favorites_reset_attributes() to reset @out_fav's contents.
  *
  * Retuns: %TRUE if no error occurred.
  */
diff --git a/tools/browser/browser-favorites.h b/tools/browser/browser-favorites.h
index e87d298..f74f5c9 100644
--- a/tools/browser/browser-favorites.h
+++ b/tools/browser/browser-favorites.h
@@ -95,6 +95,8 @@ gboolean            browser_favorites_delete       (BrowserFavorites *bfav, guin
 void                browser_favorites_free_list    (GSList *fav_list);
 void                browser_favorites_reset_attributes (BrowserFavoritesAttributes *fav);
 
+gint                browser_favorites_find         (BrowserFavorites *bfav, guint session_id, const gchar *contents,
+						    BrowserFavoritesAttributes *out_fav, GError **error);
 gboolean            browser_favorites_get          (BrowserFavorites *bfav, gint fav_id,
 						    BrowserFavoritesAttributes *out_fav, GError **error);
 G_END_DECLS
diff --git a/tools/browser/doc/gda-browser-sections.txt b/tools/browser/doc/gda-browser-sections.txt
index 873089f..77702af 100644
--- a/tools/browser/doc/gda-browser-sections.txt
+++ b/tools/browser/doc/gda-browser-sections.txt
@@ -195,6 +195,7 @@ browser_favorites_list
 browser_favorites_delete
 browser_favorites_free_list
 browser_favorites_reset_attributes
+browser_favorites_find
 browser_favorites_get
 <SUBSECTION Standard>
 BROWSER_FAVORITES
diff --git a/tools/browser/query-exec/query-favorite-selector.c b/tools/browser/query-exec/query-favorite-selector.c
index f9fbaa7..7be6098 100644
--- a/tools/browser/query-exec/query-favorite-selector.c
+++ b/tools/browser/query-exec/query-favorite-selector.c
@@ -563,28 +563,36 @@ tree_store_drag_drop_cb (GdauiTreeStore *store, const gchar *path, GtkSelectionD
 	BrowserFavoritesAttributes fav;
 	GError *error = NULL;
 	gint pos;
+	gboolean retval = TRUE;
+	gint id;
+	bfav = browser_connection_get_favorites (tsel->priv->bcnc);
 
-	memset (&fav, 0, sizeof (BrowserFavoritesAttributes));
-	fav.id = -1;
-	fav.type = BROWSER_FAVORITES_QUERIES;
-	fav.name = _("Unnamed query");
-	fav.descr = NULL;
-	fav.contents = (gchar*) selection_data->data;
+	id = browser_favorites_find (bfav, 0, (gchar*) selection_data->data, &fav, NULL);
+	if (id < 0) {
+		memset (&fav, 0, sizeof (BrowserFavoritesAttributes));
+		fav.id = -1;
+		fav.type = BROWSER_FAVORITES_QUERIES;
+		fav.name = _("Unnamed query");
+		fav.descr = NULL;
+		fav.contents = (gchar*) selection_data->data;
+	}
 
 	pos = atoi (path);
-	g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);
+	/*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/
 	
-	bfav = browser_connection_get_favorites (tsel->priv->bcnc);
 	if (! browser_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, pos, &error)) {
 		browser_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);
-		return FALSE;
+		retval = FALSE;
 	}
+	
+	if (id >= 0)
+		browser_favorites_reset_attributes (&fav);
 
-	return TRUE;
+	return retval;
 }
 
 static gboolean



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]