Successful test of loading ROM via QFileDialog, changed logic to not use native gnome file dialog as it is very lagged.

This commit is contained in:
Matthew Budd 2020-06-26 09:29:47 -04:00
parent d6ff002af0
commit f1153bfc6b
3 changed files with 165 additions and 121 deletions

View File

@ -1,5 +1,7 @@
// GameApp.cpp // GameApp.cpp
// //
#include <QFileDialog>
#include "GameApp.h" #include "GameApp.h"
#include "fceuWrapper.h" #include "fceuWrapper.h"
#include "keyscan.h" #include "keyscan.h"
@ -55,12 +57,12 @@ void gameWin_t::createMainMenu(void)
menuBar()->setNativeMenuBar(false); menuBar()->setNativeMenuBar(false);
fileMenu = menuBar()->addMenu(tr("&File")); fileMenu = menuBar()->addMenu(tr("&File"));
openAct = new QAction(tr("&Open"), this); openROM = new QAction(tr("&Open ROM"), this);
openAct->setShortcuts(QKeySequence::Open); openROM->setShortcuts(QKeySequence::Open);
openAct->setStatusTip(tr("Open an Existing File")); openROM->setStatusTip(tr("Open ROM File"));
connect(openAct, SIGNAL(triggered()), this, SLOT(openFile(void)) ); connect(openROM, SIGNAL(triggered()), this, SLOT(openROMFile(void)) );
fileMenu->addAction(openAct); fileMenu->addAction(openROM);
quitAct = new QAction(tr("&Quit"), this); quitAct = new QAction(tr("&Quit"), this);
quitAct->setStatusTip(tr("Quit the Application")); quitAct->setStatusTip(tr("Quit the Application"));
@ -77,9 +79,51 @@ void gameWin_t::createMainMenu(void)
helpMenu->addAction(aboutAct); helpMenu->addAction(aboutAct);
}; };
void gameWin_t::openFile(void) void gameWin_t::openROMFile(void)
{ {
printf("Open File\n"); int ret;
QString filename;
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(tr("All files (*.*) ;; NES files (*.nes)"));
dialog.setViewMode(QFileDialog::List);
// the gnome default file dialog is not playing nice with QT.
// TODO make this a config option to use native file dialog.
dialog.setOption(QFileDialog::DontUseNativeDialog, true);
dialog.show();
ret = dialog.exec();
if ( ret )
{
QStringList fileList;
fileList = dialog.selectedFiles();
if ( fileList.size() > 0 )
{
filename = fileList[0];
}
}
//filename = QFileDialog::getOpenFileName( this,
// "Open ROM File",
// QDir::currentPath(),
// "All files (*.*) ;; NES files (*.nes)");
if ( filename.isNull() )
{
return;
}
qDebug() << "selected file path : " << filename.toUtf8();
g_config->setOption ("SDL.LastOpenFile", filename.toStdString().c_str() );
CloseGame ();
LoadGame ( filename.toStdString().c_str() );
return; return;
} }
void gameWin_t::aboutQPlot(void) void gameWin_t::aboutQPlot(void)

View File

@ -32,7 +32,7 @@ class gameWin_t : public QMainWindow
QMenu *fileMenu; QMenu *fileMenu;
QMenu *helpMenu; QMenu *helpMenu;
QAction *openAct; QAction *openROM;
QAction *quitAct; QAction *quitAct;
QAction *aboutAct; QAction *aboutAct;
@ -46,7 +46,7 @@ class gameWin_t : public QMainWindow
void createMainMenu(void); void createMainMenu(void);
private slots: private slots:
void openFile(void); void openROMFile(void);
void aboutQPlot(void); void aboutQPlot(void);
void runGameFrame(void); void runGameFrame(void);

View File

