[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

This commit is contained in:
Julian Sparber
2017-10-07 15:15:56 +02:00
parent c25d688b81
commit 579ed0c826
6 changed files with 46 additions and 34 deletions

View File

@@ -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);
}

View File

@@ -23,8 +23,9 @@
<child>
<object class="GtkEntry" id="settings_download_directory">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="sensitive">True</property>
<property name="text">~/Downloads</property>
<property name="width_chars">25</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -36,7 +37,7 @@
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="sensitive">false</property>
<property name="label">Browse...</property>
<property name="margin_start">12</property>
</object>

View File

@@ -4,6 +4,7 @@
#include <libsoup/soup.h>
#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;

View File

@@ -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)

View File

@@ -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 */