Changeset - 24c9f6ea4d9d
[Not reviewed]
recording
0 3 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-02-08 16:39:00
hy@ozderya.net
implemented file selection and auto incrementing
3 files changed with 97 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/recordpanel.cpp
Show inline comments
 
@@ -21,6 +21,12 @@
 
#include "ui_recordpanel.h"
 

	
 
#include <QIcon>
 
#include <QFile>
 
#include <QFileInfo>
 
#include <QFileDialog>
 
#include <QRegularExpression>
 

	
 
#include <QtDebug>
 

	
 
RecordPanel::RecordPanel(QWidget *parent) :
 
    QWidget(parent),
 
@@ -30,11 +36,16 @@ RecordPanel::RecordPanel(QWidget *parent
 
{
 
    ui->setupUi(this);
 

	
 
    recordToolBar.setObjectName("tbRecord");
 

	
 
    recordAction.setCheckable(true);
 
    recordToolBar.addAction(&recordAction);
 
    ui->pbRecord->setDefaultAction(&recordAction);
 

	
 
    recordToolBar.setObjectName("tbRecord");
 
    connect(ui->pbBrowse, &QPushButton::clicked,
 
            this, &RecordPanel::selectFile);
 
    connect(&recordAction, &QAction::triggered,
 
            this, &RecordPanel::record);
 
}
 

	
 
RecordPanel::~RecordPanel()
 
@@ -46,3 +57,63 @@ QToolBar* RecordPanel::toolbar()
 
{
 
    return &recordToolBar;
 
}
 

	
 
bool RecordPanel::selectFile()
 
{
 
    QString fileName = QFileDialog::getSaveFileName(
 
        parentWidget(), tr("Select recording file"));
 

	
 
    if (fileName.isEmpty())
 
    {
 
        return false;
 
    }
 
    else
 
    {
 
        selectedFile = fileName;
 
        ui->lbFileName->setText(selectedFile);
 
        return true;
 
    }
 
}
 

	
 

	
 
void RecordPanel::record(bool start)
 
{
 
    if (selectedFile.isEmpty() && !selectFile())
 
    {
 
        return;
 
    }
 

	
 
    if (QFile::exists(selectedFile))
 
    {
 
        if (ui->cbAutoIncrement->isChecked())
 
        {
 
            // TODO: should we increment even if user selected to replace?
 
            incrementFileName();
 
        }
 
    }
 

	
 
    // TODO: implement recording
 
}
 

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

	
 
    QString base = fileInfo.completeBaseName();
 
    QRegularExpression regex("(.*?)(\\d+)(?!.*\\d)(.*)");
 
    auto match = regex.match(base);
 

	
 
    if (match.hasMatch())
 
    {
 
        bool ok;
 
        int fileNum = match.captured(2).toInt(&ok);
 
        base = match.captured(1) + QString::number(fileNum + 1) + match.captured(3);
 
    }
 
    else
 
    {
 
        base += "_1";
 
    }
 

	
 
    // TODO: check if new name exists as well!
 
    selectedFile = fileInfo.path() + "/" + base + fileInfo.suffix();
 
    ui->lbFileName->setText(selectedFile);
 
}
src/recordpanel.h
Show inline comments
 
@@ -21,6 +21,7 @@
 
#define RECORDPANEL_H
 

	
 
#include <QWidget>
 
#include <QString>
 
#include <QToolBar>
 
#include <QAction>
 

	
 
@@ -42,6 +43,29 @@ private:
 
    Ui::RecordPanel *ui;
 
    QToolBar recordToolBar;
 
    QAction recordAction;
 
    QString selectedFile;
 

	
 
    /**
 
     * @brief Increments the file name.
 
     *
 
     * If file name doesn't have a number at the end of it, a number is appended
 
     * with underscore starting from 1.
 
     */
 
    void incrementFileName(void);
 

	
 
private slots:
 
    /**
 
     * @brief Opens up the file select dialog
 
     *
 
     * If you cancel the selection operation, currently selected file is not
 
     * changed.
 
     *
 
     * @return true if file selected, false if user cancels
 
     */
 
    bool selectFile();
 

	
 
    void record(bool start);
 

	
 
};
 

	
 
#endif // RECORDPANEL_H
src/recordpanel.ui
Show inline comments
 
@@ -19,7 +19,7 @@
 
     <item>
 
      <layout class="QHBoxLayout" name="horizontalLayout">
 
       <item>
 
        <widget class="QPushButton" name="cbBrowse">
 
        <widget class="QPushButton" name="pbBrowse">
 
         <property name="toolTip">
 
          <string>Select record file</string>
 
         </property>
0 comments (0 inline, 0 general)