Пример #1
0
static void
stderr_message_internal(const char *title, enum ShowAgainStyle showAgain,
			const char *fmt, va_list *args,  va_list *args2)
{
  static gchar *buf = NULL;
  static gint   alloc = 0;
  gint len;

  len = format_string_length_upper_bound (fmt, args);

  if (len >= alloc) {
    if (buf)
      g_free (buf);
    
    alloc = nearest_pow (MAX(len + 1, 1024));
    
    buf = g_new (char, alloc);
  }
  
  vsprintf (buf, fmt, *args2);
  
  fprintf(stderr,
          "%s: %s\n", 
          title,buf);
}
Пример #2
0
static void
gtk_message_internal(const char* title, enum ShowAgainStyle showAgain,
		     char const *fmt,
                     va_list args, va_list args2)
{
  static gchar *buf = NULL;
  static gint   alloc = 0;
  gint len;
  DiaMessageInfo *msginfo;
  GtkTextBuffer *textbuffer;
  gboolean askForShowAgain = FALSE;

  if (showAgain != ALWAYS_SHOW) {
    /* We persistently stored that the user has chosen to not see the
     * dialog again (whether by checking or not unchecking the box) */
    persistence_register_boolean((gchar *)title, FALSE);
    if (persistence_get_boolean((gchar *)title)) {
      /* If not showing again, just return at once */
      return;
    }
    askForShowAgain = TRUE;    
  }

  if (message_hash_table == NULL) {
    message_hash_table = g_hash_table_new(g_str_hash, g_str_equal);
  }

  len = g_printf_string_upper_bound (fmt, args);
  if (len >= alloc) {
    if (buf)
      g_free (buf);
    
    alloc = nearest_pow (MAX(len + 1, 1024));
    
    buf = g_new (char, alloc);
  }
  
  vsprintf (buf, fmt, args2);

  msginfo = (DiaMessageInfo*)g_hash_table_lookup(message_hash_table, fmt);
  if (msginfo == NULL) {
    msginfo = g_new0(DiaMessageInfo, 1);
    g_hash_table_insert(message_hash_table, (char *)fmt, msginfo);
  }
  if (msginfo->dialog == NULL)
    message_create_dialog(title, msginfo, buf);

  if (msginfo->repeats != NULL) {
    if (g_list_length(msginfo->repeats) > 1) {
      char *newlabel;
      guint num = g_list_length(msginfo->repeats);
      /* See: https://live.gnome.org/TranslationProject/DevGuidelines/Plurals */
      newlabel = g_strdup_printf(g_dngettext (GETTEXT_PACKAGE,
					"There is %d similar message.", /* not triggered */
					"There are %d similar messages.", num), num);
      gtk_label_set_text(GTK_LABEL(msginfo->repeat_label), newlabel);
    }
    /* for repeated messages, show the last one */
    g_object_set (msginfo->dialog, "text", buf, NULL);

    gtk_widget_show(msginfo->repeat_label);
    gtk_widget_show(msginfo->show_repeats);
  }

  /* Insert in scrollable view, but only the repeated ones */
  if (msginfo->repeats != NULL) {
    textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(msginfo->repeat_view));
    gtk_text_buffer_insert_at_cursor(textbuffer, buf, -1);
  }

  msginfo->repeats = g_list_prepend(msginfo->repeats, g_strdup(buf));

  if (askForShowAgain) {
    gtk_widget_show(msginfo->no_show_again);
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(msginfo->no_show_again),
				 showAgain == SUGGEST_NO_SHOW_AGAIN);
  } else {
    gtk_widget_hide(msginfo->no_show_again);
  }

  gtk_widget_show (msginfo->dialog);
}