Example #1
0
/**
 * Main function
 */
int	main(int argc, char **argv)
{
  try
    {
      // !both filestr and backup are used for the file logger
      std::ofstream	filestr(FILE_TO_LOG);
      std::streambuf*	backup = std::clog.rdbuf();

      std::clog.rdbuf(filestr.rdbuf());
      std::clog << "#### New session opened ####" << std::endl;

      Glib::OptionContext	oc("Here's the parameters");
      Glib::OptionGroup		og("main", "main description");

      Glib::OptionEntry		verbose;
      verbose.set_long_name("verbose");
      verbose.set_short_name('v');
      verbose.set_description("set verbose level");
      verbose.set_arg_description("verbose level");

      og.add_entry(verbose);

      oc.set_main_group(og);
      oc.set_help_enabled();

      Gtk::Main		kit(argc, argv, oc);
      WindowManager	mywindow;

      Gtk::Main::run();

      std::clog << "#### Session closed ####" << std::endl;
      std::clog.rdbuf(backup);
      filestr.close();
    }
  catch (Glib::OptionError oe)
    {
      std::cerr << "OptionError: " << oe.what() << std::endl;
    }

  return 0;
}
Example #2
0
int main(int argc, char * argv[])
{
  bool bShowVersion = false;
  Glib::OptionGroup::vecustrings listRemaining;

#ifdef ENABLE_NLS
  setlocale(LC_ALL, "");
  bindtextdomain("gvbam", LOCALEDIR);
  textdomain("gvbam");
#endif // ENABLE_NLS

  Glib::set_application_name(_("VBA-M"));

  Gtk::Main oKit(argc, argv);

#ifdef USE_OPENGL
  Gtk::GL::init(argc, argv);
#endif // USE_OPENGL

  Glib::OptionContext oContext;
  Glib::OptionGroup oGroup("main_group", _("Main VBA-M options"));

  Glib::OptionEntry oVersion;
  oVersion.set_long_name("version");
  oVersion.set_short_name('v');
  oVersion.set_description(_("Output version information."));
  oGroup.add_entry(oVersion, bShowVersion);

  Glib::OptionEntry oFileName;
  oFileName.set_long_name(G_OPTION_REMAINING);
  oFileName.set_description(G_OPTION_REMAINING);
  oGroup.add_entry(oFileName, listRemaining);

  oContext.set_main_group(oGroup);

  try
  {
    oContext.parse(argc, argv);
  }
  catch (const Glib::Error& e)
  {
    Gtk::MessageDialog oDialog(e.what(),
                               false,
                               Gtk::MESSAGE_ERROR,
                               Gtk::BUTTONS_OK);
    oDialog.run();
    return 1;
  }

  if (bShowVersion)
  {
    g_print(_("VisualBoyAdvance version %s [GTK+]\n"), VERSION);
    exit(0);
  }

  Gtk::Window::set_default_icon_name("vbam");

  std::string sGtkBuilderFile = VBA::Window::sGetUiFilePath("vbam.ui");

  Glib::RefPtr<Gtk::Builder> poXml;
  try
  {
    poXml = Gtk::Builder::create();
    poXml->add_from_file(sGtkBuilderFile, "accelgroup1");
    poXml->add_from_file(sGtkBuilderFile, "MainWindow");
  }
  catch (const Gtk::BuilderError & e)
  {
    Gtk::MessageDialog oDialog(e.what(),
                               false,
                               Gtk::MESSAGE_ERROR,
                               Gtk::BUTTONS_OK);
    oDialog.run();
    return 1;
  }

  VBA::Window * poWindow = NULL;
  poXml->get_widget_derived<VBA::Window>("MainWindow", poWindow);

  if (listRemaining.size() == 1)
  {
    // Display the window before loading the file
    poWindow->show();
    while (Gtk::Main::events_pending())
    {
      Gtk::Main::iteration();
    }

    poWindow->bLoadROM(listRemaining[0]);
  }

  Gtk::Main::run(*poWindow);
  delete poWindow;

  return 0;
}