00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "intl.h"
00023 #include "globals.h"
00024 #include "plugin.h"
00025 #include "dialog.h"
00026 #include "prefs.h"
00027
00028 static void eb_gtk_dialog_callback(GtkWidget *widget, gpointer data)
00029 {
00030 callback_data *cd= (callback_data *)data;
00031 int result=0;
00032
00033 result=(int)gtk_object_get_user_data(GTK_OBJECT(widget));
00034 cd->action(cd->data, result);
00035
00036 }
00037
00038
00039
00040
00041 ebmImportData *ebmImportData_new()
00042 {
00043 ebmImportData *eid=g_new0(ebmImportData, 1);
00044 ((ebmCallbackData *)eid)->CDType=ebmIMPORTDATA;
00045 return(eid);
00046 }
00047
00048 ebmCallbackData *ebmProfileData_new(eb_local_account * ela)
00049 {
00050 ebmCallbackData *eid=g_new0(ebmCallbackData, 1);
00051 ((ebmCallbackData *)eid)->CDType=ebmPROFILEDATA;
00052 eid->user_data = ela;
00053 return(eid);
00054 }
00055
00056
00057 ebmContactData *ebmContactData_new()
00058 {
00059 ebmContactData *ecd=g_new0(ebmContactData, 1);
00060 ((ebmCallbackData *)ecd)->CDType=ebmCONTACTDATA;
00061 return(ecd);
00062 }
00063
00064 void *eb_add_menu_item(char *label, char *menu_name, eb_menu_callback callback, ebmType type, void *data)
00065 {
00066 menu_item_data *mid=NULL;
00067 menu_data *md=NULL;
00068
00069 eb_debug(DBG_CORE, ">Adding %s to menu %s\n", label, menu_name);
00070 md = GetPref(menu_name);
00071 if(!md) {
00072 eb_debug("Unknown menu requested: %s\n", menu_name);
00073 return(NULL);
00074 }
00075
00076 if(type!=md->type) {
00077 eb_debug("Incorrect ebmType passed, not adding menu item: %s\n", label);
00078 return(NULL);
00079 }
00080 mid=g_new0(menu_item_data, 1);
00081 mid->user_data=data;
00082 mid->label=label;
00083 mid->callback=callback;
00084 md->menu_items = g_list_append(md->menu_items, mid);
00085 if(md->redraw_menu) {
00086 eb_debug(DBG_CORE, "Calling redraw_menu for %s\n", menu_name);
00087 md->redraw_menu();
00088 }
00089 eb_debug(DBG_CORE, "<Successfully added menu item\n");
00090
00091 return((void *)mid);
00092 }
00093
00094 int eb_remove_menu_item(char *menu_name, void *tag)
00095 {
00096 menu_data *md=NULL;
00097 menu_item_data *mid=(menu_item_data *)tag;
00098
00099 if(mid) {
00100 eb_debug(DBG_CORE, ">Request to remove %s from menu %s\n", mid->label, menu_name);
00101 }
00102 if(!tag) {
00103 eb_debug(DBG_CORE, "<Received request to delete from menu %s, with empty tag\n", menu_name);
00104 return(-1);
00105 }
00106 md=GetPref(menu_name);
00107 if(!md) {
00108 eb_debug(DBG_CORE, "<Requested menu %s does not exist, returning failure\n", menu_name);
00109 return(-1);
00110 }
00111 md->menu_items=g_list_remove(md->menu_items, tag);
00112 if(md->redraw_menu) {
00113 eb_debug(DBG_CORE, "Calling redraw_menu\n");
00114 md->redraw_menu();
00115 }
00116 eb_debug(DBG_CORE, "<Returning success\n");
00117 return(0);
00118 }
00119
00120 void eb_do_dialog(char *message, char *title, eb_callback_action action, void *data)
00121 {
00122 callback_data *cd=g_new0(callback_data,1);
00123 cd->action=action;
00124 cd->data=data;
00125 do_dialog(message, title, eb_gtk_dialog_callback, cd);
00126 }
00127
00128 void eb_set_active_menu_status(GSList *status_menu, int status)
00129 {
00130 gtk_check_menu_item_set_active
00131 (GTK_CHECK_MENU_ITEM
00132 (
00133 g_slist_nth(status_menu, status)->data
00134 ), TRUE
00135 );
00136 }
00137
00138
00139 int eb_input_add(int fd, eb_input_condition condition, eb_input_function function,
00140 void *callback_data)
00141 {
00142 return(gdk_input_add(fd, condition, function, callback_data));
00143 }
00144
00145 void eb_input_remove(int tag)
00146 {
00147 gdk_input_remove(tag);
00148 }
00149
00150
00151
00152 #ifdef __STDC__
00153 int EB_DEBUG(const char *func, char *file, int line, char *fmt, ...)
00154 #else
00155 int EB_DEBUG(const char *func, char *file, int line, char *fmt, va_alist)
00156 char *fmt;
00157 va_dcl
00158 #endif
00159 {
00160 va_list ap;
00161 static int indent=0;
00162
00163 #ifdef __STDC__
00164 va_start(ap, fmt);
00165 #else
00166 va_start(ap);
00167 #endif
00168 if(fmt && fmt[0]=='>')
00169 indent++;
00170
00171 fprintf(stderr, "%*.*s%s[%i]:%s - ", indent, indent, " ", file, line, func);
00172 vfprintf(stderr, fmt, ap);
00173 fflush(stderr);
00174 va_end(ap);
00175
00176 if(fmt && fmt[0]=='<')
00177 indent--;
00178 if(indent<0)
00179 indent=0;
00180 return(0);
00181 }
00182
00183 const char *eb_config_dir()
00184 {
00185 return(config_dir);
00186 }