UBUpdateDlg.cpp 2.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#include <QMessageBox>
#include <QFileDialog>

#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)
    {
64
        qsMsg = tr("Files update successful!\nPlease reboot the application to access the updated documents.");
65 66 67 68 69 70 71 72 73 74 75 76
    }
    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();
}