[gnome-disk-utility/udisks2-port] Setup palimpsest to use GtkApplication



commit e6e5dc47ac2a8b030fad1efa92f1b7390ca548fe
Author: David Zeuthen <davidz redhat com>
Date:   Fri Mar 4 12:23:30 2011 -0500

    Setup palimpsest to use GtkApplication
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 configure.ac                    |    3 +
 data/Makefile.am                |    2 +-
 data/ui/Makefile.am             |   10 ++
 data/ui/palimpsest.ui           |  298 +++++++++++++++++++++++++++++++++++++++
 src/palimpsest/Makefile.am      |   10 +-
 src/palimpsest/gdu.h            |   29 ++++
 src/palimpsest/gduapplication.c |  110 ++++++++++++++
 src/palimpsest/gduapplication.h |   43 ++++++
 src/palimpsest/gdutypes.h       |   35 +++++
 src/palimpsest/main.c           |   14 ++-
 10 files changed, 547 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 576bfe1..c27a54d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,9 +29,11 @@ GNOME_MAINTAINER_MODE_DEFINES
 
 GLIB2_REQUIRED=2.22
 UDISKS2_REQUIRED=1.90
+GTK3_REQUIRED=3.0.0
 
 PKG_CHECK_MODULES(GLIB2, [gio-2.0 >= $GLIB2_REQUIRED])
 PKG_CHECK_MODULES(UDISKS2, [udisks2 >= $UDISKS2_REQUIRED])
+PKG_CHECK_MODULES(GTK3, [gtk+-3.0 >= $GTK3_REQUIRED])
 
 # ********************
 # Internationalization
@@ -61,6 +63,7 @@ data/icons/22x22/Makefile
 data/icons/24x24/Makefile
 data/icons/48x48/Makefile
 data/icons/scalable/Makefile
+data/ui/Makefile
 ])
 
 AC_OUTPUT
diff --git a/data/Makefile.am b/data/Makefile.am
index 1a13cc8..9a15d39 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,6 +1,6 @@
 NULL =
 
-SUBDIRS = icons
+SUBDIRS = ui icons
 
 desktopdir = $(datadir)/applications
 desktop_in_files = palimpsest.desktop.in
diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am
new file mode 100644
index 0000000..133df8b
--- /dev/null
+++ b/data/ui/Makefile.am
@@ -0,0 +1,10 @@
+
+NULL =
+
+uidir = $(datadir)/ui/user-accounts
+ui_DATA = 			\
+	palimpsest.ui		\
+	$(NULL)
+
+clean-local :
+	rm -f *~
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
new file mode 100644
index 0000000..9bff725
--- /dev/null
+++ b/data/ui/palimpsest.ui
@@ -0,0 +1,298 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkWindow" id="palimpsest-window">
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <property name="title" translatable="yes">Disk Utility</property>
+    <property name="default_width">400</property>
+    <property name="default_height">500</property>
+    <child>
+      <object class="GtkHBox" id="palimpsest-hbox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <child>
+          <object class="GtkVBox" id="lunlist-vbox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkScrolledWindow" id="lunlist-scrolledwindow">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">never</property>
+                <property name="shadow_type">in</property>
+                <child>
+                  <object class="GtkTreeView" id="lunlist-treeview">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="headers_visible">False</property>
+                    <child internal-child="selection">
+                      <object class="GtkTreeSelection" id="lunlist-treeview-selection"/>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolbar" id="lunlist-add-remove-toolbar">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_size">1</property>
+                <child>
+                  <object class="GtkToolButton" id="lunlist-add-toolbutton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="icon_name">list-add-symbolic</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="homogeneous">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkToolButton" id="lunlist-remove-toolbutton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="icon_name">list-remove-symbolic</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="homogeneous">True</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkNotebook" id="notebook1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <child>
+              <object class="GtkVBox" id="vbox1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <child>
+                  <object class="GtkTable" id="lun-table">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="n_rows">3</property>
+                    <property name="n_columns">4</property>
+                    <property name="column_spacing">10</property>
+                    <child>
+                      <object class="GtkLabel" id="lun-model-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Model</property>
+                        <attributes>
+                          <attribute name="foreground" value="#555555555555"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="lun-serial-number-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Serial Number</property>
+                        <attributes>
+                          <attribute name="foreground" value="#555555555555"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="left_attach">2</property>
+                        <property name="right_attach">3</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="lun-firmware-version-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Firmware Version</property>
+                        <attributes>
+                          <attribute name="foreground" value="#555555555555"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="lun-wwn-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">World Wide Name</property>
+                        <attributes>
+                          <attribute name="foreground" value="#555555555555"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="left_attach">2</property>
+                        <property name="right_attach">3</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="lun-model-value-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="lun-serial-number-value-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">3</property>
+                        <property name="right_attach">4</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="lun-firmware-version-value-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="lun-wwn-value-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">3</property>
+                        <property name="right_attach">4</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">lun</property>
+              </object>
+              <packing>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">page 2</property>
+              </object>
+              <packing>
+                <property name="position">1</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">page 3</property>
+              </object>
+              <packing>
+                <property name="position">2</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/palimpsest/Makefile.am b/src/palimpsest/Makefile.am
index 9f1382e..7daf342 100644
--- a/src/palimpsest/Makefile.am
+++ b/src/palimpsest/Makefile.am
@@ -3,8 +3,11 @@ NULL =
 
 bin_PROGRAMS = palimpsest
 
