Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

service.c File Reference

#include "intl.h"
#include <gdk/gdkprivate.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <assert.h>
#include "globals.h"
#include "account.h"
#include "dialog.h"
#include "util.h"
#include "nomodule.h"
#include "prefs.h"

Include dependency graph for service.c:

Include dependency graph

Go to the source code of this file.

Functions

gint add_service (struct service *Service_Info)
gint get_service_id (gchar *servicename)
gchar * get_service_name (gint service_id)
GList * get_service_list ()
void serv_touch_idle ()
gint report_idle ()
gint check_idle ()
void add_idle_check ()
void rename_nick_log (char *oldnick, char *newnick)

Variables

guint idle_timer
time_t lastsent = 0
int is_idle = 0
int scrnsaver_ext = 0
int NUM_SERVICES = 0
service eb_services [255]
guint idle_time = 0


Function Documentation

void add_idle_check  
 

Definition at line 240 of file service.c.

References check_idle(), idle_timer, scrnsaver_ext, and serv_touch_idle().

00241 {
00242     int eventnum, errornum;
00243     idle_timer = gtk_timeout_add(5000, (GtkFunction)check_idle, NULL);
00244     serv_touch_idle();
00245 #ifdef HAVE_MIT_SAVER_EXTENSION
00246     if (XScreenSaverQueryExtension(gdk_display, &eventnum, &errornum)) {
00247         scrnsaver_ext = 1;
00248     }
00249 #endif
00250 }

gint add_service struct service   Service_Info
 

Definition at line 64 of file service.c.

References DBG_CORE, eb_debug, GetPref(), service::name, NUM_SERVICES, service::protocol_id, service_callbacks::read_prefs_config, refresh_service_contacts(), reload_service_accounts(), and service::sc.

Referenced by load_service_plugin(), and unload_module().

00065 {
00066     int i;
00067     GList *session_prefs=NULL;
00068 
00069     assert(Service_Info);
00070 
00071     eb_debug(DBG_CORE, ">Entering\n");
00072     if(Service_Info->sc->read_prefs_config) {
00073         session_prefs=GetPref(Service_Info->name);
00074         Service_Info->sc->read_prefs_config(session_prefs);
00075     }
00076 
00077     for (i=0; i < NUM_SERVICES; i++ )
00078     {
00079         /* Check to see if another service exists for the same protocol, if so, replace it */
00080         if(!strcasecmp(eb_services[i].name,Service_Info->name))
00081         {
00082                 eb_debug(DBG_CORE, "Replacing %s service\n", Service_Info->name);
00083 //              free(eb_services[i].name);
00084                 free(eb_services[i].sc);
00085                 Service_Info->protocol_id=i;
00086                 memcpy(&eb_services[i], Service_Info, sizeof(struct service));
00087                 refresh_service_contacts(i);
00088                 reload_service_accounts(i);
00089                 eb_debug(DBG_CORE, "<Replaced existing service\n");
00090                 return(i);
00091         }
00092         
00093     }
00094     Service_Info->protocol_id=NUM_SERVICES++;
00095     memcpy(&eb_services[Service_Info->protocol_id], Service_Info, sizeof(struct service));
00096     refresh_service_contacts(i);
00097     reload_service_accounts(Service_Info->protocol_id);
00098     eb_debug(DBG_CORE, "<Added new service \n");
00099     return(Service_Info->protocol_id);
00100 }

gint check_idle   [static]
 

Definition at line 192 of file service.c.

References idle_time, is_idle, lastsent, report_idle(), RUN_SERVICE, and serv_touch_idle().

Referenced by add_idle_check().

00193 {
00194     gint idle_reporter = -1;
00195 
00196 #ifdef HAVE_MIT_SAVER_EXTENSION
00197     if (scrnsaver_ext) {
00198         static XScreenSaverInfo * mit_info = NULL;
00199         mit_info = XScreenSaverAllocInfo();
00200         XScreenSaverQueryInfo(gdk_display, DefaultRootWindow(gdk_display), mit_info);
00201         idle_time = mit_info->idle/1000;
00202         free(mit_info);
00203     } else
00204 #endif
00205     {
00206         time_t t;
00207 
00208         if (is_idle)
00209             return TRUE;
00210         time(&t);
00211         
00212         idle_time = t - lastsent;
00213     }
00214     if ((idle_time >= 600) && do_send_idle_time) {
00215         if (is_idle == 0) {
00216             GList * node;
00217             idle_reporter = gtk_timeout_add(60000, (GtkFunction)report_idle, NULL);
00218             for(node = accounts; node; node = node->next )
00219             {
00220                 if(((eb_local_account *)node->data)->connected)
00221                 {
00222                     if(RUN_SERVICE(((eb_local_account*)node->data))->set_idle)
00223                     {
00224                         RUN_SERVICE(((eb_local_account*)node->data))->set_idle(
00225                                 (eb_local_account*)node->data, idle_time);
00226                     }
00227                 }
00228             }
00229         }
00230         is_idle = 1;
00231     } else if ((idle_time < 600) && do_send_idle_time && (is_idle == 1)) {
00232         if (idle_reporter != -1)
00233             gtk_idle_remove(idle_reporter);
00234         serv_touch_idle();
00235     }
00236     return TRUE;
00237 
00238 }

gint get_service_id gchar *    servicename
 

Definition at line 103 of file service.c.

