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
This commit is contained in:
Kai Koehne
2010-08-19 16:51:27 +02:00
parent 420a2b4e6e
commit 60fffda9eb
9 changed files with 132 additions and 30 deletions

View File

@@ -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*)));
Qt4ProjectManager::QtVersionManager *qtVersions = Qt4ProjectManager::QtVersionManager::instance();
connect(qtVersions, SIGNAL(qtVersionsChanged(QList<int>)), this, SLOT(updateEnabled()));
setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
// 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);
}
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();
}
setEnabled(enable);
bool newValue = QFileInfo(viewerPath()).exists() && qmlFileFound;
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