ayttm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Ayttm-commits] CVS: ayttm/src account.c,1.6,1.7 add_contact_window.h,1


From: Colin Leroy <address@hidden>
Subject: [Ayttm-commits] CVS: ayttm/src account.c,1.6,1.7 add_contact_window.h,1.3,1.4 chat_window.c,1.24,1.25 log_window.c,1.10,1.11 service.c,1.5,1.6 service.h,1.5,1.6 util.c,1.13,1.14 util.h,1.6,1.7
Date: Thu, 16 Jan 2003 12:28:28 -0500

Update of /cvsroot/ayttm/ayttm/src
In directory subversions:/tmp/cvs-serv31500/src

Modified Files:
        account.c add_contact_window.h chat_window.c log_window.c 
        service.c service.h util.c util.h 
Log Message:
Better log handling
- filename is now Group-Nick
- old logs will get renamed to the new format
- "concatenation" of two contacts within a single
  one will merge the two logs (without messing 
  with dates, though)


Index: account.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/account.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- account.c   16 Jan 2003 13:11:01 -0000      1.6
+++ account.c   16 Jan 2003 17:28:26 -0000      1.7
@@ -34,6 +34,7 @@
 #include "triggerdecls.h"
 #include "value_pair.h"
 #include "util.h"
+#include "add_contact_window.h"
 
 void write_account_list()
 {
@@ -162,7 +163,7 @@
        char buff2[1024];
        extern int contactparse();
        extern FILE * contactin;
-
+       GList *cts = NULL;
        g_snprintf(buff2, 1024, "%scontacts",config_dir);
 
        if(!(fp = fopen(buff2,"r")))
@@ -173,6 +174,21 @@
        contactparse();
 
        fclose(fp);
+       
+       /* rename logs from old format (contact->nick) to new 
+          (contact->nick "-" contact->group->name) */
+       cts = get_all_contacts();
+       for (; cts && cts->data; cts=cts->next) {
+               struct contact * c = (struct contact *)cts->data;
+               FILE *test = NULL;
+               char buff[255];
+               printf("contact:%s\n",c->nick);
+               make_safe_filename(buff, c->nick, c->group->name);
+               if ( (test = fopen(buff,"r")) != NULL)
+                       fclose(test);
+               else 
+                       rename_nick_log(NULL, c->nick, c->group->name, c->nick);
+       }
        return 1;
 }
 

Index: add_contact_window.h
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/add_contact_window.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- add_contact_window.h        16 Jan 2003 13:11:01 -0000      1.3
+++ add_contact_window.h        16 Jan 2003 17:28:26 -0000      1.4
@@ -38,4 +38,5 @@
 }
 #endif 
 GList * get_groups();
+GList * get_all_contacts();
 #endif

Index: chat_window.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/chat_window.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- chat_window.c       16 Jan 2003 13:11:01 -0000      1.24
+++ chat_window.c       16 Jan 2003 17:28:26 -0000      1.25
@@ -1765,7 +1765,7 @@
   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
   gtk_widget_show(hbox);
 
-  make_safe_filename(buff, remote->nick);
+  make_safe_filename(buff, remote->nick, remote->group->name);
 
   if ((cw->fp = fopen(buff, "a")) == NULL) 
     {
@@ -1886,7 +1886,7 @@
       if ( iGetLocalPref("do_restore_last_conv") )
       {
          gchar buff[NAME_MAX];
-         make_safe_filename(buff, remote_contact->nick);
+         make_safe_filename(buff, remote_contact->nick, 
remote_contact->group->name);
          eb_restore_last_conv(buff,remote_contact->chatwindow);
       }
    }
@@ -2033,7 +2033,7 @@
       if ( iGetLocalPref("do_restore_last_conv") )
       {
        gchar buff[NAME_MAX];
-       make_safe_filename (buff, remote_contact->nick);
+       make_safe_filename (buff, remote_contact->nick, 
remote_contact->group->name);
        eb_restore_last_conv (buff, remote_contact->chatwindow);
       }
       gdk_window_raise(remote_contact->chatwindow->window->window);
@@ -2083,7 +2083,7 @@
          if ( iGetLocalPref("do_restore_last_conv") ) 
            {
              gchar buff[NAME_MAX];
-             make_safe_filename(buff, remote_contact->nick);
+             make_safe_filename(buff, remote_contact->nick, 
remote_contact->group->name);
              eb_restore_last_conv(buff,remote_contact->chatwindow);    
            }
           gdk_window_raise(remote_contact->chatwindow->window->window);

Index: log_window.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/log_window.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- log_window.c        16 Jan 2003 13:11:01 -0000      1.10
+++ log_window.c        16 Jan 2003 17:28:26 -0000      1.11
@@ -109,15 +109,17 @@
   gchar* p3[1];
   GSList* gl = NULL, *gl1 = NULL;
   gint idx;
-
+  gboolean empty = TRUE;
+  
   gtk_clist_freeze(GTK_CLIST(lw->date_list)); /* freeze, thaw?  So corny. */
 
