added thread that imports olds Uniboard/Sankore documents

preferencesAboutTextFull
Claudio Valerio 14 years ago
parent 3f7d47e2ec
commit 5956b9882c
  1. 155
      src/gui/UBUpdateDlg.cpp
  2. 23
      src/gui/UBUpdateDlg.h
  3. 38
      src/transition/UniboardSankoreTransition.cpp
  4. 15
      src/transition/UniboardSankoreTransition.h

@ -4,56 +4,161 @@
#include "UBUpdateDlg.h"
#include "core/memcheck.h"
#include <../Trolltech/Qt-4.7.0/include/QtWebKit/qwebpage.h>
UBUpdateDlg::UBUpdateDlg(QWidget *parent, int nbFiles, const QString& bkpPath)
: QDialog(parent)
, mpDlgBttn(NULL)
: QDialog(parent)
, mMainLayout(NULL)
, mNbFilesLabel(NULL)
, mBkpLabel(NULL)
, mBkpPath(NULL)
, mBrowseBttn(NULL)
, mpDlgBttn(NULL)
, mLayout(NULL)
, mHLayout(NULL)
, mStackedWidget(NULL)
, mDialogWidget(NULL)
, mProgressWidget(NULL)
, mProgressLayout(NULL)
, mProgressLabel(NULL)
{
setFixedSize(400, 110);
mDialogWidget = new QWidget(this);
mProgressWidget = new QWidget(this);
mStackedWidget = new QStackedWidget(this);
mStackedWidget->addWidget(mDialogWidget);
mStackedWidget->addWidget(mProgressWidget);
setFixedSize(450, 110);
setModal(true);
setWindowTitle(tr("Document updater"));
setLayout(&mLayout);
mLayout = new QVBoxLayout();
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);
mNbFilesLabel = new QLabel(mDialogWidget);
mNbFilesLabel->setText(str);
mLayout->addWidget(mNbFilesLabel);
mBkpLabel = new QLabel(mDialogWidget);
mBkpLabel->setText(tr("Backup path: "));
mBkpPath = new QLineEdit(mDialogWidget);
mBkpPath->setText(bkpPath);
mBrowseBttn = new QPushButton(mDialogWidget);
mBrowseBttn->setText(tr("Browse"));
mHLayout = new QHBoxLayout();
mHLayout->addWidget(mBkpLabel);
mHLayout->addWidget(mBkpPath, 1);
mHLayout->addWidget(mBrowseBttn);
mLayout->addLayout(mHLayout);
mpDlgBttn = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, mDialogWidget);
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(mBrowseBttn, SIGNAL(clicked()), this, SLOT(onBrowse()));
QObject::connect(mpDlgBttn, SIGNAL(accepted()), this, SLOT(onUpdate()));
QObject::connect(mpDlgBttn, SIGNAL(rejected()), this, SLOT(reject()));
mDialogWidget->setLayout(mLayout);
mStackedWidget->setCurrentWidget(mDialogWidget);
mMainLayout = new QVBoxLayout();
this->setLayout(mMainLayout);
mMainLayout->addWidget(mStackedWidget);
}
UBUpdateDlg::~UBUpdateDlg()
{
if(NULL != mpDlgBttn)
if (NULL != mpDlgBttn)
{
delete mpDlgBttn;
mpDlgBttn = NULL;
}
if (mNbFilesLabel) {
delete mNbFilesLabel;
mNbFilesLabel = NULL;
}
if (mBkpLabel) {
delete mBkpLabel;
mBkpLabel = NULL;
}
if (mBkpPath) {
delete mBkpPath;
mBkpPath = NULL;
}
if (mBrowseBttn) {
delete mBrowseBttn;
mBrowseBttn = NULL;
}
if (mProgressLabel) {
delete mProgressLabel;
mProgressLabel = NULL;
}
if (mHLayout) {
delete mHLayout;
mHLayout = NULL;
}
if (mLayout) {
delete mLayout;
mLayout = NULL;
}
if (mProgressLayout) {
delete mProgressLayout;
mProgressLayout = NULL;
}
if (mDialogWidget) {
delete mDialogWidget;
mDialogWidget = NULL;
}
if (mProgressWidget) {
delete mProgressWidget;
mProgressWidget = NULL;
}
if (mStackedWidget) {
delete mStackedWidget;
mStackedWidget = NULL;
}
if (mMainLayout) {
delete mMainLayout;
mMainLayout = NULL;
}
}
void UBUpdateDlg::onBrowse()
{
QString qsSelectedDir;
qsSelectedDir = QFileDialog::getExistingDirectory(this, tr("Select a backup folder"), mBkpPath.text());
mBkpPath.setText(qsSelectedDir);
qsSelectedDir = QFileDialog::getExistingDirectory(this, tr("Select a backup folder"), mBkpPath->text());
mBkpPath->setText(qsSelectedDir);
}
void UBUpdateDlg::onUpdate()
{
mProgressLabel = new QLabel(mProgressWidget);
mProgressLayout = new QHBoxLayout();
mProgressLayout->addWidget(mProgressLabel);
mProgressWidget->setLayout(mProgressLayout);
mStackedWidget->setCurrentWidget(mProgressWidget);
emit updateFiles();
}
@ -61,7 +166,7 @@ void UBUpdateDlg::onFilesUpdated(bool bResult)
{
QString qsMsg;
if(bResult)
if (bResult)
{
qsMsg = tr("Files update successful!\nPlease reboot the application to access the updated documents.");
}
@ -74,5 +179,11 @@ void UBUpdateDlg::onFilesUpdated(bool bResult)
QString UBUpdateDlg::backupPath()
{
return mBkpPath.text();
return mBkpPath->text();
}
void UBUpdateDlg::transitioningFile(QString fileName)
{
mProgressLabel->setText(tr("Updating file ") + fileName);
}

@ -8,6 +8,7 @@
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QStackedWidget>
class UBUpdateDlg : public QDialog
{
@ -27,15 +28,25 @@ signals:
private slots:
void onBrowse();
void onUpdate();
void transitioningFile(QString fileName);
private:
QLabel mNbFilesLabel;
QLabel mBkpLabel;
QLineEdit mBkpPath;
QPushButton mBrowseBttn;
QVBoxLayout* mMainLayout;
QLabel* mNbFilesLabel;
QLabel* mBkpLabel;
QLineEdit* mBkpPath;
QPushButton* mBrowseBttn;
QDialogButtonBox* mpDlgBttn;
QVBoxLayout mLayout;
QHBoxLayout mHLayout;
QVBoxLayout* mLayout;
QHBoxLayout* mHLayout;
QStackedWidget* mStackedWidget;
QWidget* mDialogWidget;
QWidget* mProgressWidget;
QHBoxLayout* mProgressLayout;
QLabel* mProgressLabel;
};
#endif // UBUPDATEDLG_H

@ -7,10 +7,10 @@
UniboardSankoreTransition::UniboardSankoreTransition(QObject *parent) :
QObject(parent)
, mTransitionDlg(NULL)
, mTransitionDlg(NULL)
, mThread(NULL)
{
mOldSankoreDirectory = UBFileSystemUtils::normalizeFilePath(UBDesktopServices::storageLocation(QDesktopServices::DataLocation));
qDebug() << mOldSankoreDirectory;
mUniboardSourceDirectory = UBFileSystemUtils::normalizeFilePath(UBDesktopServices::storageLocation(QDesktopServices::DataLocation));
#if defined(Q_WS_MACX)
@ -28,6 +28,11 @@ UniboardSankoreTransition::~UniboardSankoreTransition()
delete mTransitionDlg;
mTransitionDlg = NULL;
}
if(mThread){
delete mThread;
mThread = NULL;
}
}
void UniboardSankoreTransition::rollbackDocumentsTransition(QFileInfoList& fileInfoList)
@ -56,7 +61,7 @@ void UniboardSankoreTransition::documentTransition()
QString backupDirectoryPath = UBFileSystemUtils::normalizeFilePath(UBDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
if (fileInfoList.count() != 0){
mTransitionDlg = new UBUpdateDlg(0, fileInfoList.count(), backupDirectoryPath);
mTransitionDlg = new UBUpdateDlg(NULL, fileInfoList.count(), backupDirectoryPath);
connect(mTransitionDlg, SIGNAL(updateFiles()), this, SLOT(startDocumentTransition()));
connect(this, SIGNAL(transitionFinished(bool)), mTransitionDlg, SLOT(onFilesUpdated(bool)));
mTransitionDlg->show();
@ -65,6 +70,13 @@ void UniboardSankoreTransition::documentTransition()
}
void UniboardSankoreTransition::startDocumentTransition()
{
mThread = new UniboardSankoreThread(this);
mThread->start();
connect(this,SIGNAL(transitioningFile(QString)),mTransitionDlg,SLOT(transitioningFile(QString)));
}
void UniboardSankoreTransition::executeTransition()
{
bool result = false;
QString backupDestinationPath = mTransitionDlg->backupPath() + "/OldSankoreAndUniboardVersionsBackup";
@ -83,6 +95,7 @@ void UniboardSankoreTransition::startDocumentTransition()
for (fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end() && result; fileInfo += 1) {
if (fileInfo->isDir() && (fileInfo->fileName().startsWith("Uniboard Document ") || fileInfo->fileName().startsWith("Sankore Document "))){
QString sankoreDocumentName = fileInfo->fileName();
emit transitioningFile(sankoreDocumentName);
sankoreDocumentName.replace("Uniboard","Sankore");
result = UBFileSystemUtils::copyDir(fileInfo->filePath(),sankoreDocumentDirectory + "/" + sankoreDocumentName);
qslNewDocs << sankoreDocumentName;
@ -103,3 +116,22 @@ void UniboardSankoreTransition::startDocumentTransition()
mTransitionDlg->hide();
}
UniboardSankoreThread::UniboardSankoreThread(QObject* parent):QThread(parent)
{
}
UniboardSankoreThread::~UniboardSankoreThread()
{
}
void UniboardSankoreThread::run()
{
UniboardSankoreTransition* pTransition = dynamic_cast<UniboardSankoreTransition*>(parent());
pTransition->executeTransition();
}

@ -3,9 +3,21 @@
#include <QObject>
#include <QFileInfo>
#include <QThread>
#include "gui/UBUpdateDlg.h"
#include "document/UBDocumentProxy.h"
class UniboardSankoreThread : public QThread
{
Q_OBJECT
public:
UniboardSankoreThread(QObject* parent = 0);
~UniboardSankoreThread();
void run();
};
class UniboardSankoreTransition : public QObject
{
Q_OBJECT
@ -13,6 +25,7 @@ public:
explicit UniboardSankoreTransition(QObject *parent = 0);
~UniboardSankoreTransition();
void documentTransition();
void executeTransition();
private:
@ -22,10 +35,12 @@ private:
protected:
QString mUniboardSourceDirectory;
QString mOldSankoreDirectory;
UniboardSankoreThread* mThread;
signals:
void transitionFinished(bool result);
void docAdded(UBDocumentProxy* doc);
void transitioningFile(QString documentName);
private slots:
void startDocumentTransition();

Loading…
Cancel
Save