annotate src/gtk/main.cpp @ 4:5f6f2134e8ce

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