References cSetLocalPref(), DBG_CORE, eb_debug, eb_nomodule_query_callbacks(), nomodule_SERVICE_INFO, and NUM_SERVICES.

Referenced by add_button_callback(), check_login_validity(), eb_read_prefs(), join_chat_callback(), ok_callback(), reload_service_accounts(), and yyparse().

00104 {
00105     int i;
00106     char buf[1024];
00107 
00108     for (i=0; i < NUM_SERVICES; i++ )
00109     {
00110         if(strcasecmp(eb_services[i].name,servicename)==0)
00111         {
00112             return i;   
00113         }
00114     }
00115     eb_debug(DBG_CORE, "Creating empty service for %s\n", servicename);
00116     memcpy(&eb_services[NUM_SERVICES], &nomodule_SERVICE_INFO, sizeof(struct service));
00117     eb_services[NUM_SERVICES].sc=eb_nomodule_query_callbacks();
00118     eb_services[NUM_SERVICES].name = strdup(servicename);
00119     eb_services[NUM_SERVICES].protocol_id=NUM_SERVICES;
00120     NUM_SERVICES++;
00121     sprintf(buf, "%s::path", servicename);
00122     cSetLocalPref(buf, "Empty Module");
00123     return(NUM_SERVICES-1);
00124 }

GList* get_service_list  
 

Definition at line 137 of file service.c.

References NUM_SERVICES.

Referenced by check_login_validity(), eb_new_user(), edit_contact_window_new(), and show_add_defined_contact_window().

00138 {
00139     GList * newlist = NULL;
00140     int i;
00141     for( i = 0; i < NUM_SERVICES; i++ )
00142     {
00143         newlist = g_list_append( newlist, eb_services[i].name );
00144     }
00145     return newlist;
00146 }

gchar* get_service_name gint    service_id
 

Definition at line 126 of file service.c.

References service::name, and NUM_SERVICES.

Referenced by eb_read_prefs(), get_local_accounts(), and reload_service_accounts().

00127 {
00128     if ((service_id >= 0) && (service_id < NUM_SERVICES))
00129     {
00130         return (eb_services[service_id].name);
00131     }
00132 
00133     fprintf(stderr, "warning: unknown service id: %d\n", service_id);
00134     return "unknown";
00135 }

void rename_nick_log char *    oldnick,
char *    newnick
 

Definition at line 253 of file service.c.

Referenced by ok_callback().

00254 {
00255    gchar oldnicklog[255], newnicklog[255];
00256    strcpy(oldnicklog, config_dir);
00257    strcat(oldnicklog, "logs/");
00258    strcpy(newnicklog, oldnicklog);
00259    strcat(oldnicklog, oldnick);
00260    strcat(newnicklog, newnick);
00261    rename(oldnicklog, newnicklog);
00262    printf("Renamed log from %s to %s\n", oldnicklog, newnicklog);
00263 }

gint report_idle   [static]
 

Definition at line 171 of file service.c.

References idle_time, is_idle, and RUN_SERVICE.

Referenced by check_idle().

00172 {
00173     GList * node;
00174 
00175     if (!is_idle)
00176         return FALSE;
00177 
00178     for(node = accounts; node; node = node->next )
00179     {
00180         if(((eb_local_account *)node->data)->connected)
00181         {
00182             if(RUN_SERVICE(((eb_local_account*)node->data))->set_idle)
00183             {
00184                 RUN_SERVICE(((eb_local_account*)node->data))->set_idle(
00185                         (eb_local_account*)node->data, idle_time);
00186             }
00187         }
00188     }
00189     return TRUE;
00190 }

void serv_touch_idle  
 

Definition at line 148 of file service.c.

References is_idle, lastsent, and RUN_SERVICE.

Referenced by add_idle_check(), check_idle(), and send_message().

00149 {
00150     /* Are we idle?  If so, not anymore */
00151     if (is_idle > 0) {
00152         GList * node;
00153         is_idle = 0;
00154         for(node = accounts; node; node = node->next )
00155         {
00156             if(((eb_local_account *)(node->data))->connected)
00157             {
00158                 if(RUN_SERVICE(((eb_local_account*)(node->data)))->set_idle)
00159                 {
00160                     RUN_SERVICE(((eb_local_account*)node->data))->set_idle(
00161                                  (eb_local_account*)node->data, 0);
00162                 }
00163             }
00164         }
00165     }
00166     time(&lastsent);
00167 }


Variable Documentation

struct service eb_services[255]
 

Definition at line 61 of file service.c.

guint idle_time = 0 [static]
 

Definition at line 169 of file service.c.

Referenced by check_idle(), and report_idle().

guint idle_timer [static]
 

Definition at line 52 of file service.c.

Referenced by add_idle_check().

int is_idle = 0 [static]
 

Definition at line 54 of file service.c.

Referenced by check_idle(), report_idle(), and serv_touch_idle().

time_t lastsent = 0 [static]
 

Definition at line 53 of file service.c.

Referenced by check_idle(), and serv_touch_idle().

int NUM_SERVICES = 0
 

Definition at line 56 of file service.c.

Referenced by add_service(), get_service_id(), get_service_list(), and get_service_name().

int scrnsaver_ext = 0 [static]
 

Definition at line 55 of file service.c.

Referenced by add_idle_check().


Contact: Andy Maloney     [Documentation generated by doxygen]