diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | ChangeLog.ja | 7 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | libsylph/utils.c | 17 | ||||
-rw-r--r-- | libsylph/utils.h | 3 | ||||
-rw-r--r-- | src/main.c | 96 |
6 files changed, 130 insertions, 1 deletions
@@ -1,5 +1,11 @@ 2005-10-11 + * libsylph/utils.[ch] + src/main.c: output g_log() messages to the log window and log file. + * configure.in: disabled console window on win32. + +2005-10-11 + * src/folderview.c: folderview_drag_motion_cb(): win32: reset context->actions if modifier key is not pressed (fixed DnD action becoming copy by default). diff --git a/ChangeLog.ja b/ChangeLog.ja index 50b73340..fb0a0b4b 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,5 +1,12 @@ 2005-10-11 + * libsylph/utils.[ch] + src/main.c: g_log() メッセージをログウィンドウとログファイルに + 出力するようにした。 + * configure.in: win32 でコンソールウィンドウを無効にした。 + +2005-10-11 + * src/folderview.c: folderview_drag_motion_cb(): win32: 修飾キーが 押されていなかったら context->actions をリセットするようにした (DnD のアクションがデフォルトでコピーになるのを修正)。 diff --git a/configure.in b/configure.in index 2e66c3b0..0a4f3a3a 100644 --- a/configure.in +++ b/configure.in @@ -61,7 +61,7 @@ case "$target" in ;; *-*-mingw*) native_win32=yes - CFLAGS="$CFLAGS -mms-bitfields" + CFLAGS="$CFLAGS -mms-bitfields -mwindows" LIBS="$LIBS -lws2_32" ;; esac diff --git a/libsylph/utils.c b/libsylph/utils.c index 0ddae386..579edee7 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -3402,6 +3402,23 @@ void status_print(const gchar *format, ...) #define TIME_LEN 11 +void log_write(const gchar *str, const gchar *prefix) +{ + if (log_fp) { + gchar buf[TIME_LEN + 1]; + time_t t; + + time(&t); + strftime(buf, TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t)); + + fputs(buf, log_fp); + if (prefix) + fputs(prefix, log_fp); + fputs(str, log_fp); + fflush(log_fp); + } +} + void log_print(const gchar *format, ...) { va_list args; diff --git a/libsylph/utils.h b/libsylph/utils.h index 7796541b..311525b0 100644 --- a/libsylph/utils.h +++ b/libsylph/utils.h @@ -476,6 +476,9 @@ void set_log_show_status_func (LogFunc status_func); void debug_print (const gchar *format, ...) G_GNUC_PRINTF(1, 2); void status_print (const gchar *format, ...) G_GNUC_PRINTF(1, 2); +void log_write (const gchar *str, + const gchar *prefix); + void log_print (const gchar *format, ...) G_GNUC_PRINTF(1, 2); void log_message (const gchar *format, ...) G_GNUC_PRINTF(1, 2); void log_warning (const gchar *format, ...) G_GNUC_PRINTF(1, 2); @@ -72,6 +72,7 @@ #include "addressbook.h" #include "addrindex.h" #include "compose.h" +#include "logwindow.h" #include "folder.h" #include "setup.h" #include "utils.h" @@ -114,6 +115,7 @@ static void app_init (void); static void parse_gtkrc_files (void); static void setup_rc_dir (void); static void check_gpg (void); +static void set_log_handlers (gboolean enable); static gchar *get_socket_name (void); static gint prohibit_duplicate_launch (void); @@ -228,6 +230,8 @@ int main(int argc, char *argv[]) mainwin); #endif + set_log_handlers(TRUE); + account_read_config_all(); account_set_menu(); main_window_reflect_prefs_all(); @@ -553,6 +557,7 @@ void app_will_exit(GtkWidget *widget, gpointer data) remove_all_files(get_tmp_dir()); remove_all_files(get_mime_tmp_dir()); + set_log_handlers(FALSE); close_log_file(); lock_socket_remove(); @@ -623,6 +628,97 @@ static void check_gpg(void) #endif } +static void default_log_func(const gchar *log_domain, GLogLevelFlags log_level, + const gchar *message, gpointer user_data) +{ + gchar *prefix = ""; + gchar *file_prefix = ""; + LogType level = LOG_NORMAL; + gchar *str; + const gchar *message_; + + switch (log_level) { + case G_LOG_LEVEL_ERROR: + prefix = "ERROR"; + file_prefix = "*** "; + level = LOG_ERROR; + break; + case G_LOG_LEVEL_CRITICAL: + case G_LOG_LEVEL_WARNING: + prefix = "CRITICAL"; + file_prefix = "** "; + level = LOG_WARN; + break; + case G_LOG_LEVEL_MESSAGE: + prefix = "Message"; + file_prefix = "* "; + level = LOG_MSG; + break; + case G_LOG_LEVEL_INFO: + prefix = "INFO"; + file_prefix = "* "; + level = LOG_MSG; + break; + case G_LOG_LEVEL_DEBUG: + prefix = "DEBUG"; + break; + default: + prefix = "LOG"; + break; + } + + if (!message) + message_ = "(NULL) message"; + else + message_ = message; + if (log_domain) + str = g_strconcat(log_domain, "-", prefix, ": ", message_, "\n", + NULL); + else + str = g_strconcat(prefix, ": ", message_, "\n", NULL); + log_window_append(str, level); + log_write(str, file_prefix); + g_free(str); + + g_log_default_handler(log_domain, log_level, message, user_data); +} + +static void set_log_handlers(gboolean enable) +{ +#if GLIB_CHECK_VERSION(2, 6, 0) + if (enable) + g_log_set_default_handler(default_log_func, NULL); + else + g_log_set_default_handler(g_log_default_handler, NULL); +#else + static guint handler_id[4] = {0, 0, 0, 0}; + + if (enable) { + handler_id[0] = g_log_set_handler + ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL + | G_LOG_FLAG_RECURSION, default_log_func, NULL); + handler_id[1] = g_log_set_handler + ("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL + | G_LOG_FLAG_RECURSION, default_log_func, NULL); + handler_id[2] = g_log_set_handler + ("LibSylph", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL + | G_LOG_FLAG_RECURSION, default_log_func, NULL); + handler_id[3] = g_log_set_handler + ("Sylpheed", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL + | G_LOG_FLAG_RECURSION, default_log_func, NULL); + } else { + g_log_remove_handler("GLib", handler_id[0]); + g_log_remove_handler("Gtk", handler_id[1]); + g_log_remove_handler("LibSylph", handler_id[2]); + g_log_remove_handler("Sylpheed", handler_id[3]); + handler_id[0] = 0; + handler_id[1] = 0; + handler_id[2] = 0; + handler_id[3] = 0; + } +#endif +} + static gchar *get_socket_name(void) { static gchar *filename = NULL; |