New Dialogs

"A. Craig West" <[email protected]> Fri, 5 Mar 2004 19:07:22 -0500 (EST)
Newsgroups gmane.network.everybuddy.devel
Message-ID <[email protected]>
This is hopefully the final version of the new GUI dialogs implementation in
the core, seeing as I'm committing it as we speak :-).

----------------Patch Begins------------------
Index: src/dialog.h
===================================================================
--- src/dialog.h	(revision 299)
+++ 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: src/gui_comms.c
===================================================================
--- src/gui_comms.c	(revision 299)
+++ src/gui_comms.c	(working copy)
@@ -50,6 +50,9 @@
 char * away_msg=NULL;
 char * away_short=NULL;
 
+static char * true_string = "1";
+static char * false_string = "0";
+
 typedef enum {
   EB_ERROR_DIALOG,
   EB_LIST_DIALOG,
@@ -84,6 +87,7 @@
 {
   char * title;
   char * message;
+  int default_result;
 
   void * tag;
   void (*callback)(void * tag, int response);
@@ -94,6 +98,7 @@
   char * title;
   char * message;
   char * initial_contents;
+  int is_html;
 
   void * tag;
   void (*callback)(void * tag, char * response);
@@ -1156,6 +1161,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 +1179,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 +1205,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)?(true_string):(false_string);
+
+    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)?(true_string):(false_string);
+
+    num_commands=6;
+  }
+
   if(num_commands==0)
   {
     eb_show_error("Attempted to broadcast dialog of unknown type!", "Unknown dialog type");
@@ -1245,16 +1278,52 @@
   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);
+  td->is_html=html;
+
+  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;
+  ynd->default_result=default_result;
+
+  eb_gui_dialog_send(NULL, d);
 }
 
 void eb_gui_resolve_dialog(eb_gui * gui)
@@ -1316,6 +1385,40 @@
       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);
+      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
   }
 
Index: doc/GUI_SPEC
===================================================================
--- doc/GUI_SPEC	(revision 299)
+++ 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"
----------------Patch Ends------------------

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