Commit 77a281ab authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

rewrite panel properties dialog

parent 4daf3d4c
......@@ -94,6 +94,7 @@
<_description>The speed in which panel animations should occur. Possible values are "slow", "medium" and "fast". This key is only relevant if the enable_animations key is true.</_description>
</key>
<child name="background" schema="org.gnome.gnome-panel.toplevel.background"/>
<child name="theme" schema="org.gnome.gnome-panel.toplevel.theme"/>
</schema>
<schema id="org.gnome.gnome-panel.toplevel.background">
<key name="type" enum="org.gnome.gnome-panel.PanelBackgroundType">
......@@ -122,4 +123,51 @@
<_description>Determines how the image set by image-uri is rendered. Possible values are "none", "stretch", "fit". With "stretch", the image will be scaled to the panel dimensions and the aspect ratio of the image will not be maintained. With "fit", the image will be scaled (retaining the aspect ratio of the image) to the panel height (if horizontal).</_description>
</key>
</schema>
<schema id="org.gnome.gnome-panel.toplevel.theme">
<key name="custom-bg-color" type="b">
<default>false</default>
<_summary>Use custom background color</_summary>
</key>
<key name="bg-color" type="s">
<default>'#000000'</default>
<_summary>Background Color</_summary>
</key>
<key name="custom-bg-image" type="b">
<default>false</default>
<_summary>Use custom background image</_summary>
</key>
<key name="bg-image" type="s">
<default>''</default>
<_summary>Background image</_summary>
<_description>Specifies the file to be used for the background image. If the image contains an alpha channel it will be composited onto the desktop background image.</_description>
</key>
<key name="bg-image-style" enum="org.gnome.gnome-panel.PanelBackgroundImageStyle">
<default>'none'</default>
<_summary>Image options</_summary>
<_description>Determines how the image set by image-uri is rendered. Possible values are "none", "stretch", "fit". With "stretch", the image will be scaled to the panel dimensions and the aspect ratio of the image will not be maintained. With "fit", the image will be scaled (retaining the aspect ratio of the image) to the panel height (if horizontal).</_description>
</key>
<key name="bg-image-rotate" type="b">
<default>false</default>
<_summary>Rotate image on vertical panels</_summary>
<_description>If true, the background image will be rotated when the panel is oriented vertically.</_description>
</key>
<key name="custom-fg-color" type="b">
<default>false</default>
<_summary>Use custom text color</_summary>
</key>
<key name="fg-color" type="s">
<default>'#ffffff'</default>
<_summary>Text Color</_summary>
</key>
</schema>
</schemalist>
......@@ -15,6 +15,8 @@ panel_sources = \
$(gnome_panel_BUILT_SOURCES) \
gp-arrow-button.c \
gp-arrow-button.h \
gp-properties-dialog.c \
gp-properties-dialog.h \
main.c \
panel-widget.c \
button-widget.c \
......@@ -25,7 +27,6 @@ panel_sources = \
panel.c \
applet.c \
panel-util.c \
panel-properties-dialog.c \
panel-run-dialog.c \
menu.c \
panel-context-menu.c \
......@@ -71,7 +72,6 @@ panel_headers = \
panel.h \
applet.h \
panel-util.h \
panel-properties-dialog.h \
panel-run-dialog.h \
menu.h \
panel-context-menu.h \
......@@ -259,8 +259,8 @@ BUILT_SOURCES = \
$(panel_test_applets_BUILT_SOURCES)
ui_FILES = \
gp-properties-dialog.ui \
panel-addto-dialog.ui \
panel-properties-dialog.ui \
panel-run-dialog.ui
panel-resources.c: panel.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/panel.gresource.xml)
......
......@@ -29,7 +29,6 @@
#include "panel-util.h"
#include "panel-menu-button.h"
#include "panel-globals.h"
#include "panel-properties-dialog.h"
#include "panel-layout.h"
#include "panel-lockdown.h"
#include "panel-schemas.h"
......
/*
* Copyright (C) 2016 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib/gi18n.h>
#include "gp-properties-dialog.h"
struct _GpPropertiesDialog
{
GtkWindow parent;
gchar *toplevel_id;
GSettings *toplevel;
GSettings *theme;
GtkWidget *toplevel_writable;
GtkWidget *theme_writable;
GtkWidget *orientation;
GtkWidget *size;
GtkWidget *expand;
GtkWidget *auto_hide;
GtkWidget *enable_buttons;
GtkWidget *enable_arrows;
GtkWidget *custom_bg_color;
GtkWidget *bg_color_box;
GtkWidget *bg_color;
GtkWidget *custom_bg_image;
GtkWidget *bg_image_box;
GtkWidget *bg_image;
GtkWidget *tile;
GtkWidget *stretch;
GtkWidget *fit;
GtkWidget *rotate;
GtkWidget *custom_fg_color;
GtkWidget *fg_color_box;
GtkWidget *fg_color;
};
enum
{
PROP_0,
PROP_TOPLEVEL_ID,
LAST_PROP
};
static GParamSpec *properties[LAST_PROP] = { NULL };
G_DEFINE_TYPE (GpPropertiesDialog, gp_properties_dialog, GTK_TYPE_WINDOW)
static gboolean
style_get (GValue *value,
GVariant *variant,
gpointer user_data)
{
const gchar *str;
str = g_variant_get_string (variant, NULL);
if (g_strcmp0 (str, (const gchar *) user_data) == 0)
g_value_set_boolean (value, TRUE);
else
g_value_set_boolean (value, FALSE);
return TRUE;
}
static GVariant *
style_set (const GValue *value,
const GVariantType *expected_type,
gpointer user_data)
{
if (g_value_get_boolean (value))
return g_variant_new_string ((const gchar *) user_data);
return NULL;
}
static void
bg_image_changed_cb (GSettings *settings,
const gchar *key,
GpPropertiesDialog *dialog)
{
GtkFileChooser *chooser;
gchar *uri;
chooser = GTK_FILE_CHOOSER (dialog->bg_image);
uri = g_settings_get_string (dialog->theme, key);
if (!uri)
gtk_file_chooser_unselect_all (chooser);
else
gtk_file_chooser_set_uri (chooser, uri);
g_free (uri);
}
static void
bg_image_file_set_cb (GtkFileChooserButton *button,
GpPropertiesDialog *dialog)
{
gchar *uri;
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (button));
if (!uri)
uri = g_strdup ("");
g_settings_set_string (dialog->theme, "bg-image", uri);
g_free (uri);
}
static void
custom_bg_color_toggled_cb (GtkToggleButton *button,
GpPropertiesDialog *dialog)
{
gboolean sensitive;
sensitive = gtk_toggle_button_get_active (button);
gtk_widget_set_sensitive (dialog->bg_color_box, sensitive);
}
static void
custom_bg_image_toggled_cb (GtkToggleButton *button,
GpPropertiesDialog *dialog)
{
gboolean sensitive;
sensitive = gtk_toggle_button_get_active (button);
gtk_widget_set_sensitive (dialog->bg_image_box, sensitive);
}
static void
custom_fg_color_toggled_cb (GtkToggleButton *button,
GpPropertiesDialog *dialog)
{
gboolean sensitive;
sensitive = gtk_toggle_button_get_active (button);
gtk_widget_set_sensitive (dialog->fg_color_box, sensitive);
}
static gboolean
color_get (GValue *value,
GVariant *variant,
gpointer user_data)
{
const gchar *color;
GdkRGBA rgba;
g_variant_get (variant, "&s", &color);
if (!gdk_rgba_parse (&rgba, color))
return FALSE;
g_value_set_boxed (value, &rgba);
return TRUE;
}
static GVariant *
color_set (const GValue *value,
const GVariantType *expected_type,
gpointer user_data)
{
GdkRGBA *rgba;
gchar *color;
GVariant *variant;
rgba = g_value_get_boxed (value);
if (!rgba)
return NULL;
color = gdk_rgba_to_string (rgba);
variant = g_variant_new_string (color);
g_free (color);
return variant;
}
static void
setup_toplevel_bindings (GpPropertiesDialog *dialog)
{
GtkComboBoxText *text;
text = GTK_COMBO_BOX_TEXT (dialog->orientation);
gtk_combo_box_text_append (text, "top", NC_("Orientation", "Top"));
gtk_combo_box_text_append (text, "bottom", NC_("Orientation", "Bottom"));
gtk_combo_box_text_append (text, "left", NC_("Orientation", "Left"));
gtk_combo_box_text_append (text, "right", NC_("Orientation", "Right"));
g_settings_bind (dialog->toplevel, "orientation",
dialog->orientation, "active-id",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (dialog->toplevel, "size",
dialog->size, "value",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (dialog->toplevel, "expand",
dialog->expand, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (dialog->toplevel, "auto-hide",
dialog->auto_hide, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (dialog->toplevel, "enable-buttons",
dialog->enable_buttons, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (dialog->toplevel, "enable-arrows",
dialog->enable_arrows, "active",
G_SETTINGS_BIND_DEFAULT);
}
static void
setup_theme_bindings (GpPropertiesDialog *dialog)
{
g_settings_bind (dialog->theme, "custom-bg-color",
dialog->custom_bg_color, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind_with_mapping (dialog->theme, "bg-color",
dialog->bg_color, "rgba",
G_SETTINGS_BIND_DEFAULT,
color_get, color_set,
NULL, NULL);
g_settings_bind (dialog->theme, "custom-bg-image",
dialog->custom_bg_image, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind_writable (dialog->theme, "bg-image",
dialog->bg_image, "sensitive",
FALSE);
g_signal_connect (dialog->theme, "changed::bg-image",
G_CALLBACK (bg_image_changed_cb), dialog);
g_settings_bind_with_mapping (dialog->theme, "bg-image-style",
dialog->tile, "active",
G_SETTINGS_BIND_DEFAULT,
style_get, style_set,
(gpointer) "none",
NULL);
g_settings_bind_with_mapping (dialog->theme, "bg-image-style",
dialog->stretch, "active",
G_SETTINGS_BIND_DEFAULT,
style_get, style_set,
(gpointer) "stretch",
NULL);
g_settings_bind_with_mapping (dialog->theme, "bg-image-style",
dialog->fit, "active",
G_SETTINGS_BIND_DEFAULT,
style_get, style_set,
(gpointer) "fit",
NULL);
g_settings_bind (dialog->theme, "bg-image-rotate",
dialog->rotate, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (dialog->theme, "custom-fg-color",
dialog->custom_fg_color, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind_with_mapping (dialog->theme, "fg-color",
dialog->fg_color, "rgba",
G_SETTINGS_BIND_DEFAULT,
color_get, color_set,
NULL, NULL);
custom_bg_color_toggled_cb (GTK_TOGGLE_BUTTON (dialog->custom_bg_color), dialog);
custom_bg_image_toggled_cb (GTK_TOGGLE_BUTTON (dialog->custom_bg_image), dialog);
custom_fg_color_toggled_cb (GTK_TOGGLE_BUTTON (dialog->custom_fg_color), dialog);
bg_image_changed_cb (dialog->theme, "bg-image", dialog);
}
static gboolean
all_keys_writable (GSettings *settings,
const gchar **keys)
{
guint i;
for (i = 0; keys[i] != NULL; i++)
{
if (!g_settings_is_writable (settings, keys[i]))
return FALSE;
}
return TRUE;
}
static gboolean
toplevel_writable_change_event_cb (GSettings *settings,
guint key,
GpPropertiesDialog *dialog)
{
const gchar *toplevel[] = {
"orientation", "size", "expand", "auto-hide",
"enable-buttons", "enable-arrows", NULL
};
gboolean writable;
writable = all_keys_writable (settings, toplevel);
gtk_widget_set_visible (dialog->toplevel_writable, !writable);
return TRUE;
}
static gboolean
theme_writable_change_event_cb (GSettings *settings,
guint key,
GpPropertiesDialog *dialog)
{
const gchar *theme[] = {
"custom-bg-color", "bg-color", "custom-bg-image",
"bg-image", "bg-image-style", "bg-image-rotate",
"custom-fg-color", "fg-color", NULL
};
gboolean writable;
writable = all_keys_writable (settings, theme);
gtk_widget_set_visible (dialog->theme_writable, !writable);
return TRUE;
}
static void
setup_writability (GpPropertiesDialog *dialog)
{
g_signal_connect (dialog->toplevel, "writable-change-event",
G_CALLBACK (toplevel_writable_change_event_cb),
dialog);
g_signal_connect (dialog->theme, "writable-change-event",
G_CALLBACK (theme_writable_change_event_cb),
dialog);
toplevel_writable_change_event_cb (dialog->toplevel, 0, dialog);
theme_writable_change_event_cb (dialog->theme, 0, dialog);
}
static void
setup_bindings (GpPropertiesDialog *dialog)
{
setup_toplevel_bindings (dialog);
setup_theme_bindings (dialog);
}
static void
gp_properties_dialog_constructed (GObject *object)
{
GpPropertiesDialog *dialog;
const gchar *id;
const gchar *toplevel;
gchar *path;
dialog = GP_PROPERTIES_DIALOG (object);
G_OBJECT_CLASS (gp_properties_dialog_parent_class)->constructed (object);
id = dialog->toplevel_id;
toplevel = "org.gnome.gnome-panel.toplevel";
path = g_strdup_printf ("/org/gnome/gnome-panel/layout/toplevels/%s/", id);
dialog->toplevel = g_settings_new_with_path (toplevel, path);
dialog->theme = g_settings_get_child (dialog->toplevel, "theme");
g_free (path);
setup_writability (dialog);
setup_bindings (dialog);
}
static void
gp_properties_dialog_dispose (GObject *object)
{
GpPropertiesDialog *dialog;
dialog = GP_PROPERTIES_DIALOG (object);
g_clear_object (&dialog->toplevel);
g_clear_object (&dialog->theme);
G_OBJECT_CLASS (gp_properties_dialog_parent_class)->dispose (object);
}
static void
gp_properties_dialog_finalize (GObject *object)
{
GpPropertiesDialog *dialog;
dialog = GP_PROPERTIES_DIALOG (object);
g_free (dialog->toplevel_id);
G_OBJECT_CLASS (gp_properties_dialog_parent_class)->finalize (object);
}
static void
gp_properties_dialog_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GpPropertiesDialog *dialog;
dialog = GP_PROPERTIES_DIALOG (object);
switch (property_id)
{
case PROP_TOPLEVEL_ID:
dialog->toplevel_id = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
install_properties (GObjectClass *object_class)
{
properties[PROP_TOPLEVEL_ID] =
g_param_spec_string ("toplevel-id", "toplevel-id", "toplevel-id",
NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, properties);
}
static void
bind_template (GtkWidgetClass *widget_class)
{
const gchar *resource;
resource = "/org/gnome/panel/gp-properties-dialog.ui";
gtk_widget_class_set_template_from_resource (widget_class, resource);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, toplevel_writable);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, theme_writable);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, orientation);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, size);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, expand);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, auto_hide);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, enable_buttons);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, enable_arrows);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, custom_bg_color);
gtk_widget_class_bind_template_callback (widget_class, custom_bg_color_toggled_cb);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, bg_color_box);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, bg_color);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, custom_bg_image);
gtk_widget_class_bind_template_callback (widget_class, custom_bg_image_toggled_cb);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, bg_image_box);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, bg_image);
gtk_widget_class_bind_template_callback (widget_class, bg_image_file_set_cb);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, tile);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, stretch);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, fit);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, rotate);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, custom_fg_color);
gtk_widget_class_bind_template_callback (widget_class, custom_fg_color_toggled_cb);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, fg_color_box);
gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, fg_color);
}
static void
gp_properties_dialog_class_init (GpPropertiesDialogClass *dialog_class)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = G_OBJECT_CLASS (dialog_class);
widget_class = GTK_WIDGET_CLASS (dialog_class);
object_class->constructed = gp_properties_dialog_constructed;
object_class->dispose = gp_properties_dialog_dispose;
object_class->finalize = gp_properties_dialog_finalize;
object_class->set_property = gp_properties_dialog_set_property;
install_properties (object_class);
bind_template (widget_class);
}
static void
gp_properties_dialog_init (GpPropertiesDialog *dialog)
{
gtk_widget_init_template (GTK_WIDGET (dialog));
}
GtkWidget *
gp_properties_dialog_new (const gchar *toplevel_id)
{
return g_object_new (GP_TYPE_PROPERTIES_DIALOG,
"toplevel-id", toplevel_id,
NULL);
}
/*
* Copyright (C) 2016 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GP_PROPERTIES_DIALOG_H
#define GP_PROPERTIES_DIALOG_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GP_TYPE_PROPERTIES_DIALOG gp_properties_dialog_get_type ()
G_DECLARE_FINAL_TYPE (GpPropertiesDialog, gp_properties_dialog,
GP, PROPERTIES_DIALOG, GtkWindow)
GtkWidget *gp_properties_dialog_new (const gchar *toplevel_id);
G_END_DECLS
#endif
......@@ -39,7 +39,7 @@
#include "panel-util.h"
#include "panel.h"
#include "menu.h"
#include "panel-properties-dialog.h"
#include "gp-properties-dialog.h"
#include "panel-layout.h"
#include "panel-lockdown.h"
#include "panel-addto-dialog.h"
......@@ -110,6 +110,42 @@ panel_context_menu_setup_delete_panel_item (GtkWidget *menu,
gtk_widget_set_sensitive (menuitem, sensitive);
}
static void
dialog_destroy_cb (GtkWidget *dialog,
PanelToplevel *toplevel)
{
panel_toplevel_pop_autohide_disabler (toplevel);
g_object_set_data (G_OBJECT (toplevel), "gp-properties-dialog", NULL);
}
static void
present_properties_dialog (GtkWidget *widget,
PanelToplevel *toplevel)
{
GtkWidget *dialog;
dialog = g_object_get_data (G_OBJECT (toplevel), "gp-properties-dialog");
if (dialog == NULL)
{
const gchar *toplevel_id;
toplevel_id = panel_toplevel_get_id (toplevel);
dialog = gp_properties_dialog_new (toplevel_id);
g_signal_connect (dialog, "destroy",
G_CALLBACK (dialog_destroy_cb),
toplevel);
g_object_set_data_full (G_OBJECT (toplevel), "gp-properties-dialog",
dialog, (GDestroyNotify) gtk_widget_destroy);
panel_toplevel_push_autohide_disabler (toplevel);
}
gtk_window_present (GTK_WINDOW (dialog));
}
static void
panel_context_menu_build_edition (PanelWidget *panel_widget,
GtkWidget *menu)
......@@ -128,9 +164,9 @@ panel_context_menu_build_edition (PanelWidget *panel_widget,
menuitem = gtk_menu_item_new_with_mnemonic (_("_Properties"));
gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_signal_connect_swapped (menuitem, "activate",
G_CALLBACK (panel_properties_dialog_present),
panel_widget->toplevel);
g_signal_connect (menuitem, "activate",
G_CALLBACK (present_properties_dialog),
panel_widget->toplevel);
menuitem = gtk_menu_item_new_with_mnemonic (_("_Delete This Panel"));
gtk_widget_show (menuitem);
......
This diff is collapsed.