On Wed, 2006-03-15 at 03:51 -0600, Eric Rodriguez wrote:
> Here is my issue:
> 
> I am creating a very simple app that consists of a text field and a 
> submit button. My goal is to add text to the text field and when the 
> submit button is hit, it will pass a url to a browser.
> 
> For instance:
> 
> When "123" is entered into the text field and the "submit" button is 
> hit, it will open a browser to http://website.com/path=123
> 
> By scouring the web for info, I've been able to combine the text and 
> have it print at the top of the app...here's the code:
> 
> void
> on_button1_clicked(GtkButton *button, gpointer user_data){
> 
> GtkWidget * label = lookup_widget(GTK_WIDGET(button), "label1");
> GtkWidget * entry = lookup_widget(GTK_WIDGET(button), "entry1");
> 
> gchar output[50]="http://website.com/path=";;
> strcat(output,gtk_entry_get_text(GTK_ENTRY(entry)));

Bad move, it will segfault if you put into the entry 26+ characters. 

> gtk_label_set_text(GTK_LABEL(label),output);
> }
> 
> This was pretty much done for testing purposes...
> 
> Obviously, instead of having the url print on the top of the app, I'd 
> like the url to be passed to a browser when the submit button is hit.
> 
> The operating system is linux, and the browser will either be firefox or 
> konqueror.
> 
> Here is the little I have so far...
> 
> #ifdef __linux__
> #define BROWSER "konqueror"
> #else
> #define BROWSER "firefox"
> #endif
> 
> I'm sure that will define the browser, I'm just not sure how to pass the 
> url to said browser.

void
on_button1_clicked(GtkButton *button, gpointer user_data)
{
  gchar *output;
  GError *error = NULL;
  GtkWidget *label = lookup_widget(GTK_WIDGET(button), "label1");
  GtkWidget *entry = lookup_widget(GTK_WIDGET(button), "entry1");
  const gchar *url = "http://website.com/path";;

  if( entry ){
    output = g_strdup_printf("%s %s=%s",
                             BROWSER,
                             url,
                             gtk_entry_get_text(GTK_ENTRY(entry))
                            );
    g_spawn_command_line_async (output, &error);
    if( error ){
      g_print( "Error: %s\n", error->message );
      g_error_free(error);
    }
  }
}

-- 
Iago Rubio

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to