[gnome-terminal] Add TerminalInfoBar



commit 00806b85b98fd3b77d05b1800a983c34d4166ab1
Author: Christian Persch <chpe gnome org>
Date:   Sun Feb 21 21:11:39 2010 +0100

    Add TerminalInfoBar

 configure.ac            |    3 +
 src/Makefile.am         |    7 +++
 src/terminal-info-bar.c |  119 +++++++++++++++++++++++++++++++++++++++++++++++
 src/terminal-info-bar.h |   62 ++++++++++++++++++++++++
 4 files changed, 191 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9d2745c..a391515 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,9 @@ PKG_CHECK_MODULES([TERM],
    dbus-glib-1 >= $DBUS_GLIB_REQUIRED
    $PLATFORM_DEPS])
 
+PKG_CHECK_EXISTS([gtk+-2.0 >= 2.18.0],[have_gtk_2_18=yes],[have_gtk_2_18=no])
+AM_CONDITIONAL([HAVE_GTK_2_18],[test "$have_gtk_2_18" = "yes"])
+
 # Check the smclient backend
 SMCLIENT_PKGS=
 AC_MSG_CHECKING([which smclient backend to use])
diff --git a/src/Makefile.am b/src/Makefile.am
index f0277e0..d712674 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -49,6 +49,13 @@ gnome_terminal_SOURCES= \
 	terminal-window.h \
 	$(NULL)
 
+if HAVE_GTK_2_18
+gnome_terminal_SOURCES += \
+	terminal-info-bar.c \
+	terminal-info-bar.h \
+	$(NULL)
+endif
+
 nodist_gnome_terminal_SOURCES= $(BUILT_SOURCES)
 
 gnome_terminal_CPPFLAGS = \
diff --git a/src/terminal-info-bar.c b/src/terminal-info-bar.c
new file mode 100644
index 0000000..cafd12c
--- /dev/null
+++ b/src/terminal-info-bar.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright © 2010 Christian Persch
+ *
+ *  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, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope info_bar 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include "terminal-info-bar.h"
+
+#include <gtk/gtk.h>
+
+#define TERMINAL_INFO_BAR_GET_PRIVATE(info_bar)(G_TYPE_INSTANCE_GET_PRIVATE ((info_bar), TERMINAL_TYPE_INFO_BAR, TerminalInfoBarPrivate))
+
+struct _TerminalInfoBarPrivate
+{
+  GtkWidget *content_box;
+};
+
+G_DEFINE_TYPE (TerminalInfoBar, terminal_info_bar, GTK_TYPE_INFO_BAR)
+
+/* helper functions */
+
+static void
+terminal_info_bar_init (TerminalInfoBar *bar)
+{
+  GtkInfoBar *info_bar = GTK_INFO_BAR (bar);
+  TerminalInfoBarPrivate *priv;
+
+  priv = bar->priv = TERMINAL_INFO_BAR_GET_PRIVATE (bar);
+
+  priv->content_box = gtk_vbox_new (FALSE, 6);
+  gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (info_bar)),
+                      priv->content_box, TRUE, TRUE, 0);
+}
+
+static void
+terminal_info_bar_class_init (TerminalInfoBarClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (gobject_class, sizeof (TerminalInfoBarPrivate));
+}
+
+/* public API */
+
+/**
+ * terminal_info_bar_new:
+ * @type: a #GtkMessageType
+ *
+ * Returns: a new #TerminalInfoBar for @screen
+ */
+GtkWidget *
+terminal_info_bar_new (GtkMessageType type,
+                       const char *first_button_text,
+                       ...)
+{
+  GtkWidget *info_bar;
+  va_list args;
+
+  info_bar = g_object_new (TERMINAL_TYPE_INFO_BAR,
+                           "message-type", type,
+                           NULL);
+
+  va_start (args, first_button_text);
+  while (first_button_text != NULL) {
+    int response_id;
+
+    response_id = va_arg (args, int);
+    gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
+                             first_button_text, response_id);
+
+    first_button_text = va_arg (args, const char *);
+  }
+  va_end (args);
+
+  return info_bar;
+}
+
+void
+terminal_info_bar_format_text (TerminalInfoBar *bar,
+                               const char *format,
+                               ...)
+{
+  TerminalInfoBarPrivate *priv;
+  char *text;
+  GtkWidget *label;
+  va_list args;
+
+  g_return_if_fail (TERMINAL_IS_INFO_BAR (bar));
+
+  priv = bar->priv;
+
+  va_start (args, format);
+  text = g_strdup_vprintf (format, args);
+  va_end (args);
+
+  label = gtk_label_new (text);
+  g_free (text);
+  
+  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+  gtk_label_set_selectable (GTK_LABEL (label), TRUE);
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
+
+  gtk_box_pack_start (GTK_BOX (priv->content_box), label, FALSE, FALSE, 0);
+  gtk_widget_show_all (priv->content_box);
+}
diff --git a/src/terminal-info-bar.h b/src/terminal-info-bar.h
new file mode 100644
index 0000000..70083b7
--- /dev/null
+++ b/src/terminal-info-bar.h
@@ -0,0 +1,62 @@
+/*
+ *  Copyright © 2010 Christian Persch
+ *
+ *  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, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope info_bar 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef TERMINAL_INFO_BAR_H
+#define TERMINAL_INFO_BAR_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define TERMINAL_TYPE_INFO_BAR         (terminal_info_bar_get_type ())
+#define TERMINAL_INFO_BAR(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TERMINAL_TYPE_INFO_BAR, TerminalInfoBar))
+#define TERMINAL_INFO_BAR_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), TERMINAL_TYPE_INFO_BAR, TerminalInfoBarClass))
+#define TERMINAL_IS_INFO_BAR(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TERMINAL_TYPE_INFO_BAR))
+#define TERMINAL_IS_INFO_BAR_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), TERMINAL_TYPE_INFO_BAR))
+#define TERMINAL_INFO_BAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TERMINAL_TYPE_INFO_BAR, TerminalInfoBarClass))
+
+typedef struct _TerminalInfoBar        TerminalInfoBar;
+typedef struct _TerminalInfoBarClass   TerminalInfoBarClass;
+typedef struct _TerminalInfoBarPrivate TerminalInfoBarPrivate;
+
+struct _TerminalInfoBar
+{
+  GtkInfoBar parent_instance;
+
+  /*< private >*/
+  TerminalInfoBarPrivate *priv;
+};
+
+struct _TerminalInfoBarClass
+{
+  GtkInfoBarClass parent_class;
+};
+
+GType terminal_info_bar_get_type (void);
+
+GtkWidget *terminal_info_bar_new (GtkMessageType type,
+                                  const char *first_button_text,
+                                  ...) G_GNUC_NULL_TERMINATED;
+
+void terminal_info_bar_format_text (TerminalInfoBar *bar,
+                                    const char *format,
+                                    ...) G_GNUC_PRINTF (2, 3);
+
+G_END_DECLS
+
+#endif /* !TERMINAL_INFO_BAR_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]