panthera-www.cc
C++ source, ASCII text
1#include "gpanthera.hh" 2#include <gtkmm.h> 3#include <glibmm.h> 4#include <glibmm/ustring.h> 5#include <iostream> 6#include <memory> 7#include <libintl.h> 8#include <locale.h> 9#include <gtk/gtk.h> 10#include <gdk/gdk.h> 11#include <webkit/webkit.h> 12#include <fstream> 13#include <nlohmann/json.hpp> 14#include <iomanip> 15#include <sstream> 16#include <dlfcn.h> 17#include "plugin_api.h" 18 19using plugin_entrypoint_type = void(*)(void); 20 21std::string url_encode(const std::string &value) { 22// Thanks https://stackoverflow.com/a/17708801 23std::ostringstream escaped; 24escaped.fill('0'); 25escaped << std::hex; 26 27for(char c : value) { 28// Keep alphanumeric and other accepted characters intact 29if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { 30escaped << c; 31continue; 32} 33 34// Any other characters are percent-encoded 35escaped << std::uppercase; 36escaped << '%' << std::setw(2) << int((unsigned char) c); 37escaped << std::nouppercase; 38} 39 40return escaped.str(); 41} 42 43struct SearchEngine { 44Glib::ustring name; 45Glib::ustring url; 46Glib::ustring get_search_url(const std::string &query) { 47auto pos = url.find("%s"); 48if(pos == Glib::ustring::npos) { 49throw std::runtime_error("Invalid search engine URL: missing '%s' placeholder"); 50} 51auto new_url = url; 52new_url.replace(pos, 2, url_encode(query)); 53return new_url; 54} 55}; 56 57class PantheraWww : public Gtk::Application { 58Gtk::Window *window = Gtk::make_managed<Gtk::Window>(); 59protected: 60std::shared_ptr<gPanthera::LayoutManager> layout_manager; 61std::shared_ptr<gPanthera::ContentManager> content_manager; 62Gtk::Entry *url_bar = nullptr; 63std::string cookie_file = "cookies.txt"; 64std::vector<SearchEngine> search_engines; 65SearchEngine *default_search_engine = nullptr; 66 67static void notify_callback(GObject *object, GParamSpec *pspec, gpointer data) { 68if(!gtk_widget_get_parent(GTK_WIDGET(object))) { 69return; 70} 71auto parent = gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(object))); 72if(auto page = dynamic_cast<gPanthera::ContentPage*>(Glib::wrap(parent))) { 73if(g_strcmp0(pspec->name, "title") == 0) { 74if(auto label = dynamic_cast<Gtk::Label*>(page->tab_widget->get_last_child())) { 75if(strlen(webkit_web_view_get_title(WEBKIT_WEB_VIEW(object))) == 0) { 76label->set_label("Untitled"); 77} else { 78label->set_label(webkit_web_view_get_title(WEBKIT_WEB_VIEW(object))); 79} 80} 81} else if(g_strcmp0(pspec->name, "favicon") == 0) { 82// Update favicons 83if(auto image = dynamic_cast<Gtk::Image*>(page->tab_widget->get_first_child())) { 84image->set_from_icon_name("image-loading-symbolic"); 85if(auto favicon = webkit_web_view_get_favicon(WEBKIT_WEB_VIEW(object))) { 86if(G_IS_OBJECT(favicon)) { 87if(Glib::RefPtr<Gdk::Texture> texture = Glib::wrap(favicon)) { 88image->set(texture); 89} 90} 91} 92} 93} 94} 95} 96 97static void notify_focused_callback(GObject *object, GParamSpec *pspec, gpointer data) { 98if(!gtk_widget_get_parent(GTK_WIDGET(object))) { 99return; 100} 101auto this_ = static_cast<PantheraWww*>(data); 102auto parent = gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(object))); 103if(auto page = dynamic_cast<gPanthera::ContentPage*>(Glib::wrap(parent))) { 104if(g_strcmp0(pspec->name, "uri") == 0) { 105this_->url_bar->set_text(webkit_web_view_get_uri(WEBKIT_WEB_VIEW(object))); 106} 107} 108} 109 110static void on_back_pressed(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data) { 111WebKitWebView *webview = WEBKIT_WEB_VIEW(user_data); 112webkit_web_view_go_back(webview); 113} 114 115static void on_forward_pressed(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data) { 116WebKitWebView *webview = WEBKIT_WEB_VIEW(user_data); 117webkit_web_view_go_forward(webview); 118} 119 120static gboolean on_decide_policy(WebKitWebView *source, WebKitPolicyDecision *decision, WebKitPolicyDecisionType type, gpointer user_data) { 121// Middle-click opens in a new window 122if(auto self = static_cast<PantheraWww*>(user_data)) { 123if(type == WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) { 124auto action = webkit_navigation_policy_decision_get_navigation_action(WEBKIT_NAVIGATION_POLICY_DECISION(decision)); 125if(webkit_navigation_action_get_mouse_button(action) == 2) { 126Glib::ustring url = Glib::ustring(webkit_uri_request_get_uri(webkit_navigation_action_get_request(action))); 127self->on_new_tab(nullptr, url, false); 128webkit_policy_decision_ignore(decision); 129return true; 130} 131} else if(type == WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION) { 132auto action = webkit_navigation_policy_decision_get_navigation_action(WEBKIT_NAVIGATION_POLICY_DECISION(decision)); 133self->on_new_tab(nullptr, webkit_uri_request_get_uri(webkit_navigation_action_get_request(action)), false, true); 134return true; 135} 136} 137return false; 138} 139 140void on_new_tab(gPanthera::ContentStack *stack, const Glib::ustring &url = "about:blank", bool focus = true, bool new_window = false) { 141if(!stack) { 142// Find the current area 143stack = content_manager->get_last_operated_page()->get_stack(); 144} 145 146WebKitWebView *webview = WEBKIT_WEB_VIEW(webkit_web_view_new()); 147gtk_widget_set_hexpand(GTK_WIDGET(webview), true); 148gtk_widget_set_vexpand(GTK_WIDGET(webview), true); 149auto page_content = Gtk::make_managed<Gtk::Box>(); 150gtk_box_append(page_content->gobj(), GTK_WIDGET(webview)); 151auto page_tab = new Gtk::Box(); 152page_tab->set_orientation(Gtk::Orientation::HORIZONTAL); 153auto initial_icon = Gtk::make_managed<Gtk::Image>(Gio::Icon::create("image-loading-symbolic")); 154page_tab->append(*initial_icon); 155page_tab->append(*Gtk::make_managed<Gtk::Label>("Untitled")); 156page_tab->set_spacing(4); 157auto page = Gtk::make_managed<gPanthera::ContentPage>(content_manager, stack, page_content, page_tab); 158g_signal_connect(webview, "notify", G_CALLBACK(notify_callback), page->gobj()); 159g_signal_connect(webview, "decide-policy", G_CALLBACK(on_decide_policy), this); 160webkit_web_view_load_uri(webview, url.data()); 161auto cookie_manager = webkit_network_session_get_cookie_manager(webkit_web_view_get_network_session(webview)); 162webkit_cookie_manager_set_persistent_storage(cookie_manager, cookie_file.c_str(), WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT); 163webkit_cookie_manager_set_accept_policy(cookie_manager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); 164auto website_data_manager = webkit_network_session_get_website_data_manager(webkit_web_view_get_network_session(webview)); 165webkit_website_data_manager_set_favicons_enabled(website_data_manager, true); 166GtkEventController *click_controller_back = GTK_EVENT_CONTROLLER(gtk_gesture_click_new()); 167gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(click_controller_back), 8); 168g_signal_connect(click_controller_back, "pressed", G_CALLBACK(on_back_pressed), webview); 169gtk_widget_add_controller(GTK_WIDGET(webview), click_controller_back); 170 171GtkEventController *click_controller_forward = GTK_EVENT_CONTROLLER(gtk_gesture_click_new()); 172gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(click_controller_forward), 9); 173g_signal_connect(click_controller_forward, "pressed", G_CALLBACK(on_forward_pressed), webview); 174gtk_widget_add_controller(GTK_WIDGET(webview), click_controller_forward); 175 176stack->add_page(*page); 177if(focus) { 178stack->set_visible_child(*page); 179content_manager->set_last_operated_page(page); 180} 181if(new_window) { 182bool result = stack->signal_detach.emit(page); 183} 184} 185 186void on_startup() override { 187Gtk::Application::on_startup(); 188add_window(*window); 189window->set_default_size(600, 400); 190layout_manager = std::make_shared<gPanthera::LayoutManager>(); 191auto dock_stack_1 = Gtk::make_managed<gPanthera::DockStack>(layout_manager, "One", "one"); 192auto switcher_1 = Gtk::make_managed<gPanthera::DockStackSwitcher>(dock_stack_1, Gtk::Orientation::HORIZONTAL); 193auto dock_stack_2 = Gtk::make_managed<gPanthera::DockStack>(layout_manager, "Two", "two"); 194auto switcher_2 = Gtk::make_managed<gPanthera::DockStackSwitcher>(dock_stack_2, Gtk::Orientation::VERTICAL); 195auto pane_1_content = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 0); 196auto debug_button = Gtk::make_managed<Gtk::Button>("Debug"); 197pane_1_content->append(*debug_button); 198auto pane_2_content = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 0); 199auto test_notebook = Gtk::make_managed<Gtk::Notebook>(); 200test_notebook->append_page(*Gtk::make_managed<Gtk::Label>("Test 1"), *Gtk::make_managed<Gtk::Label>("Test 1")); 201pane_2_content->append(*test_notebook); 202auto pane_3_content = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 0); 203pane_3_content->append(*Gtk::make_managed<Gtk::Label>("Pane 3 content")); 204auto pane_1_icon = Gtk::make_managed<Gtk::Image>(); 205pane_1_icon->set_from_icon_name("go-home-symbolic"); 206auto pane_2_icon = Gtk::make_managed<Gtk::Image>(); 207pane_2_icon->set_from_icon_name("folder-symbolic"); 208auto pane_3_icon = Gtk::make_managed<Gtk::Image>(); 209pane_3_icon->set_from_icon_name("network-transmit-receive-symbolic"); 210auto pane_1 = Gtk::make_managed<gPanthera::DockablePane>(layout_manager, *pane_1_content, "pane1", "Pane 1", pane_1_icon); 211auto pane_2 = Gtk::make_managed<gPanthera::DockablePane>(layout_manager, *pane_2_content, "pane2", "Pane 2", pane_2_icon); 212auto pane_3 = Gtk::make_managed<gPanthera::DockablePane>(layout_manager, *pane_3_content, "pane3", "Pane 3", pane_3_icon); 213 214dock_stack_1->set_transition_type(Gtk::StackTransitionType::SLIDE_LEFT_RIGHT); 215dock_stack_1->set_transition_duration(125); 216dock_stack_1->set_expand(true); 217dock_stack_2->set_transition_type(Gtk::StackTransitionType::SLIDE_UP_DOWN); 218dock_stack_2->set_transition_duration(125); 219dock_stack_2->set_expand(true); 220 221auto outer_grid = Gtk::make_managed<Gtk::Grid>(); 222outer_grid->attach(*switcher_2, 0, 1, 1, 1); 223outer_grid->attach(*switcher_1, 1, 2, 1, 1); 224auto outer_paned = Gtk::make_managed<Gtk::Paned>(Gtk::Orientation::HORIZONTAL); 225outer_paned->set_start_child(*dock_stack_2); 226auto inner_paned = Gtk::make_managed<Gtk::Paned>(Gtk::Orientation::VERTICAL); 227auto content = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 0); 228content_manager = std::make_shared<gPanthera::ContentManager>(); 229std::function<bool(gPanthera::ContentPage*)> detach_handler; 230detach_handler = [](gPanthera::ContentPage *widget) { 231auto new_stack = Gtk::make_managed<gPanthera::ContentStack>(widget->content_manager, widget->get_stack()->get_detach_handler()); 232auto new_switcher = Gtk::make_managed<gPanthera::ContentTabBar>(new_stack, Gtk::Orientation::HORIZONTAL, dynamic_cast<gPanthera::ContentTabBar*>(widget->get_stack()->get_parent()->get_first_child())->get_extra_child_function()); 233auto new_notebook = Gtk::make_managed<gPanthera::ContentNotebook>(new_stack, new_switcher); 234auto window = new gPanthera::ContentWindow(new_notebook); 235widget->redock(new_stack); 236window->present(); 237new_stack->signal_leave_empty.connect([window]() { 238window->close(); 239delete window; 240}); 241return true; 242}; 243 244auto return_extra_child = [this](gPanthera::ContentTabBar *switcher) { 245auto new_tab_button = Gtk::make_managed<Gtk::Button>(); 246new_tab_button->set_child(*Gtk::make_managed<Gtk::Image>(Gio::Icon::create("list-add-symbolic"))); 247new_tab_button->set_tooltip_text("New tab"); 248new_tab_button->signal_clicked().connect([this, switcher]() { 249on_new_tab(switcher->get_stack()); 250}); 251return new_tab_button; 252}; 253auto content_stack = Gtk::make_managed<gPanthera::ContentStack>(content_manager, detach_handler); 254auto content_stack_switcher = Gtk::make_managed<gPanthera::ContentTabBar>(content_stack, Gtk::Orientation::HORIZONTAL, return_extra_child); 255content_manager->add_stack(content_stack); 256WebKitWebView *webview = WEBKIT_WEB_VIEW(webkit_web_view_new()); // for some reason, this has to be created 257content->set_name("content_box"); 258auto content_notebook = Gtk::make_managed<gPanthera::ContentNotebook>(content_stack, content_stack_switcher, Gtk::PositionType::TOP); 259content->append(*content_notebook); 260inner_paned->set_start_child(*content); 261inner_paned->set_end_child(*dock_stack_1); 262outer_paned->set_end_child(*inner_paned); 263outer_grid->attach(*outer_paned, 1, 1, 1, 1); 264 265// Get search engines 266std::ifstream search_engines_file_in("search_engines.json"); 267if(search_engines_file_in) { 268std::string search_engines_json((std::istreambuf_iterator<char>(search_engines_file_in)), std::istreambuf_iterator<char>()); 269search_engines_file_in.close(); 270set_search_engines_from_json(search_engines_json); 271} else { 272search_engines_file_in.close(); 273auto empty_json = nlohmann::json::array(); 274std::ofstream search_engines_file_out("search_engines.json"); 275search_engines_file_out << empty_json.dump(4); 276} 277 278// Create the toolbar 279auto main_toolbar = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 8); 280// URL bar 281url_bar = Gtk::make_managed<Gtk::Entry>(); 282url_bar->set_placeholder_text("Enter URL"); 283url_bar->set_hexpand(true); 284auto load_url_callback = [this]() { 285auto page = content_manager->get_last_operated_page(); 286bool has_protocol = url_bar->get_text().find("://") != std::string::npos; 287if(!has_protocol) { 288url_bar->set_text("http://" + url_bar->get_text()); 289} 290if(page) { 291if(auto webview = WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())) { 292webkit_web_view_load_uri(webview, url_bar->get_text().c_str()); 293} 294} 295}; 296// Go 297auto go_button = Gtk::make_managed<Gtk::Button>("Go"); 298go_button->signal_clicked().connect(load_url_callback); 299url_bar->signal_activate().connect(load_url_callback); 300content_manager->signal_page_operated.connect([this](gPanthera::ContentPage *page) { 301if(!page->get_child()) { 302return; 303} 304if(!page->get_child()->get_first_child()) { 305return; 306} 307url_bar->set_text(webkit_web_view_get_uri(WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj()))); 308guint url_update_handler = g_signal_connect(page->get_child()->get_first_child()->gobj(), "notify", G_CALLBACK(notify_focused_callback), this); 309std::shared_ptr<sigc::connection> control_signal_handler = std::make_shared<sigc::connection>(); 310*control_signal_handler = page->signal_control_status_changed.connect([this, page, control_signal_handler, url_update_handler](bool controlled) { 311if(!controlled) { 312control_signal_handler->disconnect(); 313if(page->get_child() && page->get_child()->get_first_child() && WEBKIT_IS_WEB_VIEW(page->get_child()->get_first_child()->gobj())) { 314g_signal_handler_disconnect(page->get_child()->get_first_child()->gobj(), url_update_handler); 315} 316} 317}); 318}); 319// Back, forward, reload 320auto back_button = Gtk::make_managed<Gtk::Button>(); 321back_button->set_child(*Gtk::make_managed<Gtk::Image>(Gio::Icon::create("go-previous-symbolic"))); 322back_button->set_tooltip_text("Back"); 323auto forward_button = Gtk::make_managed<Gtk::Button>(); 324forward_button->set_child(*Gtk::make_managed<Gtk::Image>(Gio::Icon::create("go-next-symbolic"))); 325forward_button->set_tooltip_text("Forward"); 326auto reload_button = Gtk::make_managed<Gtk::Button>(); 327reload_button->set_child(*Gtk::make_managed<Gtk::Image>(Gio::Icon::create("view-refresh-symbolic"))); 328reload_button->set_tooltip_text("Reload"); 329back_button->signal_clicked().connect([this]() { 330auto page = content_manager->get_last_operated_page(); 331if(page) { 332if(auto webview = WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())) { 333webkit_web_view_go_back(webview); 334} 335} 336}); 337forward_button->signal_clicked().connect([this]() { 338auto page = content_manager->get_last_operated_page(); 339if(page) { 340if(auto webview = WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())) { 341webkit_web_view_go_forward(webview); 342} 343} 344}); 345reload_button->signal_clicked().connect([this]() { 346auto page = content_manager->get_last_operated_page(); 347if(page) { 348if(auto webview = WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())) { 349webkit_web_view_reload(webview); 350} 351} 352}); 353// Search bar 354// TODO: provide history, provide a menu button with the other engines 355auto search_bar = Gtk::make_managed<Gtk::Entry>(); 356search_bar->set_placeholder_text("Search"); 357search_bar->set_hexpand(true); 358if(search_engines.empty()) { 359search_bar->set_sensitive(false); 360search_bar->set_placeholder_text("No search"); 361} 362auto search_callback = [this, search_bar, content_stack]() { 363// Create a new tab with the search results 364if(content_manager->get_last_operated_page()) { 365on_new_tab(nullptr); 366} else { 367on_new_tab(content_stack); 368} 369auto page = content_manager->get_last_operated_page(); 370if(page) { 371if(auto webview = WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())) { 372auto search_url = default_search_engine->get_search_url(search_bar->get_text()); 373webkit_web_view_load_uri(webview, search_url.c_str()); 374} 375} 376}; 377if(default_search_engine) { 378search_bar->signal_activate().connect(search_callback); 379} 380// Assemble the toolbar 381main_toolbar->append(*back_button); 382main_toolbar->append(*forward_button); 383main_toolbar->append(*reload_button); 384main_toolbar->append(*url_bar); 385main_toolbar->append(*go_button); 386main_toolbar->append(*search_bar); 387if(default_search_engine) { 388auto search_button = Gtk::make_managed<Gtk::Button>(default_search_engine->name); 389search_button->signal_clicked().connect(search_callback); 390main_toolbar->append(*search_button); 391} 392outer_grid->attach(*main_toolbar, 0, 0, 2, 1); 393window->set_child(*outer_grid); 394debug_button->signal_clicked().connect([this]() { 395if(content_manager->get_last_operated_page()) { 396std::cout << "Last operated page: " << content_manager->get_last_operated_page()->get_name() << std::endl; 397} else { 398std::cout << "No page operated!" << std::endl; 399} 400}); 401// TODO: Use the last operated page and allow opening tabs next to the last operated page using certain panes 402// Load the existing layout, if it exists 403std::ifstream layout_file_in("layout.json"); 404if(layout_file_in) { 405std::string layout_json((std::istreambuf_iterator<char>(layout_file_in)), std::istreambuf_iterator<char>()); 406layout_file_in.close(); 407layout_manager->restore_json_layout(layout_json); 408} else { 409// Create a new layout if the file doesn't exist 410layout_file_in.close(); 411 412dock_stack_1->add_pane(*pane_1); 413dock_stack_1->add_pane(*pane_3); 414dock_stack_2->add_pane(*pane_2); 415 416std::ofstream layout_file_out("layout.json"); 417layout_file_out << layout_manager->get_layout_as_json(); 418layout_file_out.close(); 419} 420// Save the layout when changed 421layout_manager->signal_pane_moved.connect([this](gPanthera::DockablePane *pane) { 422std::ofstream layout_file_out("layout.json"); 423layout_file_out << layout_manager->get_layout_as_json(); 424layout_file_out.close(); 425std::cout << "Layout changed: " << layout_manager->get_layout_as_json() << std::endl; 426}); 427 428auto new_tab_action = Gio::SimpleAction::create("new_tab"); 429new_tab_action->signal_activate().connect([this](const Glib::VariantBase&) { 430on_new_tab(nullptr); 431}); 432add_action(new_tab_action); 433set_accels_for_action("app.new_tab", {"<Primary>T"}); 434auto close_tab_action = Gio::SimpleAction::create("close_tab"); 435close_tab_action->signal_activate().connect([this](const Glib::VariantBase&) { 436auto page = content_manager->get_last_operated_page(); 437if(page) { 438page->close(); 439} 440}); 441add_action(close_tab_action); 442set_accels_for_action("app.close_tab", {"<Primary>W"}); 443 444// Load plugins 445std::ifstream plugin_file_in("plugins.json"); 446if(plugin_file_in) { 447std::string plugin_json((std::istreambuf_iterator<char>(plugin_file_in)), std::istreambuf_iterator<char>()); 448plugin_file_in.close(); 449auto json = nlohmann::json::parse(plugin_json); 450for(auto &plugin : json) { 451auto plugin_path = plugin["path"].get<std::string>(); 452load_plugin(plugin_path); 453} 454} else { 455plugin_file_in.close(); 456auto empty_json = nlohmann::json::array(); 457std::ofstream plugin_file_out("plugins.json"); 458plugin_file_out << empty_json.dump(4); 459plugin_file_out.close(); 460} 461} 462 463void on_activate() override { 464window->present(); 465} 466 467void set_search_engines_from_json(const std::string &json_string) { 468auto json = nlohmann::json::parse(json_string); 469Glib::ustring default_search_engine_name; 470for(auto &engine : json) { 471SearchEngine search_engine; 472search_engine.name = engine["name"].get<std::string>(); 473search_engine.url = engine["url"].get<std::string>(); 474search_engines.push_back(search_engine); 475if(engine.contains("default") && engine["default"].get<bool>()) { 476default_search_engine_name = engine["name"].get<std::string>(); 477} 478} 479for(auto &search_engine : search_engines) { 480if(search_engine.name == default_search_engine_name) { 481default_search_engine = &search_engine; 482break; 483} 484} 485} 486public: 487static Glib::RefPtr<PantheraWww> create() { 488return Glib::make_refptr_for_instance<PantheraWww>(new PantheraWww()); 489} 490 491std::shared_ptr<gPanthera::LayoutManager> get_layout_manager() { 492return layout_manager; 493} 494 495std::shared_ptr<gPanthera::ContentManager> get_content_manager() { 496return content_manager; 497} 498 499void load_plugin(const std::string &plugin_path) { 500void *handle = dlopen(plugin_path.c_str(), RTLD_LAZY | RTLD_GLOBAL); 501if(!handle) { 502std::cerr << "Failed to load plugin: " << dlerror() << std::endl; 503return; 504} 505auto entrypoint = (plugin_entrypoint_type)dlsym(handle, "plugin_init"); 506if(!entrypoint) { 507std::cerr << "Failed to find entrypoint in plugin: " << dlerror() << std::endl; 508dlclose(handle); 509return; 510} 511entrypoint(); 512} 513}; 514 515Glib::RefPtr<PantheraWww> app = nullptr; 516 517extern "C" { 518void panthera_log(const char *message) { 519std::cerr << message << std::endl; 520} 521 522void panthera_add_pane(const char *id, const char *label, GtkImage *icon, GtkWidget *pane) { 523auto pane_child = Glib::wrap(pane); 524auto icon_cc = Glib::wrap(icon); 525auto label_cc = Glib::ustring(label); 526auto id_cc = Glib::ustring(id); 527auto new_pane = Gtk::make_managed<gPanthera::DockablePane>(app->get_layout_manager(), *pane_child, id_cc, label_cc, icon_cc); 528app->get_layout_manager()->add_pane(new_pane); 529} 530} 531 532int main(int argc, char *argv[]) { 533gPanthera::init(); 534app = PantheraWww::create(); 535return app->run(argc, argv); 536}