Re: [gtk-list] Re: Best way to make a dialog..



> 	- make sure you are only passing a pointer to gtk_signal_connect,
> 	      e.g use &entry_ptrs, instead of entry_ptrs (although you
> 	      should get a compiler error about that...)
>           You cannot pass a structure - only a pointer to a structure.
Ok... i realize that... 

I did that though I get a nice set of garbage for the output again...
------------------------------
Server: :1123348
>From    : PQRT$oD$
                    ZYc$
To: h
BCC: h
Subject: ho
Body:
hw
-------------------------------------
 
I've attached my code and fiddled every which way to no avail so this
technique doesn't seem to work... (this is solely ui code no network
stuff)... Is my design completly off or something... ??? (arghghg this is
frustrating:P in an interesting way though).

> And no, gtk_signal_connect completely doesn't care what `user_data'
> contains.  In fact, it is common practice to pass integers in there
> so the signal code *never* deferences user_data.
> 
> - Dave
> 
#include <gtk/gtk.h>
#include "smtp_panel.h"

GtkWidget *From,*To,*BCC,*Subject,*Body;

void Destroy(GtkWidget*,GdkEvent*,gpointer);
void Send(GtkWidget*,GdkEvent*,gpointer);
void OkClicked(GtkWidget *widget,GdkEvent *event,gpointer data)
{
 smtp_info *Info = data;
  
 printf("Server\t: %s:%i\n",Info->server,Info->port);
 printf("From\t: %s\n",Info->from);
 printf("To\t: %s\n",Info->to);
 printf("BCC\t: %s\n",Info->bcc);
 printf("Subject\t: %s\n",Info->subject);
 printf("Body\t:\n%s\n",Info->body);
}


GtkWidget *smtp_panel_new(smtp_info *Info)
{
 GtkWidget *Frame,*Table,*Widget,*Pane;

 Frame = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 Table = gtk_table_new(6,2,FALSE);
 
 Widget = gtk_label_new("To:");
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(Widget),0,1,0,1);
 To = gtk_entry_new();
 if(!(Info->to == NULL))
   gtk_entry_set_text(GTK_ENTRY(To),Info->to);
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(To),1,2,0,1);

 Widget = gtk_label_new("From:");
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(Widget),0,1,1,2);
 From = gtk_entry_new();
 if(!(Info->from == NULL))
   gtk_entry_set_text(GTK_ENTRY(From),Info->from);
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(From),1,2,1,2);

 Widget = gtk_label_new("BCC:");
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(Widget),0,1,2,3);
 BCC = gtk_entry_new();
 if(!(Info->bcc == NULL))
   gtk_entry_set_text(GTK_ENTRY(BCC),Info->bcc);
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(BCC),1,2,2,3);

 Widget = gtk_label_new("Subject:");
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(Widget),0,1,3,4);
 Subject = gtk_entry_new();
 if(!(Info->subject == NULL))
   gtk_entry_set_text(GTK_ENTRY(Subject),Info->subject);
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(Subject),1,2,3,4);

 Pane = gtk_hbox_new(FALSE,0);
 Body = gtk_text_new(NULL,NULL);
 gtk_text_set_editable(GTK_TEXT(Body),TRUE);
 if(!(Info->body == NULL))
   gtk_text_insert(GTK_TEXT(Body),NULL,NULL,NULL,
                   Info->body,strlen(Info->body));
 if(!(Info->signature == NULL))
   gtk_text_insert(GTK_TEXT(Body),NULL,NULL,NULL,
                   Info->signature,strlen(Info->signature));
   
 gtk_box_pack_start(GTK_BOX(Pane),GTK_WIDGET(Body),TRUE,TRUE,0);
  
 Widget = gtk_vscrollbar_new(GTK_TEXT(Body)->vadj);
 gtk_box_pack_end(GTK_BOX(Pane),GTK_WIDGET(Widget),FALSE,TRUE,0);
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(Pane),0,2,4,5);
 
 Pane = gtk_hbox_new(FALSE,0);
 Widget = gtk_button_new_with_label("Ok");
 gtk_box_pack_start(GTK_BOX(Pane),GTK_WIDGET(Widget),TRUE,FALSE,0);

   gtk_signal_connect(GTK_OBJECT(Widget),"clicked",
                      GTK_SIGNAL_FUNC(OkClicked),NULL);

 gtk_signal_connect(GTK_OBJECT(Widget),"clicked",
                    GTK_SIGNAL_FUNC(Destroy),NULL); 

 Widget = gtk_button_new_with_label("Cancel");
 gtk_box_pack_end(GTK_BOX(Pane),GTK_WIDGET(Widget),TRUE,FALSE,0);
 gtk_signal_connect(GTK_OBJECT(Widget),"clicked",
                    GTK_SIGNAL_FUNC(Destroy), Info); 
 
 gtk_table_attach_defaults(GTK_TABLE(Table),GTK_WIDGET(Pane),0,2,5,6);

 gtk_signal_connect(GTK_OBJECT(Frame),"delete_event",
                    GTK_SIGNAL_FUNC(Destroy), NULL); 
 gtk_widget_show_all(Table);
 gtk_container_add(GTK_CONTAINER(Frame),Table);

 return Frame; 
}

void Destroy( GtkWidget *widget,GdkEvent *event,gpointer data ) 
{
 gtk_main_quit ();
}

#ifndef _smtp_panel_h
#define _smtp_panel_h

typedef struct 
 {
  gint  port;
  gchar *server,
        *from,
        *to,
        *bcc,
        *subject,
        *body,
        *signature;
  } smtp_info;

GtkWidget *smtp_panel_new(smtp_info*);

#endif
#include <stdio.h>
#include <gtk/gtk.h>
#include "smtp_panel.h"

smtp_info Info;

int main(int argc,char *argv[])
{
 GtkWidget *Window;

 Info.port   = 25;
 Info.server = "smtp.pangea.ca\0";
 Info.from   = "seanc@pangea.ca\0";
 Info.signature = "\n-=-=-=-=-\n  Sig  \n-=-=-=-=-\n\0";
 Info.to = Info.bcc = Info.subject = Info.body = NULL;

 gtk_init(&argc,&argv);
 Window = smtp_panel_new(&Info);
 gtk_window_set_title (GTK_WINDOW (Window), "Simple SMTP Client:");
 gtk_widget_show(Window);

 gtk_main();
}

APPNAME = smtp
OBJECTS = smtp_panel.o
CC = gcc
CFLAGS = -O2 `gtk-config --cflags`

all: $(APPNAME)

$(APPNAME): $(OBJECTS) $(APPNAME).o
	$(CC) -o $(APPNAME) $(APPNAME).o $(OBJECTS) `gtk-config --libs`

$(APPNAME).o: $(APPNAME).c
	$(CC) -c $(APPNAME).c `gtk-config --cflags`


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]