[Goodies-commits] r7602 - in xfmpc/trunk: . src

Vincent Legout vincent at xfce.org
Wed Jun 17 22:42:52 CEST 2009


Author: vincent
Date: 2009-06-17 20:42:52 +0000 (Wed, 17 Jun 2009)
New Revision: 7602

Added:
   xfmpc/trunk/src/main.vala
Modified:
   xfmpc/trunk/ChangeLog
   xfmpc/trunk/src/Makefile.am
   xfmpc/trunk/src/main.c
   xfmpc/trunk/src/preferences.c
   xfmpc/trunk/src/xfmpc.h
Log:
Rewrite main.c in vala


Modified: xfmpc/trunk/ChangeLog
===================================================================
--- xfmpc/trunk/ChangeLog	2009-06-17 18:14:47 UTC (rev 7601)
+++ xfmpc/trunk/ChangeLog	2009-06-17 20:42:52 UTC (rev 7602)
@@ -1,3 +1,7 @@
+2009-06-17	Vincent Legout <vincent at legout.info>
+
+Rewrite main.c in vala
+
 2009-06-16 	Vincent Legout <vincent at legout.info>
 
 Rewrite preferences.c in vala

Modified: xfmpc/trunk/src/Makefile.am
===================================================================
--- xfmpc/trunk/src/Makefile.am	2009-06-17 18:14:47 UTC (rev 7601)
+++ xfmpc/trunk/src/Makefile.am	2009-06-17 20:42:52 UTC (rev 7602)
@@ -11,7 +11,8 @@
 	interface.vala							\
 	main-window.vala						\
 	playlist.vala							\
-	preferences.vala
+	preferences.vala						\
+	main.vala
 
 vala_built_SOURCES =							\
 	$(xfmpc_VALASOURCES:.vala=.c)
@@ -24,8 +25,6 @@
 endif
 
 xfmpc_SOURCES = 							\
-	main.c								\
-	main-ui.h							\
 	mpdclient.c							\
 	mpdclient.h							\
 	xfce-arrow-button.c						\

