about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-10-14 17:23:38 +0100
committerJames Booth <boothj5@gmail.com>2012-10-14 17:23:38 +0100
commitc4fd08c430f937d66d86f783be387c15e414ebd2 (patch)
tree82b50c868d3c39528fb0516f32f1b656d002af7d /src
parent31295005283ecc1aee7dbc72c90c915b8c71c090 (diff)
downloadprofani-tty-c4fd08c430f937d66d86f783be387c15e414ebd2.tar.gz
Show history from day that session started
Diffstat (limited to 'src')
-rw-r--r--src/chat_log.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/src/chat_log.c b/src/chat_log.c
index 2a68c547..ce044aaf 100644
--- a/src/chat_log.c
+++ b/src/chat_log.c
@@ -97,41 +97,49 @@ GSList *
 chat_log_get_previous(const gchar * const login, gchar *recipient, 
     GSList *history)
 {
+    GTimeZone *tz = g_time_zone_new_local();
+    
     GDateTime *now = g_date_time_new_now_local();
-    gint session_started_day = g_date_time_get_day_of_year(session_started);
-    gint day_now = g_date_time_get_day_of_year(now);
-
-    // session started today
-    if (day_now == session_started_day) {
-        char *filename = _get_log_filename(recipient, login, now);
-        
+    GDateTime *log_date = g_date_time_new(tz, 
+        g_date_time_get_year(session_started),
+        g_date_time_get_month(session_started), 
+        g_date_time_get_day_of_month(session_started),
+        g_date_time_get_hour(session_started),
+        g_date_time_get_minute(session_started),
+        g_date_time_get_second(session_started));
+    
+    // get data from all logs from the day the session was started to today
+    while (g_date_time_get_day_of_year(log_date) <=  g_date_time_get_day_of_year(now)) {
+        char *filename = _get_log_filename(recipient, login, log_date);
+    
         FILE *logp = fopen(filename, "r");
         char *line = NULL;
         size_t read = 0;
         if (logp != NULL) {
             size_t length = getline(&line, &read, logp);
             while (length != -1) {
-                 char *copy = malloc(length);
-                 copy = strncpy(copy, line, length);
-                 copy[length -1] = '\0';
-                 history = g_slist_append(history, copy);
-                 free(line);
-                 line = NULL;
-                 read = 0;
-                 length = getline(&line, &read, logp);
+                char *copy = malloc(length);
+                copy = strncpy(copy, line, length);
+                copy[length -1] = '\0';
+                history = g_slist_append(history, copy);
+                free(line);
+                line = NULL;
+                read = 0;
+                length = getline(&line, &read, logp);
             }
+            
+            fclose(logp);
         }
         
         free(filename);
-        g_date_time_unref(now);
-        
-        return history;
-    
-    // session started before today
-    } else {
-        
-        return NULL;
+        GDateTime *next = g_date_time_add_days(log_date, 1);
+        g_date_time_unref(log_date);
+        log_date = g_date_time_ref(next);
     }
+
+    g_time_zone_unref(tz);
+
+    return history;
 }
 
 void