Commit 0b49edbb authored by ck's avatar ck
Browse files

Maemo: New project widget.

Most attributes have moved into the settings page.
parent 031acae3
......@@ -38,11 +38,14 @@
#include <QtCore/QSettings>
#include <algorithm>
namespace Qt4ProjectManager {
namespace Internal {
namespace {
const QLatin1String SettingsGroup("MaemoDeviceConfigs");
const QLatin1String IdCounterKey("IdCounter");
const QLatin1String ConfigListKey("ConfigList");
const QLatin1String NameKey("Name");
const QLatin1String TypeKey("Type");
......@@ -51,10 +54,27 @@ namespace {
const QLatin1String UserNameKey("Uname");
const QLatin1String PasswordKey("Password");
const QLatin1String TimeoutKey("Timeout");
const QLatin1String InternalIdKey("InternalId");
};
class DevConfIdMatcher
{
public:
DevConfIdMatcher(quint64 id) : m_id(id) {}
bool operator()(const MaemoDeviceConfigurations::DeviceConfig &devConfig)
{
return devConfig.internalId == m_id;
}
private:
const quint64 m_id;
};
MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QString &name)
: name(name), type(Physical), port(22), timeout(30)
: name(name),
type(Physical),
port(22),
timeout(30),
internalId(MaemoDeviceConfigurations::instance().m_nextId++)
{
}
......@@ -65,8 +85,22 @@ MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QSettings &settings)
port(settings.value(PortKey, 22).toInt()),
uname(settings.value(UserNameKey).toString()),
pwd(settings.value(PasswordKey).toString()),
timeout(settings.value(TimeoutKey, 30).toInt())
timeout(settings.value(TimeoutKey, 30).toInt()),
internalId(settings.value(InternalIdKey, MaemoDeviceConfigurations::instance().m_nextId).toInt())
{
if (internalId == MaemoDeviceConfigurations::instance().m_nextId)
++MaemoDeviceConfigurations::instance().m_nextId;
qDebug("%s: name = %s, id = %llu", Q_FUNC_INFO, qPrintable(name), internalId);
}
MaemoDeviceConfigurations::DeviceConfig::DeviceConfig()
: internalId(InvalidId)
{
}
bool MaemoDeviceConfigurations::DeviceConfig::isValid() const
{
return internalId != InvalidId;
}
void MaemoDeviceConfigurations::DeviceConfig::save(QSettings &settings) const
......@@ -78,24 +112,28 @@ void MaemoDeviceConfigurations::DeviceConfig::save(QSettings &settings) const
settings.setValue(UserNameKey, uname);
settings.setValue(PasswordKey, pwd);
settings.setValue(TimeoutKey, timeout);
settings.setValue(InternalIdKey, internalId);
}
void MaemoDeviceConfigurations::setDevConfigs(const QList<DeviceConfig> &devConfigs)
{
m_devConfigs = devConfigs;
save();
emit updated();
}
MaemoDeviceConfigurations &MaemoDeviceConfigurations::instance()
MaemoDeviceConfigurations &MaemoDeviceConfigurations::instance(QObject *parent)
{
static MaemoDeviceConfigurations configs;
return configs;
if (m_instance == 0)
m_instance = new MaemoDeviceConfigurations(parent);
return *m_instance;
}
void MaemoDeviceConfigurations::save()
{
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(SettingsGroup);
settings->setValue(IdCounterKey, m_nextId);
settings->beginWriteArray(ConfigListKey, m_devConfigs.count());
for (int i = 0; i < m_devConfigs.count(); ++i) {
settings->setArrayIndex(i);
......@@ -105,7 +143,8 @@ void MaemoDeviceConfigurations::save()
settings->endGroup();
}
MaemoDeviceConfigurations::MaemoDeviceConfigurations()
MaemoDeviceConfigurations::MaemoDeviceConfigurations(QObject *parent)
: QObject(parent)
{
load();
}
......@@ -114,6 +153,7 @@ MaemoDeviceConfigurations::MaemoDeviceConfigurations()
void MaemoDeviceConfigurations::load()
{
QSettings *settings = Core::ICore::instance()->settings();
m_nextId = settings->value(IdCounterKey, 1).toULongLong();
settings->beginGroup(SettingsGroup);
int count = settings->beginReadArray(ConfigListKey);
for (int i = 0; i < count; ++i) {
......@@ -124,5 +164,27 @@ void MaemoDeviceConfigurations::load()
settings->endGroup();
}
MaemoDeviceConfigurations::DeviceConfig MaemoDeviceConfigurations::find(const QString &name) const
{
qDebug("%s: Looking for name %s", Q_FUNC_INFO, qPrintable(name));
QList<DeviceConfig>::ConstIterator resultIt =
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
DevConfNameMatcher(name));
qDebug("Found: %d", resultIt != m_devConfigs.constEnd());
return resultIt == m_devConfigs.constEnd() ? DeviceConfig() : *resultIt;
}
MaemoDeviceConfigurations::DeviceConfig MaemoDeviceConfigurations::find(int id) const
{
qDebug("%s: Looking for id %d", Q_FUNC_INFO, id);
QList<DeviceConfig>::ConstIterator resultIt =
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
DevConfIdMatcher(id));
qDebug("Found: %d", resultIt != m_devConfigs.constEnd());
return resultIt == m_devConfigs.constEnd() ? DeviceConfig() : *resultIt;
}
MaemoDeviceConfigurations *MaemoDeviceConfigurations::m_instance = 0;
} // namespace Internal
} // namespace Qt4ProjectManager
......@@ -36,6 +36,7 @@
#define MAEMODEVICECONFIGURATIONS_H
#include <QtCore/QList>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QtGlobal>
......@@ -46,16 +47,20 @@ QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeviceConfigurations
class MaemoDeviceConfigurations : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(MaemoDeviceConfigurations)
public:
class DeviceConfig
{
public:
enum DeviceType { Physical, Simulator };
DeviceConfig();
DeviceConfig(const QString &name);
DeviceConfig(const QSettings &settings);
void save(QSettings &settings) const;
bool isValid() const;
QString name;
DeviceType type;
QString host;
......@@ -63,12 +68,16 @@ public:
QString uname;
QString pwd;
int timeout;
quint64 internalId;
private:
static const quint64 InvalidId = 0;
};
class DevConfMatcher
class DevConfNameMatcher
{
public:
DevConfMatcher(const QString &name) : m_name(name) {}
DevConfNameMatcher(const QString &name) : m_name(name) {}
bool operator()(const MaemoDeviceConfigurations::DeviceConfig &devConfig)
{
return devConfig.name == m_name;
......@@ -77,18 +86,24 @@ public:
const QString m_name;
};
static MaemoDeviceConfigurations &instance();
static MaemoDeviceConfigurations &instance(QObject *parent = 0);
QList<DeviceConfig> devConfigs() const { return m_devConfigs; }
void setDevConfigs(const QList<DeviceConfig> &devConfigs);
DeviceConfig find(const QString &name) const;
DeviceConfig find(int id) const;
signals:
void updated();
private:
MaemoDeviceConfigurations();
MaemoDeviceConfigurations(const MaemoDeviceConfigurations &);
MaemoDeviceConfigurations& operator=(const MaemoDeviceConfigurations &);
MaemoDeviceConfigurations(QObject *parent);
void load();
void save();
static MaemoDeviceConfigurations *m_instance;
QList<DeviceConfig> m_devConfigs;
quint64 m_nextId;
friend class MaemoDeviceConfigurations::DeviceConfig;
};
} // namespace Internal
......
......@@ -29,6 +29,7 @@
#include "maemomanager.h"
#include "maemodeviceconfigurations.h"
#include "maemosettingspage.h"
#include "maemotoolchain.h"
#include "maemorunconfiguration.h"
......@@ -68,6 +69,7 @@ MaemoManager::MaemoManager()
ExtensionSystem::PluginManager::instance()->addObject(m_runControlFactory);
ExtensionSystem::PluginManager::instance()->addObject(m_runConfigurationFactory);
ExtensionSystem::PluginManager::instance()->addObject(m_settingsPage);
MaemoDeviceConfigurations::instance(this);
}
MaemoManager::~MaemoManager()
......
......@@ -30,6 +30,8 @@
#ifndef MAEMORUNCONFIGURATION_H
#define MAEMORUNCONFIGURATION_H
#include "maemodeviceconfigurations.h"
#include <QtCore/QDateTime>
#include <QtGui/QWidget>
......@@ -87,28 +89,19 @@ public:
const QString sysRoot() const;
const QStringList arguments() const;
void setArguments(const QStringList &args);
void setDeviceConfig(const MaemoDeviceConfigurations::DeviceConfig &deviceConfig);
MaemoDeviceConfigurations::DeviceConfig deviceConfig() const;
QString simulator() const;
QString simulatorArgs() const;
QString simulatorPath() const;
QString visibleSimulatorParameter() const;
bool remoteHostIsSimulator() const { return m_remoteHostIsSimulator; }
const QString remoteHostName() const;
const QString remoteUserName() const;
int remotePort() const;
const QString remoteDir() const;
const QString sshCmd() const;
const QString scpCmd() const;
const QString gdbCmd() const;
const QString dumperLib() const;
void setRemoteHostIsSimulator(bool isSimulator);
void setRemoteHostName(const QString &hostName);
void setRemoteUserName(const QString &userName);
void setRemotePort(int port);
bool isQemuRunning() const;
#if USE_SSL_PASSWORD
......@@ -121,11 +114,13 @@ public:
#endif
signals:
void deviceConfigurationsUpdated();
void targetInformationChanged();
void cachedSimulatorInformationChanged();
void qemuProcessStatus(bool running);
private slots:
void updateDeviceConfigurations();
void invalidateCachedTargetInformation();
void setUserSimulatorPath(const QString &path);
......@@ -145,7 +140,6 @@ private:
bool fileNeedsDeployment(const QString &path, const QDateTime &lastDeployed) const;
private:
// Keys for saving/loading attributes.
QString m_executable;
QString m_proFilePath;
bool m_cachedTargetInformationValid;
......@@ -161,18 +155,8 @@ private:
QString m_gdbPath;
// Information about the remote host.
bool m_remoteHostIsSimulator;
QStringList m_argumentsSim;
QString m_remoteHostNameSim;
QString m_remoteUserNameSim;
int m_remotePortSim;
QStringList m_argumentsDevice;
QString m_remoteHostNameDevice;
QString m_remoteUserNameDevice;
int m_remotePortDevice;
MaemoDeviceConfigurations::DeviceConfig m_devConfig;
QStringList m_arguments;
QDateTime m_lastDeployed;
QDateTime m_debuggingHelpersLastDeployed;
......
......@@ -60,7 +60,7 @@ bool configNameExists(const QList<MaemoDeviceConfigurations::DeviceConfig> &devC
const QString &name)
{
return std::find_if(devConfs.constBegin(), devConfs.constEnd(),
MaemoDeviceConfigurations::DevConfMatcher(name)) != devConfs.constEnd();
MaemoDeviceConfigurations::DevConfNameMatcher(name)) != devConfs.constEnd();
}
class PortAndTimeoutValidator : public QIntValidator
......@@ -193,7 +193,7 @@ void MaemoSettingsPage::apply()
void MaemoSettingsPage::finish()
{
apply();
// apply();
}
MaemoSettingsWidget::MaemoSettingsWidget(QWidget *parent)
......@@ -262,9 +262,9 @@ void MaemoSettingsWidget::display(const MaemoDeviceConfigurations::DeviceConfig
{
m_ui->nameLineEdit->setText(devConfig.name);
if (devConfig.type == MaemoDeviceConfigurations::DeviceConfig::Physical)
m_ui->deviceButton->setEnabled(true);
m_ui->deviceButton->setChecked(true);
else
m_ui->simulatorButton->setEnabled(true);
m_ui->simulatorButton->setChecked(true);
m_ui->hostLineEdit->setText(devConfig.host);
m_ui->portLineEdit->setText(QString::number(devConfig.port));
m_ui->timeoutLineEdit->setText(QString::number(devConfig.timeout));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment