Changeset - 1f31600a1b32
[Not reviewed]
recording
0 2 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-02-12 03:23:19
hy@ozderya.net
ask overwrite confirmation before asking new file selection
2 files changed with 42 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/recordpanel.cpp
Show inline comments
 
@@ -48,7 +48,7 @@ RecordPanel::RecordPanel(QWidget *parent
 
    connect(ui->pbBrowse, &QPushButton::clicked,
 
            this, &RecordPanel::selectFile);
 
    connect(&recordAction, &QAction::triggered,
 
            this, &RecordPanel::record);
 
            this, &RecordPanel::onRecord);
 
}
 

	
 
RecordPanel::~RecordPanel()
 
@@ -79,11 +79,19 @@ bool RecordPanel::selectFile()
 
    }
 
}
 

	
 
void RecordPanel::record(bool start)
 
void RecordPanel::onRecord(bool start)
 
{
 
    if (!start)
 
    {
 
        stopRecording();
 
        return;
 
    }
 

	
 
    // check file name
 
    bool canceled = false;
 
    if (selectedFile.isEmpty() && !selectFile())
 
    {
 
        return;
 
        canceled = true;
 
    }
 

	
 
    if (!overwriteSelected && QFile::exists(selectedFile))
 
@@ -91,20 +99,27 @@ void RecordPanel::record(bool start)
 
        if (ui->cbAutoIncrement->isChecked())
 
        {
 
            // TODO: should we increment even if user selected to replace?
 
            incrementFileName();
 
            canceled = !incrementFileName();
 
        }
 
        else
 
        {
 
            selectFile();
 
            canceled = !confirmOverwrite(selectedFile);
 
        }
 
    }
 

	
 
    overwriteSelected = false;
 

	
 
    // TODO: implement recording
 
    if (canceled)
 
    {
 
        recordAction.setChecked(false);
 
    }
 
    else
 
    {
 
        startRecording();
 
    }
 
}
 

	
 
bool RecordPanel::incrementFileName(void) {
 
bool RecordPanel::incrementFileName(void)
 
{
 
    QFileInfo fileInfo(selectedFile);
 

	
 
    QString base = fileInfo.completeBaseName();
 
@@ -153,11 +168,11 @@ bool RecordPanel::confirmOverwrite(QStri
 
    QMessageBox mb(parentWidget());
 
    mb.setWindowTitle(tr("File Already Exists"));
 
    mb.setIcon(QMessageBox::Warning);
 
    mb.setText(tr("Auto generated file name (%1) already exists. How to continue?").arg(fileName));
 
    mb.setText(tr("File (%1) already exists. How to continue?").arg(fileName));
 

	
 
    auto bCancel    = mb.addButton(QMessageBox::Cancel);
 
    auto bOverwrite = mb.addButton(tr("Overwrite"), QMessageBox::DestructiveRole);
 
    auto bSelect    = mb.addButton(tr("Select Another File"), QMessageBox::YesRole);
 
    mb.addButton(tr("Select Another File"), QMessageBox::YesRole);
 

	
 
    mb.setEscapeButton(bCancel);
 

	
 
@@ -173,8 +188,20 @@ bool RecordPanel::confirmOverwrite(QStri
 
        selectedFile = fileName;
 
        return true;
 
    }
 
    else                    // bSelect
 
    else                    // select button
 
    {
 
        return selectFile();
 
    }
 
}
 

	
 
void RecordPanel::startRecording(void)
 
{
 
    // TODO
 
    qDebug() << "start recording";
 
}
 

	
 
void RecordPanel::stopRecording(void)
 
{
 
    // TODO
 
    qDebug() << "stop recording";
 
}
src/recordpanel.h
Show inline comments
 
@@ -69,6 +69,9 @@ private:
 
     */
 
    bool confirmOverwrite(QString fileName);
 

	
 
    void startRecording(void);
 
    void stopRecording(void);
 

	
 
private slots:
 
    /**
 
     * @brief Opens up the file select dialog
 
@@ -80,7 +83,7 @@ private slots:
 
     */
 
    bool selectFile();
 

	
 
    void record(bool start);
 
    void onRecord(bool start);
 

	
 
};
 

	
0 comments (0 inline, 0 general)