Commit 1a9ff3b3 authored by Bryant Mairs's avatar Bryant Mairs

Removed Utils library as it's no longer used.

parent 0ce13bb0
......@@ -302,16 +302,8 @@ DEFINES += NOMINMAX
#
# [REQUIRED] OPMapControl library from OpenPilot. Provides 2D mapping functionality.
#
include(libs/utils/utils_external.pri)
include(libs/opmapcontrol/opmapcontrol_external.pri)
DEPENDPATH += \
libs/utils \
libs/utils/src \
libs/opmapcontrol \
libs/opmapcontrol/src \
libs/opmapcontrol/src/mapwidget
INCLUDEPATH += \
libs/utils \
libs \
......
......@@ -25,7 +25,6 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "cache.h"
#include "utils/pathutils.h"
#include <QSettings>
namespace core {
......
/**
******************************************************************************
*
* @file abstractprocess.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ABSTRACTPROCESS_H
#define ABSTRACTPROCESS_H
#include "utils_global.h"
#include <QtCore/QStringList>
namespace Utils {
class QTCREATOR_UTILS_EXPORT AbstractProcess
{
public:
AbstractProcess() {}
virtual ~AbstractProcess() {}
QString workingDirectory() const { return m_workingDir; }
void setWorkingDirectory(const QString &dir) { m_workingDir = dir; }
QStringList environment() const { return m_environment; }
void setEnvironment(const QStringList &env) { m_environment = env; }
virtual bool start(const QString &program, const QStringList &args) = 0;
virtual void stop() = 0;
virtual bool isRunning() const = 0;
virtual qint64 applicationPID() const = 0;
virtual int exitCode() const = 0;
//signals:
virtual void processError(const QString &error) = 0;
#ifdef Q_OS_WIN
// Add PATH and SystemRoot environment variables in case they are missing
static QStringList fixWinEnvironment(const QStringList &env);
// Quote a Windows command line correctly for the "CreateProcess" API
static QString createWinCommandline(const QString &program, const QStringList &args);
// Create a bytearray suitable to be passed on as environment
// to the "CreateProcess" API (0-terminated UTF 16 strings).
static QByteArray createWinEnvironment(const QStringList &env);
#endif
private:
QString m_workingDir;
QStringList m_environment;
};
} //namespace Utils
#endif // ABSTRACTPROCESS_H
/**
******************************************************************************
*
* @file abstractprocess_win.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "abstractprocess.h"
#include <windows.h>
namespace Utils {
QStringList AbstractProcess::fixWinEnvironment(const QStringList &env)
{
QStringList envStrings = env;
// add PATH if necessary (for DLL loading)
if (envStrings.filter(QRegExp(QLatin1String("^PATH="),Qt::CaseInsensitive)).isEmpty()) {
QByteArray path = qgetenv("PATH");
if (!path.isEmpty())
envStrings.prepend(QString(QLatin1String("PATH=%1")).arg(QString::fromLocal8Bit(path)));
}
// add systemroot if needed
if (envStrings.filter(QRegExp(QLatin1String("^SystemRoot="),Qt::CaseInsensitive)).isEmpty()) {
QByteArray systemRoot = qgetenv("SystemRoot");
if (!systemRoot.isEmpty())
envStrings.prepend(QString(QLatin1String("SystemRoot=%1")).arg(QString::fromLocal8Bit(systemRoot)));
}
return envStrings;
}
QString AbstractProcess::createWinCommandline(const QString &program, const QStringList &args)
{
const QChar doubleQuote = QLatin1Char('"');
const QChar blank = QLatin1Char(' ');
const QChar backSlash = QLatin1Char('\\');
QString programName = program;
if (!programName.startsWith(doubleQuote) && !programName.endsWith(doubleQuote) && programName.contains(blank)) {
programName.insert(0, doubleQuote);
programName.append(doubleQuote);
}
// add the prgram as the first arrg ... it works better
programName.replace(QLatin1Char('/'), backSlash);
QString cmdLine = programName;
if (args.empty())
return cmdLine;
cmdLine += blank;
for (int i = 0; i < args.size(); ++i) {
QString tmp = args.at(i);
// in the case of \" already being in the string the \ must also be escaped
tmp.replace(QLatin1String("\\\""), QLatin1String("\\\\\""));
// escape a single " because the arguments will be parsed
tmp.replace(QString(doubleQuote), QLatin1String("\\\""));
if (tmp.isEmpty() || tmp.contains(blank) || tmp.contains('\t')) {
// The argument must not end with a \ since this would be interpreted
// as escaping the quote -- rather put the \ behind the quote: e.g.
// rather use "foo"\ than "foo\"
QString endQuote(doubleQuote);
int i = tmp.length();
while (i > 0 && tmp.at(i - 1) == backSlash) {
--i;
endQuote += backSlash;
}
cmdLine += QLatin1String(" \"");
cmdLine += tmp.left(i);
cmdLine += endQuote;
} else {
cmdLine += blank;
cmdLine += tmp;
}
}
return cmdLine;
}
QByteArray AbstractProcess::createWinEnvironment(const QStringList &env)
{
QByteArray envlist;
int pos = 0;
foreach (const QString &tmp, env) {
const uint tmpSize = sizeof(TCHAR) * (tmp.length() + 1);
envlist.resize(envlist.size() + tmpSize);
memcpy(envlist.data() + pos, tmp.utf16(), tmpSize);
pos += tmpSize;
}
envlist.resize(envlist.size() + 2);
envlist[pos++] = 0;
envlist[pos++] = 0;
return envlist;
}
} //namespace Utils
/**
******************************************************************************
*
* @file basevalidatinglineedit.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "basevalidatinglineedit.h"
#include <QtCore/QDebug>
enum { debug = 0 };
namespace Utils {
struct BaseValidatingLineEditPrivate {
explicit BaseValidatingLineEditPrivate(const QWidget *w);
const QColor m_okTextColor;
QColor m_errorTextColor;
BaseValidatingLineEdit::State m_state;
QString m_errorMessage;
QString m_initialText;
bool m_firstChange;
};
BaseValidatingLineEditPrivate::BaseValidatingLineEditPrivate(const QWidget *w) :
m_okTextColor(BaseValidatingLineEdit::textColor(w)),
m_errorTextColor(Qt::red),
m_state(BaseValidatingLineEdit::Invalid),
m_firstChange(true)
{
}
BaseValidatingLineEdit::BaseValidatingLineEdit(QWidget *parent) :
QLineEdit(parent),
m_bd(new BaseValidatingLineEditPrivate(this))
{
// Note that textChanged() is also triggered automagically by
// QLineEdit::setText(), no need to trigger manually.
connect(this, SIGNAL(textChanged(QString)), this, SLOT(slotChanged(QString)));
}
BaseValidatingLineEdit::~BaseValidatingLineEdit()
{
delete m_bd;
}
QString BaseValidatingLineEdit::initialText() const
{
return m_bd->m_initialText;
}
void BaseValidatingLineEdit::setInitialText(const QString &t)
{
if (m_bd->m_initialText != t) {
m_bd->m_initialText = t;
m_bd->m_firstChange = true;
setText(t);
}
}
QColor BaseValidatingLineEdit::errorColor() const
{
return m_bd->m_errorTextColor;
}
void BaseValidatingLineEdit::setErrorColor(const QColor &c)
{
m_bd->m_errorTextColor = c;
}
QColor BaseValidatingLineEdit::textColor(const QWidget *w)
{
return w->palette().color(QPalette::Active, QPalette::Text);
}
void BaseValidatingLineEdit::setTextColor(QWidget *w, const QColor &c)
{
QPalette palette = w->palette();
palette.setColor(QPalette::Active, QPalette::Text, c);
w->setPalette(palette);
}
BaseValidatingLineEdit::State BaseValidatingLineEdit::state() const
{
return m_bd->m_state;
}
bool BaseValidatingLineEdit::isValid() const
{
return m_bd->m_state == Valid;
}
QString BaseValidatingLineEdit::errorMessage() const
{
return m_bd->m_errorMessage;
}
void BaseValidatingLineEdit::slotChanged(const QString &t)
{
m_bd->m_errorMessage.clear();
// Are we displaying the initial text?
const bool isDisplayingInitialText = !m_bd->m_initialText.isEmpty() && t == m_bd->m_initialText;
const State newState = isDisplayingInitialText ?
DisplayingInitialText :
(validate(t, &m_bd->m_errorMessage) ? Valid : Invalid);
setToolTip(m_bd->m_errorMessage);
if (debug)
qDebug() << Q_FUNC_INFO << t << "State" << m_bd->m_state << "->" << newState << m_bd->m_errorMessage;
// Changed..figure out if valid changed. DisplayingInitialText is not valid,
// but should not show error color. Also trigger on the first change.
if (newState != m_bd->m_state || m_bd->m_firstChange) {
const bool validHasChanged = (m_bd->m_state == Valid) != (newState == Valid);
m_bd->m_state = newState;
m_bd->m_firstChange = false;
setTextColor(this, newState == Invalid ? m_bd->m_errorTextColor : m_bd->m_okTextColor);
if (validHasChanged) {
emit validChanged(newState == Valid);
emit validChanged();
}
}
}
void BaseValidatingLineEdit::slotReturnPressed()
{
if (isValid())
emit validReturnPressed();
}
void BaseValidatingLineEdit::triggerChanged()
{
slotChanged(text());
}
} // namespace Utils
/**
******************************************************************************
*
* @file basevalidatinglineedit.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef BASEVALIDATINGLINEEDIT_H
#define BASEVALIDATINGLINEEDIT_H
#include "utils_global.h"
#include <QtGui/QLineEdit>
namespace Utils {
struct BaseValidatingLineEditPrivate;
/**
* Base class for validating line edits that performs validation in a virtual
* validate() function to be implemented in derived classes.
* When invalid, the text color will turn red and a tooltip will
* contain the error message. This approach is less intrusive than a
* QValidator which will prevent the user from entering certain characters.
*
* The widget has a concept of an "initialText" which can be something like
* "<Enter name here>". This results in state 'DisplayingInitialText', which
* is not valid, but is not marked red.
*/
class QTCREATOR_UTILS_EXPORT BaseValidatingLineEdit : public QLineEdit
{
Q_OBJECT
Q_DISABLE_COPY(BaseValidatingLineEdit)
Q_PROPERTY(QString initialText READ initialText WRITE setInitialText DESIGNABLE true)
Q_PROPERTY(QColor errorColor READ errorColor WRITE setErrorColor DESIGNABLE true)
public:
enum State { Invalid, DisplayingInitialText, Valid };
explicit BaseValidatingLineEdit(QWidget *parent = 0);
virtual ~BaseValidatingLineEdit();
State state() const;
bool isValid() const;
QString errorMessage() const;
QString initialText() const;
void setInitialText(const QString &);
QColor errorColor() const;
void setErrorColor(const QColor &);
// Trigger an update (after changing settings)
void triggerChanged();
static QColor textColor(const QWidget *w);
static void setTextColor(QWidget *w, const QColor &c);
signals:
void validChanged();
void validChanged(bool validState);
void validReturnPressed();
protected:
virtual bool validate(const QString &value, QString *errorMessage) const = 0;
protected slots:
// Custom behaviour can be added here. The base implementation must
// be called.
virtual void slotReturnPressed();
virtual void slotChanged(const QString &t);
private:
BaseValidatingLineEditPrivate *m_bd;
};
} // namespace Utils
#endif // BASEVALIDATINGLINEEDIT_H
/**
******************************************************************************
*
* @file checkablemessagebox.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "checkablemessagebox.h"
#include "ui_checkablemessagebox.h"
#include <QtGui/QPushButton>
#include <QtCore/QDebug>
namespace Utils {
struct CheckableMessageBoxPrivate {
CheckableMessageBoxPrivate() : clickedButton(0) {}
Ui::CheckableMessageBox ui;
QAbstractButton *clickedButton;
};
CheckableMessageBox::CheckableMessageBox(QWidget *parent) :
QDialog(parent),
m_d(new CheckableMessageBoxPrivate)
{
setModal(true);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_d->ui.setupUi(this);
m_d->ui.pixmapLabel->setVisible(false);
connect(m_d->ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(m_d->ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(m_d->ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(slotClicked(QAbstractButton*)));
}
CheckableMessageBox::~CheckableMessageBox()
{
delete m_d;
}
void CheckableMessageBox::slotClicked(QAbstractButton *b)
{
m_d->clickedButton = b;
}
QAbstractButton *CheckableMessageBox::clickedButton() const
{
return m_d->clickedButton;
}
QDialogButtonBox::StandardButton CheckableMessageBox::clickedStandardButton() const
{
if (m_d->clickedButton)
return m_d->ui.buttonBox->standardButton(m_d->clickedButton);
return QDialogButtonBox::NoButton;
}
QString CheckableMessageBox::text() const
{
return m_d->ui.messageLabel->text();
}
void CheckableMessageBox::setText(const QString &t)
{
m_d->ui.messageLabel->setText(t);
}
QPixmap CheckableMessageBox::iconPixmap() const
{
if (const QPixmap *p = m_d->ui.pixmapLabel->pixmap())
return QPixmap(*p);
return QPixmap();
}
void CheckableMessageBox::setIconPixmap(const QPixmap &p)
{
m_d->ui.pixmapLabel->setPixmap(p);
m_d->ui.pixmapLabel->setVisible(!p.isNull());
}
bool CheckableMessageBox::isChecked() const
{
return m_d->ui.checkBox->isChecked();
}
void CheckableMessageBox::setChecked(bool s)
{
m_d->ui.checkBox->setChecked(s);
}
QString CheckableMessageBox::checkBoxText() const
{
return m_d->ui.checkBox->text();
}
void CheckableMessageBox::setCheckBoxText(const QString &t)
{
m_d->ui.checkBox->setText(t);
}
QDialogButtonBox::StandardButtons CheckableMessageBox::standardButtons() const
{
return m_d->ui.buttonBox->standardButtons();
}
void CheckableMessageBox::setStandardButtons(QDialogButtonBox::StandardButtons s)
{
m_d->ui.buttonBox->setStandardButtons(s);
}
QDialogButtonBox::StandardButton CheckableMessageBox::defaultButton() const
{
foreach (QAbstractButton *b, m_d->ui.buttonBox->buttons())
if (QPushButton *pb = qobject_cast<QPushButton *>(b))
if (pb->isDefault())
return m_d->ui.buttonBox->standardButton(pb);
return QDialogButtonBox::NoButton;
}
void CheckableMessageBox::setDefaultButton(QDialogButtonBox::StandardButton s)
{
if (QPushButton *b = m_d->ui.buttonBox->button(s)) {
b->setDefault(true);
b->setFocus();
}
}
QDialogButtonBox::StandardButton
CheckableMessageBox::question(QWidget *parent,
const QString &title,
const QString &question,
const QString &checkBoxText,
bool *checkBoxSetting,
QDialogButtonBox::StandardButtons buttons,
QDialogButtonBox::StandardButton defaultButton)
{
CheckableMessageBox mb(parent);
mb.setWindowTitle(title);
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
mb.setText(question);
mb.setCheckBoxText(checkBoxText);
mb.setChecked(*checkBoxSetting);
mb.setStandardButtons(buttons);
mb.setDefaultButton(defaultButton);
mb.exec();
*checkBoxSetting = mb.isChecked();
return mb.clickedStandardButton();
}
QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton db)
{
return static_cast<QMessageBox::StandardButton>(int(db));
}
} // namespace Utils
/**
******************************************************************************
*
* @file checkablemessagebox.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CHECKABLEMESSAGEBOX_H
#define CHECKABLEMESSAGEBOX_H