Skip to content
Permalink
Browse files

Fixed the value of 6 month and 1 year.

  • Loading branch information...
yetist authored and lukefromdc committed Jan 26, 2019
1 parent 3a22d4c commit 0a37810676a9ca7fbae5fe2f5fb8256846085c5a
@@ -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)
@@ -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);
@@ -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;
}
}
@@ -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)

0 comments on commit 0a37810

Please sign in to comment.
You can’t perform that action at this time.