gint luaH_cookiejar_add_cookies(lua_State *L) { SoupCookieJar *sj = SOUP_COOKIE_JAR(soupconf.cookiejar); LuakitCookieJar *j = LUAKIT_COOKIE_JAR(soupconf.cookiejar); GSList *cookies; gboolean silent = TRUE; /* cookies table */ luaH_checktable(L, 1); /* optional silent parameter */ if (lua_gettop(L) >= 2) silent = luaH_checkboolean(L, 2); /* get cookies from table */ if ((cookies = cookies_from_table(L, 1))) { j->silent = silent; /* insert cookies */ for (GSList *p = cookies; p; p = g_slist_next(p)) soup_cookie_jar_add_cookie(sj, soup_cookie_copy(p->data)); g_slist_free(cookies); j->silent = FALSE; } return 0; }
static gint luaH_box_pack(lua_State *L) { widget_t *w = luaH_checkwidget(L, 1); widget_t *child = luaH_checkwidget(L, 2); gint top = lua_gettop(L); gboolean expand = FALSE, fill = FALSE, start = TRUE; guint padding = 0; /* check for options table */ if (top > 2 && !lua_isnil(L, 3)) { luaH_checktable(L, 3); /* pack child from start or end of container? */ if (luaH_rawfield(L, 3, "from")) start = L_TK_END == l_tokenize(lua_tostring(L, -1)) ? FALSE : TRUE; /* expand? */ if (luaH_rawfield(L, 3, "expand")) expand = lua_toboolean(L, -1) ? TRUE : FALSE; /* fill? */ if (luaH_rawfield(L, 3, "fill")) fill = lua_toboolean(L, -1) ? TRUE : FALSE; /* padding? */ if (luaH_rawfield(L, 3, "padding")) padding = (guint)lua_tonumber(L, -1); /* return stack to original state */ lua_settop(L, top); } if (start) gtk_box_pack_start(GTK_BOX(w->widget), GTK_WIDGET(child->widget), expand, fill, padding); else gtk_box_pack_end(GTK_BOX(w->widget), GTK_WIDGET(child->widget), expand, fill, padding); return 0; }
static gint luaH_label_set_padding(lua_State *L, widget_t *w) { luaH_checktable(L, 3); /* get old padding values */ gint xpad = 0, ypad = 0; gtk_misc_get_padding(GTK_MISC(w->widget), &xpad, &ypad); /* get padding.x */ if (luaH_rawfield(L, 3, "x")) { xpad = (gint) lua_tonumber(L, -1); lua_pop(L, 1); } /* get padding.y */ if (luaH_rawfield(L, 3, "y")) { ypad = (gint) lua_tonumber(L, -1); lua_pop(L, 1); } gtk_misc_set_padding(GTK_MISC(w->widget), xpad, ypad); return 0; }
static gint luaH_label_set_align(lua_State *L, widget_t *w) { luaH_checktable(L, 3); /* get old alignment values */ gfloat xalign, yalign; gtk_misc_get_alignment(GTK_MISC(w->widget), &xalign, &yalign); /* get align.x */ if (luaH_rawfield(L, 3, "x")) { xalign = (gfloat) lua_tonumber(L, -1); lua_pop(L, 1); } /* get align.y */ if (luaH_rawfield(L, 3, "y")) { yalign = (gfloat) lua_tonumber(L, -1); lua_pop(L, 1); } gtk_misc_set_alignment(GTK_MISC(w->widget), xalign, yalign); return 0; }
static gint luaH_document_highlight_match(lua_State *L) { document_data_t *d = luaH_checkdocument_data(L, 1); luaH_checktable(L, 2); // TODO: handle this without __data and remove __data again lua_pushstring(L, "page"); lua_gettable(L, -2); lua_pushstring(L, "__data"); lua_rawget(L, -2); page_info_t *p = lua_touserdata(L, -1); lua_pop(L, 2); lua_pushstring(L, "match"); lua_gettable(L, -2); GList *match = lua_touserdata(L, -1); lua_pop(L, 1); if (!match || !p) luaL_typerror(L, 2, "search match"); d->current_match = match; /* scroll to match */ PopplerRectangle *r = (PopplerRectangle*) match->data; cairo_rectangle_t *pc = page_coordinates_from_pdf_coordinates(r, p); cairo_rectangle_t *dc = document_coordinates_from_page_coordinates(pc, p); gint clamp_margin = 10; gtk_adjustment_clamp_page(d->hadjust, dc->x - clamp_margin, dc->x + dc->width + clamp_margin); gtk_adjustment_clamp_page(d->vadjust, dc->y - clamp_margin, dc->y + dc->height + clamp_margin); g_free(dc); g_free(pc); document_render(d); return 0; }