<commit_before>/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#include "qt4maemodeployconfiguration.h"

#include "debianmanager.h"
#include "maddeuploadandinstallpackagesteps.h"
#include "maemoconstants.h"
#include "maemodeploybymountsteps.h"
#include "maemodeployconfigurationwidget.h"
#include "maemoglobal.h"
#include "maemoinstalltosysrootstep.h"
#include "maemopackagecreationstep.h"

#include <coreplugin/icore.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/target.h>
#include <projectexplorer/projectexplorer.h>
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <qt4projectmanager/qt4project.h>
#include <qtsupport/qtprofileinformation.h>
#include <qtsupport/qtsupportconstants.h>
#include <remotelinux/deployablefile.h>
#include <remotelinux/deployablefilesperprofile.h>
#include <remotelinux/deploymentinfo.h>
#include <remotelinux/remotelinuxcheckforfreediskspacestep.h>
#include <utils/qtcassert.h>

#include <QFileInfo>
#include <QString>

#include <QMainWindow>
#include <QMessageBox>

using namespace ProjectExplorer;
using namespace Qt4ProjectManager;
using namespace RemoteLinux;

const char OldDeployConfigId[] = "2.2MaemoDeployConfig";
const char DEPLOYMENT_ASSISTANT_SETTING[] = "RemoteLinux.DeploymentAssistant";

