7#include "DataMigration.h"
10#include "MarbleDebug.h"
11#include "MarbleDirs.h"
12#include "ui_DataMigrationWidget.h"
17#include <QDirIterator>
21#include <QProgressDialog>
29DataMigration::DataMigration(
QObject *parent )
34DataMigration::~DataMigration()
38void DataMigration::exec()
40 QStringList oldLocalPaths = MarbleDirs::oldLocalPaths();
46 QString currentLocalPath = MarbleDirs::localPath();
47 QDir currentLocalDir( currentLocalPath );
52 for(
const QString& oldLocalPath: oldLocalPaths ) {
53 QDir oldLocalDir( oldLocalPath );
60 Ui::DataMigrationWidget dataMigrationWidget;
62 dataMigrationWidget.setupUi( dialog );
64 DataMigration::moveFiles( oldLocalPath, currentLocalPath );
72void DataMigration::moveFiles(
const QString& source,
const QString& target )
75 mDebug() <<
"Removing of the target directory failed";
82 mDebug() <<
"Rename" << source <<
"to" << target;
84 mDebug() <<
"Simple renaming of the data directory failed. Moving single files";
89 progressDialog.
setMaximum( std::numeric_limits<int>::max() );
93 progressDialog.
setLabelText( tr(
"Converting data ..." ) );
97 int sourcePathLength = sourcePath.
length();
101 dirs.
push( sourcePath );
104 progressSliceSizeStack.
push( progressDialog.
maximum() );
113 mDebug() <<
"DataMigration: Current source dir path ="
115 mDebug() <<
"SliceSize =" << progressSliceSizeStack.
top();
117 if( !sourceDirPath.
startsWith( sourcePath ) ) {
119 progress += progressSliceSizeStack.
pop();
120 progressDialog.
setValue( progress );
124 QDir sourceDir( sourceDirPath );
132 int childSliceSize = 0;
134 childSliceSize = progressSliceSizeStack.
pop() / childDirs.
size();
135 progressSliceSizeStack.
push( 0 );
141 mDebug() <<
"DataMigration:" << dirs.
top()
144 progress += progressSliceSizeStack.
pop();
145 progressDialog.
setValue( progress );
149 for(
const QString& childDir: childDirs ) {
151 progressSliceSizeStack.
push( childSliceSize );
155 QString targetDirPath = sourceDirPath;
156 targetDirPath.
remove( 0, sourcePathLength );
157 targetDirPath.
prepend( target );
161 for(
const QString& file: files ) {
168 if( !sourceFilePath.
startsWith( sourcePath ) ) {
172 QString targetFilePath = sourceFilePath;
173 targetFilePath.
remove( 0, sourcePathLength );
174 targetFilePath.
prepend( target );
186#include "moc_DataMigration.cpp"
KIOCORE_EXPORT SimpleJob * rmdir(const QUrl &url)
KIOCORE_EXPORT SimpleJob * rename(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
Binds a QML item to a specific geodetic location in screen coordinates.
QString canonicalPath() const const
bool mkpath(const QString &dirPath) const const
bool rmdir(const QString &dirName) const const
bool copy(const QString &fileName, const QString &newName)
bool isEmpty() const const
qsizetype size() const const
void setAutoClose(bool close)
void setAutoReset(bool reset)
void setLabelText(const QString &text)
void setMaximum(int maximum)
void setMinimum(int minimum)
void setValue(int progress)
qsizetype length() const const
QString & prepend(QChar ch)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const