[gnomemm] Using Bonobomm...



    Ok, so I figured out how to make a Bonobomm app (using the hello example from
libbonobouimm/examples).  I'm trying to make an About dialog to pop up when I select the
about help menu item.  It may be because I've combined stuff from regexxer and the hello
example.  Maybe you guys can see what I'm doing wrong.  It keeps segfaulting:

uicomponent_impl.h:
-------------------
#ifndef GCDBURNCOMPONENT_H
#define GCDBURNCOMPONENT_H

#include <bonobomm/servers/uicomponent.h>
#include <libgnomeuimm/about.h>
#include "about.h"

namespace GCDBurn
{

class UIComponent_impl: public Gnome::Bonobo::Servers::UIComponent
{
public:

  UIComponent_impl();
  virtual ~UIComponent_impl();

  //Verb callbacks:
  virtual void on_verb_file_new();
  virtual void on_verb_file_open();
  virtual void on_verb_file_save();
  virtual void on_verb_file_saveas();
  virtual void on_verb_file_close();
  virtual void on_verb_file_exit();
  virtual void on_verb_edit_undo();
  virtual void on_verb_edit_redo();
  virtual void on_verb_help_about();

protected:
  virtual void show_nothing_dialog();
  void on_about_dialog_hide();
private:
  std::auto_ptr<GCDBurn::gcdb_About> about_dialog_;
};

} // namespace GCDBurn

#endif /* GCDBURNCOMPONENT_H */


uicomponent_impl.cc:
--------------------
#include "uicomponent_impl.h"
#include "about.h"
#include <gtkmm/messagedialog.h>
#include <libbonoboui.h>

namespace GCDBurn
{

UIComponent_impl::UIComponent_impl()
{
  add_verb_handler( SigC::slot(*this, &UIComponent_impl::on_verb_file_new), "FileNew");
  add_verb_handler( SigC::slot(*this, &UIComponent_impl::on_verb_file_open), "FileOpen");
  add_verb_handler( SigC::slot(*this, &UIComponent_impl::on_verb_file_save), "FileSave");
  add_verb_handler( SigC::slot(*this, &UIComponent_impl::on_verb_file_saveas),
"FileSaveAs");
  add_verb_handler( SigC::slot(*this, &UIComponent_impl::on_verb_file_close),
"FileClose");
  add_verb_handler( SigC::slot(*this, &UIComponent_impl::on_verb_file_exit), "FileExit");

  add_verb_handler( SigC::slot(*this, &UIComponent_impl::on_verb_edit_undo), "EditUndo");
  add_verb_handler( SigC::slot(*this, &UIComponent_impl::on_verb_edit_redo), "EditRedo");

  add_verb_handler( SigC::slot(*this, &UIComponent_impl::on_verb_help_about),
"HelpAbout");
}

UIComponent_impl::~UIComponent_impl()
{
}

void UIComponent_impl::on_verb_file_new()
{
  Gtk::MessageDialog dialog("This does nothing.");
  dialog.run();
}

void UIComponent_impl::on_verb_file_open()
{
  show_nothing_dialog();
}

void UIComponent_impl::on_verb_file_save()
{
  show_nothing_dialog();
}

void UIComponent_impl::on_verb_file_saveas()
{
  show_nothing_dialog();
}

void UIComponent_impl::on_verb_file_close()
{
  //Can't be bothered to do multiple app window management in the C++ version - it's just
a distraction.
  on_verb_file_exit();
}

void UIComponent_impl::on_verb_file_exit()
{
	/* FIXME: quit the mainloop nicely */
	exit (0);
}

void UIComponent_impl::on_verb_edit_undo()
{
  show_nothing_dialog();
}

void UIComponent_impl::on_verb_edit_redo()
{
  show_nothing_dialog();
}

void UIComponent_impl::show_nothing_dialog()
{
  Gtk::MessageDialog dialog("This does nothing; it is only a demonstration.");
  dialog.run();
}

void UIComponent_impl::on_verb_help_about()
{
	if(about_dialog_.get())
	{
		about_dialog_->present();
	}
	else
	{
		std::auto_ptr<GCDBurn::gcdb_About> dialog(new
GCDBurn::gcdb_About(*dynamic_cast<Gtk::Window*>(this)));
		dialog->signal_hide().connect(SigC::slot(*this,
&UIComponent_impl::on_about_dialog_hide));
		dialog->show();

		about_dialog_ = dialog;
	}
}

void UIComponent_impl::on_about_dialog_hide()
{
	const std::auto_ptr<GCDBurn::gcdb_About> temp(about_dialog_);
}

} // namespace GCDBurn


about.h:
--------
#ifndef GCDB_ABOUT_H
#define GCDB_ABOUT_H

#include <gtkmm/dialog.h>

namespace GCDBurn
{

class gcdb_About : public Gtk::Dialog
{
public:
	explicit gcdb_About(Gtk::Window& parent);
	virtual ~gcdb_About();
protected:
	virtual void on_response(int response_id);
};

} // namespace GCDBurn

