[gnome-disk-utility] If drive is on another seat, show "Connected to another seat"



commit ca77722ea1a6484091f2b2c05e589e131c4dbe41
Author: David Zeuthen <davidz redhat com>
Date:   Sat Apr 21 15:11:40 2012 -0400

    If drive is on another seat, show "Connected to another seat"
    
    http://people.freedesktop.org/~david/disks-location-connected-to-another-seat.png
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 configure.ac               |   23 +++++++++++++++++++++
 data/ui/palimpsest.ui      |   47 ++++++++++++++++++++++++++++++++++++++++---
 src/palimpsest/Makefile.am |    2 +
 src/palimpsest/gduutils.c  |   36 +++++++++++++++++++++++++++++++++
 src/palimpsest/gduutils.h  |    2 +
 src/palimpsest/gduwindow.c |   45 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 151 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b982cc4..da614fb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,6 +35,27 @@ PKG_CHECK_MODULES(GLIB2, [gio-unix-2.0 >= $GLIB2_REQUIRED])
 PKG_CHECK_MODULES(UDISKS2, [udisks2 >= $UDISKS2_REQUIRED])
 PKG_CHECK_MODULES(GTK3, [gtk+-3.0 >= $GTK3_REQUIRED])
 
+dnl **********************************
+dnl *** Check for libsystemd-login ***
+dnl **********************************
+
+AC_ARG_ENABLE(libsystemd_login, AS_HELP_STRING([--disable-libsystemd-login],[build without liblibsystemd-login]))
+msg_libsystemd_login=no
+LIBSYSTEMD_LOGIN_LIBS=
+LIBSYSTEMD_LOGIN_CFLAGS=
+LIBSYSTEMD_LOGIN_REQUIRED=44
+
+if test "x$enable_libsystemd_login" != "xno"; then
+  PKG_CHECK_EXISTS([libsystemd-login >= $LIBSYSTEMD_LOGIN_REQUIRED], msg_libsystemd_login=yes)
+
+  if test "x$msg_libsystemd_login" = "xyes"; then
+    PKG_CHECK_MODULES([LIBSYSTEMD_LOGIN],[libsystemd-login >= $LIBSYSTEMD_LOGIN_REQUIRED])
+    AC_DEFINE(HAVE_LIBSYSTEMD_LOGIN, 1, [Define to 1 if liblibsystemd_login is available])
+  fi
+fi
+
+AM_CONDITIONAL(USE_LIBSYSTEMD_LOGIN, [test "$msg_libsystemd_login" = "yes"])
+
 # ********************
 # Internationalization
 # ********************
@@ -83,6 +104,8 @@ echo "
         sysconfdir:                 ${sysconfdir}
         localstatedir:              ${localstatedir}
 
+        Use libsystem-login:        ${msg_libsystemd_login}
+
         compiler:                   ${CC}
         cflags:                     ${CFLAGS}
         cppflags:                   ${CPPFLAGS}
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
index c4e03cf..100b28b 100644
--- a/data/ui/palimpsest.ui
+++ b/data/ui/palimpsest.ui
@@ -471,6 +471,45 @@
                         <property name="y_padding">4</property>
                       </packing>
                     </child>
+
+                    <child>
+                      <object class="GtkLabel" id="devtab-location-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes" comments="The physical location of the drive, could be 'Connected to another seat'  or 'Bay 11 of Promise VTrak' or 'USB connector II'">Location</property>
+                        <style>
+                          <class name="dim-label"/>
+                        </style>
+                      </object>
+                      <packing>
+                        <property name="top_attach">6</property>
+                        <property name="bottom_attach">7</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                        <property name="y_padding">4</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="devtab-location-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">6</property>
+                        <property name="bottom_attach">7</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                        <property name="y_padding">4</property>
+                      </packing>
+                    </child>
+
                     <child>
                       <object class="GtkLabel" id="devtab-media-label">
                         <property name="visible">True</property>
@@ -571,8 +610,8 @@
                         </style>
                       </object>
                       <packing>
-                        <property name="top_attach">6</property>
-                        <property name="bottom_attach">7</property>
+                        <property name="top_attach">7</property>
+                        <property name="bottom_attach">8</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                         <property name="y_padding">4</property>
@@ -590,8 +629,8 @@
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">6</property>
-                        <property name="bottom_attach">7</property>
+                        <property name="top_attach">7</property>
+                        <property name="bottom_attach">8</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                         <property name="y_padding">4</property>
diff --git a/src/palimpsest/Makefile.am b/src/palimpsest/Makefile.am
index 6cfeaca..69f73d5 100644
--- a/src/palimpsest/Makefile.am
+++ b/src/palimpsest/Makefile.am
@@ -62,6 +62,7 @@ palimpsest_CFLAGS = 					\
 	$(GLIB2_CFLAGS)					\
 	$(UDISKS2_CFLAGS)				\
 	$(GTK3_CFLAGS)					\
