Exemple #1
0
static void
webview_set_history(lua_State *L, WebKitWebView *view, gint idx)
{
    gint pos, bflen;
    WebKitWebBackForwardList *bflist;
    WebKitWebHistoryItem *item = NULL;
    gchar *uri = NULL;

    if(!lua_istable(L, idx))
        luaL_error(L, "invalid history table");

    /* get history items table */
    lua_pushliteral(L, "items");
    lua_rawget(L, idx);
    bflen = lua_objlen(L, -1);

    /* create new back-forward history list */
    bflist = webkit_web_back_forward_list_new_with_web_view(view);
    webkit_web_back_forward_list_clear(bflist);

    /* get position of current history item */
    lua_pushliteral(L, "index");
    lua_rawget(L, idx);
    pos = (gint)lua_tonumber(L, -1);
    /* load last item if out of range */
    pos = (pos < 1 || pos > bflen) ? 0 : pos - bflen;
    lua_pop(L, 1);

    /* now we actually set the history to the content of the list */
    for (gint i = 1; i <= bflen; i++) {
        lua_rawgeti(L, -1, i);
        lua_pushliteral(L, "title");
        lua_rawget(L, -2);
        lua_pushliteral(L, "uri");
        lua_rawget(L, -3);
        if (pos || i < bflen) {
            item = webkit_web_history_item_new_with_data(lua_tostring(L, -1), NONULL(lua_tostring(L, -2)));
            webkit_web_back_forward_list_add_item(bflist, item);
        } else
            uri = g_strdup(lua_tostring(L, -1));
        lua_pop(L, 3);
    }

    /* load last item */
    if (uri) {
        webkit_web_view_load_uri(view, uri);
        g_free(uri);

    /* load item in history */
    } else if (bflen && webkit_web_view_can_go_back_or_forward(view, pos)) {
        webkit_web_view_go_back_or_forward(view, pos);

    /* load "about:blank" on empty history list */
    } else
        webkit_web_view_load_uri(view, "about:blank");

    lua_pop(L, 1);
}
Exemple #2
0
void wp_init()
{
	GError *error = NULL;
	GtkWidget *sw =gtk_scrolled_window_new(NULL,NULL);
	char *l;

	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	wp_vbox = gtk_vbox_new(FALSE, 6);
	moz = webkit_web_view_new();//moz_new();
	if(moz == NULL)
	{
	}
	webkit_web_view_can_go_back_or_forward(WEBKIT_WEB_VIEW(moz), 0);

	gtk_container_add(GTK_CONTAINER(sw), moz);
	gtk_box_pack_start_defaults(GTK_BOX(wp_vbox), sw);
	pgb = gtk_progress_bar_new();
	gtk_box_pack_start(GTK_BOX(wp_vbox), pgb, FALSE, TRUE, 0);
	gtk_widget_grab_focus (GTK_WIDGET (moz));
	g_signal_connect(moz, "load_progress_changed", G_CALLBACK(wp_progress), NULL);
	g_signal_connect(moz, "load_finished", G_CALLBACK(wp_progress_finished), NULL);
	g_signal_connect(moz, "load_started", G_CALLBACK(wp_progress_started), NULL);
	g_signal_connect(moz, "navigation-requested", G_CALLBACK(wp_navigation_requested), NULL);
	gtk_widget_show_all(wp_vbox);
	gtk_widget_hide(pgb);
	g_object_ref(G_OBJECT(wp_vbox));
	old_artist = g_strdup("NONE");
	/* we should add inernationalized artist|band|musician|singer|rapper|group in the regex */
	page_guess_re = g_regex_new("\\(.*(artist|band|musician|singer|rapper|group).*\\)", G_REGEX_CASELESS, 0, &error);

	strcpy(locale,"en");
	/*find locale */
	l = setlocale(LC_ALL,"");
	if(l!=NULL)
	{
		int i;
		for (i = 0; i < sizeof(wikipedia_langs) / sizeof(char *); i++) {
			if (strncmp(l, wikipedia_langs[i], 2) == 0) {
				strncpy(locale,l,2);
				locale[2] = 0;
				break;
			}
		}
	}
}