[Goodies-commits] r4511 - xfmpc/trunk/src
Mike Massonnet
mmassonnet at xfce.org
Sat Apr 5 13:17:27 CEST 2008
Author: mmassonnet
Date: 2008-04-05 11:17:27 +0000 (Sat, 05 Apr 2008)
New Revision: 4511
Added:
xfmpc/trunk/src/main-ui.xml
Removed:
xfmpc/trunk/src/interface-ui.h
Modified:
xfmpc/trunk/src/Makefile.am
xfmpc/trunk/src/interface-ui.xml
xfmpc/trunk/src/interface.c
xfmpc/trunk/src/interface.h
xfmpc/trunk/src/main.c
Log:
Code moving, throw GtkWindow inside main.c and keep XfmpcInterface simpler
* src/main.c, src/interface.c:
- Move accelerators to main.c
- Move GtkWindow creation to main.c
* src/main.c(main):
- Call gtk_widget_show_all just after a new XfmpcInterface, and later again
for the rest of the ui
Modified: xfmpc/trunk/src/Makefile.am
===================================================================
--- xfmpc/trunk/src/Makefile.am 2008-04-05 11:17:20 UTC (rev 4510)
+++ xfmpc/trunk/src/Makefile.am 2008-04-05 11:17:27 UTC (rev 4511)
@@ -2,6 +2,8 @@
xfmpc_SOURCES = \
main.c \
+ main-ui.h \
+ main-ui.xml \
interface.c \
interface.h \
interface-ui.h \
@@ -36,3 +38,11 @@
-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
-DLOCALEDIR=\"$(localedir)\"
+
+
+main-ui.h: Makefile $(srcdir)/main-ui.xml
+ exo-csource --strip-comments --strip-content --static --name=main_ui $(srcdir)/main-ui.xml > main-ui.h
+
+interface-ui.h: Makefile $(srcdir)/interface-ui.xml
+ exo-csource --strip-comments --strip-content --static --name=xfmpc_interface_ui $(srcdir)/interface-ui.xml > interface-ui.h
+
Deleted: xfmpc/trunk/src/interface-ui.h
Modified: xfmpc/trunk/src/interface-ui.xml
===================================================================
--- xfmpc/trunk/src/interface-ui.xml 2008-04-05 11:17:20 UTC (rev 4510)
+++ xfmpc/trunk/src/interface-ui.xml 2008-04-05 11:17:27 UTC (rev 4511)
@@ -1,11 +1,7 @@
<ui>
-
<accelerator action="previous" />
<accelerator action="pp" />
<accelerator action="stop" />
<accelerator action="next" />
<accelerator action="volume" />
- <accelerator action="quit" />
-
</ui>
-
Modified: xfmpc/trunk/src/interface.c
===================================================================
--- xfmpc/trunk/src/interface.c 2008-04-05 11:17:20 UTC (rev 4510)
+++ xfmpc/trunk/src/interface.c 2008-04-05 11:17:27 UTC (rev 4511)
@@ -25,8 +25,6 @@
#include <libxfce4util/libxfce4util.h>
#include "interface.h"
-#include "interface-ui.h"
-#include "extended-interface.h"
#include "preferences.h"
#include "mpdclient.h"
@@ -46,10 +44,6 @@
static gboolean xfmpc_interface_reconnect (XfmpcInterface *interface);
-static gboolean xfmpc_interface_state_event (XfmpcInterface *interface,
- GdkEventWindowState *event);
-static gboolean xfmpc_interface_closed (XfmpcInterface *interface,
- GdkEvent *event);
static void cb_song_changed (XfmpcInterface *interface);
static void cb_pp_changed (XfmpcInterface *interface,
@@ -76,46 +70,6 @@
-struct _XfmpcInterfaceClass
-{
- GtkWindowClass parent_class;
-};
-
-struct _XfmpcInterface
-{
- GtkWindow parent;
- XfmpcInterfacePrivate *priv;
- GtkWidget *extended_interface;
- XfmpcPreferences *preferences;
- XfmpcMpdclient *mpdclient;
-};
-
-struct _XfmpcInterfacePrivate
-{
- GtkWidget *button_prev;
- GtkWidget *button_pp; /* play/pause */
- GtkWidget *button_next;
- GtkWidget *button_volume;
- GtkWidget *progress_bar; /* position in song */
- GtkWidget *title;
- GtkWidget *subtitle;
- gboolean refresh_title;
-};
-
-
-
-static const GtkActionEntry action_entries[] =
-{
- { "previous", NULL, "", "<control>b", NULL, G_CALLBACK (xfmpc_interface_action_previous), },
- { "pp", NULL, "", "<control>p", NULL, G_CALLBACK (xfmpc_interface_action_pp), },
- { "stop", NULL, "", "<control>s", NULL, G_CALLBACK (xfmpc_interface_action_stop), },
- { "next", NULL, "", "<control>f", NULL, G_CALLBACK (xfmpc_interface_action_next), },
- { "volume", NULL, "", "<control>v", NULL, G_CALLBACK (xfmpc_interface_action_volume), },
- { "quit", NULL, "", "<control>q", NULL, G_CALLBACK (xfmpc_interface_action_close), },
-};
-
-
-
static GObjectClass *parent_class = NULL;
@@ -140,7 +94,7 @@
(GInstanceInitFunc) xfmpc_interface_init,
NULL
};
- xfmpc_interface_type = g_type_register_static (GTK_TYPE_WINDOW, "XfmpcInterface", &xfmpc_interface_info, 0);
+ xfmpc_interface_type = g_type_register_static (GTK_TYPE_VBOX, "XfmpcInterface", &xfmpc_interface_info, 0);
}
return xfmpc_interface_type;
@@ -167,33 +121,10 @@
{
XfmpcInterfacePrivate *priv = XFMPC_INTERFACE_GET_PRIVATE (interface);
+ gtk_container_set_border_width (GTK_CONTAINER (interface), BORDER);
interface->preferences = xfmpc_preferences_get ();
interface->mpdclient = xfmpc_mpdclient_new ();
- /* === Window === */
- gtk_window_set_icon_name (GTK_WINDOW (interface), "stock_volume");
- gtk_window_set_title (GTK_WINDOW (interface), _("Xfmpc"));
- gtk_container_set_border_width (GTK_CONTAINER (interface), BORDER);
- g_signal_connect (G_OBJECT (interface), "delete-event", G_CALLBACK (xfmpc_interface_closed), NULL);
- g_signal_connect (G_OBJECT (interface), "window-state-event", G_CALLBACK (xfmpc_interface_state_event), NULL);
-
- gint posx, posy;
- gint width, height;
- gboolean sticky;
- g_object_get (G_OBJECT (interface->preferences),
- "last-window-posx", &posx,
- "last-window-posy", &posy,
- "last-window-width", &width,
- "last-window-height", &height,
- "last-window-state-sticky", &sticky,
- NULL);
- if (G_LIKELY (posx != -1 && posy != -1))
- gtk_window_move (GTK_WINDOW (interface), posx, posy);
- if (G_LIKELY (width != -1 && height != -1))
- gtk_window_set_default_size (GTK_WINDOW (interface), width, height);
- if (sticky == TRUE)
- gtk_window_stick (GTK_WINDOW (interface));
-
/* === Interface widgets === */
GtkWidget *image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PREVIOUS, GTK_ICON_SIZE_BUTTON);
GtkWidget *control = priv->button_prev = gtk_button_new ();
@@ -223,10 +154,6 @@
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (control), 1.0);
gtk_container_add (GTK_CONTAINER (progress_box), control);
- GtkWidget *separator = gtk_hseparator_new ();
-
- interface->extended_interface = xfmpc_extended_interface_new ();
-
/* Title */
PangoAttrList* attrs = pango_attr_list_new ();
PangoAttribute* attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
@@ -259,11 +186,8 @@
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
/* === Containers === */
- GtkWidget *vbox = gtk_vbox_new (FALSE, BORDER);
- gtk_container_add (GTK_CONTAINER (interface), vbox);
-
GtkWidget *box = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (interface), box, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), priv->button_prev, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), priv->button_pp, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), priv->button_next, FALSE, FALSE, 0);
@@ -271,25 +195,10 @@
gtk_box_pack_start (GTK_BOX (box), priv->button_volume, FALSE, FALSE, 0);
box = gtk_vbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (interface), box, FALSE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (box), priv->title);
gtk_container_add (GTK_CONTAINER (box), priv->subtitle);
- gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
-
- gtk_box_pack_start (GTK_BOX (vbox), interface->extended_interface, TRUE, TRUE, 0);
-
- /* === Accelerators === */
- GtkActionGroup *action_group = gtk_action_group_new ("XfmpcInterface");
- gtk_action_group_add_actions (action_group, action_entries, G_N_ELEMENTS (action_entries), GTK_WINDOW (interface));
-
- GtkUIManager *ui_manager = gtk_ui_manager_new ();
- gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
- gtk_ui_manager_add_ui_from_string (ui_manager, xfmpc_interface_ui, xfmpc_interface_ui_length, NULL);
-
- GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (ui_manager);
- gtk_window_add_accel_group (GTK_WINDOW (interface), accel_group);
-
/* === Signals === */
g_signal_connect_swapped (priv->button_prev, "clicked",
G_CALLBACK (xfmpc_mpdclient_previous), interface->mpdclient);
@@ -337,7 +246,8 @@
GtkWidget*
xfmpc_interface_new ()
{
- return g_object_new (XFMPC_TYPE_INTERFACE, NULL);
+ return g_object_new (XFMPC_TYPE_INTERFACE,
+ "spacing", BORDER, NULL);
}
void
@@ -418,6 +328,14 @@
}
void
+xfmpc_interface_popup_volume (XfmpcInterface *interface)
+{
+ XfmpcInterfacePrivate *priv = XFMPC_INTERFACE_GET_PRIVATE (interface);
+
+ g_signal_emit_by_name (priv->button_volume, "popup", G_TYPE_NONE);
+}
+
+void
xfmpc_interface_set_time (XfmpcInterface *interface,
gint time,
gint time_total)
@@ -478,49 +396,6 @@
return FALSE;
}
-static gboolean
-xfmpc_interface_state_event (XfmpcInterface *interface,
- GdkEventWindowState *event)
-{
- if (G_UNLIKELY (event->type != GDK_WINDOW_STATE))
- return FALSE;
-
- /**
- * Hiding the top level window will unstick it too, and send a
- * window-state-event signal, so here we take the value only if
- * the window is visible
- **/
- if (event->changed_mask & GDK_WINDOW_STATE_STICKY && GTK_WIDGET_VISIBLE (GTK_WIDGET (interface)))
- {
- gboolean sticky = ((gboolean) event->new_window_state & GDK_WINDOW_STATE_STICKY) == FALSE ? FALSE : TRUE;
- g_object_set (G_OBJECT (interface->preferences),
- "last-window-state-sticky", sticky,
- NULL);
- }
-
- return FALSE;
-}
-
-static gboolean
-xfmpc_interface_closed (XfmpcInterface *interface,
- GdkEvent *event)
-{
- gint posx, posy;
- gint width, height;
- gtk_window_get_position (GTK_WINDOW (interface), &posx, &posy);
- gtk_window_get_size (GTK_WINDOW (interface), &width, &height);
-
- g_object_set (G_OBJECT (interface->preferences),
- "last-window-posx", posx,
- "last-window-posy", posy,
- "last-window-width", width,
- "last-window-height", height,
- NULL);
-
- gtk_main_quit ();
- return FALSE;
-}
-
static void
cb_song_changed (XfmpcInterface *interface)
{
@@ -580,49 +455,3 @@
priv->refresh_title = TRUE;
}
-
-
-static void
-xfmpc_interface_action_previous (GtkAction *action,
- XfmpcInterface *interface)
-{
- xfmpc_mpdclient_previous (interface->mpdclient);
-}
-
-static void
-xfmpc_interface_action_pp (GtkAction *action,
- XfmpcInterface *interface)
-{
- xfmpc_interface_pp_clicked (interface);
-}
-
-static void
-xfmpc_interface_action_stop (GtkAction *action,
- XfmpcInterface *interface)
-{
- xfmpc_mpdclient_stop (interface->mpdclient);
-}
-
-static void
-xfmpc_interface_action_next (GtkAction *action,
- XfmpcInterface *interface)
-{
- xfmpc_mpdclient_next (interface->mpdclient);
-}
-
-static void
-xfmpc_interface_action_volume (GtkAction *action,
- XfmpcInterface *interface)
-{
- XfmpcInterfacePrivate *priv = XFMPC_INTERFACE_GET_PRIVATE (interface);
-
- g_signal_emit_by_name (priv->button_volume, "popup", G_TYPE_NONE);
-}
-
-static void
-xfmpc_interface_action_close (GtkAction *action,
- XfmpcInterface *interface)
-{
- xfmpc_interface_closed (interface, NULL);
-}
-
Modified: xfmpc/trunk/src/interface.h
===================================================================
--- xfmpc/trunk/src/interface.h 2008-04-05 11:17:20 UTC (rev 4510)
+++ xfmpc/trunk/src/interface.h 2008-04-05 11:17:27 UTC (rev 4511)
@@ -19,6 +19,9 @@
#ifndef __XFMPC_INTERFACE_H__
#define __XFMPC_INTERFACE_H__
+#include "preferences.h"
+#include "mpdclient.h"
+
G_BEGIN_DECLS
#define XFMPC_TYPE_INTERFACE (xfmpc_interface_get_type())
@@ -35,6 +38,31 @@
typedef struct _XfmpcInterface XfmpcInterface;
typedef struct _XfmpcInterfacePrivate XfmpcInterfacePrivate;
+struct _XfmpcInterfaceClass
+{
+ GtkVBoxClass parent_class;
+};
+
+struct _XfmpcInterface
+{
+ GtkVBox parent;
+ XfmpcInterfacePrivate *priv;
+ XfmpcPreferences *preferences;
+ XfmpcMpdclient *mpdclient;
+};
+
+struct _XfmpcInterfacePrivate
+{
+ GtkWidget *button_prev;
+ GtkWidget *button_pp; /* play/pause */
+ GtkWidget *button_next;
+ GtkWidget *button_volume;
+ GtkWidget *progress_bar; /* position in song */
+ GtkWidget *title;
+ GtkWidget *subtitle;
+ gboolean refresh_title;
+};
+
GType xfmpc_interface_get_type () G_GNUC_CONST;
GtkWidget * xfmpc_interface_new ();
@@ -53,7 +81,7 @@
gdouble value);
void xfmpc_interface_set_volume (XfmpcInterface *interface,
guint8 volume);
-void xfmpc_interface_refresh_volume (XfmpcInterface *interface);
+void xfmpc_interface_popup_volume (XfmpcInterface *interface);
void xfmpc_interface_set_time (XfmpcInterface *interface,
gint time,
Added: xfmpc/trunk/src/main-ui.xml
===================================================================
--- xfmpc/trunk/src/main-ui.xml (rev 0)
+++ xfmpc/trunk/src/main-ui.xml 2008-04-05 11:17:27 UTC (rev 4511)
@@ -0,0 +1,3 @@
+<ui>
+ <accelerator action="quit" />
+</ui>
Modified: xfmpc/trunk/src/main.c
===================================================================
--- xfmpc/trunk/src/main.c 2008-04-05 11:17:20 UTC (rev 4510)
+++ xfmpc/trunk/src/main.c 2008-04-05 11:17:27 UTC (rev 4511)
@@ -32,10 +32,52 @@
#include <libxfcegui4/libxfcegui4.h>
#include <libxfce4util/libxfce4util.h>
+#include "preferences.h"
+#include "mpdclient.h"
+#include "main-ui.h"
#include "interface.h"
+#include "interface-ui.h"
+#include "extended-interface.h"
+#define BORDER 4
+
+static gboolean cb_window_state_event (GtkWidget *window,
+ GdkEventWindowState *event);
+static gboolean cb_window_closed (GtkWidget *window,
+ GdkEvent *event);
+static void action_main_close (GtkAction *action,
+ GtkWidget *window);
+static void action_xfmpc_interface_previous (GtkAction *action,
+ XfmpcInterface *interface);
+static void action_xfmpc_interface_pp (GtkAction *action,
+ XfmpcInterface *interface);
+static void action_xfmpc_interface_stop (GtkAction *action,
+ XfmpcInterface *interface);
+static void action_xfmpc_interface_next (GtkAction *action,
+ XfmpcInterface *interface);
+static void action_xfmpc_interface_volume (GtkAction *action,
+ XfmpcInterface *interface);
+
+
+
+static const GtkActionEntry action_entries_main[] =
+{
+ { "quit", NULL, "", "<control>q", NULL, G_CALLBACK (action_main_close), },
+};
+
+static const GtkActionEntry action_entries_xfmpc_interface[] =
+{
+ { "previous", NULL, "", "<control>b", NULL, G_CALLBACK (action_xfmpc_interface_previous), },
+ { "pp", NULL, "", "<control>p", NULL, G_CALLBACK (action_xfmpc_interface_pp), },
+ { "stop", NULL, "", "<control>s", NULL, G_CALLBACK (action_xfmpc_interface_stop), },
+ { "next", NULL, "", "<control>f", NULL, G_CALLBACK (action_xfmpc_interface_next), },
+ { "volume", NULL, "", "<control>v", NULL, G_CALLBACK (action_xfmpc_interface_volume), },
+};
+
+
+
static void
transform_string_to_int (const GValue *src,
GValue *dst)
@@ -64,12 +106,169 @@
gtk_window_set_default_icon_name ("xfmpc");
+ /* Window */
+ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_icon_name (GTK_WINDOW (window), "stock_volume");
+ gtk_window_set_title (GTK_WINDOW (window), _("Xfmpc"));
+ g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (cb_window_closed), NULL);
+ g_signal_connect (G_OBJECT (window), "window-state-event", G_CALLBACK (cb_window_state_event), NULL);
+
+ GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ /* Read window preferences */
+ gint posx, posy;
+ gint width, height;
+ gboolean sticky;
+
+ XfmpcPreferences *preferences = xfmpc_preferences_get ();
+ g_object_get (G_OBJECT (preferences),
+ "last-window-posx", &posx,
+ "last-window-posy", &posy,
+ "last-window-width", &width,
+ "last-window-height", &height,
+ "last-window-state-sticky", &sticky,
+ NULL);
+ if (G_LIKELY (posx != -1 && posy != -1))
+ gtk_window_move (GTK_WINDOW (window), posx, posy);
+ if (G_LIKELY (width != -1 && height != -1))
+ gtk_window_set_default_size (GTK_WINDOW (window), width, height);
+ if (sticky == TRUE)
+ gtk_window_stick (GTK_WINDOW (window));
+
+ /* Interface */
GtkWidget *interface = xfmpc_interface_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), interface, FALSE, FALSE, BORDER);
- gtk_widget_show_all (interface);
+ /* Separator */
+ GtkWidget *separator = gtk_hseparator_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
+ gtk_widget_show_all (window);
+
+ /* ExtendedInterface */
+ GtkWidget *extended_interface = xfmpc_extended_interface_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), extended_interface, TRUE, TRUE, 0);
+
+ gtk_widget_show_all (window);
+
+ /* Accelerators */
+ GtkUIManager *ui_manager = gtk_ui_manager_new ();
+
+ GtkActionGroup *action_group = gtk_action_group_new ("Main");
+ gtk_action_group_add_actions (action_group, action_entries_main,
+ G_N_ELEMENTS (action_entries_main),
+ GTK_WIDGET (window));
+ gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
+ gtk_ui_manager_add_ui_from_string (ui_manager, main_ui, main_ui_length, NULL);
+
+ action_group = gtk_action_group_new ("XfmpcInterface");
+ gtk_action_group_add_actions (action_group, action_entries_xfmpc_interface,
+ G_N_ELEMENTS (action_entries_xfmpc_interface),
+ XFMPC_INTERFACE (interface));
+ gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
+ gtk_ui_manager_add_ui_from_string (ui_manager, xfmpc_interface_ui, xfmpc_interface_ui_length, NULL);
+
+ GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (ui_manager);
+ gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
+
+ /* Start teh app */
+ g_object_unref (preferences);
gtk_main ();
return 0;
}
+
+
+static gboolean
+cb_window_state_event (GtkWidget *window,
+ GdkEventWindowState *event)
+{
+ if (G_UNLIKELY (event->type != GDK_WINDOW_STATE))
+ return FALSE;
+
+ /**
+ * Hiding the top level window will unstick it too, and send a
+ * window-state-event signal, so here we take the value only if
+ * the window is visible
+ **/
+ if (event->changed_mask & GDK_WINDOW_STATE_STICKY && GTK_WIDGET_VISIBLE (window))
+ {
+ gboolean sticky = ((gboolean) event->new_window_state & GDK_WINDOW_STATE_STICKY) == FALSE ? FALSE : TRUE;
+ XfmpcPreferences *preferences = xfmpc_preferences_get ();
+ g_object_set (G_OBJECT (preferences),
+ "last-window-state-sticky", sticky,
+ NULL);
+ g_object_unref (preferences);
+ }
+
+ return FALSE;
+}
+
+static gboolean
+cb_window_closed (GtkWidget *window,
+ GdkEvent *event)
+{
+ gint posx, posy;
+ gint width, height;
+ gtk_window_get_position (GTK_WINDOW (window), &posx, &posy);
+ gtk_window_get_size (GTK_WINDOW (window), &width, &height);
+
+ XfmpcPreferences *preferences = xfmpc_preferences_get ();
+ g_object_set (G_OBJECT (preferences),
+ "last-window-posx", posx,
+ "last-window-posy", posy,
+ "last-window-width", width,
+ "last-window-height", height,
+ NULL);
+ g_object_unref (preferences);
+
+ gtk_main_quit ();
+ return FALSE;
+}
+
+
+
+static void
+action_main_close (GtkAction *action,
+ GtkWidget *window)
+{
+ cb_window_closed (window, NULL);
+}
+
+static void
+action_xfmpc_interface_previous (GtkAction *action,
+ XfmpcInterface *interface)
+{
+ xfmpc_mpdclient_previous (interface->mpdclient);
+}
+
+static void
+action_xfmpc_interface_pp (GtkAction *action,
+ XfmpcInterface *interface)
+{
+ xfmpc_interface_pp_clicked (interface);
+}
+
+static void
+action_xfmpc_interface_stop (GtkAction *action,
+ XfmpcInterface *interface)
+{
+ xfmpc_mpdclient_stop (interface->mpdclient);
+}
+
+static void
+action_xfmpc_interface_next (GtkAction *action,
+ XfmpcInterface *interface)
+{
+ xfmpc_mpdclient_next (interface->mpdclient);
+}
+
+static void
+action_xfmpc_interface_volume (GtkAction *action,
+ XfmpcInterface *interface)
+{
+ xfmpc_interface_popup_volume (interface);
+}
+
More information about the Goodies-commits
mailing list