ayttm-commits
[Top][All Lists]
Advanced

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

[Ayttm-commits] CVS: ayttm/src status.c,1.24,1.25 util.c,1.15,1.16 util


From: Colin Leroy <address@hidden>
Subject: [Ayttm-commits] CVS: ayttm/src status.c,1.24,1.25 util.c,1.15,1.16 util.h,1.8,1.9
Date: Sun, 19 Jan 2003 06:18:41 -0500

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

Modified Files:
        status.c util.c util.h 
Log Message:
- src/status.c src/util.c src/util.h
First version of offline contact management cacheing



Index: status.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/status.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- status.c    19 Jan 2003 01:52:35 -0000      1.24
+++ status.c    19 Jan 2003 11:18:38 -0000      1.25
@@ -569,6 +569,11 @@
                eb_set_active_menu_status(s->ela->status_menu, new_state);
     }
     eb_debug(DBG_CORE, "%s set to state %d.\n", 
eb_services[s->ela->service_id].name, s->status );
+    if (s->ela->connected) {
+           printf("CONNECTED on %s !\n",get_service_name(s->ela->service_id));
+           /* in about 10 seconds try to flush contact mgmt queue */
+           eb_timeout_add(10000, (GtkFunction)contact_mgmt_flush, 
(gpointer)s->ela);
+    }
 
 }
 