-  make_safe_filename(name_buffer, lw->remote->nick);
+  make_safe_filename(name_buffer, lw->remote->nick, lw->remote->group->name);
        
   if ( (fp = fopen(name_buffer, "r")) != NULL) {
     gl = g_slist_alloc();
 
     while (fgets(read_buffer, 4096, fp) != NULL) {
+      empty=FALSE;         
       if ((p1 = strstr(read_buffer, _("Conversation started on "))) != NULL) 
          {
 
@@ -171,6 +173,10 @@
     perror(name_buffer);
   }
 
+  if (empty) {
+    p3[0]=_("No log available");
+    gtk_clist_append(GTK_CLIST(lw->date_list), p3);
+  }      
   lw->entries = gl;
 
   gtk_clist_thaw(GTK_CLIST(lw->date_list));

Index: service.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/service.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- service.c   16 Jan 2003 13:11:01 -0000      1.5
+++ service.c   16 Jan 2003 17:28:26 -0000      1.6
@@ -249,16 +249,35 @@
 #endif
 }
 
-//FIXME: Don't blow away an existing log
-void rename_nick_log(char *oldnick, char *newnick)
+void rename_nick_log(char *oldgroup, char *oldnick, char *newgroup, char 
*newnick)
 {
-   gchar oldnicklog[255], newnicklog[255];
-   strcpy(oldnicklog, config_dir);
-   strcat(oldnicklog, "logs/");
-   strcpy(newnicklog, oldnicklog);
-   strcat(oldnicklog, oldnick);
-   strcat(newnicklog, newnick);
-   rename(oldnicklog, newnicklog);
-   printf("Renamed log from %s to %s\n", oldnicklog, newnicklog);
+   gchar oldnicklog[255], newnicklog[255], buff[255];
+   FILE *test = NULL;
+   make_safe_filename(buff, oldnick, oldgroup);
+   strcpy(oldnicklog, buff);
+
+   make_safe_filename(buff, newnick, newgroup);
+   strcpy(newnicklog, buff);
+   
+   if ((test = fopen(newnicklog,"r")) != NULL && 
strcmp(oldnicklog,newnicklog)) {
+          FILE *oldfile = fopen(oldnicklog,"r");
+          gchar read_buffer[4096];
+          
+          fclose(test);
+          test = fopen(newnicklog,"a");
+          
+          while (fgets(read_buffer, 4096, oldfile) != NULL)
+                  fputs(read_buffer,test);
+          
+          fclose(oldfile);
+           fclose(test);
+          unlink(oldnicklog);
+          eb_debug(DBG_CORE,"Copied log from %s to %s\n", oldnicklog, 
newnicklog);
+   }
+   
+   else if (strcmp(oldnicklog,newnicklog)) {
+          rename(oldnicklog, newnicklog);
+          eb_debug(DBG_CORE,"Renamed log from %s to %s\n", oldnicklog, 
newnicklog);
+   }
 }
 

Index: service.h
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/service.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- service.h   16 Jan 2003 13:11:01 -0000      1.5
+++ service.h   16 Jan 2003 17:28:26 -0000      1.6
@@ -230,8 +230,7 @@
 void add_idle_check();
 void serv_touch_idle();
        
-void rename_nick_log(char *oldnick, char *newnick);
-
+void rename_nick_log(char *oldgroup, char *oldnick, char *newgroup, char 
*newnick);
 GList * get_service_list();
 
 #ifdef __cplusplus

Index: util.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/util.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- util.c      16 Jan 2003 13:49:09 -0000      1.13
+++ util.c      16 Jan 2003 17:28:26 -0000      1.14
@@ -1380,6 +1380,8 @@
        }
        add_group_line(g);
 
+       rename_nick_log(c->group->name, c->nick, group, c->nick);
+       
        for(; l; l=l->next)
        {
                eb_account *ea = l->data;
@@ -1389,6 +1391,7 @@
        con = find_contact_by_nick(c->nick);
        if(con) 
        {
+               rename_nick_log(group, c->nick, group, con->nick);
                l = c->accounts;
                while(l)
                {
@@ -1448,22 +1451,34 @@
                
 
 
-void make_safe_filename(gchar *buff, gchar *name)  {
+void make_safe_filename(gchar *buff, gchar *name, gchar *group)  {
        
        /* i'm pretty sure the only illegal character is '/', but maybe 
         * there are others i'm forgetting */
        char *bad_chars="/";
        char *p;
-       char holder[NAME_MAX];
+       char holder[NAME_MAX], gholder[NAME_MAX];
 
        strncpy(holder, name, NAME_MAX);
+       if (group!=NULL)
+               strncpy(gholder, group, NAME_MAX);
 
        for (p=holder; *p; p++) {
                if ( strchr(bad_chars, *p) )
                        *p='_';
        }
-       g_snprintf(buff, NAME_MAX, "%slogs/%s", 
-                               config_dir, holder);
+       if (group != NULL)
+               for (p=gholder; *p; p++) {
+                       if ( strchr(bad_chars, *p) )
+                               *p='_';
+               }
+
+       g_snprintf(buff, NAME_MAX, "%slogs/%s%s%s", 
+                               config_dir, 
+                               (group!=NULL ? gholder:""),
+                               (group!=NULL ? "-":""),
+                               holder);
+       eb_debug(DBG_CORE,"logfile: %s\n",buff);
 }
                                        
 
@@ -1569,7 +1584,7 @@
 }
 
 void rename_contact( struct contact * c, char *newname) {
-        rename_nick_log(c->nick, newname);
+        rename_nick_log(c->group->name, c->nick, c->group->name, newname);
         strncpy(c->nick, newname, 254);
         c->nick[254] = '\0';
        if (c->label)

Index: util.h
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/util.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- util.h      16 Jan 2003 13:11:01 -0000      1.6
+++ util.h      16 Jan 2003 17:28:26 -0000      1.7
@@ -105,7 +105,7 @@
 void move_contact( gchar * group, struct contact * c);
 void invite_dialog( eb_local_account * ela, char * user, char * chat_room,
                    void * id );
-void make_safe_filename(gchar *buff, gchar *name);
+void make_safe_filename(gchar *buff, gchar *name, gchar *group);
 
 pid_t create_lock_file(gchar* fname);
 void delete_lock_file(gchar* fname);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]