diff --git a/src/gui/UBUpdateDlg.cpp b/src/gui/UBUpdateDlg.cpp new file mode 100644 index 00000000..23922a85 --- /dev/null +++ b/src/gui/UBUpdateDlg.cpp @@ -0,0 +1,76 @@ +#include +#include + +#include "UBUpdateDlg.h" + +UBUpdateDlg::UBUpdateDlg(QWidget *parent, int nbFiles, const QString& bkpPath) + : QDialog(parent) + , mpDlgBttn(NULL) +{ + setFixedSize(400, 110); + setModal(true); + setWindowTitle(tr("Document updater")); + setLayout(&mLayout); + QString str = QString::number(nbFiles); + str.append(tr(" files require an update.")); + mNbFilesLabel.setText(str); + mLayout.addWidget(&mNbFilesLabel); + mBkpLabel.setText(tr("Backup path: ")); + mBkpPath.setText(bkpPath); + mBrowseBttn.setText(tr("Browse")); + mHLayout.addWidget(&mBkpLabel); + mHLayout.addWidget(&mBkpPath, 1); + mHLayout.addWidget(&mBrowseBttn); + mLayout.addLayout(&mHLayout); + + mpDlgBttn = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); + mLayout.addWidget(mpDlgBttn); + + mpDlgBttn->button(QDialogButtonBox::Ok)->setText(tr("Update")); + mpDlgBttn->button(QDialogButtonBox::Cancel)->setText("Remind me later"); + + QObject::connect(&mBrowseBttn, SIGNAL(clicked()), this, SLOT(onBrowse())); + QObject::connect(mpDlgBttn, SIGNAL(accepted()), this, SLOT(onUpdate())); + QObject::connect(mpDlgBttn, SIGNAL(rejected()), this, SLOT(reject())); +} + +UBUpdateDlg::~UBUpdateDlg() +{ + if(NULL != mpDlgBttn) + { + delete mpDlgBttn; + mpDlgBttn = NULL; + } +} + +void UBUpdateDlg::onBrowse() +{ + QString qsSelectedDir; + qsSelectedDir = QFileDialog::getExistingDirectory(this, tr("Select a backup folder"), mBkpPath.text()); + mBkpPath.setText(qsSelectedDir); +} + +void UBUpdateDlg::onUpdate() +{ + emit updateFiles(); +} + +void UBUpdateDlg::onFilesUpdated(bool bResult) +{ + QString qsMsg; + + if(bResult) + { + qsMsg = tr("Files update successful"); + } + else + { + qsMsg = tr("An error occured during the update. The files have not been affected."); + } + QMessageBox::information(this, tr("Files update results"), qsMsg, QMessageBox::Ok); +} + +QString UBUpdateDlg::backupPath() +{ + return mBkpPath.text(); +} diff --git a/src/gui/UBUpdateDlg.h b/src/gui/UBUpdateDlg.h new file mode 100644 index 00000000..ea87d5ac --- /dev/null +++ b/src/gui/UBUpdateDlg.h @@ -0,0 +1,41 @@ +#ifndef UBUPDATEDLG_H +#define UBUPDATEDLG_H + +#include +#include +#include +#include +#include +#include +#include + +class UBUpdateDlg : public QDialog +{ + Q_OBJECT + +public: + UBUpdateDlg(QWidget *parent = 0, int nbFiles = 0, const QString& bkpPath = ""); + ~UBUpdateDlg(); + QString backupPath(); + +public slots: + void onFilesUpdated(bool bResult); + +signals: + void updateFiles(); + +private slots: + void onBrowse(); + void onUpdate(); + +private: + QLabel mNbFilesLabel; + QLabel mBkpLabel; + QLineEdit mBkpPath; + QPushButton mBrowseBttn; + QDialogButtonBox* mpDlgBttn; + QVBoxLayout mLayout; + QHBoxLayout mHLayout; +}; + +#endif // UBUPDATEDLG_H