dbus client: allow building with no Mux widgets

also changed MuxFrame to actually derive from GtkFrame:
This makes it easier to use MuxFrame and GtkFrame
interchangeably.
This commit is contained in:
Jussi Kukkonen 2009-04-24 16:23:03 +01:00
parent 38676c3ed1
commit d58a5a5777
6 changed files with 123 additions and 162 deletions

View file

@ -90,5 +90,5 @@ for backend in $BACKENDS; do
eval echo $backend: \${enable_${backend}}
done
echo "DBus service: $enable_dbus_service"
echo "GTK+ UI (DBus client): $enable_gui"
echo "UI (DBus client): $enable_gui"
echo

View file

@ -208,14 +208,29 @@ AC_SUBST(DBUS_SERVICES_DIR)
AC_DEFINE_UNQUOTED(DBUS_SERVICES_DIR, "$DBUS_SERVICES_DIR", [Location of D-Bus services directory])
AC_ARG_ENABLE(gui,
AS_HELP_STRING([--enable-gui],
[enables building the GTK+ UI that uses the SyncEvolution DBus API]),
enable_gui="$enableval", enable_gui="no")
AS_HELP_STRING([--enable-gui[=gui type]],
[enables building the GTK+ UI that uses the SyncEvolution DBus API
Options: gtk, moblin]),
[ if test "$enableval" = "gtk" ; then
enable_gui=gtk
elif test "$enableval" = "yes" ; then
enable_gui=gtk
elif test "$enableval" = "moblin" ; then
enable_gui=moblin
elif test "$enableval" = "no" ; then
enable_gui=no
else
AC_ERROR([Unknown gui type: '$enableval'])
fi
])
AM_CONDITIONAL([COND_GUI], [test "$enable_gui" = "yes"])
AM_CONDITIONAL([COND_GUI], [test "$enable_gui" != "no"])
# for sync ui
if test $enable_gui == "yes"; then
if test $enable_gui == "moblin"; then
AC_DEFINE(USE_MOBLIN_UX, 1, [Use the MUX widget library])
fi
if test $enable_gui != "no"; then
PKG_CHECK_MODULES(GUI, glib-2.0 dbus-glib-1 >= 0.60 gtk+-2.0 libglade-2.0 gconf-2.0 gnome-vfs-2.0)
AC_PATH_PROG([GTK_BUILDER_CONV], gtk-builder-convert)
fi

View file