namespace Madde {
namespace Internal {

Qt4MaemoDeployConfiguration::Qt4MaemoDeployConfiguration(ProjectExplorer::Target *target,
        const Core::Id id, const QString &displayName)
    : RemoteLinuxDeployConfiguration(target, id, displayName)
{ init(); }

Qt4MaemoDeployConfiguration::Qt4MaemoDeployConfiguration(ProjectExplorer::Target *target,
        Qt4MaemoDeployConfiguration *source)
    : RemoteLinuxDeployConfiguration(target, source)
{ init(); }

QString Qt4MaemoDeployConfiguration::localDesktopFilePath(const DeployableFilesPerProFile *proFileInfo) const
{
    QTC_ASSERT(proFileInfo->projectType() == ApplicationTemplate, return QString());

    for (int i = 0; i < proFileInfo->rowCount(); ++i) {
        const DeployableFile &d = proFileInfo->deployableAt(i);
        if (QFileInfo(d.localFilePath).fileName().endsWith(QLatin1String(".desktop")))
            return d.localFilePath;
    }
    return QString();
}


DeployConfigurationWidget *Qt4MaemoDeployConfiguration::configurationWidget() const
{
    return new MaemoDeployConfigurationWidget;
}

Qt4MaemoDeployConfiguration::~Qt4MaemoDeployConfiguration() {}

Core::Id Qt4MaemoDeployConfiguration::fremantleWithPackagingId()
{
    return Core::Id("DeployToFremantleWithPackaging");
}

Core::Id Qt4MaemoDeployConfiguration::fremantleWithoutPackagingId()
{
    return Core::Id("DeployToFremantleWithoutPackaging");
}

Core::Id Qt4MaemoDeployConfiguration::harmattanId()
{
    return Core::Id("DeployToHarmattan");
}

DeploymentSettingsAssistant *Qt4MaemoDeployConfiguration::deploymentSettingsAssistant()
{
    return static_cast<DeploymentSettingsAssistant *>(target()->project()->namedSettings(QLatin1String(DEPLOYMENT_ASSISTANT_SETTING)).value<QObject *>());
}

QString Qt4MaemoDeployConfiguration::qmakeScope() const
{
    Core::Id deviceType = ProjectExplorer::DeviceTypeProfileInformation::deviceTypeId(target()->profile());

    if (deviceType == Maemo5OsType)
        return QLatin1String("maemo5");
    if (deviceType == HarmattanOsType)
        return QLatin1String("contains(MEEGO_EDITION,harmattan)");
    return QString("unix");
}

QString Qt4MaemoDeployConfiguration::installPrefix() const
{
    Core::Id deviceType = ProjectExplorer::DeviceTypeProfileInformation::deviceTypeId(target()->profile());

    if (deviceType == Maemo5OsType)
        return QLatin1String("/opt");
    if (deviceType == HarmattanOsType)
        return QLatin1String("/opt");
    return QLatin1String("/usr/local");
}

void Qt4MaemoDeployConfiguration::debianDirChanged(const Utils::FileName &dir)
{
    if (dir == DebianManager::debianDirectory(target()))
        emit packagingChanged();
}

void Qt4MaemoDeployConfiguration::setupPackaging()
{
    if (target()->project()->activeTarget() != target())
        return;

    disconnect(target()->project(), SIGNAL(fileListChanged()), this, SLOT(setupPackaging()));
    setupDebianPackaging();
}

void Qt4MaemoDeployConfiguration::setupDebianPackaging()
{
    Qt4BuildConfiguration *bc = qobject_cast<Qt4BuildConfiguration *>(target()->activeBuildConfiguration());
    if (!bc || !target()->profile())
        return;

    Utils::FileName debianDir = DebianManager::debianDirectory(target());
    Core::Id deviceType = ProjectExplorer::DeviceTypeProfileInformation::deviceTypeId(target()->profile());
    DebianManager *dm = DebianManager::instance();
    QString projectName = target()->project()->displayName();

    DebianManager::ActionStatus status = DebianManager::createTemplate(bc, debianDir);

    if (status == DebianManager::NoActionRequired ||
            status == DebianManager::ActionFailed)
        return;

    if (!DebianManager::hasPackageManagerIcon(debianDir)) {
        // Such a file is created by the mobile wizards.
        Utils::FileName iconPath = Utils::FileName::fromString(target()->project()->projectDirectory());
        iconPath.appendPath(projectName + QLatin1String("64.png"));
        if (iconPath.toFileInfo().exists())
            dm->setPackageManagerIcon(debianDir, deviceType, iconPath);
    }


<commit_msg>Madde: Only get values once they are needed<commit_after>/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#include "qt4maemodeployconfiguration.h"

#include "debianmanager.h"
#include "maddeuploadandinstallpackagesteps.h"
#include "maemoconstants.h"
#include "maemodeploybymountsteps.h"
#include "maemodeployconfigurationwidget.h"
#include "maemoglobal.h"
#include "maemoinstalltosysrootstep.h"
#include "maemopackagecreationstep.h"

#include <coreplugin/icore.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/target.h>
#include <projectexplorer/projectexplorer.h>
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <qt4projectmanager/qt4project.h>
#include <qtsupport/qtprofileinformation.h>
#include <qtsupport/qtsupportconstants.h>
#include <remotelinux/deployablefile.h>
#include <remotelinux/deployablefilesperprofile.h>
#include <remotelinux/deploymentinfo.h>
#include <remotelinux/remotelinuxcheckforfreediskspacestep.h>
#include <utils/qtcassert.h>

#include <QFileInfo>
#include <QString>

#include <QMainWindow>
#include <QMessageBox>

using namespace ProjectExplorer;
using namespace Qt4ProjectManager;
using namespace RemoteLinux;

const char OldDeployConfigId[] = "2.2MaemoDeployConfig";
const char DEPLOYMENT_ASSISTANT_SETTING[] = "RemoteLinux.DeploymentAssistant";

namespace Madde {
namespace Internal {

Qt4MaemoDeployConfiguration::Qt4MaemoDeployConfiguration(ProjectExplorer::Target *target,
        const Core::Id id, const QString &displayName)
    : RemoteLinuxDeployConfiguration(target, id, displayName)
{ init(); }

Qt4MaemoDeployConfiguration::Qt4MaemoDeployConfiguration(ProjectExplorer::Target *target,
        Qt4MaemoDeployConfiguration *source)
    : RemoteLinuxDeployConfiguration(target, source)
{ init(); }

QString Qt4MaemoDeployConfiguration::localDesktopFilePath(const DeployableFilesPerProFile *proFileInfo) const
{
    QTC_ASSERT(proFileInfo->projectType() == ApplicationTemplate, return QString());

    for (int i = 0; i < proFileInfo->rowCount(); ++i) {
        const DeployableFile &d = proFileInfo->deployableAt(i);
        if (QFileInfo(d.localFilePath).fileName().endsWith(QLatin1String(".desktop")))
            return d.localFilePath;
    }
    return QString();
}


DeployConfigurationWidget *Qt4MaemoDeployConfiguration::configurationWidget() const
{
    return new MaemoDeployConfigurationWidget;
}

Qt4MaemoDeployConfiguration::~Qt4MaemoDeployConfiguration() {}

Core::Id Qt4MaemoDeployConfiguration::fremantleWithPackagingId()
{
    return Core::Id("DeployToFremantleWithPackaging");
}

Core::Id Qt4MaemoDeployConfiguration::fremantleWithoutPackagingId()
{
    return Core::Id("DeployToFremantleWithoutPackaging");
}

Core::Id Qt4MaemoDeployConfiguration::harmattanId()
{
    return Core::Id("DeployToHarmattan");
}

DeploymentSettingsAssistant *Qt4MaemoDeployConfiguration::deploymentSettingsAssistant()
{
    return static_cast<DeploymentSettingsAssistant *>(target()->project()->namedSettings(QLatin1String(DEPLOYMENT_ASSISTANT_SETTING)).value<QObject *>());
}

QString Qt4MaemoDeployConfiguration::qmakeScope() const
{
    Core::Id deviceType = ProjectExplorer::DeviceTypeProfileInformation::deviceTypeId(target()->profile());

    if (deviceType == Maemo5OsType)
        return QLatin1String("maemo5");
    if (deviceType == HarmattanOsType)
        return QLatin1String("contains(MEEGO_EDITION,harmattan)");
    return QString("unix");
}

QString Qt4MaemoDeployConfiguration::installPrefix() const
{
    Core::Id deviceType = ProjectExplorer::DeviceTypeProfileInformation::deviceTypeId(target()->profile());

    if (deviceType == Maemo5OsType)
        return QLatin1String("/opt");
    if (deviceType == HarmattanOsType)
        return QLatin1String("/opt");
    return QLatin1String("/usr/local");
}

void Qt4MaemoDeployConfiguration::debianDirChanged(const Utils::FileName &dir)
{
    if (dir == DebianManager::debianDirectory(target()))
        emit packagingChanged();
}

void Qt4MaemoDeployConfiguration::setupPackaging()
{
    if (target()->project()->activeTarget() != target())
        return;

    disconnect(target()->project(), SIGNAL(fileListChanged()), this, SLOT(setupPackaging()));
    setupDebianPackaging();
}

void Qt4MaemoDeployConfiguration::setupDebianPackaging()
{
    Qt4BuildConfiguration *bc = qobject_cast<Qt4BuildConfiguration *>(target()->activeBuildConfiguration());
    if (!bc || !target()->profile())
        return;

    Utils::FileName debianDir = DebianManager::debianDirectory(target());
    DebianManager::ActionStatus status = DebianManager::createTemplate(bc, debianDir);

    if (status == DebianManager::NoActionRequired ||
            status == DebianManager::ActionFailed)
        return;

    Core::Id deviceType = ProjectExplorer::DeviceTypeProfileInformation::deviceTypeId(target()->profile());
    DebianManager *dm = DebianManager::instance();
    QString projectName = target()->project()->displayName();

    if (!DebianManager::hasPackageManagerIcon(debianDir)) {
        // Such a file is created by the mobile wizards.
        Utils::FileName iconPath = Utils::FileName::fromString(target()->project()->projectDirectory());
        iconPath.appendPath(projectName + QLatin1String("64.png"));
        if (iconPath.toFileInfo().exists())
            dm->setPackageManagerIcon(debianDir, deviceType, iconPath);
    }



{'fraction_non_alphanumeric': 0.13831761249420133, 'fraction_numerical': 0.008350085047162517, 'mean_word_length': 6.0683060109289615, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1556116', 'n_tokens_mistral': 3862, 'n_tokens_neox': 3664, 'n_words': 785}