1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Tidied chat_log module

This commit is contained in:
James Booth 2012-09-05 17:41:35 +01:00
parent 3edd75af75
commit c343ff410c
2 changed files with 10 additions and 8 deletions

View File

@ -37,14 +37,14 @@ static void _close_file(gpointer key, gpointer value, gpointer user_data);
void void
chat_log_init(void) chat_log_init(void)
{ {
log_msg(PROF_LEVEL_INFO, "prof", "Initialising chat logs"); log_info("Initialising chat logs");
tz = g_time_zone_new_local(); tz = g_time_zone_new_local();
logs = g_hash_table_new(NULL, (GEqualFunc) g_strcmp0); logs = g_hash_table_new(NULL, (GEqualFunc) g_strcmp0);
} }
void void
chat_log_chat(const char * const login, char *other, chat_log_chat(const gchar * const login, gchar *other,
const char * const msg, chat_log_direction_t direction) const gchar * const msg, chat_log_direction_t direction)
{ {
gpointer logpp = g_hash_table_lookup(logs, other); gpointer logpp = g_hash_table_lookup(logs, other);
FILE *logp; FILE *logp;
@ -55,12 +55,12 @@ chat_log_chat(const char * const login, char *other,
g_string_append(log_file, "/.profanity/log"); g_string_append(log_file, "/.profanity/log");
create_dir(log_file->str); create_dir(log_file->str);
char *login_dir = str_replace(login, "@", "_at_"); gchar *login_dir = str_replace(login, "@", "_at_");
g_string_append_printf(log_file, "/%s", login_dir); g_string_append_printf(log_file, "/%s", login_dir);
create_dir(log_file->str); create_dir(log_file->str);
free(login_dir); free(login_dir);
char *other_file = str_replace(other, "@", "_at_"); gchar *other_file = str_replace(other, "@", "_at_");
g_string_append_printf(log_file, "/%s.log", other_file); g_string_append_printf(log_file, "/%s.log", other_file);
logp = fopen(log_file->str, "a"); logp = fopen(log_file->str, "a");
free(other_file); free(other_file);
@ -87,7 +87,7 @@ chat_log_chat(const char * const login, char *other,
void void
chat_log_close(void) chat_log_close(void)
{ {
log_msg(PROF_LEVEL_INFO, "prof", "Closing down chat logs"); log_info("Closing down chat logs");
g_hash_table_foreach(logs, (GHFunc) _close_file, NULL); g_hash_table_foreach(logs, (GHFunc) _close_file, NULL);
g_time_zone_unref(tz); g_time_zone_unref(tz);
} }

View File

@ -23,14 +23,16 @@
#ifndef CHAT_LOG_H #ifndef CHAT_LOG_H
#define CHAT_LOG_H #define CHAT_LOG_H
#include <glib.h>
typedef enum { typedef enum {
IN, IN,
OUT OUT
} chat_log_direction_t; } chat_log_direction_t;
void chat_log_init(void); void chat_log_init(void);
void chat_log_chat(const char * const login, char *other, void chat_log_chat(const gchar * const login, gchar *other,
const char * const msg, chat_log_direction_t direction); const gchar * const msg, chat_log_direction_t direction);
void chat_log_close(void); void chat_log_close(void);
#endif #endif