[gnome-disk-utility/udisks2-port] Start working on the details pages



commit 150f3953aa917b9cf5e252c4c6a07fe5d021f0e0
Author: David Zeuthen <davidz redhat com>
Date:   Tue Mar 8 17:45:00 2011 -0500

    Start working on the details pages
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/palimpsest.ui      |  329 ++++++++++++++++++++++++++++++++++++--------
 src/palimpsest/Makefile.am |    1 +
 src/palimpsest/gdu.h       |    1 +
 src/palimpsest/gduutils.c  |  162 ++++++++++++++++++++++
 src/palimpsest/gduutils.h  |   37 +++++
 src/palimpsest/gduwindow.c |  224 ++++++++++++++++++++++++++++++-
 6 files changed, 698 insertions(+), 56 deletions(-)
---
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
index a9687c6..bbbc8c7 100644
--- a/data/ui/palimpsest.ui
+++ b/data/ui/palimpsest.ui
@@ -17,9 +17,9 @@
             <property name="can_focus">False</property>
             <child>
               <object class="GtkScrolledWindow" id="device-tree-scrolledwindow">
+                <property name="width_request">300</property>
                 <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="device-tree-treeview">
@@ -78,7 +78,7 @@
             </child>
           </object>
           <packing>
-            <property name="expand">True</property>
+            <property name="expand">False</property>
             <property name="fill">True</property>
             <property name="position">0</property>
           </packing>
@@ -87,6 +87,7 @@
           <object class="GtkNotebook" id="palimpsest-notebook">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="hexpand">True</property>
             <child>
               <object class="GtkAlignment" id="alignment1">
                 <property name="visible">True</property>
@@ -118,9 +119,10 @@
                   <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="n_rows">6</property>
+                    <property name="n_columns">2</property>
                     <property name="column_spacing">10</property>
+                    <property name="homogeneous">True</property>
                     <child>
                       <object class="GtkLabel" id="lun-model-label">
                         <property name="visible">True</property>
@@ -137,18 +139,51 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="lun-serial-number-label">
+                      <object class="GtkLabel" id="lun-model-value-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</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>
+                      <object class="GtkLabel" id="lun-write-cache-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>
+                        <property name="label" translatable="yes">Write Cache</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">5</property>
+                        <property name="bottom_attach">6</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="top_attach">4</property>
+                        <property name="bottom_attach">5</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
@@ -164,66 +199,94 @@
                         </attributes>
                       </object>
                       <packing>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="lun-wwn-label">
+                      <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">World Wide Name</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="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="lun-model-value-label">
+                      <object class="GtkLabel" id="lun-wwn-value-label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
                         <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
+                        <property name="top_attach">4</property>
+                        <property name="bottom_attach">5</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="lun-serial-number-value-label">
+                      <object class="GtkLabel" id="lun-firmware-version-value-label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
                         <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</property>
                       </object>
                       <packing>
-                        <property name="left_attach">3</property>
-                        <property name="right_attach">4</property>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_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">
+                      <object class="GtkLabel" id="lun-serial-number-value-label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
                         <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="lun-size-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Size</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>
@@ -231,14 +294,17 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="lun-wwn-value-label">
+                      <object class="GtkLabel" id="lun-size-value-label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
                         <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</property>
                       </object>
                       <packing>
-                        <property name="left_attach">3</property>
-                        <property name="right_attach">4</property>
+                        <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>
@@ -248,18 +314,9 @@
                     <child>
                       <placeholder/>
                     </child>
-                    <child>
-                      <placeholder/>
-                    </child>
-                    <child>
-                      <placeholder/>
-                    </child>
-                    <child>
-                      <placeholder/>
-                    </child>
                   </object>
                   <packing>
-                    <property name="expand">True</property>
+                    <property name="expand">False</property>
                     <property name="fill">True</property>
                     <property name="position">0</property>
                   </packing>
@@ -287,70 +344,114 @@
               </packing>
             </child>
             <child>
