Commit 8fca81d8 authored by Sébastien Blin's avatar Sébastien Blin Committed by Philippe Gorley

settings: add a default folder for receiving files

This patch also removes the pop up file chooser when accepting files.

Change-Id: I3d767a22726017a2fb5210df07894b316db216c3
Reviewed-by: Philippe Gorley's avatarPhilippe Gorley <philippe.gorley@savoirfairelinux.com>
parent 69606246
......@@ -63,5 +63,10 @@
<summary>Number of days to store the history.</summary>
<description>Keep history only within the limit. 0 for unlimited history.</description>
</key>
<key name="download-folder" type="s">
<default>""</default>
<summary>Where ring downloads files.</summary>
<description>When a contact sends a file, this file will be stored in the folder previously described.</description>
</key>
</schema>
</schemalist>
......@@ -164,7 +164,7 @@ button_add_to_conversations_clicked(ChatView *self)
}
static gchar*
file_to_manipulate(GtkWindow* top_window, bool send, const std::string& displayName = "")
file_to_manipulate(GtkWindow* top_window, bool send)
{
GtkWidget* dialog;
GtkFileChooserAction action = send? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE;
......@@ -179,9 +179,6 @@ file_to_manipulate(GtkWindow* top_window, bool send, const std::string& displayN
send? _("_Open"): _("_Save"),
GTK_RESPONSE_ACCEPT,
nullptr);
// Set default save name
if (!send)
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), displayName.c_str());
res = gtk_dialog_run (GTK_DIALOG(dialog));
......@@ -223,10 +220,21 @@ webkit_chat_container_script_dialog(G_GNUC_UNUSED GtkWidget* webview, gchar *int
lrc::api::datatransfer::Info info = {};
priv->accountContainer_->info.conversationModel->getTransferInfo(interactionId, info);
if (auto filename = file_to_manipulate(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(self))), false, info.displayName))
model->acceptTransfer(priv->conversation_->uid, interactionId, filename);
else
model->cancelTransfer(priv->conversation_->uid, interactionId);
// get prefered directory destination.
auto* download_directory_variant = g_settings_get_value(priv->settings, "download-folder");
char* download_directory_value;
g_variant_get(download_directory_variant, "&s", &download_directory_value);
std::string default_download_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
auto current_value = std::string(download_directory_value);
if (current_value.empty()) {
g_settings_set_value(priv->settings, "download-folder", g_variant_new("s", default_download_dir.c_str()));
}
// get full path
std::string filename = current_value.empty()? default_download_dir.c_str() : download_directory_value;
if (!filename.empty() && filename.back() != '/') filename += "/";
filename += info.displayName;
model->acceptTransfer(priv->conversation_->uid, interactionId, filename);
} catch (...) {
// ignore
}
......
......@@ -22,6 +22,7 @@
// GTK+ related
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <glib.h>
// LRC
#include <person.h>
......@@ -63,6 +64,7 @@ struct _GeneralSettingsViewPrivate
GtkWidget *box_profil_settings;
GtkWidget *avatarmanipulation;
GtkWidget *profile_name;
GtkWidget *directory_chooser;
/* history settings */
GtkWidget *adjustment_history_duration;
......@@ -134,6 +136,17 @@ clear_history(G_GNUC_UNUSED GtkWidget *button, GeneralSettingsView *self)
g_signal_emit(G_OBJECT(self), general_settings_view_signals[CLEAR_ALL_HISTORY], 0);
}
static void
change_prefered_directory (GtkFileChooserButton *widget, GeneralSettingsView *self)
{
g_return_if_fail(IS_GENERAL_SETTINGS_VIEW(self));
GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self);
priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
auto download_directory_value = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (priv->directory_chooser));
g_settings_set_value(priv->settings, "download-folder", g_variant_new("s", download_directory_value));
}
static void
general_settings_view_init(GeneralSettingsView *self)
{
......@@ -175,8 +188,19 @@ general_settings_view_init(GeneralSettingsView *self)
priv->adjustment_history_duration, "value",
G_SETTINGS_BIND_DEFAULT);
auto* download_directory_variant = g_settings_get_value(priv->settings, "download-folder");
char* download_directory_value;
g_variant_get(download_directory_variant, "&s", &download_directory_value);
std::string default_download_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
auto current_value = std::string(download_directory_value);
if (current_value.empty()) {
g_settings_set_value(priv->settings, "download-folder", g_variant_new("s", default_download_dir.c_str()));
}
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->directory_chooser), current_value.empty()? default_download_dir.c_str() : download_directory_value);
/* clear history */
g_signal_connect(priv->button_clear_history, "clicked", G_CALLBACK(clear_history), self);
g_signal_connect(priv->directory_chooser, "file-set", G_CALLBACK(change_prefered_directory), self);
}
static void
......@@ -199,6 +223,7 @@ general_settings_view_class_init(GeneralSettingsViewClass *klass)
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, adjustment_history_duration);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, button_clear_history);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, box_profil_settings);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, directory_chooser);
general_settings_view_signals[CLEAR_ALL_HISTORY] = g_signal_new (
"clear-all-history",
......
......@@ -143,8 +143,34 @@
<property name="draw_indicator">True</property>
</object>
</child>
<child>
<object class="GtkBox" id="hbox_file_directory">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="label_file_directory">
<property name="label" translatable="yes">Download folder</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
</object>
</child>
<child>
<object class="GtkFileChooserButton" id="directory_chooser">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action">select-folder</property>
<property name="title" translatable="yes"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="box_position_chat">
<property name="visible">True</property>
......
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