diff options
author | Tim Jenssen <tim.jenssen@nokia.com> | 2011-05-10 21:12:21 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@nokia.com> | 2011-05-10 21:12:21 +0200 |
commit | 8f40a20dd99b94041a6558053ec03bc775ae518d (patch) | |
tree | 5de8182a026a82a2c1bdd78c03dbb9c797382253 /installerbuilder/libinstaller | |
parent | 041a6e9345026d7d80434ccdac63dec8cae2af9d (diff) |
remove some un codingstyle spaces from operations
Diffstat (limited to 'installerbuilder/libinstaller')
21 files changed, 631 insertions, 673 deletions
diff --git a/installerbuilder/libinstaller/copydirectoryoperation.cpp b/installerbuilder/libinstaller/copydirectoryoperation.cpp index 49f9db99e..b98aa5179 100644 --- a/installerbuilder/libinstaller/copydirectoryoperation.cpp +++ b/installerbuilder/libinstaller/copydirectoryoperation.cpp @@ -49,7 +49,7 @@ TRANSLATOR QInstaller::CopyDirectoryOperation CopyDirectoryOperation::CopyDirectoryOperation() { - setName( QLatin1String( "CopyDirectory" ) ); + setName(QLatin1String("CopyDirectory")); } CopyDirectoryOperation::~CopyDirectoryOperation() @@ -75,8 +75,8 @@ QList< QPair<QString,QString> > CopyDirectoryOperation::fileList() Q_ASSERT(!arguments().at(0).isEmpty()); Q_ASSERT(!arguments().at(1).isEmpty()); if (m_fileList.isEmpty()) { - const QString sourcePath = arguments().at( 0 ); - const QString targetPath = arguments().at( 1 ); + const QString sourcePath = arguments().at(0); + const QString targetPath = arguments().at(1); m_fileList = generateFileList(sourcePath, targetPath); } @@ -85,27 +85,23 @@ QList< QPair<QString,QString> > CopyDirectoryOperation::fileList() QList< QPair<QString,QString> > CopyDirectoryOperation::generateFileList(const QString &sourcePath, const QString &targetPath) { - Q_ASSERT( QFileInfo( sourcePath ).isDir() ); - Q_ASSERT( !QFileInfo( targetPath ).exists() || QFileInfo( targetPath ).isDir() ); - if ( !QDir().mkpath( targetPath ) ) { - qWarning() << QLatin1String("Could not create folder ") << targetPath; + Q_ASSERT(QFileInfo(sourcePath).isDir()); + Q_ASSERT(!QFileInfo(targetPath).exists() || QFileInfo(targetPath).isDir()); + if (!QDir().mkpath(targetPath)) { + qWarning() << QLatin1String("Could not create folder") << targetPath; } else { addDirectoryToDirectoryList(targetPath); } - QDirIterator it( sourcePath, QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden | QDir::System); - while( it.hasNext() ) - { - const QFileInfo currentFileInfo( it.next() ); - if( currentFileInfo.isDir() && !currentFileInfo.isSymLink() ) - { - generateFileList( currentFileInfo.absoluteFilePath(), QDir( targetPath ).absoluteFilePath( currentFileInfo.fileName() ) ); - } - else - { + QDirIterator it(sourcePath, QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden | QDir::System); + while (it.hasNext()) { + const QFileInfo currentFileInfo(it.next()); + if (currentFileInfo.isDir() && !currentFileInfo.isSymLink()) { + generateFileList( currentFileInfo.absoluteFilePath(), QDir(targetPath).absoluteFilePath(currentFileInfo.fileName())); + } else { const QString source = currentFileInfo.absoluteFilePath(); - const QString target = QDir( targetPath ).absoluteFilePath( currentFileInfo.fileName() ); + const QString target = QDir(targetPath).absoluteFilePath(currentFileInfo.fileName()); m_fileList.append(QPair<QString, QString>(source, target)); } } @@ -124,24 +120,23 @@ bool CopyDirectoryOperation::copyFilesFromInternalFileList() // If destination file exists, then we cannot use QFile::copy() // because it does not overwrite an existing file. So we remove // the destination file. - if( QFile::exists(dest) ) - { - QFile file( dest ); - if( !file.remove() ) { - setError( UserDefinedError ); - setErrorString( tr("Could not remove destination file %1: %2.").arg( dest, file.errorString() ) ); + if (QFile::exists(dest)) { + QFile file(dest); + if (!file.remove()) { + setError(UserDefinedError); + setErrorString(tr("Could not remove destination file %1: %2.").arg( dest, file.errorString())); return false; } } - QFile file( source ); - const bool copied = file.copy( dest ); - if ( !copied ) { - setError( UserDefinedError ); - setErrorString( tr("Could not copy %1 to %2: %3.").arg( source, dest, file.errorString() ) ); + QFile file(source); + const bool copied = file.copy(dest); + if (!copied) { + setError(UserDefinedError); + setErrorString(tr("Could not copy %1 to %2: %3.").arg(source, dest, file.errorString())); return false; } else { - addFileToFileList( dest ); + addFileToFileList(dest); } } return true; @@ -149,14 +144,14 @@ bool CopyDirectoryOperation::copyFilesFromInternalFileList() bool CopyDirectoryOperation::removeFilesFromInternalFileList() { - const QStringList fileNameList = value( QLatin1String( "files" ) ).toStringList(); + const QStringList fileNameList = value(QLatin1String("files")).toStringList(); bool result = true; foreach(const QString fileName, fileNameList) { - result = result & deleteFileNowOrLater( fileName ); + result = result & deleteFileNowOrLater(fileName); } - const QStringList directoryList = value( QLatin1String( "directories" ) ).toStringList(); + const QStringList directoryList = value(QLatin1String("directories")).toStringList(); foreach(const QString directory, directoryList) { QDir().rmdir(directory); @@ -172,14 +167,14 @@ void CopyDirectoryOperation::backup() bool CopyDirectoryOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 2 ) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 2 expected.") - .arg(name()).arg( args.count() ) ); + if (args.count() != 2) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2 expected.") + .arg(name()).arg( args.count())); return false; } - const QString sourcePath = args.at( 0 ); - const QString targetPath = args.at( 1 ); +// const QString sourcePath = args.at(0); +// const QString targetPath = args.at(1); typedef QList< QPair< QString, QString > > FileList; @@ -194,28 +189,28 @@ bool CopyDirectoryOperation::performOperation() bool CopyDirectoryOperation::undoOperation() { - Q_ASSERT( arguments().count() == 2 ); + Q_ASSERT(arguments().count() == 2); - QFuture< bool > allRemoved = QtConcurrent::run(this, &CopyDirectoryOperation::removeFilesFromInternalFileList); + QFuture<bool> allRemoved = QtConcurrent::run(this, &CopyDirectoryOperation::removeFilesFromInternalFileList); letTheUiRunTillFinished(allRemoved); return allRemoved.result(); } -void CopyDirectoryOperation::addFileToFileList( const QString& fileName ) +void CopyDirectoryOperation::addFileToFileList(const QString& fileName) { - QStringList files = value( QLatin1String( "files" ) ).toStringList(); - files.push_front( fileName ); - setValue( QLatin1String( "files" ), files ); - emit outputTextChanged( fileName ); + QStringList files = value(QLatin1String("files")).toStringList(); + files.push_front(fileName); + setValue(QLatin1String("files"), files); + emit outputTextChanged(fileName); } -void CopyDirectoryOperation::addDirectoryToDirectoryList( const QString& directory ) +void CopyDirectoryOperation::addDirectoryToDirectoryList(const QString& directory) { - QStringList directories = value( QLatin1String( "directories" ) ).toStringList(); - directories.push_front( directory ); - setValue( QLatin1String( "directories" ), directories ); - emit outputTextChanged( directory ); + QStringList directories = value(QLatin1String("directories")).toStringList(); + directories.push_front(directory); + setValue( QLatin1String("directories"), directories); + emit outputTextChanged(directory); } bool CopyDirectoryOperation::testOperation() diff --git a/installerbuilder/libinstaller/createdesktopentryoperation.cpp b/installerbuilder/libinstaller/createdesktopentryoperation.cpp index 57fe6e36f..d514f761e 100644 --- a/installerbuilder/libinstaller/createdesktopentryoperation.cpp +++ b/installerbuilder/libinstaller/createdesktopentryoperation.cpp @@ -53,51 +53,50 @@ QString CreateDesktopEntryOperation::absoluteFileName() const QString filename = arguments().first(); // give filename is already absolute - if( QFileInfo( filename ).isAbsolute() ) + if (QFileInfo(filename).isAbsolute()) return filename; // we're not searching for the first time, let's re-use the old value - if( hasValue( QLatin1String( "directory" ) ) ) - return QDir( value( QLatin1String( "directory" ) ).toString() ).absoluteFilePath( filename ); + if (hasValue(QLatin1String("directory"))) + return QDir(value(QLatin1String("directory")).toString()).absoluteFilePath(filename); const QProcessEnvironment env; - QStringList XDG_DATA_DIRS = env.value( QLatin1String( "XDG_DATA_DIRS" ) ).split( QLatin1Char( ':' ), QString::SkipEmptyParts ); - QStringList XDG_DATA_HOME = env.value( QLatin1String( "XDG_DATA_HOME" ) ).split( QLatin1Char( ':' ), QString::SkipEmptyParts ); + QStringList XDG_DATA_DIRS = env.value(QLatin1String("XDG_DATA_DIRS")).split(QLatin1Char(':'), QString::SkipEmptyParts); + QStringList XDG_DATA_HOME = env.value(QLatin1String("XDG_DATA_HOME")).split(QLatin1Char(':'), QString::SkipEmptyParts); - XDG_DATA_DIRS.push_back( QLatin1String( "/usr/share" ) ); // default path - XDG_DATA_HOME.push_back( QDir::home().absoluteFilePath( QLatin1String( ".local/share" ) ) ); // default path + XDG_DATA_DIRS.push_back(QLatin1String("/usr/share")); // default path + XDG_DATA_HOME.push_back(QDir::home().absoluteFilePath(QLatin1String(".local/share"))); // default path const QStringList directories = XDG_DATA_DIRS + XDG_DATA_HOME; QString directory; - for( QStringList::const_iterator it = directories.begin(); it != directories.end(); ++it ) - { - if( it->isEmpty() ) + for (QStringList::const_iterator it = directories.begin(); it != directories.end(); ++it) { + if (it->isEmpty()) continue; - directory = QDir( *it ).absoluteFilePath( QLatin1String( "applications" ) ); - QDir dir( directory ); + directory = QDir(*it).absoluteFilePath(QLatin1String("applications")); + QDir dir(directory); // let's see wheter this dir exists or we're able to create it - if( !dir.exists() && !QDir().mkpath( directory ) ) + if (!dir.exists() && !QDir().mkpath(directory)) continue; // we just try wheter we're able to open the file in ReadWrite - QFile file( QDir( directory ).absoluteFilePath( filename ) ); + QFile file(QDir(directory).absoluteFilePath(filename)); const bool existed = file.exists(); - if( !file.open( QIODevice::ReadWrite ) ) + if (!file.open(QIODevice::ReadWrite)) continue; file.close(); - if( !existed ) + if (!existed) file.remove(); break; } - if( !QDir( directory ).exists() ) - QDir().mkpath( directory ); + if (!QDir(directory).exists()) + QDir().mkpath(directory); - setValue( QLatin1String( "directory" ), directory ); + setValue(QLatin1String("directory"), directory); - return QDir( directory ).absoluteFilePath( filename ); + return QDir(directory).absoluteFilePath(filename); } /* @@ -106,71 +105,67 @@ TRANSLATOR QInstaller::CreateDesktopEntryOperation CreateDesktopEntryOperation::CreateDesktopEntryOperation() { - setName( QLatin1String( "CreateDesktopEntry" ) ); + setName(QLatin1String("CreateDesktopEntry")); } CreateDesktopEntryOperation::~CreateDesktopEntryOperation() { - deleteFileNowOrLater( value( QLatin1String( "backupOfExistingDesktopEntry" ) ).toString() ); + deleteFileNowOrLater(value(QLatin1String("backupOfExistingDesktopEntry")).toString()); } void CreateDesktopEntryOperation::backup() { const QString filename = absoluteFileName(); - if( !QFile::exists( filename ) ) + if (!QFile::exists(filename)) return; try { - setValue( QLatin1String( "backupOfExistingDesktopEntry" ), generateTemporaryFileName( filename ) ); - } catch ( const QInstaller::Error& e ) { - setErrorString( e.message() ); + setValue(QLatin1String("backupOfExistingDesktopEntry"), generateTemporaryFileName(filename)); + } catch (const QInstaller::Error& e) { + setErrorString(e.message()); return; } - if( !QFile::copy( filename, value( QLatin1String( "backupOfExistingDesktopEntry" ) ).toString() ) ) - setErrorString( QObject::tr( "Could not backup file %1" ).arg( filename ) ); + if (!QFile::copy(filename, value(QLatin1String("backupOfExistingDesktopEntry")).toString())) + setErrorString(QObject::tr("Could not backup file %1").arg(filename)); } bool CreateDesktopEntryOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 2 ) - { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 2 expected.") - .arg(name()).arg( args.count() ) ); + if(args.count() != 2) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2 expected.") + .arg(name()).arg(args.count())); return false; } const QString filename = absoluteFileName(); - const QString& values = args[ 1 ]; + const QString& values = args[1]; - if( QFile::exists( filename ) && !deleteFileNowOrLater( filename ) ) - { - setError( UserDefinedError ); - setErrorString( tr( "Failed to overwrite %1" ).arg( filename ) ); + if (QFile::exists(filename) && !deleteFileNowOrLater(filename)) { + setError(UserDefinedError); + setErrorString(tr("Failed to overwrite %1").arg(filename)); return false; } - QFile file( filename ); - if( !file.open( QIODevice::WriteOnly ) ) - { - setError( UserDefinedError ); - setErrorString( tr( "Could not write Desktop Entry at %1" ).arg( filename ) ); + QFile file(filename); + if(!file.open(QIODevice::WriteOnly)) { + setError(UserDefinedError); + setErrorString(tr("Could not write Desktop Entry at %1").arg(filename)); return false; } QFile::setPermissions(filename, QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::ReadGroup | QFile::ReadOther); - QTextStream stream( &file ); - stream.setCodec( "UTF-8" ); - stream << QLatin1String( "[Desktop Entry]" ) << endl; - stream << QLatin1String( "Encoding=UTF-8" ) << endl; + QTextStream stream(&file); + stream.setCodec("UTF-8"); + stream << QLatin1String("[Desktop Entry]") << endl; + stream << QLatin1String("Encoding=UTF-8") << endl; // Type=Application\nExec=qtcreator\nPath=... - const QStringList pairs = values.split( QLatin1Char( '\n' ) ); - for( QStringList::const_iterator it = pairs.begin(); it != pairs.end(); ++it ) - { + const QStringList pairs = values.split(QLatin1Char('\n')); + for (QStringList::const_iterator it = pairs.begin(); it != pairs.end(); ++it) { stream << *it << endl; } @@ -182,19 +177,18 @@ bool CreateDesktopEntryOperation::undoOperation() const QString filename = absoluteFileName(); // first remove the link - if( !deleteFileNowOrLater( filename ) ) - { - setErrorString( QObject::tr( "Could not delete file %1" ).arg( filename ) ); + if (!deleteFileNowOrLater(filename)) { + setErrorString(QObject::tr("Could not delete file %1").arg(filename)); return false; } - if( !hasValue( QLatin1String( "backupOfExistingDesktopEntry" ) ) ) + if (!hasValue(QLatin1String("backupOfExistingDesktopEntry"))) return true; - const QString backupOfExistingDesktopEntry = value( QLatin1String( "backupOfExistingDesktopEntry" ) ).toString(); - const bool success = QFile::copy( backupOfExistingDesktopEntry, filename ) && deleteFileNowOrLater( backupOfExistingDesktopEntry ); - if( !success ) - setErrorString( QObject::tr( "Could not restore backup file into %1" ).arg( filename ) ); + const QString backupOfExistingDesktopEntry = value(QLatin1String("backupOfExistingDesktopEntry")).toString(); + const bool success = QFile::copy(backupOfExistingDesktopEntry, filename) && deleteFileNowOrLater(backupOfExistingDesktopEntry); + if (!success) + setErrorString(QObject::tr("Could not restore backup file into %1").arg(filename)); return success; } diff --git a/installerbuilder/libinstaller/createshortcutoperation.cpp b/installerbuilder/libinstaller/createshortcutoperation.cpp index 0aea4af63..ab7e0aff9 100644 --- a/installerbuilder/libinstaller/createshortcutoperation.cpp +++ b/installerbuilder/libinstaller/createshortcutoperation.cpp @@ -53,13 +53,13 @@ using namespace QInstaller; -static bool createLink( QString fileName, QString linkName, QString workingDir, QString arguments = QString() ) +static bool createLink(QString fileName, QString linkName, QString workingDir, QString arguments = QString()) { #ifdef Q_WS_WIN bool ret = false; fileName = QDir::toNativeSeparators(fileName); linkName = QDir::toNativeSeparators(linkName); - if ( workingDir.isEmpty() ) + if (workingDir.isEmpty()) workingDir = QFileInfo(fileName).absolutePath(); workingDir = QDir::toNativeSeparators(workingDir); @@ -78,8 +78,8 @@ static bool createLink( QString fileName, QString linkName, QString workingDir, if (SUCCEEDED(hres)) { hres = psl->SetPath((wchar_t *)fileName.utf16()); - if( SUCCEEDED( hres ) && !arguments.isNull() ) - hres = psl->SetArguments((wchar_t*)arguments.utf16() ); + if(SUCCEEDED(hres) && !arguments.isNull()) + hres = psl->SetArguments((wchar_t*)arguments.utf16()); if (SUCCEEDED(hres)) { hres = psl->SetWorkingDirectory((wchar_t *)workingDir.utf16()); if (SUCCEEDED(hres)) { @@ -101,9 +101,9 @@ static bool createLink( QString fileName, QString linkName, QString workingDir, return ret; #else - Q_UNUSED( workingDir ) - Q_UNUSED( arguments ) - return QFile::link( fileName, linkName ); + Q_UNUSED(workingDir) + Q_UNUSED(arguments) + return QFile::link(fileName, linkName); #endif } @@ -113,25 +113,25 @@ TRANSLATOR QInstaller::CreateShortcutOperation CreateShortcutOperation::CreateShortcutOperation() { - setName( QLatin1String( "CreateShortcut" ) ); + setName(QLatin1String("CreateShortcut")); } CreateShortcutOperation::~CreateShortcutOperation() { - deleteFileNowOrLater( value( QLatin1String( "backupOfExistingShortcut" ) ).toString() ); + deleteFileNowOrLater(value(QLatin1String("backupOfExistingShortcut")).toString()); } -static bool isWorkingDirOption( const QString& s ) { - return s.startsWith( QLatin1String("workingDirectory=") ); +static bool isWorkingDirOption(const QString& s) { + return s.startsWith(QLatin1String("workingDirectory=")); } -static QString getWorkingDir( QStringList& args ) { +static QString getWorkingDir(QStringList& args) { QString workingDir; // if the args contain an option in the form "workingDirectory=...", find it and consume it - QStringList::iterator wdiropt = std::find_if( args.begin(), args.end(), isWorkingDirOption ); - if ( wdiropt != args.end() ) { - workingDir = wdiropt->mid( QString::fromLatin1("workingDirectory=").size() ); - args.erase( wdiropt ); + QStringList::iterator wdiropt = std::find_if(args.begin(), args.end(), isWorkingDirOption); + if (wdiropt != args.end()) { + workingDir = wdiropt->mid(QString::fromLatin1("workingDirectory=").size()); + args.erase(wdiropt); } return workingDir; } @@ -139,9 +139,9 @@ static QString getWorkingDir( QStringList& args ) { void CreateShortcutOperation::backup() { QStringList args = this->arguments(); - getWorkingDir( args ); //consume workingDirectory= option + getWorkingDir(args); //consume workingDirectory= option - const QString path = QDir::fromNativeSeparators( QFileInfo( args.at( 1 ) ).absolutePath() ); + const QString path = QDir::fromNativeSeparators(QFileInfo(args.at(1)).absolutePath()); //verbose() << "dir to create shortcut in " << path << std::endl; @@ -150,20 +150,16 @@ void CreateShortcutOperation::backup() // find out, which part of the path is the first one we actually need to create int end = 0; QStringList directoriesToCreate; - while( true ) - { - QString p = path.section( QLatin1String("/"), 0, ++end ); - createdDir = QDir( p ); - if( !createdDir.exists() ) - { - directoriesToCreate.push_back( QDir::toNativeSeparators( createdDir.absolutePath() ) ); - verbose() << " backup created dir_pre " << QDir::toNativeSeparators( createdDir.absolutePath() ) << std::endl; - if ( p == path) + while (true) { + QString p = path.section(QLatin1String("/"), 0, ++end); + createdDir = QDir(p); + if (!createdDir.exists()) { + directoriesToCreate.push_back(QDir::toNativeSeparators(createdDir.absolutePath())); + verbose() << " backup created dir_pre " << QDir::toNativeSeparators(createdDir.absolutePath()) << std::endl; + if (p == path) break; - } - else if( p == path ) - { + } else if(p == path) { // everything did already exist -> nothing to do for us (nothing to revert then, either) createdDir = QDir::root(); break; @@ -171,86 +167,84 @@ void CreateShortcutOperation::backup() } verbose() << " backup created dir " << createdDir.absolutePath() << std::endl; - setValue( QLatin1String( "createddirs" ), directoriesToCreate ); + setValue(QLatin1String("createddirs"), directoriesToCreate); //link creation context - const QString linkLocation = arguments()[ 1 ]; - if( !QFile::exists( linkLocation ) ) + const QString linkLocation = arguments()[1]; + if (!QFile::exists(linkLocation)) return; try { - setValue( QLatin1String( "backupOfExistingShortcut" ), generateTemporaryFileName( linkLocation ) ); - } catch ( const QInstaller::Error& e ) { - setErrorString( e.message() ); + setValue(QLatin1String("backupOfExistingShortcut"), generateTemporaryFileName(linkLocation)); + } catch (const QInstaller::Error& e) { + setErrorString(e.message()); return; } - QFile f( linkLocation ); - if( !f.copy( value( QLatin1String( "backupOfExistingShortcut" ) ).toString() ) ) - setErrorString( QObject::tr( "Could not backup file %1: %2" ).arg( linkLocation, f.errorString() ) ); + QFile f(linkLocation); + if (!f.copy(value(QLatin1String("backupOfExistingShortcut")).toString())) + setErrorString(QObject::tr("Could not backup file %1: %2").arg(linkLocation, f.errorString())); } bool CreateShortcutOperation::performOperation() { QStringList args = this->arguments(); - const QString workingDir = getWorkingDir( args ); + const QString workingDir = getWorkingDir(args); - if( args.count() != 2 && args.count() != 3 ) - { - setError( InvalidArguments ); - setErrorString( QObject::tr("Invalid arguments: %1 arguments given, 2 or 3 expected (optional: \"workingDirectory=...\").").arg( args.count() ) ); + if (args.count() != 2 && args.count() != 3) { + setError(InvalidArguments); + setErrorString(QObject::tr("Invalid arguments: %1 arguments given, 2 or 3 expected (optional: \"workingDirectory=...\").").arg(args.count())); return false; } - const QString& linkTarget = args.at( 0 ); - const QString& linkLocation = args.at( 1 ); - const QString targetArguments = args.count() == 3 ? args[ 2 ] : QString(); + const QString& linkTarget = args.at(0); + const QString& linkLocation = args.at(1); + const QString targetArguments = args.count() == 3 ? args[2] : QString(); - const QString dirName = QFileInfo( linkLocation ).absolutePath(); + const QString dirName = QFileInfo(linkLocation).absolutePath(); //verbose() << "dir to create shortcut in " << dirName << std::endl; errno = 0; - const bool dirAlreadyExists = QDir( dirName ).exists(); + const bool dirAlreadyExists = QDir(dirName).exists(); const bool created = dirAlreadyExists || QDir::root().mkpath(dirName); - if ( !created ) { - setError( UserDefinedError ); - setErrorString( tr("Could not create folder %1: %2.").arg( QDir::toNativeSeparators( dirName ), QLatin1String(strerror(errno)) ) ); + if (!created) { + setError(UserDefinedError); + setErrorString(tr("Could not create folder %1: %2.").arg(QDir::toNativeSeparators(dirName), QLatin1String(strerror(errno)))); return false; } - TempDirDeleter deleter( dirName ); + TempDirDeleter deleter(dirName); - if( dirAlreadyExists ) + if (dirAlreadyExists) deleter.releaseAll(); #if 0 // disabled for now, isDir() also returns true if the link exists and points to a folder, then removing it fails // link creation - if ( QFileInfo( linkLocation ).isDir() ) { + if (QFileInfo(linkLocation).isDir()) { errno = 0; - if ( !QDir().rmdir( linkLocation ) ) { - setError( UserDefinedError ); - setErrorString( QObject::tr( "Could not create link: failed to remove folder %1: %2" ).arg( QDir::toNativeSeparators( linkLocation ), QLatin1String(strerror(errno)) ) ); + if (!QDir().rmdir(linkLocation)) { + setError(UserDefinedError); + setErrorString(QObject::tr("Could not create link: failed to remove folder %1: %2").arg(QDir::toNativeSeparators(linkLocation), QLatin1String(strerror(errno)))); return false; } } #endif - QString err; + QString errorString; - if( QFile::exists( linkLocation ) && !deleteFileNowOrLater( linkLocation, &err ) ) - { - setError( UserDefinedError ); - setErrorString( QObject::tr( "Failed to overwrite %1: %2" ).arg( QDir::toNativeSeparators( linkLocation ), err ) ); + if (QFile::exists(linkLocation) && !deleteFileNowOrLater(linkLocation, &errorString)) { + setError(UserDefinedError); + setErrorString(QObject::tr("Failed to overwrite %1: %2").arg(QDir::toNativeSeparators(linkLocation),errorString)); return false; } - const bool linked = createLink( linkTarget, linkLocation, workingDir, targetArguments ); - if ( !linked ) { - setError( UserDefinedError ); - setErrorString( tr("Could not create link %1: %2").arg( QDir::toNativeSeparators( linkLocation ), qt_error_string() ) ); + const bool linked = createLink(linkTarget, linkLocation, workingDir, targetArguments); + if (!linked) { + setError(UserDefinedError); + setErrorString(tr("Could not create link %1: %2").arg(QDir::toNativeSeparators(linkLocation), qt_error_string())); return false; } deleter.releaseAll(); @@ -262,70 +256,64 @@ bool CreateShortcutOperation::undoOperation() const QString linkLocation = arguments()[ 1 ]; const QStringList args = this->arguments(); verbose() << " undo Shortcutoperation with arguments "; - Q_FOREACH( const QString& val, args ) + Q_FOREACH(const QString& val, args) verbose() << val << " "; verbose() << std::endl; // first remove the link - if( !deleteFileNowOrLater( linkLocation ) ) - { - setErrorString( QObject::tr( "Could not delete file %1" ).arg( linkLocation ) ); + if (!deleteFileNowOrLater(linkLocation)) { + setErrorString(QObject::tr("Could not delete file %1").arg(linkLocation)); return false; } verbose() << " link has been deleted " << std::endl; - if( hasValue( QLatin1String( "backupOfExistingShortcut" ) ) ){ - - const QString backupOfExistingShortcut = value( QLatin1String( "backupOfExistingShortcut" ) ).toString(); - const bool success = QFile::copy( backupOfExistingShortcut, linkLocation ) && deleteFileNowOrLater( backupOfExistingShortcut ); - if( !success ){ - setErrorString( QObject::tr( "Could not restore backup file into %1" ).arg( linkLocation ) ); + if (hasValue(QLatin1String("backupOfExistingShortcut"))) { + const QString backupOfExistingShortcut = value(QLatin1String("backupOfExistingShortcut")).toString(); + const bool success = QFile::copy(backupOfExistingShortcut, linkLocation) && deleteFileNowOrLater(backupOfExistingShortcut); + if (!success) { + setErrorString(QObject::tr("Could not restore backup file into %1").arg(linkLocation)); return success; } } verbose() << " got behin backup " << std::endl; - const QStringList createdDirsPaths = value( QLatin1String( "createddirs" ) ).toStringList(); - if ( createdDirsPaths.isEmpty() ) //no dir to delete (QDir( createdDirPath ) would return the current working directory -> never do that + const QStringList createdDirsPaths = value(QLatin1String("createddirs")).toStringList(); + if (createdDirsPaths.isEmpty()) //no dir to delete (QDir(createdDirPath) would return the current working directory -> never do that return true; - const bool forceremoval = QVariant( value( QLatin1String( "forceremoval" ) ) ).toBool(); - QListIterator<QString> it( createdDirsPaths ); - for ( it.toBack(); it.hasPrevious(); ) - { + const bool forceremoval = QVariant(value(QLatin1String("forceremoval"))).toBool(); + QListIterator<QString> it(createdDirsPaths); + for (it.toBack(); it.hasPrevious();) { const QString createdDirPath = it.previous(); - const QDir createdDir = QDir( createdDirPath ); + const QDir createdDir = QDir(createdDirPath); verbose() << createdDir.absolutePath() << std::endl; - if( createdDir == QDir::root() ) + if (createdDir == QDir::root()) return true; QString errorString; - if( forceremoval ) - { + if (forceremoval) { verbose() << " forced removal of path " << createdDir.path() << std::endl; try{ - removeDirectory( createdDir.path(), false ); - }catch(const QInstaller::Error e){ - setError( UserDefinedError, e.message() ); + removeDirectory(createdDir.path(), false); + }catch(const QInstaller::Error e) { + setError(UserDefinedError, e.message()); return false; } - } - else - { + } else { // even remove some hidden, OS-created files in there #if defined Q_WS_MAC - QFile::remove( createdDir.path() + QLatin1String( "/.DS_Store" ) ); + QFile::remove(createdDir.path() + QLatin1String("/.DS_Store")); #elif defined Q_WS_WIN - QFile::remove( createdDir.path() + QLatin1String( "/Thumbs.db" ) ); + QFile::remove(createdDir.path() + QLatin1String("/Thumbs.db")); #endif errno = 0; verbose() << " removal of path " << createdDir.path() << std::endl; - const bool result = QDir::root().rmdir( createdDir.path() ); - if ( !result ) { - if ( errorString.isEmpty() ) - setError( UserDefinedError, tr("Cannot remove directory %1: %2").arg( createdDir.path(), errorString ) ); + const bool result = QDir::root().rmdir(createdDir.path()); + if (!result) { + if (errorString.isEmpty()) + setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), errorString)); else - setError( UserDefinedError, tr("Cannot remove directory %1: %2").arg( createdDir.path(), QLatin1String(strerror(errno)) ) ); + setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), QLatin1String(strerror(errno)))); return result; } } diff --git a/installerbuilder/libinstaller/elevatedexecuteoperation.cpp b/installerbuilder/libinstaller/elevatedexecuteoperation.cpp index b333bf7da..95bd6b2b5 100644 --- a/installerbuilder/libinstaller/elevatedexecuteoperation.cpp +++ b/installerbuilder/libinstaller/elevatedexecuteoperation.cpp @@ -2,7 +2,7 @@ ** ** This file is part of Qt SDK** ** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** Copyright(c) 2011 Nokia Corporation and/or its subsidiary(-ies).* ** ** Contact: Nokia Corporation qt-info@nokia.com** ** @@ -27,7 +27,7 @@ ** 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** If you are unsure which license is appropriate for your use, please contact -** (qt-info@nokia.com). +**(qt-info@nokia.com). ** **************************************************************************/ #include "elevatedexecuteoperation.h" @@ -45,8 +45,8 @@ using namespace QInstaller; class ElevatedExecuteOperation::Private { public: - explicit Private( ElevatedExecuteOperation* qq ) - : q( qq ), process(0), showStandardError(false) + explicit Private(ElevatedExecuteOperation* qq) + : q(qq), process(0), showStandardError(false) { } ~Private() @@ -65,10 +65,10 @@ public: }; ElevatedExecuteOperation::ElevatedExecuteOperation() - : d( new Private( this ) ) + : d(new Private(this)) { // this operation has to "overwrite" the Execute operation from KDUpdater - setName( QLatin1String( "Execute" ) ); + setName(QLatin1String("Execute")); } ElevatedExecuteOperation::~ElevatedExecuteOperation() @@ -79,10 +79,10 @@ bool ElevatedExecuteOperation::performOperation() { // This operation receives only one argument. It is the complete // command line of the external program to execute. - if( arguments().isEmpty() ) + if (arguments().isEmpty()) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %1: %2 arguments given, at least 1 expected.").arg( name(), QString::number( arguments().count() ) ) ); + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %1: %2 arguments given, at least 1 expected.").arg(name(), QString::number(arguments().count()))); return false; } QStringList args; @@ -109,49 +109,49 @@ bool ElevatedExecuteOperation::Private::run(const QStringList& arguments) } - if ( args.last().endsWith( QLatin1String("showStandardError") ) ) { + if (args.last().endsWith(QLatin1String("showStandardError"))) { showStandardError = true; args.pop_back(); } QList< int > allowedExitCodes; - QRegExp re( QLatin1String( "^\\{((-?\\d+,)*-?\\d+)\\}$" ) ); - if( re.exactMatch( args.first() ) ) + QRegExp re(QLatin1String("^\\{((-?\\d+,)*-?\\d+)\\}$")); + if (re.exactMatch(args.first())) { - const QStringList numbers = re.cap( 1 ).split( QLatin1Char( ',' ) ); - for( QStringList::const_iterator it = numbers.constBegin(); it != numbers.constEnd(); ++it ) - allowedExitCodes.push_back( it->toInt() ); + const QStringList numbers = re.cap(1).split(QLatin1Char(',')); + for(QStringList::const_iterator it = numbers.constBegin(); it != numbers.constEnd(); ++it) + allowedExitCodes.push_back(it->toInt()); args.pop_front(); } else { - allowedExitCodes.push_back( 0 ); + allowedExitCodes.push_back(0); } - const QString callstr = args.join( QLatin1String( " " ) ); + const QString callstr = args.join(QLatin1String(" ")); // unix style: when there's an ampersand after the command, it's started detached - if( args.count() >= 2 && args.last() == QLatin1String( "&" ) ) + if (args.count() >= 2 && args.last() == QLatin1String("&")) { args.pop_back(); - const bool success = QProcess::startDetached( args.front(), args.mid( 1 ) ); - if ( !success ) { - q->setError( UserDefinedError ); - q->setErrorString( tr( "Execution failed: Could not start detached: \"%1\"" ).arg( callstr ) ); + const bool success = QProcess::startDetached(args.front(), args.mid(1)); + if (!success) { + q->setError(UserDefinedError); + q->setErrorString(tr("Execution failed: Could not start detached: \"%1\"").arg(callstr)); } return success; } process = new QProcessWrapper(); if (!workingDirectory.isEmpty()) { - process->setWorkingDirectory( workingDirectory ); + process->setWorkingDirectory(workingDirectory); QInstaller::verbose() << " ElevatedExecuteOperation setWorkingDirectory: " << workingDirectory << std::endl; } QProcessEnvironment penv; - //there is no way to serialize a QProcessEnvironment properly other than per mangled QStringList :/ (i.e. no other way to list all keys) - process->setEnvironment( KDUpdater::Environment::instance()->applyTo( penv ).toStringList() ); + //there is no way to serialize a QProcessEnvironment properly other than per mangled QStringList :/(i.e. no other way to list all keys) + process->setEnvironment(KDUpdater::Environment::instance()->applyTo(penv).toStringList()); if (showStandardError) process->setProcessChannelMode(QProcess::MergedChannels); @@ -161,19 +161,19 @@ bool ElevatedExecuteOperation::Private::run(const QStringList& arguments) //we still like the none blocking possibility to perform this operation without threads QEventLoop loop; if (QThread::currentThread() == qApp->thread()) { - QObject::connect( process, SIGNAL( finished( int, QProcess::ExitStatus ) ), &loop, SLOT( quit() ) ); + QObject::connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), &loop, SLOT(quit())); } //readProcessOutput should only called from this current Thread -> Qt::DirectConnection - QObject::connect( process, SIGNAL( readyRead() ), q, SLOT( readProcessOutput() ), Qt::DirectConnection ); + QObject::connect(process, SIGNAL(readyRead()), q, SLOT(readProcessOutput()), Qt::DirectConnection); #ifdef Q_OS_WIN if (args.count() == 1) { - process->setNativeArguments( args.front() ); + process->setNativeArguments(args.front()); QInstaller::verbose() << " ElevatedExecuteOperation setNativeArguments to start: " << args.front() << std::endl; process->start(QString(), QStringList()); } else #endif - process->start( args.front(), args.mid( 1 ) ); - QInstaller::verbose() << args.front() << " started, arguments: " << QStringList(args.mid( 1 )).join(QLatin1String(" ")) << std::endl; + process->start(args.front(), args.mid(1)); + QInstaller::verbose() << args.front() << " started, arguments: " << QStringList(args.mid(1)).join(QLatin1String(" ")) << std::endl; bool success = false; //we still like the none blocking possibility to perform this operation without threads @@ -184,11 +184,11 @@ bool ElevatedExecuteOperation::Private::run(const QStringList& arguments) } bool returnValue = true; - if ( !success ) + if (!success) { - q->setError( UserDefinedError ); + q->setError(UserDefinedError); //TODO: pass errorString() through the wrapper */ - q->setErrorString( tr( "Execution failed: Could not start: \"%1\"" ).arg( callstr ) ); + q->setErrorString(tr("Execution failed: Could not start: \"%1\"").arg(callstr)); returnValue = false; } @@ -199,19 +199,19 @@ bool ElevatedExecuteOperation::Private::run(const QStringList& arguments) readProcessOutput(); } - q->setValue( QLatin1String( "ExitCode" ), process->exitCode() ); + q->setValue(QLatin1String("ExitCode"), process->exitCode()); - if ( process->exitStatus() == QProcess::CrashExit ) + if (process->exitStatus() == QProcess::CrashExit) { - q->setError( UserDefinedError ); - q->setErrorString( tr( "Execution failed (Crash): \"%1\"" ).arg( callstr ) ); + q->setError(UserDefinedError); + q->setErrorString(tr("Execution failed(Crash): \"%1\"").arg(callstr)); returnValue = false; } - if ( !allowedExitCodes.contains( process->exitCode() ) ) + if (!allowedExitCodes.contains(process->exitCode())) { - q->setError( UserDefinedError ); - q->setErrorString( tr( "Execution failed (Unexpected exit code: %1): \"%2\"" ).arg( QString::number( process->exitCode() ), callstr ) ); + q->setError(UserDefinedError); + q->setErrorString(tr("Execution failed(Unexpected exit code: %1): \"%2\"").arg(QString::number(process->exitCode()), callstr)); returnValue = false; } @@ -239,9 +239,9 @@ void ElevatedExecuteOperation::Private::readProcessOutput() QInstaller::verbose() << Q_FUNC_INFO << QLatin1String(" can only be called from the same thread as the process is.") << std::endl; } const QByteArray output = process->readAll(); - if( !output.isEmpty() ) { - QInstaller::verbose() << QString::fromLocal8Bit( output ) << std::endl; - emit q->outputTextChanged( QString::fromLocal8Bit( output ) ); + if (!output.isEmpty()) { + QInstaller::verbose() << QString::fromLocal8Bit(output) << std::endl; + emit q->outputTextChanged(QString::fromLocal8Bit(output)); } } diff --git a/installerbuilder/libinstaller/environmentvariablesoperation.cpp b/installerbuilder/libinstaller/environmentvariablesoperation.cpp index 1c2bde7bc..9bffa429c 100644 --- a/installerbuilder/libinstaller/environmentvariablesoperation.cpp +++ b/installerbuilder/libinstaller/environmentvariablesoperation.cpp @@ -137,9 +137,9 @@ UpdateOperation::Error undoSetting(const QString ®Path, bool EnvironmentVariableOperation::performOperation() { if (arguments().count() < 2 || arguments().count() > 4) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 2-3 expected.") - .arg(name()).arg( arguments().count() ) ); + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2-3 expected.") + .arg(name()).arg( arguments().count())); return false; } @@ -151,8 +151,7 @@ bool EnvironmentVariableOperation::performOperation() isPersistent = arguments().count() >= 3 ? arguments().at(2) == QLatin1String("true") : true; const bool isSystemWide = arguments().count() >= 4 ? arguments().at(3) == QLatin1String("true") : false; QString oldvalue; - if (isPersistent) - { + if (isPersistent) { const QString regPath = isSystemWide ? QLatin1String( "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" ) : QLatin1String( "HKEY_CURRENT_USER\\Environment" ); diff --git a/installerbuilder/libinstaller/extractarchiveoperation.cpp b/installerbuilder/libinstaller/extractarchiveoperation.cpp index a58cc0071..b5f5252e2 100644 --- a/installerbuilder/libinstaller/extractarchiveoperation.cpp +++ b/installerbuilder/libinstaller/extractarchiveoperation.cpp @@ -47,7 +47,7 @@ TRANSLATOR QInstaller::ExtractArchiveOperation ExtractArchiveOperation::ExtractArchiveOperation() { - setName( QLatin1String( "Extract" ) ); + setName(QLatin1String("Extract")); } ExtractArchiveOperation::~ExtractArchiveOperation() @@ -62,33 +62,33 @@ void ExtractArchiveOperation::backup() bool ExtractArchiveOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 2 ) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 2 expected.") - .arg(name()).arg( args.count() ) ); + if (args.count() != 2) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2 expected.") + .arg(name()).arg(args.count())); return false; } const QString archivePath = args.first(); - const QString targetDir = args.at( 1 ); + const QString targetDir = args.at(1); Receiver receiver; Callback callback; //usually we have to connect it as queued connection but then some blocking work is in the main thread - connect( &callback, SIGNAL(progressChanged(QString)), this, SLOT(slotProgressChanged(QString)), Qt::DirectConnection ); - connect( &callback, SIGNAL(progressChanged(int)), this, SIGNAL(progressChanged(int)), Qt::QueuedConnection ); + connect(&callback, SIGNAL(progressChanged(QString)), this, SLOT(slotProgressChanged(QString)), Qt::DirectConnection); + connect(&callback, SIGNAL(progressChanged(int)), this, SIGNAL(progressChanged(int)), Qt::QueuedConnection); - if(QInstaller::Installer *installer = this->value( QLatin1String( "installer" )).value<QInstaller::Installer*>()) { - connect( installer, SIGNAL( statusChanged( QInstaller::Installer::Status ) ), &callback, - SLOT( statusChanged( QInstaller::Installer::Status ) ), Qt::QueuedConnection ); + if (QInstaller::Installer *installer = this->value(QLatin1String("installer")).value<QInstaller::Installer*>()) { + connect(installer, SIGNAL(statusChanged(QInstaller::Installer::Status)), &callback, + SLOT(statusChanged(QInstaller::Installer::Status)), Qt::QueuedConnection); } //Runnable is derived from QRunable which will be deleted by the ThreadPool -> no parent is needed - Runnable* runnable = new Runnable( archivePath, targetDir, &callback ); - connect( runnable, SIGNAL(finished(bool,QString)), &receiver, SLOT(runnableFinished(bool,QString)), Qt::QueuedConnection ); + Runnable* runnable = new Runnable(archivePath, targetDir, &callback); + connect(runnable, SIGNAL(finished(bool,QString)), &receiver, SLOT(runnableFinished(bool,QString)), Qt::QueuedConnection); QEventLoop loop; - connect( &receiver, SIGNAL( finished() ), &loop, SLOT( quit() ) ); + connect(&receiver, SIGNAL(finished()), &loop, SLOT(quit())); if (QThreadPool::globalInstance()->tryStart(runnable)) { loop.exec(); } else { @@ -104,21 +104,21 @@ bool ExtractArchiveOperation::performOperation() //TODO use backups for rollback, too? doesn't work for uninstallation though //delete all backups we can delete right now, remember the rest - Q_FOREACH( const StringPair& i, backupFiles ) - deleteFileNowOrLater( i.second ); + Q_FOREACH(const StringPair& i, backupFiles) + deleteFileNowOrLater(i.second); - if ( !receiver.success ) { - setError( UserDefinedError ); - setErrorString( receiver.errorString ); + if (!receiver.success) { + setError(UserDefinedError); + setErrorString(receiver.errorString); return false; } return true; } -WorkerThread::WorkerThread( ExtractArchiveOperation *op, const QStringList &files, QObject* parent ) - : QThread( parent ) - , m_files( files ) - , m_op( op ) +WorkerThread::WorkerThread(ExtractArchiveOperation *op, const QStringList &files, QObject* parent) + : QThread(parent) + , m_files(files) + , m_op(op) { } @@ -127,53 +127,49 @@ WorkerThread::WorkerThread( ExtractArchiveOperation *op, const QStringList &file */ void WorkerThread::run() { - ExtractArchiveOperation* const op = m_op;//dynamic_cast< ExtractArchiveOperation* >( parent() ); - Q_ASSERT( op != 0 ); + ExtractArchiveOperation* const op = m_op;//dynamic_cast< ExtractArchiveOperation* >(parent()); + Q_ASSERT(op != 0); int progress = -1; int index = 0; const int count = m_files.count(); - Q_FOREACH( const QString &file, m_files ) - { - const QFileInfo fi( file ); - emit outputTextChanged( file ); - if( fi.isFile() || fi.isSymLink() ) - { - op->deleteFileNowOrLater( fi.absoluteFilePath() ); - } - else if( fi.isDir() ) - { + Q_FOREACH(const QString &file, m_files) { + const QFileInfo fi(file); + emit outputTextChanged(file); + if (fi.isFile() || fi.isSymLink()) { + op->deleteFileNowOrLater(fi.absoluteFilePath()); + } else if (fi.isDir()) { const QDir d = fi.dir(); // even remove some hidden, OS-created files in there #if defined Q_WS_MAC - op->deleteFileNowOrLater( file + QLatin1String( "/.DS_Store" ) ); + op->deleteFileNowOrLater(file + QLatin1String("/.DS_Store")); #elif defined Q_WS_WIN - op->deleteFileNowOrLater( file + QLatin1String( "/Thumbs.db" ) ); + op->deleteFileNowOrLater(file + QLatin1String("/Thumbs.db")); #endif - d.rmdir( file ); // directory may not exist + d.rmdir(file); // directory may not exist } const int newProgress = (index++) * 100 / count; - if( progress != newProgress ) - emit progressChanged( newProgress ); + if (progress != newProgress) + emit progressChanged(newProgress); progress = newProgress; } } bool ExtractArchiveOperation::undoOperation() { - Q_ASSERT( arguments().count() == 2 ); + Q_ASSERT(arguments().count() == 2); //const QString archivePath = arguments().first(); //const QString targetDir = arguments().last(); - const QStringList m_files = value( QLatin1String( "files" ) ).toStringList(); + const QStringList m_files = value(QLatin1String("files")).toStringList(); - WorkerThread* const thread = new WorkerThread( this, m_files ); + WorkerThread* const thread = new WorkerThread(this, m_files); connect(thread, SIGNAL(outputTextChanged(QString)), this, SIGNAL(outputTextChanged(QString)), Qt::QueuedConnection); - connect( thread, SIGNAL( progressChanged( int ) ), this, SIGNAL( progressChanged( int ) ), Qt::QueuedConnection ); + connect(thread, SIGNAL(progressChanged(int)), this, SIGNAL(progressChanged(int)), Qt::QueuedConnection); QEventLoop loop; - connect( thread, SIGNAL(finished()), &loop, SLOT( quit() ), Qt::QueuedConnection ); + connect(thread, SIGNAL(finished()), &loop, SLOT(quit()), Qt::QueuedConnection); thread->start(); loop.exec(); thread->deleteLater(); @@ -191,10 +187,10 @@ ExtractArchiveOperation* ExtractArchiveOperation::clone() const } //this slot is direct connected to the caller so please don't call it from another thread in the same time -void ExtractArchiveOperation::slotProgressChanged( const QString& filename ) +void ExtractArchiveOperation::slotProgressChanged(const QString& filename) { - QStringList m_files = value( QLatin1String( "files" ) ).toStringList(); - m_files.push_front( filename ); - setValue( QLatin1String( "files" ), m_files ); - emit outputTextChanged( filename ); + QStringList m_files = value(QLatin1String("files")).toStringList(); + m_files.push_front(filename); + setValue(QLatin1String("files"), m_files); + emit outputTextChanged(filename); } diff --git a/installerbuilder/libinstaller/installiconsoperation.cpp b/installerbuilder/libinstaller/installiconsoperation.cpp index c847b0343..7b1bfe85a 100644 --- a/installerbuilder/libinstaller/installiconsoperation.cpp +++ b/installerbuilder/libinstaller/installiconsoperation.cpp @@ -57,57 +57,57 @@ TRANSLATOR QInstaller::InstallIconsOperation QString InstallIconsOperation::targetDirectory() { // we're not searching for the first time, let's re-use the old value - if( hasValue( QLatin1String( "targetdirectory" ) ) ) - return value( QLatin1String( "targetdirectory" ) ).toString(); + if (hasValue(QLatin1String("targetdirectory"))) + return value(QLatin1String("targetdirectory")).toString(); #if QT_VERSION >= 0x040600 const QProcessEnvironment env; - QStringList XDG_DATA_DIRS = env.value( QLatin1String( "XDG_DATA_DIRS" ) ).split( QLatin1Char( ':' ), QString::SkipEmptyParts ); + QStringList XDG_DATA_DIRS = env.value(QLatin1String("XDG_DATA_DIRS")).split(QLatin1Char(':'), QString::SkipEmptyParts); #else const QStringList env = QProcess::systemEnvironment(); QStringList XDG_DATA_DIRS; - for( QStringList::const_iterator it = env.begin(); it != env.end(); ++it ) + for(QStringList::const_iterator it = env.begin(); it != env.end(); ++it) { - if( it->startsWith( QLatin1String( "XDG_DATA_DIRS=" ) ) ) - XDG_DATA_DIRS = it->mid( it->indexOf( QLatin1Char( '=' ) ) + 1 ).split( QLatin1Char( ':' ) ); + if (it->startsWith(QLatin1String("XDG_DATA_DIRS="))) + XDG_DATA_DIRS = it->mid(it->indexOf(QLatin1Char('=')) + 1).split(QLatin1Char(':')); } #endif - XDG_DATA_DIRS.push_back( QLatin1String( "/usr/share" ) ); // default path - XDG_DATA_DIRS.push_back( QDir::home().absoluteFilePath( QLatin1String( ".icons" ) ) ); // default path + XDG_DATA_DIRS.push_back(QLatin1String("/usr/share")); // default path + XDG_DATA_DIRS.push_back(QDir::home().absoluteFilePath(QLatin1String(".icons"))); // default path const QStringList& directories = XDG_DATA_DIRS; QString directory; - for( QStringList::const_iterator it = directories.begin(); it != directories.end(); ++it ) + for(QStringList::const_iterator it = directories.begin(); it != directories.end(); ++it) { - if( it->isEmpty() ) + if (it->isEmpty()) continue; - if( it + 1 == directories.end() ) - directory = QDir( *it ).absolutePath(); + if (it + 1 == directories.end()) + directory = QDir(*it).absolutePath(); else - directory = QDir( *it ).absoluteFilePath( QLatin1String( "icons" ) ); - QDir dir( directory ); + directory = QDir(*it).absoluteFilePath(QLatin1String("icons")); + QDir dir(directory); // let's see wheter this dir exists or we're able to create it - if( !dir.exists() && !QDir().mkpath( directory ) ) + if (!dir.exists() && !QDir().mkpath(directory)) continue; // we just try wheter we're able to open the file in ReadWrite - QFile file( QDir( directory ).absoluteFilePath( QLatin1String( "tmpfile" ) ) ); + QFile file(QDir(directory).absoluteFilePath(QLatin1String("tmpfile"))); const bool existed = file.exists(); - if( !file.open( QIODevice::ReadWrite ) ) + if (!file.open(QIODevice::ReadWrite)) continue; file.close(); - if( !existed ) + if (!existed) file.remove(); break; } - if( !QDir( directory ).exists() ) - QDir().mkpath( directory ); + if (!QDir(directory).exists()) + QDir().mkpath(directory); - setValue( QLatin1String( "directory" ), directory ); + setValue(QLatin1String("directory"), directory); return directory; @@ -115,16 +115,16 @@ QString InstallIconsOperation::targetDirectory() InstallIconsOperation::InstallIconsOperation() { - setName( QLatin1String( "InstallIcons" ) ); + setName(QLatin1String("InstallIcons")); } InstallIconsOperation::~InstallIconsOperation() { - const QStringList backupFiles = value( QLatin1String( "backupfiles" ) ).toStringList(); - for( QStringList::const_iterator it = backupFiles.begin(); it != backupFiles.end(); it += 2 ) + const QStringList backupFiles = value(QLatin1String("backupfiles")).toStringList(); + for(QStringList::const_iterator it = backupFiles.begin(); it != backupFiles.end(); it += 2) { - const QString& backup = *( it + 1 ); - deleteFileNowOrLater( backup ); + const QString& backup = *(it + 1); + deleteFileNowOrLater(backup); } } @@ -136,24 +136,22 @@ void InstallIconsOperation::backup() bool InstallIconsOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 1 ) - { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 1 expected.") - .arg(name()).arg( args.count() ) ); + if (args.count() != 1) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 1 expected.") + .arg(name()).arg(args.count())); return false; } const QString source = args.first(); - if( source.isEmpty() ) - { - setError( InvalidArguments ); - setErrorString( QObject::tr("Invalid Argument: source folder must not be empty.") ); + if (source.isEmpty()) { + setError(InvalidArguments); + setErrorString(QObject::tr("Invalid Argument: source folder must not be empty.")); return false; } - const QDir sourceDir = QDir( source ); - const QDir targetDir = QDir( targetDirectory() ); + const QDir sourceDir = QDir(source); + const QDir targetDir = QDir(targetDirectory()); QStringList files; QStringList backupFiles; @@ -163,58 +161,52 @@ bool InstallIconsOperation::performOperation() int currentItem = 0; // iterate a first time to count the items (for proper progress) - QDirIterator itCount( sourceDir.path(), QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories ); - while( itCount.hasNext() ) - { + QDirIterator itCount(sourceDir.path(), QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + while (itCount.hasNext()) { itCount.next(); ++numItems; } - Installer* const installer = qVariantValue< Installer* >( value( QLatin1String( "installer" ) ) ); + Installer* const installer = qVariantValue< Installer* >(value(QLatin1String("installer"))); // iterate a second time to get the actual work done - QDirIterator it( sourceDir.path(), QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories ); - while( it.hasNext() ) - { + QDirIterator it(sourceDir.path(), QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + while (it.hasNext()) { qApp->processEvents(); const int status = installer->status(); - if( status == Installer::InstallerCanceledByUser || status == Installer::InstallerFailed ) + if (status == Installer::InstallerCanceledByUser || status == Installer::InstallerFailed) return true; const QString source = it.next(); - const QString target = targetDir.absoluteFilePath( sourceDir.relativeFilePath( source ) ); + const QString target = targetDir.absoluteFilePath(sourceDir.relativeFilePath(source)); - emit outputTextChanged( target ); - emit progressChanged( ++currentItem * 100 / numItems ); + emit outputTextChanged(target); + emit progressChanged(++currentItem * 100 / numItems); const QFileInfo fi = it.fileInfo(); - if( !fi.isDir() ) - { - if( QFile( target ).exists() ) - { + if (!fi.isDir()) { + if (QFile(target).exists()) { // first backup... - const QString backup = generateTemporaryFileName( target + QLatin1String("XXXXXX") ); - QFile bf( target ); - if( !bf.copy( backup ) ) - { - setError( UserDefinedError ); - setErrorString( QObject::tr( "Could not backup file %1: %2" ).arg( target, bf.errorString() ) ); + const QString backup = generateTemporaryFileName(target + QLatin1String("XXXXXX")); + QFile bf(target); + if (!bf.copy(backup)) { + setError(UserDefinedError); + setErrorString(QObject::tr("Could not backup file %1: %2").arg(target, bf.errorString())); undoOperation(); return false; } - backupFiles.push_back( target ); - backupFiles.push_back( backup ); - setValue( QLatin1String( "backupfiles" ), backupFiles ); + backupFiles.push_back(target); + backupFiles.push_back(backup); + setValue(QLatin1String("backupfiles"), backupFiles); // then delete it QString errStr; - if( !deleteFileNowOrLater( target, &errStr ) ) - { - setError( UserDefinedError ); - setErrorString( QObject::tr( "Failed to overwrite %1: %2" ).arg( target, errStr ) ); + if (!deleteFileNowOrLater(target, &errStr)) { + setError(UserDefinedError); + setErrorString(QObject::tr("Failed to overwrite %1: %2").arg(target, errStr)); undoOperation(); return false; } @@ -222,39 +214,33 @@ bool InstallIconsOperation::performOperation() } // copy the file to its new location - QFile cf( source ); - if( !cf.copy( target ) ) - { - setError( UserDefinedError ); - setErrorString( QObject::tr( "Failed to copy file %1: %2" ).arg( target, cf.errorString() ) ); + QFile cf(source); + if (!cf.copy(target)) { + setError(UserDefinedError); + setErrorString(QObject::tr("Failed to copy file %1: %2").arg(target, cf.errorString())); undoOperation(); return false; } - deleteFileNowOrLater( source ); - files.push_back( source ); - files.push_back( target ); - setValue( QLatin1String( "files" ), files ); - } - else if( fi.isDir() && !QDir( target ).exists() ) - { - if( !QDir().mkpath( target ) ) - { - setErrorString( QObject::tr( "Could not create folder at %1: %2" ).arg( target, qt_error_string() ) ); + deleteFileNowOrLater(source); + files.push_back(source); + files.push_back(target); + setValue(QLatin1String("files"), files); + } else if (fi.isDir() && !QDir(target).exists()) { + if (!QDir().mkpath(target)) { + setErrorString(QObject::tr("Could not create folder at %1: %2").arg(target, qt_error_string())); undoOperation(); return false; } - createdDirectories.push_front( target ); - setValue( QLatin1String( "createddirectories" ), createdDirectories ); + createdDirectories.push_front(target); + setValue(QLatin1String("createddirectories"), createdDirectories); } } // this should work now if not, it's not _that_ problematic... - try - { - removeDirectory( source ); + try { + removeDirectory(source); } - catch( ... ) - { + catch(...) { } // reached this? cool :-) @@ -266,51 +252,48 @@ bool InstallIconsOperation::undoOperation() bool success = true; // first copy back all files to their origin - const QStringList files = value( QLatin1String( "files" ) ).toStringList(); - for( QStringList::const_iterator it = files.begin(); it != files.end(); it += 2 ) - { + const QStringList files = value(QLatin1String("files")).toStringList(); + for (QStringList::const_iterator it = files.begin(); it != files.end(); it += 2) { qApp->processEvents(); const QString& source = *it; - const QString& target = *( it + 1 ); + const QString& target = *(it + 1); // first make sure the "source" path is valid - QDir().mkpath( QFileInfo( source ).absolutePath() ); + QDir().mkpath(QFileInfo(source).absolutePath()); // now copy target to source (feels weird, I know...) - success = QFile::copy( target, source ) && success; + success = QFile::copy(target, source) && success; // and remove target - success = QFile::remove( target ) && success; + success = QFile::remove(target) && success; } // then copy back and remove all backuped files - const QStringList backupFiles = value( QLatin1String( "backupfiles" ) ).toStringList(); - for( QStringList::const_iterator it = backupFiles.begin(); it != backupFiles.end(); it += 2 ) - { + const QStringList backupFiles = value(QLatin1String("backupfiles")).toStringList(); + for (QStringList::const_iterator it = backupFiles.begin(); it != backupFiles.end(); it += 2) { const QString& target = *it; - const QString& backup = *( it + 1 ); + const QString& backup = *(it + 1); // remove the target - if( QFile::exists( target ) ) - success = deleteFileNowOrLater( target ) && success; + if (QFile::exists(target)) + success = deleteFileNowOrLater(target) && success; // then copy the backup onto the target - success = QFile::copy( backup, target ) && success; + success = QFile::copy(backup, target) && success; // finally remove the backp - success = deleteFileNowOrLater( backup ) && success; + success = deleteFileNowOrLater(backup) && success; } // then remove all directories created by us - const QStringList createdDirectories = value( QLatin1String( "createddirectories" ) ).toStringList(); - for( QStringList::const_iterator it = createdDirectories.begin(); it != createdDirectories.end(); ++it ) - { - const QDir dir( *it ); + const QStringList createdDirectories = value(QLatin1String("createddirectories")).toStringList(); + for(QStringList::const_iterator it = createdDirectories.begin(); it != createdDirectories.end(); ++it) { + const QDir dir(*it); // even remove some hidden, OS-created files in there #if defined Q_WS_MAC - QFile::remove( dir.absoluteFilePath( QLatin1String( ".DS_Store" ) ) ); + QFile::remove(dir.absoluteFilePath(QLatin1String(".DS_Store"))); #elif defined Q_WS_WIN - QFile::remove( dir.absoluteFilePath( QLatin1String( "/Thumbs.db" ) ) ); + QFile::remove(dir.absoluteFilePath(QLatin1String("/Thumbs.db"))); #endif - success = QDir::root().rmdir( dir.path() ); + success = QDir::root().rmdir(dir.path()); } return success; diff --git a/installerbuilder/libinstaller/qtpatchoperation.cpp b/installerbuilder/libinstaller/qtpatchoperation.cpp index fe791fec7..e6da1ee18 100644 --- a/installerbuilder/libinstaller/qtpatchoperation.cpp +++ b/installerbuilder/libinstaller/qtpatchoperation.cpp @@ -52,63 +52,63 @@ using namespace QInstaller; //"anonymous" namespace to make clear that this is only for inside use namespace { - QMap<QByteArray, QByteArray> generatePatchValueMap( const QByteArray & newQtPath, - const QHash<QString, QByteArray> & qmakeValueHash ) + QMap<QByteArray, QByteArray> generatePatchValueMap(const QByteArray & newQtPath, + const QHash<QString, QByteArray> & qmakeValueHash) { QMap<QByteArray, QByteArray> replaceMap; //first == searchstring: second == replace string char nativeSeperator = QDir::separator().toAscii(); QByteArray oldValue; - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_PREFIX") ); - replaceMap.insert( QByteArray("qt_prfxpath=%1").replace( "%1", oldValue ), - QByteArray("qt_prfxpath=%1/").replace( "%1/", newQtPath ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_PREFIX")); + replaceMap.insert(QByteArray("qt_prfxpath=%1").replace("%1", oldValue), + QByteArray("qt_prfxpath=%1/").replace("%1/", newQtPath)); - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_DOCS") ); - replaceMap.insert( QByteArray("qt_docspath=%1").replace( "%1", oldValue ), - QByteArray("qt_docspath=%1/doc").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_DOCS")); + replaceMap.insert(QByteArray("qt_docspath=%1").replace("%1", oldValue), + QByteArray("qt_docspath=%1/doc").replace("%1/", newQtPath + nativeSeperator)); - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_HEADERS") ); - replaceMap.insert( QByteArray("qt_hdrspath=%1").replace( "%1", oldValue ), - QByteArray("qt_hdrspath=%1/include").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_HEADERS")); + replaceMap.insert(QByteArray("qt_hdrspath=%1").replace("%1", oldValue), + QByteArray("qt_hdrspath=%1/include").replace("%1/", newQtPath + nativeSeperator)); - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_LIBS") ); - replaceMap.insert( QByteArray("qt_libspath=%1").replace( "%1", oldValue ), - QByteArray("qt_libspath=%1/lib").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_LIBS")); + replaceMap.insert(QByteArray("qt_libspath=%1").replace("%1", oldValue), + QByteArray("qt_libspath=%1/lib").replace("%1/", newQtPath + nativeSeperator)); - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_BINS") ); - replaceMap.insert( QByteArray("qt_binspath=%1").replace( "%1", oldValue ), - QByteArray("qt_binspath=%1/bin").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_BINS")); + replaceMap.insert(QByteArray("qt_binspath=%1").replace("%1", oldValue), + QByteArray("qt_binspath=%1/bin").replace("%1/", newQtPath + nativeSeperator)); - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_PLUGINS") ); - replaceMap.insert( QByteArray("qt_plugpath=%1").replace( "%1", oldValue ), - QByteArray("qt_plugpath=%1/plugins").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_PLUGINS")); + replaceMap.insert(QByteArray("qt_plugpath=%1").replace("%1", oldValue), + QByteArray("qt_plugpath=%1/plugins").replace("%1/", newQtPath + nativeSeperator)); - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_IMPORTS") ); - replaceMap.insert( QByteArray("qt_impspath=%1").replace( "%1", oldValue ), - QByteArray("qt_impspath=%1/imports").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_IMPORTS")); + replaceMap.insert(QByteArray("qt_impspath=%1").replace("%1", oldValue), + QByteArray("qt_impspath=%1/imports").replace("%1/", newQtPath + nativeSeperator)); - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_DATA") ); - replaceMap.insert( QByteArray("qt_datapath=%1").replace( "%1", oldValue ), - QByteArray("qt_datapath=%1/").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_DATA")); + replaceMap.insert( QByteArray("qt_datapath=%1").replace("%1", oldValue), + QByteArray("qt_datapath=%1/").replace("%1/", newQtPath + nativeSeperator)); - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_TRANSLATIONS") ); - replaceMap.insert( QByteArray("qt_trnspath=%1").replace( "%1", oldValue ), - QByteArray("qt_trnspath=%1/translations").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_TRANSLATIONS")); + replaceMap.insert( QByteArray("qt_trnspath=%1").replace("%1", oldValue), + QByteArray("qt_trnspath=%1/translations").replace("%1/", newQtPath + nativeSeperator)); // This must not be patched. Commenting out to fix QTSDK-429 -// oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_CONFIGURATION")); -// replaceMap.insert( QByteArray("qt_stngpath=%1").replace( "%1", oldValue), -// QByteArray("qt_stngpath=%1").replace( "%1", newQtPath)); +// oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_CONFIGURATION")); +// replaceMap.insert( QByteArray("qt_stngpath=%1").replace("%1", oldValue), +// QByteArray("qt_stngpath=%1").replace("%1", newQtPath)); //examples and demoes can patched outside separately, //but for cosmetic reasons - if the qt version gets no examples later. - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_EXAMPLES") ); - replaceMap.insert( QByteArray("qt_xmplpath=%1").replace( "%1", oldValue ), - QByteArray("qt_xmplpath=%1/examples").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_EXAMPLES")); + replaceMap.insert( QByteArray("qt_xmplpath=%1").replace("%1", oldValue), + QByteArray("qt_xmplpath=%1/examples").replace("%1/", newQtPath + nativeSeperator)); - oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_DEMOS") ); - replaceMap.insert( QByteArray("qt_demopath=%1").replace( "%1", oldValue ), - QByteArray("qt_demopath=%1/demos").replace( "%1/", newQtPath + nativeSeperator ) ); + oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_DEMOS")); + replaceMap.insert( QByteArray("qt_demopath=%1").replace("%1", oldValue), + QByteArray("qt_demopath=%1/demos").replace("%1/", newQtPath + nativeSeperator)); return replaceMap; } @@ -134,10 +134,10 @@ bool QtPatchOperation::performOperation() // 1. type // 2. new/target qtpath - if( arguments().count() != 2 ) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 2 expected.") - .arg(name()).arg( arguments().count() ) ); + if(arguments().count() != 2) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2 expected.") + .arg(name()).arg(arguments().count())); return false; } @@ -148,11 +148,11 @@ bool QtPatchOperation::performOperation() type.contains(QLatin1String("mac"), Qt::CaseInsensitive); if (!isPlatformSupported) { - setError( InvalidArguments ); - setErrorString( tr("First argument should be 'linux', 'mac' or 'windows'. No other type is supported at this time.") ); + setError(InvalidArguments); + setErrorString(tr("First argument should be 'linux', 'mac' or 'windows'. No other type is supported at this time.")); return false; } - const QString newQtPathStr = QDir::toNativeSeparators( arguments().at(1) ); + const QString newQtPathStr = QDir::toNativeSeparators(arguments().at(1)); const QByteArray newQtPath = newQtPathStr.toUtf8(); QString qmakePath = QString::fromUtf8(newQtPath) + QLatin1String("/bin/qmake"); @@ -162,10 +162,10 @@ bool QtPatchOperation::performOperation() if (!QFile::exists(qmakePath)) { - setError( UserDefinedError ); - setErrorString( tr("QMake from the current Qt version \n(%1)" \ + setError(UserDefinedError); + setErrorString(tr("QMake from the current Qt version \n(%1)" \ "is not existing. Please make a bugreport with this dialog at http://bugreports.qt.nokia.com.\n" \ - ).arg(QDir::toNativeSeparators(qmakePath))); + ).arg(QDir::toNativeSeparators(qmakePath))); return false; } @@ -174,35 +174,35 @@ bool QtPatchOperation::performOperation() if (qmakeValueHash.isEmpty()) { - setError( UserDefinedError ); - setErrorString( tr("The output of \n%1 -query\n" \ + setError(UserDefinedError); + setErrorString(tr("The output of \n%1 -query\n" \ "is not parseable. Please make a bugreport with this dialog http://bugreports.qt.nokia.com.\n" \ "output: \"%2\"").arg(QDir::toNativeSeparators(qmakePath), QString::fromUtf8(qmakeOutput))); return false; } - const QByteArray oldQtPath = qmakeValueHash.value( QLatin1String("QT_INSTALL_PREFIX") ); + const QByteArray oldQtPath = qmakeValueHash.value(QLatin1String("QT_INSTALL_PREFIX")); bool oldQtPathFromQMakeIsEmpty = oldQtPath.isEmpty(); //maybe we don't need this, but I 255 should be a rational limit if (255 < newQtPath.size()) { - setError( UserDefinedError ); - setErrorString( tr("Qt patch error: new Qt dir(%1)\n" \ - "needs to be less than 255 characters.").arg(newQtPathStr) ); + setError(UserDefinedError); + setErrorString(tr("Qt patch error: new Qt dir(%1)\n" \ + "needs to be less than 255 characters.").arg(newQtPathStr)); return false; } QFile patchFileListFile; - if( type == QLatin1String("windows") ) - patchFileListFile.setFileName( QLatin1String(":/files-to-patch-windows") ); - else if( type == QLatin1String("linux") ) - patchFileListFile.setFileName( QLatin1String(":/files-to-patch-linux") ); + if(type == QLatin1String("windows")) + patchFileListFile.setFileName(QLatin1String(":/files-to-patch-windows")); + else if(type == QLatin1String("linux")) + patchFileListFile.setFileName(QLatin1String(":/files-to-patch-linux")); else if (type == QLatin1String("mac")) - patchFileListFile.setFileName( QLatin1String(":/files-to-patch-macx") ); + patchFileListFile.setFileName(QLatin1String(":/files-to-patch-macx")); if (! patchFileListFile.open(QFile::ReadOnly)) { - setError( UserDefinedError ); - setErrorString( tr("Qt patch error: Can not open %1.").arg(patchFileListFile.fileName()) ); + setError(UserDefinedError); + setErrorString(tr("Qt patch error: Can not open %1.").arg(patchFileListFile.fileName())); return false; } @@ -234,7 +234,7 @@ bool QtPatchOperation::performOperation() QString prefix = QFile::decodeName(newQtPath); - if (! prefix.endsWith(QLatin1Char('/')) ) + if (! prefix.endsWith(QLatin1Char('/'))) prefix += QLatin1Char('/'); //BEGIN - patch binary files @@ -250,8 +250,8 @@ bool QtPatchOperation::performOperation() } if (!QtPatch::openFileForPatching(&file)) { - setError( UserDefinedError ); - setErrorString( tr("Qt patch error: Can not open %1(%2).").arg(file.fileName()).arg(file.errorString()) ); + setError(UserDefinedError); + setErrorString(tr("Qt patch error: Can not open %1(%2).").arg(file.fileName()).arg(file.errorString())); return false; } @@ -310,7 +310,7 @@ bool QtPatchOperation::performOperation() bool successMacRelocating = false; const Installer* const installer = qVariantValue<Installer*>(value(QLatin1String("installer"))); if (!installer) { - setError( UserDefinedError ); + setError(UserDefinedError); setErrorString(tr("Needed installer object in \"%1\" operation is empty.").arg(name())); return false; } @@ -318,19 +318,18 @@ bool QtPatchOperation::performOperation() successMacRelocating = relocator.apply(newQtPathStr, installer->value(QLatin1String("TargetDir"))); if (!successMacRelocating) { - setError( UserDefinedError ); + setError(UserDefinedError); setErrorString(tr("Error while relocating Qt: %1").arg(relocator.errorMessage())); return false; } #endif - if (oldQtPathFromQMakeIsEmpty) - { - setError( UserDefinedError ); - setErrorString( tr("The installer was not able to get the unpatched path from \n%1.(maybe it is broken or removed)\n" \ + if (oldQtPathFromQMakeIsEmpty) { + setError(UserDefinedError); + setErrorString(tr("The installer was not able to get the unpatched path from \n%1.(maybe it is broken or removed)\n" \ "It tried to patch the Qt binaries, but all other files in Qt are unpatched.\n" \ "This could result in a broken Qt version.\n" \ "Sometimes it helps to restart the installer with a switched off antivirus software." - ).arg(QDir::toNativeSeparators(qmakePath))); + ).arg(QDir::toNativeSeparators(qmakePath))); return false; } diff --git a/installerbuilder/libinstaller/registerdocumentationoperation.cpp b/installerbuilder/libinstaller/registerdocumentationoperation.cpp index 3b8352e92..1e334a0ca 100644 --- a/installerbuilder/libinstaller/registerdocumentationoperation.cpp +++ b/installerbuilder/libinstaller/registerdocumentationoperation.cpp @@ -89,10 +89,10 @@ bool RegisterDocumentationOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 1 ) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 1 expected.") - .arg(name()).arg( args.count() ) ); + if (args.count() != 1) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 1 expected.") + .arg(name()).arg( args.count())); return false; } const QString helpFile = args.at(0); @@ -106,8 +106,8 @@ bool RegisterDocumentationOperation::performOperation() const QString collectionFile = settingsDir.absolutePath() + QLatin1String("/helpcollection.qhc"); qDebug() << "collectionFile: " << collectionFile; - if ( !QFileInfo( helpFile ).exists() ) { - setError ( UserDefinedError ); + if (!QFileInfo( helpFile ).exists()) { + setError(UserDefinedError); setErrorString( tr("Could not register help file %1: File not found.").arg( helpFile ) ); return false; } @@ -131,7 +131,7 @@ bool RegisterDocumentationOperation::undoOperation() settingsDir.mkpath(settingsDir.absolutePath()); const QString collectionFile = settingsDir.absolutePath() + QLatin1String("/helpcollection.qhc"); - if ( !QFileInfo( helpFile ).exists() ) { + if (!QFileInfo( helpFile ).exists()) { setError ( UserDefinedError ); setErrorString( tr("Could not unregister help file %1: File not found.").arg( helpFile ) ); return false; diff --git a/installerbuilder/libinstaller/registerfiletypeoperation.cpp b/installerbuilder/libinstaller/registerfiletypeoperation.cpp index c2c2c88db..21000cf9e 100644 --- a/installerbuilder/libinstaller/registerfiletypeoperation.cpp +++ b/installerbuilder/libinstaller/registerfiletypeoperation.cpp @@ -60,10 +60,9 @@ bool RegisterFileTypeOperation::performOperation() // (content type) // (icon) #ifdef Q_WS_WIN - if( arguments().count() < 2 || arguments().count() > 5 ) - { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0").arg(name()) ); + if (arguments().count() < 2 || arguments().count() > 5) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0").arg(name())); return false; } const QString extension = arguments()[ 0 ]; @@ -75,46 +74,44 @@ bool RegisterFileTypeOperation::performOperation() const QString settingsPrefix = QString::fromLatin1( "Software/Classes/" ); //QSettings settings( QLatin1String( "HKEY_CLASSES_ROOT" ), QSettings::NativeFormat ); - QSettings settings( QLatin1String( "HKEY_CURRENT_USER" ), QSettings::NativeFormat ); + QSettings settings(QLatin1String("HKEY_CURRENT_USER"), QSettings::NativeFormat); // first backup the old values - setValue( QLatin1String( "oldClass" ), settings.value( QString::fromLatin1( "%1.%2/Default" ).arg( settingsPrefix, extension ) ) ); - setValue( QLatin1String( "oldContentType" ), settings.value( QString::fromLatin1( "%1.%2/Content Type" ).arg( settingsPrefix, extension ) ) ); + setValue(QLatin1String("oldClass"), settings.value(QString::fromLatin1("%1.%2/Default").arg(settingsPrefix, extension))); + setValue(QLatin1String("oldContentType"), settings.value(QString::fromLatin1("%1.%2/Content Type").arg(settingsPrefix, extension))); // the file extension was not yet registered. Let's do so now - settings.setValue( QString::fromLatin1( "%1.%2/Default" ).arg( settingsPrefix, extension ), - className ); + settings.setValue(QString::fromLatin1("%1.%2/Default").arg(settingsPrefix, extension), className); // register the content type, if given - if( !contentType.isEmpty() ) - settings.setValue( QString::fromLatin1( "%1.%2/Content Type" ).arg( settingsPrefix, extension ), - contentType ); + if (!contentType.isEmpty()) + settings.setValue(QString::fromLatin1("%1.%2/Content Type").arg(settingsPrefix, extension), contentType); //const QString className = settings.value( QString::fromLatin1( ".%1/Default" ).arg( extension ) ).toString(); //const QString oldClassName = value( QString::fromLatin1( ".%1/Default" ).arg( extension ) ).toString(); - setValue( QLatin1String( "className" ), className ); + setValue(QLatin1String("className"), className); // setValue( QLatin1String( "oldDescription" ), settings.value( QString::fromLatin1( "%1/Default" ).arg( oldClassName ) ) ); // setValue( QLatin1String( "oldIcon" ), settings.value( QString::fromLatin1( "%1/DefaultIcon/Default" ).arg( oldClassName ) ) ); // setValue( QLatin1String( "oldCommand" ), settings.value( QString::fromLatin1( "%1/shell/Open/Command/Default" ).arg( oldClassName ) ) ); // register the description, if given - if( !description.isEmpty() ) - settings.setValue( QString::fromLatin1( "%1%2/Default" ).arg( settingsPrefix, className ), - description ); + if (!description.isEmpty()) + settings.setValue(QString::fromLatin1("%1%2/Default").arg(settingsPrefix, className), description); // register the icon, if given - if( !icon.isEmpty() ) - settings.setValue( QString::fromLatin1( "%1%2/DefaultIcon/Default" ).arg( settingsPrefix, className ), - icon ); + if (!icon.isEmpty()) { + settings.setValue(QString::fromLatin1("%1%2/DefaultIcon/Default").arg(settingsPrefix, + className), icon); + } // register the command to open the file - settings.setValue( QString::fromLatin1( "%1%2/shell/Open/Command/Default" ).arg( settingsPrefix, className ), - command ); + settings.setValue(QString::fromLatin1("%1%2/shell/Open/Command/Default").arg(settingsPrefix, + className), command ); return true; #else - setError( UserDefinedError ); - setErrorString( QObject::tr( "Registering file types in only supported on Windows." ) ); + setError(UserDefinedError); + setErrorString(QObject::tr("Registering file types in only supported on Windows.")); return false; #endif } @@ -127,61 +124,65 @@ bool RegisterFileTypeOperation::undoOperation() // (content type) // (icon) #ifdef Q_WS_WIN - if( arguments().count() < 2 || arguments().count() > 5 ) - { - setErrorString( tr("Register File Type: Invalid arguments") ); + if (arguments().count() < 2 || arguments().count() > 5) { + setErrorString(tr("Register File Type: Invalid arguments")); return false; } - const QString extension = arguments()[ 0 ]; - const QString command = arguments()[ 1 ]; - const QString description = arguments().count() > 2 ? arguments()[ 2 ] : QString(); // optional - const QString contentType = arguments().count() > 3 ? arguments()[ 3 ] : QString(); // optional - const QString icon = arguments().count() > 4 ? arguments()[ 4 ] : QString(); // optional - const QString className = QString::fromLatin1( "%1_auto_file" ).arg( extension ); - const QString settingsPrefix = QString::fromLatin1( "Software/Classes/" ); + const QString extension = arguments()[0]; + const QString command = arguments()[1]; + const QString description = arguments().count() > 2 ? arguments()[2] : QString(); // optional + const QString contentType = arguments().count() > 3 ? arguments()[3] : QString(); // optional + const QString icon = arguments().count() > 4 ? arguments()[4] : QString(); // optional + const QString className = QString::fromLatin1("%1_auto_file").arg(extension); + const QString settingsPrefix = QString::fromLatin1("Software/Classes/"); - QSettings settings( QLatin1String( "HKEY_CURRENT_USER" ), QSettings::NativeFormat ); + QSettings settings(QLatin1String("HKEY_CURRENT_USER"), QSettings::NativeFormat); - const QString restoredClassName = value( QLatin1String( "oldClassName" ) ).toString(); + const QString restoredClassName = value(QLatin1String("oldClassName")).toString(); // register the command to open the file - if( settings.value( QString::fromLatin1( "%1%2/shell/Open/Command/Default" ).arg( settingsPrefix, className ) ).toString() != command ) + if (settings.value(QString::fromLatin1("%1%2/shell/Open/Command/Default").arg(settingsPrefix, className)).toString() != command) return false; - if( settings.value( QString::fromLatin1( "%1%2/DefaultIcon/Default" ).arg( settingsPrefix, className ) ).toString() != icon ) + if (settings.value(QString::fromLatin1("%1%2/DefaultIcon/Default").arg(settingsPrefix, className)).toString() != icon) return false; - if( settings.value( QString::fromLatin1( "%1%2/Default" ).arg( settingsPrefix, className ) ).toString() != description ) + if (settings.value(QString::fromLatin1("%1%2/Default").arg(settingsPrefix, className)).toString() != description) return false; - if( settings.value( QString::fromLatin1( "%1.%2/Content Type" ).arg( settingsPrefix, extension ) ).toString() != contentType ) + if (settings.value(QString::fromLatin1("%1.%2/Content Type").arg(settingsPrefix, extension)).toString() != contentType) return false; - if( settings.value( QString::fromLatin1( "%1.%2/Default" ).arg( settingsPrefix, extension ) ).toString() != className ) + if (settings.value(QString::fromLatin1("%1.%2/Default").arg(settingsPrefix, extension)).toString() != className) return false; - const QVariant oldCommand = value( QLatin1String( "oldCommand" ) ); - if( !oldCommand.isNull() ) - settings.setValue( QString::fromLatin1( "%1%2/shell/Open/Command/Default" ).arg( settingsPrefix, restoredClassName ), - oldCommand ); - else - settings.remove( QString::fromLatin1( "%1%2/shell/Open/Command/Default" ).arg( settingsPrefix, className ) ); + const QVariant oldCommand = value(QLatin1String("oldCommand")); + if (!oldCommand.isNull()) { + settings.setValue(QString::fromLatin1("%1%2/shell/Open/Command/Default").arg(settingsPrefix, + restoredClassName ), oldCommand); + } else { + settings.remove(QString::fromLatin1("%1%2/shell/Open/Command/Default").arg(settingsPrefix, + className)); + } // register the icon, if given - const QVariant oldIcon = value( QLatin1String( "oldIcon" ) ); - if( !oldIcon.isNull() ) - settings.setValue( QString::fromLatin1( "%1%2/DefaultIcon/Default" ).arg( settingsPrefix, restoredClassName ), - oldIcon ); - else - settings.remove( QString::fromLatin1( "%1%2/DefaultIcon/Default" ).arg( settingsPrefix, className ) ); + const QVariant oldIcon = value(QLatin1String("oldIcon")); + if (!oldIcon.isNull()) { + settings.setValue(QString::fromLatin1("%1%2/DefaultIcon/Default").arg( settingsPrefix, + restoredClassName), oldIcon); + } else { + settings.remove(QString::fromLatin1("%1%2/DefaultIcon/Default").arg(settingsPrefix, + className)); + } // register the description, if given - const QVariant oldDescription = value( QLatin1String( "oldDescription" ) ); - if( !oldDescription.isNull() ) - settings.setValue( QString::fromLatin1( "%1%2/Default" ).arg( settingsPrefix, restoredClassName ), - oldDescription ); - else - settings.remove( QString::fromLatin1( "%1%2/Default" ).arg( settingsPrefix, className ) ); + const QVariant oldDescription = value(QLatin1String("oldDescription")); + if (!oldDescription.isNull()) { + settings.setValue(QString::fromLatin1("%1%2/Default").arg(settingsPrefix, restoredClassName), + oldDescription ); + } else { + settings.remove(QString::fromLatin1("%1%2/Default").arg(settingsPrefix, className)); + } // content type - settings.remove( QString::fromLatin1( "%1%2" ).arg( settingsPrefix, className ) ); + settings.remove(QString::fromLatin1("%1%2").arg(settingsPrefix, className)); const QVariant oldContentType = value( QLatin1String( "oldContentType" ) ); if( !oldContentType.isNull() ) diff --git a/installerbuilder/libinstaller/registerqtoperation.cpp b/installerbuilder/libinstaller/registerqtoperation.cpp index c4e419529..e83d998a8 100644 --- a/installerbuilder/libinstaller/registerqtoperation.cpp +++ b/installerbuilder/libinstaller/registerqtoperation.cpp @@ -66,9 +66,9 @@ bool RegisterQtInCreatorOperation::performOperation() const QStringList args = arguments(); if( args.count() < 3) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, minimum 3 expected.") - .arg(name()).arg( args.count() ) ); + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, minimum 3 expected.") + .arg(name()).arg( args.count())); return false; } diff --git a/installerbuilder/libinstaller/registerqtv2operation.cpp b/installerbuilder/libinstaller/registerqtv2operation.cpp index 90f7d1a20..b797e0b39 100644 --- a/installerbuilder/libinstaller/registerqtv2operation.cpp +++ b/installerbuilder/libinstaller/registerqtv2operation.cpp @@ -67,7 +67,7 @@ bool RegisterQtInCreatorV2Operation::performOperation() const QStringList args = arguments(); if (args.count() < 2) { - setError( InvalidArguments ); + setError(InvalidArguments); setErrorString( tr("Invalid arguments in %0: %1 arguments given, minimum 2 expected.") .arg(name()).arg( args.count() ) ); return false; @@ -75,7 +75,7 @@ bool RegisterQtInCreatorV2Operation::performOperation() const Installer* const installer = qVariantValue<Installer*>(value(QLatin1String("installer"))); if (!installer) { - setError( UserDefinedError ); + setError(UserDefinedError); setErrorString(tr("Needed installer object in \"%1\" operation is empty.").arg(name())); return false; } @@ -137,7 +137,7 @@ bool RegisterQtInCreatorV2Operation::undoOperation() const QStringList args = arguments(); if (args.count() < 2) { - setError( InvalidArguments ); + setError(InvalidArguments); setErrorString( tr("Invalid arguments in %0: %1 arguments given, minimum 2 expected.") .arg(name()).arg( args.count() ) ); return false; @@ -145,7 +145,7 @@ bool RegisterQtInCreatorV2Operation::undoOperation() const Installer* const installer = qVariantValue<Installer*>(value(QLatin1String("installer"))); if (!installer) { - setError( UserDefinedError ); + setError(UserDefinedError); setErrorString(tr("Needed installer object in \"%1\" operation is empty.").arg(name())); return false; } @@ -155,7 +155,7 @@ bool RegisterQtInCreatorV2Operation::undoOperation() const QString &versionName = args.value(argCounter++); const QString &path = args.value(argCounter++); QString qmakePath = QDir(path).absolutePath(); - if ( !qmakePath.endsWith(QLatin1String("qmake")) + if (!qmakePath.endsWith(QLatin1String("qmake")) || !qmakePath.endsWith(QLatin1String("qmake.exe"))) { #if defined ( Q_OS_WIN ) diff --git a/installerbuilder/libinstaller/registertoolchainoperation.cpp b/installerbuilder/libinstaller/registertoolchainoperation.cpp index 4c7f4270f..ff5d6f8f7 100644 --- a/installerbuilder/libinstaller/registertoolchainoperation.cpp +++ b/installerbuilder/libinstaller/registertoolchainoperation.cpp @@ -79,15 +79,15 @@ bool RegisterToolChainOperation::performOperation() const QStringList args = arguments(); if (args.count() < 4) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, minimum 4 expected.") - .arg(name()).arg( args.count() ) ); + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, minimum 4 expected.") + .arg(name()).arg(args.count())); return false; } const Installer* const installer = qVariantValue<Installer*>(value(QLatin1String("installer"))); if (!installer) { - setError( UserDefinedError ); + setError(UserDefinedError); setErrorString(tr("Needed installer object in \"%1\" operation is empty.").arg(name())); return false; } @@ -122,7 +122,7 @@ bool RegisterToolChainOperation::performOperation() // Check version: int version = data.value(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 0).toInt(); if (version < 1) { - setError( UserDefinedError ); + setError(UserDefinedError); setErrorString(tr("Toolchain settings xml file %1 has not the right version.") .arg(toolChainsXmlFilePath)); return false; @@ -182,9 +182,9 @@ bool RegisterToolChainOperation::undoOperation() const QStringList args = arguments(); if (args.count() < 4) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, minimum 4 expected.") - .arg(name()).arg( args.count() ) ); + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, minimum 4 expected.") + .arg(name()).arg( args.count() ) ); return false; } @@ -192,9 +192,7 @@ bool RegisterToolChainOperation::undoOperation() const QString &rootInstallPath = installer->value(QLatin1String("TargetDir")); int argCounter = 0; - const QString &toolChainKey = args.at(argCounter++); //Qt SDK:gccPath const QString &toolChainType = args.at(argCounter++); //where this toolchain is defined in QtCreator - const QString &displayName = args.at(argCounter++); //nice special Toolchain (Qt SDK) const QString &abiString = args.at(argCounter++); //x86-windows-msys-pe-32bit const QString &compilerPath = args.at(argCounter++); //gccPath QString debuggerPath; @@ -222,7 +220,7 @@ bool RegisterToolChainOperation::undoOperation() // Check version: int version = data.value(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 0).toInt(); if (version < 1) { - setError( UserDefinedError ); + setError(UserDefinedError); setErrorString(tr("Toolchain settings xml file %1 has not the right version.") .arg(toolChainsXmlFilePath)); return false; diff --git a/installerbuilder/libinstaller/replaceoperation.cpp b/installerbuilder/libinstaller/replaceoperation.cpp index 4b9f31260..d7b50d733 100644 --- a/installerbuilder/libinstaller/replaceoperation.cpp +++ b/installerbuilder/libinstaller/replaceoperation.cpp @@ -61,9 +61,9 @@ bool ReplaceOperation::performOperation() // 1. filename // 2. Source-String // 3. Replace-String - if( args.count() != 3 ) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 3 expected.") + if (args.count() != 3) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 3 expected.") .arg(name()).arg( args.count() ) ); return false; } @@ -78,8 +78,8 @@ bool ReplaceOperation::performOperation() QFile file(currentFileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - setError( UserDefinedError ); - setErrorString( QObject::tr( "Failed to open %1 for reading" ).arg( currentFileName ) ); + setError(UserDefinedError); + setErrorString(QObject::tr("Failed to open %1 for reading").arg(currentFileName)); return false; } @@ -88,13 +88,13 @@ bool ReplaceOperation::performOperation() file.close(); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - setError( UserDefinedError ); - setErrorString( QObject::tr( "Failed to open %1 for writing" ).arg( currentFileName ) ); + setError(UserDefinedError); + setErrorString(QObject::tr("Failed to open %1 for writing").arg(currentFileName)); return false; } //TODO: check that toAscii is right(?) - file.write( replacedFileContent.toLocal8Bit() ); + file.write(replacedFileContent.toLocal8Bit()); file.close(); return true; diff --git a/installerbuilder/libinstaller/selfrestartoperation.cpp b/installerbuilder/libinstaller/selfrestartoperation.cpp index caf51c3f0..909d59c9c 100644 --- a/installerbuilder/libinstaller/selfrestartoperation.cpp +++ b/installerbuilder/libinstaller/selfrestartoperation.cpp @@ -39,7 +39,7 @@ using namespace QInstaller; SelfRestartOperation::SelfRestartOperation() { - setName( QLatin1String( "SelfRestart" ) ); + setName(QLatin1String("SelfRestart")); } SelfRestartOperation::~SelfRestartOperation() @@ -48,32 +48,35 @@ SelfRestartOperation::~SelfRestartOperation() void SelfRestartOperation::backup() { - setValue( QLatin1String( "PreviousSelfRestart" ), KDSelfRestarter::restartOnQuit() ); + setValue(QLatin1String("PreviousSelfRestart"), KDSelfRestarter::restartOnQuit()); } bool SelfRestartOperation::performOperation() { - const Installer* const installer = qVariantValue< Installer* >( value( QLatin1String( "installer" ) ) ); - if( !installer->isUpdater() ) - { - setError( UserDefinedError ); - setErrorString ( tr("Self Restart: Only valid within Updater.") ); + const Installer* const installer = qVariantValue<Installer*>(value(QLatin1String("installer"))); + if (!installer) { + setError(UserDefinedError); + setErrorString(tr("Needed installer object in \"%1\" operation is empty.").arg(name())); + return false; + } + if (!installer->isUpdater()) { + setError(UserDefinedError); + setErrorString(tr("Self Restart: Only valid within Updater.")); return false; } - if( !arguments().isEmpty() ) - { - setError( InvalidArguments ); - setErrorString( tr("Self Restart: Invalid arguments") ); + if (!arguments().isEmpty()) { + setError(InvalidArguments); + setErrorString(tr("Self Restart: Invalid arguments")); return false; } - KDSelfRestarter::setRestartOnQuit( true ); + KDSelfRestarter::setRestartOnQuit(true); return KDSelfRestarter::restartOnQuit(); } bool SelfRestartOperation::undoOperation() { - KDSelfRestarter::setRestartOnQuit( value( QLatin1String( "PreviousSelfRestart" ) ).toBool() ); + KDSelfRestarter::setRestartOnQuit(value(QLatin1String("PreviousSelfRestart")).toBool()); return true; } diff --git a/installerbuilder/libinstaller/setdemospathonqtoperation.cpp b/installerbuilder/libinstaller/setdemospathonqtoperation.cpp index 575c5ddad..eaac48a53 100644 --- a/installerbuilder/libinstaller/setdemospathonqtoperation.cpp +++ b/installerbuilder/libinstaller/setdemospathonqtoperation.cpp @@ -58,10 +58,10 @@ bool SetDemosPathOnQtOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 2) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, exact 2 expected.") - .arg(name()).arg( arguments().count() ) ); + if (args.count() != 2) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, exact 2 expected.") + .arg(name()).arg(arguments().count())); return false; } @@ -78,30 +78,30 @@ bool SetDemosPathOnQtOperation::performOperation() if (qmakeValueHash.isEmpty()) { - setError( UserDefinedError ); - setErrorString( tr("The output of \n%1 -query\n" \ - "is not parseable. Please make a bugreport with this dialog http://bugreports.qt.nokia.com.\n" \ - "output: \"%2\"").arg(QDir::toNativeSeparators(qmakePath), QString::fromUtf8(qmakeOutput))); + setError(UserDefinedError); + setErrorString(tr("The output of \n%1 -query\n" \ + "is not parseable. Please make a bugreport with this dialog http://bugreports.qt.nokia.com.\n" \ + "output: \"%2\"").arg(QDir::toNativeSeparators(qmakePath), QString::fromUtf8(qmakeOutput))); return false; } - QByteArray oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_DEMOS") ); + QByteArray oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_DEMOS")); bool oldQtPathFromQMakeIsEmpty = oldValue.isEmpty(); if (oldQtPathFromQMakeIsEmpty) { verbose() << "qpatch: warning: It was not able to get the old values from " << qPrintable(qmakePath) << std::endl; } if (255 < newValue.size()) { - setError( UserDefinedError ); - setErrorString( tr("Qt patch error: new Qt demo path(%1)\n" \ - "needs to be less than 255 characters.").arg(QString::fromLocal8Bit(newValue)) ); + setError(UserDefinedError); + setErrorString(tr("Qt patch error: new Qt demo path(%1)\n" \ + "needs to be less than 255 characters.").arg(QString::fromLocal8Bit(newValue)) ); return false; } QString qtConfPath = qtDir + QLatin1String("/bin/qt.conf"); if (QFile::exists(qtConfPath)) { QSettings settings(qtConfPath, QSettings::IniFormat); - settings.setValue( QLatin1String("Paths/Demos"), QString::fromUtf8(newValue)); + settings.setValue(QLatin1String("Paths/Demos"), QString::fromUtf8(newValue)); } oldValue = QByteArray("qt_demopath=%1").replace("%1", oldValue); @@ -109,7 +109,8 @@ bool SetDemosPathOnQtOperation::performOperation() bool isPatched = QtPatch::patchBinaryFile(qmakePath, oldValue, newValue); if (!isPatched) { - QInstaller::verbose() << "qpatch: warning: could not patched the demo path in " << qPrintable(qmakePath) << std::endl; + QInstaller::verbose() << "qpatch: warning: could not patched the demo path in " + << qPrintable(qmakePath) << std::endl; } return true; diff --git a/installerbuilder/libinstaller/setexamplespathonqtoperation.cpp b/installerbuilder/libinstaller/setexamplespathonqtoperation.cpp index 17b668d38..17cceadeb 100644 --- a/installerbuilder/libinstaller/setexamplespathonqtoperation.cpp +++ b/installerbuilder/libinstaller/setexamplespathonqtoperation.cpp @@ -58,10 +58,10 @@ bool SetExamplesPathOnQtOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 2) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, exact 2 expected.") - .arg(name()).arg( arguments().count() ) ); + if (args.count() != 2) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, exact 2 expected.") + .arg(name()).arg(arguments().count())); return false; } @@ -78,23 +78,24 @@ bool SetExamplesPathOnQtOperation::performOperation() if (qmakeValueHash.isEmpty()) { - setError( UserDefinedError ); - setErrorString( tr("The output of \n%1 -query\n" \ - "is not parseable. Please make a bugreport with this dialog http://bugreports.qt.nokia.com.\n" \ - "output: \"%2\"").arg(QDir::toNativeSeparators(qmakePath), QString::fromUtf8(qmakeOutput))); + setError(UserDefinedError); + setErrorString(tr("The output of \n%1 -query\n" \ + "is not parseable. Please make a bugreport with this dialog http://bugreports.qt.nokia.com.\n" \ + "output: \"%2\"").arg(QDir::toNativeSeparators(qmakePath), QString::fromUtf8(qmakeOutput))); return false; } - QByteArray oldValue = qmakeValueHash.value( QLatin1String("QT_INSTALL_EXAMPLES") ); + QByteArray oldValue = qmakeValueHash.value(QLatin1String("QT_INSTALL_EXAMPLES")); bool oldQtPathFromQMakeIsEmpty = oldValue.isEmpty(); if (oldQtPathFromQMakeIsEmpty) { - verbose() << "qpatch: warning: It was not able to get the old values from " << qPrintable(qmakePath) << std::endl; + verbose() << "qpatch: warning: It was not able to get the old values from " + << qPrintable(qmakePath) << std::endl; } if (255 < newValue.size()) { - setError( UserDefinedError ); - setErrorString( tr("Qt patch error: new Qt example path(%1)\n" \ - "needs to be less than 255 characters.").arg(QString::fromLocal8Bit(newValue)) ); + setError(UserDefinedError); + setErrorString(tr("Qt patch error: new Qt example path(%1)\n" \ + "needs to be less than 255 characters.").arg(QString::fromLocal8Bit(newValue))); return false; } diff --git a/installerbuilder/libinstaller/setimportspathonqtcoreoperation.cpp b/installerbuilder/libinstaller/setimportspathonqtcoreoperation.cpp index 0f3d237ce..9d8f9c505 100644 --- a/installerbuilder/libinstaller/setimportspathonqtcoreoperation.cpp +++ b/installerbuilder/libinstaller/setimportspathonqtcoreoperation.cpp @@ -100,10 +100,10 @@ bool SetImportsPathOnQtCoreOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 2) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, exact 2 expected.") - .arg(name()).arg( arguments().count() ) ); + if (args.count() != 2) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, exact 2 expected.") + .arg(name()).arg( arguments().count())); return false; } @@ -116,13 +116,13 @@ bool SetImportsPathOnQtCoreOperation::performOperation() } QStringList libraryFiles; #ifdef Q_OS_WIN - libraryFiles << QString( QLatin1String("%1/QtCore4.dll") ).arg(qtCoreLibraryDir); - libraryFiles << QString( QLatin1String("%1/QtCore4d.dll") ).arg(qtCoreLibraryDir); + libraryFiles << QString(QLatin1String("%1/QtCore4.dll")).arg(qtCoreLibraryDir); + libraryFiles << QString(QLatin1String("%1/QtCore4d.dll")).arg(qtCoreLibraryDir); #else libraryFiles << qtCoreLibraryDir + QLatin1String("/libQtCore.so"); #endif - foreach(const QString coreLibrary, libraryFiles) { - if( QFile::exists(coreLibrary) ) { + foreach (const QString coreLibrary, libraryFiles) { + if (QFile::exists(coreLibrary)) { QByteArray oldValue(getOldValue(coreLibrary)); Q_ASSERT(!oldValue.isEmpty()); oldValue = QByteArray("qt_impspath=%1").replace("%1", oldValue); diff --git a/installerbuilder/libinstaller/setpluginpathonqtcoreoperation.cpp b/installerbuilder/libinstaller/setpluginpathonqtcoreoperation.cpp index d531d37f7..9acc64b75 100644 --- a/installerbuilder/libinstaller/setpluginpathonqtcoreoperation.cpp +++ b/installerbuilder/libinstaller/setpluginpathonqtcoreoperation.cpp @@ -46,7 +46,7 @@ QByteArray getOldValue(const QString & binaryPath) { QFileInfo fileInfo(binaryPath); - if ( !fileInfo.exists() ) { + if (!fileInfo.exists()) { verbose() << "qpatch: warning: file `" << qPrintable(binaryPath) << "' not found" << std::endl; return QByteArray(); } @@ -54,12 +54,12 @@ QByteArray getOldValue(const QString & binaryPath) QFile file(binaryPath); int readOpenCount = 0; - while (! file.open(QFile::ReadOnly) && readOpenCount < 20000) { + while (!file.open(QFile::ReadOnly) && readOpenCount < 20000) { ++readOpenCount; qApp->processEvents(); } Q_ASSERT(file.isOpen()); - if (! file.isOpen()) { + if (!file.isOpen()) { verbose() << "qpatch: warning: file `" << qPrintable(binaryPath) << "' can not open as ReadOnly." << std::endl; verbose() << file.errorString() << std::endl; return QByteArray(); @@ -100,10 +100,10 @@ bool SetPluginPathOnQtCoreOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 2) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, exact 2 expected.") - .arg(name()).arg( arguments().count() ) ); + if (args.count() != 2) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, exact 2 expected.") + .arg(name()).arg( arguments().count())); return false; } @@ -116,13 +116,13 @@ bool SetPluginPathOnQtCoreOperation::performOperation() } QStringList libraryFiles; #ifdef Q_OS_WIN - libraryFiles << QString( QLatin1String("%1/QtCore4.dll") ).arg(qtCoreLibraryDir); - libraryFiles << QString( QLatin1String("%1/QtCore4d.dll") ).arg(qtCoreLibraryDir); + libraryFiles << QString(QLatin1String("%1/QtCore4.dll")).arg(qtCoreLibraryDir); + libraryFiles << QString(QLatin1String("%1/QtCore4d.dll")).arg(qtCoreLibraryDir); #else libraryFiles << qtCoreLibraryDir + QLatin1String("/libQtCore.so"); #endif - foreach(const QString coreLibrary, libraryFiles) { - if( QFile::exists(coreLibrary) ) { + foreach (const QString coreLibrary, libraryFiles) { + if (QFile::exists(coreLibrary) ) { QByteArray oldValue(getOldValue(coreLibrary)); Q_ASSERT(!oldValue.isEmpty()); oldValue = QByteArray("qt_plugpath=%1").replace("%1", oldValue); diff --git a/installerbuilder/libinstaller/setqtcreatorvalueoperation.cpp b/installerbuilder/libinstaller/setqtcreatorvalueoperation.cpp index 0eee398d7..43308fe0b 100644 --- a/installerbuilder/libinstaller/setqtcreatorvalueoperation.cpp +++ b/installerbuilder/libinstaller/setqtcreatorvalueoperation.cpp @@ -64,7 +64,7 @@ void SetQtCreatorValueOperation::backup() namespace { QString groupName(const QString & groupName) { - if(groupName == QLatin1String("General")) { + if (groupName == QLatin1String("General")) { return QString(); } else { return groupName; @@ -76,10 +76,10 @@ bool SetQtCreatorValueOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 4) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, exact 4 expected(rootInstallPath,group,key,value).") - .arg(name()).arg( arguments().count() ) ); + if (args.count() != 4) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, exact 4 expected(rootInstallPath,group,key,value).") + .arg(name()).arg( arguments().count())); return false; } @@ -92,13 +92,13 @@ bool SetQtCreatorValueOperation::performOperation() QSettings settings(rootInstallPath + QLatin1String(QtCreatorSettingsSuffixPath), QSettings::IniFormat); - if(!group.isEmpty()) { + if (!group.isEmpty()) { settings.beginGroup(group); } settings.setValue(key, value); - if(!group.isEmpty()) { + if (!group.isEmpty()) { settings.endGroup(); } diff --git a/installerbuilder/libinstaller/simplemovefileoperation.cpp b/installerbuilder/libinstaller/simplemovefileoperation.cpp index 5abea0437..201746803 100644 --- a/installerbuilder/libinstaller/simplemovefileoperation.cpp +++ b/installerbuilder/libinstaller/simplemovefileoperation.cpp @@ -46,7 +46,7 @@ TRANSLATOR QInstaller::SimpleMoveFileOperation SimpleMoveFileOperation::SimpleMoveFileOperation() { - setName( QLatin1String( "SimpleMoveFile" ) ); + setName(QLatin1String("SimpleMoveFile")); } SimpleMoveFileOperation::~SimpleMoveFileOperation() @@ -60,44 +60,44 @@ void SimpleMoveFileOperation::backup() bool SimpleMoveFileOperation::performOperation() { const QStringList args = arguments(); - if( args.count() != 2 ) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 2 expected.") - .arg(name()).arg( args.count() ) ); + if (args.count() != 2) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2 expected.") + .arg(name()).arg(args.count())); return false; } - const QString source = args.at( 0 ); - const QString target = args.at( 1 ); + const QString source = args.at(0); + const QString target = args.at(1); - if (source.isEmpty() || target.isEmpty() ) { - setError( UserDefinedError ); - setErrorString( tr("None of the arguments can be empty: source(\"%1\"), target(\"%2\")") - .arg(source, target) ); + if (source.isEmpty() || target.isEmpty()) { + setError(UserDefinedError); + setErrorString(tr("None of the arguments can be empty: source(\"%1\"), target(\"%2\")") + .arg(source, target)); return false; } // If destination file exists, then we cannot use QFile::copy() // because it does not overwrite an existing file. So we remove // the destination file. - if( QFile::exists( target ) ) + if (QFile::exists(target)) { - QFile file( target ); - if( !file.remove() ) { - setError( UserDefinedError ); - setErrorString( tr("can not copy source(\"%1\") to target(\"%2\"), because target is existing and not removable.") - .arg(source, target) ); + QFile file(target); + if (!file.remove()) { + setError(UserDefinedError); + setErrorString(tr("can not copy source(\"%1\") to target(\"%2\"), because target is existing and not removable.") + .arg(source, target)); return false; } } - QFile file( source ); - const bool moved = file.rename( target ); - if ( !moved ) { - setError( UserDefinedError ); - setErrorString( tr("can not move source(\"%1\") to target(\"%2\"), %3") - .arg(source, target, file.errorString()) ); + QFile file(source); + const bool moved = file.rename(target); + if (!moved) { + setError(UserDefinedError); + setErrorString(tr("can not move source(\"%1\") to target(\"%2\"), %3") + .arg(source, target, file.errorString())); return false; } return true; @@ -105,10 +105,10 @@ bool SimpleMoveFileOperation::performOperation() bool SimpleMoveFileOperation::undoOperation() { - const QString source = arguments().at( 0 ); - const QString target = arguments().at( 1 ); - QFile file( target ); - file.rename( source ); + const QString source = arguments().at(0); + const QString target = arguments().at(1); + QFile file(target); + file.rename(source); return true; } |