@ -12,7 +12,7 @@ static void mux_frame_buildable_add_child (GtkBuildable *buildable,
GObject *child,
const gchar *type);
G_DEFINE_TYPE_WITH_CODE (MuxFrame, mux_frame, GTK_TYPE_BIN,
G_DEFINE_TYPE_WITH_CODE (MuxFrame, mux_frame, GTK_TYPE_FRAME,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, mux_frame_buildable_init))
static void
@ -27,7 +27,6 @@ mux_frame_finalize (GObject *object)
G_OBJECT_CLASS (mux_frame_parent_class)->finalize (object);
}
static void
mux_frame_update_style (MuxFrame *frame)
{
@ -54,10 +53,10 @@ mux_frame_update_style (MuxFrame *frame)
}
if (font) {
if (frame->title) {
if (GTK_FRAME (frame)->label_widget) {
PangoFontDescription *desc;
desc = pango_font_description_from_string (font);
gtk_widget_modify_font (frame->title, desc);
gtk_widget_modify_font (GTK_FRAME (frame)->label_widget, desc);
pango_font_description_free (desc);
}
g_free (font);
@ -65,31 +64,28 @@ mux_frame_update_style (MuxFrame *frame)
}
static void
mux_frame_set_title_widget (MuxFrame *frame, GtkWidget *title)
label_changed_cb (MuxFrame *frame)
{
g_return_if_fail (MUX_IS_FRAME (frame));
g_return_if_fail (!title || GTK_IS_LABEL (title) || !title->parent);
char *font = NULL;
GtkFrame *gtk_frame = GTK_FRAME (frame);
if (frame->title == title)
if (!gtk_frame->label_widget)
return;
if (frame->title) {
gtk_widget_unparent (frame->title);
/* ensure font is correct */
gtk_widget_style_get (GTK_WIDGET (frame),
"title-font", &font,
NULL);
if (font) {
PangoFontDescription *desc;
desc = pango_font_description_from_string (font);
gtk_widget_modify_font (gtk_frame->label_widget, desc);
pango_font_description_free (desc);
g_free (font);
}
frame->title = title;
if (title) {
gtk_widget_show (title);
gtk_widget_set_parent (title, GTK_WIDGET (frame));
}
mux_frame_update_style (frame);
if (GTK_WIDGET_VISIBLE (frame))
gtk_widget_queue_resize (GTK_WIDGET (frame));
gtk_misc_set_alignment (GTK_MISC (gtk_frame->label_widget), 0.0, 1.0);
}
static void
rounded_rectangle (cairo_t * cr,
double x, double y, double w, double h,
@ -157,7 +153,7 @@ mux_frame_paint (GtkWidget *widget, GdkRectangle *area)
cairo_paint (cairo);
/* draw bullet before title */
if (frame->title) {
if (GTK_FRAME (frame)->label_widget) {
gdk_cairo_set_source_color (cairo, &frame->bullet_color);
rounded_rectangle (cairo,
@ -180,48 +176,22 @@ mux_frame_paint (GtkWidget *widget, GdkRectangle *area)
static gboolean
mux_frame_expose(GtkWidget *widget,
GdkEventExpose *event)
{
{
GtkWidgetClass *grand_parent;
if (GTK_WIDGET_DRAWABLE (widget)) {
mux_frame_paint (widget, &event->area);
(* GTK_WIDGET_CLASS (mux_frame_parent_class)->expose_event) (widget, event);
grand_parent = GTK_WIDGET_CLASS (g_type_class_peek_parent (mux_frame_parent_class));
grand_parent->expose_event (widget, event);
}
return FALSE;
}
static void
mux_frame_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data)
{
MuxFrame *mux_frame = MUX_FRAME (container);
GtkBin *bin = GTK_BIN (container);
if (bin->child)
(* callback) (bin->child, callback_data);
if (mux_frame->title)
(* callback) (mux_frame->title, callback_data);
}
static void
mux_frame_remove (GtkContainer *container,
GtkWidget *child)
{
MuxFrame *frame = MUX_FRAME (container);
if (child == frame->title) {
mux_frame_set_title_widget (frame, NULL);
} else {
GTK_CONTAINER_CLASS (mux_frame_parent_class)->remove (container, child);
}
}
static void
mux_frame_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
MuxFrame *mux_frame = MUX_FRAME (widget);
GtkFrame *frame = GTK_FRAME (widget);
GtkBin *bin = GTK_BIN (widget);
GtkRequisition child_req;
GtkRequisition title_req;
@ -231,8 +201,8 @@ mux_frame_size_request (GtkWidget *widget,
gtk_widget_size_request (bin->child, &child_req);
title_req.width = title_req.height = 0;
if (mux_frame->title) {
gtk_widget_size_request (mux_frame->title, &title_req);
if (frame->label_widget) {
gtk_widget_size_request (frame->label_widget, &title_req);
/* add room for bullet */
title_req.height = title_req.height * mux_frame_bullet_size_factor +
2 * MUX_FRAME_BULLET_PADDING;
@ -256,6 +226,7 @@ mux_frame_size_allocate (GtkWidget *widget,
{
GtkBin *bin = GTK_BIN (widget);
MuxFrame *mux_frame = MUX_FRAME (widget);
GtkFrame *frame = GTK_FRAME (widget);
GtkAllocation child_allocation;
int xmargin, ymargin, title_height;
@ -266,10 +237,10 @@ mux_frame_size_allocate (GtkWidget *widget,
widget->style->ythickness;
title_height = 0;
if (mux_frame->title) {
if (frame->label_widget) {
GtkAllocation title_allocation;
GtkRequisition title_req;
gtk_widget_get_child_requisition (mux_frame->title, &title_req);
gtk_widget_get_child_requisition (frame->label_widget, &title_req);
/* the bullet is bigger than the text */
title_height = title_req.height * mux_frame_bullet_size_factor +
@ -281,7 +252,7 @@ mux_frame_size_allocate (GtkWidget *widget,
title_allocation.width = MIN (title_req.width,
allocation->width - 2 * xmargin - title_height);
title_allocation.height = title_height - 2 * MUX_FRAME_BULLET_PADDING;
gtk_widget_size_allocate (mux_frame->title, &title_allocation);
gtk_widget_size_allocate (frame->label_widget, &title_allocation);
mux_frame->bullet_allocation.x = allocation->x + xmargin + MUX_FRAME_BULLET_PADDING;
mux_frame->bullet_allocation.y = allocation->y + ymargin + MUX_FRAME_BULLET_PADDING;
@ -295,10 +266,10 @@ mux_frame_size_allocate (GtkWidget *widget,
child_allocation.height = allocation->height - 2 * ymargin - title_height;
if (GTK_WIDGET_MAPPED (widget) &&
(child_allocation.x != mux_frame->child_allocation.x ||
child_allocation.y != mux_frame->child_allocation.y ||
child_allocation.width != mux_frame->child_allocation.width ||
child_allocation.height != mux_frame->child_allocation.height)) {
(child_allocation.x != frame->child_allocation.x ||
child_allocation.y != frame->child_allocation.y ||
child_allocation.width != frame->child_allocation.width ||
child_allocation.height != frame->child_allocation.height)) {
gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
}
@ -306,7 +277,7 @@ mux_frame_size_allocate (GtkWidget *widget,
gtk_widget_size_allocate (bin->child, &child_allocation);
}
mux_frame->child_allocation = child_allocation;
frame->child_allocation = child_allocation;
}
static void mux_frame_style_set (GtkWidget *widget,
@ -324,7 +295,6 @@ mux_frame_class_init (MuxFrameClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GParamSpec *pspec;
object_class->dispose = mux_frame_dispose;
@ -335,9 +305,6 @@ mux_frame_class_init (MuxFrameClass *klass)
widget_class->size_allocate = mux_frame_size_allocate;
widget_class->style_set = mux_frame_style_set;
container_class->forall = mux_frame_forall;
container_class->remove = mux_frame_remove;
pspec = g_param_spec_boxed ("border-color",
"Border color",
"Color of the outside border",
@ -379,7 +346,8 @@ mux_frame_buildable_init (GtkBuildableIface *iface)
static void
mux_frame_init (MuxFrame *self)
{
g_signal_connect (self, "notify::label-widget",
G_CALLBACK (label_changed_cb), NULL);
}
GtkWidget*
@ -390,28 +358,3 @@ mux_frame_new (void)
NULL);
}
const char*
mux_frame_get_title (MuxFrame *frame)
{
g_return_val_if_fail (MUX_IS_FRAME (frame), NULL);
if (frame->title) {
return gtk_label_get_text (GTK_LABEL (frame->title));
}
return NULL;
}
void
mux_frame_set_title (MuxFrame *frame, const char *title)
{
GtkWidget *w = NULL;
g_return_if_fail (MUX_IS_FRAME (frame));
if (title) {
w = gtk_label_new (title);
gtk_widget_set_name (w, "mux_frame_title");
gtk_misc_set_alignment (GTK_MISC (w), 0.0, 1.0);
}
mux_frame_set_title_widget (frame, w);
}

View file

@ -24,11 +24,8 @@ G_BEGIN_DECLS
(G_TYPE_INSTANCE_GET_CLASS ((obj), MUX_TYPE_FRAME, MuxFrameClass))
typedef struct {
GtkBin parent;
GtkFrame parent;
GtkWidget *title;
GtkAllocation child_allocation;
GtkAllocation bullet_allocation;
GdkColor bullet_color;
@ -36,16 +33,13 @@ typedef struct {
} MuxFrame;
typedef struct {
GtkBinClass parent_class;
GtkFrameClass parent_class;
} MuxFrameClass;
GType mux_frame_get_type (void);
GtkWidget* mux_frame_new (void);
const char* mux_frame_get_title (MuxFrame *frame);
void mux_frame_set_title (MuxFrame *bin, const char *title);
G_END_DECLS
#endif

View file

@ -33,8 +33,11 @@
#include <synthesis/engine_defs.h>
#include "sync-ui-config.h"
#ifdef USE_MOBLIN_UX
#include "mux-frame.h"
#include "mux-window.h"
#endif
#define SYNC_UI_GCONF_DIR "/apps/sync-ui"
#define SYNC_UI_SERVER_KEY SYNC_UI_GCONF_DIR"/server"
@ -615,29 +618,34 @@ sync_type_toggled_cb (GObject *radio, app_data *data)
}
#ifdef USE_MOBLIN_UX
/* truly stupid, but glade doesn't allow custom containers.
Now glade file has dummy containers that will be replaced here.
The dummy should be a gtkbin and it's parent should be a box with just one child */
static GtkWidget*
switch_dummy_to_mux_frame (GtkWidget *dummy)
{
GtkWidget *frame, *child, *parent;
GtkWidget *frame, *parent;
const char *title;
g_assert (GTK_IS_BIN (dummy));
frame = mux_frame_new ();
gtk_widget_set_name (frame, gtk_widget_get_name (dummy));
title = gtk_frame_get_label (GTK_FRAME(dummy));
if (title && strlen (title) > 0)
gtk_frame_set_label (GTK_FRAME (frame), title);
parent = gtk_widget_get_parent (dummy);
g_assert (GTK_IS_BOX (parent));
child = gtk_bin_get_child (GTK_BIN (dummy));
gtk_container_remove (GTK_CONTAINER (dummy), child);
gtk_widget_reparent (gtk_bin_get_child (GTK_BIN (dummy)), frame);
gtk_container_remove (GTK_CONTAINER (parent), dummy);
/* make sure there are no other children in box */
g_assert (gtk_container_get_children (GTK_CONTAINER (parent)) == NULL);
frame = mux_frame_new ();
gtk_box_pack_start (GTK_BOX (parent), frame, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (frame), child);
gtk_widget_show (frame);
return frame;
}
@ -653,12 +661,27 @@ switch_dummy_to_mux_window (GtkWidget *dummy)
g_assert (GTK_IS_BIN (dummy));
window = mux_window_new ();
gtk_widget_set_name (window, gtk_widget_get_name (dummy));
gtk_window_set_title (GTK_WINDOW (window), "Sync");
mux_window_set_decorations (MUX_WINDOW (window), MUX_DECOR_CLOSE);
gtk_widget_reparent (gtk_bin_get_child (GTK_BIN (dummy)), window);
return window;
}
#else
/* return the placeholders themselves when not using Moblin UX */
static GtkWidget*
switch_dummy_to_mux_frame (GtkWidget *dummy) {
return dummy;
}
static GtkWidget*
switch_dummy_to_mux_window (GtkWidget *dummy)
{
return dummy;
}
#endif
static void
show_link_button_url (GtkLinkButton *link)
@ -758,28 +781,16 @@ init_ui (app_data *data)
swap the all dummy widgets with Muxwidgets */
data->sync_win = switch_dummy_to_mux_window (GTK_WIDGET (gtk_builder_get_object (builder, "sync_win")));
data->services_win = switch_dummy_to_mux_window (GTK_WIDGET (gtk_builder_get_object (builder, "services_win")));
gtk_widget_set_name (data->services_win, "services_win");
gtk_window_set_transient_for (GTK_WINDOW (data->services_win),
GTK_WINDOW (data->sync_win));
data->service_settings_win = switch_dummy_to_mux_window (GTK_WIDGET (gtk_builder_get_object (builder, "service_settings_win")));
gtk_widget_set_name (data->services_win, "service_settings_win");
data->main_frame = switch_dummy_to_mux_frame (GTK_WIDGET (gtk_builder_get_object (builder, "main_frame")));
gtk_widget_set_name (data->main_frame, "main_frame");
data->log_frame = switch_dummy_to_mux_frame (GTK_WIDGET (gtk_builder_get_object (builder, "log_frame")));
gtk_widget_set_name (data->log_frame, "log_frame");
mux_frame_set_title (MUX_FRAME (data->log_frame), "Log");
data->services_frame = switch_dummy_to_mux_frame (GTK_WIDGET (gtk_builder_get_object (builder, "services_frame")));
gtk_widget_set_name (data->services_frame, "services_frame");
mux_frame_set_title (MUX_FRAME (data->services_frame), "Services");
data->backup_frame = switch_dummy_to_mux_frame (GTK_WIDGET (gtk_builder_get_object (builder, "backup_frame")));
gtk_widget_set_name (data->backup_frame, "backup_frame");
mux_frame_set_title (MUX_FRAME (data->backup_frame), "Backup");
frame = switch_dummy_to_mux_frame (GTK_WIDGET (gtk_builder_get_object (builder, "services_list_frame")));
mux_frame_set_title (MUX_FRAME (frame), "Sync services");
gtk_widget_set_name (frame, "services_list_frame");
data->service_settings_frame = switch_dummy_to_mux_frame (GTK_WIDGET (gtk_builder_get_object (builder, "service_settings_frame")));
mux_frame_set_title (MUX_FRAME (frame), "Sync service settings");
g_signal_connect (data->sync_win, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
@ -1010,13 +1021,11 @@ show_settings_window (app_data *data, server_config *config)
config->name ? config->name : "");
g_object_set_data (G_OBJECT (data->service_name_entry), "value", &config->name);
if (config->name) {
mux_frame_set_title (MUX_FRAME (data->service_settings_frame), config->name);
gtk_frame_set_label (GTK_FRAME (data->service_settings_frame), config->name);
gtk_widget_hide (data->service_name_label);
gtk_widget_hide (data->service_name_entry);
} else {
mux_frame_set_title (MUX_FRAME (data->service_settings_frame), "New service");
gtk_frame_set_label (GTK_FRAME (data->service_settings_frame), "New service");
gtk_widget_show (data->service_name_label);
gtk_widget_show (data->service_name_entry);
}

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Tue Apr 21 12:41:05 2009 -->
<!--Generated with glade3 3.4.5 on Fri Apr 24 13:50:07 2009 -->
<glade-interface>
<widget class="GtkWindow" id="sync_win">
<property name="border_width">5</property>
@ -384,7 +384,7 @@ synchronize your data between your netbook and a web service.</property>
<widget class="GtkFrame" id="log_frame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<child>
<widget class="GtkVBox" id="vbox18">
<property name="visible">True</property>
@ -512,7 +512,7 @@ synchronize your data between your netbook and a web service.</property>
<widget class="GtkFrame" id="backup_frame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<child>
<widget class="GtkAlignment" id="alignment3">
<property name="height_request">110</property>
@ -594,7 +594,7 @@ backup</property>
<widget class="GtkFrame" id="services_frame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<child>
<widget class="GtkAlignment" id="alignment5">
<property name="height_request">110</property>
@ -1007,35 +1007,27 @@ you can setup a service manually.</property>
<property name="column_spacing">5</property>
<property name="row_spacing">4</property>
<child>
<widget class="GtkEntry" id="service_name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="service_name_label">
<widget class="GtkLabel" id="label10">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Service name</property>
<property name="label" translatable="yes">Password</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_SHRINK | GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="username_entry">
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Username</property>
</widget>
<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_SHRINK | GTK_FILL</property>
</packing>
</child>
<child>
@ -1052,27 +1044,35 @@ you can setup a service manually.</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<widget class="GtkEntry" id="username_entry">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Username</property>
<property name="can_focus">True</property>
</widget>
<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>
</packing>
</child>
<child>
<widget class="GtkLabel" id="service_name_label">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Service name</property>
</widget>
<packing>
<property name="x_options">GTK_SHRINK | GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label10">
<widget class="GtkEntry" id="service_name_entry">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Password</property>
<property name="can_focus">True</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_SHRINK | GTK_FILL</property>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
</widget>