kopia lustrzana https://gitlab.com/Zwarf/picplanner
Improve search functionality
rodzic
e3d19f2628
commit
58519b5b8d
|
@ -65,6 +65,51 @@ struct _PicplannerWindow
|
|||
|
||||
G_DEFINE_TYPE (PicplannerWindow, picplanner_window, ADW_TYPE_APPLICATION_WINDOW)
|
||||
|
||||
static gboolean
|
||||
find_loc_children (GWeatherLocation *location,
|
||||
const char *search_str,
|
||||
GWeatherLocation **locations,
|
||||
int *iteration)
|
||||
{
|
||||
GWeatherLocation *child = NULL;
|
||||
while ((child = gweather_location_next_child (location, child)) != NULL)
|
||||
{
|
||||
if (gweather_location_get_level (child) == GWEATHER_LOCATION_CITY &&
|
||||
*iteration < 10)
|
||||
{
|
||||
const char *city = gweather_location_get_name (child);
|
||||
const char *city_norm = g_utf8_normalize (city, strlen (city), G_NORMALIZE_ALL_COMPOSE);
|
||||
const char *city_string = g_utf8_casefold (city_norm, strlen (city_norm));
|
||||
if (strstr (city_string, search_str))
|
||||
{
|
||||
locations[*iteration] = g_object_ref(child);
|
||||
(*iteration)++;
|
||||
//g_print ("Search: %s, City to append: %s\n",search_str, city_string);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (find_loc_children (child, search_str, locations, iteration))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
find_loc (GWeatherLocation *world,
|
||||
const char *search_str,
|
||||
GWeatherLocation **locations)
|
||||
{
|
||||
int *iteration;
|
||||
int iter = 0;
|
||||
iteration = &iter;
|
||||
|
||||
find_loc_children (world, search_str, locations, iteration);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
search_location (GtkWidget *self,
|
||||
gpointer user_data)
|
||||
|
@ -73,12 +118,29 @@ search_location (GtkWidget *self,
|
|||
PicplannerWindow *window = user_data;
|
||||
(void) window;
|
||||
|
||||
const char *search_string = gtk_editable_get_text (GTK_EDITABLE (window->search_entry));
|
||||
const char *search_string_casefold = g_utf8_casefold (search_string, strlen (search_string));
|
||||
g_print ("Search string: %s\n", search_string_casefold);
|
||||
const char *search_text = gtk_editable_get_text (GTK_EDITABLE (window->search_entry));
|
||||
const char *search_norm = g_utf8_normalize (search_text, strlen (search_text), G_NORMALIZE_ALL_COMPOSE);
|
||||
const char *search_string = g_utf8_casefold (search_text, strlen (search_norm));
|
||||
g_print ("Search string: %s\n", search_string);
|
||||
|
||||
|
||||
GWeatherLocation *world = gweather_location_get_world ();
|
||||
GWeatherLocation *locations[10];
|
||||
|
||||
for (int i=0; i<10; i++)
|
||||
locations[i] = NULL;
|
||||
|
||||
if (!strstr ("", search_string))
|
||||
{
|
||||
find_loc (world, search_string, locations);
|
||||
}
|
||||
|
||||
for (int i=0; i<10; i++)
|
||||
{
|
||||
if (locations[i])
|
||||
g_print ("Found locations: %s\n", gweather_location_get_name (locations[i]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Ładowanie…
Reference in New Issue