summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@nokia.com>2010-08-19 16:51:27 +0200
committerKai Koehne <kai.koehne@nokia.com>2010-08-19 17:22:13 +0200
commit60fffda9eb1f51cea6de74fb131b1d0d6bb6bbfd (patch)
treeffd98a8d7bf6ed8423b003f3dd60f4b13dc27090
parent420a2b4e6efdae067728d8a552016ed614f1d541 (diff)
downloadqt-creator-60fffda9eb1f51cea6de74fb131b1d0d6bb6bbfd.tar.gz
QmlProject: Search for qmlviewer in configured Qt versions (if not found in $PATH)
If no 'qmlviewer' executable is found in the PATH, iterate through the list of configured Qt versions and try to find a qmlviewer there. This should help users configuring creator such to play with Qml. Right now the first qmlviewer found in a Qt version is selected. A UI to let the user select one explicitly was not possible any more (string freeze). This requires a dependency from QmlProjectManager to Qt4ProjectManager. Reviewed-by: dt
-rw-r--r--src/plugins/plugins.pro1
-rw-r--r--src/plugins/qmlprojectmanager/QmlProjectManager.pluginspec2
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectmanager_dependencies.pri1
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp83
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h6
-rw-r--r--src/plugins/qt4projectmanager/qt4projectmanager.pro4
-rw-r--r--src/plugins/qt4projectmanager/qt4projectmanager_global.h41
-rw-r--r--src/plugins/qt4projectmanager/qtversionmanager.cpp17
-rw-r--r--src/plugins/qt4projectmanager/qtversionmanager.h7
9 files changed, 132 insertions, 30 deletions
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
index f59ddb97a4..f958d426e0 100644
--- a/src/plugins/plugins.pro
+++ b/src/plugins/plugins.pro
@@ -190,6 +190,7 @@ plugin_qmlprojectmanager.depends = plugin_texteditor
plugin_qmlprojectmanager.depends += plugin_projectexplorer
plugin_qmlprojectmanager.depends += plugin_qmljseditor
plugin_qmlprojectmanager.depends += plugin_debugger
+plugin_qmlprojectmanager.depends += plugin_qt4projectmanager
plugin_qmldesigner.subdir = qmldesigner
plugin_qmldesigner.depends = plugin_coreplugin
diff --git a/src/plugins/qmlprojectmanager/QmlProjectManager.pluginspec b/src/plugins/qmlprojectmanager/QmlProjectManager.pluginspec
index eca6196a3e..8e3405428e 100644
--- a/src/plugins/qmlprojectmanager/QmlProjectManager.pluginspec
+++ b/src/plugins/qmlprojectmanager/QmlProjectManager.pluginspec
@@ -18,5 +18,7 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General
<dependency name="TextEditor" version="2.1.0"/>
<dependency name="QmlJSEditor" version="2.1.0"/>
<dependency name="Debugger" version="2.1.0" />
+ <dependency name="ProjectExplorer" version="2.1.0"/>
+ <dependency name="Qt4ProjectManager" version="2.1.0" />
</dependencyList>
</plugin>
diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanager_dependencies.pri b/src/plugins/qmlprojectmanager/qmlprojectmanager_dependencies.pri
index 74bc6fed60..9cdedcd2c3 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectmanager_dependencies.pri
+++ b/src/plugins/qmlprojectmanager/qmlprojectmanager_dependencies.pri
@@ -2,3 +2,4 @@ include(../../plugins/projectexplorer/projectexplorer.pri)
include(../../plugins/texteditor/texteditor.pri)
include(../../plugins/qmljseditor/qmljseditor.pri)
include(../../plugins/debugger/debugger.pri)
+include(../../plugins/qt4projectmanager/qt4projectmanager.pri)
diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
index 3b959f83af..3e3e75ffeb 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
@@ -41,6 +41,8 @@
#include <coreplugin/ifile.h>
#include <utils/synchronousprocess.h>
#include <utils/pathchooser.h>
+#include <qt4projectmanager/qtversionmanager.h>
+#include <qt4projectmanager/qt4projectmanagerconstants.h>
#include <QFormLayout>
#include <QComboBox>
@@ -94,20 +96,10 @@ void QmlProjectRunConfiguration::ctor()
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(changeCurrentFile(Core::IEditor*)));
- setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
+ Qt4ProjectManager::QtVersionManager *qtVersions = Qt4ProjectManager::QtVersionManager::instance();
+ connect(qtVersions, SIGNAL(qtVersionsChanged(QList<int>)), this, SLOT(updateEnabled()));
- // prepend creator/bin dir to search path (only useful for special creator-qml package)
- const QString searchPath = QCoreApplication::applicationDirPath()
- + Utils::SynchronousProcess::pathSeparator()
- + QString(qgetenv("PATH"));
-
-#ifdef Q_OS_MAC
- const QString qmlViewerName = QLatin1String("QMLViewer");
-#else
- const QString qmlViewerName = QLatin1String("qmlviewer");
-#endif
-
- m_qmlViewerDefaultPath = Utils::SynchronousProcess::locateBinary(searchPath, qmlViewerName);
+ setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
}
QmlProjectRunConfiguration::~QmlProjectRunConfiguration()
@@ -128,7 +120,8 @@ QString QmlProjectRunConfiguration::viewerPath() const
{
if (!m_qmlViewerCustomPath.isEmpty())
return m_qmlViewerCustomPath;
- return m_qmlViewerDefaultPath;
+
+ return viewerDefaultPath();
}
QStringList QmlProjectRunConfiguration::viewerArguments() const
@@ -182,8 +175,11 @@ QWidget *QmlProjectRunConfiguration::createConfigurationWidget()
Utils::PathChooser *qmlViewer = new Utils::PathChooser;
qmlViewer->setExpectedKind(Utils::PathChooser::Command);
qmlViewer->setPath(viewerPath());
+
connect(qmlViewer, SIGNAL(changed(QString)), this, SLOT(onViewerChanged()));
+ QToolButton *qtVersionSelector = new QToolButton;
+
QLineEdit *qmlViewerArgs = new QLineEdit;
qmlViewerArgs->setText(m_qmlViewerArgs);
connect(qmlViewerArgs, SIGNAL(textChanged(QString)), this, SLOT(onViewerArgsChanged()));
@@ -267,7 +263,7 @@ void QmlProjectRunConfiguration::setMainScript(const QString &scriptFile)
} else {
m_usingCurrentFile = false;
m_mainScriptFilename = qmlTarget()->qmlProject()->projectDir().absoluteFilePath(scriptFile);
- setEnabled(true);
+ updateEnabled();
}
}
@@ -315,40 +311,79 @@ bool QmlProjectRunConfiguration::fromMap(const QVariantMap &map)
return RunConfiguration::fromMap(map);
}
-void QmlProjectRunConfiguration::changeCurrentFile(Core::IEditor *editor)
+void QmlProjectRunConfiguration::changeCurrentFile(Core::IEditor * /*editor*/)
+{
+ updateEnabled();
+}
+
+void QmlProjectRunConfiguration::updateEnabled()
{
+ bool qmlFileFound = false;
if (m_usingCurrentFile) {
- bool enable = false;
+ Core::IEditor *editor = Core::EditorManager::instance()->currentEditor();
if (editor) {
m_currentFileFilename = editor->file()->fileName();
if (Core::ICore::instance()->mimeDatabase()->findByFile(mainScript()).type() == QLatin1String("application/x-qml"))
- enable = true;
+ qmlFileFound = true;
}
if (!editor
|| Core::ICore::instance()->mimeDatabase()->findByFile(mainScript()).type() == QLatin1String("application/x-qmlproject")) {
// find a qml file with lowercase filename. This is slow but only done in initialization/other border cases.
- foreach(const QString& filename, m_projectTarget->qmlProject()->files()) {
+ foreach(const QString &filename, m_projectTarget->qmlProject()->files()) {
const QFileInfo fi(filename);
if (!filename.isEmpty() && fi.baseName()[0].isLower()
&& Core::ICore::instance()->mimeDatabase()->findByFile(fi).type() == QLatin1String("application/x-qml"))
{
m_currentFileFilename = filename;
- enable = true;
+ qmlFileFound = true;
break;
}
}
}
+ } else { // use default one
+ qmlFileFound = !m_mainScriptFilename.isEmpty();
+ }
+
+ bool newValue = QFileInfo(viewerPath()).exists() && qmlFileFound;
- setEnabled(enable);
+ if (m_isEnabled != newValue) {
+ m_isEnabled = newValue;
+ emit isEnabledChanged(m_isEnabled);
}
}
-void QmlProjectRunConfiguration::setEnabled(bool value)
+QString QmlProjectRunConfiguration::viewerDefaultPath() const
{
- m_isEnabled = value;
- emit isEnabledChanged(m_isEnabled);
+ QString path;
+
+ // prepend creator/bin dir to search path (only useful for special creator-qml package)
+ const QString searchPath = QCoreApplication::applicationDirPath()
+ + Utils::SynchronousProcess::pathSeparator()
+ + QString::fromLocal8Bit(qgetenv("PATH"));
+
+
+#ifdef Q_OS_MAC
+ const QString qmlViewerName = QLatin1String("QMLViewer");
+#else
+ const QString qmlViewerName = QLatin1String("qmlviewer");
+#endif
+
+ path = Utils::SynchronousProcess::locateBinary(searchPath, qmlViewerName);
+ if (!path.isEmpty())
+ return path;
+
+ // Try to locate default path in Qt Versions
+ Qt4ProjectManager::QtVersionManager *qtVersions = Qt4ProjectManager::QtVersionManager::instance();
+ foreach (Qt4ProjectManager::QtVersion *version, qtVersions->validVersions()) {
+ if (!version->qmlviewerCommand().isEmpty()
+ && version->supportsTargetId(Qt4ProjectManager::Constants::DESKTOP_TARGET_ID)) {
+ return version->qmlviewerCommand();
+ }
+ }
+
+ return path;
}
} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h
index 1782046f9e..53adfb0cb6 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h
+++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h
@@ -88,18 +88,19 @@ public slots:
void changeCurrentFile(Core::IEditor*);
private slots:
-
QString mainScript() const;
void setMainScript(const QString &scriptFile);
void updateFileComboBox();
+ void updateEnabled();
+
void onViewerChanged();
void onViewerArgsChanged();
void onDebugServerAddressChanged();
void onDebugServerPortChanged();
-
protected:
+ QString viewerDefaultPath() const;
QmlProjectRunConfiguration(Internal::QmlProjectTarget *parent, QmlProjectRunConfiguration *source);
virtual bool fromMap(const QVariantMap &map);
void setEnabled(bool value);
@@ -114,7 +115,6 @@ private:
QString m_scriptFile;
QString m_qmlViewerCustomPath;
- QString m_qmlViewerDefaultPath;
QString m_qmlViewerArgs;
QmlProjectRunConfigurationDebugData m_debugData;
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.pro b/src/plugins/qt4projectmanager/qt4projectmanager.pro
index f4c492ac33..28f45408b6 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.pro
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.pro
@@ -1,5 +1,6 @@
TEMPLATE = lib
TARGET = Qt4ProjectManager
+DEFINES += QT4PROJECTMANAGER_LIBRARY
QT += network
include(../../qtcreatorplugin.pri)
include(qt4projectmanager_dependencies.pri)
@@ -44,7 +45,8 @@ HEADERS += qt4projectmanagerplugin.h \
gettingstartedwelcomepage.h \
qt4buildconfiguration.h \
qt4target.h \
- qmakeparser.h
+ qmakeparser.h \
+ qt4projectmanager_global.h
SOURCES += qt4projectmanagerplugin.cpp \
qt4projectmanager.cpp \
qt4project.cpp \
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager_global.h b/src/plugins/qt4projectmanager/qt4projectmanager_global.h
new file mode 100644
index 0000000000..54880b014c
--- /dev/null
+++ b/src/plugins/qt4projectmanager/qt4projectmanager_global.h
@@ -0,0 +1,41 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef QT4PROJECTMANAGER_GLOBAL_H
+#define QT4PROJECTMANAGER_GLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(QT4PROJECTMANAGER_LIBRARY)
+# define QT4PROJECTMANAGER_EXPORT Q_DECL_EXPORT
+#else
+# define QT4PROJECTMANAGER_EXPORT Q_DECL_IMPORT
+#endif
+
+#endif // QT4PROJECTMANAGER_GLOBAL_H
diff --git a/src/plugins/qt4projectmanager/qtversionmanager.cpp b/src/plugins/qt4projectmanager/qtversionmanager.cpp
index 7eae510d64..06b9d18ecd 100644
--- a/src/plugins/qt4projectmanager/qtversionmanager.cpp
+++ b/src/plugins/qt4projectmanager/qtversionmanager.cpp
@@ -749,6 +749,7 @@ void QtVersion::setQMakeCommand(const QString& qmakeCommand)
#endif
m_designerCommand.clear();
m_linguistCommand.clear();
+ m_qmlviewerCommand.clear();
m_uicCommand.clear();
m_toolChainUpToDate = false;
// TODO do i need to optimize this?
@@ -1202,6 +1203,22 @@ QString QtVersion::linguistCommand() const
return m_linguistCommand;
}
+QString QtVersion::qmlviewerCommand() const
+{
+ if (!isValid())
+ return QString();
+ if (m_qmlviewerCommand.isNull()) {
+#ifdef Q_OS_MAC
+ const QString qmlViewerName = QLatin1String("QMLViewer");
+#else
+ const QString qmlViewerName = QLatin1String("qmlviewer");
+#endif
+
+ m_qmlviewerCommand = findQtBinary(possibleGuiBinaries(qmlViewerName));
+ }
+ return m_qmlviewerCommand;
+}
+
bool QtVersion::supportsTargetId(const QString &id) const
{
updateToolChainAndMkspec();
diff --git a/src/plugins/qt4projectmanager/qtversionmanager.h b/src/plugins/qt4projectmanager/qtversionmanager.h
index 3716635d14..fe4484ce3b 100644
--- a/src/plugins/qt4projectmanager/qtversionmanager.h
+++ b/src/plugins/qt4projectmanager/qtversionmanager.h
@@ -30,6 +30,7 @@
#ifndef QTVERSIONMANAGER_H
#define QTVERSIONMANAGER_H
+#include "qt4projectmanager_global.h"
#include <projectexplorer/taskwindow.h>
#include <projectexplorer/toolchain.h>
#include <QSharedPointer>
@@ -45,7 +46,7 @@ class QtOptionsPageWidget;
class QtOptionsPage;
}
-class QtVersion
+class QT4PROJECTMANAGER_EXPORT QtVersion
{
friend class QtVersionManager;
public:
@@ -70,6 +71,7 @@ public:
QString uicCommand() const;
QString designerCommand() const;
QString linguistCommand() const;
+ QString qmlviewerCommand() const;
bool supportsTargetId(const QString &id) const;
QSet<QString> supportedTargetIds() const;
@@ -189,6 +191,7 @@ private:
mutable QString m_uicCommand;
mutable QString m_designerCommand;
mutable QString m_linguistCommand;
+ mutable QString m_qmlviewerCommand;
mutable QSet<QString> m_targetIds;
};
@@ -199,7 +202,7 @@ struct QMakeAssignment
QString value;
};
-class QtVersionManager : public QObject
+class QT4PROJECTMANAGER_EXPORT QtVersionManager : public QObject
{
Q_OBJECT
// for getUniqueId();