Commit c7273c06 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

sidebar: show the property views in expandable sections

parent 793feee8
...@@ -107,6 +107,9 @@ ...@@ -107,6 +107,9 @@
<key name="sidebar-visible" type="b"> <key name="sidebar-visible" type="b">
<default>true</default> <default>true</default>
</key> </key>
<key name="sidebar-sections" type="as">
<default>[]</default>
</key>
<key name="properties-visible" type="b"> <key name="properties-visible" type="b">
<default>false</default> <default>false</default>
</key> </key>
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#define MIN_HISTOGRAM_HEIGHT 280 #define MIN_HISTOGRAM_HEIGHT 280
static void gth_image_histogram_gth_multipage_child_interface_init (GthMultipageChildInterface *iface);
static void gth_image_histogram_gth_property_view_interface_init (GthPropertyViewInterface *iface); static void gth_image_histogram_gth_property_view_interface_init (GthPropertyViewInterface *iface);
...@@ -45,13 +44,11 @@ G_DEFINE_TYPE_WITH_CODE (GthImageHistogram, ...@@ -45,13 +44,11 @@ G_DEFINE_TYPE_WITH_CODE (GthImageHistogram,
gth_image_histogram, gth_image_histogram,
GTK_TYPE_BOX, GTK_TYPE_BOX,
G_ADD_PRIVATE (GthImageHistogram) G_ADD_PRIVATE (GthImageHistogram)
G_IMPLEMENT_INTERFACE (GTH_TYPE_MULTIPAGE_CHILD,
gth_image_histogram_gth_multipage_child_interface_init)
G_IMPLEMENT_INTERFACE (GTH_TYPE_PROPERTY_VIEW, G_IMPLEMENT_INTERFACE (GTH_TYPE_PROPERTY_VIEW,
gth_image_histogram_gth_property_view_interface_init)) gth_image_histogram_gth_property_view_interface_init))
static void static gboolean
gth_image_histogram_real_set_file (GthPropertyView *base, gth_image_histogram_real_set_file (GthPropertyView *base,
GthFileData *file_data) GthFileData *file_data)
{ {
...@@ -61,34 +58,32 @@ gth_image_histogram_real_set_file (GthPropertyView *base, ...@@ -61,34 +58,32 @@ gth_image_histogram_real_set_file (GthPropertyView *base,
if (file_data == NULL) { if (file_data == NULL) {
gth_histogram_calculate_for_image (self->priv->histogram, NULL); gth_histogram_calculate_for_image (self->priv->histogram, NULL);
return; return FALSE;
} }
browser = (GthBrowser *) gtk_widget_get_toplevel (GTK_WIDGET (base)); browser = (GthBrowser *) gtk_widget_get_toplevel (GTK_WIDGET (base));
if (! gtk_widget_is_toplevel (GTK_WIDGET (browser))) { if (! gtk_widget_is_toplevel (GTK_WIDGET (browser)))
gth_histogram_calculate_for_image (self->priv->histogram, NULL); return FALSE;
return;
}
viewer_page = gth_browser_get_viewer_page (browser); viewer_page = gth_browser_get_viewer_page (browser);
if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) { if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
gth_histogram_calculate_for_image (self->priv->histogram, NULL); return FALSE;
return;
}
gth_histogram_calculate_for_image (self->priv->histogram, gth_image_viewer_page_get_current_image (GTH_IMAGE_VIEWER_PAGE (viewer_page))); gth_histogram_calculate_for_image (self->priv->histogram, gth_image_viewer_page_get_current_image (GTH_IMAGE_VIEWER_PAGE (viewer_page)));
return TRUE;
} }
static const char * static const char *
gth_image_histogram_real_get_name (GthMultipageChild *self) gth_image_histogram_real_get_name (GthPropertyView *self)
{ {
return _("Histogram"); return _("Histogram");
} }
static const char * static const char *
gth_image_histogram_real_get_icon (GthMultipageChild *self) gth_image_histogram_real_get_icon (GthPropertyView *self)
{ {
return "histogram-symbolic"; return "histogram-symbolic";
} }
...@@ -112,16 +107,10 @@ gth_image_histogram_class_init (GthImageHistogramClass *klass) ...@@ -112,16 +107,10 @@ gth_image_histogram_class_init (GthImageHistogramClass *klass)
static void static void
gth_image_histogram_gth_multipage_child_interface_init (GthMultipageChildInterface *iface) gth_image_histogram_gth_property_view_interface_init (GthPropertyViewInterface *iface)
{ {
iface->get_name = gth_image_histogram_real_get_name; iface->get_name = gth_image_histogram_real_get_name;
iface->get_icon = gth_image_histogram_real_get_icon; iface->get_icon = gth_image_histogram_real_get_icon;
}
static void
gth_image_histogram_gth_property_view_interface_init (GthPropertyViewInterface *iface)
{
iface->set_file = gth_image_histogram_real_set_file; iface->set_file = gth_image_histogram_real_set_file;
} }
...@@ -150,7 +139,6 @@ gth_image_histogram_init (GthImageHistogram *self) ...@@ -150,7 +139,6 @@ gth_image_histogram_init (GthImageHistogram *self)
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL); gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
gtk_box_set_spacing (GTK_BOX (self), 6); gtk_box_set_spacing (GTK_BOX (self), 6);
gtk_container_set_border_width (GTK_CONTAINER (self), 2);
settings = g_settings_new (GTHUMB_IMAGE_VIEWER_SCHEMA); settings = g_settings_new (GTHUMB_IMAGE_VIEWER_SCHEMA);
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#define LABEL_MAX_WIDTH 200 #define LABEL_MAX_WIDTH 200
static void gth_map_view_gth_multipage_child_interface_init (GthMultipageChildInterface *iface);
static void gth_map_view_gth_property_view_interface_init (GthPropertyViewInterface *iface); static void gth_map_view_gth_property_view_interface_init (GthPropertyViewInterface *iface);
...@@ -48,8 +47,6 @@ G_DEFINE_TYPE_WITH_CODE (GthMapView, ...@@ -48,8 +47,6 @@ G_DEFINE_TYPE_WITH_CODE (GthMapView,
gth_map_view, gth_map_view,
GTK_TYPE_BOX, GTK_TYPE_BOX,
G_ADD_PRIVATE (GthMapView) G_ADD_PRIVATE (GthMapView)
G_IMPLEMENT_INTERFACE (GTH_TYPE_MULTIPAGE_CHILD,
gth_map_view_gth_multipage_child_interface_init)
G_IMPLEMENT_INTERFACE (GTH_TYPE_PROPERTY_VIEW, G_IMPLEMENT_INTERFACE (GTH_TYPE_PROPERTY_VIEW,
gth_map_view_gth_property_view_interface_init)) gth_map_view_gth_property_view_interface_init))
...@@ -139,7 +136,7 @@ decimal_coordinates_to_string (double latitude, ...@@ -139,7 +136,7 @@ decimal_coordinates_to_string (double latitude,
} }
static void static gboolean
gth_map_view_real_set_file (GthPropertyView *base, gth_map_view_real_set_file (GthPropertyView *base,
GthFileData *file_data) GthFileData *file_data)
{ {
...@@ -197,18 +194,20 @@ gth_map_view_real_set_file (GthPropertyView *base, ...@@ -197,18 +194,20 @@ gth_map_view_real_set_file (GthPropertyView *base,
gtk_widget_hide (self->priv->embed); gtk_widget_hide (self->priv->embed);
gtk_widget_show (self->priv->no_gps_label); gtk_widget_show (self->priv->no_gps_label);
} }
return (coordinates_available == 2);
} }
static const char * static const char *
gth_map_view_real_get_name (GthMultipageChild *self) gth_map_view_real_get_name (GthPropertyView *self)
{ {
return _("Map"); return _("Map");
} }
static const char * static const char *
gth_map_view_real_get_icon (GthMultipageChild *self) gth_map_view_real_get_icon (GthPropertyView *self)
{ {
return "map-symbolic"; return "map-symbolic";
} }
...@@ -320,15 +319,9 @@ gth_map_view_init (GthMapView *self) ...@@ -320,15 +319,9 @@ gth_map_view_init (GthMapView *self)
static void static void
gth_map_view_gth_multipage_child_interface_init (GthMultipageChildInterface *iface) gth_map_view_gth_property_view_interface_init (GthPropertyViewInterface *iface)
{ {
iface->get_name = gth_map_view_real_get_name; iface->get_name = gth_map_view_real_get_name;
iface->get_icon = gth_map_view_real_get_icon; iface->get_icon = gth_map_view_real_get_icon;
}
static void
gth_map_view_gth_property_view_interface_init (GthPropertyViewInterface *iface)
{
iface->set_file = gth_map_view_real_set_file; iface->set_file = gth_map_view_real_set_file;
} }
...@@ -1986,8 +1986,9 @@ _gth_browser_close_final_step (gpointer user_data) ...@@ -1986,8 +1986,9 @@ _gth_browser_close_final_step (gpointer user_data)
last_window = g_list_length (gtk_application_get_windows (gtk_window_get_application (GTK_WINDOW (browser)))) == 1; last_window = g_list_length (gtk_application_get_windows (gtk_window_get_application (GTK_WINDOW (browser)))) == 1;
if (gtk_widget_get_realized (GTK_WIDGET (browser))) { if (gtk_widget_get_realized (GTK_WIDGET (browser))) {
gboolean maximized; gboolean maximized;
GtkAllocation allocation; GtkAllocation allocation;
char **sidebar_sections;
/* Save visualization options only if the window is not maximized. */ /* Save visualization options only if the window is not maximized. */
...@@ -2022,6 +2023,10 @@ _gth_browser_close_final_step (gpointer user_data) ...@@ -2022,6 +2023,10 @@ _gth_browser_close_final_step (gpointer user_data)
g_settings_set_enum (browser->priv->browser_settings, PREF_FULLSCREEN_SIDEBAR, browser->priv->fullscreen_state.sidebar); g_settings_set_enum (browser->priv->browser_settings, PREF_FULLSCREEN_SIDEBAR, browser->priv->fullscreen_state.sidebar);
g_settings_set_boolean (browser->priv->browser_settings, PREF_FULLSCREEN_THUMBNAILS_VISIBLE, browser->priv->fullscreen_state.thumbnail_list); g_settings_set_boolean (browser->priv->browser_settings, PREF_FULLSCREEN_THUMBNAILS_VISIBLE, browser->priv->fullscreen_state.thumbnail_list);
sidebar_sections = gth_sidebar_get_sections_status (GTH_SIDEBAR (browser->priv->file_properties));
g_settings_set_strv (browser->priv->browser_settings, PREF_BROWSER_SIDEBAR_SECTIONS, (const char **) sidebar_sections);
g_strfreev (sidebar_sections);
} }
/**/ /**/
...@@ -4255,6 +4260,7 @@ gth_browser_init (GthBrowser *browser) ...@@ -4255,6 +4260,7 @@ gth_browser_init (GthBrowser *browser)
{ {
int window_width; int window_width;
int window_height; int window_height;
char **sidebar_sections;
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *scrolled_window; GtkWidget *scrolled_window;
char *general_filter; char *general_filter;
...@@ -4797,13 +4803,15 @@ gth_browser_init (GthBrowser *browser) ...@@ -4797,13 +4803,15 @@ gth_browser_init (GthBrowser *browser)
/* the file property box */ /* the file property box */
browser->priv->file_properties = gth_sidebar_new (); sidebar_sections = g_settings_get_strv (browser->priv->browser_settings, PREF_BROWSER_SIDEBAR_SECTIONS);
browser->priv->file_properties = gth_sidebar_new (sidebar_sections);
gtk_widget_set_size_request (browser->priv->file_properties, -1, FILE_PROPERTIES_MINIMUM_HEIGHT); gtk_widget_set_size_request (browser->priv->file_properties, -1, FILE_PROPERTIES_MINIMUM_HEIGHT);
gtk_widget_hide (browser->priv->file_properties); gtk_widget_hide (browser->priv->file_properties);
gtk_paned_pack2 (GTK_PANED (_gth_browser_get_browser_file_properties_container (browser)), gtk_paned_pack2 (GTK_PANED (_gth_browser_get_browser_file_properties_container (browser)),
browser->priv->file_properties, browser->priv->file_properties,
! browser->priv->file_properties_on_the_right, ! browser->priv->file_properties_on_the_right,
FALSE); FALSE);
g_strfreev (sidebar_sections);
g_signal_connect (gth_sidebar_get_toolbox (GTH_SIDEBAR (browser->priv->file_properties)), g_signal_connect (gth_sidebar_get_toolbox (GTH_SIDEBAR (browser->priv->file_properties)),
"options-visibility", "options-visibility",
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* GThumb
*
* Copyright (C) 2019 Free Software Foundation, Inc.
*
* 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 "glib-utils.h"
#include "gth-file-comment.h"
#include "gth-main.h"
#include "gth-sidebar.h"
#define GTH_STYLE_CLASS_COMMENT "comment"
struct _GthFileCommentPrivate {
GtkWidget *comment_view;
GtkWidget *comment_win;
GthFileData *last_file_data;
};
static void gth_file_comment_gth_property_view_interface_init (GthPropertyViewInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GthFileComment,
gth_file_comment,
GTK_TYPE_BOX,
G_ADD_PRIVATE (GthFileComment)
G_IMPLEMENT_INTERFACE (GTH_TYPE_PROPERTY_VIEW,
gth_file_comment_gth_property_view_interface_init))
static char *
get_comment (GthFileData *file_data)
{
GString *string;
GthMetadata *value;
gboolean not_void = FALSE;
string = g_string_new (NULL);
value = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::description");
if (value != NULL) {
const char *formatted;
formatted = gth_metadata_get_formatted (value);
if ((formatted != NULL) && (*formatted != '\0')) {
g_string_append (string, formatted);
not_void = TRUE;
}
}
return g_string_free (string, ! not_void);
}
static gboolean
gth_file_comment_real_set_file (GthPropertyView *base,
GthFileData *file_data)
{
GthFileComment *self;
GtkTextBuffer *text_buffer;
char *comment;
self = GTH_FILE_COMMENT (base);
if (file_data != self->priv->last_file_data) {
_g_object_unref (self->priv->last_file_data);
self->priv->last_file_data = gth_file_data_dup (file_data);
}
if (file_data == NULL) {
gtk_widget_hide (self->priv->comment_win);
return FALSE;
}
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->priv->comment_view));
comment = get_comment (file_data);
if (comment != NULL) {
GtkTextIter iter;
GtkAdjustment *vadj;
gtk_text_buffer_set_text (text_buffer, comment, strlen (comment));
gtk_text_buffer_get_iter_at_line (text_buffer, &iter, 0);
gtk_text_buffer_place_cursor (text_buffer, &iter);
vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->priv->comment_win));
gtk_adjustment_set_value (vadj, 0.0);
gtk_widget_show (self->priv->comment_win);
g_free (comment);
}
else
gtk_widget_hide (self->priv->comment_win);
return (comment != NULL);
}
static const char *
gth_file_comment_real_get_name (GthPropertyView *self)
{
return _("Comment");
}
static const char *
gth_file_comment_real_get_icon (GthPropertyView *self)
{
return "comment-symbolic";
}
static void
gth_file_comment_finalize (GObject *base)
{
GthFileComment *self;
self = (GthFileComment *) base;
_g_object_unref (self->priv->last_file_data);
G_OBJECT_CLASS (gth_file_comment_parent_class)->finalize (base);
}
static void
gth_file_comment_class_init (GthFileCommentClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gth_file_comment_finalize;
}
static void
gth_file_comment_init (GthFileComment *self)
{
self->priv = gth_file_comment_get_instance_private (self);
self->priv->last_file_data = NULL;
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
self->priv->comment_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (self->priv->comment_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (self->priv->comment_win), GTK_SHADOW_ETCHED_IN);
//gtk_widget_set_size_request (self->priv->comment_win, -1, COMMENT_DEFAULT_HEIGHT);
gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->comment_win), GTH_STYLE_CLASS_COMMENT);
gtk_box_pack_start (GTK_BOX (self), self->priv->comment_win, TRUE, TRUE, 0);
self->priv->comment_view = gtk_text_view_new ();
gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->comment_view), GTH_STYLE_CLASS_COMMENT);
gtk_text_view_set_editable (GTK_TEXT_VIEW (self->priv->comment_view), FALSE);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (self->priv->comment_view), GTK_WRAP_WORD);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (self->priv->comment_view), TRUE);
gtk_widget_show (self->priv->comment_view);
gtk_container_add (GTK_CONTAINER (self->priv->comment_win), self->priv->comment_view);
}
static void
gth_file_comment_gth_property_view_interface_init (GthPropertyViewInterface *iface)
{
iface->get_name = gth_file_comment_real_get_name;
iface->get_icon = gth_file_comment_real_get_icon;
iface->set_file = gth_file_comment_real_set_file;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* GThumb
*
* Copyright (C) 2019 Free Software Foundation, Inc.
*
* 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 GTH_FILE_COMMENT_H
#define GTH_FILE_COMMENT_H
#include <gtk/gtk.h>
#include "gth-file-data.h"
G_BEGIN_DECLS
#define GTH_TYPE_FILE_COMMENT (gth_file_comment_get_type ())
#define GTH_FILE_COMMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_FILE_COMMENT, GthFileComment))
#define GTH_FILE_COMMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_FILE_COMMENT, GthFileCommentClass))
#define GTH_IS_FILE_COMMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_FILE_COMMENT))
#define GTH_IS_FILE_COMMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_FILE_COMMENT))
#define GTH_FILE_COMMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTH_TYPE_FILE_COMMENT, GthFileCommentClass))
typedef struct _GthFileComment GthFileComment;
typedef struct _GthFileCommentClass GthFileCommentClass;
typedef struct _GthFileCommentPrivate GthFileCommentPrivate;
struct _GthFileComment {
GtkBox parent_instance;
GthFileCommentPrivate *priv;
};
struct _GthFileCommentClass {
GtkBoxClass parent_class;
};
GType gth_file_comment_get_type (void);
G_END_DECLS
#endif /* GTH_FILE_COMMENT_H */
...@@ -23,37 +23,37 @@ ...@@ -23,37 +23,37 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include "glib-utils.h" #include "glib-utils.h"
#include "gth-file-details.h" #include "gth-file-details.h"
#include "gth-multipage.h"
#include "gth-sidebar.h" #include "gth-sidebar.h"
static void gth_file_details_gth_multipage_child_interface_init (GthMultipageChildInterface *iface); static void gth_file_details_gth_property_view_interface_init (GthPropertyViewInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GthFileDetails, G_DEFINE_TYPE_WITH_CODE (GthFileDetails,
gth_file_details, gth_file_details,
GTH_TYPE_FILE_PROPERTIES, GTH_TYPE_FILE_PROPERTIES,
G_IMPLEMENT_INTERFACE (GTH_TYPE_MULTIPAGE_CHILD, G_IMPLEMENT_INTERFACE (GTH_TYPE_PROPERTY_VIEW,
gth_file_details_gth_multipage_child_interface_init)) gth_file_details_gth_property_view_interface_init))
static const char * static const char *
gth_file_details_real_get_name (GthMultipageChild *self) gth_file_details_real_get_name (GthPropertyView *self)
{ {
return _("Details"); return _("Metadata");
} }
static const char * static const char *
gth_file_details_real_get_icon (GthMultipageChild *self) gth_file_details_real_get_icon (GthPropertyView *self)
{ {
return "format-justify-fill-symbolic"; return "tag-symbolic";
} }
static void static void
gth_file_details_class_init (GthFileDetailsClass *klass) gth_file_details_class_init (GthFileDetailsClass *klass)
{ {
/*