GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Dec 20, 2014 9:45 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Validate format of the string typed in gtk_entry
PostPosted: Mon Sep 09, 2013 12:29 am 
Offline
Familiar Face

Joined: Thu Nov 22, 2012 3:46 pm
Posts: 26
I need to write a function that will validate device name typed by user in gtk entry field.

Device must be in the following form:

Code:
"/dev/video + one digits" ( e.g. /dev/video1 )


For this I made function but I don't now how to write condition

Code:
   void validate_device_cb (GtkEntry* entry, const gchar* text, gint length, gint* position, gpointer data)
   {
      GtkEditable *editable = GTK_EDITABLE (entry);
      int i, count = 0;
      gchar *result = g_new (gchar, length);

      for (i = 0; i < length; i++) {
            /* insert condition here */

                  continue;
            result[count++] = text[i];
      }      
      if (count > 0) {
            g_signal_handlers_block_by_func (G_OBJECT (editable),
                        G_CALLBACK (validate_device_cb), data);
            gtk_editable_insert_text (editable, result, count, position);
            g_signal_handlers_unblock_by_func (G_OBJECT (editable),
                        G_CALLBACK (validate_device_cb), data);
      }
      g_signal_stop_emission_by_name (G_OBJECT (editable), "insert_text");

      g_free (result);
   }


gtk entry must should accept only this chars typed:

Code:
    first typed: '/'
    second       'd'
    third        'e'
    fourth       'v'
    fifth        '/'
    sixth        'v'
    seventh      'i'
    eight        'd' 
    .........
    eleven        digit
    twelve        digit


setting device entry:

Code:
    video_device = gtk_entry_new_with_max_length(12);
    gtk_editable_set_editable(GTK_EDITABLE(video_device),TRUE);
    g_signal_connect(G_OBJECT(video_device), "insert_text" , G_CALLBACK(validate_device_cb), NULL);


Any help are welcome
Best regards


Top
 Profile  
 
 Post subject: Re: Validate format of the string typed in gtk_entry
PostPosted: Mon Sep 09, 2013 5:56 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 799
Location: UK
Hello,

Would it be easier for the user to use a combo box to select from the available video devices rather than type in or appear to type in the whole of the device name.

What you need to do is find all the video devices, insert their names into the combo box then allow the user to select the correct device.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group