Commit 386262d6 authored by Moritz Sokoll's avatar Moritz Sokoll 💬
Browse files

added tab creation and numbered tab titles

parent 90534b68
Pipeline #221 failed with stages
in 7 minutes and 13 seconds
SRC = src/help.cpp src/values.cpp src/tabs.cpp src/main.cpp
SRC = src/help.cpp src/config.cpp src/values.cpp src/tabs.cpp src/main.cpp
DEPS = gtk+-3.0 webkit2gtk-4.0
CFLAGS = -fpermissive `pkg-config --cflags --libs $(DEPS)` -g
OUTF = -o bin/gwebb
OUTF = -o bin/gweb
CC = g++
DESTDIR ?= /usr/bin/
build:
$(CC) $(CFLAGS) $(SRC) $(OUTF)
all: build
install: build man
mv $(OUTF) $(DESTDIR)
man:
mkdir -p /usr/local/man/man1
cp gweb.man /usr/local/man/man1/gweb.1
gzip /usr/local/man/man1/gweb.1
mandb
.TH "gweb" "16" "May 2021" "gweb 0.1.1" ""
.hy
.SH NAME
.PP
gweb \[en] a simple gtk/WebKitGtk based browser
.SH SYNOPSIS
.PP
\f[B]gweb\f[R] [OPTION] [URL]
\f[B]gweb-bm\f[R] [OPTION] BOOKMARK
.SH DESCRIPTION
\f[B]gweb\f[R] is a simple mostly keyboard and url-bar driven browser using Gtk and WebKitGtk as the frontend.
It also comes with \f[B]gweb-bm\f[R] for bookmarking
.SH OPTIONS
\f[B]--help\f[R],\f[B] -h\f[R]: displays a help message
\f[B]--version\f[R],\f[B] -v\f[R]: displays a help message
#include "libgweb/config.hpp"
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
namespace libgweb {
Config::Config(const char *default_url_p, const char *search_engine_url_p) {
default_url = default_url_p;
search_engine_url = search_engine_url_p;
}
//libgweb::Config parse_config_file(const char* path) {}
}
......@@ -41,15 +41,4 @@ namespace libgweb {
}
}
//returns a connected string of str_a and str_b
char* strconnect(const char* str_a, const char* str_b) {
char strbuf[sizeof(str_a) + sizeof(str_b)] = { ' ' };
for(int i=0; i<libgweb::strlen(str_a); i++) {
strbuf[i] = str_a[i];
}
for(int i=0; i<libgweb::strlen(str_b); i++) {
strbuf[libgweb::strlen(str_a)+i] = str_b[i];
}
return strbuf;
}
}
/*
definition for a config File parser
*/
namespace libgweb {
class Config {
public:
char *default_url;
char *search_engine_url;
Config(const char *default_url, const char *search_engine_url);
};
//libgweb::Config parse_config_file(const char *path);
}
......@@ -8,7 +8,6 @@ namespace libgweb {
int strlen(const char* instr);
std::vector<char*> split(const char* instr, const char delim);
bool strstartswith(const char* str_a, const char* str_b);
char* strconnect(const char* str_a, const char* str_b);
}
#endif
......@@ -8,11 +8,18 @@ uses the namespace libgweb
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
namespace libgweb {
/*typedef struct {
GtkNotebook *notebook;
GtkEntry *entry;
WebKitWebView *webview;
GtkBox *box;
} Tab;*/
int create_tab(GtkNotebook *notebook, const char* uri, const char* title);
void web_view_load_changed(WebKitWebView *webview,
WebKitLoadEvent loadevent,
gpointer userdata);
void entry_uri_update(GtkEntry *entry, gpointer userdata);
//void update_tab_title(WebKitWebView *webview, WebKitLoadEvent loadevent, Tab *userdata);
}
#endif
......@@ -7,10 +7,16 @@
#include "libgweb/tabs.hpp"
using namespace std;
static void destroy( GtkWidget *widget, gpointer data) { gtk_main_quit(); }
void create_tab(GtkButton *button, gpointer user_data) {
string tabnum = to_string(gtk_notebook_get_n_pages(GTK_NOTEBOOK(user_data)) + 1);
string tabname = "Tab " + tabnum;
libgweb::create_tab(GTK_NOTEBOOK(user_data), "https://duckduckgo.com", tabname.c_str());
}
int main(int argc, char* argv[]) {
GtkWidget *window, *notebook;
GtkWidget *window, *notebook, *addbtn;
bool gui = true;
......@@ -30,26 +36,38 @@ int main(int argc, char* argv[]) {
//check if the last argument is a uri/url and try using it if so
string uri;
if (argc >= 2) {
if (argv[argc-1][0] != '-') { uri = argv[argc-1]; } else { uri = "https://google.com"; }
if (argv[argc-1][0] != '-') { uri = argv[argc-1]; } else { uri = "https://duckduckgo.com"; }
} else {
uri = "https://google.com";
uri = "https://duckduckgo.com";
}
if (!gui) { return 0; }
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
notebook = gtk_notebook_new();
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
addbtn = gtk_button_new_with_label("new tab");
gtk_notebook_set_action_widget(GTK_NOTEBOOK(notebook), addbtn, GTK_PACK_END);
gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), true);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(G_OBJECT(addbtn), "clicked", G_CALLBACK(create_tab), notebook);
//setting window properties
gtk_window_set_title(GTK_WINDOW(window), "gweb");
gtk_window_set_default_size(GTK_WINDOW(window), 600, 800);
//adding widgets to their parents if needed
gtk_container_add(GTK_CONTAINER(window), notebook);
string tabnum = to_string(gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook)) + 1);
string tabname = "Tab " + tabnum;
libgweb::create_tab(GTK_NOTEBOOK(notebook), uri.c_str(), "Tab 1");
//displaying the widgets
gtk_widget_show(window);
gtk_widget_show(notebook);
gtk_widget_show(addbtn);
//running the gui application
gtk_main();
......
......@@ -7,6 +7,7 @@ uses the namespace libgweb
#include "libgweb/help.hpp"
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
#include <string>
void libgweb::web_view_load_changed(WebKitWebView *webview, WebKitLoadEvent loadevent, gpointer userdata) {
switch (loadevent) {
......@@ -25,16 +26,38 @@ void libgweb::web_view_load_changed(WebKitWebView *webview, WebKitLoadEvent load
}
void libgweb::entry_uri_update(GtkEntry *entry, gpointer userdata) {
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(userdata), gtk_entry_get_text(entry));
std::string url(gtk_entry_get_text(entry));
if (!libgweb::strstartswith(url.c_str(), "http://") && !libgweb::strstartswith(url.c_str(), "https://")) {
url = "http://" + url;
}
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(userdata), url.c_str());
}
/*void libgweb::update_tab_title(WebKitWebView *webview, WebKitLoadEvent loadevent, libgweb::Tab *userdata) {
switch(loadevent) {
case WEBKIT_LOAD_STARTED:
gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(*userdata->notebook), *userdata->box, webkit_web_view_get_uri(webview));
break;
case WEBKIT_LOAD_REDIRECTED:
gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(*userdata->notebook), *userdata->box, webkit_web_view_get_uri(webview));
break;
case WEBKIT_LOAD_COMMITTED:
gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(*userdata->notebook), *userdata->box, webkit_web_view_get_uri(webview));
break;
case WEBKIT_LOAD_FINISHED:
gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(*userdata->notebook), *userdata->box, webkit_web_view_get_uri(webview));
break;
}
}*/
int libgweb::create_tab(GtkNotebook *notebook, const char* uri, const char* title) {
char* url = uri;
if (!libgweb::strstartswith(url, "http://") || !libgweb::strstartswith(url, "https://")) {
url = libgweb::strconnect("http://", url);
std::string url(uri);
if (!libgweb::strstartswith(url.c_str(), "http://") && !libgweb::strstartswith(url.c_str(), "https://")) {
url = "http://" + url;
}
//we need a webview for viewing the web, an entry as a url bar and a box to pack them in
GtkWidget *webview, *box, *entry;
//we need a webview for viewing the web, an entry as a url bar, a progress bar and a box to pack them in
GtkWidget *webview, *box, *entry, *progress_bar;
webview = webkit_web_view_new();
......@@ -47,14 +70,20 @@ int libgweb::create_tab(GtkNotebook *notebook, const char* uri, const char* titl
gtk_box_pack_start(GTK_BOX(box), entry, false, false, 0);
gtk_box_pack_end(GTK_BOX(box), webview, true, true, 0);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), url);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), url.c_str());
//set the text of the entry to be the url
gtk_entry_set_text(GTK_ENTRY(entry), url);
gtk_entry_set_text(GTK_ENTRY(entry), url.c_str());
/*libgweb::Tab *tab_type;
tab_type->notebook = notebook;
tab_type->entry = GTK_ENTRY(entry);
tab_type->webview = WEBKIT_WEB_VIEW(webview);
tab_type->box = GTK_BOX(box);*/
int nbstat = gtk_notebook_append_page(GTK_NOTEBOOK(notebook), box, gtk_label_new(title));
g_signal_connect(G_OBJECT(webview), "load-changed", G_CALLBACK(libgweb::web_view_load_changed), entry);
//g_signal_connect(G_OBJECT(webview), "load-changed", G_CALLBACK(libgweb::update_tab_title), &tab_type);
g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(libgweb::entry_uri_update), webview);
gtk_widget_show_all(box);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment