[libgweather] [libgweather] Add gweather_location_entry_has_custom_text() API



commit 30bcfacd01061bea0c6eb48ea4c08c94ad55bdbb
Author: Vincent Untz <vuntz gnome org>
Date:   Wed Aug 12 10:59:14 2009 +0200

    [libgweather] Add gweather_location_entry_has_custom_text() API
    
    This is needed if we want to know whether the text in the entry is the
    default text for the location, or something that was modified by the
    user.
    
    Part of http://bugzilla.gnome.org/show_bug.cgi?id=591516

 libgweather/location-entry.c |   32 ++++++++++++++++++++++++++++++++
 libgweather/location-entry.h |    3 +++
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/libgweather/location-entry.c b/libgweather/location-entry.c
index 331fdaa..34cc5ca 100644
--- a/libgweather/location-entry.c
+++ b/libgweather/location-entry.c
@@ -67,6 +67,7 @@ static gboolean match_selected (GtkEntryCompletion *completion,
 				GtkTreeModel       *model,
 				GtkTreeIter        *iter,
 				gpointer            entry);
+static void     entry_changed (GWeatherLocationEntry *entry);
 
 static void
 gweather_location_entry_init (GWeatherLocationEntry *entry)
@@ -84,6 +85,10 @@ gweather_location_entry_init (GWeatherLocationEntry *entry)
 
     gtk_entry_set_completion (GTK_ENTRY (entry), completion);
     g_object_unref (completion);
+
+    entry->custom_text = FALSE;
+    g_signal_connect (entry, "changed",
+		      G_CALLBACK (entry_changed), NULL);
 }
 
 static void
@@ -159,6 +164,12 @@ get_property (GObject *object, guint prop_id,
 }
 
 static void
+entry_changed (GWeatherLocationEntry *entry)
+{
+    entry->custom_text = TRUE;
+}
+
+static void
 set_location_internal (GWeatherLocationEntry *entry,
 		       GtkTreeModel          *model,
 		       GtkTreeIter           *iter)
@@ -176,10 +187,12 @@ set_location_internal (GWeatherLocationEntry *entry,
 			    -1);
 	entry->location = gweather_location_ref (loc);
 	gtk_entry_set_text (GTK_ENTRY (entry), name);
+	entry->custom_text = FALSE;
 	g_free (name);
     } else {
 	entry->location = NULL;
 	gtk_entry_set_text (GTK_ENTRY (entry), "");
+	entry->custom_text = TRUE;
     }
 
     gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
@@ -246,6 +259,25 @@ gweather_location_entry_get_location (GWeatherLocationEntry *entry)
 }
 
 /**
+ * gweather_location_entry_has_custom_text:
+ * @entry: a #GWeatherLocationEntry
+ *
+ * Checks whether or not @entry's text has been modified by the user.
+ * Note that this does not mean that no location is associated with @entry.
+ * gweather_location_entry_get_location() should be used for this.
+ *
+ * Return value: %TRUE if @entry's text was modified by the user, or %FALSE if
+ * it's set to the default text of a location.
+ **/
+gboolean
+gweather_location_entry_has_custom_text (GWeatherLocationEntry *entry)
+{
+    g_return_val_if_fail (GWEATHER_IS_LOCATION_ENTRY (entry), FALSE);
+
+    return entry->custom_text;
+}
+
+/**
  * gweather_location_entry_set_city:
  * @entry: a #GWeatherLocationEntry
  * @city_name: (allow-none): the city name, or %NULL
diff --git a/libgweather/location-entry.h b/libgweather/location-entry.h
index e628383..919d22b 100644
--- a/libgweather/location-entry.h
+++ b/libgweather/location-entry.h
@@ -36,6 +36,7 @@ typedef struct {
 
     /*< private >*/
     GWeatherLocation *location, *top;
+    guint custom_text : 1;
 } GWeatherLocationEntry;
 
 typedef struct {
@@ -51,6 +52,8 @@ void              gweather_location_entry_set_location (GWeatherLocationEntry *e
 							GWeatherLocation      *loc);
 GWeatherLocation *gweather_location_entry_get_location (GWeatherLocationEntry *entry);
 
+gboolean          gweather_location_entry_has_custom_text (GWeatherLocationEntry *entry);
+
 gboolean          gweather_location_entry_set_city     (GWeatherLocationEntry *entry,
 							const char            *city_name,
 							const char            *code);



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