[nautilus-ideviceinfo/gtk3: 3/5] Port code and ui to GTK3
- From: Martin Szulecki <mszulecki src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-ideviceinfo/gtk3: 3/5] Port code and ui to GTK3
- Date: Sun, 30 Nov 2014 16:47:19 +0000 (UTC)
commit 9ff505d9d6ba4acfb2bb93b4b5297d97f422b5c9
Author: Martin Szulecki <m szulecki mirell de>
Date: Sun Nov 30 17:45:30 2014 +0100
Port code and ui to GTK3
configure.ac | 14 +-
src/ideviceinfo-property-page.c | 32 +++-
src/ideviceinfo-property-page.h | 4 +-
src/nautilus-afc2-warning-bar.c | 14 +-
src/nautilus-afc2-warning-bar.h | 4 +-
src/nautilus-ideviceinfo.ui | 78 ++++++++-
src/rb-segmented-bar.c | 362 +++++++++++++++++++++++++++++++-------
7 files changed, 406 insertions(+), 102 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 78ca3b1..355a308 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,21 +14,21 @@ AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_LIBTOOL
-LIBIMOBILE_REQS=0.9.7
-GLIB2_REQS=2.14.1
-LIBPLIST_REQS=0.15
-GTK2_REQS=2.16
+LIBIMOBILE_REQS=1.1.7
+GLIB2_REQS=2.38.0
+LIBPLIST_REQS=1.12
+GTK3_REQS=3.10.0
NAUTILUS_REQS=2.21.2
-LIBGPOD_REQS=0.7.90
+LIBGPOD_REQS=0.8.2
LIBXML_REQS=2.6.30
# Checks for libraries.
PKG_CHECK_MODULES(WIDGET, libimobiledevice-1.0 >= $LIBIMOBILE_REQS
glib-2.0 >= $GLIB2_REQS
libplist >= $LIBPLIST_REQS
- gtk+-2.0 >= $GTK2_REQS)
+ gtk+-3.0 >= $GTK3_REQS)
PKG_CHECK_MODULES(libnautilusextension, libnautilus-extension >= $NAUTILUS_REQS)
-PKG_CHECK_MODULES(libgpod, libgpod-1.0 >= $LIBGPOD_REQS, enable_libgpod=yes, enable_libgpod=no)
+PKG_CHECK_MODULES(libgpod, libgpod-1.0 >= $LIBGPOD_REQS, enable_libgpod=no, enable_libgpod=no)
PKG_CHECK_MODULES(libxml, libxml-2.0 >= $LIBXML_REQS)
PKG_CHECK_MODULES(providerinfo, mobile-broadband-provider-info, enable_carrier_lookup=yes,
enable_carrier_lookup=no)
diff --git a/src/ideviceinfo-property-page.c b/src/ideviceinfo-property-page.c
index d50d195..a9e6c09 100644
--- a/src/ideviceinfo-property-page.c
+++ b/src/ideviceinfo-property-page.c
@@ -31,6 +31,7 @@
#include <libnautilus-extension/nautilus-property-page-provider.h>
#include <libimobiledevice/libimobiledevice.h>
+#include <libimobiledevice/afc.h>
#include <libimobiledevice/lockdown.h>
#include <libimobiledevice/installation_proxy.h>
@@ -55,6 +56,9 @@
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
+#ifndef MOBILE_BROADBAND_PROVIDER_INFO
+#define MOBILE_BROADBAND_PROVIDER_INFO DATADIR"/mobile-broadband-provider-info/serviceproviders.xml"
+#endif
#endif
#include "rb-segmented-bar.h"
@@ -83,14 +87,14 @@ typedef struct {
gboolean has_afc2; /* Whether AFC2 is available */
} CompletedMessage;
-G_DEFINE_TYPE(NautilusIdeviceinfoPage, nautilus_ideviceinfo_page, GTK_TYPE_VBOX)
+G_DEFINE_TYPE(NautilusIdeviceinfoPage, nautilus_ideviceinfo_page, GTK_TYPE_BOX)
static const char UIFILE[] = NAUTILUS_EXTENSION_DIR "/nautilus-ideviceinfo.ui";
static gchar *value_formatter(gdouble percent, gpointer user_data)
{
gsize total_size = GPOINTER_TO_SIZE(user_data);
- return g_format_size_for_display (percent * total_size * 1048576);
+ return g_format_size (percent * total_size * 1048576);
}
#ifdef HAVE_MOBILE_PROVIDER_INFO
@@ -513,7 +517,7 @@ end_phone:
/* set disk usage information */
char *storage_formatted_size = NULL;
char *markup = NULL;
- storage_formatted_size = g_format_size_for_display (disk_total);
+ storage_formatted_size = g_format_size (disk_total);
markup = g_markup_printf_escaped ("<b>%s</b> (%s)", _("Storage"), storage_formatted_size);
gtk_label_set_markup(lbStorage, markup);
g_free(storage_formatted_size);
@@ -617,7 +621,7 @@ static gpointer ideviceinfo_load_data(gpointer data)
goto leave;
}
- if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(dev, &client, "nautilus-ideviceinfo")) {
+ if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(dev, &client, PACKAGE_NAME)) {
completed_message_free(msg);
client = NULL;
goto leave;
@@ -641,12 +645,12 @@ static gpointer ideviceinfo_load_data(gpointer data)
}
/* get number of applications */
- uint16_t iport = 0;
+ lockdownd_service_descriptor_t service = NULL;
- if ((lockdownd_start_service(client, "com.apple.mobile.installation_proxy", &iport) ==
LOCKDOWN_E_SUCCESS) && iport) {
+ if ((lockdownd_start_service(client, INSTPROXY_SERVICE_NAME, &service) == LOCKDOWN_E_SUCCESS) &&
service) {
CHECK_CANCELLED;
instproxy_client_t ipc = NULL;
- if (instproxy_client_new(dev, iport, &ipc) == INSTPROXY_E_SUCCESS) {
+ if (instproxy_client_new(dev, service, &ipc) == INSTPROXY_E_SUCCESS) {
plist_t opts = instproxy_client_options_new();
plist_t apps = NULL;
instproxy_client_options_add(opts, "ApplicationType", "User", NULL);
@@ -661,11 +665,21 @@ static gpointer ideviceinfo_load_data(gpointer data)
}
}
+ if (service) {
+ lockdownd_service_descriptor_free(service);
+ service = NULL;
+ }
+
/* Detect whether AFC2 is available */
- if ((lockdownd_start_service(client, "com.apple.afc2", &iport) == LOCKDOWN_E_SUCCESS) && iport) {
+ if ((lockdownd_start_service(client, AFC_SERVICE_NAME"2", &service) == LOCKDOWN_E_SUCCESS) &&
service) {
msg->has_afc2 = TRUE;
}
+ if (service) {
+ lockdownd_service_descriptor_free(service);
+ service = NULL;
+ }
+
g_idle_add((GSourceFunc) update_ui, msg);
leave:
@@ -762,7 +776,7 @@ GtkWidget *nautilus_ideviceinfo_page_new(const char *uuid, const char *mount_pat
GtkLabel *lbUUIDText = GTK_LABEL(gtk_builder_get_object (di->priv->builder, "lbUUIDText"));
gtk_label_set_text(lbUUIDText, di->priv->uuid);
- di->priv->thread = g_thread_create(ideviceinfo_load_data, di, TRUE, NULL);
+ di->priv->thread = g_thread_new("ideviceinfo-load", ideviceinfo_load_data, di);
return GTK_WIDGET (di);
}
diff --git a/src/ideviceinfo-property-page.h b/src/ideviceinfo-property-page.h
index 74b8e5d..6f0c691 100644
--- a/src/ideviceinfo-property-page.h
+++ b/src/ideviceinfo-property-page.h
@@ -36,12 +36,12 @@ typedef struct NautilusIdeviceinfoPageClass NautilusIdeviceinfoPageClass;
typedef struct NautilusIdeviceinfoPagePrivate NautilusIdeviceinfoPagePrivate;
struct NautilusIdeviceinfoPage {
- GtkVBox parent;
+ GtkBox parent;
NautilusIdeviceinfoPagePrivate *priv;
};
struct NautilusIdeviceinfoPageClass {
- GtkVBoxClass parent_class;
+ GtkBoxClass parent_class;
};
GType nautilus_ideviceinfo_page_get_type(void);
diff --git a/src/nautilus-afc2-warning-bar.c b/src/nautilus-afc2-warning-bar.c
index abdfb54..96e85e7 100644
--- a/src/nautilus-afc2-warning-bar.c
+++ b/src/nautilus-afc2-warning-bar.c
@@ -42,7 +42,7 @@ enum {
LAST_SIGNAL
};
-G_DEFINE_TYPE (NautilusAfc2WarningBar, nautilus_afc2_warning_bar, GTK_TYPE_HBOX)
+G_DEFINE_TYPE (NautilusAfc2WarningBar, nautilus_afc2_warning_bar, GTK_TYPE_BOX)
static void
nautilus_afc2_warning_bar_class_init (NautilusAfc2WarningBarClass *klass)
@@ -57,7 +57,7 @@ nautilus_afc2_warning_bar_class_init (NautilusAfc2WarningBarClass *klass)
static void
nautilus_afc2_warning_bar_init (NautilusAfc2WarningBar *bar)
{
- GtkWidget *label;
+ GtkWidget *label;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *image;
@@ -69,16 +69,17 @@ nautilus_afc2_warning_bar_init (NautilusAfc2WarningBar *bar)
gtk_box_set_spacing (GTK_BOX (bar), 6);
gtk_widget_show (hbox);
- image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
+ image = gtk_image_new_from_icon_name ("dialog-warning", GTK_ICON_SIZE_DIALOG);
gtk_widget_show (image);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 4);
- vbox = gtk_vbox_new (FALSE, 6);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_widget_show (vbox);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
label = gtk_label_new (_("Jailbroken filesystem browsing is unsupported"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
@@ -86,7 +87,8 @@ nautilus_afc2_warning_bar_init (NautilusAfc2WarningBar *bar)
hint = g_strdup_printf ("<i>%s</i>", _("Accessing the root filesystem of the device can cause
damage. If problems occur, a restore will be necessary."));
gtk_label_set_markup (GTK_LABEL (label), hint);
g_free (hint);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
}
diff --git a/src/nautilus-afc2-warning-bar.h b/src/nautilus-afc2-warning-bar.h
index c1a9613..b279441 100644
--- a/src/nautilus-afc2-warning-bar.h
+++ b/src/nautilus-afc2-warning-bar.h
@@ -38,14 +38,14 @@ typedef struct NautilusAfc2WarningBarPrivate NautilusAfc2WarningBarPrivate;
typedef struct
{
- GtkHBox box;
+ GtkBox box;
NautilusAfc2WarningBarPrivate *priv;
} NautilusAfc2WarningBar;
typedef struct
{
- GtkHBoxClass parent_class;
+ GtkBoxClass parent_class;
} NautilusAfc2WarningBarClass;
GType nautilus_afc2_warning_bar_get_type (void);
diff --git a/src/nautilus-ideviceinfo.ui b/src/nautilus-ideviceinfo.ui
index a73cf51..e49c6bb 100644
--- a/src/nautilus-ideviceinfo.ui
+++ b/src/nautilus-ideviceinfo.ui
@@ -1,19 +1,22 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.2 -->
<interface>
- <requires lib="gtk+" version="2.16"/>
- <!-- interface-naming-policy project-wide -->
- <object class="GtkVBox" id="ideviceinfo">
+ <requires lib="gtk+" version="3.0"/>
+ <object class="GtkBox" id="ideviceinfo">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
- <object class="GtkVBox" id="vbGeneral">
+ <object class="GtkBox" id="vbGeneral">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">General</property>
<attributes>
@@ -29,12 +32,14 @@
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="top_padding">8</property>
<property name="left_padding">12</property>
<property name="right_padding">8</property>
<child>
<object class="GtkTable" id="table1">
<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">4</property>
@@ -43,6 +48,7 @@
<object class="GtkLabel" id="lbDeviceName">
<property name="width_request">60</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -53,6 +59,7 @@
<object class="GtkLabel" id="lbDeviceVersion">
<property name="width_request">120</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -67,6 +74,7 @@
<object class="GtkLabel" id="lbDeviceModel">
<property name="width_request">60</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -81,6 +89,7 @@
<object class="GtkLabel" id="lbDeviceSerial">
<property name="width_request">120</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -97,6 +106,7 @@
<object class="GtkLabel" id="lbUUID">
<property name="width_request">59</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -110,6 +120,7 @@
<child>
<object class="GtkLabel" id="lbDeviceNameText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -123,6 +134,7 @@
<child>
<object class="GtkLabel" id="lbDeviceModelText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -138,6 +150,7 @@
<child>
<object class="GtkLabel" id="lbDeviceVersionText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -151,6 +164,7 @@
<child>
<object class="GtkLabel" id="lbDeviceSerialText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -166,6 +180,7 @@
<child>
<object class="GtkLabel" id="lbUUIDText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -183,22 +198,26 @@
</object>
<packing>
<property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkVBox" id="vbPhone">
+ <object class="GtkBox" id="vbPhone">
+ <property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">Phone</property>
@@ -215,12 +234,14 @@
<child>
<object class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="top_padding">8</property>
<property name="left_padding">12</property>
<property name="right_padding">8</property>
<child>
<object class="GtkTable" id="table2">
<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">4</property>
@@ -229,6 +250,7 @@
<object class="GtkLabel" id="lbTelNo">
<property name="width_request">120</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xpad">1</property>
@@ -243,6 +265,7 @@
<object class="GtkLabel" id="lbCarrier">
<property name="width_request">110</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xpad">1</property>
@@ -259,6 +282,7 @@
<object class="GtkLabel" id="lbIMEI">
<property name="width_request">120</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -274,6 +298,7 @@
<object class="GtkLabel" id="lbIMSI">
<property name="width_request">110</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -291,6 +316,7 @@
<object class="GtkLabel" id="lbModemFw">
<property name="width_request">120</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xpad">1</property>
@@ -307,6 +333,7 @@
<object class="GtkLabel" id="lbICCID">
<property name="width_request">110</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -323,6 +350,7 @@
<child>
<object class="GtkLabel" id="lbTelNoText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -336,6 +364,7 @@
<child>
<object class="GtkLabel" id="lbIMEIText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -351,6 +380,7 @@
<child>
<object class="GtkLabel" id="lbModemFwText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xpad">1</property>
@@ -367,6 +397,7 @@
<child>
<object class="GtkLabel" id="lbICCIDText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -382,6 +413,7 @@
<child>
<object class="GtkLabel" id="lbIMSIText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -397,6 +429,7 @@
<child>
<object class="GtkLabel" id="lbCarrierText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="selectable">True</property>
</object>
@@ -409,22 +442,27 @@
</child>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
- <object class="GtkVBox" id="vbNetwork">
+ <object class="GtkBox" id="vbNetwork">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Network</property>
<attributes>
@@ -440,12 +478,14 @@
<child>
<object class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="top_padding">8</property>
<property name="left_padding">12</property>
<property name="right_padding">8</property>
<child>
<object class="GtkTable" id="table3">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<property name="column_spacing">4</property>
@@ -454,6 +494,7 @@
<object class="GtkLabel" id="lbBTMac">
<property name="width_request">130</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -467,6 +508,7 @@
<object class="GtkLabel" id="lbWiFiMac">
<property name="width_request">130</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -481,6 +523,7 @@
<child>
<object class="GtkLabel" id="lbBTMacText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -494,6 +537,7 @@
<child>
<object class="GtkLabel" id="lbWiFiMacText">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">1</property>
<property name="ypad">1</property>
@@ -510,23 +554,28 @@
</child>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
- <object class="GtkVBox" id="vbStorage">
+ <object class="GtkBox" id="vbStorage">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Storage</property>
</object>
@@ -539,29 +588,37 @@
<child>
<object class="GtkAlignment" id="alignment4">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="top_padding">8</property>
<property name="left_padding">8</property>
<property name="right_padding">8</property>
<child>
- <object class="GtkVBox" id="vbox8">
+ <object class="GtkBox" id="vbox8">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkAlignment" id="disk_usage">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbiPodInfo">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
@@ -569,12 +626,15 @@
</child>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
+ <property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
diff --git a/src/rb-segmented-bar.c b/src/rb-segmented-bar.c
index 542e753..1210c0a 100644
--- a/src/rb-segmented-bar.c
+++ b/src/rb-segmented-bar.c
@@ -31,6 +31,7 @@
#include "config.h"
#endif
#include <math.h>
+#include <locale.h>
#include <cairo/cairo.h>
#include <gtk/gtk.h>
#include "rb-segmented-bar.h"
@@ -38,12 +39,9 @@
#define MINIMUM_HEIGHT 26
static void rb_segmented_bar_finalize (GObject *object);
-static void rb_segmented_bar_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
static void rb_segmented_bar_size_allocate(GtkWidget *widget,
GtkAllocation *allocation);
-static gboolean rb_segmented_bar_expose (GtkWidget *widget,
- GdkEventExpose *event);
+static gboolean rb_segmented_bar_draw (GtkWidget *widget, cairo_t *context);
static void rb_segmented_bar_get_property (GObject *object, guint param_id,
GValue *value, GParamSpec *pspec);
static void rb_segmented_bar_set_property (GObject *object, guint param_id,
@@ -51,9 +49,17 @@ static void rb_segmented_bar_set_property (GObject *object, guint param_id,
static gchar *rb_segmented_bar_default_value_formatter (gdouble percent,
gpointer data);
+static void rb_segmented_bar_get_preferred_height (GtkWidget *widget,
+ int *minimum_height,
+ int *natural_height);
+static void rb_segmented_bar_get_preferred_width (GtkWidget *widget,
+ int *minimum_width,
+ int *natural_width);
static void compute_layout_size (RBSegmentedBar *bar);
+static AtkObject * rb_segmented_bar_get_accessible (GtkWidget *widget);
+
enum
{
PROP_0,
@@ -79,6 +85,9 @@ struct _RBSegmentedBarPrivate {
RBSegmentedBarValueFormatter value_formatter;
gpointer value_formatter_data;
+
+ char *a11y_description;
+ char *a11y_locale;
};
G_DEFINE_TYPE (RBSegmentedBar, rb_segmented_bar, GTK_TYPE_WIDGET)
@@ -135,7 +144,7 @@ rb_segmented_bar_init (RBSegmentedBar *bar)
priv->segment_box_size = 12;
priv->segment_box_spacing = 6;
priv->value_formatter = rb_segmented_bar_default_value_formatter;
- GTK_WIDGET_SET_FLAGS (GTK_WIDGET (bar), GTK_NO_WINDOW);
+ gtk_widget_set_has_window (GTK_WIDGET (bar), FALSE);
}
static void
@@ -148,9 +157,11 @@ rb_segmented_bar_class_init (RBSegmentedBarClass *klass)
object_class->get_property = rb_segmented_bar_get_property;
object_class->set_property = rb_segmented_bar_set_property;
- widget_class->expose_event = rb_segmented_bar_expose;
- widget_class->size_request = rb_segmented_bar_size_request;
+ widget_class->draw = rb_segmented_bar_draw;
+ widget_class->get_preferred_width = rb_segmented_bar_get_preferred_width;
+ widget_class->get_preferred_height = rb_segmented_bar_get_preferred_height;
widget_class->size_allocate = rb_segmented_bar_size_allocate;
+ widget_class->get_accessible = rb_segmented_bar_get_accessible;
/**
* RBSegmentedBar::show-reflection
@@ -263,29 +274,45 @@ rb_segmented_bar_default_value_formatter (gdouble percent,
}
static void
-rb_segmented_bar_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+rb_segmented_bar_get_preferred_height (GtkWidget *widget, int *minimum_height, int *natural_height)
{
RBSegmentedBarPrivate *priv;
- guint real_height;
+ unsigned int height;
- g_return_if_fail (requisition != NULL);
priv = RB_SEGMENTED_BAR_GET_PRIVATE (RB_SEGMENTED_BAR (widget));
-
if (priv->reflect) {
- real_height = MINIMUM_HEIGHT*1.75;
+ height = MINIMUM_HEIGHT * 1.75;
} else {
- real_height = MINIMUM_HEIGHT;
+ height = MINIMUM_HEIGHT;
}
+
if (priv->show_labels) {
compute_layout_size (RB_SEGMENTED_BAR (widget));
- requisition->height = MAX (MINIMUM_HEIGHT + priv->bar_label_spacing + priv->layout_height,
- real_height);
- } else {
- requisition->height = real_height;
+ height = MAX (MINIMUM_HEIGHT + priv->bar_label_spacing + priv->layout_height, height);
}
- requisition->width = MAX (priv->layout_width, 200);
+
+ if (minimum_height)
+ *minimum_height = height;
+ if (natural_height)
+ *natural_height = height;
+}
+
+static void
+rb_segmented_bar_get_preferred_width (GtkWidget *widget, int *minimum_width, int *natural_width)
+{
+ RBSegmentedBarPrivate *priv;
+ int width;
+
+ priv = RB_SEGMENTED_BAR_GET_PRIVATE (RB_SEGMENTED_BAR (widget));
+
+ compute_layout_size (RB_SEGMENTED_BAR (widget));
+ width = MAX (priv->layout_width, 200);
+
+ if (minimum_width)
+ *minimum_width = width;
+ if (natural_width)
+ *natural_width = width;
}
static PangoLayout *create_adapt_layout (GtkWidget *widget, PangoLayout *layout,
@@ -389,6 +416,7 @@ rb_segmented_bar_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
guint real_height;
RBSegmentedBarPrivate *priv = RB_SEGMENTED_BAR_GET_PRIVATE (widget);
+ GtkAllocation new_allocation;
g_return_if_fail(RB_IS_SEGMENTED_BAR(widget));
g_return_if_fail(allocation != NULL);
@@ -398,16 +426,17 @@ rb_segmented_bar_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
} else {
real_height = priv->bar_height;
}
- widget->allocation = *allocation;
+ gtk_widget_set_allocation (widget, allocation);
if (priv->show_labels) {
compute_layout_size (RB_SEGMENTED_BAR (widget));
- widget->allocation.height = MAX (priv->bar_height + priv->bar_label_spacing +
priv->layout_height,
- real_height);
+ new_allocation.height = MAX (priv->bar_height + priv->bar_label_spacing + priv->layout_height,
+ real_height);
} else {
- widget->allocation.height = real_height;
+ new_allocation.height = real_height;
}
- widget->allocation.width = priv->layout_width + 2*(priv->h_padding);
- GTK_WIDGET_CLASS(rb_segmented_bar_parent_class)->size_allocate(widget, allocation);
+ new_allocation.width = priv->layout_width + 2*(priv->h_padding);
+ gtk_widget_set_allocation (widget, &new_allocation);
+ GTK_WIDGET_CLASS(rb_segmented_bar_parent_class)->size_allocate(widget, allocation);
}
@@ -422,6 +451,10 @@ guint rb_segmented_bar_add_segment (RBSegmentedBar *bar,
Segment *segment = rb_segment_new (title, percent, &color);
priv->segments = g_list_append (priv->segments, segment);
index = g_list_index (priv->segments, segment);
+
+ g_free (priv->a11y_description);
+ priv->a11y_description = NULL;
+
gtk_widget_queue_draw (GTK_WIDGET (bar));
gtk_widget_queue_resize (GTK_WIDGET (bar));
@@ -443,6 +476,9 @@ void rb_segmented_bar_update_segment (RBSegmentedBar *bar,
Segment *segment = g_list_nth_data (priv->segments, segment_index);
if (segment != NULL) {
segment->percent = percent;
+ g_free (priv->a11y_description);
+ priv->a11y_description = NULL;
+
gtk_widget_queue_draw (GTK_WIDGET (bar));
}
}
@@ -647,25 +683,30 @@ static void rb_segmented_bar_render_labels (RBSegmentedBar *bar,
RBSegmentedBarPrivate *priv;
PangoLayout *layout;
Color text_color;
- GdkColor *gdk_color;
+ GdkRGBA gdk_color;
+ gboolean ltr = TRUE;
int x = 0;
GList *it;
- gboolean is_rtl = (gtk_widget_get_direction(GTK_WIDGET(bar)) == GTK_TEXT_DIR_RTL);
priv = RB_SEGMENTED_BAR_GET_PRIVATE (RB_SEGMENTED_BAR (bar));
if (priv->segments == NULL) {
return;
}
- gdk_color = >K_WIDGET (bar)->style->fg[GTK_WIDGET_STATE (GTK_WIDGET (bar))];
- text_color.red = gdk_color->red / 65535.0;
- text_color.green = gdk_color->green / 65535.0;
- text_color.blue = gdk_color->blue / 65535.0;
+ gtk_style_context_get_color (gtk_widget_get_style_context (GTK_WIDGET (bar)),
+ gtk_widget_get_state_flags (GTK_WIDGET (bar)),
+ &gdk_color);
+
+ if (gtk_widget_get_direction (GTK_WIDGET (bar)) == GTK_TEXT_DIR_RTL) {
+ ltr = FALSE;
+ x = priv->layout_width;
+ }
+
+ text_color.red = gdk_color.red;
+ text_color.green = gdk_color.green;
+ text_color.blue = gdk_color.blue;
text_color.alpha = 1.0;
layout = NULL;
- if (is_rtl) {
- x = priv->layout_width - priv->segment_box_size;
- }
for (it = priv->segments; it != NULL; it = it->next) {
cairo_pattern_t *grad;
int layout_width;
@@ -673,6 +714,10 @@ static void rb_segmented_bar_render_labels (RBSegmentedBar *bar,
gchar *value_str;
Segment *segment;
+ if (ltr == FALSE) {
+ x -= priv->segment_box_size + priv->segment_box_spacing;
+ }
+
segment = (Segment *)it->data;
cairo_set_line_width (context, 1);
cairo_rectangle (context, x + 0.5, 2 + 0.5,
@@ -689,18 +734,20 @@ static void rb_segmented_bar_render_labels (RBSegmentedBar *bar,
cairo_stroke (context);
cairo_pattern_destroy (grad);
- if (is_rtl)
- x -= (segment->layout_width + priv->segment_box_spacing);
- else
+ if (ltr) {
x += priv->segment_box_size + priv->segment_box_spacing;
+ }
layout = create_adapt_layout (GTK_WIDGET (bar), layout,
FALSE, TRUE);
pango_layout_set_text (layout, segment->label, -1);
pango_layout_get_pixel_size (layout,
&layout_width, &layout_height);
+ if (ltr == FALSE) {
+ x -= priv->segment_box_spacing + layout_width;
+ }
- cairo_move_to (context, (is_rtl) ? x+((int)segment->layout_width - (int)layout_width) : x, 0);
+ cairo_move_to (context, x, 0);
cairo_set_source_rgba (context,
text_color.red, text_color.green,
text_color.blue, 0.9);
@@ -715,62 +762,56 @@ static void rb_segmented_bar_render_labels (RBSegmentedBar *bar,
pango_layout_set_text (layout, value_str, -1);
g_free (value_str);
- if (is_rtl && ((int)layout_width >= (int)segment->layout_width)) {
- int value_layout_width = layout_width;
- int value_layout_height = layout_height;
- pango_layout_get_pixel_size (layout,
- &value_layout_width, &value_layout_height);
- cairo_move_to (context, x+(segment->layout_width-value_layout_width), layout_height);
- } else {
- cairo_move_to (context, x, layout_height);
- }
+ cairo_move_to (context, x, layout_height);
cairo_set_source_rgba (context,
text_color.red, text_color.green,
text_color.blue, 0.75);
pango_cairo_show_layout (context, layout);
cairo_fill (context);
- if (is_rtl)
- x -= (priv->segment_box_size + priv->segment_label_spacing);
- else
+ if (ltr) {
x += segment->layout_width + priv->segment_label_spacing;
+ } else {
+ x -= segment->layout_width - layout_width;
+ }
}
g_object_unref (G_OBJECT (layout));
}
static gboolean
-rb_segmented_bar_expose (GtkWidget *widget,
- GdkEventExpose *event)
+rb_segmented_bar_draw (GtkWidget *widget, cairo_t *context)
{
RBSegmentedBar *bar;
RBSegmentedBarPrivate *priv;
- cairo_t *context;
cairo_pattern_t *bar_pattern;
+ GtkAllocation allocation;
g_return_val_if_fail (RB_IS_SEGMENTED_BAR (widget), FALSE);
- if (GTK_WIDGET_DRAWABLE (widget) == FALSE) {
- return FALSE;
- }
bar = RB_SEGMENTED_BAR (widget);
priv = RB_SEGMENTED_BAR_GET_PRIVATE (bar);
- context = gdk_cairo_create (GDK_DRAWABLE (widget->window));
-
if (priv->reflect) {
cairo_push_group (context);
}
cairo_set_operator (context, CAIRO_OPERATOR_OVER);
- cairo_translate (context, widget->allocation.x + priv->h_padding,
- widget->allocation.y);
+ gtk_widget_get_allocation (widget, &allocation);
+ if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_LTR) {
+ cairo_translate (context, allocation.x + priv->h_padding, allocation.y);
+ } else {
+ cairo_translate (context,
+ allocation.x + allocation.width - priv->h_padding,
+ allocation.y);
+ cairo_scale (context, -1.0, 1.0);
+ }
cairo_rectangle (context, 0, 0,
- widget->allocation.width - priv->h_padding,
+ allocation.width - priv->h_padding,
MAX (2*priv->bar_height, priv->bar_height + priv->bar_label_spacing +
priv->layout_height));
cairo_clip (context);
bar_pattern = rb_segmented_bar_render (bar,
- widget->allocation.width - 2*priv->h_padding,
+ allocation.width - 2*priv->h_padding,
priv->bar_height);
cairo_save (context);
@@ -785,7 +826,7 @@ rb_segmented_bar_expose (GtkWidget *widget,
cairo_save (context);
cairo_rectangle (context, 0, priv->bar_height,
- widget->allocation.width - priv->h_padding,
+ allocation.width - priv->h_padding,
priv->bar_height);
cairo_clip (context);
cairo_matrix_init_scale (&matrix, 1, -1);
@@ -812,17 +853,16 @@ rb_segmented_bar_expose (GtkWidget *widget,
if (priv->show_labels) {
if (priv->reflect) {
cairo_translate (context,
- widget->allocation.x + (widget->allocation.width -
priv->layout_width)/2,
- widget->allocation.y + priv->bar_height + priv->bar_label_spacing);
+ allocation.x + (allocation.width - priv->layout_width)/2,
+ allocation.y + priv->bar_height + priv->bar_label_spacing);
} else {
cairo_translate (context,
- -priv->h_padding + (widget->allocation.width - priv->layout_width)/2,
+ -priv->h_padding + (allocation.width - priv->layout_width)/2,
priv->bar_height + priv->bar_label_spacing);
}
rb_segmented_bar_render_labels (bar, context);
}
cairo_pattern_destroy (bar_pattern);
- cairo_destroy (context);
return TRUE;
}
@@ -843,3 +883,191 @@ void rb_segmented_bar_set_value_formatter (RBSegmentedBar *bar,
priv->value_formatter = formatter;
priv->value_formatter_data = data;
}
+
+static const char *
+get_a11y_description (RBSegmentedBar *bar)
+{
+ RBSegmentedBarPrivate *priv;
+
+ priv = RB_SEGMENTED_BAR_GET_PRIVATE (bar);
+ if (priv->a11y_description == NULL) {
+ GList *i;
+ GString *desc = g_string_new ("");
+
+ for (i = priv->segments; i != NULL; i = i->next) {
+ Segment *segment;
+ char *value_str;
+
+ segment = (Segment *)i->data;
+
+ g_assert (priv->value_formatter != NULL);
+ value_str = priv->value_formatter (segment->percent,
+ priv->value_formatter_data);
+
+ g_string_append_printf (desc, "%s: %s\n", segment->label, value_str);
+ g_free (value_str);
+ }
+
+ priv->a11y_description = g_string_free (desc, FALSE);
+ }
+ return priv->a11y_description;
+}
+
+static const char *
+get_a11y_locale (RBSegmentedBar *bar)
+{
+ RBSegmentedBarPrivate *priv;
+
+ priv = RB_SEGMENTED_BAR_GET_PRIVATE (bar);
+ if (priv->a11y_locale == NULL) {
+ priv->a11y_locale = setlocale (LC_MESSAGES, "");
+ }
+ return priv->a11y_locale;
+}
+
+/* A11y type hack copied from nautilus/eel/eel-accessibility.c */
+
+static GType
+create_a11y_derived_type (const char *type_name, GType existing_type, GClassInitFunc class_init)
+{
+ GType type;
+ GType parent_atk_type;
+ GTypeQuery query;
+ AtkObjectFactory *factory;
+ GTypeInfo typeinfo = {0,};
+
+ type = g_type_from_name (type_name);
+ if (type != G_TYPE_INVALID) {
+ return type;
+ }
+
+ factory = atk_registry_get_factory (atk_get_default_registry (), existing_type);
+ parent_atk_type = atk_object_factory_get_accessible_type (factory);
+ if (parent_atk_type == G_TYPE_INVALID) {
+ return G_TYPE_INVALID;
+ }
+
+ g_type_query (parent_atk_type, &query);
+ if (class_init) {
+ typeinfo.class_init = class_init;
+ }
+ typeinfo.class_size = query.class_size;
+ typeinfo.instance_size = query.instance_size;
+
+ type = g_type_register_static (parent_atk_type, type_name, &typeinfo, 0);
+ return type;
+}
+
+/* AtkObject implementation */
+
+static gint
+a11y_impl_get_n_children (AtkObject *obj)
+{
+ return 0;
+}
+
+static AtkObject *
+a11y_impl_ref_child (AtkObject *obj, gint i)
+{
+ return NULL;
+}
+
+/* AtkImage */
+
+static void
+a11y_impl_get_image_position (AtkImage *image, gint *x, gint *y, AtkCoordType coord_type)
+{
+ atk_component_get_extents (ATK_COMPONENT (image), x, y, NULL, NULL, coord_type);
+}
+
+static const char *
+a11y_impl_get_image_description (AtkImage *image)
+{
+ RBSegmentedBar *bar;
+ bar = RB_SEGMENTED_BAR (g_object_get_data (G_OBJECT (image), "rb-atk-widget"));
+ return get_a11y_description (bar);
+}
+
+static void
+a11y_impl_get_image_size (AtkImage *image, gint *width, gint *height)
+{
+ GtkAllocation alloc;
+ GtkWidget *widget;
+
+ widget = GTK_WIDGET (g_object_get_data (G_OBJECT (image), "rb-atk-widget"));
+
+ gtk_widget_get_allocation (widget, &alloc);
+ *width = alloc.width;
+ *height = alloc.height;
+}
+
+static const char *
+a11y_impl_get_image_locale (AtkImage *image)
+{
+ RBSegmentedBar *bar;
+ bar = RB_SEGMENTED_BAR (g_object_get_data (G_OBJECT (image), "rb-atk-widget"));
+ return get_a11y_locale (bar);
+}
+
+static void
+rb_segmented_bar_a11y_class_init (AtkObjectClass *klass)
+{
+ AtkObjectClass *atkobject_class = ATK_OBJECT_CLASS (klass);
+
+ atkobject_class->get_n_children = a11y_impl_get_n_children;
+ atkobject_class->ref_child = a11y_impl_ref_child;
+}
+
+static void
+rb_segmented_bar_a11y_image_init (AtkImageIface *iface)
+{
+ iface->get_image_position = a11y_impl_get_image_position;
+ iface->get_image_description = a11y_impl_get_image_description;
+ iface->get_image_size = a11y_impl_get_image_size;
+ iface->get_image_locale = a11y_impl_get_image_locale;
+ /* don't need set_image_description, do we? */
+}
+
+static void
+destroy_accessible (gpointer data, GObject *obj)
+{
+ atk_object_notify_state_change (ATK_OBJECT (data), ATK_STATE_DEFUNCT, TRUE);
+}
+
+static AtkObject *
+rb_segmented_bar_get_accessible (GtkWidget *widget)
+{
+ static GType a11ytype = G_TYPE_INVALID;
+ AtkObject *accessible;
+ accessible = g_object_get_data (G_OBJECT (widget), "rb-atk-object");
+ if (accessible != NULL) {
+ return accessible;
+ }
+
+ if (a11ytype == G_TYPE_INVALID) {
+ const GInterfaceInfo atk_image_info = {
+ (GInterfaceInitFunc) rb_segmented_bar_a11y_image_init,
+ (GInterfaceFinalizeFunc) NULL,
+ NULL
+ };
+
+ a11ytype = create_a11y_derived_type ("RBSegmentedBarA11y",
+ GTK_TYPE_WIDGET,
+ (GClassInitFunc) rb_segmented_bar_a11y_class_init);
+ if (a11ytype == G_TYPE_INVALID) {
+ g_warning ("unable to create a11y type for segmented bar");
+ return NULL;
+ }
+
+ g_type_add_interface_static (a11ytype, ATK_TYPE_IMAGE, &atk_image_info);
+ }
+
+ accessible = g_object_new (a11ytype, NULL);
+ atk_object_set_role (accessible, ATK_ROLE_IMAGE);
+ atk_object_initialize (accessible, widget);
+
+ g_object_set_data_full (G_OBJECT (widget), "rb-atk-object", accessible, (GDestroyNotify)
destroy_accessible);
+ g_object_set_data (G_OBJECT (accessible), "rb-atk-widget", widget);
+
+ return accessible;
+}
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]