[refactor] move GSettings to app
This commit is contained in:
@@ -77,6 +77,7 @@ static gint signalIds [N_SIGNALS];
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
GSettings *settings;
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
TeleportPeer *peerList;
|
TeleportPeer *peerList;
|
||||||
} TeleportAppPrivate;
|
} TeleportAppPrivate;
|
||||||
@@ -297,6 +298,46 @@ callback_notify_user (GObject *instance, gchar *name, gpointer window) {
|
|||||||
//create_user_notification("icon.png", 2000, "Mark's laptop");
|
//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
|
static void
|
||||||
teleport_app_startup (GApplication *app) {
|
teleport_app_startup (GApplication *app) {
|
||||||
TeleportAppPrivate *priv;
|
TeleportAppPrivate *priv;
|
||||||
@@ -349,6 +390,8 @@ teleport_app_activate (GApplication *app) {
|
|||||||
static void
|
static void
|
||||||
teleport_app_finalize (GObject *object)
|
teleport_app_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
|
/*TeleportAppPrivate priv = mainApplication->priv;
|
||||||
|
g_clear_object (&priv->settings);*/
|
||||||
G_OBJECT_CLASS (teleport_app_parent_class)->finalize (object);
|
G_OBJECT_CLASS (teleport_app_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,6 +486,9 @@ static void
|
|||||||
teleport_app_init (TeleportApp *app) {
|
teleport_app_init (TeleportApp *app) {
|
||||||
TeleportAppPrivate *priv = teleport_app_get_instance_private (app);
|
TeleportAppPrivate *priv = teleport_app_get_instance_private (app);
|
||||||
app->priv = priv;
|
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);
|
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 *,
|
void create_user_notification (const char *,
|
||||||
const int,
|
const int,
|
||||||
const char *,
|
const char *,
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
#include "teleport-peer.h"
|
#include "teleport-peer.h"
|
||||||
#include "teleport-remote-device.h"
|
#include "teleport-remote-device.h"
|
||||||
|
|
||||||
TeleportWindow *mainWin;
|
|
||||||
|
|
||||||
struct _TeleportWindow
|
struct _TeleportWindow
|
||||||
{
|
{
|
||||||
GtkApplicationWindow parent;
|
GtkApplicationWindow parent;
|
||||||
@@ -35,7 +33,6 @@ typedef struct _TeleportWindowPrivate TeleportWindowPrivate;
|
|||||||
|
|
||||||
struct _TeleportWindowPrivate
|
struct _TeleportWindowPrivate
|
||||||
{
|
{
|
||||||
GSettings *settings;
|
|
||||||
GtkWidget *gears;
|
GtkWidget *gears;
|
||||||
GtkWidget *this_device_settings_button;
|
GtkWidget *this_device_settings_button;
|
||||||
GtkWidget *remote_devices_box;
|
GtkWidget *remote_devices_box;
|
||||||
@@ -76,7 +73,7 @@ static void
|
|||||||
on_click_this_device_settings_button (GtkWidget *widget,
|
on_click_this_device_settings_button (GtkWidget *widget,
|
||||||
gpointer user_data) {
|
gpointer user_data) {
|
||||||
TeleportWindowPrivate *priv = (TeleportWindowPrivate *) user_data;
|
TeleportWindowPrivate *priv = (TeleportWindowPrivate *) user_data;
|
||||||
g_settings_set_string (priv->settings,
|
g_settings_set_string (teleport_app_get_settings (),
|
||||||
"device-name",
|
"device-name",
|
||||||
gtk_entry_get_text (GTK_ENTRY (priv->this_device_settings_entry)));
|
gtk_entry_get_text (GTK_ENTRY (priv->this_device_settings_entry)));
|
||||||
}
|
}
|
||||||
@@ -88,28 +85,9 @@ teleport_window_init (TeleportWindow *win)
|
|||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GtkWidget *menu;
|
GtkWidget *menu;
|
||||||
GtkFileChooserButton *downloadDir;
|
GtkFileChooserButton *downloadDir;
|
||||||
mainWin = win;
|
GSettings *settings = teleport_app_get_settings ();
|
||||||
|
|
||||||
priv = teleport_window_get_instance_private (win);
|
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));
|
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);
|
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",
|
priv->this_device_name_label, "label",
|
||||||
G_SETTINGS_BIND_DEFAULT);
|
G_SETTINGS_BIND_DEFAULT);
|
||||||
|
|
||||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (downloadDir),
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (downloadDir),
|
||||||
g_settings_get_string(priv->settings,
|
g_settings_get_string(settings,
|
||||||
"download-dir"));
|
"download-dir"));
|
||||||
|
|
||||||
g_signal_connect (downloadDir, "file-set", G_CALLBACK (change_download_directory_cb), priv->settings);
|
g_signal_connect (downloadDir, "file-set", G_CALLBACK (change_download_directory_cb), settings);
|
||||||
g_signal_connect (priv->settings, "changed", G_CALLBACK (update_download_directory), downloadDir);
|
g_signal_connect (settings, "changed", G_CALLBACK (update_download_directory), downloadDir);
|
||||||
|
|
||||||
g_object_unref (builder);
|
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,
|
priv->this_device_settings_entry = GTK_WIDGET (gtk_builder_get_object (builder,
|
||||||
"this_device_settings_entry"));
|
"this_device_settings_entry"));
|
||||||
g_settings_bind (priv->settings,
|
g_settings_bind (settings,
|
||||||
"device-name",
|
"device-name",
|
||||||
priv->this_device_settings_entry,
|
priv->this_device_settings_entry,
|
||||||
"text",
|
"text",
|
||||||
@@ -207,8 +185,6 @@ teleport_window_dispose (GObject *object)
|
|||||||
win = TELEPORT_WINDOW (object);
|
win = TELEPORT_WINDOW (object);
|
||||||
priv = teleport_window_get_instance_private (win);
|
priv = teleport_window_get_instance_private (win);
|
||||||
|
|
||||||
g_clear_object (&priv->settings);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (teleport_window_parent_class)->dispose (object);
|
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);
|
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
|
void
|
||||||
teleport_show_no_device_message (TeleportWindow *self, gboolean show)
|
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 *,
|
void update_remote_device_list_remove (TeleportWindow *,
|
||||||
Peer *);
|
Peer *);
|
||||||
|
|
||||||
gchar * teleport_get_download_directory (void);
|
|
||||||
gchar * teleport_get_device_name (void);
|
|
||||||
void teleport_show_no_device_message (TeleportWindow *,
|
void teleport_show_no_device_message (TeleportWindow *,
|
||||||
gboolean);
|
gboolean);
|
||||||
void teleport_show_no_avahi_message (TeleportWindow *,
|
void teleport_show_no_avahi_message (TeleportWindow *,
|
||||||
|
|||||||
Reference in New Issue
Block a user