OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemomanager.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "maemomanager.h"
35
36 #include "maemoconstants.h"
37 #include "maemodeploystepfactory.h"
38 #include "maemodeviceconfigurations.h"
39 #include "maemoglobal.h"
40 #include "maemopackagecreationfactory.h"
41 #include "maemopublishingwizardfactories.h"
42 #include "maemoqemumanager.h"
43 #include "maemorunfactories.h"
44 #include "maemosettingspages.h"
45 #include "maemotemplatesmanager.h"
46 #include "maemotoolchain.h"
47
48 #include <extensionsystem/pluginmanager.h>
49 #include <qt4projectmanager/qtversionmanager.h>
50
51 #include <QtCore/QDir>
52 #include <QtCore/QFile>
53 #include <QtCore/QTextStream>
54
55 using namespace ExtensionSystem;
56 using namespace ProjectExplorer;
57
58 namespace Qt4ProjectManager {
59     namespace Internal {
60
61 MaemoManager *MaemoManager::m_instance = 0;
62
63 MaemoManager::MaemoManager()
64     : QObject(0)
65     , m_runControlFactory(new MaemoRunControlFactory(this))
66     , m_runConfigurationFactory(new MaemoRunConfigurationFactory(this))
67     , m_packageCreationFactory(new MaemoPackageCreationFactory(this))
68     , m_deployStepFactory(new MaemoDeployStepFactory(this))
69     , m_deviceConfigurationsSettingsPage(new MaemoDeviceConfigurationsSettingsPage(this))
70     , m_qemuSettingsPage(new MaemoQemuSettingsPage(this))
71     , m_publishingFactoryFremantleFree(new MaemoPublishingWizardFactoryFremantleFree(this))
72 {
73     Q_ASSERT(!m_instance);
74
75     m_instance = this;
76     MaemoQemuManager::instance(this);
77     MaemoDeviceConfigurations::instance(this);
78     MaemoTemplatesManager::instance(this);
79
80     PluginManager *pluginManager = PluginManager::instance();
81     pluginManager->addObject(m_runControlFactory);
82     pluginManager->addObject(m_runConfigurationFactory);
83     pluginManager->addObject(m_packageCreationFactory);
84     pluginManager->addObject(m_deployStepFactory);
85     pluginManager->addObject(m_deviceConfigurationsSettingsPage);
86     pluginManager->addObject(m_qemuSettingsPage);
87     pluginManager->addObject(m_publishingFactoryFremantleFree);
88 }
89
90 MaemoManager::~MaemoManager()
91 {
92     // TODO: Remove in reverse order of adding.
93     PluginManager *pluginManager = PluginManager::instance();
94     pluginManager->removeObject(m_runControlFactory);
95     pluginManager->removeObject(m_runConfigurationFactory);
96     pluginManager->removeObject(m_deployStepFactory);
97     pluginManager->removeObject(m_packageCreationFactory);
98     pluginManager->removeObject(m_deviceConfigurationsSettingsPage);
99     pluginManager->removeObject(m_qemuSettingsPage);
100     pluginManager->removeObject(m_publishingFactoryFremantleFree);
101
102     m_instance = 0;
103 }
104
105 MaemoManager &MaemoManager::instance()
106 {
107     Q_ASSERT(m_instance);
108     return *m_instance;
109 }
110
111 bool MaemoManager::isValidMaemoQtVersion(const QtVersion *version) const
112 {
113     QProcess madAdminProc;
114     const QStringList arguments(QLatin1String("list"));
115     if (!MaemoGlobal::callMadAdmin(madAdminProc, arguments, version))
116         return false;
117     if (!madAdminProc.waitForStarted() || !madAdminProc.waitForFinished())
118         return false;
119
120     madAdminProc.setReadChannel(QProcess::StandardOutput);
121     const QByteArray targetName = MaemoGlobal::targetName(version).toAscii();
122     while (madAdminProc.canReadLine()) {
123         const QByteArray &line = madAdminProc.readLine();
124         if (line.contains(targetName)
125             && (line.contains("(installed)") || line.contains("(default)")))
126             return true;
127     }
128     return false;
129 }
130
131 ToolChain* MaemoManager::maemoToolChain(const QtVersion *version) const
132 {
133     return new MaemoToolChain(version);
134 }
135
136     } // namespace Internal
137 } // namespace Qt4ProjectManager