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:
parent
d6ff002af0
commit
f1153bfc6b
|
@ -1,5 +1,7 @@
|
|||
// GameApp.cpp
|
||||
//
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "GameApp.h"
|
||||
#include "fceuWrapper.h"
|
||||
#include "keyscan.h"
|
||||
|
@ -55,12 +57,12 @@ void gameWin_t::createMainMenu(void)
|
|||
menuBar()->setNativeMenuBar(false);
|
||||
fileMenu = menuBar()->addMenu(tr("&File"));
|
||||
|
||||
openAct = new QAction(tr("&Open"), this);
|
||||
openAct->setShortcuts(QKeySequence::Open);
|
||||
openAct->setStatusTip(tr("Open an Existing File"));
|
||||
connect(openAct, SIGNAL(triggered()), this, SLOT(openFile(void)) );
|
||||
openROM = new QAction(tr("&Open ROM"), this);
|
||||
openROM->setShortcuts(QKeySequence::Open);
|
||||
openROM->setStatusTip(tr("Open ROM File"));
|
||||
connect(openROM, SIGNAL(triggered()), this, SLOT(openROMFile(void)) );
|
||||
|
||||
fileMenu->addAction(openAct);
|
||||
fileMenu->addAction(openROM);
|
||||
|
||||
quitAct = new QAction(tr("&Quit"), this);
|
||||
quitAct->setStatusTip(tr("Quit the Application"));
|
||||
|
@ -77,9 +79,51 @@ void gameWin_t::createMainMenu(void)
|
|||
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;
|
||||
}
|
||||
void gameWin_t::aboutQPlot(void)
|
||||
|
|
|
@ -32,7 +32,7 @@ class gameWin_t : public QMainWindow
|
|||
QMenu *fileMenu;
|
||||
QMenu *helpMenu;
|
||||
|
||||
QAction *openAct;
|
||||
QAction *openROM;
|
||||
QAction *quitAct;
|
||||
QAction *aboutAct;
|
||||
|
||||
|
@ -46,7 +46,7 @@ class gameWin_t : public QMainWindow
|
|||
void createMainMenu(void);
|
||||
|
||||
private slots:
|
||||
void openFile(void);
|
||||
void openROMFile(void);
|
||||
void aboutQPlot(void);
|
||||
void runGameFrame(void);
|
||||
|
||||
|
|
|
@ -251,58 +251,58 @@ std::string GetFilename (const char *title, bool save, const char *filter)
|
|||
fname = GetOpenFileName (&ofn);
|
||||
|
||||
#endif
|
||||
#ifdef _GTK
|
||||
int fullscreen = 0;
|
||||
g_config->getOption ("SDL.Fullscreen", &fullscreen);
|
||||
if (fullscreen)
|
||||
ToggleFS ();
|
||||
|
||||
GtkWidget *fileChooser;
|
||||
|
||||
GtkFileFilter *filterX;
|
||||
GtkFileFilter *filterAll;
|
||||
|
||||
filterX = gtk_file_filter_new ();
|
||||
gtk_file_filter_add_pattern (filterX, filter);
|
||||
gtk_file_filter_set_name (filterX, filter);
|
||||
|
||||
|
||||
filterAll = gtk_file_filter_new ();
|
||||
gtk_file_filter_add_pattern (filterAll, "*");
|
||||
gtk_file_filter_set_name (filterAll, "All Files");
|
||||
|
||||
if (save)
|
||||
fileChooser = gtk_file_chooser_dialog_new ("Save as", NULL,
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Save",
|
||||
GTK_RESPONSE_ACCEPT, NULL);
|
||||
else
|
||||
fileChooser = gtk_file_chooser_dialog_new ("Open", NULL,
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Open",
|
||||
GTK_RESPONSE_ACCEPT, NULL);
|
||||
|
||||
// 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), filterAll);
|
||||
int response = gtk_dialog_run (GTK_DIALOG (fileChooser));
|
||||
|
||||
// flush gtk events
|
||||
while (gtk_events_pending ())
|
||||
gtk_main_iteration_do (TRUE);
|
||||
|
||||
if (response == GTK_RESPONSE_ACCEPT)
|
||||
fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser));
|
||||
|
||||
gtk_widget_destroy (fileChooser);
|
||||
|
||||
while (gtk_events_pending ())
|
||||
gtk_main_iteration_do (TRUE);
|
||||
#endif
|
||||
//#ifdef _GTK
|
||||
// int fullscreen = 0;
|
||||
// g_config->getOption ("SDL.Fullscreen", &fullscreen);
|
||||
// if (fullscreen)
|
||||
// ToggleFS ();
|
||||
//
|
||||
// GtkWidget *fileChooser;
|
||||
//
|
||||
// GtkFileFilter *filterX;
|
||||
// GtkFileFilter *filterAll;
|
||||
//
|
||||
// filterX = gtk_file_filter_new ();
|
||||
// gtk_file_filter_add_pattern (filterX, filter);
|
||||
// gtk_file_filter_set_name (filterX, filter);
|
||||
//
|
||||
//
|
||||
// filterAll = gtk_file_filter_new ();
|
||||
// gtk_file_filter_add_pattern (filterAll, "*");
|
||||
// gtk_file_filter_set_name (filterAll, "All Files");
|
||||
//
|
||||
// if (save)
|
||||
// fileChooser = gtk_file_chooser_dialog_new ("Save as", NULL,
|
||||
// GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
// "_Cancel",
|
||||
// GTK_RESPONSE_CANCEL,
|
||||
// "_Save",
|
||||
// GTK_RESPONSE_ACCEPT, NULL);
|
||||
// else
|
||||
// fileChooser = gtk_file_chooser_dialog_new ("Open", NULL,
|
||||
// GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
// "_Cancel",
|
||||
// GTK_RESPONSE_CANCEL,
|
||||
// "_Open",
|
||||
// GTK_RESPONSE_ACCEPT, NULL);
|
||||
//
|
||||
// // 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), filterAll);
|
||||
// int response = gtk_dialog_run (GTK_DIALOG (fileChooser));
|
||||
//
|
||||
// // flush gtk events
|
||||
// while (gtk_events_pending ())
|
||||
// gtk_main_iteration_do (TRUE);
|
||||
//
|
||||
// if (response == GTK_RESPONSE_ACCEPT)
|
||||
// fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser));
|
||||
//
|
||||
// gtk_widget_destroy (fileChooser);
|
||||
//
|
||||
// while (gtk_events_pending ())
|
||||
// gtk_main_iteration_do (TRUE);
|
||||
//#endif
|
||||
FCEUI_ToggleEmulationPause ();
|
||||
return fname;
|
||||
}
|
||||
|
@ -319,62 +319,62 @@ std::string GetUserText (const char *title)
|
|||
* TODO fix it
|
||||
*/
|
||||
#if 0
|
||||
|
||||
GtkWidget* d;
|
||||
GtkWidget* entry;
|
||||
|
||||
d = gtk_dialog_new_with_buttons(title, NULL, GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_OK);
|
||||
|
||||
entry = gtk_entry_new();
|
||||
|
||||
GtkWidget* vbox = gtk_dialog_get_content_area(GTK_DIALOG(d));
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(vbox), entry);
|
||||
|
||||
gtk_widget_show_all(d);
|
||||
|
||||
gtk_dialog_run(GTK_DIALOG(d));
|
||||
|
||||
// flush gtk events
|
||||
while(gtk_events_pending())
|
||||
gtk_main_iteration_do(TRUE);
|
||||
|
||||
std::string input = gtk_entry_get_text(GTK_ENTRY(entry));
|
||||
|
||||
if (FCEUI_EmulationPaused() == 0)
|
||||
FCEUI_ToggleEmulationPause(); // pause emulation
|
||||
|
||||
int fullscreen = 0;
|
||||
g_config->getOption("SDL.Fullscreen", &fullscreen);
|
||||
if(fullscreen)
|
||||
ToggleFS(); // disable fullscreen emulation
|
||||
|
||||
FILE *fpipe;
|
||||
std::string command = "zenity --entry --title=\"";
|
||||
command.append(title);
|
||||
command.append("\" --text=\"");
|
||||
command.append(title);
|
||||
command.append(":\"");
|
||||
|
||||
if (!(fpipe = (FILE*)popen(command.c_str(),"r"))) // If fpipe is NULL
|
||||
FCEUD_PrintError("Pipe error on opening zenity");
|
||||
int c;
|
||||
std::string input;
|
||||
while((c = fgetc(fpipe)))
|
||||
{
|
||||
if (c == EOF || c == '\n')
|
||||
break;
|
||||
input += c;
|
||||
}
|
||||
pclose(fpipe);
|
||||
gtk_widget_destroy(d);
|
||||
|
||||
|
||||
while(gtk_events_pending())
|
||||
gtk_main_iteration_do(TRUE);
|
||||
|
||||
FCEUI_ToggleEmulationPause(); // unpause emulation
|
||||
return input;
|
||||
//
|
||||
// GtkWidget* d;
|
||||
// GtkWidget* entry;
|
||||
//
|
||||
// d = gtk_dialog_new_with_buttons(title, NULL, GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_OK);
|
||||
//
|
||||
// entry = gtk_entry_new();
|
||||
//
|
||||
// GtkWidget* vbox = gtk_dialog_get_content_area(GTK_DIALOG(d));
|
||||
//
|
||||
// gtk_container_add(GTK_CONTAINER(vbox), entry);
|
||||
//
|
||||
// gtk_widget_show_all(d);
|
||||
//
|
||||
// gtk_dialog_run(GTK_DIALOG(d));
|
||||
//
|
||||
// // flush gtk events
|
||||
// while(gtk_events_pending())
|
||||
// gtk_main_iteration_do(TRUE);
|
||||
//
|
||||
// std::string input = gtk_entry_get_text(GTK_ENTRY(entry));
|
||||
//
|
||||
// if (FCEUI_EmulationPaused() == 0)
|
||||
// FCEUI_ToggleEmulationPause(); // pause emulation
|
||||
//
|
||||
// int fullscreen = 0;
|
||||
// g_config->getOption("SDL.Fullscreen", &fullscreen);
|
||||
// if(fullscreen)
|
||||
// ToggleFS(); // disable fullscreen emulation
|
||||
//
|
||||
// FILE *fpipe;
|
||||
// std::string command = "zenity --entry --title=\"";
|
||||
// command.append(title);
|
||||
// command.append("\" --text=\"");
|
||||
// command.append(title);
|
||||
// command.append(":\"");
|
||||
//
|
||||
// if (!(fpipe = (FILE*)popen(command.c_str(),"r"))) // If fpipe is NULL
|
||||
// FCEUD_PrintError("Pipe error on opening zenity");
|
||||
// int c;
|
||||
// std::string input;
|
||||
// while((c = fgetc(fpipe)))
|
||||
// {
|
||||
// if (c == EOF || c == '\n')
|
||||
// break;
|
||||
// input += c;
|
||||
// }
|
||||
// pclose(fpipe);
|
||||
// gtk_widget_destroy(d);
|
||||
//
|
||||
//
|
||||
// while(gtk_events_pending())
|
||||
// gtk_main_iteration_do(TRUE);
|
||||
//
|
||||
// FCEUI_ToggleEmulationPause(); // unpause emulation
|
||||
// return input;
|
||||
#endif // #if 0
|
||||
#endif
|
||||
return "";
|
||||
|
@ -1643,10 +1643,10 @@ int DWaitButton (const uint8 * text, ButtConfig * bc, int wb, int *buttonConfigS
|
|||
while (1)
|
||||
{
|
||||
int done = 0;
|
||||
#ifdef _GTK
|
||||
while (gtk_events_pending ())
|
||||
gtk_main_iteration_do (FALSE);
|
||||
#endif
|
||||
//#ifdef _GTK
|
||||
// while (gtk_events_pending ())
|
||||
// gtk_main_iteration_do (FALSE);
|
||||
//#endif
|
||||
while (SDL_PollEvent (&event))
|
||||
{
|
||||
done++;
|
||||
|
|
Loading…
Reference in New Issue