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