devicemanager.h 3.65 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30
#ifndef DEVICEMANAGER_H
#define DEVICEMANAGER_H
31

32
#include "idevice.h"
33

34
#include <projectexplorer/projectexplorer_export.h>
35
#include <utils/fileutils.h>
Tobias Hunger's avatar
Tobias Hunger committed
36
37

#include <utils/fileutils.h>
38

39
#include <QObject>
40

41
namespace ProjectExplorer {
42
class IDevice;
43
class IDeviceFactory;
44

45
46
class ProjectExplorerPlugin;

47
namespace Internal {
48
49
class DeviceManagerPrivate;
class DeviceSettingsWidget;
50
} // namespace Internal
51

52
class PROJECTEXPLORER_EXPORT DeviceManager : public QObject
53
54
{
    Q_OBJECT
55
    friend class Internal::DeviceSettingsWidget;
56
    friend class IDevice;
57

58
public:
59
    ~DeviceManager();
60

61
    static DeviceManager *instance();
62

63
    int deviceCount() const;
64
    IDevice::ConstPtr deviceAt(int index) const;
65

66
    IDevice::ConstPtr find(Core::Id id) const;
67
    IDevice::ConstPtr defaultDevice(Core::Id deviceType) const;
68
    bool hasDevice(const QString &name) const;
69

70
    void addDevice(const IDevice::ConstPtr &device);
71
    void removeDevice(Core::Id id);
72

73
74
    bool isLoaded() const;

75
signals:
76
77
    void deviceAdded(Core::Id id);
    void deviceRemoved(Core::Id id);
78
    void deviceUpdated(Core::Id id);
79
80
    void deviceListChanged();
    void updated(); // Emitted for all of the above.
81

82
83
    void devicesLoaded(); // Emitted once load() is done

84
85
86
private slots:
    void save();

87
private:
88
    DeviceManager(bool isInstance = true);
89

90
    void load();
91
    void loadPre2_6();
92
    static const IDeviceFactory *restoreFactory(const QVariantMap &map);
93
94
    void fromMap(const QVariantMap &map);
    QVariantMap toMap() const;
95
    void ensureOneDefaultDevicePerType();
96

97
    // For SettingsWidget.
98
    IDevice::Ptr mutableDevice(Core::Id id) const;
99
100
    void setDefaultDevice(int index);
    static DeviceManager *cloneInstance();
101
102
    static void replaceInstance();
    static void removeClonedInstance();
103

104
105
106
107
    // For IDevice.
    IDevice::Ptr fromRawPointer(IDevice *device) const;
    IDevice::ConstPtr fromRawPointer(const IDevice *device) const;

108
    static Utils::FileName settingsFilePath(const QString &extension);
109
110
111
    static void copy(const DeviceManager *source, DeviceManager *target, bool deep);

    Internal::DeviceManagerPrivate * const d;
112
113
114

    friend class Internal::DeviceManagerPrivate;
    friend class ProjectExplorerPlugin;
115
116
};

117
} // namespace ProjectExplorer
118

119
#endif // DEVICEMANAGER_H