@ -251,58 +251,58 @@ std::string GetFilename (const char *title, bool save, const char *filter)
fname = GetOpenFileName (&ofn); fname = GetOpenFileName (&ofn);
#endif #endif
#ifdef _GTK //#ifdef _GTK
int fullscreen = 0; // int fullscreen = 0;
g_config->getOption ("SDL.Fullscreen", &fullscreen); // g_config->getOption ("SDL.Fullscreen", &fullscreen);
if (fullscreen) // if (fullscreen)
ToggleFS (); // ToggleFS ();
//
GtkWidget *fileChooser; // GtkWidget *fileChooser;
//
GtkFileFilter *filterX; // GtkFileFilter *filterX;
GtkFileFilter *filterAll; // GtkFileFilter *filterAll;
//
filterX = gtk_file_filter_new (); // filterX = gtk_file_filter_new ();
gtk_file_filter_add_pattern (filterX, filter); // gtk_file_filter_add_pattern (filterX, filter);
gtk_file_filter_set_name (filterX, filter); // gtk_file_filter_set_name (filterX, filter);
//
//
filterAll = gtk_file_filter_new (); // filterAll = gtk_file_filter_new ();
gtk_file_filter_add_pattern (filterAll, "*"); // gtk_file_filter_add_pattern (filterAll, "*");
gtk_file_filter_set_name (filterAll, "All Files"); // gtk_file_filter_set_name (filterAll, "All Files");
//
if (save) // if (save)
fileChooser = gtk_file_chooser_dialog_new ("Save as", NULL, // fileChooser = gtk_file_chooser_dialog_new ("Save as", NULL,
GTK_FILE_CHOOSER_ACTION_SAVE, // GTK_FILE_CHOOSER_ACTION_SAVE,
"_Cancel", // "_Cancel",
GTK_RESPONSE_CANCEL, // GTK_RESPONSE_CANCEL,
"_Save", // "_Save",
GTK_RESPONSE_ACCEPT, NULL); // GTK_RESPONSE_ACCEPT, NULL);
else // else
fileChooser = gtk_file_chooser_dialog_new ("Open", NULL, // fileChooser = gtk_file_chooser_dialog_new ("Open", NULL,
GTK_FILE_CHOOSER_ACTION_OPEN, // GTK_FILE_CHOOSER_ACTION_OPEN,
"_Cancel", // "_Cancel",
GTK_RESPONSE_CANCEL, // GTK_RESPONSE_CANCEL,
"_Open", // "_Open",
GTK_RESPONSE_ACCEPT, NULL); // GTK_RESPONSE_ACCEPT, NULL);
//
// TODO: make file filters case insensitive // // TODO: make file filters case insensitive
//gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterX); // //gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterX);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fileChooser), filterAll); // gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fileChooser), filterAll);
int response = gtk_dialog_run (GTK_DIALOG (fileChooser)); // int response = gtk_dialog_run (GTK_DIALOG (fileChooser));
//
// flush gtk events // // flush gtk events
while (gtk_events_pending ()) // while (gtk_events_pending ())
gtk_main_iteration_do (TRUE); // gtk_main_iteration_do (TRUE);
//
if (response == GTK_RESPONSE_ACCEPT) // if (response == GTK_RESPONSE_ACCEPT)
fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); // fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser));
//
gtk_widget_destroy (fileChooser); // gtk_widget_destroy (fileChooser);
//
while (gtk_events_pending ()) // while (gtk_events_pending ())
gtk_main_iteration_do (TRUE); // gtk_main_iteration_do (TRUE);
#endif //#endif
FCEUI_ToggleEmulationPause (); FCEUI_ToggleEmulationPause ();
return fname; return fname;
} }
@ -319,62 +319,62 @@ std::string GetUserText (const char *title)
* TODO fix it * TODO fix it
*/ */
#if 0 #if 0
//
GtkWidget* d; // GtkWidget* d;
GtkWidget* entry; // GtkWidget* entry;
//
d = gtk_dialog_new_with_buttons(title, NULL, GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_OK); // d = gtk_dialog_new_with_buttons(title, NULL, GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_OK);
//
entry = gtk_entry_new(); // entry = gtk_entry_new();
//
GtkWidget* vbox = gtk_dialog_get_content_area(GTK_DIALOG(d)); // GtkWidget* vbox = gtk_dialog_get_content_area(GTK_DIALOG(d));
//
gtk_container_add(GTK_CONTAINER(vbox), entry); // gtk_container_add(GTK_CONTAINER(vbox), entry);
//
gtk_widget_show_all(d); // gtk_widget_show_all(d);
//
gtk_dialog_run(GTK_DIALOG(d)); // gtk_dialog_run(GTK_DIALOG(d));
//
// flush gtk events // // flush gtk events
while(gtk_events_pending()) // while(gtk_events_pending())
gtk_main_iteration_do(TRUE); // gtk_main_iteration_do(TRUE);
//
std::string input = gtk_entry_get_text(GTK_ENTRY(entry)); // std::string input = gtk_entry_get_text(GTK_ENTRY(entry));
//
if (FCEUI_EmulationPaused() == 0) // if (FCEUI_EmulationPaused() == 0)
FCEUI_ToggleEmulationPause(); // pause emulation // FCEUI_ToggleEmulationPause(); // pause emulation
//
int fullscreen = 0; // int fullscreen = 0;
g_config->getOption("SDL.Fullscreen", &fullscreen); // g_config->getOption("SDL.Fullscreen", &fullscreen);
if(fullscreen) // if(fullscreen)
ToggleFS(); // disable fullscreen emulation // ToggleFS(); // disable fullscreen emulation
//
FILE *fpipe; // FILE *fpipe;
std::string command = "zenity --entry --title=\""; // std::string command = "zenity --entry --title=\"";
command.append(title); // command.append(title);
command.append("\" --text=\""); // command.append("\" --text=\"");
command.append(title); // command.append(title);
command.append(":\""); // command.append(":\"");
//
if (!(fpipe = (FILE*)popen(command.c_str(),"r"))) // If fpipe is NULL // if (!(fpipe = (FILE*)popen(command.c_str(),"r"))) // If fpipe is NULL
FCEUD_PrintError("Pipe error on opening zenity"); // FCEUD_PrintError("Pipe error on opening zenity");
int c; // int c;
std::string input; // std::string input;
while((c = fgetc(fpipe))) // while((c = fgetc(fpipe)))
{ // {
if (c == EOF || c == '\n') // if (c == EOF || c == '\n')
break; // break;
input += c; // input += c;
} // }
pclose(fpipe); // pclose(fpipe);
gtk_widget_destroy(d); // gtk_widget_destroy(d);
//
//
while(gtk_events_pending()) // while(gtk_events_pending())
gtk_main_iteration_do(TRUE); // gtk_main_iteration_do(TRUE);
//
FCEUI_ToggleEmulationPause(); // unpause emulation // FCEUI_ToggleEmulationPause(); // unpause emulation
return input; // return input;
#endif // #if 0 #endif // #if 0
#endif #endif
return ""; return "";
@ -1643,10 +1643,10 @@ int DWaitButton (const uint8 * text, ButtConfig * bc, int wb, int *buttonConfigS
while (1) while (1)
{ {
int done = 0; int done = 0;
#ifdef _GTK //#ifdef _GTK
while (gtk_events_pending ()) // while (gtk_events_pending ())
gtk_main_iteration_do (FALSE); // gtk_main_iteration_do (FALSE);
#endif //#endif
while (SDL_PollEvent (&event)) while (SDL_PollEvent (&event))
{ {
done++; done++;