[Pommed-commits] r272 - trunk/gpomme
Julien Blache
jblache at alioth.debian.org
Thu Feb 22 23:31:53 CET 2007
Author: jblache
Date: 2007-02-22 23:31:52 +0100 (Thu, 22 Feb 2007)
New Revision: 272
Added:
trunk/gpomme/conffile.c
trunk/gpomme/conffile.h
Modified:
trunk/gpomme/Makefile
trunk/gpomme/gpomme.1
trunk/gpomme/gpomme.c
trunk/gpomme/gpomme.h
Log:
Add conffile code to gpomme.
Removes the -t option, will be handled through the config file instead.
Incomplete code, lacks config file saving and config GUI.
Modified: trunk/gpomme/Makefile
===================================================================
--- trunk/gpomme/Makefile 2007-02-22 20:56:19 UTC (rev 271)
+++ trunk/gpomme/Makefile 2007-02-22 22:31:52 UTC (rev 272)
@@ -12,10 +12,13 @@
AUDIOFILE_CFLAGS = $(shell pkg-config audiofile --cflags)
AUDIOFILE_LIBS = $(shell pkg-config audiofile --libs)
-CFLAGS = -g -O2 -Wall $(ALSA_CFLAGS) $(AUDIOFILE_CFLAGS) $(DBUS_CFLAGS) $(GTK_CFLAGS)
-LDFLAGS = -lpthread $(ALSA_LIBS) $(AUDIOFILE_LIBS) $(DBUS_LIBS) $(GTK_LIBS)
+CONFUSE_CFLAGS = $(shell pkg-config libconfuse --cflags)
+CONFUSE_LIBS = $(shell pkg-config libconfuse --libs)
-SOURCES = gpomme.c theme.c audio.c ../dbus-client/dbus-client.c
+CFLAGS = -g -O2 -Wall $(ALSA_CFLAGS) $(AUDIOFILE_CFLAGS) $(DBUS_CFLAGS) $(GTK_CFLAGS) $(CONFUSE_CFLAGS)
+LDFLAGS = -lpthread $(ALSA_LIBS) $(AUDIOFILE_LIBS) $(DBUS_LIBS) $(GTK_LIBS) $(CONFUSE_LIBS)
+
+SOURCES = gpomme.c theme.c audio.c conffile.c ../dbus-client/dbus-client.c
POFILES = po/fr.po po/de.po po/es.po
OBJS = $(SOURCES:%.c=%.o)
@@ -33,6 +36,8 @@
audio.o: audio.c audio.h gpomme.h
+conffile.o: conffile.c conffile.h gpomme.h theme.h
+
../dbus-client/dbus-client.o: ../dbus-client/dbus-client.c ../dbus-client/dbus-client.h
%.mo: %.po
Added: trunk/gpomme/conffile.c
===================================================================
--- trunk/gpomme/conffile.c 2007-02-22 20:56:19 UTC (rev 271)
+++ trunk/gpomme/conffile.c 2007-02-22 22:31:52 UTC (rev 272)
@@ -0,0 +1,131 @@
+/*
+ * gpomme - GTK application for use with pommed
+ *
+ * $Id$
+ *
+ * Copyright (C) 2007 Julien BLACHE <jb at jblache.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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <confuse.h>
+
+#include "gpomme.h"
+#include "theme.h"
+
+/*
+ * TODO
+ * - print config with cfg_print() (need to create the path if it doesn't exist)
+ * - build config file path
+ */
+
+#define CONFFILE "/dev/null"
+
+static cfg_opt_t cfg_opts[] =
+ {
+ CFG_STR("theme", DEFAULT_THEME, CFGF_NONE),
+ CFG_INT("timeout", 900, CFGF_NONE),
+ CFG_END()
+ };
+
+
+static int
+config_validate_positive_integer(cfg_t *cfg, cfg_opt_t *opt)
+{
+ int value = cfg_opt_getnint(opt, cfg_opt_size(opt) - 1);
+
+ if (value < 0)
+ {
+ cfg_error(cfg, "Error: Value for '%s' must be positive", opt->name);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+config_validate_string(cfg_t *cfg, cfg_opt_t *opt)
+{
+ char *value = cfg_opt_getnstr(opt, cfg_opt_size(opt) - 1);
+
+ if (strlen(value) == 0)
+ {
+ cfg_error(cfg, "Error: Value for '%s' must be a non-zero string", opt->name);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int
+config_load(void)
+{
+ cfg_t *cfg;
+
+ int ret;
+
+ cfg = cfg_init(cfg_opts, CFGF_NONE);
+
+ if (cfg == NULL)
+ {
+ fprintf(stderr, "Failed to initialize configuration parser\n");
+
+ return -1;
+ }
+
+ /* Set up config values validation */
+ cfg_set_validate_func(cfg, "theme", config_validate_string);
+ cfg_set_validate_func(cfg, "timeout", config_validate_positive_integer);
+
+ /*
+ * Do the actual parsing.
+ * If the file does not exist or cannot be opened,
+ * we'll be using the default values defined in the cfg_opt_t array.
+ */
+ ret = cfg_parse(cfg, CONFFILE);
+ if ((ret != CFG_SUCCESS) && (ret != CFG_FILE_ERROR))
+ {
+ cfg_free(cfg);
+
+ fprintf(stderr, "Failed to parse configuration file\n");
+
+ return -1;
+ }
+
+ /* Fill up the structs */
+ mbp_w.timeout = cfg_getint(cfg, "timeout");
+
+ ret = theme_load(cfg_getstr(cfg, "theme"));
+ if (ret < 0)
+ {
+ fprintf(stderr, "Failed to load theme '%s', using '%s' instead\n",
+ cfg_getstr(cfg, "theme"), DEFAULT_THEME);
+
+ ret = theme_load(DEFAULT_THEME);
+ if (ret < 0)
+ {
+ fprintf(stderr, "Failed to load default theme '%s'\n", DEFAULT_THEME);
+
+ return -1;
+ }
+ }
+
+ cfg_free(cfg);
+
+ return 0;
+}
Property changes on: trunk/gpomme/conffile.c
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gpomme/conffile.h
===================================================================
--- trunk/gpomme/conffile.h 2007-02-22 20:56:19 UTC (rev 271)
+++ trunk/gpomme/conffile.h 2007-02-22 22:31:52 UTC (rev 272)
@@ -0,0 +1,11 @@
+/*
+ * $Id$
+ */
+
+#ifndef __CONFFILE_H__
+#define __CONFFILE_H__
+
+int
+config_load(void);
+
+#endif /* !__CONFFILE_H__ */
Property changes on: trunk/gpomme/conffile.h
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/gpomme/gpomme.1
===================================================================
--- trunk/gpomme/gpomme.1 2007-02-22 20:56:19 UTC (rev 271)
+++ trunk/gpomme/gpomme.1 2007-02-22 22:31:52 UTC (rev 272)
@@ -20,12 +20,6 @@
.TP
.B \-v
Print version information.
-.TP
-.BI \-t \ theme_name
-Use
-.I theme_name
-as the icon theme for
-.B gpomme
.SH AUTHOR
.B gpomme
Modified: trunk/gpomme/gpomme.c
===================================================================
--- trunk/gpomme/gpomme.c 2007-02-22 20:56:19 UTC (rev 271)
+++ trunk/gpomme/gpomme.c 2007-02-22 22:31:52 UTC (rev 272)
@@ -38,6 +38,7 @@
#include "gpomme.h"
#include "theme.h"
#include "audio.h"
+#include "conffile.h"
#include "../dbus-client/dbus-client.h"
@@ -45,22 +46,9 @@
#define _(str) gettext(str)
-struct
-{
- GtkWidget *window; /* The window itself */
+struct _mbp_w mbp_w;
- GtkWidget *img_align; /* Image container */
- GtkWidget *image; /* Current image, if any */
- GtkWidget *label; /* Text label */
-
- GtkWidget *pbar_align; /* Progress bar container */
- GtkWidget *pbar; /* Progress bar */
- int pbar_state;
-
- guint timer;
-} mbp_w;
-
struct
{
int muted;
@@ -196,7 +184,7 @@
gtk_widget_show_all(window);
- mbp_w.timer = g_timeout_add(900, hide_window, NULL);
+ mbp_w.timer = g_timeout_add(mbp_w.timeout, hide_window, NULL);
}
@@ -419,12 +407,11 @@
usage(void)
{
printf("gpomme v" M_VERSION " ($Rev$) graphical client for pommed\n");
- printf("Copyright (C) 2006 Julien BLACHE <jb at jblache.org> and others\n");
+ printf("Copyright (C) 2006-2007 Julien BLACHE <jb at jblache.org> and others\n");
printf("Usage:\n");
- printf("\tgpomme\t\t-- start gpomme with the default theme\n");
+ printf("\tgpomme\t\t-- start gpomme\n");
printf("\tgpomme -v\t-- print version and exit\n");
- printf("\tgpomme -t Tango\t-- start gpomme with the Tango theme\n");
}
@@ -437,21 +424,24 @@
{
int c;
int ret;
- char *theme_name;
- theme_name = DEFAULT_THEME;
+ gtk_init(&argc, &argv);
- while ((c = getopt(argc, argv, "t:v")) != -1)
+ ret = config_load();
+ if (ret < 0)
{
+ fprintf(stderr, "Failed to load configuration\n");
+
+ exit(1);
+ }
+
+ while ((c = getopt(argc, argv, "v")) != -1)
+ {
switch (c)
{
- case 't':
- theme_name = optarg;
- break;
-
case 'v':
printf("gpomme v" M_VERSION " ($Rev$) graphical client for pommed\n");
- printf("Copyright (C) 2006 Julien BLACHE <jb at jblache.org> and others\n");
+ printf("Copyright (C) 2006-2007 Julien BLACHE <jb at jblache.org> and others\n");
exit(0);
break;
@@ -476,17 +466,6 @@
if (ret < 0)
printf("Failed to create audio thread\n");
- gtk_init(&argc, &argv);
-
- ret = theme_load(theme_name);
-
- if (ret < 0)
- {
- fprintf(stderr, "Failed to load theme '%s'\n", theme_name);
-
- exit(1);
- }
-
create_window();
g_timeout_add(100, mbp_dbus_listen, NULL);
Modified: trunk/gpomme/gpomme.h
===================================================================
--- trunk/gpomme/gpomme.h 2007-02-22 20:56:19 UTC (rev 271)
+++ trunk/gpomme/gpomme.h 2007-02-22 22:31:52 UTC (rev 272)
@@ -5,8 +5,31 @@
#ifndef __GPOMME_H__
#define __GPOMME_H__
+#include <gtk/gtk.h>
+
#define THEME_BASE "/usr/share/gpomme/themes"
-#define M_VERSION "0.4"
+#define M_VERSION "0.5"
+
+struct _mbp_w
+{
+ GtkWidget *window; /* The window itself */
+
+ GtkWidget *img_align; /* Image container */
+ GtkWidget *image; /* Current image, if any */
+
+ GtkWidget *label; /* Text label */
+
+ GtkWidget *pbar_align; /* Progress bar container */
+ GtkWidget *pbar; /* Progress bar */
+ int pbar_state;
+
+ int timeout;
+ guint timer;
+};
+
+extern struct _mbp_w mbp_w;
+
+
#endif /* !__GPOMME_H__ */
More information about the Pommed-commits
mailing list