Mercurial > vba-linux
view src/gtk/main.cpp @ 3:b05d00f19d80
fix some formatting
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:33:11 -0600 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.2 // Copyright (C) 1999-2003 Forgotten3 // Copyright (C) 2004 Forgotten and the VBA development team5 // This program is free software; you can redistribute it and/or modify6 // it under the terms of the GNU General Public License as published by7 // 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 of12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 // GNU General Public License for more details.14 //15 // You should have received a copy of the GNU General Public License16 // along with this program; if not, write to the Free Software Foundation,17 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.19 #include <limits.h>20 #include <stdlib.h>21 #include "../getopt.h"23 #include <list>25 #include <libglademm.h>26 #include <gtkmm/main.h>27 #include <gtkmm/window.h>28 #include <gtkmm/messagedialog.h>30 #include "images/vba-wm-pixbufs.h"32 #include "window.h"33 #include "intl.h"35 using Gnome::Glade::Xml;37 static const char * csProgramName;39 static int iShowHelp;40 static int iShowVersion;42 // Non-characters used for long options that have no equivalent short option43 enum44 {45 IGNORED_OPTION = CHAR_MAX + 146 };48 static const char csShortOptions[] = "V";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 };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 else64 {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 }74 exit(iStatus);75 }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_6485 };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 }94 Gtk::Window::set_default_icon_list(listPixbuf);95 }97 int main(int argc, char * argv[])98 {99 csProgramName = argv[0];101 #ifdef ENABLE_NLS102 setlocale(LC_ALL, "");103 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);104 textdomain(GETTEXT_PACKAGE);105 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");106 #endif // ENABLE_NLS108 Gtk::Main oKit(argc, argv);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 options121 break;122 default:123 vUsage(1);124 break;125 }126 }128 if (iShowVersion)129 {130 g_print(_("VisualBoyAdvance version %s [GTK+]\n"), VERSION);131 exit(0);132 }134 if (iShowHelp)135 {136 vUsage(0);137 }139 vSetDefaultWindowIcon();141 Glib::RefPtr<Xml> poXml;142 try143 {144 poXml = Xml::create(PKGDATADIR "/vba.glade", "MainWindow");145 }146 catch (const Xml::Error & e)147 {148 Gtk::MessageDialog oDialog(e.what(),149 #ifndef GTKMM20150 false,151 #endif // ! GTKMM20152 Gtk::MESSAGE_ERROR,153 Gtk::BUTTONS_OK);154 oDialog.run();155 return 1;156 }158 VBA::Window * poWindow = NULL;159 poXml->get_widget_derived<VBA::Window>("MainWindow", poWindow);161 if (optind < argc)162 {163 // Display the window before loading the file164 poWindow->show();165 while (Gtk::Main::events_pending())166 {167 Gtk::Main::iteration();168 }170 poWindow->bLoadROM(argv[optind]);171 }173 Gtk::Main::run(*poWindow);174 delete poWindow;176 return 0;177 }