changeset 464:e4840b288be0

Add "/buffer date"
author Mikael Berthe <mikael@lilotux.net>
date Thu, 29 Sep 2005 22:31:56 +0200
parents 339e85418b49
children 52171a3dc199
files mcabber/src/commands.c mcabber/src/hbuf.c mcabber/src/hbuf.h mcabber/src/screen.c mcabber/src/screen.h
diffstat 5 files changed, 61 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Thu Sep 29 22:03:22 2005 +0200
+++ b/mcabber/src/commands.c	Thu Sep 29 22:31:56 2005 +0200
@@ -136,6 +136,7 @@
   compl_add_category_word(COMPL_BUFFER, "top");
   compl_add_category_word(COMPL_BUFFER, "search_backward");
   compl_add_category_word(COMPL_BUFFER, "search_forward");
+  compl_add_category_word(COMPL_BUFFER, "date");
   compl_add_category_word(COMPL_BUFFER, "%");
 
   // Group category
@@ -660,6 +661,22 @@
       search_dir = 1;
     else
       scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter");
+  } else if (!strncasecmp(arg, "date", 4)) {
+    arg += 4;
+    if (*arg++ != ' ') {
+      scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter");
+      return;
+    }
+    while (*arg == ' ') arg++;
+    if (*arg) {
+      time_t t = from_iso8601(arg, 0);
+      if (t)
+        scr_BufferDate(t);
+      else
+        scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter");
+    }
+    else
+      scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter");
   } else if (*arg == '%') {
     arg++;
     while (*arg == ' ') arg++;
--- a/mcabber/src/hbuf.c	Thu Sep 29 22:03:22 2005 +0200
+++ b/mcabber/src/hbuf.c	Thu Sep 29 22:31:56 2005 +0200
@@ -296,6 +296,22 @@
   return hbuf;
 }
 
+//  hbuf_jump_date(hbuf, t)
+// Return a pointer to the first line after date t in the history buffer
+GList *hbuf_jump_date(GList *hbuf, time_t t)
+{
+  hbuf_block *blk;
+
+  hbuf = g_list_first(hbuf);
+
+  for ( ; hbuf && g_list_next(hbuf); hbuf = g_list_next(hbuf)) {
+    blk = (hbuf_block*)(hbuf->data);
+    if (blk->prefix.timestamp >= t) break;
+  }
+
+  return hbuf;
+}
+
 //  hbuf_jump_percent(hbuf, pc)
 // Return a pointer to the line at % pc of the history buffer
 GList *hbuf_jump_percent(GList *hbuf, int pc)
--- a/mcabber/src/hbuf.h	Thu Sep 29 22:03:22 2005 +0200
+++ b/mcabber/src/hbuf.h	Thu Sep 29 22:31:56 2005 +0200
@@ -35,6 +35,7 @@
 
 hbb_line **hbuf_get_lines(GList *hbuf, unsigned int n);
 GList *hbuf_search(GList *hbuf, int direction, const char *string);
+GList *hbuf_jump_date(GList *hbuf, time_t t);
 GList *hbuf_jump_percent(GList *hbuf, int pc);
 
 #endif /* __HBUF_H__ */
--- a/mcabber/src/screen.c	Thu Sep 29 22:03:22 2005 +0200
+++ b/mcabber/src/screen.c	Thu Sep 29 22:31:56 2005 +0200
@@ -1123,6 +1123,32 @@
   doupdate();
 }
 
+//  scr_BufferDate(t)
+// Jump to the first line after date t in the buffer
+// t is a date in seconds since `00:00:00 1970-01-01 UTC'
+void scr_BufferDate(time_t t)
+{
+  window_entry_t *win_entry;
+  GList *search_res;
+
+  // Get win_entry
+  if (!current_buddy) return;
+  win_entry  = scr_SearchWindow(CURRENT_JID);
+  if (!win_entry) return;
+
+  search_res = hbuf_jump_date(win_entry->hbuf, t);
+
+  win_entry->cleared = FALSE;
+  win_entry->top = search_res;
+
+  // Refresh the window
+  scr_UpdateWindow(win_entry);
+
+  // Finished :)
+  update_panels();
+  doupdate();
+}
+
 //  scr_set_chatmode()
 // Public function to (un)set chatmode...
 inline void scr_set_chatmode(int enable)
--- a/mcabber/src/screen.h	Thu Sep 29 22:03:22 2005 +0200
+++ b/mcabber/src/screen.h	Thu Sep 29 22:31:56 2005 +0200
@@ -55,6 +55,7 @@
 void scr_BufferClear(void);
 void scr_BufferSearch(int direction, const char *text);
 void scr_BufferPercent(int pc);
+void scr_BufferDate(time_t t);
 void scr_RosterUnreadMessage(int);
 void scr_RosterJumpAlternate(void);