maemomanager.cpp 5.84 KB
Newer Older
ck's avatar
ck committed
1
2
3
4
5
6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
kh1's avatar
kh1 committed
7
** Contact: Nokia Corporation (qt-info@nokia.com)
ck's avatar
ck committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/

#include "maemomanager.h"

ck's avatar
ck committed
32
#include "maemodeviceconfigurations.h"
33
#include "maemorunfactories.h"
34
#include "maemosettingspage.h"
ck's avatar
ck committed
35
36
37
38
39
40
41
42
43
#include "maemotoolchain.h"
#include "maemorunconfiguration.h"

#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/modemanager.h>
#include <extensionsystem/pluginmanager.h>

44
45
#include <QtCore/QDir>
#include <QtCore/QFile>
ck's avatar
ck committed
46
#include <QtCore/QList>
47
#include <QtCore/QTextStream>
ck's avatar
ck committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61

#include <QtGui/QAction>

namespace Qt4ProjectManager {
    namespace Internal {

MaemoManager *MaemoManager::m_instance = 0;

const QSize iconSize = QSize(24, 20);

MaemoManager::MaemoManager()
    : QObject(0)
    , m_runControlFactory(new MaemoRunControlFactory(this))
    , m_runConfigurationFactory(new MaemoRunConfigurationFactory(this))
62
    , m_settingsPage(new MaemoSettingsPage(this))
ck's avatar
ck committed
63
64
    , m_qemuCommand(0)
{
65
66
    Q_ASSERT(!m_instance);

67
    m_instance = this;
68
69
    MaemoDeviceConfigurations::instance(this);

ck's avatar
ck committed
70
71
72
73
74
75
    icon.addFile(":/qt-maemo/images/qemu-run.png", iconSize);
    icon.addFile(":/qt-maemo/images/qemu-stop.png", iconSize, QIcon::Normal,
        QIcon::On);

    ExtensionSystem::PluginManager::instance()->addObject(m_runControlFactory);
    ExtensionSystem::PluginManager::instance()->addObject(m_runConfigurationFactory);
76
    ExtensionSystem::PluginManager::instance()->addObject(m_settingsPage);
ck's avatar
ck committed
77
78
79
80
81
82
}

MaemoManager::~MaemoManager()
{
    ExtensionSystem::PluginManager::instance()->removeObject(m_runControlFactory);
    ExtensionSystem::PluginManager::instance()->removeObject(m_runConfigurationFactory);
83
    ExtensionSystem::PluginManager::instance()->removeObject(m_settingsPage);
84
85

    m_instance = 0;
ck's avatar
ck committed
86
87
}

88
MaemoManager &MaemoManager::instance()
ck's avatar
ck committed
89
{
90
    Q_ASSERT(m_instance);
91
    return *m_instance;
ck's avatar
ck committed
92
93
}

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
bool
MaemoManager::isValidMaemoQtVersion(const Qt4ProjectManager::QtVersion *version) const
{
    QString path = QDir::cleanPath(version->qmakeCommand());
    path = path.remove(QLatin1String("/bin/qmake" EXEC_SUFFIX));

    QDir dir(path);
    dir.cdUp(); dir.cdUp();

    QFile file(dir.absolutePath() + QLatin1String("/cache/madde.conf"));
    if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        const QString &target = path.mid(path.lastIndexOf(QLatin1Char('/')) + 1);
        QTextStream stream(&file);
        while (!stream.atEnd()) {
            const QString &line = stream.readLine().trimmed();
            if (line.startsWith(QLatin1String("target"))
                && line.endsWith(target)) {
                    return true;
            }
        }
    }
    return false;
}

ck's avatar
ck committed
118
119
120
121
122
123
124
125
126
ProjectExplorer::ToolChain*
MaemoManager::maemoToolChain(const QtVersion *version) const
{
    return new MaemoToolChain(version);
}

void
MaemoManager::addQemuSimulatorStarter(Project *project)
{
Tobias Hunger's avatar
Tobias Hunger committed
127
128
129
    if (projects.contains(project))
        return;

ck's avatar
ck committed
130
131
132
133
134
135
136
137
138
139
140
    projects.insert(project);

    if (m_qemuCommand) {
        m_qemuCommand->action()->setVisible(true);
        return;
    }

    Core::ICore *core = Core::ICore::instance();
    Core::ModeManager *modeManager = core->modeManager();
    Core::ActionManager *actionManager = core->actionManager();

141
    QAction *action = new QAction("Maemo Emulator", this);
ck's avatar
ck committed
142
    action->setIcon(icon.pixmap(iconSize));
143
144
    action->setToolTip(tr("Start Maemo Emulator"));
    m_qemuCommand = actionManager->registerAction(action, "MaemoEmulator",
ck's avatar
ck committed
145
146
        QList<int>() << Core::Constants::C_GLOBAL_ID);
    modeManager->addAction(m_qemuCommand, 1);
147
    m_qemuCommand->action()->setEnabled(false);
ck's avatar
ck committed
148
149
150
151
152
153
154
155
156
    m_qemuCommand->setAttribute(Core::Command::CA_UpdateText);
    m_qemuCommand->setAttribute(Core::Command::CA_UpdateIcon);

    connect(m_qemuCommand->action(), SIGNAL(triggered()), this, SLOT(triggered()));
}

void
MaemoManager::removeQemuSimulatorStarter(Project *project)
{
157
158
159
160
161
    if (projects.contains(project)) {
        projects.remove(project);
        if (projects.isEmpty() && m_qemuCommand)
            m_qemuCommand->action()->setVisible(false);
    }
ck's avatar
ck committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
}

void
MaemoManager::setQemuSimulatorStarterEnabled(bool enable)
{
    if (m_qemuCommand)
        m_qemuCommand->action()->setEnabled(enable);
}

void
MaemoManager::triggered()
{
    emit startStopQemu();
}

void
MaemoManager::updateQemuSimulatorStarter(bool running)
{
    if (m_qemuCommand) {
        QIcon::State state = QIcon::Off;
182
        QString toolTip(tr("Start Maemo Emulator"));
ck's avatar
ck committed
183
184
        if (running) {
            state = QIcon::On;
185
            toolTip = tr("Stop Maemo Emulator");
ck's avatar
ck committed
186
187
188
189
190
191
192
193
194
195
        }

        QAction *action = m_qemuCommand->action();
        action->setToolTip(toolTip);
        action->setIcon(icon.pixmap(iconSize, QIcon::Normal, state));
    }
}

    } // namespace Internal
} // namespace Qt4ProjectManager