Commit 90534b68 authored by Moritz Sokoll's avatar Moritz Sokoll 💬
Browse files

reimplemented tabbing | url bar works

parent 6b6feae6
Pipeline #220 failed with stages
in 1 minute and 53 seconds
SRC = src/main.cpp src/values.cpp src/tabs.cpp
SRC = src/help.cpp src/values.cpp src/tabs.cpp src/main.cpp
DEPS = gtk+-3.0 webkit2gtk-4.0
CFLAGS = -fpermissive `pkg-config --cflags --libs $(DEPS)`
CFLAGS = -fpermissive `pkg-config --cflags --libs $(DEPS)` -g
OUTF = -o bin/gwebb
DEBUGOUTF = -o bin/gwebb-debug
CC = g++
all:
build:
$(CC) $(CFLAGS) $(SRC) $(OUTF)
debug-build:
$(CC) $(CFLAGS) -g $(SRC) $(DEBUGOUTF)
all: build
......@@ -3,3 +3,11 @@
GwebB is a web browser created to be simple, fast and feature rich
### Features
- [x] Tabbing
- [ ] Adblocking
- [ ] Configuration
- [ ] Extensions/Scripting support
### libgweb
libgweb is a small library designed to abstract browser initalization, configuration and some basic helper functions
#include <vector>
#include "libgweb/help.hpp"
namespace libgweb {
int strlen(const char* instr) {
int count = 0;
while (instr[count] != '\0') {
count++;
}
return count;
}
std::vector<char*> split(const char* instr, const char delim=' ') {
char* strbuf;
std::vector<char*> out;
for (int i=0; i<strlen(instr); i++) {
if (instr[i] == delim) {
out.push_back(strbuf);
strbuf = "";
} else {
strbuf += instr[i];
}
}
return out;
}
//checks if str_a startswith str_b
bool strstartswith(const char* str_a, const char* str_b) {
if(libgweb::strlen(str_b) > libgweb::strlen(str_a)) {
return false;
} else {
bool startswith = true;
for(int i=0; i<libgweb::strlen(str_b); i++) {
if(str_b[i] != str_a[i]) {
startswith = false;
break;
}
}
return startswith;
}
}
//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;
}
}
#ifndef GWEBB_TABS_H
#define GWEBB_TABS_H
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
namespace libgweb {
int createTab(GtkNotebook *notebook, const char* uri, const char* title);
void changeTabTitle(GtkWidget *webview, gpointer data);
}
#endif
/*
help defines a few helper functions for gweb
*/
#ifndef GWEB_HELP_H
#define GWEB_HELP_H
#include <vector>
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
/*
tabs.h
declares functions for the easier creation of tabs
uses the namespace libgweb
*/
#ifndef GWEB_TABS_H
#define GWEB_TABS_H
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
namespace libgweb {
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);
}
#endif
#ifndef GWEBB_VALUES_H
#define GWEBB_VALUES_H
/*
values.hpp
contains never switching values in regard to gwebb
constants are put under the namespace libgweb
*/
#ifndef GWEB_VALUES_H
#define GWEB_VALUES_H
namespace libgweb {
extern const char* GWEBB_VERSION_STR;
extern const char* GWEBB_HELP_STR;
......
......@@ -3,14 +3,14 @@
#include <stdio.h>
#include <string.h>
#include <iostream>
#include "lib/values.hpp"
#include "lib/tabs.hpp"
#include "libgweb/values.hpp"
#include "libgweb/tabs.hpp"
using namespace std;
static void destroy( GtkWidget *widget, gpointer data) { gtk_main_quit(); }
int main(int argc, char* argv[]) {
GtkWidget* notebook, *window;
GtkWidget *window, *notebook;
bool gui = true;
......@@ -21,27 +21,32 @@ int main(int argc, char* argv[]) {
printf("GWebB Version: %s\n", libgweb::GWEBB_VERSION_STR);
gui = false;
}
else if (arg == (string) "-h" || arg == (string) "--help") {
} else if (arg == (string) "-h" || arg == (string) "--help") {
printf("%s\n", libgweb::GWEBB_HELP_STR);
gui = false;
}
}
//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"; }
} else {
uri = "https://google.com";
}
if (!gui) {return 0;}
if (!gui) { return 0; }
gtk_init(&argc, &argv);
//create the notebook widget with one page
notebook = gtk_notebook_new();
int nbstat = libgweb::createTab(GTK_NOTEBOOK(notebook), "https://google.de", "test sheesh");
if (nbstat == -1) { printf("gtk notebook page appending failed"); return 1; }
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
notebook = gtk_notebook_new();
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
//adding widgets to their parents if needed
gtk_container_add(GTK_CONTAINER(window), notebook);
libgweb::create_tab(GTK_NOTEBOOK(notebook), uri.c_str(), "Tab 1");
//displaying the widgets
gtk_widget_show(window);
gtk_widget_show(notebook);
......
#include "lib/tabs.hpp"
/*
tabs.cpp
defines functions for the easier creation of tabs
uses the namespace libgweb
*/
#include "libgweb/tabs.hpp"
#include "libgweb/help.hpp"
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
void libgweb::changeTabTitle(GtkWidget *webview, gpointer data) {
gtk_notebook_set_tab_label(GTK_NOTEBOOK(data),
webview,
gtk_label_new(webkit_web_view_get_title(WEBKIT_WEB_VIEW(webview)
)));
void libgweb::web_view_load_changed(WebKitWebView *webview, WebKitLoadEvent loadevent, gpointer userdata) {
switch (loadevent) {
case WEBKIT_LOAD_STARTED:
gtk_entry_set_text(GTK_ENTRY(userdata), webkit_web_view_get_uri(webview));
break;
case WEBKIT_LOAD_REDIRECTED:
gtk_entry_set_text(GTK_ENTRY(userdata), webkit_web_view_get_uri(webview));
break;
case WEBKIT_LOAD_COMMITTED:
gtk_entry_set_text(GTK_ENTRY(userdata), webkit_web_view_get_uri(webview));
break;
case WEBKIT_LOAD_FINISHED:
break;
}
}
int libgweb::createTab(GtkNotebook *notebook, const char* uri, const char* title) {
void libgweb::entry_uri_update(GtkEntry *entry, gpointer userdata) {
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(userdata), gtk_entry_get_text(entry));
}
//TODO: add all Widgets
GtkWidget *webview, *grid, *uribar, *backbtn, *forwardbtn, *reloadbtn;
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);
}
//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;
webview = webkit_web_view_new();
uribar = gtk_entry_new();
backbtn = gtk_button_new_from_icon_name("go-previous", GTK_ICON_SIZE_SMALL_TOOLBAR);
forwardbtn = gtk_button_new_from_icon_name("go-next", GTK_ICON_SIZE_SMALL_TOOLBAR);
reloadbtn = gtk_button_new_from_icon_name("view-refresh", GTK_ICON_SIZE_SMALL_TOOLBAR);
//TODO: Implement grid for all widgets
grid = gtk_grid_new();
//append children
gtk_grid_attach(GTK_GRID(grid), uribar, 3, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), webview, 0, 1, 3, 1);
gtk_grid_attach(GTK_GRID(grid), backbtn, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), forwardbtn, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), reloadbtn, 0, 2, 1, 1);
//enable devtools
WebKitSettings *settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview));
g_object_set(G_OBJECT(settings), "enable-developer-extras", true, NULL);
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
entry = gtk_entry_new();
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), uri);
int nbstat = gtk_notebook_append_page(GTK_NOTEBOOK(notebook), grid, gtk_label_new(title));
g_signal_connect(G_OBJECT(webview), "notify::title", G_CALLBACK(changeTabTitle), (gpointer ) notebook);
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);
//set the text of the entry to be the url
gtk_entry_set_text(GTK_ENTRY(entry), url);
int nbstat = gtk_notebook_append_page(GTK_NOTEBOOK(notebook), box, gtk_label_new(title));
gtk_widget_show(uribar);
//gtk_widget_show(webview);
gtk_widget_show(grid);
g_signal_connect(G_OBJECT(webview), "load-changed", G_CALLBACK(libgweb::web_view_load_changed), entry);
g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(libgweb::entry_uri_update), webview);
gtk_widget_show_all(box);
return nbstat;
}
#include "lib/values.hpp"
/*
values.cpp
contains constants in regard to gwebb
constants are put under the namespace libgweb
*/
#include "libgweb/values.hpp"
const char* libgweb::GWEBB_VERSION_STR = "0.0.1";
const char* libgweb::GWEBB_HELP_STR = "Usage: gwebb [option] [url]\n"
"Options:\n"
......
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