From b72cabd80e6f29ee90bf895a353560ec14b3ad7f Mon Sep 17 00:00:00 2001 From: bgk Date: Thu, 5 Jun 2008 16:31:38 +0000 Subject: [PATCH] GTK GUI: - Modified the directories dialog so that it uses GtkFileChooserButtons instead of just txt fields - The emulator won't try to write in the rom folder anymore by default, since it has no reason to be writable - Fixed the quicksave menu --- src/gtk/vba.glade | 257 ++---------------------------------- src/gtk/window.cpp | 84 ++++++------ src/gtk/window.h | 2 - src/gtk/windowcallbacks.cpp | 72 +++------- 4 files changed, 71 insertions(+), 344 deletions(-) diff --git a/src/gtk/vba.glade b/src/gtk/vba.glade index 19a94047..3c98bc94 100644 --- a/src/gtk/vba.glade +++ b/src/gtk/vba.glade @@ -1661,7 +1661,7 @@ True 5 - 4 + 2 True @@ -1674,10 +1674,9 @@ - + True - True - * + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER 1 @@ -1685,46 +1684,6 @@ GTK_EXPAND - - - True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-cancel - - - - - 2 - 3 - GTK_FILL - GTK_EXPAND - - - - - True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-open - - - - - 3 - 4 - GTK_FILL - GTK_EXPAND - - True @@ -1738,28 +1697,6 @@ GTK_EXPAND - - - True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-open - - - - - 3 - 4 - 1 - 2 - GTK_FILL - GTK_EXPAND - - True @@ -1774,10 +1711,9 @@ - + True - True - * + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER 1 @@ -1787,50 +1723,6 @@ GTK_EXPAND - - - True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-open - - - - - 3 - 4 - 2 - 3 - GTK_FILL - GTK_EXPAND - - - - - True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-cancel - - - - - 2 - 3 - 2 - 3 - GTK_FILL - GTK_EXPAND - - True @@ -1845,10 +1737,9 @@ - + True - True - * + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER 1 @@ -1858,50 +1749,6 @@ GTK_EXPAND - - - True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-cancel - - - - - 2 - 3 - 3 - 4 - GTK_FILL - GTK_EXPAND - - - - - True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-open - - - - - 3 - 4 - 3 - 4 - GTK_FILL - GTK_EXPAND - - True @@ -1916,10 +1763,9 @@ - + True - True - * + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER 1 @@ -1930,54 +1776,9 @@ - + True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-cancel - - - - - 2 - 3 - 4 - 5 - GTK_FILL - GTK_EXPAND - - - - - True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-open - - - - - 3 - 4 - 4 - 5 - GTK_FILL - GTK_EXPAND - - - - - True - True - * + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER 1 @@ -1987,28 +1788,6 @@ GTK_EXPAND - - - True - True - GTK_RELIEF_NONE - 0 - - - True - gtk-cancel - - - - - 2 - 3 - 1 - 2 - GTK_FILL - GTK_EXPAND - - 2 @@ -2019,21 +1798,11 @@ True GTK_BUTTONBOX_END - + True True True - gtk-cancel - True - -6 - - - - - True - True - True - gtk-ok + gtk-close True -5 diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 0be27483..e95b2bae 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -107,11 +107,11 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : // Get config // - vInitConfig(); - m_sUserDataDir = Glib::get_home_dir() + "/.gvba"; m_sConfigFile = m_sUserDataDir + "/config"; + vInitConfig(); + if (! Glib::file_test(m_sUserDataDir, Glib::FILE_TEST_EXISTS)) { mkdir(m_sUserDataDir.c_str(), 0777); @@ -180,7 +180,7 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : char csName[20]; snprintf(csName, 20, "LoadGameSlot%d", i + 1); m_apoLoadGameItem[i] = dynamic_cast(_poXml->get_widget(csName)); - snprintf(csName, 20, "LoadGameSlot%d", i + 1); + snprintf(csName, 20, "SaveGameSlot%d", i + 1); m_apoSaveGameItem[i] = dynamic_cast(_poXml->get_widget(csName)); m_apoLoadGameItem[i]->signal_activate().connect(sigc::bind( @@ -968,11 +968,11 @@ void Window::vInitConfig() // Directories section // m_poDirConfig = m_oConfig.poAddSection("Directories"); - m_poDirConfig->vSetKey("gb_roms", "" ); - m_poDirConfig->vSetKey("gba_roms", "" ); - m_poDirConfig->vSetKey("batteries", "" ); - m_poDirConfig->vSetKey("saves", "" ); - m_poDirConfig->vSetKey("captures", "" ); + m_poDirConfig->vSetKey("gb_roms", Glib::get_home_dir()); + m_poDirConfig->vSetKey("gba_roms", Glib::get_home_dir()); + m_poDirConfig->vSetKey("batteries", m_sUserDataDir); + m_poDirConfig->vSetKey("saves", m_sUserDataDir); + m_poDirConfig->vSetKey("captures", m_sUserDataDir); // Core section // @@ -1068,27 +1068,27 @@ void Window::vCheckConfig() sValue = m_poDirConfig->sGetKey("gb_roms"); if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR)) { - m_poDirConfig->vSetKey("gb_roms", ""); + m_poDirConfig->vSetKey("gb_roms", Glib::get_home_dir()); } sValue = m_poDirConfig->sGetKey("gba_roms"); if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR)) { - m_poDirConfig->vSetKey("gba_roms", ""); + m_poDirConfig->vSetKey("gba_roms", Glib::get_home_dir()); } sValue = m_poDirConfig->sGetKey("batteries"); if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR)) { - m_poDirConfig->vSetKey("batteries", ""); + m_poDirConfig->vSetKey("batteries", m_sUserDataDir); } sValue = m_poDirConfig->sGetKey("saves"); if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR)) { - m_poDirConfig->vSetKey("saves", ""); + m_poDirConfig->vSetKey("saves", m_sUserDataDir); } sValue = m_poDirConfig->sGetKey("captures"); if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR)) { - m_poDirConfig->vSetKey("captures", ""); + m_poDirConfig->vSetKey("captures", m_sUserDataDir); } // Core section @@ -1575,16 +1575,15 @@ void Window::vComputeFrameskip(int _iRate) void Window::vCaptureScreen(int _iNum) { std::string sBaseName; - std::string sCaptureDir = m_poDirConfig->sGetKey("captures"); - if (sCaptureDir == "") + std::string sDir = m_poDirConfig->sGetKey("captures"); + if (sDir == "") { - sBaseName = sCutSuffix(m_sRomFile); - } - else - { - sBaseName = sCaptureDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)); + sDir = m_sUserDataDir; } + sBaseName = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)); + + char * csFile = g_strdup_printf("%s_%02d.png", sBaseName.c_str(), _iNum); @@ -1625,16 +1624,23 @@ void Window::vCreateFileOpenDialog() poDialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); poDialog->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); - if (sGBDir != "") + try { - poDialog->add_shortcut_folder(sGBDir); - poDialog->set_current_folder(sGBDir); - } + if (sGBDir != "") + { + poDialog->add_shortcut_folder(sGBDir); + poDialog->set_current_folder(sGBDir); + } - if (sGBADir != "" && sGBADir != sGBDir) + if (sGBADir != "" && sGBADir != sGBDir) + { + poDialog->add_shortcut_folder(sGBADir); + poDialog->set_current_folder(sGBADir); + } + } + catch (const Gtk::FileChooserError& e) { - poDialog->add_shortcut_folder(sGBADir); - poDialog->set_current_folder(sGBADir); + // Most likely the shortcut already exists, so do nothing } const char * acsPattern[] = @@ -1681,13 +1687,11 @@ void Window::vLoadBattery() std::string sDir = m_poDirConfig->sGetKey("batteries"); if (sDir == "") { - sBattery = sCutSuffix(m_sRomFile) + ".sav"; - } - else - { - sBattery = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".sav"; + sDir = m_sUserDataDir; } + sBattery = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".sav"; + if (m_stEmulator.emuReadBattery(sBattery.c_str())) { systemScreenMessage(_("Loaded battery")); @@ -1700,13 +1704,11 @@ void Window::vSaveBattery() std::string sDir = m_poDirConfig->sGetKey("batteries"); if (sDir == "") { - sBattery = sCutSuffix(m_sRomFile) + ".sav"; - } - else - { - sBattery = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".sav"; + sDir = m_sUserDataDir; } + sBattery = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".sav"; + if (m_stEmulator.emuWriteBattery(sBattery.c_str())) { systemScreenMessage(_("Saved battery")); @@ -1792,13 +1794,11 @@ void Window::vUpdateGameSlots() std::string sDir = m_poDirConfig->sGetKey("saves"); if (sDir == "") { - sFileBase = sCutSuffix(m_sRomFile); - } - else - { - sFileBase = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)); + sDir = m_sUserDataDir; } + sFileBase = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)); + const char * csDateFormat = _("%Y/%m/%d %H:%M:%S"); for (int i = 0; i < 10; i++) diff --git a/src/gtk/window.h b/src/gtk/window.h index 41172fd9..37aa3218 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -162,8 +162,6 @@ protected: virtual void vOnVideoScaleToggled(Gtk::CheckMenuItem * _poCMI, int _iScale); virtual void vOnLayerToggled(Gtk::CheckMenuItem * _poCMI, int _iLayer); virtual void vOnDirectories(); - virtual void vOnDirectoryReset(Gtk::Entry * _poEntry); - virtual void vOnDirectorySelect(Gtk::Entry * _poEntry); virtual void vOnPauseWhenInactiveToggled(Gtk::CheckMenuItem * _poCMI); virtual void vOnSelectBios(); virtual void vOnUseBiosToggled(Gtk::CheckMenuItem * _poCMI); diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index 7e9af1e3..d8301d4b 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -618,82 +618,42 @@ void Window::vOnDirectories() struct { const char * m_csKey; - const char * m_csEntry; - const char * m_csResetButton; - const char * m_csSelectButton; + const char * m_csFileChooserButton; } astRow[] = { - { "gba_roms", "GBARomsDirEntry", "GBARomsDirResetButton", "GBARomsDirSelectButton" }, - { "gb_roms", "GBRomsDirEntry", "GBRomsDirResetButton", "GBRomsDirSelectButton" }, - { "batteries", "BatteriesDirEntry", "BatteriesDirResetButton", "BatteriesDirSelectButton" }, - { "saves", "SavesDirEntry", "SavesDirResetButton", "SavesDirSelectButton" }, - { "captures", "CapturesDirEntry", "CapturesDirResetButton", "CapturesDirSelectButton" } + { "gba_roms", "GBARomsDirEntry" }, + { "gb_roms", "GBRomsDirEntry" }, + { "batteries", "BatteriesDirEntry" }, + { "saves", "SavesDirEntry" }, + { "captures", "CapturesDirEntry" } }; for (guint i = 0; i < G_N_ELEMENTS(astRow); i++) { - Gtk::Entry * poEntry = dynamic_cast(poXml->get_widget(astRow[i].m_csEntry)); - Gtk::Button * poReset = dynamic_cast(poXml->get_widget(astRow[i].m_csResetButton)); - Gtk::Button * poSelect = dynamic_cast(poXml->get_widget(astRow[i].m_csSelectButton)); + Gtk::FileChooserButton * poFileChooserButton = dynamic_cast(poXml->get_widget(astRow[i].m_csFileChooserButton)); - poEntry->set_text(m_poDirConfig->sGetKey(astRow[i].m_csKey)); - - poReset->signal_clicked().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnDirectoryReset), - poEntry)); - poSelect->signal_clicked().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnDirectorySelect), - poEntry)); + poFileChooserButton->set_current_folder(m_poDirConfig->sGetKey(astRow[i].m_csKey)); } Gtk::Dialog * poDialog = dynamic_cast(poXml->get_widget("DirectoriesDialog")); poDialog->set_transient_for(*this); + poDialog->run(); - if (poDialog->run() == Gtk::RESPONSE_OK) + for (guint i = 0; i < G_N_ELEMENTS(astRow); i++) { - for (guint i = 0; i < G_N_ELEMENTS(astRow); i++) - { - Gtk::Entry * poEntry = dynamic_cast(poXml->get_widget(astRow[i].m_csEntry)); - Glib::ustring sDir = poEntry->get_text(); - if (! Glib::file_test(sDir, Glib::FILE_TEST_IS_DIR)) - { - sDir = ""; - } - m_poDirConfig->vSetKey(astRow[i].m_csKey, sDir); - } + Gtk::FileChooserButton * poFileChooserButton = dynamic_cast(poXml->get_widget(astRow[i].m_csFileChooserButton)); + Glib::ustring sDir = poFileChooserButton->get_current_folder(); - // Needed if saves dir changed - vUpdateGameSlots(); + m_poDirConfig->vSetKey(astRow[i].m_csKey, sDir); } + // Needed if saves dir changed + vUpdateGameSlots(); + delete poDialog; } -void Window::vOnDirectoryReset(Gtk::Entry * _poEntry) -{ - _poEntry->set_text(""); -} - -void Window::vOnDirectorySelect(Gtk::Entry * _poEntry) -{ - Gtk::FileChooserDialog oDialog(*this, _("Select directory"), - Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); - oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - oDialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); - - if (_poEntry->get_text() != "") - { - oDialog.add_shortcut_folder(_poEntry->get_text()); - oDialog.set_current_folder(_poEntry->get_text()); - } - - if (oDialog.run() == Gtk::RESPONSE_OK) - { - _poEntry->set_text(oDialog.get_filename()); - } -} - void Window::vOnPauseWhenInactiveToggled(Gtk::CheckMenuItem * _poCMI) { m_poDisplayConfig->vSetKey("pause_when_inactive", _poCMI->get_active());