[nautilus] nautilus-search-engine: search by creation time
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] nautilus-search-engine: search by creation time
- Date: Sat, 27 Nov 2021 11:14:38 +0000 (UTC)
commit 639eb6dd6115ae617bc4dc26d752060ef301e94e
Author: Nishit Patel <nishitlimbani130 gmail com>
Date: Mon Jul 19 17:52:27 2021 +0530
nautilus-search-engine: search by creation time
this will let user search for the files using the
crtime (creation time) of the files
Closes #1761
data/org.gnome.nautilus.gschema.xml | 1 +
src/nautilus-query.h | 3 +-
src/nautilus-search-engine-model.c | 6 +++-
src/nautilus-search-engine-recent.c | 11 ++++++--
src/nautilus-search-engine-simple.c | 9 +++++-
src/nautilus-search-engine-tracker.c | 28 +++++++++++++++---
src/nautilus-search-hit.c | 44 +++++++++++++++++++++++++++++
src/nautilus-search-hit.h | 2 ++
src/nautilus-search-popover.c | 18 ++++++++++--
src/resources/ui/nautilus-search-popover.ui | 21 ++++++++++++--
10 files changed, 130 insertions(+), 13 deletions(-)
---
diff --git a/data/org.gnome.nautilus.gschema.xml b/data/org.gnome.nautilus.gschema.xml
index 34af6f87a..75f736e38 100644
--- a/data/org.gnome.nautilus.gschema.xml
+++ b/data/org.gnome.nautilus.gschema.xml
@@ -59,6 +59,7 @@
<enum id="org.gnome.nautilus.SearchFilterTimeType">
<value value="0" nick="last_modified"/>
<value value="1" nick="last_used"/>
+ <value value="2" nick="created"/>
</enum>
<enum id="org.gnome.nautilus.CompressionFormat">
diff --git a/src/nautilus-query.h b/src/nautilus-query.h
index 6d6f66250..47f053f04 100644
--- a/src/nautilus-query.h
+++ b/src/nautilus-query.h
@@ -26,7 +26,8 @@
typedef enum {
NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS,
- NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED
+ NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED,
+ NAUTILUS_QUERY_SEARCH_TYPE_CREATED
} NautilusQuerySearchType;
typedef enum {
diff --git a/src/nautilus-search-engine-model.c b/src/nautilus-search-engine-model.c
index 58ae6bf11..8bf7da941 100644
--- a/src/nautilus-search-engine-model.c
+++ b/src/nautilus-search-engine-model.c
@@ -181,10 +181,14 @@ model_directory_ready_cb (NautilusDirectory *directory,
{
current_file_unix_time = nautilus_file_get_atime (file);
}
- else
+ else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
{
current_file_unix_time = nautilus_file_get_mtime (file);
}
+ else
+ {
+ current_file_unix_time = nautilus_file_get_btime (file);
+ }
found = nautilus_file_date_in_between (current_file_unix_time,
initial_date,
diff --git a/src/nautilus-search-engine-recent.c b/src/nautilus-search-engine-recent.c
index bc2ad84f0..6082e4a1a 100644
--- a/src/nautilus-search-engine-recent.c
+++ b/src/nautilus-search-engine-recent.c
@@ -294,8 +294,15 @@ recent_thread_func (gpointer user_data)
initial_date = g_ptr_array_index (date_range, 0);
end_date = g_ptr_array_index (date_range, 1);
type = nautilus_query_get_search_type (self->query);
- target_time = (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS) ?
- visited : modified;
+
+ if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
+ {
+ target_time = visited;
+ }
+ else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
+ {
+ target_time = modified;
+ }
if (!nautilus_file_date_in_between (target_time,
initial_date, end_date))
diff --git a/src/nautilus-search-engine-simple.c b/src/nautilus-search-engine-simple.c
index 4264cfe7c..3ed02e016 100644
--- a/src/nautilus-search-engine-simple.c
+++ b/src/nautilus-search-engine-simple.c
@@ -277,6 +277,7 @@ send_batch_in_idle (SearchThreadData *thread_data)
G_FILE_ATTRIBUTE_STANDARD_TYPE "," \
G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
G_FILE_ATTRIBUTE_TIME_ACCESS "," \
+ G_FILE_ATTRIBUTE_TIME_CREATED "," \
G_FILE_ATTRIBUTE_ID_FILE
static void
@@ -296,6 +297,7 @@ visit_directory (GFile *dir,
gboolean visited;
guint64 atime;
guint64 mtime;
+ guint64 ctime;
GDateTime *initial_date;
GDateTime *end_date;
gchar *uri;
@@ -354,6 +356,7 @@ visit_directory (GFile *dir,
mtime = g_file_info_get_attribute_uint64 (info, "time::modified");
atime = g_file_info_get_attribute_uint64 (info, "time::access");
+ ctime = g_file_info_get_attribute_uint64 (info, "time::created");
if (found && date_range != NULL)
{
@@ -366,10 +369,14 @@ visit_directory (GFile *dir,
{
current_file_time = atime;
}
- else
+ else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
{
current_file_time = mtime;
}
+ else
+ {
+ current_file_time = ctime;
+ }
found = nautilus_file_date_in_between (current_file_time,
initial_date,
end_date);
diff --git a/src/nautilus-search-engine-tracker.c b/src/nautilus-search-engine-tracker.c
index a3e20b6dd..e0c2c8c8d 100644
--- a/src/nautilus-search-engine-tracker.c
+++ b/src/nautilus-search-engine-tracker.c
@@ -179,6 +179,7 @@ cursor_callback (GObject *object,
const char *uri;
const char *mtime_str;
const char *atime_str;
+ const char *ctime_str;
const gchar *snippet;
GTimeVal tv;
gdouble rank, match;
@@ -204,7 +205,8 @@ cursor_callback (GObject *object,
uri = tracker_sparql_cursor_get_string (cursor, 0, NULL);
rank = tracker_sparql_cursor_get_double (cursor, 1);
mtime_str = tracker_sparql_cursor_get_string (cursor, 2, NULL);
- atime_str = tracker_sparql_cursor_get_string (cursor, 3, NULL);
+ ctime_str = tracker_sparql_cursor_get_string (cursor, 3, NULL);
+ atime_str = tracker_sparql_cursor_get_string (cursor, 4, NULL);
basename = g_path_get_basename (uri);
hit = nautilus_search_hit_new (uri);
@@ -214,7 +216,7 @@ cursor_callback (GObject *object,
if (tracker->fts_enabled)
{
- snippet = tracker_sparql_cursor_get_string (cursor, 4, NULL);
+ snippet = tracker_sparql_cursor_get_string (cursor, 5, NULL);
nautilus_search_hit_set_fts_snippet (hit, snippet);
}
@@ -240,6 +242,17 @@ cursor_callback (GObject *object,
{
g_warning ("unable to parse atime: %s", atime_str);
}
+ if (g_time_val_from_iso8601 (ctime_str, &tv))
+ {
+ GDateTime *date;
+ date = g_date_time_new_from_timeval_local (&tv);
+ nautilus_search_hit_set_creation_time (hit, date);
+ g_date_time_unref (date);
+ }
+ else
+ {
+ g_warning ("unable to parse ctime: %s", ctime_str);
+ }
g_queue_push_head (tracker->hits_pending, hit);
check_pending_hits (tracker, FALSE);
@@ -339,6 +352,7 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
" ?url"
" xsd:double(COALESCE(?rank2, ?rank1)) AS ?rank"
" nfo:fileLastModified(?file)"
+ " nfo:fileCreated(?file)"
" nfo:fileLastAccessed(?file)");
if (tracker->fts_enabled && *search_text)
@@ -359,7 +373,8 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
" nfo:fileLastModified ?mtime;"
" nfo:fileLastAccessed ?atime;"
" nie:dataSource/tracker:available true;"
- " nie:url ?url.");
+ " nie:url ?url."
+ " OPTIONAL { ?file nfo:fileCreated ?ctime.}");
if (mimetypes->len > 0)
{
@@ -429,11 +444,16 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
g_string_append_printf (sparql, "?atime >= \"%s\"^^xsd:dateTime", initial_date_format);
g_string_append_printf (sparql, " && ?atime <= \"%s\"^^xsd:dateTime", end_date_format);
}
- else
+ else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
{
g_string_append_printf (sparql, "?mtime >= \"%s\"^^xsd:dateTime", initial_date_format);
g_string_append_printf (sparql, " && ?mtime <= \"%s\"^^xsd:dateTime", end_date_format);
}
+ else
+ {
+ g_string_append_printf (sparql, "?ctime >= \"%s\"^^xsd:dateTime", initial_date_format);
+ g_string_append_printf (sparql, " && ?ctime <= \"%s\"^^xsd:dateTime", end_date_format);
+ }
g_free (initial_date_format);
diff --git a/src/nautilus-search-hit.c b/src/nautilus-search-hit.c
index 4eb2e39d1..6efaa5613 100644
--- a/src/nautilus-search-hit.c
+++ b/src/nautilus-search-hit.c
@@ -35,6 +35,7 @@ struct _NautilusSearchHit
GDateTime *modification_time;
GDateTime *access_time;
+ GDateTime *creation_time;
gdouble fts_rank;
gchar *fts_snippet;
@@ -47,6 +48,7 @@ enum
PROP_RELEVANCE,
PROP_MODIFICATION_TIME,
PROP_ACCESS_TIME,
+ PROP_CREATION_TIME,
PROP_FTS_RANK,
PROP_FTS_SNIPPET,
NUM_PROPERTIES
@@ -217,6 +219,24 @@ nautilus_search_hit_set_access_time (NautilusSearchHit *hit,
}
}
+void
+nautilus_search_hit_set_creation_time (NautilusSearchHit *hit,
+ GDateTime *date)
+{
+ if (hit->creation_time != NULL)
+ {
+ g_date_time_unref (hit->creation_time);
+ }
+ if (date != NULL)
+ {
+ hit->creation_time = g_date_time_ref (date);
+ }
+ else
+ {
+ hit->creation_time = NULL;
+ }
+}
+
void
nautilus_search_hit_set_fts_snippet (NautilusSearchHit *hit,
const gchar *snippet)
@@ -268,6 +288,12 @@ nautilus_search_hit_set_property (GObject *object,
}
break;
+ case PROP_CREATION_TIME:
+ {
+ nautilus_search_hit_set_creation_time (hit, g_value_get_boxed (value));
+ }
+ break;
+
case PROP_FTS_SNIPPET:
{
g_free (hit->fts_snippet);
@@ -325,6 +351,12 @@ nautilus_search_hit_get_property (GObject *object,
}
break;
+ case PROP_CREATION_TIME:
+ {
+ g_value_set_boxed (value, hit->creation_time);
+ }
+ break;
+
case PROP_FTS_SNIPPET:
{
g_value_set_string (value, hit->fts_snippet);
@@ -354,6 +386,10 @@ nautilus_search_hit_finalize (GObject *object)
{
g_date_time_unref (hit->modification_time);
}
+ if (hit->creation_time != NULL)
+ {
+ g_date_time_unref (hit->creation_time);
+ }
g_free (hit->fts_snippet);
@@ -392,6 +428,14 @@ nautilus_search_hit_class_init (NautilusSearchHitClass *class)
"access time",
G_TYPE_DATE_TIME,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+ g_object_class_install_property (object_class,
+ PROP_CREATION_TIME,
+ g_param_spec_boxed ("creation-time",
+ "creation time",
+ "creation time",
+ G_TYPE_DATE_TIME,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_RELEVANCE,
g_param_spec_double ("relevance",
diff --git a/src/nautilus-search-hit.h b/src/nautilus-search-hit.h
index 33c7990f5..ec0746525 100644
--- a/src/nautilus-search-hit.h
+++ b/src/nautilus-search-hit.h
@@ -36,6 +36,8 @@ void nautilus_search_hit_set_modification_time (NautilusSearchHit
GDateTime *date);
void nautilus_search_hit_set_access_time (NautilusSearchHit *hit,
GDateTime *date);
+void nautilus_search_hit_set_creation_time (NautilusSearchHit *hit,
+ GDateTime *date);
void nautilus_search_hit_set_fts_snippet (NautilusSearchHit *hit,
const gchar *snippet);
void nautilus_search_hit_compute_scores (NautilusSearchHit *hit,
diff --git a/src/nautilus-search-popover.c b/src/nautilus-search-popover.c
index d823cdbb9..e81124910 100644
--- a/src/nautilus-search-popover.c
+++ b/src/nautilus-search-popover.c
@@ -45,6 +45,7 @@ struct _NautilusSearchPopover
GtkWidget *type_stack;
GtkWidget *last_used_button;
GtkWidget *last_modified_button;
+ GtkWidget *created_button;
GtkWidget *full_text_search_button;
GtkWidget *filename_search_button;
@@ -349,10 +350,14 @@ search_time_type_changed (GtkToggleButton *button,
{
type = NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED;
}
- else
+ else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (popover->last_used_button)))
{
type = NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS;
}
+ else
+ {
+ type = NAUTILUS_QUERY_SEARCH_TYPE_CREATED;
+ }
g_settings_set_enum (nautilus_preferences, "search-filter-time-type", type);
@@ -859,6 +864,7 @@ nautilus_search_popover_class_init (NautilusSearchPopoverClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, type_stack);
gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, last_used_button);
gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, last_modified_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, created_button);
gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, full_text_search_button);
gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, filename_search_button);
@@ -905,11 +911,19 @@ nautilus_search_popover_init (NautilusSearchPopover *self)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_modified_button), TRUE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_used_button), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->created_button), FALSE);
}
- else
+ else if (filter_time_type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_modified_button), FALSE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_used_button), TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->created_button), FALSE);
+ }
+ else
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_modified_button), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_used_button), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->created_button), TRUE);
}
self->fts_enabled = g_settings_get_boolean (nautilus_preferences,
diff --git a/src/resources/ui/nautilus-search-popover.ui b/src/resources/ui/nautilus-search-popover.ui
index ca0919fb4..8557d5391 100644
--- a/src/resources/ui/nautilus-search-popover.ui
+++ b/src/resources/ui/nautilus-search-popover.ui
@@ -216,10 +216,27 @@
<signal name="toggled" handler="search_time_type_changed" object="NautilusSearchPopover"
swapped="no" />
</object>
<packing>
- <property name="left_attach">1</property>
- <property name="top_attach">2</property>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
</packing>
</child>
+ <child>
+ <object class="GtkRadioButton" id="created_button">
+ <property name="label" translatable="yes">Created</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">False</property>
+ <property name="use-underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw-indicator">True</property>
+ <property name="group">last_modified_button</property>
+ <signal name="toggled" handler="search_time_type_changed"
object="NautilusSearchPopover" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">4</property>
+ </packing>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]