Modified: xfmpc/trunk/src/main.c
===================================================================
--- xfmpc/trunk/src/main.c	2009-06-17 18:14:47 UTC (rev 7601)
+++ xfmpc/trunk/src/main.c	2009-06-17 20:42:52 UTC (rev 7602)
@@ -1,5 +1,6 @@
 /*
- *  Copyright (c) 2008-2009 Mike Massonnet <mmassonnet at xfce.org>
+ *  Copyright (c) 2009 Mike Massonnet <mmassonnet at xfce.org>
+ *  Copyright (c) 2009 Vincent Legout <vincent at xfce.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -16,76 +17,103 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-#ifdef HAVE_CONFIG_H
+#include <glib.h>
+#include <glib-object.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libxfce4util/libxfce4util.h>
 #include <config.h>
-#endif
+#include <gtk/gtk.h>
 
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
 
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
+#define XFMPC_PREFERENCES_TYPE_SONG_FORMAT (xfmpc_preferences_song_format_get_type ())
 
-#include <gtk/gtk.h>
-#include <libxfcegui4/libxfcegui4.h>
+#define XFMPC_TYPE_MAIN_WINDOW (xfmpc_main_window_get_type ())
+#define XFMPC_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFMPC_TYPE_MAIN_WINDOW, XfmpcMainWindow))
+#define XFMPC_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFMPC_TYPE_MAIN_WINDOW, XfmpcMainWindowClass))
+#define XFMPC_IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFMPC_TYPE_MAIN_WINDOW))
+#define XFMPC_IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFMPC_TYPE_MAIN_WINDOW))
+#define XFMPC_MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFMPC_TYPE_MAIN_WINDOW, XfmpcMainWindowClass))
 
-#include "xfmpc.h"
+typedef struct _XfmpcMainWindow XfmpcMainWindow;
+typedef struct _XfmpcMainWindowClass XfmpcMainWindowClass;
 
+typedef enum  {
+	XFMPC_PREFERENCES_SONG_FORMAT_TITLE,
+	XFMPC_PREFERENCES_SONG_FORMAT_ALBUM_TITLE,
+	XFMPC_PREFERENCES_SONG_FORMAT_ARTIST_TITLE,
+	XFMPC_PREFERENCES_SONG_FORMAT_ARTIST_TITLE_DATE,
+	XFMPC_PREFERENCES_SONG_FORMAT_ARTIST_ALBUM_TITLE,
+	XFMPC_PREFERENCES_SONG_FORMAT_ARTIST_ALBUM_TRACK_TITLE,
+	XFMPC_PREFERENCES_SONG_FORMAT_CUSTOM_FORMAT
+} XfmpcPreferencesSongFormat;
 
-static void
-transform_string_to_int (const GValue *src,
-                         GValue *dst)
-{
-  g_value_set_int (dst, (gint) strtol (g_value_get_string (src), NULL, 10));
-}
 
-static void
-transform_string_to_boolean (const GValue *src,
-                             GValue *dst)
-{
-  g_value_set_boolean (dst, (gboolean) strcmp (g_value_get_string (src), "FALSE") != 0);
-}
 
-static void
-transform_string_to_enum (const GValue *src,
-                          GValue *dst)
-{
-  GEnumClass *klass;
-  gint        value = 0;
-  guint       n;
+void xfmpc_transform_string_to_int (const GValue* src, GValue* dst);
+void xfmpc_transform_string_to_boolean (const GValue* src, GValue* dst);
+void xfmpc_transform_string_to_enum (const GValue* src, GValue* dst);
+GType xfmpc_preferences_song_format_get_type (void);
+XfmpcMainWindow* xfmpc_main_window_new (void);
+XfmpcMainWindow* xfmpc_main_window_construct (GType object_type);
+GType xfmpc_main_window_get_type (void);
+gint xfmpc_main (char** args, int args_length1);
 
-  klass = g_type_class_ref (G_VALUE_TYPE (dst));
-  for (n = 0; n < klass->n_values; ++n)
-    {
-      value = klass->values[n].value;
-      if (!g_ascii_strcasecmp (klass->values[n].value_name, g_value_get_string (src)))
-        break;
-    }
-  g_type_class_unref (klass);
 
-  g_value_set_enum (dst, value);
+
+void xfmpc_transform_string_to_int (const GValue* src, GValue* dst) {
+	g_value_set_int (&(*dst), (gint) strtoul (g_value_get_string (&(*src)), NULL, 0));
 }
 
 
+void xfmpc_transform_string_to_boolean (const GValue* src, GValue* dst) {
+	g_value_set_boolean (&(*dst), g_utf8_collate (g_value_get_string (&(*src)), "FALSE") != 0);
+}
 
-int
-main (int argc, char *argv[])
-{
-  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
-  gtk_init (&argc, &argv);
+void xfmpc_transform_string_to_enum (const GValue* src, GValue* dst) {
+	GEnumClass* klass;
+	gint i;
+	GEnumValue* enum_value;
+	klass = (GEnumClass*) g_type_class_ref (G_VALUE_TYPE (&(*dst)));
+	i = 0;
+	enum_value = NULL;
+	while ((enum_value = g_enum_get_value (klass, i)) != NULL) {
+		char* _tmp1_;
+		char* _tmp0_;
+		gboolean _tmp2_;
+		_tmp1_ = NULL;
+		_tmp0_ = NULL;
+		if ((_tmp2_ = strcmp (_tmp0_ = g_utf8_casefold (enum_value->value_name, -1), _tmp1_ = g_utf8_casefold (g_value_get_string (&(*src)), -1)) == 0, _tmp1_ = (g_free (_tmp1_), NULL), _tmp0_ = (g_free (_tmp0_), NULL), _tmp2_)) {
+			break;
+		}
+		i++;
+	}
+	g_value_set_enum (&(*dst), enum_value->value);
+	(klass == NULL) ? NULL : (klass = (g_type_class_unref (klass), NULL));
+}
 
-  g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, transform_string_to_int);
-  g_value_register_transform_func (G_TYPE_STRING, G_TYPE_BOOLEAN, transform_string_to_boolean);
-  g_value_register_transform_func (G_TYPE_STRING, G_TYPE_ENUM, transform_string_to_enum);
 
-  GtkWidget *window = (GtkWidget *)xfmpc_main_window_new ();
-  gtk_widget_show_all (window);
+gint xfmpc_main (char** args, int args_length1) {
+	XfmpcMainWindow* window;
+	gint _tmp0_;
+	xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+	gtk_init (&args_length1, &args);
+	g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, (GValueTransform) xfmpc_transform_string_to_int);
+	g_value_register_transform_func (G_TYPE_STRING, G_TYPE_BOOLEAN, (GValueTransform) xfmpc_transform_string_to_boolean);
+	g_value_register_transform_func (G_TYPE_STRING, XFMPC_PREFERENCES_TYPE_SONG_FORMAT, (GValueTransform) xfmpc_transform_string_to_enum);
+	window = g_object_ref_sink (xfmpc_main_window_new ());
+	gtk_widget_show_all ((GtkWidget*) window);
+	gtk_main ();
+	return (_tmp0_ = 0, (window == NULL) ? NULL : (window = (g_object_unref (window), NULL)), _tmp0_);
+}
 
-  gtk_main ();
 
-  return 0;
+int main (int argc, char ** argv) {
+	g_type_init ();
+	return xfmpc_main (argv, argc);
 }
 
+
+
+

Added: xfmpc/trunk/src/main.vala
===================================================================
--- xfmpc/trunk/src/main.vala	                        (rev 0)
+++ xfmpc/trunk/src/main.vala	2009-06-17 20:42:52 UTC (rev 7602)
@@ -0,0 +1,71 @@
+/*
+ *  Copyright (c) 2009 Mike Massonnet <mmassonnet at xfce.org>
+ *  Copyright (c) 2009 Vincent Legout <vincent at xfce.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+using Gtk;
+
+namespace Xfmpc {
+
+	static void transform_string_to_int (GLib.Value src, out GLib.Value dst) {
+		dst.set_int ((int) (src.get_string ()).to_ulong ());
+	}
+
+	static void transform_string_to_boolean (GLib.Value src, out GLib.Value dst) {
+		dst.set_boolean ((src.get_string ()).collate ("FALSE") != 0);
+	}
+
+	static void transform_string_to_enum (GLib.Value src, out GLib.Value dst) {
+		GLib.EnumClass klass = (GLib.EnumClass) (dst.type ()).class_ref ();
+		int i = 0;
+		unowned EnumValue enum_value;
+
+		while ((enum_value = klass.get_value (i)) != null)
+		{
+			if (GLib.strcmp ((enum_value.value_name).casefold (), (src.get_string ()).casefold ()) == 0)
+				break;
+			i ++;
+		}
+
+		dst.set_enum (enum_value.value);
+  	}
+
+	public static int main (string[] args) {
+		Xfce.textdomain (Config.GETTEXT_PACKAGE, Config.PACKAGE_LOCALE_DIR, "UTF-8");
+
+		Gtk.init (ref args);
+
+  		GLib.Value.register_transform_func (typeof (string),
+						    typeof (int),
+						    (GLib.ValueTransform) transform_string_to_int);
+  		GLib.Value.register_transform_func (typeof (string),
+						    typeof (bool),
+						    (GLib.ValueTransform) transform_string_to_boolean);
+  		GLib.Value.register_transform_func (typeof (string),
+						    typeof (Xfmpc.Preferences.SongFormat),
+						    (GLib.ValueTransform) transform_string_to_enum);
+
+		Xfmpc.MainWindow window = new Xfmpc.MainWindow ();
+		window.show_all ();
+
+		Gtk.main ();
+
+		return 0;
+	}
+}
+
+/* vi:set ts=8 sw=8: */

