17 #include "ui_DataMigrationWidget.h"
22 #include <QDirIterator>
27 #include <QProgressDialog>
53 QDir currentLocalDir( currentLocalPath );
54 if( currentLocalDir.
entryList( QDir::AllEntries | QDir::NoDotAndDotDot ).
size() != 0 ) {
58 foreach(
const QString& oldLocalPath, oldLocalPaths ) {
59 QDir oldLocalDir( oldLocalPath );
61 if( oldLocalDir.
entryList( QDir::AllEntries | QDir::NoDotAndDotDot ).
size() == 0 ) {
66 Ui::DataMigrationWidget dataMigrationWidget;
68 dataMigrationWidget.setupUi( dialog );
69 if( dialog->exec() == QDialog::Accepted ) {
70 DataMigration::moveFiles( oldLocalPath, currentLocalPath );
78 void DataMigration::moveFiles(
const QString& source,
const QString& target )
80 if( !
QDir().rmdir( target ) ) {
81 mDebug() <<
"Removing of the target directory failed";
88 mDebug() <<
"Rename" << source <<
"to" << target;
89 if( !
QDir().rename( source, target ) ) {
90 mDebug() <<
"Simple renaming of the data directory failed. Moving single files";
95 progressDialog.
setMaximum( std::numeric_limits<int>::max() );
103 int sourcePathLength = sourcePath.
length();
107 dirs.
push( sourcePath );
110 progressSliceSizeStack.
push( progressDialog.
maximum() );
119 mDebug() <<
"DataMigration: Current source dir path ="
121 mDebug() <<
"SliceSize =" << progressSliceSizeStack.
top();
123 if( !sourceDirPath.
startsWith( sourcePath ) ) {
125 progress += progressSliceSizeStack.
pop();
126 progressDialog.
setValue( progress );
130 QDir sourceDir( sourceDirPath );
132 QStringList files = sourceDir.entryList( QDir::Files
134 | QDir::NoDotAndDotDot );
135 QStringList childDirs = sourceDir.entryList( QDir::Dirs
137 | QDir::NoDotAndDotDot );
138 int childSliceSize = 0;
140 childSliceSize = progressSliceSizeStack.
pop() / childDirs.
size();
141 progressSliceSizeStack.
push( 0 );
147 mDebug() <<
"DataMigration:" << dirs.
top()
150 progress += progressSliceSizeStack.
pop();
151 progressDialog.
setValue( progress );
155 foreach(
const QString& childDir, childDirs ) {
156 dirs.
push( sourceDirPath +
'/' + childDir );
157 progressSliceSizeStack.
push( childSliceSize );
161 QString targetDirPath = sourceDirPath;
162 targetDirPath.
remove( 0, sourcePathLength );
163 targetDirPath.
prepend( target );
167 foreach(
const QString& file, files ) {
172 QString sourceFilePath = sourceDirPath;
173 sourceFilePath +=
'/';
174 sourceFilePath += file;
176 if( !sourceFilePath.
startsWith( sourcePath ) ) {
180 QString targetFilePath = sourceFilePath;
181 targetFilePath.
remove( 0, sourcePathLength );
182 targetFilePath.
prepend( target );
194 #include "DataMigration.moc"
void setMaximum(int maximum)
QString & prepend(QChar ch)
void setLabelText(const QString &text)
static QString localPath()
QString & remove(int position, int n)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool copy(const QString &newName)
void setValue(int progress)
bool rmdir(const QString &dirName) const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void setAutoClose(bool close)
void setAutoReset(bool reset)
DataMigration(QObject *parent)
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
QString canonicalPath() const
void setMinimum(int minimum)
QDebug mDebug()
a function to replace qDebug() in Marble library code
static QStringList oldLocalPaths()
bool mkpath(const QString &dirPath) const