GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 30, 2014 11:50 am

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: WebKit URI Issues
PostPosted: Wed Sep 26, 2012 4:26 am 
Offline
Familiar Face

Joined: Sat Mar 03, 2012 2:45 am
Posts: 18
Hello Everyone.

I have a gtk+ webkit application that works good other then a my callback function. When my callback "load_commit_cb" loads the gtk_main_quit(); function is not closing the app when i land on that url. Any Suggestions. My Full Code is Below. - Thank You

Code:
#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <webkit/webkit.h>

GtkWidget *window;      // Top Window
GtkWidget *button_box;  // Top Button Box
GtkWidget *scrolled;   // Main Scrolled Window
GtkWidget *box;         //Main Window Box
GtkWidget *btn_new_os;  //New User
WebKitWebView* web_view;

static void new_os(GtkWidget *new_os, gpointer data)
{
   gtk_main_quit ();
}

static void load_commit_cb (WebKitWebView* web_view, gpointer data)
{
    const gchar* uri = webkit_web_view_get_uri (web_view);

   WebKitLoadStatus status = webkit_web_view_get_load_status(web_view);
   
   if(status == WEBKIT_LOAD_FINISHED)
   {
      if(uri == "http://localhost/?i=logout")
      {
         gtk_main_quit ();
      }
   }
}

static GtkWidget* create_button_box (void)
{
   button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_button_box_set_layout(GTK_WIDGET(button_box), GTK_BUTTONBOX_START);
   gtk_widget_set_sensitive (GTK_WIDGET(button_box), FALSE);

   btn_new_os = gtk_button_new_with_label ("New User");
   gtk_container_add (GTK_CONTAINER (button_box), btn_new_os);
   g_signal_connect (btn_new_os, "clicked", G_CALLBACK (new_os), NULL);

   gtk_widget_show_all(button_box);

   return button_box;
}

static GtkWidget* create_scrolled (void)
{
   scrolled = gtk_scrolled_window_new(NULL, NULL);
   gtk_widget_set_hexpand (GTK_WIDGET(scrolled), TRUE);
   gtk_widget_set_vexpand (GTK_WIDGET(scrolled), TRUE);

   web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
    gtk_container_add (GTK_CONTAINER (scrolled), GTK_WIDGET (web_view));
   
   g_signal_connect (G_OBJECT (web_view), "load-status", G_CALLBACK (load_commit_cb), web_view);
   
   gchar* uri = (gchar*) ("http://localhost/?i=login");
    webkit_web_view_open (web_view, uri);
   

   return scrolled;
}

static GtkWidget* create_box (void)
{
   box = gtk_box_new (GTK_ORIENTATION_VERTICAL, NULL);
   gtk_widget_set_hexpand (GTK_WIDGET(box), TRUE);
   gtk_widget_set_vexpand (GTK_WIDGET(box), TRUE);

    gtk_box_pack_start (GTK_BOX (box), create_button_box (), FALSE, FALSE, 0);
    gtk_box_pack_start (GTK_BOX (box), create_scrolled (), TRUE, TRUE, 0);
    gtk_container_add (GTK_CONTAINER (window), box);

   return box;
}

static GtkWidget* create_window (void)
{
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), "mytitle");
   gtk_window_set_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
   gtk_window_set_default_size (GTK_WINDOW(window), 1200, 800);

   /* Exit when the window is closed */
   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
   
   return window;
}

int main (int argc, char *argv[])
{
#ifdef ENABLE_NLS
   bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   textdomain (GETTEXT_PACKAGE);
#endif

   
   gtk_init (&argc, &argv);

   window = create_window ();
   box = create_box ();
   gtk_widget_show_all (window);
   gtk_widget_show_all (box);

   gtk_main ();

   return 0;
}



Top
 Profile  
 
 Post subject: Re: WebKit URI Issues
PostPosted: Wed Sep 26, 2012 7:02 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

Please do not post duplicate questions. Your previous question got some responses, so please continue the conversation there.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: WebKit URI Issues
PostPosted: Wed Sep 26, 2012 7:04 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 750
Location: UK
Hi,

Just so that you know, what you have done is reproduce your same errors again but in a slightly different way from your other posting http://www.gtkforums.com/viewtopic.php?f=3&t=178153.

Again you do not say what versions you are using or even what language.

In your function create_scolled()
Code:
   g_signal_connect (G_OBJECT (web_view), "load-status", G_CALLBACK (load_commit_cb), web_view);
there is no signal called "load-status". It is a property and what you should use is the notify signal like this
Code:
   g_signal_connect (G_OBJECT (web_view), "notify::load-status", G_CALLBACK (load_commit_cb), web_view);
It will then call the call-back whenever the property is changed.

Your function proto-type for load_commit_cb() is incorrect. Although is does not matter in this case, it is always good practice to have it correct in the first place so that any modifications to your code later does not mess things up. This should read as
Code:
static void load_commit_cb (GObject *gobject,  GParamSpec *pspec,  gpointer user_data)


Again you are comparing constant string pointers. As these are pointers that are created from different sources they will always be different and will never compare true. To be more accurate you are comparing the address of "http://localhost/?i=logout" and the address of the result from webkit_web_view_get_uri(). I expect that you wanted to compare the strings and not the addresses. What you need to do is use something along the lines of
Code:
        if (g_strcmp0(uri, "http://localhost/?i=logout") == 0)

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 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