Modified: xfmpc/trunk/src/preferences.c
===================================================================
--- xfmpc/trunk/src/preferences.c	2009-06-17 18:14:47 UTC (rev 7601)
+++ xfmpc/trunk/src/preferences.c	2009-06-17 20:42:52 UTC (rev 7602)
@@ -256,7 +256,7 @@
 	g_return_if_fail (self != NULL);
 	rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4/xfmpcrc", FALSE);
 	if (rc == NULL) {
-		g_warning ("preferences.vala:171: Failed to save the preferences");
+		g_warning ("preferences.vala:170: Failed to save the preferences");
 		(rc == NULL) ? NULL : (rc = (xfce_rc_close (rc), NULL));
 		return;
 	}

Modified: xfmpc/trunk/src/xfmpc.h
===================================================================
--- xfmpc/trunk/src/xfmpc.h	2009-06-17 18:14:47 UTC (rev 7601)
+++ xfmpc/trunk/src/xfmpc.h	2009-06-17 20:42:52 UTC (rev 7602)
@@ -293,6 +293,7 @@
 void xfmpc_preferences_set_song_format (XfmpcPreferences* self, XfmpcPreferencesSongFormat value);
 const char* xfmpc_preferences_get_song_format_custom (XfmpcPreferences* self);
 void xfmpc_preferences_set_song_format_custom (XfmpcPreferences* self, const char* value);
+gint xfmpc_main (char** args, int args_length1);
 
 
 G_END_DECLS




More information about the Goodies-commits mailing list