diff options
author | Wu Xiaotian <[email protected]> | 2019-01-26 10:13:23 +0800 |
---|---|---|
committer | lukefromdc <[email protected]> | 2019-01-28 22:24:13 +0000 |
commit | 0a37810676a9ca7fbae5fe2f5fb8256846085c5a (patch) | |
tree | 0b7b9a5559d507719b5ec79597a0ceefff33fed2 | |
parent | 3a22d4c63d42009024830f494fe0ec3679382631 (diff) | |
download | caja-0a37810676a9ca7fbae5fe2f5fb8256846085c5a.tar.bz2 caja-0a37810676a9ca7fbae5fe2f5fb8256846085c5a.tar.xz |
Fixed the value of 6 month and 1 year.
-rw-r--r-- | libcaja-private/caja-query.c | 18 | ||||
-rw-r--r-- | libcaja-private/caja-query.h | 4 | ||||
-rw-r--r-- | libcaja-private/caja-search-engine-simple.c | 17 | ||||
-rw-r--r-- | src/caja-query-editor.c | 58 |
4 files changed, 67 insertions, 30 deletions
diff --git a/libcaja-private/caja-query.c b/libcaja-private/caja-query.c index 465e5a45..dd0384f0 100644 --- a/libcaja-private/caja-query.c +++ b/libcaja-private/caja-query.c @@ -36,7 +36,7 @@ struct CajaQueryDetails char *location_uri; GList *mime_types; GList *tags; - gint64 duration; + gint64 timestamp; gint64 size; }; @@ -77,7 +77,7 @@ static void caja_query_init (CajaQuery *query) { query->details = g_new0 (CajaQueryDetails, 1); - query->details->duration = 0; + query->details->timestamp = 0; query->details->size = 0; } @@ -383,7 +383,7 @@ caja_query_to_xml (CajaQuery *query) char *mimetype; char *tag; GList *l; - gint64 duration; + gint64 timestamp; gint64 size; xml = g_string_new (""); @@ -426,10 +426,10 @@ caja_query_to_xml (CajaQuery *query) g_string_append (xml, " </tags>\n"); } - if (query->details->duration != 0) + if (query->details->timestamp != 0) { g_string_append_printf(xml, " <duration>%ld</duration>", - query->details->duration); + query->details->timestamp); } if (query->details->size != 0) @@ -463,14 +463,14 @@ caja_query_save (CajaQuery *query, char *file) return res; } -void caja_query_set_duration(CajaQuery *query, gint64 sec) +void caja_query_set_timestamp(CajaQuery *query, gint64 sec) { - query->details->duration = sec; + query->details->timestamp = sec; } -gint64 caja_query_get_duration(CajaQuery *query) +gint64 caja_query_get_timestamp(CajaQuery *query) { - return query->details->duration; + return query->details->timestamp; } void caja_query_set_size(CajaQuery *query, gint64 size) diff --git a/libcaja-private/caja-query.h b/libcaja-private/caja-query.h index b4c5c035..a1ec2864 100644 --- a/libcaja-private/caja-query.h +++ b/libcaja-private/caja-query.h @@ -69,8 +69,8 @@ char * caja_query_to_readable_string (CajaQuery *query); CajaQuery * caja_query_load (char *file); gboolean caja_query_save (CajaQuery *query, char *file); -gint64 caja_query_get_duration (CajaQuery *query); -void caja_query_set_duration (CajaQuery *query, gint64 sec); +gint64 caja_query_get_timestamp (CajaQuery *query); +void caja_query_set_timestamp (CajaQuery *query, gint64 sec); gint64 caja_query_get_size (CajaQuery *query); void caja_query_set_size (CajaQuery *query, gint64 size); diff --git a/libcaja-private/caja-search-engine-simple.c b/libcaja-private/caja-search-engine-simple.c index 09ac0a03..9e6084a7 100644 --- a/libcaja-private/caja-search-engine-simple.c +++ b/libcaja-private/caja-search-engine-simple.c @@ -48,7 +48,7 @@ typedef struct gint n_processed_files; GList *uri_hits; - gint64 duration; + gint64 timestamp; gint64 size; } SearchThreadData; @@ -126,7 +126,7 @@ search_thread_data_new (CajaSearchEngineSimple *engine, data->tags = caja_query_get_tags (query); data->mime_types = caja_query_get_mime_types (query); - data->duration = caja_query_get_duration (query); + data->timestamp = caja_query_get_timestamp (query); data->size = caja_query_get_size (query); data->cancellable = g_cancellable_new (); @@ -355,7 +355,6 @@ visit_directory (GFile *dir, SearchThreadData *data) const char *id; gboolean visited; GTimeVal result; - time_t timestamp; gchar *attributes; GString *attr_string; @@ -366,7 +365,7 @@ visit_directory (GFile *dir, SearchThreadData *data) if (data->tags != NULL) { g_string_append (attr_string, "," G_FILE_ATTRIBUTE_XATTR_XDG_TAGS); } - if (data->duration != 0) { + if (data->timestamp != 0) { g_string_append (attr_string, "," G_FILE_ATTRIBUTE_TIME_MODIFIED "," G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC); } @@ -384,8 +383,6 @@ visit_directory (GFile *dir, SearchThreadData *data) return; } - timestamp = time(NULL); - while ((info = g_file_enumerator_next_file (enumerator, data->cancellable, NULL)) != NULL) { if (g_file_info_get_is_hidden (info)) @@ -434,13 +431,13 @@ visit_directory (GFile *dir, SearchThreadData *data) hit = file_has_all_tags (info, data->tags); } - if (hit && data->duration != 0) { + if (hit && data->timestamp != 0) { g_file_info_get_modification_time (info, &result); - if (data->duration > 0) { - if (timestamp - result.tv_sec < data->duration) + if (data->timestamp > 0) { + if (data->timestamp < result.tv_sec) hit = FALSE; } else { - if (timestamp - result.tv_sec > ABS(data->duration)) + if (result.tv_sec < ABS(data->timestamp)) hit = FALSE; } } diff --git a/src/caja-query-editor.c b/src/caja-query-editor.c index fc25b104..355c8e09 100644 --- a/src/caja-query-editor.c +++ b/src/caja-query-editor.c @@ -35,6 +35,17 @@ #include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> +enum +{ + DURATION_INVALID, + DURATION_ONE_HOUR, + DURATION_ONE_DAY, + DURATION_ONE_WEEK, + DURATION_ONE_MONTH, + DURATION_SIX_MONTHS, + DURATION_ONE_YEAR, +}; + typedef enum { CAJA_QUERY_EDITOR_ROW_LOCATION, @@ -1054,7 +1065,7 @@ static GtkWidget *modtime_row_create_widgets(CajaQueryEditorRow *row) gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); - duration_store = gtk_list_store_new(2, G_TYPE_LONG, G_TYPE_STRING); + duration_store = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING); duration_combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(duration_store)); g_object_unref(duration_store); @@ -1063,17 +1074,17 @@ static GtkWidget *modtime_row_create_widgets(CajaQueryEditorRow *row) "text", 1, NULL); gtk_list_store_append(duration_store, &iter); - gtk_list_store_set(duration_store, &iter, 0, 3600, 1, _("1 Hour"), -1); + gtk_list_store_set(duration_store, &iter, 0, DURATION_ONE_HOUR, 1, _("1 Hour"), -1); gtk_list_store_append(duration_store, &iter); - gtk_list_store_set(duration_store, &iter, 0, 86400, 1, _("1 Day"), -1); + gtk_list_store_set(duration_store, &iter, 0, DURATION_ONE_DAY, 1, _("1 Day"), -1); gtk_list_store_append(duration_store, &iter); - gtk_list_store_set(duration_store, &iter, 0, 604800, 1, _("1 Week"), -1); + gtk_list_store_set(duration_store, &iter, 0, DURATION_ONE_WEEK, 1, _("1 Week"), -1); gtk_list_store_append(duration_store, &iter); - gtk_list_store_set(duration_store, &iter, 0, 2419200, 1, _("1 Month"), -1); + gtk_list_store_set(duration_store, &iter, 0, DURATION_ONE_MONTH, 1, _("1 Month"), -1); gtk_list_store_append(duration_store, &iter); - gtk_list_store_set(duration_store, &iter, 0, 14515200, 1, _("6 Months"), -1); + gtk_list_store_set(duration_store, &iter, 0, DURATION_SIX_MONTHS, 1, _("6 Months"), -1); gtk_list_store_append(duration_store, &iter); - gtk_list_store_set(duration_store, &iter, 0, 29030400, 1, _("1 Year"), -1); + gtk_list_store_set(duration_store, &iter, 0, DURATION_ONE_YEAR, 1, _("1 Year"), -1); gtk_combo_box_set_active(GTK_COMBO_BOX(duration_combo), 0); @@ -1096,7 +1107,9 @@ static void modtime_row_add_to_query(CajaQueryEditorRow *row, CajaQuery *query) GtkTreeIter iter; GtkTreeIter duration_iter; gboolean is_greater = FALSE; - gint64 duration; + GDateTime *now, *datetime; + gint duration; + gint64 timestamp; if (!GTK_IS_CONTAINER(row->type_widget)) return; @@ -1121,7 +1134,34 @@ static void modtime_row_add_to_query(CajaQueryEditorRow *row, CajaQuery *query) duration_model = gtk_combo_box_get_model(GTK_COMBO_BOX(duration_combo)); gtk_tree_model_get(duration_model, &duration_iter, 0, &duration, -1); - caja_query_set_duration(query, is_greater ? duration : -duration); + now = g_date_time_new_now_local (); + switch (duration) + { + case DURATION_ONE_HOUR: + datetime = g_date_time_add_hours (now, -1); + break; + case DURATION_ONE_DAY: + datetime = g_date_time_add_days (now, -1); + break; + case DURATION_ONE_WEEK: + datetime = g_date_time_add_weeks (now, -1); + break; + case DURATION_ONE_MONTH: + datetime = g_date_time_add_months (now, -1); + break; + case DURATION_SIX_MONTHS: + datetime = g_date_time_add_months (now, -6); + break; + case DURATION_ONE_YEAR: + datetime = g_date_time_add_years (now, -1); + break; + } + + g_date_time_unref (now); + timestamp = g_date_time_to_unix (datetime); + g_date_time_unref (datetime); + + caja_query_set_timestamp(query, is_greater ? timestamp: -timestamp); } static void modtime_row_free_data(CajaQueryEditorRow *row) |