#endif /* GCDB_ABOUT_H */


about.cc:
---------
#include "about.h"

#include <glib.h>
#include <atkmm.h>
#include <gtkmm/alignment.h>
#include <gtkmm/box.h>
#include <gtkmm/image.h>
#include <gtkmm/label.h>
#include <gtkmm/stock.h>

#include <config.h>

namespace
{

const char gcdburn_icon_filename[] = GCDBURN_DATADIR G_DIR_SEPARATOR_S
				     "pixmaps" G_DIR_SEPARATOR_S "gcdburn.png";

const char gcdburn_project_url[]   = "none";
const char gcdburn_author_mail[]   = "Bryan Forbes <mxpxfifws yahoo com>";
const char gcdburn_debian_mail[]   = "none";

class SelectableLabel : public Gtk::Label
{
public:
	explicit SelectableLabel(const Glib::ustring& label);
	virtual ~SelectableLabel();

protected:
	virtual bool on_focus(Gtk::DirectionType direction);
};

SelectableLabel::SelectableLabel(const Glib::ustring& label)
:
	Gtk::Label(label)
{
	set_selectable(true);
}

SelectableLabel::~SelectableLabel()
{}

bool SelectableLabel::on_focus(Gtk::DirectionType)
{
	if(can_focus() && !is_focus())
	{
		grab_focus();
		return true;
	}

	return false;
}

class ContributorBox : public Gtk::VBox
{
public:
	ContributorBox(const Glib::ustring& what, const Glib::ustring& who);
	virtual ~ContributorBox();
};

ContributorBox::ContributorBox(const Glib::ustring& what, const Glib::ustring& who)
:
	Gtk::VBox(false, 2)
{
	using namespace Gtk;
	
	Label *const label_what = new Label();
	pack_start(*manage(label_what), PACK_SHRINK);
	label_what->set_markup("<span size=\"small\">" + what + "</span>");

	Label *const label_who = new SelectableLabel(who);
	pack_start(*manage(label_who), PACK_SHRINK);

	const Glib::RefPtr<Atk::Object> accessible_what = label_what->get_accessible();
	const Glib::RefPtr<Atk::Object> accessible_who  = label_who->get_accessible();

	accessible_what->add_relationship(Atk::RELATION_FLOWS_TO,   accessible_who);
	accessible_who ->add_relationship(Atk::RELATION_FLOWS_FROM, accessible_what);
}

ContributorBox::~ContributorBox()
{}

} // anonymous namespace


namespace GCDBurn
{

gcdb_About::gcdb_About(Gtk::Window& parent)
:
	Gtk::Dialog("About GCDBurn", parent, false, true)
{
	using namespace Gtk;

	add_button(Stock::OK, RESPONSE_OK)->grab_focus();
	set_default_response(RESPONSE_OK);

	Box& box_dialog = *get_vbox();
	Alignment *const alignment = new Alignment(0.5, 1./3., 0.5, 0.5);
	box_dialog.pack_start(*manage(alignment), PACK_EXPAND_WIDGET);
	alignment->set_border_width(20);

	Box *const box = new VBox(false, 20);
	alignment->add(*manage(box));

	{
		Box *const box_title = new HBox(false, 10);
		box->pack_start(*manage(box_title), PACK_EXPAND_PADDING);

		Image *const image = new Image(gcdburn_icon_filename);
		box_title->pack_start(*manage(image), PACK_EXPAND_WIDGET);
		image->set_alignment(1.0, 0.5);

		Label *const label_title = new Label();
		box_title->pack_start(*manage(label_title), PACK_EXPAND_WIDGET);
		label_title->set_alignment(0.0, 0.5);
		label_title->set_markup("<span size=\"xx-large\" weight=\"heavy\">" PACKAGE_STRING
"</span>");

		const Glib::RefPtr<Atk::Object> image_accessible = image->get_accessible();
		image_accessible->set_name("GCDBurn icon");
	}
	{
		Box *const box_text = new VBox(false, 10);
		box->pack_start(*manage(box_text), PACK_EXPAND_WIDGET);

		Widget *const label_url = new SelectableLabel(gcdburn_project_url);
		box_text->pack_start(*manage(label_url), PACK_EXPAND_PADDING, 5);

		Widget *const box_author = new ContributorBox("written by", gcdburn_author_mail);
		box_text->pack_start(*manage(box_author), PACK_EXPAND_PADDING);

		Widget *const box_debian = new ContributorBox("Debian package by",
gcdburn_debian_mail);
		box_text->pack_start(*manage(box_debian), PACK_EXPAND_PADDING);
	}

	alignment->show_all();
}

gcdb_About::~gcdb_About()
{}

void gcdb_About::on_response(int)
{
	hide();
}

} // namespace GCDBurn


