From b960a591cb26b4feb8d44816b978cf7035650d73 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 27 Dec 2018 07:53:07 +0100 Subject: [PATCH] wip: first version --- .gitignore | 2 + meson.build | 9 +++ ssb-gtk/main.c | 21 +++++++ ssb-gtk/meson.build | 8 +++ ssb-gtk/ssb-app.c | 130 ++++++++++++++++++++++++++++++++++++++++++++ ssb-gtk/ssb-app.h | 16 ++++++ 6 files changed, 186 insertions(+) create mode 100644 .gitignore create mode 100644 meson.build create mode 100644 ssb-gtk/main.c create mode 100644 ssb-gtk/meson.build create mode 100644 ssb-gtk/ssb-app.c create mode 100644 ssb-gtk/ssb-app.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4c0162 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.dir-locals.el +/build/ diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..5eef17d --- /dev/null +++ b/meson.build @@ -0,0 +1,9 @@ +project('ssb-gtk', 'c', version: '0.0.1') + +glib_required = '>= 2.40' +gtk_required = '>= 3.20' + +glib = dependency('glib-2.0', version: glib_required) +gtk = dependency('gtk+-3.0', version: gtk_required) + +subdir('ssb-gtk') diff --git a/ssb-gtk/main.c b/ssb-gtk/main.c new file mode 100644 index 0000000..885289f --- /dev/null +++ b/ssb-gtk/main.c @@ -0,0 +1,21 @@ +#include +#include + +#include "ssb-app.h" + +#define SSB_APP_NAME "ssb" +#define DEFAULT_CAP_KEY "1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=" +#define GETTEXT_PACKAGE "ssb-gtk" + +int +main(int argc, char **argv) +{ + SsbApp *app; + gint status; + + app = ssb_app_new(); + status = g_application_run(G_APPLICATION(app), argc, argv); + g_object_unref(app); + + return status; +} diff --git a/ssb-gtk/meson.build b/ssb-gtk/meson.build new file mode 100644 index 0000000..f86415f --- /dev/null +++ b/ssb-gtk/meson.build @@ -0,0 +1,8 @@ +sources = [ + 'main.c', + 'ssb-app.c', +] + +executable('ssb-gtk', sources, + dependencies: [glib, gtk], + install: true) diff --git a/ssb-gtk/ssb-app.c b/ssb-gtk/ssb-app.c new file mode 100644 index 0000000..ecd7b67 --- /dev/null +++ b/ssb-gtk/ssb-app.c @@ -0,0 +1,130 @@ +#include "ssb-app.h" + +struct _SsbApp { + GtkApplication parent_instance; + + gchar *ssb_dir; +}; + +G_DEFINE_TYPE(SsbApp, ssb_app, GTK_TYPE_APPLICATION); + +static GOptionEntry entries[] = { + {"noauth", 'n', 0, G_OPTION_ARG_NONE, NULL, "Noauth mode. Skip secret-handshake authentication and box-stream encryption. This option makes the -k, -K, and -c options to have no effect and output a warning if used.", NULL}, + {"ipv4", '4', 0, G_OPTION_ARG_NONE, NULL, "Connect to the server over IPv4 only", NULL}, + {"ipv6", '6', 0, G_OPTION_ARG_NONE, NULL, "Connect to the server over IPv6 only", NULL}, + {"capkey", 'c', 0, G_OPTION_ARG_STRING, NULL, "Capability key for the secret handshake. If not set, the default SSB capability key will be used", "CAPKEY"}, + {"server", 's', 0, G_OPTION_ARG_STRING, NULL, "The hostname to connect to. Defaults to localhost", "HOST"}, + {"port", 'p', 0, G_OPTION_ARG_INT, NULL, "The port to connect to. Default is 8008.", "PORT"}, + {"socket", 'u', 0, G_OPTION_ARG_FILENAME, NULL, "Unix socket path to connect to instead of a TCP socket. Conflicts with -s and -p", "PATH"}, + {"key", 'k', 0, G_OPTION_ARG_STRING, NULL, "The key to connect to. Default is your public key as read from the private key file", "KEY"}, + {"keypair-seed", 'K', 0, G_OPTION_ARG_STRING, NULL, "Private key seed to use for the secret handshake. Default is to use the private key from your privace key file.", "SEED"}, + {"version", 'v', NULL, } + {NULL} +}; + +static void +print_version(void) { + // TODO: Move these to constants or something + g_print("ssb-gtk %d.%d.%d\n", 0, 0, 1); +} + +static int +local_options(GApplication *app, GVriantDict *options, gpointer user_data) +{ + gboolean version = FALSE; + + g_variant_dict_lookup(options, "version", "b", &version); + + if (version) { + print_version(); + + return 0; + } + + return -1; +} + +SsbApp * +ssb_app_new(void) +{ + SsbApp *app = g_object_new(SSB_TYPE_APP, NULL); + + g_application_add_main_option_entries(G_APPLICATION(app), entries); + g_application_set_option_context_description(G_APPLICATION(app), "Report issues at https://gitea.polonkai.eu/gergely/ssb-gtk/issues"); + g_application_set_option_context_summary(G_APPLICATION(app), "An SSB client for the GNOME desktop."); + + g_signal_connect(app, "handle-local-options", G_CALLBACK(local_options), NULL); + + return app; +} + +static void +ssb_app_finalize(GObject *gobject) +{ + SsbApp *app = SSB_APP(gobject); + + app->ssb_dir = (g_free(app->ssb_dir), NULL); +} + +static void +ssb_app_startup(GApplication *app) +{ + G_APPLICATION_CLASS(ssb_app_parent_class)->startup(app); + g_print("Starting up!\n"); +} + +static void +ssb_app_activate(GApplication *app) +{ + G_APPLICATION_CLASS(ssb_app_parent_class)->activate(app); + g_print("Activate!\n"); +} + +static void +ssb_app_shutdown(GApplication *app) +{ + g_print("Shutting down…\n"); + G_APPLICATION_CLASS(ssb_app_parent_class)->shutdown(app); +} + +static void +ssb_app_init(SsbApp *app) +{ + gchar **envp = g_get_environ(); + const gchar *app_dir_path = g_environ_getenv(envp, "ssb_path"); + + app->ssb_dir = NULL; + + if (app_dir_path != NULL) { + app->ssb_dir = g_strdup(app_dir_path); + } else { + const gchar *home = g_environ_getenv(envp, "HOME"); + const gchar *appname = g_environ_getenv(envp, "ssb_appname"); + + if (home == NULL) { + home = "."; + } + + if (appname == NULL) { + appname = "ssb"; + } + + app->ssb_dir = g_strdup_printf("%s/.%s", home, appname); + } + + g_strfreev(envp); + + g_debug("SsbApp initialised with app dir %s", app->ssb_dir); +} + +static void +ssb_app_class_init(SsbAppClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GApplicationClass *app_class = G_APPLICATION_CLASS(klass); + + gobject_class->finalize = ssb_app_finalize; + app_class->activate = ssb_app_activate; + app_class->startup = ssb_app_startup; + app_class->shutdown = ssb_app_shutdown; +} diff --git a/ssb-gtk/ssb-app.h b/ssb-gtk/ssb-app.h new file mode 100644 index 0000000..46ab1a3 --- /dev/null +++ b/ssb-gtk/ssb-app.h @@ -0,0 +1,16 @@ +#ifndef __SSB_APP_H__ +# define __SSB_APP_H__ + +# include +# include + +#define SSB_TYPE_APP ssb_app_get_type() +G_DECLARE_FINAL_TYPE(SsbApp, ssb_app, SSB, APP, GtkApplication) + +G_BEGIN_DECLS + +SsbApp *ssb_app_new(void); + +G_END_DECLS + +#endif /* __SSB_APP_H__ */