RE: Re: How to "strcmp" data from gtk_entry?



Hi all,

I hope I read (and understood) the former e-mails correct, so here it goes:

1. The gtk_entry should have the signal "changed" attached so that if this
entry is changed the event handler kicks in.

2. In the callbacks.c a function something like on_gtk_entry_changed()
should exist.

3. In this function a static variable (global scope) defined like "gboolean
gtk_entry_changed = FALSE;" should be set to TRUE.

4. In the function on_dialog_button_ok_clicked() this entry should be read
with gtk_editable_get_chars().

5. Do something with the chars you got from gtk_editable_get_chars(). Not
the silly stuff I wrote, but a full working user checking mechanisme, code
based on checking against a list of known valid users.

see the following snippet:

--8<--------------------------------------------------------------

static gchar *my_dialog_some_entry_text;
static gboolean my_dialog_some_entry_changed = FALSE;

void
on_my_dialog_some_entry_changed(GtkEditable *editable, gpointer user_data)
{
  my_dialog_some_entry_changed = TRUE;
}

void
on_my_dialog_button_ok_clicked(GtkButton *button, gpointer user_data)
{
  extern GtkWidget *my_dialog_some_entry;

  if(my_dialog_some_entry_changed)
  {
    my_dialog_some_entry = lookup_widget(GTK_WIDGET(button),
"my_dialog_some_entry");
    my_dialog_some_entry_text =
gtk_editable_get_chars(GTK_EDITABLE(my_and_dialog_some_entry), 0, -1);
  }
  if(my_dialog_some_entry_text == g_strdup("known user"))
  {
    gtk_entry_set_text(my_dialog_some_entry, g_strdup("you have entered:
__known user__"));
  }
  else
  {
    gtk_entry_set_text(my_dialog_some_entry, g_strdup("you have entered
something else"));
  }
}

--8<--------------------------------------------------------------

Do NOT forget to "g_free(*char);" the strings no longer needed !!

also look at:

http://developer.gnome.org/doc/API/2.0/glib/glib-String-Utility-Functions.ht
ml#g-strdup
or 
http://developer.gnome.org/doc/API/2.0/glib/glib-String-Utility-Functions.ht
ml#g-strdup-printf

http://developer.gnome.org/doc/API/2.0/gtk/GtkEditable.html

http://developer.gnome.org/doc/API/2.0/gtk/GtkEntry.html

Kind regards,

Bert Timmerman.

Disclaimer: I'm not liable for anything you can think of, and nor is my
employer ;-)


>  -----Original Message-----
> From: 	gtk-list-admin gnome org@CORUS   On Behalf Of "george
> carter" <cglobal25 hotmail com>
> Sent:	maandag 25 augustus 2003 15:00
> To:	gtk-list gnome org
> Subject:	Fwd: Re: How to "strcmp" data from gtk_entry?
> 
> 
> 
> 
> >From: Vadim Berezniker <vadim berezniker com>
> >To: george carter <cglobal25 hotmail com>
> >CC: gtk-list gnome org
> >Subject: Re: How to "strcmp" data from gtk_entry?
> >Date: Mon, 18 Aug 2003 06:27:30 -0400
> >
> >george carter wrote:
> >>   I'm having a small problem with using the data from a gtk_entry.  I
> >>would like a user to enter a username and password into a gtk_entry.  I
> >>don't have a problem with connect the button signals or anything.  I'm
> >>calling a function which should compare the gtk_entry data with
> "username"
> >>for example, but I'm not sure how to approach it.  I figure I would use
> >>"strcmp" and if it returns false than "set_text_entry" to "user not in
> >>database." How would I put "data" into the strcmp function?
> >
> >if(!strcmp(gtk_entry_get_text(username_entry), "unsecure_user"))
> >	printf("The username is correct.\n");
> >
> 
> I've tried this code but it doesn't seem to compile without errors.  I was
> actually expecting something with a comparision resulting in a true or
> false
> being returned.  Maybe something similar to this:
> if (strcmp(s1,s2)==0)
> 	printf("equal\n");
> 	else if (strcmp(s1,s2)<0)
> I'm just not sure how to plug in the values.  Any ideas?
> 
> _________________________________________________________________
> MSN 8: Get 6 months for $9.95/month. http://join.msn.com/?page=dept/dialup
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list



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