home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / gtk / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-21  |  3.8 KB  |  178 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. #include <limits.h>
  20. #include <stdlib.h>
  21. #include "../getopt.h"
  22.  
  23. #include <list>
  24.  
  25. #include <libglademm.h>
  26. #include <gtkmm/main.h>
  27. #include <gtkmm/window.h>
  28. #include <gtkmm/messagedialog.h>
  29.  
  30. #include "images/vba-wm-pixbufs.h"
  31.  
  32. #include "window.h"
  33. #include "intl.h"
  34.  
  35. using Gnome::Glade::Xml;
  36.  
  37. static const char * csProgramName;
  38.  
  39. static int iShowHelp;
  40. static int iShowVersion;
  41.  
  42. // Non-characters used for long options that have no equivalent short option
  43. enum
  44. {
  45.   IGNORED_OPTION = CHAR_MAX + 1
  46. };
  47.  
  48. static const char csShortOptions[] = "V";
  49.  
  50. static const struct option astLongOptions[] =
  51. {
  52.   { "help",    no_argument, &iShowHelp, IGNORED_OPTION },
  53.   { "version", no_argument, NULL,       'V'            },
  54.   { 0, 0, 0, 0 }
  55. };
  56.  
  57. static void vUsage(int iStatus)
  58. {
  59.   if (iStatus != 0)
  60.   {
  61.     g_printerr(_("Try `%s --help' for more information.\n"), csProgramName);
  62.   }
  63.   else
  64.   {
  65.     g_print(_("Usage: %s [option ...] [file]\n"), csProgramName);
  66.     g_print(_("\
  67. \n\
  68. Options:\n\
  69.       --help            Output this help.\n\
  70.   -V, --version         Output version information.\n\
  71. "));
  72.   }
  73.  
  74.   exit(iStatus);
  75. }
  76.  
  77. static void vSetDefaultWindowIcon()
  78. {
  79.   const guint8 * apuiInlinePixbuf[] =
  80.   {
  81.     stock_vba_wm_16,
  82.     stock_vba_wm_32,
  83.     stock_vba_wm_48,
  84.     stock_vba_wm_64
  85.   };
  86.  
  87.   std::list<Glib::RefPtr<Gdk::Pixbuf> > listPixbuf;
  88.   for (guint i = 0; i < G_N_ELEMENTS(apuiInlinePixbuf); i++)
  89.   {
  90.     listPixbuf.push_back(
  91.       Gdk::Pixbuf::create_from_inline(-1, apuiInlinePixbuf[i]));
  92.   }
  93.  
  94.   Gtk::Window::set_default_icon_list(listPixbuf);
  95. }
  96.  
  97. int main(int argc, char * argv[])
  98. {
  99.   csProgramName = argv[0];
  100.  
  101. #ifdef ENABLE_NLS
  102.   setlocale(LC_ALL, "");
  103.   bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
  104.   textdomain(GETTEXT_PACKAGE);
  105.   bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
  106. #endif // ENABLE_NLS
  107.  
  108.   Gtk::Main oKit(argc, argv);
  109.  
  110.   int iOpt;
  111.   while ((iOpt = getopt_long(argc, argv, csShortOptions, astLongOptions, NULL))
  112.          != -1)
  113.   {
  114.     switch (iOpt)
  115.     {
  116.     case 'V':
  117.       iShowVersion = 1;
  118.       break;
  119.     case 0:
  120.       // Long options
  121.       break;
  122.     default:
  123.       vUsage(1);
  124.       break;
  125.     }
  126.   }
  127.  
  128.   if (iShowVersion)
  129.   {
  130.     g_print(_("VisualBoyAdvance version %s [GTK+]\n"), VERSION);
  131.     exit(0);
  132.   }
  133.  
  134.   if (iShowHelp)
  135.   {
  136.     vUsage(0);
  137.   }
  138.  
  139.   vSetDefaultWindowIcon();
  140.  
  141.   Glib::RefPtr<Xml> poXml;
  142.   try
  143.   {
  144.     poXml = Xml::create(PKGDATADIR "/vba.glade", "MainWindow");
  145.   }
  146.   catch (const Xml::Error & e)
  147.   {
  148.     Gtk::MessageDialog oDialog(e.what(),
  149. #ifndef GTKMM20
  150.                                false,
  151. #endif // ! GTKMM20
  152.                                Gtk::MESSAGE_ERROR,
  153.                                Gtk::BUTTONS_OK);
  154.     oDialog.run();
  155.     return 1;
  156.   }
  157.  
  158.   VBA::Window * poWindow = NULL;
  159.   poXml->get_widget_derived<VBA::Window>("MainWindow", poWindow);
  160.  
  161.   if (optind < argc)
  162.   {
  163.     // Display the window before loading the file
  164.     poWindow->show();
  165.     while (Gtk::Main::events_pending())
  166.     {
  167.       Gtk::Main::iteration();
  168.     }
  169.  
  170.     poWindow->bLoadROM(argv[optind]);
  171.   }
  172.  
  173.   Gtk::Main::run(*poWindow);
  174.   delete poWindow;
  175.  
  176.   return 0;
  177. }
  178.