[DEV] Dialog changes

"A. Craig West" <[email protected]> Mon, 23 Feb 2004 15:07:14 -0500 (EST)
Newsgroups gmane.network.everybuddy.user
Message-ID <[email protected]>
Here is the proposed core changes for the remaining dialogs. I have also added
a default_result field to the yesno dialog, and changed it's expected answer
to "1" and "0" for consistency.
These changes will require some changes to the Gui's, particularly ebqt. At the
moment, nobody is using these dialogs, but that can be expected to change.
-Craig

----------------Begin Patch-------------------
Index: core/src/dialog.h
===================================================================
--- core/src/dialog.h	(revision 295)
+++ 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, int result, void (*callback)(void * tag, int response), void * tag);
+void eb_show_text_dialog(char * message, char * title, char * value, int html, void (*callback)(void * tag, char * response), void * tag);
 
 #ifdef __cplusplus
 }
Index: core/src/gui_comms.c
===================================================================
--- core/src/gui_comms.c	(revision 295)
+++ core/src/gui_comms.c	(working copy)
@@ -84,6 +84,7 @@
 {
   char * title;
   char * message;
+  char * default_result;
 
   void * tag;
   void (*callback)(void * tag, int response);
@@ -94,6 +95,7 @@
   char * title;
   char * message;
   char * initial_contents;
+  char * is_html;
 
   void * tag;
   void (*callback)(void * tag, char * response);
@@ -1156,6 +1158,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;
 
@@ -1172,8 +1176,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;
@@ -1199,7 +1202,34 @@
 
     num_commands=5+len;
   }
+  else if(d->type==EB_YESNO_DIALOG)
+  {
+    eb_yesno_dialog * ynd=(eb_yesno_dialog *)d->data;
 
+    notify_command=(char **)malloc(5*sizeof(char *));
+    notify_command[0]=yesno_dialog;
+    notify_command[1]=buf;
+    notify_command[2]=ynd->title;
+    notify_command[3]=ynd->message;
+    notify_command[4]=ynd->default_result;
+
+    num_commands=5;
+  }
+  else if(d->type==EB_TEXT_DIALOG)
+  {
+    eb_text_dialog * td=(eb_text_dialog *)d->data;
+
+    notify_command=(char **)malloc(6*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;
+    notify_command[5]=td->is_html;
+
+    num_commands=6;
+  }
+
   if(num_commands==0)
   {
     eb_show_error("Attempted to broadcast dialog of unknown type!", "Unknown dialog type");
@@ -1245,16 +1275,58 @@
   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,
+		int html, 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);
+  if (html)
+    td->is_html=strdup("1");
+  else
+    td->is_html=strdup("0");
+
+  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, int default_result,
+		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;
+  if (default_result)
+    ynd->default_result=strdup("1");
+  else
+    ynd->default_result=strdup("0");
+
+  eb_gui_dialog_send(NULL, d);
 }
 
 void eb_gui_resolve_dialog(eb_gui * gui)
@@ -1316,6 +1388,42 @@
       break;
     }
 
+    case(EB_YESNO_DIALOG) : {
+      eb_yesno_dialog * ynd=(eb_yesno_dialog *)d->data;
+
+      int result = 0;
+      if(!strcmp("1", gui->params[2]))
+	result = 1;
+      else if(!strcmp("0", gui->params[2]))
+	result = 0;
+      else
+      {
+        eb_do_client_error(gui, "Not a valid option, must be \"1\" or \"0\"");
+        return;
+      }
+
+      ynd->callback(ynd->tag, result);
+
+      free(ynd->title);
+      free(ynd->message);
+      free(ynd->default_result);
+      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->is_html);
+      free(td);
+      break;
+    }
+
     default : {} // to stop complaints that I haven't handled all the enums
   }
 
Index: core/doc/GUI_SPEC
===================================================================
--- core/doc/GUI_SPEC	(revision 295)
+++ core/doc/GUI_SPEC	(working copy)
@@ -302,12 +302,12 @@
 
 (2) Yes/No dialog
 
-Server: "yesno_dialog" "tag code" "title" "message"
+Server: "yesno_dialog" "tag code" "title" "message" "default result"
 
 To resolve:
 
 Client: "resolve_dialog" "tag code" "result"
-"result" is either "yes" or "no"
+"result" is either "1" or "0"
 
 The server then broadcasts:
 Server: "dialog_resolved" "tag code"
@@ -327,10 +327,12 @@
 These are large dialogs suitable for entry of large amounts of 
 text, such as a buddy profile. When it opens, usually it will 
 have something in it already. If not, "current contents" is an 
-empty string.
+empty string. "is html" will be "1" if the text is expected to
+be formatted as html, otherwise it will be "0".
 
-Server: "text_dialog" "tag code" "current contents"
 
+Server: "text_dialog" "tag code" "title" "message" "current contents" "is html"
+
 Client: "resolve_dialog" "tag code" "new contents"
 
 Server (to all): "dialog_resolved" "tag code"
----------------End Patch-------------------

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