OSDN Git Service

RemoteLinux: Remote environment refactoring.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / remotelinux / maemoglobal.cpp
index 9eb1676..d65349b 100644 (file)
 #include "maemoconstants.h"
 #include "maemoqemumanager.h"
 
-#include <projectexplorer/projectexplorerconstants.h>
-
-#include <coreplugin/filemanager.h>
-#include <utils/ssh/sshconnection.h>
 #include <qt4projectmanager/qt4projectmanagerconstants.h>
-#include <qtsupport/qtversionmanager.h>
-#include <qt4projectmanager/qt4target.h>
+#include <qtsupport/baseqtversion.h>
+#include <remotelinux/linuxdeviceconfiguration.h>
+#include <remotelinux/remotelinux_constants.h>
 #include <utils/environment.h>
 
-#include <QtCore/QDateTime>
 #include <QtCore/QDir>
 #include <QtCore/QFileInfo>
 #include <QtCore/QProcess>
@@ -82,40 +78,17 @@ bool MaemoGlobal::isMeegoTargetId(const QString &id)
 
 bool MaemoGlobal::isValidMaemo5QtVersion(const QString &qmakePath)
 {
-    return isValidMaemoQtVersion(qmakePath, LinuxDeviceConfiguration::Maemo5OsType);
+    return isValidMaemoQtVersion(qmakePath, QLatin1String(Maemo5OsType));
 }
 
 bool MaemoGlobal::isValidHarmattanQtVersion(const QString &qmakePath)
 {
-    return isValidMaemoQtVersion(qmakePath, LinuxDeviceConfiguration::HarmattanOsType);
+    return isValidMaemoQtVersion(qmakePath, QLatin1String(HarmattanOsType));
 }
 
 bool MaemoGlobal::isValidMeegoQtVersion(const QString &qmakePath)
 {
-    return isValidMaemoQtVersion(qmakePath, LinuxDeviceConfiguration::MeeGoOsType);
-}
-
-bool MaemoGlobal::isLinuxQt(const QtSupport::BaseQtVersion *qtVersion)
-{
-    if (!qtVersion)
-        return false;
-    const QList<ProjectExplorer::Abi> &abis = qtVersion->qtAbis();
-    foreach (const ProjectExplorer::Abi &abi, abis) {
-        if (abi.os() == ProjectExplorer::Abi::LinuxOS)
-            return true;
-    }
-    return false;
-}
-
-bool MaemoGlobal::hasLinuxQt(const ProjectExplorer::Target *target)
-{
-    const Qt4BaseTarget * const qtTarget
-        = qobject_cast<const Qt4BaseTarget *>(target);
-    if (!qtTarget)
-        return false;
-    const Qt4BuildConfiguration * const bc
-        = qtTarget->activeBuildConfiguration();
-    return bc && isLinuxQt(bc->qtVersion());
+    return isValidMaemoQtVersion(qmakePath, QLatin1String(MeeGoOsType));
 }
 
 bool MaemoGlobal::isValidMaemoQtVersion(const QString &qmakePath, const QString &osType)