-              <object class="GtkVBox" id="vbox2">
+              <object class="GtkVBox" id="looptab_vbox">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <child>
                   <object class="GtkTable" id="loop-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="n_rows">4</property>
+                    <property name="n_columns">2</property>
                     <property name="column_spacing">10</property>
+                    <property name="homogeneous">True</property>
                     <child>
-                      <object class="GtkLabel" id="loop-backing-file-label">
+                      <object class="GtkLabel" id="loop-size-label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">1</property>
-                        <property name="label" translatable="yes">Backing File</property>
+                        <property name="label" translatable="yes">Size</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="loop-size-label">
+                      <object class="GtkLabel" id="loop-size-value-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</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="loop-file-label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">1</property>
-                        <property name="label" translatable="yes">Size</property>
+                        <property name="label" translatable="yes">File</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">2</property>
+                        <property name="bottom_attach">3</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="loop-backing-file-value-label">
+                      <object class="GtkLabel" id="loop-file-value-label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
                         <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="loop-size-value-label">
+                      <object class="GtkLabel" id="loop-device-label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Device</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="loop-device-value-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
                         <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</property>
                       </object>
                       <packing>
-                        <property name="left_attach">3</property>
-                        <property name="right_attach">4</property>
+                        <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>
@@ -361,17 +462,112 @@
                     <child>
                       <placeholder/>
                     </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>
+              <packing>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="looptab_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">loop</property>
+              </object>
+              <packing>
+                <property name="position">2</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkVBox" id="blocktab_vbox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <child>
+                  <object class="GtkTable" id="block-table">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="n_rows">3</property>
+                    <property name="n_columns">2</property>
+                    <property name="column_spacing">10</property>
+                    <property name="homogeneous">True</property>
                     <child>
-                      <placeholder/>
+                      <object class="GtkLabel" id="block-size-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Size</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>
-                      <placeholder/>
+                      <object class="GtkLabel" id="block-size-value-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</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>
-                      <placeholder/>
+                      <object class="GtkLabel" id="block-device-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Device</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>
-                      <placeholder/>
+                      <object class="GtkLabel" id="block-device-value-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="xalign">0</property>
+                        <property name="selectable">True</property>
+                        <property name="ellipsize">end</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/>
@@ -386,6 +582,29 @@
                     <property name="position">0</property>
                   </packing>
                 </child>
+              </object>
+              <packing>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="blocktab_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">block</property>
+              </object>
+              <packing>
+                <property name="position">3</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkVBox" id="newtab_vbox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <child>
+                  <placeholder/>
+                </child>
                 <child>
                   <placeholder/>
                 </child>
@@ -394,17 +613,17 @@
                 </child>
               </object>
               <packing>
-                <property name="position">2</property>
+                <property name="position">4</property>
               </packing>
             </child>
             <child type="tab">
-              <object class="GtkLabel" id="label2">
+              <object class="GtkLabel" id="newtab_label">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label" translatable="yes">loop</property>
+                <property name="label" translatable="yes">new</property>
               </object>
               <packing>
-                <property name="position">2</property>
+                <property name="position">3</property>
                 <property name="tab_fill">False</property>
               </packing>
             </child>
diff --git a/src/palimpsest/Makefile.am b/src/palimpsest/Makefile.am
index 86ab3fd..0c5bc3d 100644
--- a/src/palimpsest/Makefile.am
+++ b/src/palimpsest/Makefile.am
@@ -9,6 +9,7 @@ palimpsest_SOURCES = 					\
 	gduapplication.h	gduapplication.c	\
 	gdudevicetreemodel.h	gdudevicetreemodel.c	\
 	gdutypes.h					\
+	gduutils.h		gduutils.c		\
 	gduwindow.h		gduwindow.c		\
 	$(NULL)
 
diff --git a/src/palimpsest/gdu.h b/src/palimpsest/gdu.h
index 715d735..a5fbcba 100644
--- a/src/palimpsest/gdu.h
+++ b/src/palimpsest/gdu.h
@@ -26,6 +26,7 @@
 #include <gdutypes.h>
 #include <gduapplication.h>
 #include <gdudevicetreemodel.h>
