Commit 97b35586 authored by Julian Sparber's avatar Julian Sparber

[refactor] move GSettings to app

parent 5cd1716a
......@@ -77,6 +77,7 @@ static gint signalIds [N_SIGNALS];
typedef struct
{
GSettings *settings;
GtkWidget *window;
TeleportPeer *peerList;
} TeleportAppPrivate;
......@@ -297,6 +298,46 @@ callback_notify_user (GObject *instance, gchar *name, gpointer window) {
//create_user_notification("icon.png", 2000, "Mark's laptop");
}
GSettings *
teleport_app_get_settings (void) {
TeleportAppPrivate *priv;
priv = teleport_app_get_instance_private (mainApplication);
return priv->settings;
}
static void
init_settings (GSettings *settings) {
if (g_settings_get_user_value (settings, "download-dir") == NULL) {
g_print ("Download dir set to XDG DOWNLOAD directory\n");
if (g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD) != NULL) {
g_settings_set_string (settings,
"download-dir",
g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD));
}
else {
g_print ("Error: XDG DOWNLOAD is not set.\n");
}
}
if (g_settings_get_user_value (settings, "device-name") == NULL) {
g_settings_set_string (settings,
"device-name",
g_get_host_name());
}
}
gchar *
teleport_get_device_name (void)
{
return g_settings_get_string (teleport_app_get_settings (), "device-name");
}
gchar *
teleport_get_download_directory (void)
{
return g_settings_get_string (teleport_app_get_settings (), "download-dir");
}
static void
teleport_app_startup (GApplication *app) {
TeleportAppPrivate *priv;
......@@ -349,6 +390,8 @@ teleport_app_activate (GApplication *app) {
static void
teleport_app_finalize (GObject *object)
{
/*TeleportAppPrivate priv = mainApplication->priv;
g_clear_object (&priv->settings);*/
G_OBJECT_CLASS (teleport_app_parent_class)->finalize (object);
}
......@@ -443,6 +486,9 @@ static void
teleport_app_init (TeleportApp *app) {
TeleportAppPrivate *priv = teleport_app_get_instance_private (app);
app->priv = priv;
priv->settings = g_settings_new ("com.frac_tion.teleport");
init_settings (priv->settings);
}
......@@ -28,6 +28,9 @@ G_DECLARE_FINAL_TYPE (TeleportApp, teleport_app, TELEPORT, APP, GtkApplication)
TeleportApp *teleport_app_new (void);
GSettings *teleport_app_get_settings (void);
gchar *teleport_get_download_directory (void);
gchar *teleport_get_device_name (void);
void create_user_notification (const char *,
const int,
const char *,
......
......@@ -24,8 +24,6 @@
#include "teleport-peer.h"
#include "teleport-remote-device.h"
TeleportWindow *mainWin;
struct _TeleportWindow
{
GtkApplicationWindow parent;
......@@ -35,7 +33,6 @@ typedef struct _TeleportWindowPrivate TeleportWindowPrivate;
struct _TeleportWindowPrivate
{
GSettings *settings;
GtkWidget *gears;
GtkWidget *this_device_settings_button;
GtkWidget *remote_devices_box;
......@@ -76,7 +73,7 @@ static void
on_click_this_device_settings_button (GtkWidget *widget,
gpointer user_data) {
TeleportWindowPrivate *priv = (TeleportWindowPrivate *) user_data;
g_settings_set_string (priv->settings,
g_settings_set_string (teleport_app_get_settings (),
"device-name",
gtk_entry_get_text (GTK_ENTRY (priv->this_device_settings_entry)));
}
......@@ -88,28 +85,9 @@ teleport_window_init (TeleportWindow *win)
GtkBuilder *builder;
GtkWidget *menu;
GtkFileChooserButton *downloadDir;
mainWin = win;
GSettings *settings = teleport_app_get_settings ();
priv = teleport_window_get_instance_private (win);
priv->settings = g_settings_new ("com.frac_tion.teleport");
if (g_settings_get_user_value (priv->settings, "download-dir") == NULL) {
g_print ("Download dir set to XDG DOWNLOAD directory\n");
if (g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD) != NULL) {
g_settings_set_string (priv->settings,
"download-dir",
g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD));
}
else {
g_print ("Error: XDG DOWNLOAD is not set.\n");
}
}
if (g_settings_get_user_value (priv->settings, "device-name") == NULL) {
g_settings_set_string (priv->settings,
"device-name",
g_get_host_name());
}
gtk_widget_init_template (GTK_WIDGET (win));
......@@ -120,16 +98,16 @@ teleport_window_init (TeleportWindow *win)
gtk_menu_button_set_popover(GTK_MENU_BUTTON (priv->gears), menu);
g_settings_bind (priv->settings, "device-name",
g_settings_bind (settings, "device-name",
priv->this_device_name_label, "label",
G_SETTINGS_BIND_DEFAULT);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (downloadDir),
g_settings_get_string(priv->settings,
g_settings_get_string(settings,
"download-dir"));
g_signal_connect (downloadDir, "file-set", G_CALLBACK (change_download_directory_cb), priv->settings);
g_signal_connect (priv->settings, "changed", G_CALLBACK (update_download_directory), downloadDir);
g_signal_connect (downloadDir, "file-set", G_CALLBACK (change_download_directory_cb), settings);
g_signal_connect (settings, "changed", G_CALLBACK (update_download_directory), downloadDir);
g_object_unref (builder);
......@@ -140,7 +118,7 @@ teleport_window_init (TeleportWindow *win)
priv->this_device_settings_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"this_device_settings_entry"));
g_settings_bind (priv->settings,
g_settings_bind (settings,
"device-name",
priv->this_device_settings_entry,
"text",
......@@ -207,8 +185,6 @@ teleport_window_dispose (GObject *object)
win = TELEPORT_WINDOW (object);
priv = teleport_window_get_instance_private (win);
g_clear_object (&priv->settings);
G_OBJECT_CLASS (teleport_window_parent_class)->dispose (object);
}
......@@ -234,24 +210,6 @@ teleport_window_new (TeleportApp *app)
return g_object_new (TELEPORT_WINDOW_TYPE, "application", app, NULL);
}
gchar *
teleport_get_device_name (void)
{
TeleportWindowPrivate *priv;
priv = teleport_window_get_instance_private (mainWin);
return g_settings_get_string (priv->settings, "device-name");
}
gchar *
teleport_get_download_directory (void)
{
TeleportWindowPrivate *priv;
priv = teleport_window_get_instance_private (mainWin);
return g_settings_get_string (priv->settings, "download-dir");
}
void
teleport_show_no_device_message (TeleportWindow *self, gboolean show)
{
......
......@@ -38,8 +38,6 @@ void update_remote_device_list (TeleportWindow *,
void update_remote_device_list_remove (TeleportWindow *,
Peer *);
gchar * teleport_get_download_directory (void);
gchar * teleport_get_device_name (void);
void teleport_show_no_device_message (TeleportWindow *,
gboolean);
void teleport_show_no_avahi_message (TeleportWindow *,
......
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