summaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/doc/AnacondaWidgets-docs.xml1
-rw-r--r--widgets/src/Makefile.am4
-rw-r--r--widgets/src/MountpointSelector.c237
-rw-r--r--widgets/src/MountpointSelector.h67
4 files changed, 308 insertions, 1 deletions
diff --git a/widgets/doc/AnacondaWidgets-docs.xml b/widgets/doc/AnacondaWidgets-docs.xml
index 031c8dec5..01838a188 100644
--- a/widgets/doc/AnacondaWidgets-docs.xml
+++ b/widgets/doc/AnacondaWidgets-docs.xml
@@ -32,6 +32,7 @@
<chapter id="disks">
<title>Disk-Related Widgets</title>
<xi:include href="xml/DiskOverview.xml" />
+ <xi:include href="xml/MountpointSelector.xml" />
</chapter>
<chapter id="miscellaneous">
diff --git a/widgets/src/Makefile.am b/widgets/src/Makefile.am
index 894516a01..cef38b56e 100644
--- a/widgets/src/Makefile.am
+++ b/widgets/src/Makefile.am
@@ -1,6 +1,6 @@
# Makefile.am for anaconda widgets
#
-# Copyright (C) 2011 Red Hat, Inc.
+# Copyright (C) 2011-2012 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
@@ -28,6 +28,7 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-introspection --enable-gtk-doc
GISOURCES = BaseWindow.c \
DiskOverview.c \
HubWindow.c \
+ MountpointSelector.c \
SpokeSelector.c \
SpokeWindow.c \
StandaloneWindow.c \
@@ -37,6 +38,7 @@ GISOURCES = BaseWindow.c \
GIHDRS = BaseWindow.h \
DiskOverview.h \
HubWindow.h \
+ MountpointSelector.h \
SpokeSelector.h \
SpokeWindow.h \
StandaloneWindow.h \
diff --git a/widgets/src/MountpointSelector.c b/widgets/src/MountpointSelector.c
new file mode 100644
index 000000000..ea8bfc7ab
--- /dev/null
+++ b/widgets/src/MountpointSelector.c
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2012 Red Hat, 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/>.
+ *
+ * Author: Chris Lumens <clumens@redhat.com>
+ */
+
+#include <gdk/gdk.h>
+
+#include "MountpointSelector.h"
+#include "intl.h"
+
+/**
+ * SECTION: MountpointSelector
+ * @title: AnacondaMountpointSelector
+ * @short_description: A graphical way to select a mount point.
+ *
+ * A #AnacondaMountpointSelector is a widget that appears on the custom partitioning
+ * Mountpoint and allows the user to select a single mount point to do additional
+ * configuration.
+ *
+ * As a #AnacondaMountpointSelector is a subclass of a #GtkEventBox, any signals
+ * may be caught. However ::button-press-event is the most important one and is
+ * how we determine what should be displayed on the rest of the screen.
+ */
+
+enum {
+ PROP_NAME = 1,
+ PROP_SIZE,
+ PROP_MOUNTPOINT
+};
+
+#define DEFAULT_NAME "Root"
+#define DEFAULT_SIZE "0 GB"
+#define DEFAULT_MOUNTPOINT "/"
+
+struct _AnacondaMountpointSelectorPrivate {
+ GtkWidget *grid;
+ GtkWidget *name_label, *size_label, *mountpoint_label;
+ GtkWidget *arrow;
+};
+
+G_DEFINE_TYPE(AnacondaMountpointSelector, anaconda_mountpoint_selector, GTK_TYPE_EVENT_BOX)
+
+static void anaconda_mountpoint_selector_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+static void anaconda_mountpoint_selector_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+
+static gboolean anaconda_mountpoint_selector_focus_changed(GtkWidget *widget, GdkEventFocus *event, gpointer user_data);
+
+static void anaconda_mountpoint_selector_class_init(AnacondaMountpointSelectorClass *klass) {
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->set_property = anaconda_mountpoint_selector_set_property;
+ object_class->get_property = anaconda_mountpoint_selector_get_property;
+
+ /**
+ * AnacondaMountpointSelector:name:
+ *
+ * The :name string is the primary text displayed for a given mountpoint.
+ *
+ * Since: 1.0
+ */
+ g_object_class_install_property(object_class,
+ PROP_NAME,
+ g_param_spec_string("name",
+ P_("name"),
+ P_("Name display"),
+ DEFAULT_NAME,
+ G_PARAM_READWRITE));
+
+ /**
+ * AnacondaMountpointSelector:size:
+ *
+ * The :size string is the size of the mountpoint, including whatever units
+ * it is measured in.
+ *
+ * Since: 1.0
+ */
+ g_object_class_install_property(object_class,
+ PROP_SIZE,
+ g_param_spec_string("size",
+ P_("size"),
+ P_("Size display"),
+ DEFAULT_SIZE,
+ G_PARAM_READWRITE));
+
+ /**
+ * AnacondaMountpointSelector:mountpoint:
+ *
+ * The :mountpoint string is where on the filesystem this is mounted.
+ *
+ * Since: 1.0
+ */
+ g_object_class_install_property(object_class,
+ PROP_MOUNTPOINT,
+ g_param_spec_string("mountpoint",
+ P_("mountpoint"),
+ P_("Mount point display"),
+ DEFAULT_MOUNTPOINT,
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private(object_class, sizeof(AnacondaMountpointSelectorPrivate));
+}
+
+/**
+ * anaconda_mountpoint_selector_new:
+ *
+ * Creates a new #AnacondaMountpointSelector, which is a selectable display for a
+ * single mountpoint. Many mountpoints may be pot together into a list, displaying
+ * all configured filesystems at once.
+ *
+ * Returns: A new #AnacondaMountpointSelector.
+ */
+GtkWidget *anaconda_mountpoint_selector_new() {
+ return g_object_new(ANACONDA_TYPE_MOUNTPOINT_SELECTOR, NULL);
+}
+
+static void anaconda_mountpoint_selector_init(AnacondaMountpointSelector *mountpoint) {
+ char *markup;
+
+ mountpoint->priv = G_TYPE_INSTANCE_GET_PRIVATE(mountpoint,
+ ANACONDA_TYPE_MOUNTPOINT_SELECTOR,
+ AnacondaMountpointSelectorPrivate);
+
+ /* Allow tabbing from one MountpointSelector to the next, and make sure it's
+ * selectable with the keyboard.
+ */
+ gtk_widget_set_can_focus(GTK_WIDGET(mountpoint), TRUE);
+ gtk_widget_add_events(GTK_WIDGET(mountpoint), GDK_FOCUS_CHANGE_MASK|GDK_KEY_RELEASE_MASK);
+ g_signal_connect(mountpoint, "focus-in-event", G_CALLBACK(anaconda_mountpoint_selector_focus_changed), NULL);
+ g_signal_connect(mountpoint, "focus-out-event", G_CALLBACK(anaconda_mountpoint_selector_focus_changed), NULL);
+
+ /* Create the grid. */
+ mountpoint->priv->grid = gtk_grid_new();
+ gtk_grid_set_column_spacing(GTK_GRID(mountpoint->priv->grid), 12);
+ gtk_widget_set_margin_left(GTK_WIDGET(mountpoint->priv->grid), 30);
+
+ /* Create the icons. */
+ mountpoint->priv->arrow = NULL;
+
+ /* Create the name label. */
+ mountpoint->priv->name_label = gtk_label_new(NULL);
+ markup = g_markup_printf_escaped("<span fgcolor='black' size='large' weight='bold'>%s</span>", _(DEFAULT_NAME));
+ gtk_label_set_markup(GTK_LABEL(mountpoint->priv->name_label), markup);
+ gtk_misc_set_alignment(GTK_MISC(mountpoint->priv->name_label), 0, 0);
+ g_free(markup);
+
+ /* Create the size label. */
+ mountpoint->priv->size_label = gtk_label_new(NULL);
+ markup = g_markup_printf_escaped("<span fgcolor='black' size='large' weight='bold'>%s</span>", _(DEFAULT_SIZE));
+ gtk_label_set_markup(GTK_LABEL(mountpoint->priv->size_label), markup);
+ gtk_misc_set_alignment(GTK_MISC(mountpoint->priv->size_label), 0, 0);
+ g_free(markup);
+
+ /* Create the mountpoint label. */
+ mountpoint->priv->mountpoint_label = gtk_label_new(NULL);
+ markup = g_markup_printf_escaped("<span fgcolor='grey' size='small'>%s</span>", _(DEFAULT_MOUNTPOINT));
+ gtk_label_set_markup(GTK_LABEL(mountpoint->priv->name_label), markup);
+ gtk_misc_set_alignment(GTK_MISC(mountpoint->priv->name_label), 0, 0);
+ g_free(markup);
+
+ /* Add everything to the grid, add the grid to the widget. */
+ gtk_grid_attach(GTK_GRID(mountpoint->priv->grid), mountpoint->priv->name_label, 0, 0, 1, 1);
+ gtk_grid_attach(GTK_GRID(mountpoint->priv->grid), mountpoint->priv->size_label, 1, 0, 1, 1);
+ gtk_grid_attach(GTK_GRID(mountpoint->priv->grid), mountpoint->priv->mountpoint_label, 0, 1, 1, 2);
+
+ gtk_container_add(GTK_CONTAINER(mountpoint), mountpoint->priv->grid);
+}
+
+static void anaconda_mountpoint_selector_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) {
+ AnacondaMountpointSelector *widget = ANACONDA_MOUNTPOINT_SELECTOR(object);
+ AnacondaMountpointSelectorPrivate *priv = widget->priv;
+
+ switch(prop_id) {
+ case PROP_NAME:
+ g_value_set_string (value, gtk_label_get_text(GTK_LABEL(priv->name_label)));
+ break;
+
+ case PROP_SIZE:
+ g_value_set_string (value, gtk_label_get_text(GTK_LABEL(priv->size_label)));
+ break;
+
+ case PROP_MOUNTPOINT:
+ g_value_set_string (value, gtk_label_get_text(GTK_LABEL(priv->mountpoint_label)));
+ break;
+ }
+}
+
+static void anaconda_mountpoint_selector_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) {
+ AnacondaMountpointSelector *widget = ANACONDA_MOUNTPOINT_SELECTOR(object);
+ AnacondaMountpointSelectorPrivate *priv = widget->priv;
+
+ switch(prop_id) {
+ case PROP_NAME: {
+ char *markup = g_markup_printf_escaped("<span fgcolor='black' size='large' weight='bold'>%s</span>", g_value_get_string(value));
+ gtk_label_set_markup(GTK_LABEL(priv->name_label), markup);
+ g_free(markup);
+ break;
+ }
+
+ case PROP_SIZE: {
+ char *markup = g_markup_printf_escaped("<span fgcolor='black' size='large' weight='bold'>%s</span>", g_value_get_string(value));
+ gtk_label_set_markup(GTK_LABEL(priv->size_label), markup);
+ g_free(markup);
+ break;
+ }
+
+ case PROP_MOUNTPOINT: {
+ char *markup = g_markup_printf_escaped("<span fgcolor='grey' size='small'>%s</span>", g_value_get_string(value));
+ gtk_label_set_markup(GTK_LABEL(priv->mountpoint_label), markup);
+ g_free(markup);
+ break;
+ }
+ }
+}
+
+static gboolean anaconda_mountpoint_selector_focus_changed(GtkWidget *widget, GdkEventFocus *event, gpointer user_data) {
+ GtkStateFlags new_state;
+
+ new_state = gtk_widget_get_state_flags(widget) & ~GTK_STATE_FOCUSED;
+ if (event->in)
+ new_state |= GTK_STATE_FOCUSED;
+ gtk_widget_set_state_flags(widget, new_state, TRUE);
+ return FALSE;
+}
diff --git a/widgets/src/MountpointSelector.h b/widgets/src/MountpointSelector.h
new file mode 100644
index 000000000..e9a5b9ae4
--- /dev/null
+++ b/widgets/src/MountpointSelector.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2012 Red Hat, 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/>.
+ *
+ * Author: Chris Lumens <clumens@redhat.com>
+ */
+
+#ifndef _MOUNTPOINT_SELECTOR_H
+#define _MOUNTPOINT_SELECTOR_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define ANACONDA_TYPE_MOUNTPOINT_SELECTOR (anaconda_mountpoint_selector_get_type())
+#define ANACONDA_MOUNTPOINT_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANACONDA_TYPE_MOUNTPOINT_SELECTOR, AnacondaMountpointSelector))
+#define ANACONDA_IS_MOUNTPOINT_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj)), ANACONDA_TYPE_MOUNTPOINT_SELECTOR)
+#define ANACONDA_MOUNTPOINT_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ANACONDA_TYPE_MOUNTPOINT_SELECTOR, AnacondaMountpointSelectorClass))
+#define ANACONDA_IS_MOUNTPOINT_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ANACONDA_TYPE_MOUNTPOINT_SELECTOR))
+#define ANACONDA_MOUNTPOINT_SELECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ANACONDA_TYPE_MOUNTPOINT_SELECTOR, AnacondaMountpointSelectorClass))
+
+typedef struct _AnacondaMountpointSelector AnacondaMountpointSelector;
+typedef struct _AnacondaMountpointSelectorClass AnacondaMountpointSelectorClass;
+typedef struct _AnacondaMountpointSelectorPrivate AnacondaMountpointSelectorPrivate;
+
+/**
+ * AnacondaMountpointSelector:
+ *
+ * The AnacondaMountpointSelector struct contains only private fields and should
+ * not be directly accessed.
+ */
+struct _AnacondaMountpointSelector {
+ GtkEventBox parent;
+
+ /*< private >*/
+ AnacondaMountpointSelectorPrivate *priv;
+};
+
+/**
+ * AnacondaMountpointSelectorClass:
+ * @parent_class: The object class structure needs to be the first element in
+ * the widget class structure in order for the class mechanism
+ * to work correctly. This allows an AnacondaMountpointSelectorClass
+ * pointer to be cast to a #GtkEventBox pointer.
+ */
+struct _AnacondaMountpointSelectorClass {
+ GtkEventBoxClass parent_class;
+};
+
+GType anaconda_mountpoint_selector_get_type (void);
+GtkWidget *anaconda_mountpoint_selector_new ();
+
+G_END_DECLS
+
+#endif