+#include <gduutils.h>
 #include <gduwindow.h>
 
 #endif /* __GDU_H__ */
diff --git a/src/palimpsest/gduutils.c b/src/palimpsest/gduutils.c
new file mode 100644
index 0000000..a4e39d7
--- /dev/null
+++ b/src/palimpsest/gduutils.c
@@ -0,0 +1,162 @@
+/* -*- 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 "gduutils.h"
+
+#define KILOBYTE_FACTOR 1000.0
+#define MEGABYTE_FACTOR (1000.0 * 1000.0)
+#define GIGABYTE_FACTOR (1000.0 * 1000.0 * 1000.0)
+#define TERABYTE_FACTOR (1000.0 * 1000.0 * 1000.0 * 1000.0)
+
+#define KIBIBYTE_FACTOR 1024.0
+#define MEBIBYTE_FACTOR (1024.0 * 1024.0)
+#define GIBIBYTE_FACTOR (1024.0 * 1024.0 * 1024.0)
+#define TEBIBYTE_FACTOR (1024.0 * 1024.0 * 1024.0 * 10242.0)
+
+static char *
+get_pow2_size (guint64 size)
+{
+  gchar *str;
+  gdouble displayed_size;
+  const gchar *unit;
+  guint digits;
+
+  if (size < MEBIBYTE_FACTOR)
+    {
+      displayed_size = (double) size / KIBIBYTE_FACTOR;
+      unit = "KiB";
+    }
+  else if (size < GIBIBYTE_FACTOR)
+    {
+      displayed_size = (double) size / MEBIBYTE_FACTOR;
+      unit = "MiB";
+    }
+  else if (size < TEBIBYTE_FACTOR)
+    {
+      displayed_size = (double) size / GIBIBYTE_FACTOR;
+      unit = "GiB";
+    }
+  else
+    {
+      displayed_size = (double) size / TEBIBYTE_FACTOR;
+      unit = "TiB";
+    }
+
+  if (displayed_size < 10.0)
+    digits = 1;
+  else
+    digits = 0;
+
+  str = g_strdup_printf ("%.*f %s", digits, displayed_size, unit);
+
+  return str;
+}
+
+static char *
+get_pow10_size (guint64 size)
+{
+  gchar *str;
+  gdouble displayed_size;
+  const gchar *unit;
+  guint digits;
+
+  if (size < MEGABYTE_FACTOR)
+    {
+      displayed_size = (double) size / KILOBYTE_FACTOR;
+      unit = "KB";
+    }
+  else if (size < GIGABYTE_FACTOR)
+    {
+      displayed_size = (double) size / MEGABYTE_FACTOR;
+      unit = "MB";
+    }
+  else if (size < TERABYTE_FACTOR)
+    {
+      displayed_size = (double) size / GIGABYTE_FACTOR;
+      unit = "GB";
+    }
+  else
+    {
+      displayed_size = (double) size / TERABYTE_FACTOR;
+      unit = "TB";
+    }
+
+  if (displayed_size < 10.0)
+    digits = 1;
+  else
+    digits = 0;
+
+  str = g_strdup_printf ("%.*f %s", digits, displayed_size, unit);
+
+  return str;
+}
+
+gchar *
+gdu_util_get_size_for_display (guint64 size,
+                               gboolean use_pow2,
+                               gboolean long_string)
+{
+  gchar *str;
+
+  if (long_string)
+    {
+      gchar *size_str;
+      size_str = g_strdup_printf ("%'" G_GINT64_FORMAT, size);
+      if (use_pow2)
+        {
+          gchar *pow2_str;
+          pow2_str = get_pow2_size (size);
+          /* Translators: The first %s is the size in power-of-2 units, e.g. '64 KiB'
+           * the second %s is the size as a number e.g. '65,536 bytes'
+           */
+          str = g_strdup_printf (_("%s (%s bytes)"), pow2_str, size_str);
+          g_free (pow2_str);
+        }
+      else
+        {
+          gchar *pow10_str;
+          pow10_str = get_pow10_size (size);
+          /* Translators: The first %s is the size in power-of-10 units, e.g. '100 KB'
+           * the second %s is the size as a number e.g. '100,000 bytes'
+           */
+          str = g_strdup_printf (_("%s (%s bytes)"), pow10_str, size_str);
+          g_free (pow10_str);
+        }
+
+      g_free (size_str);
+    }
+  else
+    {
+      if (use_pow2)
+        {
+          str = get_pow2_size (size);
+        }
+      else
+        {
+          str = get_pow10_size (size);
+        }
+    }
+  return str;
+}
diff --git a/src/palimpsest/gduutils.h b/src/palimpsest/gduutils.h
new file mode 100644
index 0000000..c7ec490
--- /dev/null
+++ b/src/palimpsest/gduutils.h
@@ -0,0 +1,37 @@
+/* -*- 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_UTILS_H__
+#define __GDU_UTILS_H__
+
+#include <gtk/gtk.h>
+#include "gdutypes.h"
+
+G_BEGIN_DECLS
+
+gchar *gdu_util_get_size_for_display (guint64  size,
+                                      gboolean use_pow2,
+                                      gboolean long_string);
+
+G_END_DECLS
+
+#endif /* __GDU_UTILS_H__ */
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index b4c2436..39e3b08 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -26,6 +26,16 @@
 #include "gduapplication.h"
 #include "gduwindow.h"
 #include "gdudevicetreemodel.h"
