aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--deps/sysobj_early/gui/uri_handler.c48
-rw-r--r--deps/sysobj_early/gui/uri_handler.h32
-rw-r--r--shell/shell.c25
4 files changed, 107 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8bbf301c..8bbdd837 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -98,6 +98,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/includes/${HARDINFO_ARCH}
${CMAKE_SOURCE_DIR}/deps/uber-graph
${CMAKE_SOURCE_DIR}/deps/sysobj_early/include
+ ${CMAKE_SOURCE_DIR}/deps/sysobj_early/gui
${CMAKE_BINARY_DIR}
${GTK_INCLUDE_DIRS}
${LIBSOUP_INCLUDE_DIRS}
@@ -216,6 +217,7 @@ endforeach()
add_library(sysobj_early STATIC
deps/sysobj_early/src/gg_slist.c
deps/sysobj_early/src/strstr_word.c
+ deps/sysobj_early/gui/uri_handler.c
)
set_target_properties(sysobj_early PROPERTIES COMPILE_FLAGS "-std=c99 -Wall -Wextra -Wno-parentheses -Wno-unused-function")
diff --git a/deps/sysobj_early/gui/uri_handler.c b/deps/sysobj_early/gui/uri_handler.c
new file mode 100644
index 00000000..055dbaca
--- /dev/null
+++ b/deps/sysobj_early/gui/uri_handler.c
@@ -0,0 +1,48 @@
+/*
+ * sysobj - https://github.com/bp0/verbose-spork
+ * Copyright (C) 2018 Burt P. <pburt0@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <stdio.h>
+#include "uri_handler.h"
+
+static uri_handler uri_func = NULL;
+
+void uri_set_function(uri_handler f) {
+ uri_func = f;
+}
+
+gboolean uri_open(const gchar *uri) {
+ gboolean ret = FALSE;
+ if (uri_func)
+ ret = uri_func(uri);
+ if (ret) return TRUE;
+
+ return uri_open_default(uri);
+}
+
+gboolean uri_open_default(const gchar *uri) {
+ gchar *argv[] = { "/usr/bin/xdg-open", (gchar*)uri, NULL };
+ GError *err = NULL;
+ g_spawn_async(NULL, argv, NULL, G_SPAWN_DEFAULT, NULL, NULL, NULL, &err );
+ if (err) {
+ fprintf(stderr, "Error opening URI %s: %s\n", uri, err->message);
+ g_error_free(err);
+ }
+ return TRUE;
+}
diff --git a/deps/sysobj_early/gui/uri_handler.h b/deps/sysobj_early/gui/uri_handler.h
new file mode 100644
index 00000000..8d7892c5
--- /dev/null
+++ b/deps/sysobj_early/gui/uri_handler.h
@@ -0,0 +1,32 @@
+/*
+ * sysobj - https://github.com/bp0/verbose-spork
+ * Copyright (C) 2018 Burt P. <pburt0@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef URI_HANDLER_H
+#define URI_HANDLER_H
+
+#include <glib.h>
+
+typedef gboolean (*uri_handler)(const gchar *uri);
+
+void uri_set_function(uri_handler f);
+gboolean uri_open(const gchar *uri);
+gboolean uri_open_default(const gchar *uri); /* uses xdg-open */
+
+#endif
diff --git a/shell/shell.c b/shell/shell.c
index 75ee8300..31836d62 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -720,6 +720,22 @@ select_first_tree_item(gpointer data)
return FALSE;
}
+gboolean hardinfo_link(const gchar *uri) {
+ /* Clicked link events pass through here on their
+ * way to the default handler (xdg-open).
+ *
+ * TODO: In the future, links could be used to
+ * jump to different pages in hardinfo.
+ *
+ * if (g_str_has_prefix(uri, "hardinfo:")) {
+ * hardinfo_navigate(g_utf8_strchr(uri, strlen("hardinfo"), ':') + 1);
+ * return TRUE;
+ * }
+ */
+
+ return FALSE; /* didn't handle it */
+}
+
void shell_init(GSList * modules)
{
if (shell) {
@@ -729,6 +745,8 @@ void shell_init(GSList * modules)
DEBUG("initializing shell");
+ uri_set_function(hardinfo_link);
+
create_window();
shell_action_set_property("ConnectToAction", "is-important", TRUE);
@@ -1502,6 +1520,10 @@ static void module_selected_show_info_list(GKeyFile *key_file,
ngroups > 1);
}
+static gboolean detail_activate_link (GtkLabel *label, gchar *uri, gpointer user_data) {
+ return uri_open(uri);
+}
+
static void module_selected_show_info_detail(GKeyFile *key_file,
ShellModuleEntry *entry,
gchar **groups)
@@ -1570,6 +1592,9 @@ static void module_selected_show_info_detail(GKeyFile *key_file,
gtk_box_pack_start(GTK_BOX(value_box), value_icon, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(value_box), value_label, TRUE, TRUE, 0);
+ g_signal_connect(key_label, "activate-link", G_CALLBACK(detail_activate_link), NULL);
+ g_signal_connect(value_label, "activate-link", G_CALLBACK(detail_activate_link), NULL);
+
gtk_widget_show(key_label);
gtk_widget_show(value_box);
gtk_widget_show(value_label);