@@ -155,33 +128,20 @@ QString MaemoGlobal::devrootshPath()
 
 int MaemoGlobal::applicationIconSize(const QString &osType)
 {
-    return osType == LinuxDeviceConfiguration::HarmattanOsType ? 80 : 64;
+    return osType == QLatin1String(HarmattanOsType) ? 80 : 64;
 }
 
 QString MaemoGlobal::remoteSudo(const QString &osType, const QString &uname)
 {
     if (uname == QLatin1String("root"))
         return QString();
-    if (osType == LinuxDeviceConfiguration::Maemo5OsType
-            || osType == LinuxDeviceConfiguration::HarmattanOsType
-            || osType == LinuxDeviceConfiguration::MeeGoOsType) {
+    if (osType == QLatin1String(Maemo5OsType) || osType == QLatin1String(HarmattanOsType)
+            || osType == QLatin1String(MeeGoOsType)) {
         return devrootshPath();
     }
     return QString(); // Using sudo would open a can of worms.
 }
 
-QString MaemoGlobal::remoteCommandPrefix(const QString &osType, const QString &userName,
-    const QString &commandFilePath)
-{
-    QString prefix = QString::fromLocal8Bit("%1 chmod a+x %2; %3; ")
-        .arg(remoteSudo(osType, userName), commandFilePath, remoteSourceProfilesCommand());
-    if (osType != LinuxDeviceConfiguration::Maemo5OsType
-            && osType != LinuxDeviceConfiguration::HarmattanOsType) {
-        prefix += QLatin1String("DISPLAY=:0.0 ");
-    }
-    return prefix;
-}
-
 QString MaemoGlobal::remoteSourceProfilesCommand()
 {
     const QList<QByteArray> profiles = QList<QByteArray>() << "/etc/profile"
@@ -192,37 +152,6 @@ QString MaemoGlobal::remoteSourceProfilesCommand()
     return QString::fromAscii(remoteCall);
 }
 
-QString MaemoGlobal::remoteEnvironment(const QList<Utils::EnvironmentItem> &list)
-{
-    QString env;
-    QString placeHolder = QLatin1String("%1=%2 ");
-    foreach (const Utils::EnvironmentItem &item, list)
-        env.append(placeHolder.arg(item.name).arg(item.value));
-    return env.mid(0, env.size() - 1);
-}
-
-QString MaemoGlobal::failedToConnectToServerMessage(const Utils::SshConnection::Ptr &connection,
-    const LinuxDeviceConfiguration::ConstPtr &deviceConfig)
-{
-    QString errorMsg = tr("Could not connect to host: %1")
-        .arg(connection->errorString());
-
-    if (deviceConfig->type() == LinuxDeviceConfiguration::Emulator) {
-        if (connection->errorState() == Utils::SshTimeoutError
-                || connection->errorState() == Utils::SshSocketError) {
-            errorMsg += tr("\nDid you start Qemu?");
-        }
-   } else if (connection->errorState() == Utils::SshTimeoutError) {
-        errorMsg += tr("\nIs the device connected and set up for network access?");
-    }
-    return errorMsg;
-}
-
-QString MaemoGlobal::deviceConfigurationName(const LinuxDeviceConfiguration::ConstPtr &devConf)
-{
-    return devConf ? devConf->name() : tr("(No device)");
-}
-
 PortList MaemoGlobal::freePorts(const LinuxDeviceConfiguration::ConstPtr &devConf,
     const QtSupport::BaseQtVersion *qtVersion)
 {
@@ -266,7 +195,7 @@ QString MaemoGlobal::madCommand(const QString &qmakePath)
 
 QString MaemoGlobal::madDeveloperUiName(const QString &osType)
 {
-    return osType == LinuxDeviceConfiguration::HarmattanOsType
+    return osType == QLatin1String(HarmattanOsType)
         ? tr("SDK Connectivity") : tr("Mad Developer");
 }
 
@@ -274,12 +203,12 @@ QString MaemoGlobal::osType(const QString &qmakePath)
 {
     const QString &name = targetName(qmakePath);
     if (name.startsWith(QLatin1String("fremantle")))
-        return LinuxDeviceConfiguration::Maemo5OsType;
+        return QLatin1String(Maemo5OsType);
     if (name.startsWith(QLatin1String("harmattan")))
-        return LinuxDeviceConfiguration::HarmattanOsType;
+        return QLatin1String(HarmattanOsType);
     if (name.startsWith(QLatin1String("meego")))
-        return LinuxDeviceConfiguration::MeeGoOsType;
-    return LinuxDeviceConfiguration::GenericLinuxOsType;
+        return QLatin1String(MeeGoOsType);
+    return QLatin1String(Constants::GenericLinuxOsType);
 }
 
 QString MaemoGlobal::architecture(const QString &qmakePath)
@@ -296,91 +225,32 @@ QString MaemoGlobal::architecture(const QString &qmakePath)
     return arch;
 }
 
-bool MaemoGlobal::removeRecursively(const QString &filePath, QString &error)
+void MaemoGlobal::addMaddeEnvironment(Utils::Environment &env, const QString &qmakePath)
 {
-    error.clear();
-    QFileInfo fileInfo(filePath);
-    if (!fileInfo.exists())
-        return true;
-    QFile::setPermissions(filePath, fileInfo.permissions() | QFile::WriteUser);
-    if (fileInfo.isDir()) {
-        QDir dir(filePath);
-        QStringList fileNames = dir.entryList(QDir::Files | QDir::Hidden
-            | QDir::System | QDir::Dirs | QDir::NoDotAndDotDot);
-        foreach (const QString &fileName, fileNames) {
-            if (!removeRecursively(filePath + QLatin1Char('/') + fileName, error))
-                return false;
-        }
-        dir.cdUp();
-        if (!dir.rmdir(fileInfo.fileName())) {
-            error = tr("Failed to remove directory '%1'.")
-                .arg(QDir::toNativeSeparators(filePath));
-            return false;
-        }
-    } else {
-        if (!QFile::remove(filePath)) {
-            error = tr("Failed to remove file '%1'.")
-                .arg(QDir::toNativeSeparators(filePath));
-            return false;
-        }
-    }
-    return true;
-}
-
-bool MaemoGlobal::copyRecursively(const QString &srcFilePath,
-    const QString &tgtFilePath, QString *error)
-{
-    QFileInfo srcFileInfo(srcFilePath);
-    if (srcFileInfo.isDir()) {
-        QDir targetDir(tgtFilePath);
-        targetDir.cdUp();
-        if (!targetDir.mkdir(QFileInfo(tgtFilePath).fileName())) {
-            if (error) {
-                *error = tr("Failed to create directory '%1'.")
-                    .arg(QDir::toNativeSeparators(tgtFilePath));
-                return false;
-            }
-        }
-        QDir sourceDir(srcFilePath);
-        QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
-        foreach (const QString &fileName, fileNames) {
-            const QString newSrcFilePath
-                = srcFilePath + QLatin1Char('/') + fileName;
-            const QString newTgtFilePath
-                = tgtFilePath + QLatin1Char('/') + fileName;
-            if (!copyRecursively(newSrcFilePath, newTgtFilePath))
-                return false;
-        }
-    } else {
-        if (!QFile::copy(srcFilePath, tgtFilePath)) {
-            if (error) {
-                *error = tr("Could not copy file '%1' to '%2'.")
-                    .arg(QDir::toNativeSeparators(srcFilePath),
-                         QDir::toNativeSeparators(tgtFilePath));
-            }
-            return false;
-        }
-    }
-    return true;
+    Utils::Environment maddeEnv;
+#ifdef Q_OS_WIN
+    const QString root = maddeRoot(qmakePath);
+    env.prependOrSetPath(root + QLatin1String("/bin"));
+    env.prependOrSet(QLatin1String("HOME"),
+        QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
+#else
+    Q_UNUSED(qmakePath);
+#endif
+    for (Utils::Environment::const_iterator it = maddeEnv.constBegin(); it != maddeEnv.constEnd(); ++it)
+        env.prependOrSet(it.key(), it.value());
 }
 
-bool MaemoGlobal::isFileNewerThan(const QString &filePath,
-    const QDateTime &timeStamp)
+void MaemoGlobal::transformMaddeCall(QString &command, QStringList &args, const QString &qmakePath)
 {
-    QFileInfo fileInfo(filePath);
-    if (!fileInfo.exists() || fileInfo.lastModified() >= timeStamp)
-        return true;
-    if (fileInfo.isDir()) {
-        const QStringList dirContents = QDir(filePath)
-            .entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
-        foreach (const QString &curFileName, dirContents) {
-            const QString curFilePath
-                = filePath + QLatin1Char('/') + curFileName;
-            if (isFileNewerThan(curFilePath, timeStamp))
-                return true;
-        }
-    }
-    return false;
+#ifdef Q_OS_WIN
+    const QString root = maddeRoot(qmakePath);
+    args.prepend(command);
+    command = root + QLatin1String("/bin/sh.exe");
+#else
+    Q_UNUSED(command);
+    Q_UNUSED(args);
+    Q_UNUSED(qmakePath);
+#endif
 }
 
 bool MaemoGlobal::callMad(QProcess &proc, const QStringList &args,
@@ -405,16 +275,10 @@ bool MaemoGlobal::callMaddeShellScript(QProcess &proc,
         return false;
     QString actualCommand = command;
     QStringList actualArgs = targetArgs(qmakePath, useTarget) + args;
-#ifdef Q_OS_WIN
     Utils::Environment env(proc.systemEnvironment());
-    const QString root = maddeRoot(qmakePath);
-    env.prependOrSetPath(root + QLatin1String("/bin"));
-    env.prependOrSet(QLatin1String("HOME"),
-        QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
+    addMaddeEnvironment(env, qmakePath);
     proc.setEnvironment(env.toStringList());
-    actualArgs.prepend(command);
-    actualCommand = root + QLatin1String("/bin/sh.exe");
-#endif
+    transformMaddeCall(actualCommand, actualArgs, qmakePath);
     proc.start(actualCommand, actualArgs);
     return true;
 }
@@ -428,27 +292,5 @@ QStringList MaemoGlobal::targetArgs(const QString &qmakePath, bool useTarget)
     return args;
 }
 
-QString MaemoGlobal::osTypeToString(const QString &osType)
-{
-    if (osType == LinuxDeviceConfiguration::Maemo5OsType)
-        return QLatin1String("Maemo5/Fremantle");
-    if (osType == LinuxDeviceConfiguration::HarmattanOsType)
-        return QLatin1String("Harmattan");
-    if (osType == LinuxDeviceConfiguration::MeeGoOsType)
-        return QLatin1String("MeeGo");
-    return QLatin1String("Other Linux");
-}
-
-MaemoGlobal::PackagingSystem MaemoGlobal::packagingSystem(const QString &osType)
-{
-    if (osType == LinuxDeviceConfiguration::Maemo5OsType
-           || osType == LinuxDeviceConfiguration::HarmattanOsType) {
-        return Dpkg;
-    }
-    if (osType == LinuxDeviceConfiguration::MeeGoOsType)
-        return Rpm;
-    return Tar;
-}
-
 } // namespace Internal
 } // namespace RemoteLinux