+#include "gduutils.h"
+
+/* Keep in sync with tabs in palimpsest.ui file */
+typedef enum
+{
+  DETAILS_PAGE_NOT_SELECTED,
+  DETAILS_PAGE_LUN,
+  DETAILS_PAGE_LOOP,
+  DETAILS_PAGE_BLOCK
+} DetailsPage;
 
 struct _GduWindow
 {
@@ -36,6 +46,11 @@ struct _GduWindow
 
   GtkBuilder *builder;
   GduDeviceTreeModel *model;
+
+  DetailsPage current_page;
+  GDBusObjectProxy *current_object_proxy;
+
+  GtkWidget *lun_write_cache_switch;
 };
 
 typedef struct
@@ -62,6 +77,9 @@ gdu_window_finalize (GObject *object)
 {
   GduWindow *window = GDU_WINDOW (object);
 
+  if (window->current_object_proxy != NULL)
+    g_object_unref (window->current_object_proxy);
+
   g_object_unref (window->builder);
   g_object_unref (window->model);
   g_object_unref (window->client);
@@ -102,6 +120,65 @@ on_row_inserted (GtkTreeModel *tree_model,
   gtk_tree_view_expand_all (GTK_TREE_VIEW (gdu_window_get_widget (window, "device-tree-treeview")));
 }
 
+static void select_details_page (GduWindow         *window,
+                                 GDBusObjectProxy  *object_proxy,
+                                 DetailsPage        page);
+
+static void
+set_selected_object_proxy (GduWindow        *window,
+                           GDBusObjectProxy *object_proxy)
+{
+  if (object_proxy != NULL)
+    {
+      UDisksBlockDevice *block;
+
+      if (UDISKS_PEEK_LUN (object_proxy) != NULL)
+        {
+          select_details_page (window, object_proxy, DETAILS_PAGE_LUN);
+        }
+      else if ((block = UDISKS_PEEK_BLOCK_DEVICE (object_proxy)) != NULL)
+        {
+          if (strlen (udisks_block_device_get_loop_backing_file (block)) > 0)
+            select_details_page (window, object_proxy, DETAILS_PAGE_LOOP);
+          else
+            select_details_page (window, object_proxy, DETAILS_PAGE_BLOCK);
+        }
+      else
+        {
+          g_assert_not_reached ();
+        }
+    }
+  else
+    {
+      select_details_page (window, NULL, DETAILS_PAGE_NOT_SELECTED);
+    }
+}
+
+static void
+on_tree_selection_changed (GtkTreeSelection *tree_selection,
+                           gpointer          user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+
+  if (gtk_tree_selection_get_selected (tree_selection, &model, &iter))
+    {
+      GDBusObjectProxy *object_proxy;
+      gtk_tree_model_get (model,
+                          &iter,
+                          GDU_DEVICE_TREE_MODEL_COLUMN_OBJECT_PROXY,
+                          &object_proxy,
+                          -1);
+      set_selected_object_proxy (window, object_proxy);
+      g_object_unref (object_proxy);
+    }
+  else
+    {
+      set_selected_object_proxy (window, NULL);
+    }
+}
+
 gboolean _gdu_application_get_running_from_source_tree (GduApplication *app);
 
 static void
@@ -116,6 +193,7 @@ gdu_window_constructed (GObject *object)
   GtkTreeSelection *selection;
   const gchar *path;
   GtkWidget *w;
+  GtkWidget *align;
   GtkStyleContext *context;
 
   /* chain up */
@@ -138,7 +216,7 @@ gdu_window_constructed (GObject *object)
   w = gdu_window_get_widget (window, "palimpsest-hbox");
   gtk_widget_reparent (w, GTK_WIDGET (window));
   gtk_window_set_title (GTK_WINDOW (window), _("Disk Utility"));
-  gtk_window_set_default_size (GTK_WINDOW (window), 400, 500);
+  gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
   gtk_container_set_border_width (GTK_CONTAINER (window), 12);
 
   notebook = GTK_NOTEBOOK (gdu_window_get_widget (window, "palimpsest-notebook"));
@@ -160,6 +238,10 @@ gdu_window_constructed (GObject *object)
 
   selection = gtk_tree_view_get_selection (tree_view);
   gtk_tree_selection_set_select_function (selection, dont_select_headings, NULL, NULL);
+  g_signal_connect (selection,
+                    "changed",
+                    G_CALLBACK (on_tree_selection_changed),
+                    window);
 
   column = gtk_tree_view_column_new ();
   gtk_tree_view_append_column (tree_view, column);
@@ -194,6 +276,17 @@ gdu_window_constructed (GObject *object)
                     G_CALLBACK (on_row_inserted),
                     window);
   gtk_tree_view_expand_all (tree_view);
