Save/Open Session - refactor supportedFileTypes() to accept operation - Open/Save as input parameter and return file types accordingly
This commit is contained in:
parent
93dbe8e118
commit
822ee2a4b4
@ -145,7 +145,8 @@ void MainWindow::on_actionOpenSession_triggered()
|
||||
|
||||
static QString dirName;
|
||||
QString fileName;
|
||||
QStringList fileTypes = SessionFileFormat::supportedFileTypes();
|
||||
QStringList fileTypes = SessionFileFormat::supportedFileTypes(
|
||||
SessionFileFormat::kOpenFile);
|
||||
QString fileType;
|
||||
QString errorStr;
|
||||
bool ret;
|
||||
@ -159,7 +160,6 @@ void MainWindow::on_actionOpenSession_triggered()
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
fileTypes.append("All files (*)");
|
||||
if (fileTypes.size())
|
||||
fileType = fileTypes.at(0);
|
||||
|
||||
@ -193,7 +193,8 @@ void MainWindow::on_actionSaveSession_triggered()
|
||||
qDebug("Save Session Action");
|
||||
|
||||
static QString fileName;
|
||||
QStringList fileTypes = SessionFileFormat::supportedFileTypes();
|
||||
QStringList fileTypes = SessionFileFormat::supportedFileTypes(
|
||||
SessionFileFormat::kSaveFile);
|
||||
QString fileType;
|
||||
QString errorStr;
|
||||
QFileDialog::Options options;
|
||||
|
@ -42,10 +42,16 @@ QDialog* SessionFileFormat::saveOptionsDialog()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
QStringList SessionFileFormat::supportedFileTypes()
|
||||
QStringList SessionFileFormat::supportedFileTypes(Operation op)
|
||||
{
|
||||
return QStringList()
|
||||
<< "Ostinato Session (*.ossn)";
|
||||
QStringList fileTypes;
|
||||
|
||||
fileTypes << "Ostinato Session (*.ossn)";
|
||||
|
||||
if (op == kOpenFile)
|
||||
fileTypes << "All files (*)";
|
||||
|
||||
return fileTypes;
|
||||
}
|
||||
|
||||
void SessionFileFormat::openAsync(const QString fileName,
|
||||
@ -54,7 +60,7 @@ void SessionFileFormat::openAsync(const QString fileName,
|
||||
fileName_ = fileName;
|
||||
openSession_ = &session;
|
||||
error_ = &error;
|
||||
op_ = kOpen;
|
||||
op_ = kOpenFile;
|
||||
stop_ = false;
|
||||
|
||||
start();
|
||||
@ -67,7 +73,7 @@ void SessionFileFormat::saveAsync(
|
||||
saveSession_ = &session;
|
||||
fileName_ = fileName;
|
||||
error_ = &error;
|
||||
op_ = kSave;
|
||||
op_ = kSaveFile;
|
||||
stop_ = false;
|
||||
|
||||
start();
|
||||
@ -104,8 +110,8 @@ void SessionFileFormat::cancel()
|
||||
|
||||
void SessionFileFormat::run()
|
||||
{
|
||||
if (op_ == kOpen)
|
||||
if (op_ == kOpenFile)
|
||||
result_ = open(fileName_, *openSession_, *error_);
|
||||
else if (op_ == kSave)
|
||||
else if (op_ == kSaveFile)
|
||||
result_ = save(*saveSession_, fileName_, *error_);
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ class SessionFileFormat : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Operation { kOpenFile, kSaveFile };
|
||||
|
||||
SessionFileFormat();
|
||||
virtual ~SessionFileFormat();
|
||||
|
||||
@ -50,7 +52,7 @@ public:
|
||||
|
||||
bool result();
|
||||
|
||||
static QStringList supportedFileTypes();
|
||||
static QStringList supportedFileTypes(Operation op);
|
||||
|
||||
static SessionFileFormat* fileFormatFromFile(const QString fileName);
|
||||
static SessionFileFormat* fileFormatFromType(const QString fileType);
|
||||
@ -72,16 +74,11 @@ protected:
|
||||
bool stop_;
|
||||
|
||||
private:
|
||||
enum kOp {
|
||||
kOpen,
|
||||
kSave
|
||||
};
|
||||
|
||||
QString fileName_;
|
||||
OstProto::SessionContent *openSession_;
|
||||
const OstProto::SessionContent *saveSession_;
|
||||
QString *error_;
|
||||
kOp op_;
|
||||
Operation op_;
|
||||
bool result_;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user