about summary refs log tree commit diff stats
path: root/src/chat_log.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-10-14 16:34:47 +0100
committerJames Booth <boothj5@gmail.com>2012-10-14 16:34:47 +0100
commit460b244048d9002b9fa9f3acd82998492cbfc93d (patch)
treef1b6784489e48956a9a9654b248e1d43c44d11d0 /src/chat_log.c
parent90164fc2c0dd675d64ea63a0ee812fac1538431d (diff)
downloadprofani-tty-460b244048d9002b9fa9f3acd82998492cbfc93d.tar.gz
Refactored chat_log.c
Diffstat (limited to 'src/chat_log.c')
-rw-r--r--src/chat_log.c78
1 files changed, 31 insertions, 47 deletions
diff --git a/src/chat_log.c b/src/chat_log.c
index ea19a594..45daaeec 100644
--- a/src/chat_log.c
+++ b/src/chat_log.c
@@ -130,59 +130,17 @@ chat_log_close(void)
     g_date_time_unref(started);
 }
 
-static char *
-_get_log_filename(char *other, const char * const login, GDateTime *dt)
-{
-    GString *log_file = g_string_new(getenv("HOME"));
-    g_string_append(log_file, "/.profanity/log");
-    create_dir(log_file->str);
-
-    gchar *login_dir = str_replace(login, "@", "_at_");
-    g_string_append_printf(log_file, "/%s", login_dir);
-    create_dir(log_file->str);
-    free(login_dir);
-
-    gchar *other_file = str_replace(other, "@", "_at_");
-    g_string_append_printf(log_file, "/%s", other_file);
-    create_dir(log_file->str);
-    free(other_file);
-
-    gchar *date = g_date_time_format(dt, "/%Y_%m_%d.log");
-    g_string_append(log_file, date);
-
-    char *result = strdup(log_file->str);
-    g_string_free(log_file, TRUE);
-
-    return result;
-}
-
-
 static struct dated_chat_log *
 _create_log(char *other, const char * const login)
 {
-    GString *log_file = g_string_new(getenv("HOME"));
-    g_string_append(log_file, "/.profanity/log");
-    create_dir(log_file->str);
-
-    gchar *login_dir = str_replace(login, "@", "_at_");
-    g_string_append_printf(log_file, "/%s", login_dir);
-    create_dir(log_file->str);
-    free(login_dir);
-
-    gchar *other_file = str_replace(other, "@", "_at_");
-    g_string_append_printf(log_file, "/%s", other_file);
-    create_dir(log_file->str);
-    free(other_file);
-
-    GDateTime *dt = g_date_time_new_now_local();
-    gchar *date = g_date_time_format(dt, "/%Y_%m_%d.log");
-    g_string_append(log_file, date);
+    GDateTime *now = g_date_time_new_now_local();
+    char *filename = _get_log_filename(other, login, now);
 
     struct dated_chat_log *new_log = malloc(sizeof(struct dated_chat_log));
-    new_log->filename = strdup(log_file->str);
-    new_log->date = dt;
+    new_log->filename = strdup(filename);
+    new_log->date = now;
 
-    g_string_free(log_file, TRUE);
+    free(filename);
 
     return new_log;
 }
@@ -225,3 +183,29 @@ gboolean _key_equals(void *key1, void *key2)
     
     return (g_strcmp0(str1, str2) == 0);
 }
+
+static char *
+_get_log_filename(char *other, const char * const login, GDateTime *dt)
+{
+    GString *log_file = g_string_new(getenv("HOME"));
+    g_string_append(log_file, "/.profanity/log");
+    create_dir(log_file->str);
+
+    gchar *login_dir = str_replace(login, "@", "_at_");
+    g_string_append_printf(log_file, "/%s", login_dir);
+    create_dir(log_file->str);
+    free(login_dir);
+
+    gchar *other_file = str_replace(other, "@", "_at_");
+    g_string_append_printf(log_file, "/%s", other_file);
+    create_dir(log_file->str);
+    free(other_file);
+
+    gchar *date = g_date_time_format(dt, "/%Y_%m_%d.log");
+    g_string_append(log_file, date);
+
+    char *result = strdup(log_file->str);
+    g_string_free(log_file, TRUE);
+
+    return result;
+}