rlm@1: // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. rlm@1: // Copyright (C) 1999-2003 Forgotten rlm@1: // Copyright (C) 2004 Forgotten and the VBA development team rlm@1: rlm@1: // This program is free software; you can redistribute it and/or modify rlm@1: // it under the terms of the GNU General Public License as published by rlm@1: // the Free Software Foundation; either version 2, or(at your option) rlm@1: // any later version. rlm@1: // rlm@1: // This program is distributed in the hope that it will be useful, rlm@1: // but WITHOUT ANY WARRANTY; without even the implied warranty of rlm@1: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the rlm@1: // GNU General Public License for more details. rlm@1: // rlm@1: // You should have received a copy of the GNU General Public License rlm@1: // along with this program; if not, write to the Free Software Foundation, rlm@1: // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. rlm@1: rlm@1: #include rlm@1: #include rlm@1: #include "../getopt.h" rlm@1: rlm@1: #include rlm@1: rlm@1: #include rlm@1: #include rlm@1: #include rlm@1: #include rlm@1: rlm@1: #include "images/vba-wm-pixbufs.h" rlm@1: rlm@1: #include "window.h" rlm@1: #include "intl.h" rlm@1: rlm@1: using Gnome::Glade::Xml; rlm@1: rlm@1: static const char * csProgramName; rlm@1: rlm@1: static int iShowHelp; rlm@1: static int iShowVersion; rlm@1: rlm@1: // Non-characters used for long options that have no equivalent short option rlm@1: enum rlm@1: { rlm@1: IGNORED_OPTION = CHAR_MAX + 1 rlm@1: }; rlm@1: rlm@1: static const char csShortOptions[] = "V"; rlm@1: rlm@1: static const struct option astLongOptions[] = rlm@1: { rlm@1: { "help", no_argument, &iShowHelp, IGNORED_OPTION }, rlm@1: { "version", no_argument, NULL, 'V' }, rlm@1: { 0, 0, 0, 0 } rlm@1: }; rlm@1: rlm@1: static void vUsage(int iStatus) rlm@1: { rlm@1: if (iStatus != 0) rlm@1: { rlm@1: g_printerr(_("Try `%s --help' for more information.\n"), csProgramName); rlm@1: } rlm@1: else rlm@1: { rlm@1: g_print(_("Usage: %s [option ...] [file]\n"), csProgramName); rlm@1: g_print(_("\ rlm@1: \n\ rlm@1: Options:\n\ rlm@1: --help Output this help.\n\ rlm@1: -V, --version Output version information.\n\ rlm@1: ")); rlm@1: } rlm@1: rlm@1: exit(iStatus); rlm@1: } rlm@1: rlm@1: static void vSetDefaultWindowIcon() rlm@1: { rlm@1: const guint8 * apuiInlinePixbuf[] = rlm@1: { rlm@1: stock_vba_wm_16, rlm@1: stock_vba_wm_32, rlm@1: stock_vba_wm_48, rlm@1: stock_vba_wm_64 rlm@1: }; rlm@1: rlm@1: std::list > listPixbuf; rlm@1: for (guint i = 0; i < G_N_ELEMENTS(apuiInlinePixbuf); i++) rlm@1: { rlm@1: listPixbuf.push_back( rlm@1: Gdk::Pixbuf::create_from_inline(-1, apuiInlinePixbuf[i])); rlm@1: } rlm@1: rlm@1: Gtk::Window::set_default_icon_list(listPixbuf); rlm@1: } rlm@1: rlm@1: int main(int argc, char * argv[]) rlm@1: { rlm@1: csProgramName = argv[0]; rlm@1: rlm@1: #ifdef ENABLE_NLS rlm@1: setlocale(LC_ALL, ""); rlm@1: bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); rlm@1: textdomain(GETTEXT_PACKAGE); rlm@1: bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); rlm@1: #endif // ENABLE_NLS rlm@1: rlm@1: Gtk::Main oKit(argc, argv); rlm@1: rlm@1: int iOpt; rlm@1: while ((iOpt = getopt_long(argc, argv, csShortOptions, astLongOptions, NULL)) rlm@1: != -1) rlm@1: { rlm@1: switch (iOpt) rlm@1: { rlm@1: case 'V': rlm@1: iShowVersion = 1; rlm@1: break; rlm@1: case 0: rlm@1: // Long options rlm@1: break; rlm@1: default: rlm@1: vUsage(1); rlm@1: break; rlm@1: } rlm@1: } rlm@1: rlm@1: if (iShowVersion) rlm@1: { rlm@1: g_print(_("VisualBoyAdvance version %s [GTK+]\n"), VERSION); rlm@1: exit(0); rlm@1: } rlm@1: rlm@1: if (iShowHelp) rlm@1: { rlm@1: vUsage(0); rlm@1: } rlm@1: rlm@1: vSetDefaultWindowIcon(); rlm@1: rlm@1: Glib::RefPtr poXml; rlm@1: try rlm@1: { rlm@1: poXml = Xml::create(PKGDATADIR "/vba.glade", "MainWindow"); rlm@1: } rlm@1: catch (const Xml::Error & e) rlm@1: { rlm@1: Gtk::MessageDialog oDialog(e.what(), rlm@1: #ifndef GTKMM20 rlm@1: false, rlm@1: #endif // ! GTKMM20 rlm@1: Gtk::MESSAGE_ERROR, rlm@1: Gtk::BUTTONS_OK); rlm@1: oDialog.run(); rlm@1: return 1; rlm@1: } rlm@1: rlm@1: VBA::Window * poWindow = NULL; rlm@1: poXml->get_widget_derived("MainWindow", poWindow); rlm@1: rlm@1: if (optind < argc) rlm@1: { rlm@1: // Display the window before loading the file rlm@1: poWindow->show(); rlm@1: while (Gtk::Main::events_pending()) rlm@1: { rlm@1: Gtk::Main::iteration(); rlm@1: } rlm@1: rlm@1: poWindow->bLoadROM(argv[optind]); rlm@1: } rlm@1: rlm@1: Gtk::Main::run(*poWindow); rlm@1: delete poWindow; rlm@1: rlm@1: return 0; rlm@1: }