aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-24 09:48:32 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-24 09:48:32 +0000
commit1c1bda20ea6669dc22cbbd48a68309d7366b5502 (patch)
tree109fad4d788716cb0165ccce2a7a140aa0ae7587
parente8e00d80489ea73dbba740b5fd4972fddd2dd7f3 (diff)
downloadpaludis-1c1bda20ea6669dc22cbbd48a68309d7366b5502.tar.gz
paludis-1c1bda20ea6669dc22cbbd48a68309d7366b5502.tar.xz
Make the message window less useless
-rw-r--r--src/gtkpaludis/Makefile.am5
-rw-r--r--src/gtkpaludis/main_window.cc126
-rw-r--r--src/gtkpaludis/message_window.cc179
-rw-r--r--src/gtkpaludis/message_window.hh41
4 files changed, 350 insertions, 1 deletions
diff --git a/src/gtkpaludis/Makefile.am b/src/gtkpaludis/Makefile.am
index 75ddbbc..5ad80ca 100644
--- a/src/gtkpaludis/Makefile.am
+++ b/src/gtkpaludis/Makefile.am
@@ -5,7 +5,9 @@ AM_CXXFLAGS = -I$(top_srcdir) \
DEFS= \
-DSYSCONFDIR=\"$(sysconfdir)\" \
- -DLIBEXECDIR=\"$(libexecdir)\"
+ -DLIBEXECDIR=\"$(libexecdir)\" \
+ -DGLIBMM_EXCEPTIONS_ENABLED=1
+
SUBDIRS = .
if ENABLE_GTK
@@ -16,6 +18,7 @@ gtkpaludis_SOURCES = \
command_line.cc command_line.hh \
browse_tree.cc browse_tree.hh \
information_tree.cc information_tree.hh \
+ message_window.cc message_window.hh \
main_window.cc main_window.hh \
gtkpaludis.cc
diff --git a/src/gtkpaludis/main_window.cc b/src/gtkpaludis/main_window.cc
new file mode 100644
index 0000000..cde5ff1
--- /dev/null
+++ b/src/gtkpaludis/main_window.cc
@@ -0,0 +1,126 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "main_window.hh"
+#include "browse_tree.hh"
+#include "information_tree.hh"
+#include "message_window.hh"
+
+#include <paludis/about.hh>
+#include <paludis/util/stringify.hh>
+
+#include <gtkmm/box.h>
+#include <gtkmm/button.h>
+#include <gtkmm/entry.h>
+#include <gtkmm/frame.h>
+#include <gtkmm/label.h>
+#include <gtkmm/paned.h>
+#include <gtkmm/scrolledwindow.h>
+#include <gtkmm/stock.h>
+#include <gtkmm/textview.h>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template<>
+ struct Implementation<MainWindow> :
+ InternalCounted<MainWindow>
+ {
+ Gtk::VBox main_container;
+
+ Gtk::HBox search_container;
+ Gtk::Label search_label;
+ Gtk::Entry search_box;
+ Gtk::Button search_button;
+
+ Gtk::HPaned middle_pane;
+
+ Gtk::Frame information_frame;
+ Gtk::ScrolledWindow information_window;
+ InformationTree information_tree;
+
+ Gtk::Frame browse_frame;
+ Gtk::ScrolledWindow browse_window;
+ BrowseTree browse_tree;
+
+ Gtk::Frame messages_frame;
+ Gtk::ScrolledWindow messages_window;
+ MessageWindow messages;
+
+ Implementation();
+ };
+}
+
+Implementation<MainWindow>::Implementation() :
+ main_container(false, 5),
+ search_container(false, 5),
+ search_label(" Search: "),
+ search_button(Gtk::Stock::FIND),
+ information_frame(" Information: "),
+ browse_frame(" Browse: "),
+ browse_tree(&information_tree),
+ messages_frame(" Messages: ")
+{
+}
+
+MainWindow::MainWindow() :
+ PrivateImplementationPattern<MainWindow>(new Implementation<MainWindow>)
+{
+ set_title("gtkPaludis " + stringify(PALUDIS_VERSION_MAJOR) + "." +
+ stringify(PALUDIS_VERSION_MINOR) + "." +
+ stringify(PALUDIS_VERSION_MICRO));
+
+ set_default_size(600, 400);
+ set_border_width(5);
+
+ add(_imp->main_container);
+
+ _imp->main_container.pack_start(_imp->search_container, Gtk::PACK_SHRINK);
+ _imp->search_container.pack_start(_imp->search_label, Gtk::PACK_SHRINK);
+ _imp->search_container.pack_start(_imp->search_box);
+ _imp->search_container.pack_end(_imp->search_button, Gtk::PACK_SHRINK);
+
+ _imp->main_container.pack_start(_imp->middle_pane, Gtk::PACK_EXPAND_WIDGET);
+ _imp->middle_pane.pack1(_imp->browse_frame);
+ _imp->middle_pane.pack2(_imp->information_frame);
+
+ _imp->browse_frame.add(_imp->browse_window);
+ _imp->browse_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ _imp->browse_window.set_border_width(5);
+ _imp->browse_window.add(_imp->browse_tree);
+
+ _imp->information_frame.add(_imp->information_window);
+ _imp->information_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ _imp->information_window.set_border_width(5);
+ _imp->information_window.add(_imp->information_tree);
+
+ _imp->main_container.pack_end(_imp->messages_frame, Gtk::PACK_SHRINK);
+ _imp->messages_frame.add(_imp->messages_window);
+ _imp->messages_window.set_border_width(5);
+ _imp->messages_window.add(_imp->messages);
+ _imp->messages_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+
+ show_all_children();
+}
+
+MainWindow::~MainWindow()
+{
+}
+
diff --git a/src/gtkpaludis/message_window.cc b/src/gtkpaludis/message_window.cc
new file mode 100644
index 0000000..667e69b
--- /dev/null
+++ b/src/gtkpaludis/message_window.cc
@@ -0,0 +1,179 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "message_window.hh"
+#include <gtkmm/main.h>
+#include <paludis/util/log.hh>
+#include <unistd.h>
+#include <fcntl.h>
+
+using namespace paludis;
+
+namespace
+{
+ class Pipe :
+ InstantiationPolicy<Pipe, instantiation_method::NonCopyableTag>
+ {
+ private:
+ int _fds[2];
+
+ public:
+ Pipe()
+ {
+ if (-1 == pipe(_fds))
+ throw InternalError(PALUDIS_HERE, "pipe(2) failed");
+ }
+
+ ~Pipe()
+ {
+ close(_fds[0]);
+ close(_fds[1]);
+ }
+
+ int read_fd() const
+ {
+ return _fds[0];
+ }
+
+ int write_fd() const
+ {
+ return _fds[1];
+ }
+ };
+
+ /**
+ * Output stream buffer class that's opened via an FD.
+ *
+ * See \ref TCppSL Ch. 13.13 for what we're doing here. The buffer code is
+ * based upon the "io/outbuf2.hpp" example in section 13.13.3.
+ */
+ class FDOutputStreamBuf :
+ public std::streambuf
+ {
+ protected:
+ int fd;
+
+ virtual int_type
+ overflow(int_type c)
+ {
+ if (c != EOF)
+ {
+ char z = c;
+ if (1 != write(fd, &z, 1))
+ return EOF;
+ }
+ return c;
+ }
+
+ virtual std::streamsize
+ xsputn(const char * s, std::streamsize num)
+ {
+ return write(fd, s, num);
+ }
+
+ public:
+ FDOutputStreamBuf(const int f) :
+ fd(f)
+ {
+ }
+ };
+
+ /**
+ * Member from base initialisation for FDOutputStream.
+ */
+ class FDOutputStreamBase
+ {
+ protected:
+ FDOutputStreamBuf buf;
+
+ public:
+ FDOutputStreamBase(const int fd) :
+ buf(fd)
+ {
+ }
+ };
+
+ /**
+ * Output stream buffer class that's opened via an FD.
+ */
+ class FDOutputStream :
+ protected FDOutputStreamBase,
+ public std::ostream
+ {
+ public:
+ FDOutputStream(const int fd) :
+ FDOutputStreamBase(fd),
+ std::ostream(&buf)
+ {
+ }
+ };
+}
+
+namespace paludis
+{
+ template<>
+ struct Implementation<MessageWindow> :
+ InternalCounted<Implementation<MessageWindow> >
+ {
+ Pipe log_pipe;
+ MessageWindow * const owner;
+ Glib::RefPtr<Glib::IOChannel> log_connection;
+ FDOutputStream stream;
+
+ Implementation(MessageWindow * const o) :
+ owner(o),
+ log_connection(Glib::IOChannel::create_from_fd(log_pipe.read_fd())),
+ stream(log_pipe.write_fd())
+ {
+ Glib::signal_io().connect(sigc::mem_fun(*owner, &MessageWindow::on_log_read),
+ log_pipe.read_fd(), Glib::IO_IN);
+ Log::get_instance()->set_log_stream(&stream);
+ Log::get_instance()->message(ll_debug, lc_no_context, "Message window initialised");
+ }
+ };
+}
+
+MessageWindow::MessageWindow() :
+ PrivateImplementationPattern<MessageWindow>(new Implementation<MessageWindow>(this))
+{
+ set_editable(false);
+}
+
+MessageWindow::~MessageWindow()
+{
+}
+
+bool
+MessageWindow::on_log_read(Glib::IOCondition io_condition)
+{
+ if (0 == io_condition & Glib::IO_IN)
+ return false;
+
+ Glib::ustring buf;
+
+#ifndef GLIBMM_EXCEPTIONS_ENABLED
+# error Your glibcc hates us
+#endif
+
+ _imp->log_connection->read_line(buf);
+ get_buffer()->insert(get_buffer()->end(), buf);
+
+ return true;
+}
+
diff --git a/src/gtkpaludis/message_window.hh b/src/gtkpaludis/message_window.hh
new file mode 100644
index 0000000..7540535
--- /dev/null
+++ b/src/gtkpaludis/message_window.hh
@@ -0,0 +1,41 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_SRC_GTKPALUDIS_MESSAGE_WINDOW_HH
+#define PALUDIS_GUARD_SRC_GTKPALUDIS_MESSAGE_WINDOW_HH 1
+
+#include <gtkmm/textview.h>
+#include <gtkmm/main.h>
+#include <paludis/util/private_implementation_pattern.hh>
+
+namespace paludis
+{
+ class MessageWindow :
+ public Gtk::TextView,
+ private PrivateImplementationPattern<MessageWindow>
+ {
+ public:
+ MessageWindow();
+ virtual ~MessageWindow();
+
+ bool on_log_read(Glib::IOCondition);
+ };
+}
+
+#endif