Marble
7 #include "DataMigration.h"
10 #include "MarbleDebug.h"
11 #include "MarbleDirs.h"
12 #include "ui_DataMigrationWidget.h"
17 #include <QDirIterator>
21 #include <QProgressDialog>
29 DataMigration::DataMigration(
QObject *parent )
34 DataMigration::~DataMigration()
38 void 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 );
72 void 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() );
107 while( !
dirs.isEmpty() ) {
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 );
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"
void setValue(int progress)
bool copy(const QString &newName)
QString & prepend(QChar ch)
void setLabelText(const QString &text)
void setMinimum(int minimum)
bool rmdir(const QString &dirName) const const
QString canonicalPath() const const
bool mkpath(const QString &dirPath) const const
void setAutoClose(bool close)
bool isEmpty() const const
Binds a QML item to a specific geodetic location in screen coordinates.
QString & remove(int position, int n)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
void setAutoReset(bool reset)
KIOCORE_EXPORT SimpleJob * rmdir(const QUrl &url)
int rename(const QString &in, const QString &out)
QDebug mDebug()
a function to replace qDebug() in Marble library code
void setMaximum(int maximum)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:25 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.