merged, now has download bar, other misc fixes
This commit is contained in:
parent
92e8fd101c
commit
b6e181e82a
2
Makefile
2
Makefile
|
@ -31,7 +31,7 @@ clean:
|
||||||
dist: clean
|
dist: clean
|
||||||
@echo creating dist tarball
|
@echo creating dist tarball
|
||||||
@mkdir -p surf-${VERSION}
|
@mkdir -p surf-${VERSION}
|
||||||
@cp -R LICENSE Makefile README config.def.h config.mk \
|
@cp -R LICENSE Makefile README config.mk \
|
||||||
surf.1 ${SRC} surf-${VERSION}
|
surf.1 ${SRC} surf-${VERSION}
|
||||||
@tar -cf surf-${VERSION}.tar surf-${VERSION}
|
@tar -cf surf-${VERSION}.tar surf-${VERSION}
|
||||||
@gzip surf-${VERSION}.tar
|
@gzip surf-${VERSION}.tar
|
||||||
|
|
10
config.mk
10
config.mk
|
@ -16,11 +16,11 @@ INCS = -I. -I/usr/include ${GTKINC}
|
||||||
LIBS = -L/usr/lib -lc ${GTKLIB}
|
LIBS = -L/usr/lib -lc ${GTKLIB}
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
|
CPPFLAGS = -DVERSION=\"${VERSION}\"
|
||||||
#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
||||||
CFLAGS = -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
|
#CFLAGS = -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
|
||||||
#LDFLAGS = -s ${LIBS}
|
LDFLAGS = -s ${LIBS}
|
||||||
LDFLAGS = ${LIBS}
|
#LDFLAGS = ${LIBS}
|
||||||
|
|
||||||
# Solaris
|
# Solaris
|
||||||
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
|
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
|
||||||
|
|
68
surf.c
68
surf.c
|
@ -21,15 +21,15 @@
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
Atom urlprop;
|
Atom urlprop;
|
||||||
typedef struct Client {
|
typedef struct Client {
|
||||||
GtkWidget *win, *scroll, *vbox, *urlbar, *searchbar;
|
GtkWidget *win, *scroll, *vbox, *pbar, *urlbar, *searchbar;
|
||||||
WebKitWebView *view;
|
WebKitWebView *view;
|
||||||
WebKitDownload * dl;
|
|
||||||
gchar *title;
|
gchar *title;
|
||||||
gint progress;
|
gint progress;
|
||||||
struct Client *next;
|
struct Client *next;
|
||||||
} Client;
|
} Client;
|
||||||
SoupCookieJar *cookiejar;
|
SoupCookieJar *cookiejar;
|
||||||
Client *clients = NULL;
|
Client *clients = NULL;
|
||||||
|
GSList *downloads = NULL;
|
||||||
gboolean embed = FALSE;
|
gboolean embed = FALSE;
|
||||||
gboolean showxid = FALSE;
|
gboolean showxid = FALSE;
|
||||||
gboolean ignore_once = FALSE;
|
gboolean ignore_once = FALSE;
|
||||||
|
@ -37,12 +37,10 @@ extern char *optarg;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
|
|
||||||
static void cleanup(void);
|
static void cleanup(void);
|
||||||
static gboolean decidewindow(WebKitWebView *view, WebKitWebFrame *f,
|
|
||||||
WebKitNetworkRequest *r, WebKitWebNavigationAction *n,
|
|
||||||
WebKitWebPolicyDecision *p, gpointer d);
|
|
||||||
static void destroyclient(Client *c);
|
static void destroyclient(Client *c);
|
||||||
static void destroywin(GtkWidget* w, gpointer d);
|
static void destroywin(GtkWidget* w, gpointer d);
|
||||||
static void die(char *str);
|
static void die(char *str);
|
||||||
|
static void downloadcb(WebKitDownload *o, GParamSpec *pspec, gpointer d);
|
||||||
static gboolean download(WebKitWebView *view, WebKitDownload *o, gpointer d);
|
static gboolean download(WebKitWebView *view, WebKitDownload *o, gpointer d);
|
||||||
static gchar *geturi(Client *c);
|
static gchar *geturi(Client *c);
|
||||||
static void hidesearch(Client *c);
|
static void hidesearch(Client *c);
|
||||||
|
@ -66,14 +64,7 @@ void
|
||||||
cleanup(void) {
|
cleanup(void) {
|
||||||
while(clients)
|
while(clients)
|
||||||
destroyclient(clients);
|
destroyclient(clients);
|
||||||
}
|
g_slist_free(downloads);
|
||||||
|
|
||||||
gboolean
|
|
||||||
decidewindow(WebKitWebView *view, WebKitWebFrame *f,
|
|
||||||
WebKitNetworkRequest *r, WebKitWebNavigationAction *n,
|
|
||||||
WebKitWebPolicyDecision *p, gpointer d) {
|
|
||||||
/* TODO */
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -83,6 +74,7 @@ destroyclient(Client *c) {
|
||||||
gtk_widget_destroy(GTK_WIDGET(webkit_web_view_new()));
|
gtk_widget_destroy(GTK_WIDGET(webkit_web_view_new()));
|
||||||
gtk_widget_destroy(c->scroll);
|
gtk_widget_destroy(c->scroll);
|
||||||
gtk_widget_destroy(c->urlbar);
|
gtk_widget_destroy(c->urlbar);
|
||||||
|
gtk_widget_destroy(c->pbar);
|
||||||
gtk_widget_destroy(c->searchbar);
|
gtk_widget_destroy(c->searchbar);
|
||||||
gtk_widget_destroy(c->vbox);
|
gtk_widget_destroy(c->vbox);
|
||||||
gtk_widget_destroy(c->win);
|
gtk_widget_destroy(c->win);
|
||||||
|
@ -108,20 +100,52 @@ void die(char *str) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
downloadcb(WebKitDownload *o, GParamSpec *pspec, gpointer d) {
|
||||||
|
Client *c = (Client *) d;
|
||||||
|
GSList *i;
|
||||||
|
WebKitDownload *dl;
|
||||||
|
GString *text;
|
||||||
|
|
||||||
|
text = g_string_new("");
|
||||||
|
for (i = downloads; i != NULL; i = i->next) {
|
||||||
|
dl = i->data;
|
||||||
|
if (webkit_download_get_status(dl) == WEBKIT_DOWNLOAD_STATUS_STARTED
|
||||||
|
|| webkit_download_get_status(dl) == WEBKIT_DOWNLOAD_STATUS_CREATED) {
|
||||||
|
g_string_append_printf(text, "%s[%.0f%%] ",
|
||||||
|
webkit_download_get_suggested_filename(dl),
|
||||||
|
webkit_download_get_progress(dl)*100);
|
||||||
|
} else {
|
||||||
|
downloads = g_slist_remove(downloads, dl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (downloads == NULL) {
|
||||||
|
gtk_label_set_text((GtkLabel *) c->pbar, "");
|
||||||
|
gtk_widget_hide(c->pbar);
|
||||||
|
} else {
|
||||||
|
gtk_label_set_text((GtkLabel *) c->pbar, text->str);
|
||||||
|
}
|
||||||
|
g_string_free(text, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
download(WebKitWebView *view, WebKitDownload *o, gpointer d) {
|
download(WebKitWebView *view, WebKitDownload *o, gpointer d) {
|
||||||
/* TODO */
|
/* TODO */
|
||||||
|
Client *c = (Client *) d;
|
||||||
const gchar *home;
|
const gchar *home;
|
||||||
gchar *uri, *filename;
|
gchar *uri, *filename;
|
||||||
|
|
||||||
home = g_get_home_dir();
|
home = g_get_home_dir();
|
||||||
filename = g_build_filename(home, ".surf", "dl",
|
filename = g_build_filename(home, ".surf", "dl",
|
||||||
webkit_download_get_suggested_filename(o), NULL);
|
webkit_download_get_suggested_filename(o), NULL);
|
||||||
g_mkdir(g_path_get_dirname(filename), 0755);
|
|
||||||
uri = g_strconcat("file://", filename, NULL);
|
uri = g_strconcat("file://", filename, NULL);
|
||||||
webkit_download_set_destination_uri(o, uri);
|
webkit_download_set_destination_uri(o, uri);
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
g_free(uri);
|
g_free(uri);
|
||||||
|
downloads = g_slist_append(downloads, o);
|
||||||
|
gtk_widget_show(c->pbar);
|
||||||
|
g_signal_connect(o, "notify::progress", G_CALLBACK(downloadcb), d);
|
||||||
|
g_signal_connect(o, "notify::status", G_CALLBACK(downloadcb), d);
|
||||||
webkit_download_start(o);
|
webkit_download_start(o);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +329,6 @@ newclient(void) {
|
||||||
g_signal_connect(G_OBJECT(c->view), "load-committed", G_CALLBACK(loadcommit), c);
|
g_signal_connect(G_OBJECT(c->view), "load-committed", G_CALLBACK(loadcommit), c);
|
||||||
g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
|
g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
|
||||||
g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(newwindow), c);
|
g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(newwindow), c);
|
||||||
g_signal_connect(G_OBJECT(c->view), "new-window-policy-decision-requested", G_CALLBACK(decidewindow), c);
|
|
||||||
g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(download), c);
|
g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(download), c);
|
||||||
|
|
||||||
/* urlbar */
|
/* urlbar */
|
||||||
|
@ -316,20 +339,26 @@ newclient(void) {
|
||||||
c->searchbar = gtk_entry_new();
|
c->searchbar = gtk_entry_new();
|
||||||
gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE);
|
gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE);
|
||||||
|
|
||||||
|
/* downloadbar */
|
||||||
|
c->pbar = gtk_label_new("");
|
||||||
|
|
||||||
/* Arranging */
|
/* Arranging */
|
||||||
gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view));
|
gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view));
|
||||||
gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
|
gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
|
||||||
gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
|
gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
|
||||||
gtk_container_add(GTK_CONTAINER(c->vbox), c->searchbar);
|
gtk_container_add(GTK_CONTAINER(c->vbox), c->searchbar);
|
||||||
gtk_container_add(GTK_CONTAINER(c->vbox), c->urlbar);
|
gtk_container_add(GTK_CONTAINER(c->vbox), c->urlbar);
|
||||||
|
gtk_container_add(GTK_CONTAINER(c->vbox), c->pbar);
|
||||||
|
|
||||||
/* Setup */
|
/* Setup */
|
||||||
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->urlbar, FALSE, FALSE, 0, GTK_PACK_START);
|
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->urlbar, FALSE, FALSE, 0, GTK_PACK_START);
|
||||||
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->searchbar, FALSE, FALSE, 0, GTK_PACK_START);
|
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->searchbar, FALSE, FALSE, 0, GTK_PACK_START);
|
||||||
|
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->pbar, FALSE, FALSE, 0, GTK_PACK_START);
|
||||||
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START);
|
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START);
|
||||||
gtk_widget_grab_focus(GTK_WIDGET(c->view));
|
gtk_widget_grab_focus(GTK_WIDGET(c->view));
|
||||||
gtk_widget_hide_all(c->searchbar);
|
gtk_widget_hide_all(c->searchbar);
|
||||||
gtk_widget_hide_all(c->urlbar);
|
gtk_widget_hide_all(c->urlbar);
|
||||||
|
gtk_widget_hide_all(c->pbar);
|
||||||
gtk_widget_show(c->vbox);
|
gtk_widget_show(c->vbox);
|
||||||
gtk_widget_show(c->scroll);
|
gtk_widget_show(c->scroll);
|
||||||
gtk_widget_show(GTK_WIDGET(c->view));
|
gtk_widget_show(GTK_WIDGET(c->view));
|
||||||
|
@ -469,11 +498,16 @@ int main(int argc, char *argv[]) {
|
||||||
if(!clients)
|
if(!clients)
|
||||||
newclient();
|
newclient();
|
||||||
|
|
||||||
|
/* make dirs */
|
||||||
|
home = g_get_home_dir();
|
||||||
|
filename = g_build_filename(home, ".surf", NULL);
|
||||||
|
g_mkdir_with_parents(filename, 0711);
|
||||||
|
filename = g_build_filename(home, ".surf", "dl", NULL);
|
||||||
|
g_mkdir_with_parents(filename, 0755);
|
||||||
|
|
||||||
/* cookie persistance */
|
/* cookie persistance */
|
||||||
s = webkit_get_default_session();
|
s = webkit_get_default_session();
|
||||||
home = g_get_home_dir();
|
|
||||||
filename = g_build_filename(home, ".surf", "cookies", NULL);
|
filename = g_build_filename(home, ".surf", "cookies", NULL);
|
||||||
g_mkdir(g_path_get_dirname(filename), 0755);
|
|
||||||
cookiejar = soup_cookie_jar_text_new(filename, FALSE);
|
cookiejar = soup_cookie_jar_text_new(filename, FALSE);
|
||||||
soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
|
soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user