[sound-juicer] Add SjAlbumChooserDialog
- From: Phillip Wood <pwood src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sound-juicer] Add SjAlbumChooserDialog
- Date: Tue, 16 Aug 2016 10:29:51 +0000 (UTC)
commit ba1b0c5ccd2b85ebfa460df40c58a42c0fc47c11
Author: Phillip Wood <phillip wood dunelm org uk>
Date: Tue Aug 9 14:06:12 2016 +0100
Add SjAlbumChooserDialog
A template widget replacement for the current multiple album dialog
implementation with the following improvements:
• Respect GtkSettings:gtk-dialogs-use-header.
• Use the new GtkScrolledWindow:max-content-height/width properties to
set an appropriate window size for the number of rows being displayed.†
• Use GtkListBox rather than GtkTreeView.
This commit adds the new code for the dialog - it does not populate the
rows yet, the next commit with copy and paste the code for that from
sj-main.c.
This commit raises the required Gtk version to 3.21.3.
† For this to work a new dialog instance must be created for each new
album list.
configure.ac | 2 +-
data/sj-album-chooser-dialog.ui | 64 +++++++++++++
data/sound-juicer.gresource.xml | 1 +
po/POTFILES.in | 1 +
src/Makefile.am | 2 +
src/sj-album-chooser-dialog.c | 197 +++++++++++++++++++++++++++++++++++++++
src/sj-album-chooser-dialog.h | 46 +++++++++
7 files changed, 312 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 730a1e4..22f69a1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,7 @@ AC_PROG_MKDIR_P
GNOME_COMPILE_WARNINGS([maximum])
-GTK_REQUIRED=3.19.6
+GTK_REQUIRED=3.21.3
GLIB_GSETTINGS
# Find glib-compile-resources
diff --git a/data/sj-album-chooser-dialog.ui b/data/sj-album-chooser-dialog.ui
new file mode 100644
index 0000000..9b224c7
--- /dev/null
+++ b/data/sj-album-chooser-dialog.ui
@@ -0,0 +1,64 @@
+<interface>
+ <template class="SjAlbumChooserDialog" parent="GtkDialog">
+ <property name="deletable">False</property>
+ <property name="destroy-with-parent">True</property>
+ <property name="modal">True</property>
+ <property name="title" translatable="yes">Select Album</property>
+ <property name="type-hint">dialog</property>
+ <child type="action">
+ <object class="GtkButton" id="select_button">
+ <property name="can-default">True</property>
+ <property name="label" translatable="yes">_Select</property>
+ <property name="use-underline">True</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="accept" default="true">select_button</action-widget>
+ </action-widgets>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="vbox">
+ <property name="border_width">6</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">This CD could be more than one album. Please select
which album it is.</property>
+ <property name="margin-end">12</property>
+ <property name="margin-start">12</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow">
+ <property name="expand">True</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <property name="max-content-height">600</property>
+ <property name="max-content-width">800</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkListBox" id="list_box">
+ <property name="activate-on-single-click">False</property>
+ <property name="expand">True</property>
+ <property name="selection-mode">browse</property>
+ <property name="visible">True</property>
+ <signal name="row-activated" handler="row_activated_cb"/>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/data/sound-juicer.gresource.xml b/data/sound-juicer.gresource.xml
index b48dfbc..5b12cbc 100644
--- a/data/sound-juicer.gresource.xml
+++ b/data/sound-juicer.gresource.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/sound-juicer">
+ <file preprocess="xml-stripblanks">sj-album-chooser-dialog.ui</file>
<file preprocess="xml-stripblanks">sound-juicer.ui</file>
<file alias="gtk/menus.ui" preprocess="xml-stripblanks">sound-juicer-menu.ui</file>
<file alias="gtk/help-overlay.ui" preprocess="xml-stripblanks">sound-juicer-shortcuts.ui</file>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 521bacd..a4ce941 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@
data/org.gnome.sound-juicer.gschema.xml
data/sound-juicer.desktop.in.in
data/appdata/sound-juicer.appdata.xml.in
+data/sj-album-chooser-dialog.ui
data/sound-juicer.ui
data/sound-juicer-menu.ui
data/sound-juicer-shortcuts.ui
diff --git a/src/Makefile.am b/src/Makefile.am
index 1ca13bb..374f350 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,8 @@
bin_PROGRAMS += sound-juicer
sound_juicer_SOURCES += \
+ src/sj-album-chooser-dialog.c \
+ src/sj-album-chooser-dialog.h \
src/egg-play-preview.c \
src/egg-play-preview.h \
src/sj-about.c \
diff --git a/src/sj-album-chooser-dialog.c b/src/sj-album-chooser-dialog.c
new file mode 100644
index 0000000..1efd203
--- /dev/null
+++ b/src/sj-album-chooser-dialog.c
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2016 Phillip Wood <phillip wood dunelm org uk>
+ *
+ * Sound Juicer - sj-album-chooser-dialog.c
+ *
+ * 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/>.
+ *
+ * Authors: Phillip Wood <phillip wood dunelm org uk>
+ */
+
+#include "sj-album-chooser-dialog.h"
+
+struct _SjAlbumChooserDialogClass {
+ GtkDialogClass parent_class;
+};
+
+struct _SjAlbumChooserDialog {
+ GtkDialog parent;
+ GtkListBox *list_box;
+ GList *albums;
+};
+
+G_DEFINE_TYPE (SjAlbumChooserDialog, sj_album_chooser_dialog, GTK_TYPE_DIALOG)
+
+enum {
+ PROP_ALBUMS = 1,
+ LAST_PROP
+};
+
+static GParamSpec *properties[LAST_PROP];
+
+static const gchar* album_quark_text = "sj-album-chooser-dialog-album";
+static GQuark album_quark;
+
+static GtkListBoxRow*
+create_row (AlbumDetails *album)
+{
+ return NULL;
+}
+
+static void
+add_album (gpointer album,
+ gpointer list_box)
+{
+ GtkListBoxRow *row;
+
+ row = create_row (album);
+ gtk_list_box_insert (list_box, GTK_WIDGET (row), -1);
+}
+
+static void
+set_albums (SjAlbumChooserDialog *dialog,
+ GList *albums)
+{
+ GtkListBoxRow *row;
+
+ dialog->albums = albums;
+ if (dialog->albums != NULL) {
+ g_list_foreach (albums, add_album, dialog->list_box);
+ row = gtk_list_box_get_row_at_index (dialog->list_box, 0);
+ gtk_list_box_select_row (dialog->list_box, row);
+ }
+}
+
+static void
+row_activated_cb (GtkListBox *list_box,
+ GtkListBoxRow *row,
+ gpointer dialog)
+{
+ gtk_dialog_response (dialog, GTK_RESPONSE_ACCEPT);
+}
+
+static void
+sj_album_chooser_dialog_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ SjAlbumChooserDialog *dialog;
+
+ dialog = SJ_ALBUM_CHOOSER_DIALOG (object);
+
+ switch (property_id) {
+ case PROP_ALBUMS:
+ g_value_set_pointer (value, dialog->albums);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+sj_album_chooser_dialog_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ SjAlbumChooserDialog *dialog;
+
+ dialog = SJ_ALBUM_CHOOSER_DIALOG (object);
+
+ switch (property_id) {
+ case PROP_ALBUMS:
+ set_albums (dialog, g_value_get_pointer (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+sj_album_chooser_dialog_class_init (SjAlbumChooserDialogClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->get_property = sj_album_chooser_dialog_get_property;
+ object_class->set_property = sj_album_chooser_dialog_set_property;
+
+ properties[PROP_ALBUMS] =
+ g_param_spec_pointer ("albums", "albums", "albums",
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_properties (object_class, LAST_PROP, properties);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/sound-juicer/sj-album-chooser-dialog.ui");
+ gtk_widget_class_bind_template_child (widget_class,
+ SjAlbumChooserDialog,
+ list_box);
+ gtk_widget_class_bind_template_callback (widget_class, row_activated_cb);
+
+ album_quark = g_quark_from_static_string (album_quark_text);
+}
+
+static void
+sj_album_chooser_dialog_init (SjAlbumChooserDialog *dialog)
+{
+ gtk_widget_init_template (GTK_WIDGET (dialog));
+}
+
+/**
+ * sj_album_chooser_dialog_new:
+ * @dialog: The parent window.
+ * @albums: (element-type AlbumDetails): The list of albums to show.
+ *
+ * Create a new dialog showing @albums.
+ *
+ * Returns: The new dialog.
+ */
+GtkWidget*
+sj_album_chooser_dialog_new (GtkWindow *parent_window,
+ GList *albums)
+{
+ GtkSettings *settings;
+ gboolean use_header_bar;
+
+ settings = gtk_settings_get_default ();
+ g_object_get (settings, "gtk-dialogs-use-header", &use_header_bar, NULL);
+ return GTK_WIDGET (g_object_new (SJ_TYPE_ALBUM_CHOOSER_DIALOG,
+ "albums", albums,
+ "transient-for", parent_window,
+ "use-header-bar", use_header_bar,
+ NULL));
+}
+
+/**
+ * sj_album_chooser_dialog_get_selected_album:
+ * @dialog: The dialog to query.
+ *
+ * Get the currently selected album.
+ *
+ * Returns: The selected album
+ */
+AlbumDetails*
+sj_album_chooser_dialog_get_selected_album (SjAlbumChooserDialog *dialog)
+{
+ GtkListBoxRow *row;
+
+ g_return_val_if_fail (SJ_IS_ALBUM_CHOOSER_DIALOG (dialog), NULL);
+
+ if (dialog->albums == NULL)
+ return NULL;
+
+ row = gtk_list_box_get_selected_row (dialog->list_box);
+ return g_object_get_qdata ((GObject*) row, album_quark);
+}
diff --git a/src/sj-album-chooser-dialog.h b/src/sj-album-chooser-dialog.h
new file mode 100644
index 0000000..e50befc
--- /dev/null
+++ b/src/sj-album-chooser-dialog.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2016 Phillip Wood <phillip wood dunelm org uk>
+ *
+ * Sound Juicer - sj-album-chooser-dialog.h
+ *
+ * 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/>.
+ *
+ * Authors: Phillip Wood <phillip wood dunelm org uk>
+ */
+
+#ifndef SJ_ALBUM_CHOOSER_DIALOG_H
+#define SJ_ALBUM_CHOOSER_DIALOG_H
+
+#include <gtk/gtk.h>
+#include "sj-structures.h"
+
+G_BEGIN_DECLS
+
+#define SJ_TYPE_ALBUM_CHOOSER_DIALOG (sj_album_chooser_dialog_get_type ())
+#define SJ_ALBUM_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SJ_TYPE_ALBUM_CHOOSER_DIALOG,
SjAlbumChooserDialog))
+#define SJ_ALBUM_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
SJ_TYPE_ALBUM_CHOOSER_DIALOG, SjAlbumChooserDialogClass))
+#define SJ_IS_ALBUM_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SJ_TYPE_ALBUM_CHOOSER_DIALOG))
+#define SJ_IS_ALBUM_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
SJ_TYPE_ALBUM_CHOOSER_DIALOG))
+#define SJ_ALBUM_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
SJ_TYPE_ALBUM_CHOOSER_DIALOG, SjAlbumChooserDialogClass))
+
+typedef struct _SjAlbumChooserDialog SjAlbumChooserDialog;
+typedef struct _SjAlbumChooserDialogClass SjAlbumChooserDialogClass;
+
+GType sj_album_chooser_dialog_get_type (void) G_GNUC_CONST;
+GtkWidget* sj_album_chooser_dialog_new (GtkWindow *parent, GList *albums);
+AlbumDetails* sj_album_chooser_dialog_get_selected_album (SjAlbumChooserDialog *dialog);
+
+G_END_DECLS
+
+#endif /* SJ_ALBUM_CHOOSER_DIALOG_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]