From: S?bastien G. <kx...@us...> - 2004-05-05 01:34:40
|
Update of /cvsroot/vba/VisualBoyAdvance/src/gtk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11297 Modified Files: vba.glade window.cpp window.h windowcallbacks.cpp Log Message: Added battery file import/export. Index: window.h =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/window.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** window.h 4 May 2004 20:33:16 -0000 1.14 --- window.h 5 May 2004 01:34:31 -0000 1.15 *************** *** 139,143 **** virtual void vOnRecentReset(); virtual void vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI); ! virtual void vOnRecent(std::string _sFile); virtual void vOnFileClose(); virtual void vOnFileExit(); --- 139,145 ---- virtual void vOnRecentReset(); virtual void vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI); ! virtual void vOnRecentFile(std::string _sFile); ! virtual void vOnImportBatteryFile(); ! virtual void vOnExportBatteryFile(); virtual void vOnFileClose(); virtual void vOnFileExit(); Index: window.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/window.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** window.cpp 4 May 2004 20:33:16 -0000 1.14 --- window.cpp 5 May 2004 01:34:31 -0000 1.15 *************** *** 205,208 **** --- 205,220 ---- poCMI)); + // Import menu + // + poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("ImportBatteryFile")); + poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnImportBatteryFile)); + m_listSensitiveWhenPlaying.push_back(poMI); + + // Export menu + // + poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("ExportBatteryFile")); + poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnExportBatteryFile)); + m_listSensitiveWhenPlaying.push_back(poMI); + // Frameskip menu // *************** *** 1145,1149 **** poIMI->signal_activate().connect(SigC::bind<std::string>( ! SigC::slot(*this, &Window::vOnRecent), *it)); --- 1157,1161 ---- poIMI->signal_activate().connect(SigC::bind<std::string>( ! SigC::slot(*this, &Window::vOnRecentFile), *it)); Index: vba.glade =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/vba.glade,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** vba.glade 3 May 2004 17:00:27 -0000 1.9 --- vba.glade 5 May 2004 01:34:31 -0000 1.10 *************** *** 51,55 **** <child internal-child="image"> ! <widget class="GtkImage" id="image108"> <property name="visible">True</property> <property name="stock">gtk-open</property> --- 51,55 ---- <child internal-child="image"> ! <widget class="GtkImage" id="image114"> <property name="visible">True</property> <property name="stock">gtk-open</property> *************** *** 409,412 **** --- 409,425 ---- <property name="label" translatable="yes">_Import</property> <property name="use_underline">True</property> + + <child> + <widget class="GtkMenu" id="ImportMenu_menu"> + + <child> + <widget class="GtkMenuItem" id="ImportBatteryFile"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Battery file...</property> + <property name="use_underline">True</property> + </widget> + </child> + </widget> + </child> </widget> </child> *************** *** 417,420 **** --- 430,446 ---- <property name="label" translatable="yes">E_xport</property> <property name="use_underline">True</property> + + <child> + <widget class="GtkMenu" id="ExportMenu_menu"> + + <child> + <widget class="GtkMenuItem" id="ExportBatteryFile"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Battery file...</property> + <property name="use_underline">True</property> + </widget> + </child> + </widget> + </child> </widget> </child> *************** *** 455,459 **** <child internal-child="image"> ! <widget class="GtkImage" id="image109"> <property name="visible">True</property> <property name="stock">gtk-close</property> --- 481,485 ---- <child internal-child="image"> ! <widget class="GtkImage" id="image115"> <property name="visible">True</property> <property name="stock">gtk-close</property> *************** *** 476,480 **** <child internal-child="image"> ! <widget class="GtkImage" id="image110"> <property name="visible">True</property> <property name="stock">gtk-quit</property> --- 502,506 ---- <child internal-child="image"> ! <widget class="GtkImage" id="image116"> <property name="visible">True</property> <property name="stock">gtk-quit</property> Index: windowcallbacks.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/windowcallbacks.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** windowcallbacks.cpp 4 May 2004 20:33:16 -0000 1.3 --- windowcallbacks.cpp 5 May 2004 01:34:31 -0000 1.4 *************** *** 245,259 **** } ! if (Glib::file_test(oDialog.get_filename(), Glib::FILE_TEST_EXISTS)) { ! Gtk::MessageDialog oConfirm(*this, ! _("File already exists. Overwrite it?"), #ifndef GTKMM20 ! false, #endif // ! GTKMM20 ! Gtk::MESSAGE_QUESTION, ! Gtk::BUTTONS_YES_NO, ! true); ! if (oConfirm.run() != Gtk::RESPONSE_YES) { continue; --- 245,258 ---- } ! if (Glib::file_test(sFile, Glib::FILE_TEST_EXISTS)) { ! Gtk::MessageDialog oConfirmDialog(*this, ! _("File already exists. Overwrite it?"), #ifndef GTKMM20 ! false, #endif // ! GTKMM20 ! Gtk::MESSAGE_QUESTION, ! Gtk::BUTTONS_YES_NO); ! if (oConfirmDialog.run() != Gtk::RESPONSE_YES) { continue; *************** *** 375,383 **** } ! void Window::vOnRecent(std::string _sFile) { bLoadROM(_sFile); } void Window::vOnFileClose() { --- 374,580 ---- } ! void Window::vOnRecentFile(std::string _sFile) { bLoadROM(_sFile); } + void Window::vOnImportBatteryFile() + { + std::string sSaveDir = m_poDirConfig->sGetKey("saves"); + + #ifdef GTKMM20 + + Gtk::FileSelection oDialog(_("Import battery file")); + oDialog.set_transient_for(*this); + + if (sSaveDir == "") + { + oDialog.set_filename(Glib::path_get_dirname(m_sRomFile) + "/"); + } + else + { + oDialog.set_filename(sSaveDir + "/"); + } + + #else // ! GTKMM20 + + Gtk::FileChooserDialog oDialog(*this, _("Import battery file")); + oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + oDialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + + if (sSaveDir == "") + { + oDialog.set_current_folder(Glib::path_get_dirname(m_sRomFile)); + } + else + { + oDialog.set_current_folder(sSaveDir); + oDialog.add_shortcut_folder(sSaveDir); + } + + Gtk::FileFilter oBatteryFilter; + oBatteryFilter.set_name(_("Battery file")); + oBatteryFilter.add_pattern("*.[sS][aA][vV]"); + + Gtk::FileFilter oFlashFilter; + oFlashFilter.set_name(_("Flash save")); + oFlashFilter.add_pattern("*.[dD][aA][tT]"); + + oDialog.add_filter(oBatteryFilter); + oDialog.add_filter(oFlashFilter); + + #endif // ! GTKMM20 + + while (oDialog.run() == Gtk::RESPONSE_OK) + { + Gtk::MessageDialog oConfirmDialog(*this, + _("Importing a battery file will erase any saved games and reset the emulator. Do you want to continue?"), + #ifndef GTKMM20 + false, + #endif // ! GTKMM20 + Gtk::MESSAGE_QUESTION, + Gtk::BUTTONS_YES_NO); + if (oConfirmDialog.run() != Gtk::RESPONSE_YES) + { + continue; + } + + if (m_stEmulator.emuReadBattery(oDialog.get_filename().c_str())) + { + m_stEmulator.emuReset(); + break; + } + else + { + Gtk::MessageDialog oErrorDialog(*this, + _("Importing the battery file failed."), + #ifndef GTKMM20 + false, + #endif // ! GTKMM20 + Gtk::MESSAGE_ERROR, + Gtk::BUTTONS_CLOSE); + oErrorDialog.run(); + } + } + } + + void Window::vOnExportBatteryFile() + { + std::string sSaveDir = m_poDirConfig->sGetKey("saves"); + + #ifdef GTKMM20 + + Gtk::FileSelection oDialog(_("Export battery file")); + oDialog.set_transient_for(*this); + + if (sSaveDir == "") + { + oDialog.set_filename(Glib::path_get_dirname(m_sRomFile) + "/"); + } + else + { + oDialog.set_filename(sSaveDir + "/"); + } + + #else // ! GTKMM20 + + Gtk::FileChooserDialog oDialog(*this, _("Export battery file"), + Gtk::FILE_CHOOSER_ACTION_SAVE); + oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + oDialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); + + if (sSaveDir == "") + { + oDialog.set_current_folder(Glib::path_get_dirname(m_sRomFile)); + } + else + { + oDialog.set_current_folder(sSaveDir); + oDialog.add_shortcut_folder(sSaveDir); + } + + Gtk::FileFilter oBatteryFilter; + oBatteryFilter.set_name(_("Battery file")); + oBatteryFilter.add_pattern("*.[sS][aA][vV]"); + + Gtk::FileFilter oFlashFilter; + oFlashFilter.set_name(_("Flash save")); + oFlashFilter.add_pattern("*.[dD][aA][tT]"); + + oDialog.add_filter(oBatteryFilter); + oDialog.add_filter(oFlashFilter); + + #endif // ! GTKMM20 + + while (oDialog.run() == Gtk::RESPONSE_OK) + { + Glib::ustring sFile = oDialog.get_filename(); + Glib::ustring sExt; + + #ifdef GTKMM20 + + sExt = ".sav"; + + #else // ! GTKMM20 + + if (oDialog.get_filter() == &oBatteryFilter) + { + sExt = ".sav"; + } + else + { + sExt = ".dat"; + } + + #endif // ! GTKMM20 + + if (! bHasSuffix(sFile, sExt, false)) + { + sFile += sExt; + } + + if (Glib::file_test(sFile, Glib::FILE_TEST_EXISTS)) + { + Gtk::MessageDialog oConfirmDialog(*this, + _("File already exists. Overwrite it?"), + #ifndef GTKMM20 + false, + #endif // ! GTKMM20 + Gtk::MESSAGE_QUESTION, + Gtk::BUTTONS_YES_NO); + if (oConfirmDialog.run() != Gtk::RESPONSE_YES) + { + continue; + } + } + + bool bResult; + if (m_eCartridge == CartridgeGB) + { + bResult = gbWriteBatteryFile(sFile.c_str(), false); + } + else + { + bResult = m_stEmulator.emuWriteBattery(sFile.c_str()); + } + + if (bResult) + { + break; + } + else + { + Gtk::MessageDialog oErrorDialog(*this, + _("Exporting the battery file failed."), + #ifndef GTKMM20 + false, + #endif // ! GTKMM20 + Gtk::MESSAGE_ERROR, + Gtk::BUTTONS_CLOSE); + oErrorDialog.run(); + } + } + } + void Window::vOnFileClose() { *************** *** 996,1002 **** } - // TEST - printf("scan code: %hd\n", _pstEvent->hardware_keycode); - switch (eKey) { --- 1193,1196 ---- |