timeformat.diff
author Myhailo Danylenko <isbear@ukrpost.net>
Sat, 07 Nov 2015 17:39:49 +0200
changeset 88 0a87df8ad9c1
parent 87 78238d26911a
child 92 66f7e2aa040c
permissions -rw-r--r--
Refresh queue for new mcabber

# HG changeset patch
# Parent 66f6d14c851bd0280966a8263ff4119588775620
[experimental] Allow user to modify time formatting

  * give user full control and full responsibility
  * add time_prefix = 3, that uses
    * time_format (normal prefix format string)
    * time_format_special (special prefix format string)
    * time_prefix_len (normal prefix width + 5)
  * fall back to 0, if any of these unset

diff -r 66f6d14c851b mcabber/mcabber/screen.c
--- a/mcabber/mcabber/screen.c	Tue Nov 11 23:42:00 2014 +0200
+++ b/mcabber/mcabber/screen.c	Tue Nov 11 23:43:05 2014 +0200
@@ -85,6 +85,7 @@
 static void scr_end_current_completion(void);
 static void scr_insert_text(const char*);
 static void scr_handle_tab(gboolean fwd);
+static unsigned int attention_sign(void);
 
 static void scr_glog_print(const gchar *log_domain, GLogLevelFlags log_level,
                            const gchar *message, gpointer user_data);
@@ -222,8 +223,6 @@
 
 /* Functions */
 
-static unsigned int attention_sign(void);
-
 static int find_color(const char *name)
 {
   int result;
@@ -875,38 +874,100 @@
 static const char *timeprefixes[] = {
   "%m-%d %H:%M ",
   "%H:%M ",
-  " "
+  " ",
+  NULL,
 };
 
 static const char *spectimeprefixes[] = {
   "%m-%d %H:%M:%S   ",
   "%H:%M:%S   ",
-  "   "
+  "   ",
+  NULL,
 };
 
 static int timepreflengths[] = {
   // (length of the corresponding timeprefix + 5)
   17,
   11,
-  6
+  6,
+  0,
 };
 
+/*
+static struct {
+  char format;
+  unsigned short len;
+} timeprefix_characters[] = {
+  { 'C', 2  },
+  { 'd', 2  },
+  { 'D', 10 },
+  { 'e', 2  },
+  { 'F', 10 },
+  { 'G', 4  },
+  { 'g', 2  },
+  { 'H', 2  },
+  { 'I', 2  },
+  { 'j', 3  },
+  { 'k', 2  },
+  { 'l', 2  },
+  { 'm', 2  },
+  { 'M', 2  },
+  { 'p', 2  }, // ? locale-dependent, can set LC_CTIME=C?
+  { 'P', 2  }, // ?
+  { 'R', 5  },
+  { 'S', 2  },
+  { 'T', 8  },
+  { 'u', 1  },
+  { 'U', 2  },
+  { 'V', 2  },
+  { 'w', 1  },
+  { 'W', 2  },
+  { 'y', 2  },
+  { 'Y', 4  },
+  { 'z', 5  },
+  { '%', 1  },
+  { '\0', 0 }, // end marker
+};
+*/
+
+static guint gettprefixnum (void)
+{
+  guint n = settings_opt_get_int ("time_prefix");
+  static gboolean initialized = FALSE;
+  if (n < 3)
+    return n;
+  if (n > 3)
+    return 0;
+  if (!initialized) {
+    const char *tp  = settings_opt_get ("time_format");
+    const char *stp = settings_opt_get ("time_format_special");
+    guint       tpl = settings_opt_get_int ("time_prefix_len");
+    if (!tp || !*tp || !stp || !*stp || tpl < 6) {
+      tp  = timeprefixes[0];
+      stp = spectimeprefixes[0];
+      tpl = timepreflengths[0];
+    }
+    timeprefixes[3]     = g_strdup (tp);
+    spectimeprefixes[3] = g_strdup (stp);
+    timepreflengths[3]  = tpl;
+    initialized = TRUE;
+  }
+  return 3;
+}
+
 static const char *gettprefix(void)
 {
-  guint n = settings_opt_get_int("time_prefix");
-  return timeprefixes[(n < 3 ? n : 0)];
+  return timeprefixes[gettprefixnum()];
 }
 
 static const char *getspectprefix(void)
 {
-  guint n = settings_opt_get_int("time_prefix");
-  return spectimeprefixes[(n < 3 ? n : 0)];
+  return spectimeprefixes[gettprefixnum()];
 }
 
 guint scr_getprefixwidth(void)
 {
-  guint n = settings_opt_get_int("time_prefix");
-  return timepreflengths[(n < 3 ? n : 0)];
+  return timepreflengths[gettprefixnum()];
 }
 
 guint scr_gettextwidth(void)