+	$(LIBSYSTEMD_LOGIN_CFLAGS)			\
 	$(WARN_CFLAGS)					\
 	-lm						\
 	$(NULL)
@@ -70,6 +71,7 @@ palimpsest_LDADD = 					\
 	$(GLIB2_LIBS)					\
 	$(UDISKS2_LIBS)					\
 	$(GTK3_LIBS)					\
+	$(LIBSYSTEMD_LOGIN_LIBS)			\
 	$(NULL)
 
 EXTRA_DIST = 						\
diff --git a/src/palimpsest/gduutils.c b/src/palimpsest/gduutils.c
index a1139c3..67e6712 100644
--- a/src/palimpsest/gduutils.c
+++ b/src/palimpsest/gduutils.c
@@ -25,6 +25,10 @@
 
 #include "gduutils.h"
 
+#if defined(HAVE_LIBSYSTEMD_LOGIN)
+#include <systemd/sd-login.h>
+#endif
+
 gboolean
 gdu_utils_has_configuration (UDisksBlock  *block,
                              const gchar  *type,
@@ -374,3 +378,35 @@ gdu_options_update_entry_option (GtkWidget       *options_entry,
   g_free (ui_escaped);
   g_free (opts);
 }
+
+#if defined(HAVE_LIBSYSTEMD_LOGIN)
+#include <systemd/sd-login.h>
+
+const gchar *
+gdu_utils_get_seat (void)
+{
+  static gsize once = 0;
+  static char *seat = NULL;
+
+  if (g_once_init_enter (&once))
+    {
+      char *session = NULL;
+      if (sd_pid_get_session (getpid (), &session) == 0)
+        {
+          sd_session_get_seat (session, &seat);
+          /* we intentionally leak seat here... */
+        }
+      g_once_init_leave (&once, (gsize) 1);
+    }
+  return seat;
+}
+
+#else
+
+const gchar *
+gdu_utils_get_seat (void)
+{
+  return NULL;
+}
+
+#endif
diff --git a/src/palimpsest/gduutils.h b/src/palimpsest/gduutils.h
index 659a82e..65560ce 100644
--- a/src/palimpsest/gduutils.h
+++ b/src/palimpsest/gduutils.h
@@ -55,6 +55,8 @@ void gdu_options_update_entry_option (GtkWidget       *options_entry,
                                       GtkWidget       *widget,
                                       GtkWidget       *entry);
 
+const gchar *gdu_utils_get_seat (void);
+
 G_END_DECLS
 
 #endif /* __GDU_UTILS_H__ */
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index 607e9d6..744a0f7 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -1542,6 +1542,7 @@ update_device_page_for_drive (GduWindow      *window,
   GIcon *media_icon;
   guint64 size;
   UDisksDriveAta *ata;
+  const gchar *our_seat;
 
   //g_debug ("In update_device_page_for_drive() - selected=%s",
   //         object != NULL ? g_dbus_object_get_object_path (object) : "<nothing>");
@@ -1618,6 +1619,50 @@ update_device_page_for_drive (GduWindow      *window,
               "devtab-wwn-value-label",
               udisks_drive_get_wwn (drive), SET_MARKUP_FLAGS_NONE);
 
+  /* Figure out Location ...
+   *
+   * TODO: should also show things like "USB port 3" (if connected
+   * to the main chassis) or "Bay 11 of Promise VTRAK 630" (if in a
+   * disk enclosure)...
+   */
+  s = NULL;
+  /* First see if connected to another seat than ours */
+  our_seat = gdu_utils_get_seat ();
+  if (our_seat != NULL)
+    {
+      const gchar *drive_seat = NULL;
+      /* Assume seat0 if a) device is not tagged; or b) udisks does not
+       * have seat-support.
+       *
+       * Note that seat support was added in udisks 1.95.0 (and so was the
+       * UDISKS_CHECK_VERSION macro) - for now, be compatible with older
+       * versions instead of bumping requirement in configure.ac
+       */
+#ifdef UDISKS_CHECK_VERSION
+# if UDISKS_CHECK_VERSION(1,95,0)
+      drive_seat = udisks_drive_get_seat (drive);
+# endif
+#endif
+      if (drive_seat == NULL || strlen (drive_seat) == 0)
+        drive_seat = "seat0";
+      if (g_strcmp0 (our_seat, drive_seat) != 0)
+        {
+          /* Translators: Shown in "Location" when drive is connected to another seat than where
+           * our application is running.
+           */
+          s = g_strdup (_("Connected to another seat"));
+        }
+    }
+  if (s != NULL)
+    {
+      set_markup (window,
+                  "devtab-location-label",
+                  "devtab-location-value-label",
+                  s, SET_MARKUP_FLAGS_NONE);
+      g_free (s);
+    }
+
+
   if (ata != NULL && !udisks_drive_get_media_removable (drive))
     {
       gboolean smart_is_supported;



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