[epiphany] Add default zoom level option to preferences dialog
- From: Jan-Michael Brummer <jbrummer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Add default zoom level option to preferences dialog
- Date: Fri, 4 Jan 2019 17:27:58 +0000 (UTC)
commit 26eee0065f897465069b27e6cb3d7486aa41f60e
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Tue Dec 25 14:34:58 2018 +0100
Add default zoom level option to preferences dialog
Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/8
embed/ephy-web-view.c | 6 +-
lib/ephy-profile-utils.h | 2 +-
lib/ephy-zoom.c | 11 +++-
lib/history/ephy-history-service-hosts-table.c | 17 ++++--
lib/history/ephy-history-service-urls-table.c | 2 +-
src/ephy-window.c | 6 +-
src/prefs-dialog.c | 37 ++++++++++++
src/profile-migrator/ephy-profile-migrator.c | 81 +++++++++++++++++++++++++-
src/resources/gtk/prefs-dialog.ui | 49 +++++++++++++++-
src/window-commands.c | 2 +-
tests/ephy-history-test.c | 19 +++++-
11 files changed, 216 insertions(+), 16 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index a3c9fa9e9..2155d482b 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1731,7 +1731,11 @@ get_host_for_url_cb (gpointer service,
current_zoom = webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW (view));
- if (host->visit_count == 0) {
+ /* Use default zoom level in case web page is
+ * - not visited before
+ * - uses default zoom level (0)
+ */
+ if (host->visit_count == 0 || host->zoom_level == 0.0) {
set_zoom = g_settings_get_double (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL);
} else {
set_zoom = host->zoom_level;
diff --git a/lib/ephy-profile-utils.h b/lib/ephy-profile-utils.h
index c5432e11b..0ed11f65e 100644
--- a/lib/ephy-profile-utils.h
+++ b/lib/ephy-profile-utils.h
@@ -24,7 +24,7 @@
G_BEGIN_DECLS
-#define EPHY_PROFILE_MIGRATION_VERSION 28
+#define EPHY_PROFILE_MIGRATION_VERSION 29
#define EPHY_INSECURE_PASSWORDS_MIGRATION_VERSION 11
#define EPHY_SETTINGS_MIGRATION_VERSION 16
#define EPHY_FIREFOX_SYNC_PASSWORDS_MIGRATION_VERSION 19
diff --git a/lib/ephy-zoom.c b/lib/ephy-zoom.c
index 53fd4e507..8591d0092 100644
--- a/lib/ephy-zoom.c
+++ b/lib/ephy-zoom.c
@@ -19,6 +19,11 @@
*/
#include "config.h"
+
+#include <glib.h>
+
+#include "ephy-prefs.h"
+#include "ephy-settings.h"
#include "ephy-zoom.h"
#define NUM_ZOOM_STEPS 14
@@ -56,14 +61,14 @@ ephy_zoom_get_changed_zoom_level (float level, int steps)
if (i == NUM_ZOOM_STEPS) {
/* No exact step found, try to find the nearest value */
for (i = 0; i < NUM_ZOOM_STEPS - 1; i++) {
- if (zoom_steps[i] > level && zoom_steps[i + 1] < level)
+ if (zoom_steps[i] < level && zoom_steps[i + 1] > level)
break;
}
}
if (i == NUM_ZOOM_STEPS) {
- /* Still no match? Set it to default (1.0) */
- i = 5;
+ /* Still no match? Return default */
+ return g_settings_get_double (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL);
}
if (steps == -1 && i > 0) {
diff --git a/lib/history/ephy-history-service-hosts-table.c b/lib/history/ephy-history-service-hosts-table.c
index 5b2edfab1..f9695356a 100644
--- a/lib/history/ephy-history-service-hosts-table.c
+++ b/lib/history/ephy-history-service-hosts-table.c
@@ -22,6 +22,8 @@
#include "ephy-history-service.h"
#include "ephy-history-service-private.h"
+#include "ephy-prefs.h"
+#include "ephy-settings.h"
#include "ephy-string.h"
#include <glib/gi18n.h>
@@ -39,7 +41,7 @@ ephy_history_service_initialize_hosts_table (EphyHistoryService *self)
"url LONGVARCAR,"
"title LONGVARCAR,"
"visit_count INTEGER DEFAULT 0 NOT NULL,"
- "zoom_level REAL DEFAULT 1.0)", &error);
+ "zoom_level REAL DEFAULT 0.0)", &error);
if (error) {
g_warning ("Could not create hosts table: %s", error->message);
@@ -94,6 +96,7 @@ ephy_history_service_update_host_row (EphyHistoryService *self, EphyHistoryHost
{
EphySQLiteStatement *statement;
GError *error = NULL;
+ gdouble zoom_level;
g_assert (self->history_thread == g_thread_self ());
g_assert (self->history_database != NULL);
@@ -107,10 +110,16 @@ ephy_history_service_update_host_row (EphyHistoryService *self, EphyHistoryHost
return;
}
+ zoom_level = host->zoom_level;
+
+ /* Ensure that a change value which equals default zoom level is stored as 0.0 */
+ if (zoom_level == g_settings_get_double (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL))
+ zoom_level = 0.0f;
+
if (ephy_sqlite_statement_bind_string (statement, 0, host->url, &error) == FALSE ||
ephy_sqlite_statement_bind_string (statement, 1, host->title, &error) == FALSE ||
ephy_sqlite_statement_bind_int (statement, 2, host->visit_count, &error) == FALSE ||
- ephy_sqlite_statement_bind_double (statement, 3, host->zoom_level, &error) == FALSE ||
+ ephy_sqlite_statement_bind_double (statement, 3, zoom_level, &error) == FALSE ||
ephy_sqlite_statement_bind_int (statement, 4, host->id, &error) == FALSE) {
g_warning ("Could not modify host in hosts table: %s", error->message);
g_error_free (error);
@@ -176,7 +185,7 @@ ephy_history_service_get_host_row (EphyHistoryService *self, const gchar *host_s
}
if (host == NULL) {
- host = ephy_history_host_new (NULL, NULL, 0, 1.0);
+ host = ephy_history_host_new (NULL, NULL, 0, 0.0);
} else {
if (host->url)
g_free (host->url);
@@ -408,7 +417,7 @@ ephy_history_service_get_host_row_from_url (EphyHistoryService *self,
}
if (host == NULL) {
- host = ephy_history_host_new (host_locations->data, hostname, 0, 1.0);
+ host = ephy_history_host_new (host_locations->data, hostname, 0, 0.0);
if (!self->read_only)
ephy_history_service_add_host_row (self, host);
}
diff --git a/lib/history/ephy-history-service-urls-table.c b/lib/history/ephy-history-service-urls-table.c
index cb5cd2d38..a1a4daa9b 100644
--- a/lib/history/ephy-history-service-urls-table.c
+++ b/lib/history/ephy-history-service-urls-table.c
@@ -213,7 +213,7 @@ create_url_from_statement (EphySQLiteStatement *statement)
ephy_sqlite_statement_get_column_as_int64 (statement, 5));
url->id = ephy_sqlite_statement_get_column_as_int (statement, 0);
- url->host = ephy_history_host_new (NULL, NULL, 0, 1.0);
+ url->host = ephy_history_host_new (NULL, NULL, 0, 0.0);
url->hidden = ephy_sqlite_statement_get_column_as_int (statement, 6);
url->host->id = ephy_sqlite_statement_get_column_as_int (statement, 7);
url->sync_id = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 8));
diff --git a/src/ephy-window.c b/src/ephy-window.c
index e391276ff..22fe0b064 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1066,7 +1066,7 @@ sync_tab_zoom (WebKitWebView *web_view, GParamSpec *pspec, EphyWindow *window)
can_zoom_out = FALSE;
}
- if (zoom != 1.0) {
+ if (zoom != g_settings_get_double (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL)) {
can_zoom_normal = TRUE;
}
@@ -3640,6 +3640,10 @@ ephy_window_set_zoom (EphyWindow *window,
else if (zoom == ZOOM_OUT)
zoom = ephy_zoom_get_changed_zoom_level (current_zoom, -1);
+ /* Use default zoom value if zoom is not set */
+ if (!zoom)
+ zoom = g_settings_get_double (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL);
+
if (zoom != current_zoom)
webkit_web_view_set_zoom_level (web_view, zoom);
}
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 648c5f7f9..761af6d03 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -56,6 +56,7 @@
#include <gtk/gtk.h>
#include <JavaScriptCore/JavaScript.h>
#include <json-glib/json-glib.h>
+#include <math.h>
#include <string.h>
#define DOWNLOAD_BUTTON_WIDTH 8
@@ -104,6 +105,7 @@ struct _PrefsDialog {
GtkWidget *mono_fontbutton;
GtkWidget *css_checkbox;
GtkWidget *css_edit_button;
+ GtkWidget *default_zoom_spin_button;
GtkWidget *reader_mode_box;
GtkWidget *reader_mode_font_style;
GtkWidget *reader_mode_color_scheme;
@@ -927,6 +929,35 @@ on_search_engine_dialog_button_clicked (GtkWidget *button,
gtk_window_present (search_engine_dialog);
}
+static gboolean
+on_default_zoom_spin_button_output (GtkSpinButton *spin,
+ gpointer user_data)
+{
+ GtkAdjustment *adjustment;
+ g_autofree gchar *text = NULL;
+ gdouble value;
+
+ adjustment = gtk_spin_button_get_adjustment (spin);
+ value = (int)gtk_adjustment_get_value (adjustment);
+ text = g_strdup_printf ("%.f%%", value);
+ gtk_entry_set_text (GTK_ENTRY (spin), text);
+
+ return TRUE;
+}
+
+static void
+on_default_zoom_spin_button_value_changed (GtkSpinButton *spin,
+ gpointer user_data)
+{
+ GtkAdjustment *adjustment;
+ gdouble value;
+
+ adjustment = gtk_spin_button_get_adjustment (spin);
+ value = gtk_adjustment_get_value (adjustment);
+ value = roundf(value) / 100;
+ g_settings_set_double (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL, value);
+}
+
static void
prefs_dialog_class_init (PrefsDialogClass *klass)
{
@@ -970,6 +1001,7 @@ prefs_dialog_class_init (PrefsDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, PrefsDialog, mono_fontbutton);
gtk_widget_class_bind_template_child (widget_class, PrefsDialog, css_checkbox);
gtk_widget_class_bind_template_child (widget_class, PrefsDialog, css_edit_button);
+ gtk_widget_class_bind_template_child (widget_class, PrefsDialog, default_zoom_spin_button);
gtk_widget_class_bind_template_child (widget_class, PrefsDialog, reader_mode_box);
gtk_widget_class_bind_template_child (widget_class, PrefsDialog, reader_mode_font_style);
gtk_widget_class_bind_template_child (widget_class, PrefsDialog, reader_mode_color_scheme);
@@ -1027,6 +1059,8 @@ prefs_dialog_class_init (PrefsDialogClass *klass)
gtk_widget_class_bind_template_callback (widget_class, on_sync_device_name_change_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_sync_device_name_save_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_sync_device_name_cancel_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_default_zoom_spin_button_output);
+ gtk_widget_class_bind_template_callback (widget_class, on_default_zoom_spin_button_value_changed);
}
static void
@@ -2157,6 +2191,9 @@ setup_fonts_page (PrefsDialog *dialog)
"clicked",
G_CALLBACK (css_edit_button_clicked_cb),
dialog);
+
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->default_zoom_spin_button),
+ g_settings_get_double (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL) *
100);
}
static void
diff --git a/src/profile-migrator/ephy-profile-migrator.c b/src/profile-migrator/ephy-profile-migrator.c
index 14b276946..08c9485cd 100644
--- a/src/profile-migrator/ephy-profile-migrator.c
+++ b/src/profile-migrator/ephy-profile-migrator.c
@@ -1226,6 +1226,84 @@ migrate_nothing (void)
*/
}
+static void
+migrate_zoom_level (void)
+{
+ EphySQLiteConnection *history_db = NULL;
+ EphySQLiteStatement *statement = NULL;
+ GError *error = NULL;
+ char *history_filename;
+ const char *sql_query;
+
+ history_filename = g_build_filename (ephy_dot_dir (), EPHY_HISTORY_FILE, NULL);
+ if (!g_file_test (history_filename, G_FILE_TEST_EXISTS)) {
+ LOG ("There is no history to migrate...");
+ goto out;
+ }
+
+ history_db = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE,
+ history_filename);
+ ephy_sqlite_connection_open (history_db, &error);
+ if (error) {
+ g_warning ("Failed to open history database: %s", error->message);
+ g_clear_object (&history_db);
+ goto out;
+ }
+
+ /* Update zoom level values. */
+ sql_query = "UPDATE hosts SET zoom_level = 0.0 WHERE zoom_level = 1.0";
+ ephy_sqlite_connection_execute (history_db, sql_query, &error);
+ if (error) {
+ g_warning ("Failed to update zoom level: %s", error->message);
+ goto out;
+ }
+
+ sql_query = "CREATE TABLE hosts_backup ("
+ "id INTEGER PRIMARY KEY,"
+ "url LONGVARCAR,"
+ "title LONGVARCAR,"
+ "visit_count INTEGER DEFAULT 0 NOT NULL,"
+ "zoom_level REAL DEFAULT 0.0)";
+
+ ephy_sqlite_connection_execute (history_db, sql_query, &error);
+ if (error) {
+ g_warning ("Failed to create host backup table: %s", error->message);
+ goto out;
+ }
+
+ sql_query = "INSERT INTO hosts_backup SELECT id,url,title,visit_count,zoom_level FROM hosts";
+ ephy_sqlite_connection_execute (history_db, sql_query, &error);
+ if (error) {
+ g_warning ("Failed to copy data from hosts to hosts_backup: %s", error->message);
+ goto out;
+ }
+
+ sql_query = "DROP TABLE hosts";
+ ephy_sqlite_connection_execute (history_db, sql_query, &error);
+ if (error) {
+ g_warning ("Failed to remove table hosts: %s", error->message);
+ goto out;
+ }
+
+ sql_query = "ALTER TABLE hosts_backup RENAME TO hosts";
+ ephy_sqlite_connection_execute (history_db, sql_query, &error);
+ if (error) {
+ g_warning ("Failed to rename hosts_backup to hosts: %s", error->message);
+ goto out;
+ }
+
+out:
+ g_free (history_filename);
+ if (history_db) {
+ ephy_sqlite_connection_close (history_db);
+ g_object_unref (history_db);
+ }
+ if (statement)
+ g_object_unref (statement);
+ if (error)
+ g_error_free (error);
+}
+
/* If adding anything here, you need to edit EPHY_PROFILE_MIGRATION_VERSION
* in ephy-profile-utils.h. */
const EphyProfileMigrator migrators[] = {
@@ -1256,7 +1334,8 @@ const EphyProfileMigrator migrators[] = {
/* 25 */ migrate_passwords_timestamp,
/* 26 */ migrate_nothing,
/* 27 */ migrate_search_engines,
- /* 28 */ migrate_annoyance_list
+ /* 28 */ migrate_annoyance_list,
+ /* 29 */ migrate_zoom_level
};
static gboolean
diff --git a/src/resources/gtk/prefs-dialog.ui b/src/resources/gtk/prefs-dialog.ui
index a080e16dc..eabe9d116 100644
--- a/src/resources/gtk/prefs-dialog.ui
+++ b/src/resources/gtk/prefs-dialog.ui
@@ -538,6 +538,7 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
+ <property name="spacing">6</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
@@ -570,6 +571,38 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="spacing">24</property>
+ <property name="margin-start">12</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ <property name="label" translatable="yes">Default zoom level:</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="default_zoom_spin_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="input_purpose">number</property>
+ <property name="adjustment">zoom_adjustment</property>
+ <property name="max_width_chars">5</property>
+ <property name="value">100</property>
+ <signal name="value-changed"
handler="on_default_zoom_spin_button_value_changed"/>
+ <signal name="output" handler="on_default_zoom_spin_button_output"/>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
<child>
<object class="GtkBox" id="reader_mode_box">
<property name="visible">True</property>
@@ -582,7 +615,6 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
- <property name="margin_top">6</property>
<property name="label" translatable="yes">Reader Mode</property>
<attributes>
<attribute name="weight" value="bold"/>
@@ -661,7 +693,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
</object>
@@ -1350,4 +1382,17 @@
<widget name="sync_device_name_change_button"/>
</widgets>
</object>
+ <object class="GtkSizeGroup">
+ <property name="mode">horizontal</property>
+ <widgets>
+ <widget name="css_edit_button"/>
+ <widget name="default_zoom_spin_button"/>
+ </widgets>
+ </object>
+ <object class="GtkAdjustment" id="zoom_adjustment">
+ <property name="lower">33</property>
+ <property name="upper">300</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
</interface>
diff --git a/src/window-commands.c b/src/window-commands.c
index afb8bda04..ef6c99023 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1743,7 +1743,7 @@ window_cmd_zoom_normal (GSimpleAction *action,
gpointer user_data)
{
EphyWindow *window = user_data;
- ephy_window_set_zoom (window, 1.0);
+ ephy_window_set_zoom (window, 0.0);
}
void
diff --git a/tests/ephy-history-test.c b/tests/ephy-history-test.c
index 0fa8040dd..e1d549b87 100644
--- a/tests/ephy-history-test.c
+++ b/tests/ephy-history-test.c
@@ -19,6 +19,8 @@
*/
#include "config.h"
+#include "ephy-debug.h"
+#include "ephy-file-helpers.h"
#include "ephy-history-service.h"
#include <glib/gstdio.h>
@@ -497,8 +499,19 @@ test_clear (void)
int
main (int argc, char *argv[])
{
+ int ret;
+
gtk_test_init (&argc, &argv);
+ ephy_debug_init ();
+
+ if (!ephy_file_helpers_init (NULL,
+ EPHY_FILE_HELPERS_TESTING_MODE | EPHY_FILE_HELPERS_ENSURE_EXISTS,
+ NULL)) {
+ g_debug ("Something wrong happened with ephy_file_helpers_init()");
+ return -1;
+ }
+
g_test_add_func ("/embed/history/test_create_history_service", test_create_history_service);
g_test_add_func ("/embed/history/test_create_history_service_and_destroy_later",
test_create_history_service_and_destroy_later);
g_test_add_func ("/embed/history/test_create_history_entry", test_create_history_entry);
@@ -513,5 +526,9 @@ main (int argc, char *argv[])
g_test_add_func ("/embed/history/test_complex_url_query_with_time_range",
test_complex_url_query_with_time_range);
g_test_add_func ("/embed/history/test_clear", test_clear);
- return g_test_run ();
+ ret = g_test_run ();
+
+ ephy_file_helpers_shutdown ();
+
+ return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]