-palimpsest_SOURCES = 									\
-						main.c					\
+palimpsest_SOURCES = 					\
+				main.c			\
+	gdu.h						\
+	gduapplication.h	gduapplication.c	\
+	gdutypes.h					\
 	$(NULL)
 
 palimpsest_CPPFLAGS = 					\
@@ -17,11 +20,14 @@ palimpsest_CPPFLAGS = 					\
 palimpsest_CFLAGS = 					\
 	$(GLIB2_CFLAGS)					\
 	$(UDISKS2_CFLAGS)				\
+	$(GTK3_CFLAGS)					\
+	$(WARN_CFLAGS)					\
 	$(NULL)
 
 palimpsest_LDADD = 					\
 	$(GLIB2_LIBS)					\
 	$(UDISKS2_LIBS)					\
+	$(GTK3_LIBS)					\
 	$(NULL)
 
 clean-local :
diff --git a/src/palimpsest/gdu.h b/src/palimpsest/gdu.h
new file mode 100644
index 0000000..b61add8
--- /dev/null
+++ b/src/palimpsest/gdu.h
@@ -0,0 +1,29 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#ifndef __GDU_H__
+#define __GDU_H__
+
+#include <gdutypes.h>
+#include <gduapplication.h>
+
+#endif /* __GDU_H__ */
diff --git a/src/palimpsest/gduapplication.c b/src/palimpsest/gduapplication.c
new file mode 100644
index 0000000..209482c
--- /dev/null
+++ b/src/palimpsest/gduapplication.c
@@ -0,0 +1,110 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#include "config.h"
+#include <glib/gi18n.h>
+
+#include "gduapplication.h"
+
+struct _GduApplication
+{
+  GtkApplication parent_instance;
+  GtkBuilder *builder;
+  GtkWindow *window;
+};
+
+typedef struct
+{
+  GtkApplicationClass parent_class;
+} GduApplicationClass;
+
+G_DEFINE_TYPE (GduApplication, gdu_application, GTK_TYPE_APPLICATION);
+
+static void
+gdu_application_init (GduApplication *app)
+{
+  GError *error;
+
+  app->builder = gtk_builder_new ();
+
+  error = NULL;
+  if (gtk_builder_add_from_file (app->builder,
+                                 "../../data/ui/palimpsest.ui",
+                                 &error) == 0)
+    {
+      g_error ("Error loading palimpsest.ui: %s", error->message);
+      g_error_free (error);
+    }
+}
+
+static void
+gdu_application_finalize (GObject *object)
+{
+  GduApplication *app = GDU_APPLICATION (object);
+
+  g_object_unref (app->builder);
+
+  G_OBJECT_CLASS (gdu_application_parent_class)->finalize (object);
+}
+
+static void
+gdu_application_activate (GApplication *_app)
+{
+  GduApplication *app = GDU_APPLICATION (_app);
+
+  app->window = GTK_WINDOW (gtk_builder_get_object (app->builder, "palimpsest-window"));
+  gtk_window_set_application (app->window, GTK_APPLICATION (app));
+  gtk_widget_show_all (GTK_WIDGET (app->window));
+}
+
+static void
+gdu_application_class_init (GduApplicationClass *klass)
+{
+  GObjectClass *gobject_class;
+  GApplicationClass *application_class;
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = gdu_application_finalize;
+
+  application_class = G_APPLICATION_CLASS (klass);
+  application_class->activate = gdu_application_activate;
+}
+
+GApplication *
+gdu_application_new (void)
+{
+  gtk_init (NULL, NULL);
+  return G_APPLICATION (g_object_new (GDU_TYPE_APPLICATION,
+                                      "application-id", "org.gnome.DiskUtility",
+                                      "flags", G_APPLICATION_FLAGS_NONE,
+                                      NULL));
+}
+
+GtkWidget *
+gdu_application_get_widget (GduApplication *app,
+                            const gchar    *name)
+{
+  g_return_val_if_fail (GDU_IS_APPLICATION (app), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+  return GTK_WIDGET (gtk_builder_get_object (app->builder, name));
+}
+
diff --git a/src/palimpsest/gduapplication.h b/src/palimpsest/gduapplication.h
new file mode 100644
index 0000000..8bb8b68
--- /dev/null
+++ b/src/palimpsest/gduapplication.h
@@ -0,0 +1,43 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#ifndef __GDU_APPLICATION_H__
+#define __GDU_APPLICATION_H__
+
+#include <gtk/gtk.h>
+#include "gdutypes.h"
+
+G_BEGIN_DECLS
+
+#define GDU_TYPE_APPLICATION         (gdu_application_get_type ())
+#define GDU_APPLICATION(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GDU_TYPE_APPLICATION, GduApplication))
+#define GDU_IS_APPLICATION(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDU_TYPE_APPLICATION))
+
+GType         gdu_application_get_type   (void) G_GNUC_CONST;
+GApplication *gdu_application_new        (void);
+GtkWidget    *gdu_application_get_widget (GduApplication *app,
+                                            const gchar    *name);
+
+
+G_END_DECLS
+
+#endif /* __GDU_APPLICATION_H__ */
diff --git a/src/palimpsest/gdutypes.h b/src/palimpsest/gdutypes.h
new file mode 100644
index 0000000..0f10947
--- /dev/null
+++ b/src/palimpsest/gdutypes.h
@@ -0,0 +1,35 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#ifndef __GDU_TYPES_H__
+#define __GDU_TYPES_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+struct _GduApplication;
+typedef struct _GduApplication GduApplication;
+
+G_END_DECLS
+
+#endif /* __GDU_TYPES_H__ */
diff --git a/src/palimpsest/main.c b/src/palimpsest/main.c
index 090ed26..e5f3a72 100644
--- a/src/palimpsest/main.c
+++ b/src/palimpsest/main.c
@@ -1,5 +1,5 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
-/*
+ *
  * Copyright (C) 2008-2011 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -23,11 +23,17 @@
 #include "config.h"
 #include <glib/gi18n.h>
 
-#include <glib.h>
+#include "gdu.h"
 
 int
 main (int argc, char *argv[])
 {
-  g_print (_("Hello world!\n"));
-  return 0;
+  GApplication *app;
+  gint status;
+
+  app = gdu_application_new ();
+  status = g_application_run (G_APPLICATION (app), argc, argv);
+  g_object_unref (app);
+
+  return status;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]