+
+  /* insert widgets not yet supported by the glade app */
+  window->lun_write_cache_switch = gtk_switch_new ();
+  align = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
+  gtk_container_add (GTK_CONTAINER (align), window->lun_write_cache_switch);
+  gtk_table_attach (GTK_TABLE (gdu_window_get_widget (window, "lun-table")),
+                    align,
+                    1, 2,
+                    5, 6,
+                    GTK_FILL, 0,
+                    0, 0);
 }
 
 static void
@@ -320,3 +413,132 @@ gdu_window_get_widget (GduWindow    *window,
   g_return_val_if_fail (name != NULL, NULL);
   return GTK_WIDGET (gtk_builder_get_object (window->builder, name));
 }
+
+static void
+teardown_details_page (GduWindow         *window,
+                       GDBusObjectProxy *object_proxy,
+                       gint              page)
+{
+  //g_debug ("teardown for %s, page %d",
+  //       object_proxy != NULL ? g_dbus_object_proxy_get_object_path (object_proxy) : "<none>",
+  //         page);
+  switch (page)
+    {
+    case DETAILS_PAGE_NOT_SELECTED:
+      break;
+    case DETAILS_PAGE_LUN:
+      break;
+    case DETAILS_PAGE_LOOP:
+      break;
+    case DETAILS_PAGE_BLOCK:
+      break;
+    }
+}
+
+static void
+set_string (GduWindow   *window,
+            const gchar *label_id,
+            const gchar *text)
+{
+  if (text == NULL || strlen (text) == 0)
+    text = "â??";
+
+  /* TODO: utf-8 validate */
+  gtk_label_set_text (GTK_LABEL (gdu_window_get_widget (window, label_id)), text);
+}
+
+static void
+set_size (GduWindow   *window,
+          const gchar *label_id,
+          guint64      size)
+{
+  gchar *s;
+  s = gdu_util_get_size_for_display (size, FALSE, TRUE);
+  set_string (window, label_id, s);
+  g_free (s);
+}
+
+static void
+setup_details_page (GduWindow         *window,
+                    GDBusObjectProxy *object_proxy,
+                    gint              page)
+{
+  //g_debug ("setup for %s, page %d",
+  //         object_proxy != NULL ? g_dbus_object_proxy_get_object_path (object_proxy) : "<none>",
+  //         page);
+  switch (page)
+    {
+    case DETAILS_PAGE_NOT_SELECTED:
+      break;
+    case DETAILS_PAGE_LUN:
+      {
+        UDisksLun *lun;
+        const gchar *lun_vendor;
+        const gchar *lun_model;
+        gchar *s;
+
+        lun = UDISKS_PEEK_LUN (object_proxy);
+        lun_vendor = udisks_lun_get_vendor (lun);
+        lun_model = udisks_lun_get_model (lun);
+        if (strlen (lun_vendor) == 0)
+          s = g_strdup (lun_model);
+        else if (strlen (lun_model) == 0)
+          s = g_strdup (lun_vendor);
+        else
+          s = g_strconcat (lun_vendor, " ", lun_model, NULL);
+        gtk_label_set_text (GTK_LABEL (gdu_window_get_widget (window, "lun-model-value-label")), s);
+        g_free (s);
+
+        set_string (window, "lun-serial-number-value-label", udisks_lun_get_serial (lun));
+        set_string (window, "lun-firmware-version-value-label", udisks_lun_get_revision (lun));
+        set_string (window, "lun-wwn-value-label", udisks_lun_get_wwn (lun));
+        set_size (window, "lun-size-value-label", udisks_lun_get_size (lun));
+        /* TODO: get this from udisks */
+        gtk_switch_set_active (GTK_SWITCH (window->lun_write_cache_switch), TRUE);
+      }
+      break;
+    case DETAILS_PAGE_LOOP:
+      {
+        UDisksBlockDevice *block;
+        block = UDISKS_PEEK_BLOCK_DEVICE (object_proxy);
+        set_string (window, "loop-device-value-label", udisks_block_device_get_preferred_device (block));
+        set_string (window, "loop-file-value-label", udisks_block_device_get_loop_backing_file (block));
+        set_size (window, "loop-size-value-label", udisks_block_device_get_size (block));
+      }
+      break;
+
+    case DETAILS_PAGE_BLOCK:
+      {
+        UDisksBlockDevice *block;
+        block = UDISKS_PEEK_BLOCK_DEVICE (object_proxy);
+        set_string (window, "block-device-value-label", udisks_block_device_get_preferred_device (block));
+        set_size (window, "block-size-value-label", udisks_block_device_get_size (block));
+      }
+      break;
+    }
+}
+
+static void
+select_details_page (GduWindow         *window,
+                     GDBusObjectProxy  *object_proxy,
+                     DetailsPage        page)
+{
+  GtkNotebook *notebook;
+
+  notebook = GTK_NOTEBOOK (gdu_window_get_widget (window, "palimpsest-notebook"));
+
+  teardown_details_page (window,
+                         window->current_object_proxy,
+                         window->current_page);
+
+  window->current_page = page;
+  if (window->current_object_proxy != NULL)
+    g_object_unref (window->current_object_proxy);
+  window->current_object_proxy = object_proxy != NULL ? g_object_ref (object_proxy) : NULL;
+
+  setup_details_page (window,
+                      window->current_object_proxy,
+                      window->current_page);
+
+  gtk_notebook_set_current_page (notebook, page);
+}



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