2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "pathchooser.h"
|
|
|
|
|
|
2008-12-09 15:25:01 +01:00
|
|
|
#include "basevalidatinglineedit.h"
|
2010-09-23 11:06:12 +02:00
|
|
|
#include "environment.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
#include "qtcassert.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-02-22 12:25:19 +01:00
|
|
|
#include "synchronousprocess.h"
|
|
|
|
|
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <QtCore/QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QDir>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <QtCore/QFileInfo>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QSettings>
|
2011-02-22 12:25:19 +01:00
|
|
|
#include <QtCore/QProcess>
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2011-02-22 12:25:19 +01:00
|
|
|
#include <QtGui/qevent.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <QtGui/QDesktopServices>
|
|
|
|
|
#include <QtGui/QFileDialog>
|
|
|
|
|
#include <QtGui/QHBoxLayout>
|
|
|
|
|
#include <QtGui/QLineEdit>
|
|
|
|
|
#include <QtGui/QToolButton>
|
2008-12-11 15:11:15 +01:00
|
|
|
#include <QtGui/QPushButton>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
/*static*/ const char * const Utils::PathChooser::browseButtonLabel =
|
2009-06-03 20:45:49 +02:00
|
|
|
#ifdef Q_WS_MAC
|
2009-10-05 11:06:05 +02:00
|
|
|
QT_TRANSLATE_NOOP("Utils::PathChooser", "Choose...");
|
2008-12-05 18:51:07 +01:00
|
|
|
#else
|
2009-10-05 11:06:05 +02:00
|
|
|
QT_TRANSLATE_NOOP("Utils::PathChooser", "Browse...");
|
2008-12-05 18:51:07 +01:00
|
|
|
#endif
|
|
|
|
|
|
2009-04-17 09:03:32 +02:00
|
|
|
namespace Utils {
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// ------------------ PathValidatingLineEdit
|
2010-09-23 11:06:12 +02:00
|
|
|
|
2008-12-09 11:27:17 +01:00
|
|
|
class PathValidatingLineEdit : public BaseValidatingLineEdit
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
2008-12-05 18:51:07 +01:00
|
|
|
explicit PathValidatingLineEdit(PathChooser *chooser, QWidget *parent = 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual bool validate(const QString &value, QString *errorMessage) const;
|
2008-12-05 18:51:07 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
PathChooser *m_chooser;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
PathValidatingLineEdit::PathValidatingLineEdit(PathChooser *chooser, QWidget *parent) :
|
|
|
|
|
BaseValidatingLineEdit(parent),
|
|
|
|
|
m_chooser(chooser)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(chooser, return);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PathValidatingLineEdit::validate(const QString &value, QString *errorMessage) const
|
|
|
|
|
{
|
2008-12-05 18:51:07 +01:00
|
|
|
return m_chooser->validatePath(value, errorMessage);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-22 12:25:19 +01:00
|
|
|
// ------------------ BinaryVersionToolTipEventFilter
|
|
|
|
|
// Event filter to be installed on a lineedit used for entering
|
|
|
|
|
// executables, taking the arguments to print the version ('--version').
|
|
|
|
|
// On a tooltip event, the version is obtained by running the binary and
|
|
|
|
|
// setting its stdout as tooltip.
|
|
|
|
|
|
|
|
|
|
class BinaryVersionToolTipEventFilter : public QObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit BinaryVersionToolTipEventFilter(QLineEdit *le);
|
|
|
|
|
|
|
|
|
|
virtual bool eventFilter(QObject *, QEvent *);
|
|
|
|
|
|
|
|
|
|
QStringList arguments() const { return m_arguments; }
|
|
|
|
|
void setArguments(const QStringList &arguments) { m_arguments = arguments; }
|
|
|
|
|
|
|
|
|
|
static QString toolVersion(const QString &binary, const QStringList &arguments);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Extension point for concatenating existing tooltips.
|
|
|
|
|
virtual QString defaultToolTip() const { return QString(); }
|
|
|
|
|
|
|
|
|
|
QStringList m_arguments;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BinaryVersionToolTipEventFilter::BinaryVersionToolTipEventFilter(QLineEdit *le) :
|
|
|
|
|
QObject(le)
|
|
|
|
|
{
|
|
|
|
|
le->installEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BinaryVersionToolTipEventFilter::eventFilter(QObject *o, QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (e->type() != QEvent::ToolTip)
|
|
|
|
|
return false;
|
|
|
|
|
QLineEdit *le = qobject_cast<QLineEdit *>(o);
|
|
|
|
|
QTC_ASSERT(le, return false; )
|
|
|
|
|
|
|
|
|
|
const QString binary = le->text();
|
|
|
|
|
if (!binary.isEmpty()) {
|
|
|
|
|
const QString version = BinaryVersionToolTipEventFilter::toolVersion(QDir::cleanPath(binary), m_arguments);
|
|
|
|
|
if (!version.isEmpty()) {
|
|
|
|
|
// Concatenate tooltips.
|
|
|
|
|
QString tooltip = QLatin1String("<html><head/><body>");
|
|
|
|
|
const QString defaultValue = defaultToolTip();
|
|
|
|
|
if (!defaultValue.isEmpty()) {
|
|
|
|
|
tooltip += QLatin1String("<p>");
|
|
|
|
|
tooltip += defaultValue;
|
|
|
|
|
tooltip += QLatin1String("</p>");
|
|
|
|
|
}
|
|
|
|
|
tooltip += QLatin1String("<pre>");
|
|
|
|
|
tooltip += version;
|
|
|
|
|
tooltip += QLatin1String("</pre><body></html>");
|
|
|
|
|
le->setToolTip(tooltip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BinaryVersionToolTipEventFilter::toolVersion(const QString &binary, const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
if (binary.isEmpty())
|
|
|
|
|
return QString();
|
|
|
|
|
QProcess proc;
|
|
|
|
|
proc.start(binary, arguments);
|
|
|
|
|
if (!proc.waitForStarted())
|
|
|
|
|
return QString();
|
|
|
|
|
if (!proc.waitForFinished()) {
|
|
|
|
|
Utils::SynchronousProcess::stopProcess(proc);
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
return QString::fromLocal8Bit(proc.readAllStandardOutput());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extends BinaryVersionToolTipEventFilter to prepend the existing pathchooser
|
|
|
|
|
// tooltip to display the full path.
|
|
|
|
|
class PathChooserBinaryVersionToolTipEventFilter : public BinaryVersionToolTipEventFilter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit PathChooserBinaryVersionToolTipEventFilter(PathChooser *pe) :
|
|
|
|
|
BinaryVersionToolTipEventFilter(pe->lineEdit()), m_pathChooser(pe) {}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual QString defaultToolTip() const
|
|
|
|
|
{ return m_pathChooser->errorMessage(); }
|
|
|
|
|
|
|
|
|
|
const PathChooser *m_pathChooser;
|
|
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// ------------------ PathChooserPrivate
|
2010-09-23 11:06:12 +02:00
|
|
|
|
|
|
|
|
class PathChooserPrivate
|
2008-12-09 11:27:17 +01:00
|
|
|
{
|
2010-09-23 11:06:12 +02:00
|
|
|
public:
|
2008-12-05 18:51:07 +01:00
|
|
|
PathChooserPrivate(PathChooser *chooser);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-23 11:06:12 +02:00
|
|
|
QString expandedPath(const QString &path) const;
|
|
|
|
|
|
2009-04-17 09:03:32 +02:00
|
|
|
QHBoxLayout *m_hLayout;
|
2008-12-02 12:01:29 +01:00
|
|
|
PathValidatingLineEdit *m_lineEdit;
|
2008-12-05 18:51:07 +01:00
|
|
|
PathChooser::Kind m_acceptingKind;
|
|
|
|
|
QString m_dialogTitleOverride;
|
2009-06-29 14:47:04 +02:00
|
|
|
QString m_dialogFilter;
|
2008-12-19 18:25:20 +01:00
|
|
|
QString m_initialBrowsePathOverride;
|
2010-09-17 13:59:59 +02:00
|
|
|
QString m_baseDirectory;
|
2010-09-23 11:06:12 +02:00
|
|
|
Environment m_environment;
|
2011-02-22 12:25:19 +01:00
|
|
|
BinaryVersionToolTipEventFilter *m_binaryVersionToolTipEventFilter;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
PathChooserPrivate::PathChooserPrivate(PathChooser *chooser) :
|
2009-04-17 09:03:32 +02:00
|
|
|
m_hLayout(new QHBoxLayout),
|
2008-12-05 18:51:07 +01:00
|
|
|
m_lineEdit(new PathValidatingLineEdit(chooser)),
|
2011-02-22 12:25:19 +01:00
|
|
|
m_acceptingKind(PathChooser::Directory),
|
|
|
|
|
m_binaryVersionToolTipEventFilter(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-23 11:06:12 +02:00
|
|
|
QString PathChooserPrivate::expandedPath(const QString &input) const
|
|
|
|
|
{
|
2010-09-29 11:33:07 +02:00
|
|
|
if (input.isEmpty())
|
|
|
|
|
return input;
|
2010-10-06 16:11:07 +02:00
|
|
|
const QString path = QDir::fromNativeSeparators(m_environment.expandVariables(input));
|
2010-09-29 11:33:07 +02:00
|
|
|
if (path.isEmpty())
|
2010-09-23 11:06:12 +02:00
|
|
|
return path;
|
|
|
|
|
|
2010-09-29 11:33:07 +02:00
|
|
|
switch (m_acceptingKind) {
|
|
|
|
|
case PathChooser::Command:
|
|
|
|
|
case PathChooser::ExistingCommand: {
|
|
|
|
|
const QString expanded = m_environment.searchInPath(path, QStringList(m_baseDirectory));
|
|
|
|
|
return expanded.isEmpty() && m_acceptingKind == PathChooser::Command ? path : expanded;
|
|
|
|
|
}
|
|
|
|
|
case PathChooser::Any:
|
|
|
|
|
break;
|
|
|
|
|
case PathChooser::Directory:
|
|
|
|
|
case PathChooser::File:
|
|
|
|
|
if (!m_baseDirectory.isEmpty() && QFileInfo(path).isRelative())
|
|
|
|
|
return QFileInfo(m_baseDirectory + QLatin1Char('/') + path).absoluteFilePath();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-09-23 11:06:12 +02:00
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
PathChooser::PathChooser(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
2008-12-05 18:51:07 +01:00
|
|
|
m_d(new PathChooserPrivate(this))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-04-17 09:03:32 +02:00
|
|
|
m_d->m_hLayout->setContentsMargins(0, 0, 0, 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
connect(m_d->m_lineEdit, SIGNAL(validReturnPressed()), this, SIGNAL(returnPressed()));
|
2009-06-19 17:55:47 +02:00
|
|
|
connect(m_d->m_lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(changed(QString)));
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(m_d->m_lineEdit, SIGNAL(validChanged()), this, SIGNAL(validChanged()));
|
2009-10-22 17:57:16 +02:00
|
|
|
connect(m_d->m_lineEdit, SIGNAL(validChanged(bool)), this, SIGNAL(validChanged(bool)));
|
2009-03-19 09:32:09 +01:00
|
|
|
connect(m_d->m_lineEdit, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-28 17:38:41 +01:00
|
|
|
m_d->m_lineEdit->setMinimumWidth(200);
|
2009-04-17 09:03:32 +02:00
|
|
|
m_d->m_hLayout->addWidget(m_d->m_lineEdit);
|
|
|
|
|
m_d->m_hLayout->setSizeConstraint(QLayout::SetMinimumSize);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-17 09:03:32 +02:00
|
|
|
addButton(tr(browseButtonLabel), this, SLOT(slotBrowse()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-17 09:03:32 +02:00
|
|
|
setLayout(m_d->m_hLayout);
|
2008-12-02 12:01:29 +01:00
|
|
|
setFocusProxy(m_d->m_lineEdit);
|
2010-09-23 11:06:12 +02:00
|
|
|
setEnvironment(Environment::systemEnvironment());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PathChooser::~PathChooser()
|
|
|
|
|
{
|
|
|
|
|
delete m_d;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-17 09:03:32 +02:00
|
|
|
void PathChooser::addButton(const QString &text, QObject *receiver, const char *slotFunc)
|
|
|
|
|
{
|
2009-06-03 20:45:49 +02:00
|
|
|
#ifdef Q_WS_MAC
|
2009-04-17 09:03:32 +02:00
|
|
|
QPushButton *button = new QPushButton;
|
|
|
|
|
#else
|
|
|
|
|
QToolButton *button = new QToolButton;
|
|
|
|
|
#endif
|
|
|
|
|
button->setText(text);
|
|
|
|
|
connect(button, SIGNAL(clicked()), receiver, slotFunc);
|
|
|
|
|
m_d->m_hLayout->addWidget(button);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-22 15:18:42 +02:00
|
|
|
QAbstractButton *PathChooser::buttonAtIndex(int index) const
|
|
|
|
|
{
|
|
|
|
|
return findChildren<QAbstractButton*>().at(index);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-17 13:59:59 +02:00
|
|
|
QString PathChooser::baseDirectory() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_baseDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::setBaseDirectory(const QString &directory)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_baseDirectory = directory;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-23 11:06:12 +02:00
|
|
|
void PathChooser::setEnvironment(const Utils::Environment &env)
|
|
|
|
|
{
|
2010-10-06 13:38:16 +02:00
|
|
|
QString oldExpand = path();
|
2010-09-23 11:06:12 +02:00
|
|
|
m_d->m_environment = env;
|
2010-10-06 13:38:16 +02:00
|
|
|
if (path() != oldExpand)
|
|
|
|
|
emit changed(rawPath());
|
2010-09-23 11:06:12 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QString PathChooser::path() const
|
|
|
|
|
{
|
2010-12-06 11:01:02 +01:00
|
|
|
return m_d->expandedPath(QDir::fromNativeSeparators(m_d->m_lineEdit->text()));
|
2010-09-23 11:06:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PathChooser::rawPath() const
|
|
|
|
|
{
|
|
|
|
|
return QDir::fromNativeSeparators(m_d->m_lineEdit->text());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::setPath(const QString &path)
|
|
|
|
|
{
|
2008-12-19 16:39:02 +01:00
|
|
|
m_d->m_lineEdit->setText(QDir::toNativeSeparators(path));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::slotBrowse()
|
|
|
|
|
{
|
2008-12-19 18:25:20 +01:00
|
|
|
emit beforeBrowsing();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QString predefined = path();
|
2008-12-19 18:25:20 +01:00
|
|
|
if ((predefined.isEmpty() || !QFileInfo(predefined).isDir())
|
|
|
|
|
&& !m_d->m_initialBrowsePathOverride.isNull()) {
|
|
|
|
|
predefined = m_d->m_initialBrowsePathOverride;
|
|
|
|
|
if (!QFileInfo(predefined).isDir())
|
|
|
|
|
predefined.clear();
|
|
|
|
|
}
|
2008-12-05 18:51:07 +01:00
|
|
|
|
|
|
|
|
// Prompt for a file/dir
|
|
|
|
|
QString newPath;
|
|
|
|
|
switch (m_d->m_acceptingKind) {
|
|
|
|
|
case PathChooser::Directory:
|
|
|
|
|
newPath = QFileDialog::getExistingDirectory(this,
|
2010-05-14 15:45:43 +02:00
|
|
|
makeDialogTitle(tr("Choose Directory")), predefined);
|
2008-12-05 18:51:07 +01:00
|
|
|
break;
|
2010-09-23 11:06:12 +02:00
|
|
|
case PathChooser::ExistingCommand:
|
2008-12-05 18:51:07 +01:00
|
|
|
case PathChooser::Command:
|
2010-09-23 11:06:12 +02:00
|
|
|
newPath = QFileDialog::getOpenFileName(this,
|
|
|
|
|
makeDialogTitle(tr("Choose Executable")), predefined,
|
|
|
|
|
m_d->m_dialogFilter);
|
|
|
|
|
break;
|
|
|
|
|
case PathChooser::File: // fall through
|
2008-12-05 18:51:07 +01:00
|
|
|
newPath = QFileDialog::getOpenFileName(this,
|
2010-05-14 15:45:43 +02:00
|
|
|
makeDialogTitle(tr("Choose File")), predefined,
|
2009-06-29 14:47:04 +02:00
|
|
|
m_d->m_dialogFilter);
|
2008-12-05 18:51:07 +01:00
|
|
|
break;
|
2010-08-16 18:23:30 +02:00
|
|
|
case PathChooser::Any: {
|
|
|
|
|
QFileDialog dialog(this);
|
|
|
|
|
dialog.setFileMode(QFileDialog::AnyFile);
|
|
|
|
|
dialog.setWindowTitle(makeDialogTitle(tr("Choose File")));
|
|
|
|
|
QFileInfo fi(predefined);
|
|
|
|
|
if (fi.exists())
|
|
|
|
|
dialog.setDirectory(fi.absolutePath());
|
2010-09-16 12:50:18 +02:00
|
|
|
// FIXME: fix QFileDialog so that it filters properly: lib*.a
|
|
|
|
|
dialog.setNameFilter(m_d->m_dialogFilter);
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
|
|
|
// probably loop here until the *.framework dir match
|
2010-08-16 18:23:30 +02:00
|
|
|
QStringList paths = dialog.selectedFiles();
|
|
|
|
|
if (!paths.isEmpty())
|
|
|
|
|
newPath = paths.at(0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-12-05 18:51:07 +01:00
|
|
|
|
|
|
|
|
default:
|
2010-09-16 12:50:18 +02:00
|
|
|
break;
|
2008-12-05 18:51:07 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-19 15:32:21 +01:00
|
|
|
// Delete trailing slashes unless it is "/"|"\\", only
|
2008-12-09 11:27:17 +01:00
|
|
|
if (!newPath.isEmpty()) {
|
2008-12-19 15:32:21 +01:00
|
|
|
newPath = QDir::toNativeSeparators(newPath);
|
2008-12-09 11:27:17 +01:00
|
|
|
if (newPath.size() > 1 && newPath.endsWith(QDir::separator()))
|
|
|
|
|
newPath.truncate(newPath.size() - 1);
|
2008-12-02 12:01:29 +01:00
|
|
|
setPath(newPath);
|
|
|
|
|
}
|
2008-12-19 15:32:21 +01:00
|
|
|
|
|
|
|
|
emit browsingFinished();
|
2010-11-23 15:19:20 +01:00
|
|
|
m_d->m_lineEdit->triggerChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PathChooser::isValid() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_lineEdit->isValid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PathChooser::errorMessage() const
|
|
|
|
|
{
|
2008-12-09 11:27:17 +01:00
|
|
|
return m_d->m_lineEdit->errorMessage();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PathChooser::validatePath(const QString &path, QString *errorMessage)
|
|
|
|
|
{
|
2010-09-23 11:06:12 +02:00
|
|
|
QString expandedPath = m_d->expandedPath(path);
|
|
|
|
|
|
|
|
|
|
QString displayPath = expandedPath;
|
|
|
|
|
if (expandedPath.isEmpty())
|
|
|
|
|
//: Selected path is not valid:
|
|
|
|
|
displayPath = tr("<not valid>");
|
|
|
|
|
|
|
|
|
|
if (expandedPath.isEmpty()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = tr("The path must not be empty.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-12-05 18:51:07 +01:00
|
|
|
|
2010-09-23 11:06:12 +02:00
|
|
|
const QFileInfo fi(expandedPath);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
// Check if existing
|
|
|
|
|
switch (m_d->m_acceptingKind) {
|
|
|
|
|
case PathChooser::Directory: // fall through
|
2010-09-23 11:06:12 +02:00
|
|
|
case PathChooser::File: // fall through
|
|
|
|
|
case PathChooser::ExistingCommand:
|
2008-12-05 18:51:07 +01:00
|
|
|
if (!fi.exists()) {
|
|
|
|
|
if (errorMessage)
|
2010-09-23 11:06:12 +02:00
|
|
|
*errorMessage = tr("The path '%1' does not exist.").arg(QDir::toNativeSeparators(expandedPath));
|
2008-12-05 18:51:07 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PathChooser::Command: // fall through
|
|
|
|
|
default:
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check expected kind
|
|
|
|
|
switch (m_d->m_acceptingKind) {
|
|
|
|
|
case PathChooser::Directory:
|
2010-03-15 16:15:36 +01:00
|
|
|
if (!fi.isDir()) {
|
2008-12-05 18:51:07 +01:00
|
|
|
if (errorMessage)
|
2010-09-23 11:06:12 +02:00
|
|
|
*errorMessage = tr("The path <b>%1</b> is not a directory.").arg(QDir::toNativeSeparators(expandedPath));
|
2008-12-05 18:51:07 +01:00
|
|
|
return false;
|
2008-12-09 11:27:17 +01:00
|
|
|
}
|
2008-12-05 18:51:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PathChooser::File:
|
2010-03-15 16:15:36 +01:00
|
|
|
if (!fi.isFile()) {
|
2008-12-05 18:51:07 +01:00
|
|
|
if (errorMessage)
|
2010-09-23 11:06:12 +02:00
|
|
|
*errorMessage = tr("The path <b>%1</b> is not a file.").arg(QDir::toNativeSeparators(expandedPath));
|
2008-12-05 18:51:07 +01:00
|
|
|
return false;
|
2008-12-09 11:27:17 +01:00
|
|
|
}
|
2008-12-05 18:51:07 +01:00
|
|
|
break;
|
|
|
|
|
|
2010-09-23 11:06:12 +02:00
|
|
|
case PathChooser::ExistingCommand:
|
|
|
|
|
if (!fi.isFile() || !fi.isExecutable()) {
|
|
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = tr("The path <b>%1</b> is not a executable file.").arg(QDir::toNativeSeparators(expandedPath));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
case PathChooser::Command:
|
|
|
|
|
break;
|
|
|
|
|
|
2010-08-16 18:23:30 +02:00
|
|
|
case PathChooser::Any:
|
|
|
|
|
break;
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
default:
|
|
|
|
|
;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-09-29 12:03:14 +02:00
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = tr("Full path: <b>%1</b>").arg(QDir::toNativeSeparators(expandedPath));
|
2008-12-05 18:51:07 +01:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PathChooser::label()
|
|
|
|
|
{
|
|
|
|
|
return tr("Path:");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PathChooser::homePath()
|
|
|
|
|
{
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
// Return 'users/<name>/Documents' on Windows, since Windows explorer
|
|
|
|
|
// does not let people actually display the contents of their home
|
|
|
|
|
// directory. Alternatively, create a QtCreator-specific directory?
|
|
|
|
|
return QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
|
|
|
|
|
#else
|
|
|
|
|
return QDir::homePath();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
void PathChooser::setExpectedKind(Kind expected)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_acceptingKind = expected;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-29 14:47:04 +02:00
|
|
|
PathChooser::Kind PathChooser::expectedKind() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_acceptingKind;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
void PathChooser::setPromptDialogTitle(const QString &title)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_dialogTitleOverride = title;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-29 14:47:04 +02:00
|
|
|
QString PathChooser::promptDialogTitle() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_dialogTitleOverride;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::setPromptDialogFilter(const QString &filter)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_dialogFilter = filter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PathChooser::promptDialogFilter() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_dialogFilter;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-19 18:25:20 +01:00
|
|
|
void PathChooser::setInitialBrowsePathBackup(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_initialBrowsePathOverride = path;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
QString PathChooser::makeDialogTitle(const QString &title)
|
|
|
|
|
{
|
|
|
|
|
if (m_d->m_dialogTitleOverride.isNull())
|
|
|
|
|
return title;
|
|
|
|
|
else
|
|
|
|
|
return m_d->m_dialogTitleOverride;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:50:18 +02:00
|
|
|
QLineEdit *PathChooser::lineEdit() const
|
|
|
|
|
{
|
|
|
|
|
// HACK: Make it work with HistoryCompleter.
|
|
|
|
|
if (m_d->m_lineEdit->objectName().isEmpty())
|
|
|
|
|
m_d->m_lineEdit->setObjectName(objectName() + QLatin1String("LineEdit"));
|
|
|
|
|
return m_d->m_lineEdit;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-22 12:25:19 +01:00
|
|
|
QString PathChooser::toolVersion(const QString &binary, const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
return BinaryVersionToolTipEventFilter::toolVersion(binary, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
BinaryVersionToolTipEventFilter *ef = new BinaryVersionToolTipEventFilter(le);
|
|
|
|
|
ef->setArguments(arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList PathChooser::commandVersionArguments() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_binaryVersionToolTipEventFilter ?
|
|
|
|
|
m_d->m_binaryVersionToolTipEventFilter->arguments() :
|
|
|
|
|
QStringList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::setCommandVersionArguments(const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
if (arguments.isEmpty()) {
|
|
|
|
|
if (m_d->m_binaryVersionToolTipEventFilter) {
|
|
|
|
|
delete m_d->m_binaryVersionToolTipEventFilter;
|
|
|
|
|
m_d->m_binaryVersionToolTipEventFilter = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!m_d->m_binaryVersionToolTipEventFilter)
|
|
|
|
|
m_d->m_binaryVersionToolTipEventFilter = new PathChooserBinaryVersionToolTipEventFilter(this);
|
|
|
|
|
m_d->m_binaryVersionToolTipEventFilter->setArguments(arguments);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 14:09:21 +01:00
|
|
|
} // namespace Utils
|