@@ -588,7 +593,7 @@
        GList *node = accounts ;
        while(node) {
                eb_local_account *ac = (eb_local_account*)(node->data);
-               if (ac->connected) {
+               if (ac && ac->connected) {
                        RUN_SERVICE(ac)->logout(ac) ;
                }
                node = node->next ;

Index: util.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/util.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- util.c      18 Jan 2003 11:44:39 -0000      1.15
+++ util.c      19 Jan 2003 11:18:38 -0000      1.16
@@ -1015,6 +1015,9 @@
 {
     GList * l1;
 
+    if (handle == NULL)
+           return NULL;
+
     for(l1 = accounts; l1; l1=l1->next )
     {
          eb_local_account * account = (eb_local_account*)l1->data;
@@ -1138,11 +1141,7 @@
 {
     struct contact * c = a->account_contact;
     if (!find_suitable_local_account(NULL, a->service_id)) {
-       char *buff = g_strdup_printf(_("You should be connected to %s before 
removing this account"), 
-                                   get_service_name(a->service_id));
-       do_error_dialog(buff, _("Error"));
-       g_free(buff);
-       return 0;
+       contact_mgmt_queue_add(a, MGMT_DEL, NULL);
     }
 
     buddy_logoff(a);
@@ -1220,11 +1219,7 @@
     struct contact * c = find_contact_by_nick( contact );
     eb_account * ea = find_account_by_handle(account->handle, 
account->service_id);
     if (!find_suitable_local_account(NULL, account->service_id)) {
-       char *buff = g_strdup_printf(_("You should be connected to %s before 
adding this account"), 
-                                       get_service_name(account->service_id));
-       do_error_dialog(buff, _("Error"));
-       g_free(buff);
-       return;
+       contact_mgmt_queue_add(account, MGMT_ADD, 
c?c->group->name:_("Unknown"));
     }
     if(ea)
     {      /* shouldn't it be ea->account_contact->group->name ? */
@@ -1332,6 +1327,10 @@
        if(!strcasecmp(ng, og))
                return;
 
+       if (!find_suitable_local_account(NULL, ea->service_id)) {
+               contact_mgmt_queue_add(ea, MGMT_MOV, ng);
+       }
+               
        /* adding to ignore */
        if(!strcmp(ng, _("Ignore")) && RUN_SERVICE(ea)->ignore_user)
                RUN_SERVICE(ea)->ignore_user(ea);
@@ -1352,14 +1351,6 @@
        gchar * new_group = con->group->name;
        gchar *old_group = c->group->name;
 
-       if (!find_suitable_local_account(NULL, ea->service_id)) {
-               char *buff = g_strdup_printf(_("You should be connected to %s 
before moving this account"), 
-                                               
get_service_name(ea->service_id));
-               do_error_dialog(buff, _("Error"));
-               g_free(buff);
-               return;
-       }
-               
        handle_group_change(ea, old_group, new_group);
 
        c->accounts = g_list_remove(c->accounts, ea);
@@ -1393,28 +1384,6 @@
        grouplist * g = c->group;
        struct contact *con;
        GList *l = c->accounts;
-       char *not_connected = NULL;
-       for(; l; l=l->next)
-       {
-               eb_account *ea = l->data;
-               if (!find_suitable_local_account(NULL, ea->service_id)) {
-                       if (not_connected && 
!strstr(not_connected,get_service_name(ea->service_id))) {
-                               char *old = not_connected;
-                               not_connected = g_strdup_printf("%s,%s", 
not_connected, get_service_name(ea->service_id));
-                               g_free(old);
-                       } else if (!not_connected)
-                               not_connected = 
g_strdup(get_service_name(ea->service_id));
-               }
-       }
-       if(not_connected != NULL) {
-               char *buff = g_strdup_printf(_("You should be connected to %s 
before moving this contact"), 
-                                           not_connected);
-               do_error_dialog(buff, _("Error"));
-               g_free(buff);
-               g_free(not_connected);
-               return;
-       }
-       l = c->accounts;
        
        g->members = g_list_remove(g->members, c);
        remove_contact_line(c);
@@ -1661,3 +1630,92 @@
        return newlist;
 }
 
+void contact_mgmt_queue_add(eb_account *ea, int action, char *new_group)
+{
+       FILE *fp;
+       char buff [NAME_MAX];
+       g_snprintf(buff, NAME_MAX, "%s%ccontact_actions_queue", 
+                               config_dir, 
+                               G_DIR_SEPARATOR);
+       fp = fopen(buff,"a");
+       if (!fp) {
+               perror(buff);
+               return;
+       }
+       
+       fprintf(fp, "%s\t%d\t%s\t%s\t%s\n",
+               get_service_name(ea->service_id),
+               action,
+               ea->handle,
+               (action!=MGMT_ADD ? ea->account_contact->group->name:"NULL"),
+               (new_group!=NULL ? new_group:"NULL"));
+       
+       fclose(fp);
+}
+
+gint contact_mgmt_flush(eb_local_account *ela)
+{
+       FILE *queue, *temp;
+       char buff[NAME_MAX], queue_name[NAME_MAX], temp_name[NAME_MAX];
+       char *str = NULL;
+       g_snprintf(queue_name, NAME_MAX, "%s%ccontact_actions_queue", 
+                               config_dir, 
+                               G_DIR_SEPARATOR);
+       
+       queue = fopen(queue_name, "r");
+       if (!queue)
+               return 0;
+       g_snprintf(temp_name, NAME_MAX, "%s%ccontact_actions_queue.new", 
+                               config_dir, 
+                               G_DIR_SEPARATOR);
+       
+       temp = fopen(temp_name, "w");
+       
+       if (!temp) {
+               perror(buff);
+               return 0;
+       }
+       
+       while( fgets(buff, sizeof(buff), queue)  != NULL )
+       {               
+               char buff_backup[NAME_MAX];
+               strcpy(buff_backup, buff);
+               str = strtok( buff, "\t" );
+               if(!strcmp(str,get_service_name(ela->service_id))) {
+                       int action     = atoi(strtok(NULL,"\t"));
+                       char *handle   = strtok(NULL,"\t");
+                       char *oldgroup = strtok(NULL,"\t");
+                       char *newgroup = strtok(NULL,"\n");
+                       eb_account *ea = NULL;
+                       if (action == MGMT_ADD || action == MGMT_MOV) {
+                               ea = find_account_by_handle(
+                                               handle, 
+                                               ela->service_id);
+                       } else {
+                               continue; /* should re-create a
+                                         dummy eb_account */
+                       }
+                       if (action == MGMT_ADD && RUN_SERVICE(ea)->add_user) {
+                               RUN_SERVICE(ea)->add_user(ea);
+                       }
+                       if (action == MGMT_MOV && 
RUN_SERVICE(ea)->change_group) {
+                               char realgrp[NAME_MAX];
+                               /* this is "a bit" ugly :-( */
+                               
strcpy(realgrp,ea->account_contact->group->name);
+                               
strcpy(ea->account_contact->group->name,oldgroup);
+                               RUN_SERVICE(ea)->change_group(ea, newgroup);
+                               strcpy(ea->account_contact->group->name, 
realgrp);
+                       }
+
+               } else {
+                       /* not for me */
+                       fprintf(temp, "%s", buff_backup);
+               }
+       }
+       
+       fclose (temp);
+       fclose (queue);
+       rename (temp_name, queue_name);
+       return 0;
+       
+}

Index: util.h
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/util.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- util.h      18 Jan 2003 11:44:39 -0000      1.8
+++ util.h      19 Jan 2003 11:18:38 -0000      1.9
@@ -61,6 +61,13 @@
 
 };
 
+enum
+{
+  MGMT_ADD,
+  MGMT_DEL,
+  MGMT_MOV
+};
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -111,6 +118,8 @@
 void delete_lock_file(gchar* fname);
 void eb_generic_menu_function(void *add_button, gpointer userdata);
 GList * get_groups();
+void contact_mgmt_queue_add(eb_account *ea, int action, char *group);
+gint contact_mgmt_flush(eb_local_account *ela);
 
 #ifdef __cplusplus
 } /* extern "C" */





reply via email to

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