Commit 67b5d0b0 authored by Giovanni Panozzo's avatar Giovanni Panozzo

Fixes for deprecated "resolution" setting, issue #1323

parent 8b925f0e
......@@ -218,10 +218,12 @@ remmina_file_load(const gchar *filename)
gchar *proto;
gchar **keys;
gchar *key;
gchar *resolution_str;
gint i;
gchar *s, *sec;
RemminaProtocolPlugin* protocol_plugin;
RemminaSecretPlugin *secret_plugin;
int w, h;
gkeyfile = g_key_file_new();
......@@ -279,8 +281,24 @@ remmina_file_load(const gchar *filename)
}
else
{
remmina_file_set_string_ref(remminafile, key,
/* If we find "resolution", then we split it in two */
if (strcmp(key, "resolution") == 0)
{
resolution_str = g_key_file_get_string(gkeyfile, "remmina", key, NULL);
if (remmina_public_split_resolution_string(resolution_str, &w, &h)) {
remmina_file_set_string_ref(remminafile, "resolution_width", g_strdup_printf("%i", w));
remmina_file_set_string_ref(remminafile, "resolution_height", g_strdup_printf("%i", h));
} else {
remmina_file_set_string_ref(remminafile, "resolution_width", NULL);
remmina_file_set_string_ref(remminafile, "resolution_height", NULL);
}
g_free(resolution_str);
}
else
{
remmina_file_set_string_ref(remminafile, key,
g_key_file_get_string(gkeyfile, "remmina", key, NULL));
}
}
}
g_strfreev(keys);
......@@ -305,23 +323,16 @@ void remmina_file_set_string(RemminaFile *remminafile, const gchar *setting, con
void remmina_file_set_string_ref(RemminaFile *remminafile, const gchar *setting, gchar *value)
{
TRACE_CALL("remmina_file_set_string_ref");
gint n, w, h;
const gchar* message;
if (value)
{
/* As special case here, the "resolution" field is split into two
* extra fields "resolution_width" and "resolution_height".
* The "resolution" field is left here for compatibility,
* and will never be saved on new files.
* This code is useful when loading files with only "resolution" field set */
/* We refuse to accept to set the "resolution" field */
if (strcmp(setting, "resolution") == 0) {
n = sscanf(value, "%dx%d", &w, &h);
if (n < 2)
h = 600;
if (n < 1)
w = 800;
g_hash_table_insert(remminafile->settings, g_strdup("resolution_width"), g_strdup_printf("%i", w));
g_hash_table_insert(remminafile->settings, g_strdup("resolution_height"), g_strdup_printf("%i", h));
message = "WARNING: the \"resolution\" setting in .pref files is deprecated, but some code in remmina or in a plugin is trying to set it.\n";
fputs(message, stdout);
remmina_main_show_warning_dialog(message);
return;
}
g_hash_table_insert(remminafile->settings, g_strdup(setting), value);
}
......@@ -335,7 +346,11 @@ const gchar*
remmina_file_get_string(RemminaFile *remminafile, const gchar *setting)
{
TRACE_CALL("remmina_file_get_string");
gchar *value, *w, *h;
gchar *value;
const gchar* message;
/* Returned value is a pointer to the string stored on the hash table,
* please do not free it or the hash table will contain invalid pointer */
if ( !remmina_masterthread_exec_is_main_thread() )
{
......@@ -353,17 +368,11 @@ remmina_file_get_string(RemminaFile *remminafile, const gchar *setting)
return retval;
}
/* For backward compatibility with old code that needs to read the
* "resolution" preference setting*/
if (strcmp(setting, "resolution") == 0) {
w = (gchar*) g_hash_table_lookup(remminafile->settings, "resolution_width");
h = (gchar*) g_hash_table_lookup(remminafile->settings, "resolution_height");
if (w == NULL)
w = "800";
if (h == NULL)
h = "600";
value = g_strdup_printf("%sx%s", w, h);
g_hash_table_insert(remminafile->settings, g_strdup("resolution"), value);
message = "WARNING: the \"resolution\" setting in .pref files is deprecated, but some code in remmina or in a plugin is trying to read it.\n";
fputs(message, stdout);
remmina_main_show_warning_dialog(message);
return NULL;
}
value = (gchar*) g_hash_table_lookup(remminafile->settings, setting);
......@@ -564,13 +573,14 @@ void remmina_file_update_screen_resolution(RemminaFile *remminafile)
#else
gint monitor;
#endif
gchar *pos;
gchar *resolution;
const gchar *resolution_w, *resolution_h;
gint x, y;
GdkRectangle rect;
resolution = g_strdup(remmina_file_get_string(remminafile, "resolution"));
if (resolution == NULL || strchr(resolution, 'x') == NULL)
resolution_w = remmina_file_get_string(remminafile, "resolution_width");
resolution_h = remmina_file_get_string(remminafile, "resolution_height");
if (resolution_w == NULL || resolution_h == NULL || resolution_w[0] == 0 || resolution_h[0] == 0)
{
display = gdk_display_get_default();
/* gdk_display_get_device_manager deprecated since 3.20, Use gdk_display_get_default_seat */
......@@ -592,14 +602,6 @@ void remmina_file_update_screen_resolution(RemminaFile *remminafile)
remmina_file_set_int(remminafile, "resolution_width", rect.width);
remmina_file_set_int(remminafile, "resolution_height", rect.height);
}
else
{
pos = strchr(resolution, 'x');
*pos++ = '\0';
remmina_file_set_int(remminafile, "resolution_width", MAX(100, MIN(4096, atoi(resolution))));
remmina_file_set_int(remminafile, "resolution_height", MAX(100, MIN(4096, atoi(pos))));
}
g_free(resolution);
}
const gchar*
......
......@@ -497,7 +497,8 @@ static void remmina_file_editor_create_resolution(RemminaFileEditor* gfe, const
TRACE_CALL("remmina_file_editor_create_resolution");
GtkWidget* widget;
GtkWidget* hbox;
const gchar* resolution;
const gchar *resolution_w, *resolution_h;
gchar *res_str;
widget = gtk_label_new(_("Resolution"));
gtk_widget_show(widget);
......@@ -519,9 +520,14 @@ static void remmina_file_editor_create_resolution(RemminaFileEditor* gfe, const
gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 0);
gfe->priv->resolution_custom_radio = widget;
resolution = remmina_file_get_string(gfe->priv->remmina_file, "resolution");
resolution_w = remmina_file_get_string(gfe->priv->remmina_file, "resolution_width");
resolution_h = remmina_file_get_string(gfe->priv->remmina_file, "resolution_height");
widget = remmina_public_create_combo_text_d(remmina_pref.resolutions, resolution, NULL);
if (resolution_w && resolution_h && resolution_w[0] != 0 && resolution_h[0] != 0)
res_str = g_strdup_printf("%sx%s", resolution_w, resolution_h);
else
res_str = NULL;
widget = remmina_public_create_combo_text_d(remmina_pref.resolutions, res_str, NULL);
gtk_widget_show(widget);
gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
gfe->priv->resolution_custom_combo = widget;
......@@ -534,15 +540,17 @@ static void remmina_file_editor_create_resolution(RemminaFileEditor* gfe, const
g_signal_connect(G_OBJECT(gfe->priv->resolution_custom_radio), "toggled",
G_CALLBACK(remmina_file_editor_button_on_toggled), gfe->priv->resolution_custom_combo);
if (!resolution || strchr(resolution, 'x') == NULL)
if (res_str)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gfe->priv->resolution_auto_radio), TRUE);
gtk_widget_set_sensitive(gfe->priv->resolution_custom_combo, FALSE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gfe->priv->resolution_custom_radio), TRUE);
}
else
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gfe->priv->resolution_custom_radio), TRUE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gfe->priv->resolution_auto_radio), TRUE);
gtk_widget_set_sensitive(gfe->priv->resolution_custom_combo, FALSE);
}
g_free(res_str);
}
static GtkWidget* remmina_file_editor_create_text(RemminaFileEditor* gfe, GtkWidget* grid,
......@@ -1127,6 +1135,9 @@ static void remmina_file_editor_update_settings(RemminaFileEditor* gfe)
static void remmina_file_editor_update(RemminaFileEditor* gfe)
{
TRACE_CALL("remmina_file_editor_update");
gchar *custom_resolution, *res_w, *res_h;
int w, h;
RemminaFileEditorPriv* priv = gfe->priv;
remmina_file_set_string(priv->remmina_file, "name", gtk_entry_get_text(GTK_ENTRY(priv->name_entry)));
......@@ -1145,13 +1156,28 @@ static void remmina_file_editor_update(RemminaFileEditor* gfe)
if (priv->resolution_auto_radio)
{
remmina_file_set_string_ref(
priv->remmina_file,
"resolution",
(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->resolution_auto_radio)) ?
NULL :
remmina_public_combo_get_active_text(
GTK_COMBO_BOX(priv->resolution_custom_combo))));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->resolution_auto_radio)))
{
/* Resolution is set to auto */
res_w = res_h = NULL;
}
else
{
/* Resolution is set to a value from the list */
custom_resolution = remmina_public_combo_get_active_text(GTK_COMBO_BOX(priv->resolution_custom_combo));
if (sscanf(custom_resolution, "%dx%d", &w, &h) >= 2)
{
res_w = g_strdup_printf("%i", w);
res_h = g_strdup_printf("%i", h);
}
else
{
res_w = res_h = NULL;
}
g_free(custom_resolution);
}
remmina_file_set_string_ref(priv->remmina_file, "resolution_width", res_w);
remmina_file_set_string_ref(priv->remmina_file, "resolution_height", res_h);
}
if (priv->keymap_combo)
......
......@@ -1245,3 +1245,14 @@ void remmina_main_update_file_datetime(RemminaFile *file)
return;
remmina_main_load_files();
}
void remmina_main_show_warning_dialog(const gchar* message)
{
GtkWidget* dialog;
if (remminamain->window) {
dialog = gtk_message_dialog_new(remminamain->window, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
message, g_get_application_name());
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
}
......@@ -117,6 +117,8 @@ void remmina_main_update_file_datetime(RemminaFile *file);
void remmina_main_destroy(void);
void remmina_main_show_warning_dialog(const gchar* message);
G_END_DECLS
#endif /* __REMMINAMAIN_H__ */
......@@ -731,3 +731,14 @@ gchar* remmina_public_str_replace_in_place(gchar *string, const gchar *search, c
return string;
}
int remmina_public_split_resolution_string(const char *resolution_string, int *w, int *h)
{
int lw, lh;
if (resolution_string == NULL || resolution_string[0] == 0)
return 0;
if (sscanf(resolution_string, "%dx%d", &lw, &lh) != 2)
return 0;
*w = lw;
*h = lh;
return 1;
}
......@@ -116,4 +116,6 @@ gchar* remmina_public_str_replace(const gchar *string, const gchar *search, cons
/* Replaces all occurences of search in a new copy of string by replacement
* and overwrites the original string */
gchar* remmina_public_str_replace_in_place(gchar *string, const gchar *search, const gchar *replacement);
int remmina_public_split_resolution_string(const char *resolution_string, int *w, int *h);
#endif /* __REMMINAPUBLIC_H__ */
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