[beast/devel: 31/35] BST: bstsplash: eliminate printf-variants
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast/devel: 31/35] BST: bstsplash: eliminate printf-variants
- Date: Tue, 14 May 2013 19:40:31 +0000 (UTC)
commit e19056ddb7f887c7bcaf36e93694bb25354d3b57
Author: Tim Janik <timj gnu org>
Date: Tue May 14 20:59:59 2013 +0200
BST: bstsplash: eliminate printf-variants
beast-gtk/bstmain.cc | 12 +++++-----
beast-gtk/bstsplash.cc | 58 ++++++++++++++---------------------------------
beast-gtk/bstsplash.hh | 12 ++-------
3 files changed, 26 insertions(+), 56 deletions(-)
---
diff --git a/beast-gtk/bstmain.cc b/beast-gtk/bstmain.cc
index 1ab6716..d8530c6 100644
--- a/beast-gtk/bstmain.cc
+++ b/beast-gtk/bstmain.cc
@@ -54,7 +54,7 @@ server_registration (SfiProxy server,
else
{
const char *base = strrchr (what, '/');
- bst_splash_update_item ((GtkWidget*) data, "%s", base ? base + 1 : what);
+ bst_splash_update_item ((GtkWidget*) data, base ? base + 1 : what);
if (error && error[0])
g_message ("failed to register \"%s\": %s", what, error);
}
@@ -101,10 +101,10 @@ main (int argc,
bst_splash_set_title (beast_splash, _("BEAST Startup"));
gtk_object_set_user_data (GTK_OBJECT (beast_splash), NULL); /* fix for broken user_data in 2.2 */
bst_splash_set_text (beast_splash,
- "<b><big>BEAST</big></b>\n"
- "<b>The Better Audio System</b>\n"
- "<b>Version %s (%s)</b>\n",
- BST_VERSION, BST_VERSION_HINT);
+ Rapicorn::string_format ("<b><big>BEAST</big></b>\n"
+ "<b>The Better Audio System</b>\n"
+ "<b>Version %s (%s)</b>\n",
+ BST_VERSION, BST_VERSION_HINT));
bst_splash_update_entity (beast_splash, _("Startup"));
bst_splash_show_grab (beast_splash);
@@ -850,7 +850,7 @@ beast_show_about_box (void)
if (!GTK_WIDGET_VISIBLE (beast_splash))
{
bst_splash_set_title (beast_splash, _("BEAST About"));
- bst_splash_update_entity (beast_splash, _("BEAST Version %s"), BST_VERSION);
+ bst_splash_update_entity (beast_splash, Rapicorn::string_format (_("BEAST Version %s"), BST_VERSION));
bst_splash_update_item (beast_splash, _("Contributions made by:"));
bst_splash_animate_strings (beast_splash, contributors);
}
diff --git a/beast-gtk/bstsplash.cc b/beast-gtk/bstsplash.cc
index cd897d1..9ba3b5f 100644
--- a/beast-gtk/bstsplash.cc
+++ b/beast-gtk/bstsplash.cc
@@ -5,6 +5,9 @@
#include <string.h>
+#define SPLASH_REFRESH_TIMEOUT (0 * 1000 * 250) // just for debugging
+
+
/* --- prototypes --- */
static void bst_splash_class_init (BstSplashClass *klass);
static void bst_splash_init (BstSplash *splash);
@@ -271,44 +274,25 @@ bst_splash_release_grab (GtkWidget *widget)
}
void
-bst_splash_update_entity (GtkWidget *widget,
- const gchar *format,
- ...)
+bst_splash_update_entity (GtkWidget *widget, const std::string &message)
{
- BstSplash *self;
- va_list args;
- gchar *text;
-
g_return_if_fail (BST_IS_SPLASH (widget));
- self = BST_SPLASH (widget);
- va_start (args, format);
- text = g_strdup_vprintf (format, args);
- va_end (args);
+ BstSplash *self = BST_SPLASH (widget);
- gtk_label_set_text (GTK_LABEL (self->entity), text);
+ gtk_label_set_text (GTK_LABEL (self->entity), message.c_str());
gtk_label_set_text (GTK_LABEL (self->item), NULL);
- g_free (text);
+ g_usleep (SPLASH_REFRESH_TIMEOUT);
}
void
-bst_splash_update_item (GtkWidget *widget,
- const gchar *format,
- ...)
+bst_splash_update_item (GtkWidget *widget, const std::string &message)
{
- BstSplash *self;
- va_list args;
- gchar *text;
-
g_return_if_fail (BST_IS_SPLASH (widget));
- self = BST_SPLASH (widget);
- va_start (args, format);
- text = g_strdup_vprintf (format, args);
- va_end (args);
+ BstSplash *self = BST_SPLASH (widget);
- gtk_label_set_text (GTK_LABEL (self->item), text);
- g_free (text);
+ gtk_label_set_text (GTK_LABEL (self->item), message.c_str());
if (GTK_WIDGET_VISIBLE (self))
{
@@ -316,8 +300,7 @@ bst_splash_update_item (GtkWidget *widget,
frac /= self->max_items;
gtk_progress_bar_set_fraction (self->pbar, MIN (frac, 1.0));
bst_splash_update ();
- if (0)
- g_usleep (1000 * 250);
+ g_usleep (SPLASH_REFRESH_TIMEOUT);
}
}
@@ -331,29 +314,22 @@ bst_splash_update (void)
}
void
-bst_splash_set_text (GtkWidget *widget,
- const gchar *format,
- ...)
+bst_splash_set_text (GtkWidget *widget, const std::string &message)
{
BstSplash *self;
- va_list args;
- gchar *text;
g_return_if_fail (BST_IS_SPLASH (widget));
- va_start (args, format);
- text = g_strdup_vprintf (format, args);
- va_end (args);
-
self = BST_SPLASH (widget);
gtk_container_foreach (GTK_CONTAINER (self->splash_box), (GtkCallback) gtk_widget_destroy, NULL);
- if (text)
+ if (!message.empty())
{
- gchar *str = text;
+ std::string text = message;
+ char *str = &text[0];
while (str)
{
GtkWidget *label;
- gchar *p = strchr (str, '\n');
+ char *p = strchr (str, '\n');
if (p)
*p++ = 0;
label = (GtkWidget*) g_object_new (GTK_TYPE_LABEL,
@@ -365,9 +341,9 @@ bst_splash_set_text (GtkWidget *widget,
str = p;
}
}
- g_free (text);
if (GTK_WIDGET_VISIBLE (self))
bst_splash_update ();
+ g_usleep (SPLASH_REFRESH_TIMEOUT);
}
void
diff --git a/beast-gtk/bstsplash.hh b/beast-gtk/bstsplash.hh
index d670956..59524c8 100644
--- a/beast-gtk/bstsplash.hh
+++ b/beast-gtk/bstsplash.hh
@@ -57,18 +57,12 @@ void bst_splash_set_title (GtkWidget *widget,
const gchar *title);
void bst_splash_show_grab (GtkWidget *widget);
void bst_splash_release_grab (GtkWidget *widget);
-void bst_splash_set_text (GtkWidget *widget,
- const gchar *format,
- ...) G_GNUC_PRINTF (2, 3);
+void bst_splash_set_text (GtkWidget *widget, const std::string &message);
void bst_splash_set_animation (GtkWidget *widget,
GdkPixbufAnimation *anim);
void bst_splash_update (void);
-void bst_splash_update_entity (GtkWidget *widget,
- const gchar *format,
- ...) G_GNUC_PRINTF (2, 3);
-void bst_splash_update_item (GtkWidget *widget,
- const gchar *format,
- ...) G_GNUC_PRINTF (2, 3);
+void bst_splash_update_entity (GtkWidget *widget, const std::string &message);
+void bst_splash_update_item (GtkWidget *widget, const std::string &message);
void bst_splash_animate_strings (GtkWidget *splash,
const gchar **strings);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]