/****************************************************************************
**
** Copyright (C) 2012 - 2014 Jolla Ltd.
** Contact: http://jolla.com/
**
** This file is part of Qt Creator.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Digia.
**
****************************************************************************/

#ifndef NXTSDKMANAGER_H
#define NXTSDKMANAGER_H

#include <qtc/nxtsdk.h>

#include <ssh/sshconnection.h>
#include <utils/environment.h>

#include <QObject>

QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE

namespace Utils {
class PersistentSettingsWriter;
class FileName;
}

namespace ProjectExplorer {
class Kit;
class Project;
}

namespace Nxt {
namespace Internal {

class NxtSdkManager : public QObject
{
    Q_OBJECT
public:
    static NxtSdkManager *instance();
    static QString sdkToolsDirectory();
    static QString globalSdkToolsDirectory();
    static bool authorizePublicKey(const QString &authorizedKeysPath, const QString &publicKeyPath, QString &error);
    static bool isNxtKit(const ProjectExplorer::Kit *kit);
    static QString targetNameForKit(const ProjectExplorer::Kit *kit);
    static QList<ProjectExplorer::Kit *> kitsForTarget(const QString &targetName);
    static bool hasNxtDevice(ProjectExplorer::Kit *kit);
    static bool validateKit(const ProjectExplorer::Kit* kit);
    static bool generateSshKey(const QString &privKeyPath, QString &error);

    ~NxtSdkManager() override;
    static QList<NxtSdk*> sdks();
    static NxtSdk* sdk(const QString &virtualMachineName);
    static NxtSdk* createSdk(const QString &vmName);
    static void addSdk(NxtSdk *sdk);
    static void removeSdk(NxtSdk *sdk);
    static void restoreSdks();
    static bool hasSdk(const NxtSdk *sdk);

    static QList<ProjectExplorer::Kit*> nxtKits();

public slots:
    void storeSdks();

signals:
    void sdksUpdated();
    void initialized();

private slots:
    void initialize();
    void updateDevices();

private:
    NxtSdkManager();
    void restore();
    QList<NxtSdk*> restoreSdks(const Utils::FileName &fileName);
    static QList<NxtToolChain*> nxtToolChains();
    static QList<NxtQtVersion*> nxtQtVersions();
    Utils::FileName checkLocalConfig(const Utils::FileName &l, const Utils::FileName &g);
private:
    static NxtSdkManager *m_instance;
    QMap<QString, NxtSdk*> m_sdks;
    bool m_intialized;
    Utils::PersistentSettingsWriter *m_writer;
    QString m_installDir;
    int m_version;
    friend class NxtPlugin;
};

} // namespace Internal
} // namespace Nxt

#endif // NXTSDKMANAGER_H
