Revision: 820 http://svn.sourceforge.net/geany/?rev=820&view=rev Author: ntrel Date: 2006-09-17 13:40:15 -0700 (Sun, 17 Sep 2006)
Log Message: ----------- Improve utils_get_current_time_string().
Modified Paths: -------------- trunk/ChangeLog trunk/src/msgwindow.c trunk/src/utils.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-09-17 19:58:04 UTC (rev 819) +++ trunk/ChangeLog 2006-09-17 20:40:15 UTC (rev 820) @@ -3,6 +3,8 @@ * src/templates.h, src/templates.c: Move all static strings from templates.h to templates.c. * src/sci_cb.c: Fix sign comparison warning. + * src/utils.c, src/msgwindow.c: + Improve utils_get_current_time_string().
2006-09-15 Nick Treleaven nick.treleaven@btinternet.com
Modified: trunk/src/msgwindow.c =================================================================== --- trunk/src/msgwindow.c 2006-09-17 19:58:04 UTC (rev 819) +++ trunk/src/msgwindow.c 2006-09-17 20:40:15 UTC (rev 820) @@ -244,10 +244,6 @@ // display status message in status bar ui_set_statusbar(string, FALSE);
- gtk_list_store_append(msgwindow.store_status, &iter); - //gtk_list_store_insert(msgwindow.store_status, &iter, 0); - //gtk_list_store_set(msgwindow.store_status, &iter, 0, (state > 0) ? &white : &dark, 1, string, -1); - // add a timestamp to status messages time_str = utils_get_current_time_string(); if (time_str == NULL) @@ -256,6 +252,8 @@ statusmsg = g_strconcat(time_str, ": ", string, NULL); g_free(time_str);
+ // add message to Status window + gtk_list_store_append(msgwindow.store_status, &iter); gtk_list_store_set(msgwindow.store_status, &iter, 0, ((state++ % 2) == 0) ? &white : &dark, 1, statusmsg, -1); g_free(statusmsg);
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2006-09-17 19:58:04 UTC (rev 819) +++ trunk/src/utils.c 2006-09-17 20:40:15 UTC (rev 820) @@ -1231,21 +1231,15 @@ }
-// returned string must be freed. +// Returns: new string with the current time formatted HH:MM:SS. gchar *utils_get_current_time_string() { - GTimeVal cur_time; - gchar *date_str, *time_str, *result; - gchar **strv; + const time_t tp = time(NULL); + const struct tm *tmval = localtime(&tp); + gchar *result = g_malloc0(9);
- g_get_current_time(&cur_time); - date_str = ctime(&cur_time.tv_sec); //uses internal string buffer - strv = g_strsplit(date_str, " ", 6); - - // if single digit day then strv[2] will be empty - time_str = (*strv[2] == 0) ? strv[4] : strv[3]; - result = g_strdup(time_str); - g_strfreev(strv); + strftime(result, 9, "%T", tmval); + result[8] = '\0'; return result; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.