From 579ed0c82615b4b65d8435b9fc59e2f0e977ddf1 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Sat, 7 Oct 2017 15:15:56 +0200 Subject: [PATCH] [feat] download dir can be set by the user and use gsettings for storing the download directory [fix] use inside flatpak the ~/Downloads directory to save files --- data/com.frac_tion.teleport.gschema.xml | 26 ++++++----------- src/main.c | 6 ---- src/settings.ui | 5 ++-- src/teleport-get.c | 3 +- src/teleport-window.c | 38 ++++++++++++++++++++----- src/teleport-window.h | 2 ++ 6 files changed, 46 insertions(+), 34 deletions(-) diff --git a/data/com.frac_tion.teleport.gschema.xml b/data/com.frac_tion.teleport.gschema.xml index 5bb1a71..5cba701 100644 --- a/data/com.frac_tion.teleport.gschema.xml +++ b/data/com.frac_tion.teleport.gschema.xml @@ -1,25 +1,15 @@ - - 'Monospace 12' - Font - The font to be used for content. + + '~/Downloads' + Download directory + The directory to save all incoming files. - - - - - - - 'none' - Transition - The transition to use when switching tabs. - - - false - Show words - Whether to show a word list in the sidebar + + 'unknown' + Device name + The device name shown to other devices. diff --git a/src/main.c b/src/main.c index 68f8120..4988bc2 100644 --- a/src/main.c +++ b/src/main.c @@ -5,11 +5,5 @@ int main (int argc, char *argv[]) { - if (g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD) == NULL) { - g_print("Update XDG user dirs\n"); - g_spawn_command_line_sync("xdg-user-dirs-update", NULL, NULL, NULL, NULL); - } - g_print("Download dir: %s\n", g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD)); - return g_application_run (G_APPLICATION (teleport_app_new ()), argc, argv); } diff --git a/src/settings.ui b/src/settings.ui index b319f40..6279722 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -23,8 +23,9 @@ True - False + True ~/Downloads + 25 0 @@ -36,7 +37,7 @@ True - False + false Browse... 12 diff --git a/src/teleport-get.c b/src/teleport-get.c index 37969fe..7f7e854 100644 --- a/src/teleport-get.c +++ b/src/teleport-get.c @@ -4,6 +4,7 @@ #include #include "teleport-app.h" +#include "teleport-window.h" #include "teleport-get.h" static int saveFile (SoupMessage *, const gchar *, const gchar *); @@ -147,7 +148,7 @@ int teleport_get_do_downloading (const char *originDevice, const char *url, const char *filename) { - const gchar *outputDirectory = g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD); + const gchar *outputDirectory = teleport_get_download_directory(); g_print("Downloading %s to %s\n", url, g_uri_escape_string(filename, NULL, TRUE)); get (g_strdup(url), originDevice, outputDirectory, filename); return 0; diff --git a/src/teleport-window.c b/src/teleport-window.c index 91469e1..84873a6 100644 --- a/src/teleport-window.c +++ b/src/teleport-window.c @@ -36,6 +36,19 @@ teleport_window_init (TeleportWindow *win) mainWin = 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"); + } + } gtk_widget_init_template (GTK_WIDGET (win)); @@ -46,8 +59,10 @@ teleport_window_init (TeleportWindow *win) gtk_menu_button_set_popover(GTK_MENU_BUTTON (priv->gears), menu); gtk_label_set_text (GTK_LABEL (priv->this_device_name_label), g_get_host_name()); - gtk_entry_set_text (downloadDir, g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD)); - gtk_entry_set_width_chars(downloadDir, 30); + + g_settings_bind (priv->settings, "download-dir", + downloadDir, "text", + G_SETTINGS_BIND_DEFAULT); //g_object_unref (menu); //g_object_unref (label); @@ -176,13 +191,13 @@ find_child(GtkWidget *parent, const gchar *name) static void teleport_window_dispose (GObject *object) { - //TeleportWindow *win; - //TeleportWindowPrivate *priv; + TeleportWindow *win; + TeleportWindowPrivate *priv; - //win = TELEPORT_WINDOW (object); - //priv = teleport_window_get_instance_private (win); + win = TELEPORT_WINDOW (object); + priv = teleport_window_get_instance_private (win); - //g_clear_object (&priv->settings); + g_clear_object (&priv->settings); G_OBJECT_CLASS (teleport_window_parent_class)->dispose (object); } @@ -207,6 +222,15 @@ teleport_window_new (TeleportApp *app) return g_object_new (TELEPORT_WINDOW_TYPE, "application", app, NULL); } + +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_window_open (TeleportWindow *win, GFile *file) diff --git a/src/teleport-window.h b/src/teleport-window.h index c6c7f6c..9799ccf 100644 --- a/src/teleport-window.h +++ b/src/teleport-window.h @@ -20,4 +20,6 @@ void update_remote_device_list (TeleportWindow *, void update_remote_device_list_remove (TeleportWindow *, Peer *); +gchar * teleport_get_download_directory (void); + #endif /* __TELEPORT_WINDOW_H */