interface.h:
------------
#ifndef GCDBURN_MAIN_H
#define GCDBURN_MAIN_H

#include <gtkmm.h>
#include <libgnomeuimm.h>
#include <glibmm.h>
#include <bonobomm/widgets/window.h>
#include "uicomponent_impl.h"

namespace GCDBurn
{

class gcdb : public Gnome::Bonobo::Window
{
public:
	gcdb();
	virtual ~gcdb();

protected:
	// member methods
	void on_quit();
	void set_up_menus();
	void set_up_toolbar();
	void do_nothing();

	// member widgets
	Gnome::UI::AppBar status;

	GCDBurn::UIComponent_impl m_servantComponent;
};

} // namespace GCDBurn

#endif // GCDBURN_MAIN_H


interface.cc:
-------------
#include "interface.h"
#include "uicomponent_impl.h"

#include <libbonoboui.h>
#include <fstream>

#define GCDBURN_UI_XML "gcdburn_ui.xml"

namespace GCDBurn
{

gcdb::gcdb() :
	Gnome::Bonobo::Window("GCDBurn", "Gnome CD Burn")
{
	try
	{
		Bonobo::UIContainer_var cppContainer = get_ui_container();
		Bonobo::UIComponent_var cppComponent = m_servantComponent._this();
		
		cppComponent->setContainer(cppContainer);
		char *fname = bonobo_ui_util_get_ui_fname("", DATADIR GCDBURN_UI_XML);
		
		std::string strXML;
		std::ifstream fStream (fname);
		if (fStream.is_open ())
		{
		    while(!(fStream.eof ()))
		    {
			char chTemp = fStream.get ();
			if(!(fStream.eof ()))
			    strXML += chTemp;
		    }
		}
		
		cppContainer->setNode ("/", strXML.c_str(), cppComponent->name());
	}
	catch (const CORBA::Exception& ex)
	{
		g_warning("debug: CORBA::Exception\n");
	}
	
	set_wmclass("gcdburn", "gcdburn_class");
	set_resizable();
	set_default_size(300, 400);

	show_all_children();
}

gcdb::~gcdb()
{
}

void gcdb::on_quit()
{
	hide();
}

void gcdb::do_nothing()
{
}

} // namespace GCDBurn


main.cc:
--------
#include "interface.h"
#include <libbonoboui.h>

int main(int argc, char **argv)
{
	if(!bonobo_ui_init("GCDBurn", "0.1", &argc, argv))
		g_error(_("Cannot init libbonoboui code"));
	Gtk::Main main_instance(&argc, &argv);
	GCDBurn::gcdb window;
	Gtk::Main::run(window);

	return 0;
}

gcdburn_ui.xml:
---------------
<Root>
<commands>
<cmd name="FileNew" stockid="gtk-new"/>
<cmd name="FileOpen" stockid="gtk-open" priority="1"/>
<cmd name="FileSave" stockid="gtk-save" priority="1"/>
<cmd name="FileSaveAs" stockid="gtk-save-as"/>
<cmd name="FileClose" stockid="gtk-close"/>
<cmd name="FileExit" stockid="gtk-quit"/>
<cmd name="EditUndo" stockid="gtk-undo"/>
<cmd name="EditRedo" stockid="gtk-redo"/>
<cmd name="EditCut" stockid="gtk-cut"/>
<cmd name="EditCopy" stockid="gtk-copy"/>
<cmd name="EditPaste" stockid="gtk-paste"/>
<cmd name="EditSelect" label="Select" tip="Select"/>
<cmd name="EditClear" stockid="gtk-clear"/>
<cmd name="HelpAbout" label="About..." tip="About this application" pixtype="stock"
pixname="gtk-preferences"/>
</commands>
<menu>
<submenu name="File" label="File">
<menuitem name="FileNew" verb=""/>
<menuitem name="FileOpen" verb=""/>
<menuitem name="FileSave" verb=""/>
<menuitem name="FileSaveAs" verb=""/>
<menuitem name="FileClose" verb=""/>
<menuitem name="FileExit" verb=""/>
</submenu>
<submenu name="Edit" label="Edit">
<menuitem name="EditUndo" verb=""/>
<menuitem name="EditRedo" verb=""/>
<separator/>
<menuitem name="EditCut" verb=""/>
<menuitem name="EditCopy" verb=""/>
<menuitem name="EditPaste" verb=""/>
<menuitem name="EditSelect" verb=""/>
<menuitem name="EditClear" verb=""/>
</submenu>
<submenu name="Help" stockid="gtk-help">
<menuitem name="HelpAbout" verb=""/>
</submenu>
</menu>
<dockitem name="Toolbar" relief="none" homogeneous="1" behavior="exclusive" >
<toolitem name="FileOpen" verb=""/>
<toolitem name="FileSave" verb=""/>
<toolitem name="FileExit" verb=""/>
<placeholder/>
</dockitem>
</Root>

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/



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