GUI comm changes

"A. Craig West" <[email protected]> Thu, 19 Feb 2004 03:28:10 -0500 (EST)
Newsgroups gmane.network.everybuddy.user
Message-ID <[email protected]>
On Thu, 19 Feb 2004, A. Craig West wrote:

> There is a problem with this, however. The gui methods I would use to
> implement this, eb_show_text_dialog and eb_show_yesno_dialog, are not
> currently implemented. I plan to implement these, but now I am concerned
> that perhaps the guis don't all implement them either...

Okay, I have, in the process of adding implementation for these two gui
methods, noticed that the GUI spec for the text dialog is:
Server: "text_dialog" "tag code" "current contents"
Client: "resolve_dialog" "tag code" "new contents"

I have determined that this method would be much more useful (and some of the
current code implies it was intended to be) if it was:
Server: "text_dialog" "tag code" "title" "message" "current contents"
Client: "resolve_dialog" "tag code" "new contents"

The core part of this change follows, but it will require changes in the
guis which I can't easily make. On the other hand, it won't affect code
currently in use, seeing as these dialogs aren't implemented.

---------------- Begin Patch ----------------
Index: core/src/dialog.h
===================================================================
--- core/src/dialog.h	(revision 273)
+++ core/src/dialog.h	(working copy)
@@ -8,6 +8,8 @@
 
 void eb_show_error(char * message, char * title);
 void eb_show_list_dialog(char * message, char * title, char **list, void (*callback)(void * tag, char * response), void * tag);
+void eb_show_yesno_dialog(char * message, char * title, void (*callback)(void * tag, int response), void * tag);
+void eb_show_text_dialog(char * message, char * title, char * value, void (*callback)(void * tag, char * response), void * tag);
 
 #ifdef __cplusplus
 }
Index: core/src/gui_comms.c
===================================================================
--- core/src/gui_comms.c	(revision 273)
+++ core/src/gui_comms.c	(working copy)
@@ -1164,6 +1164,8 @@
   char ** notify_command=NULL;
   char error_dialog[]="error_dialog";
   char list_dialog[]="list_dialog";
+  char yesno_dialog[]="yesno_dialog";
+  char text_dialog[]="text_dialog";
   char buf[32];
   int num_commands=0;
 
@@ -1180,8 +1182,7 @@
     notify_command[3]=ed->message;
     num_commands=4;
   }
-
-  if(d->type==EB_LIST_DIALOG)
+  else if(d->type==EB_LIST_DIALOG)
   {
     eb_list_dialog * ld=(eb_list_dialog *)d->data;
     EList * n;
@@ -1207,7 +1208,32 @@
 
     num_commands=5+len;
   }
+  else if(d->type==EB_YESNO_DIALOG)
+  {
+    eb_yesno_dialog * ynd=(eb_yesno_dialog *)d->data;
 
+    notify_command=(char **)malloc(4*sizeof(char *));
+    notify_command[0]=yesno_dialog;
+    notify_command[1]=buf;
+    notify_command[2]=ynd->title;
+    notify_command[3]=ynd->message;
+
+    num_commands=4;
+  }
+  else if(d->type==EB_TEXT_DIALOG)
+  {
+    eb_text_dialog * td=(eb_text_dialog *)d->data;
+
+    notify_command=(char **)malloc(5*sizeof(char *));
+    notify_command[0]=text_dialog;
+    notify_command[1]=buf;
+    notify_command[2]=td->title;
+    notify_command[3]=td->message;
+    notify_command[4]=td->initial_contents;
+
+    num_commands=5;
+  }
+
   if(num_commands==0)
   {
     eb_show_error("Attempted to broadcast dialog of unknown type!", "Unknown dialog type");
@@ -1253,16 +1279,50 @@
   eb_gui_dialog_send(NULL, d);
 }
 
-void eb_show_text_dialog(char * title, char * value,
-		void (*action)(char * text, void * data),
-		void * data )
+void eb_show_text_dialog(char * message, char * title, char * value,
+		void (*callback)(void * tag, char * response),
+		void * tag)
 {
-  printf("Oooh, it wants some teeext...\n");
+  eb_dialog * d=(eb_dialog *)malloc(sizeof(eb_dialog));
+  eb_text_dialog * td=(eb_text_dialog *)malloc(sizeof(eb_text_dialog));
+
+  dialogs=e_list_append(dialogs, d);
+
+  d->id=next_dialog_id++;
+  d->data=td;
+  d->type=EB_TEXT_DIALOG;
+
+  td->message=strdup(message);
+  td->title=strdup(title);
+  td->callback=callback;
+  td->tag=tag;
+  if (value == NULL)
+    td->initial_contents=strdup("");
+  else
+    td->initial_contents=strdup(value);
+
+  eb_gui_dialog_send(NULL, d);
 }
 
-void eb_show_yesno_dialog( char * message, char * title, void * callback_func, void * data )
+void eb_show_yesno_dialog( char * message, char * title,
+		void (*callback)(void * tag, int response),
+		void * tag)
 {
-  printf("Ask a question!\n");
+  eb_dialog * d=(eb_dialog *)malloc(sizeof(eb_dialog));
+  eb_yesno_dialog * ynd=(eb_yesno_dialog *)malloc(sizeof(eb_yesno_dialog));
+
+  dialogs=e_list_append(dialogs, d);
+
+  d->id=next_dialog_id++;
+  d->data=ynd;
+  d->type=EB_YESNO_DIALOG;
+
+  ynd->message=strdup(message);
+  ynd->title=strdup(title);
+  ynd->callback=callback;
+  ynd->tag=tag;
+
+  eb_gui_dialog_send(NULL, d);
 }
 
 void eb_gui_resolve_dialog(eb_gui * gui)
@@ -1324,6 +1384,40 @@
       break;
     }
 
+    case(EB_YESNO_DIALOG) : {
+      eb_yesno_dialog * ynd=(eb_yesno_dialog *)d->data;
+
+      int result = 0;
+      if(!strcmp("yes", gui->params[2]))
+	result = 1;
+      else if(!strcmp("no", gui->params[2]))
+	result = 0;
+      else
+      {
+        eb_do_client_error(gui, "Not a valid option, must be yes or no");
+        return;
+      }
+
+      ynd->callback(ynd->tag, result);
+
+      free(ynd->title);
+      free(ynd->message);
+      free(ynd);
+      break;
+    }
+
+    case(EB_TEXT_DIALOG) : {
+      eb_text_dialog * td=(eb_text_dialog *)d->data;
+
+      td->callback(td->tag, gui->params[2]);
+
+      free(td->title);
+      free(td->message);
+      free(td->initial_contents);
+      free(td);
+      break;
+    }
+
     default : {} // to stop complaints that I haven't handled all the enums
   }
 
----------------- End Patch -----------------



-- 
Craig West         Ph: (416) 666-1645	|  It's not a bug,
[email protected]              	|  It's a feature...