RemoteLinux: Block cloning of device configs when the dialog is open.

Change-Id: Ifc8bc835765ac8b92efbccf57e6d0d7a01998a58
Reviewed-on: http://codereview.qt-project.org/6322
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
This commit is contained in:
Christian Kandeler
2011-10-10 13:36:22 +02:00
parent a7f78991c9
commit 3fb9321bd8
3 changed files with 29 additions and 0 deletions

View File

@@ -52,6 +52,8 @@ const QLatin1String IdCounterKey("IdCounter");
const QLatin1String ConfigListKey("ConfigList");
const QLatin1String DefaultKeyFilePathKey("DefaultKeyFile");
bool cloningBlocked = false;
class DevConfNameMatcher
{
public:
@@ -103,6 +105,8 @@ void LinuxDeviceConfigurations::replaceInstance(const LinuxDeviceConfigurations
LinuxDeviceConfigurations *LinuxDeviceConfigurations::cloneInstance()
{
if (cloningBlocked)
return 0;
LinuxDeviceConfigurations * const other = new LinuxDeviceConfigurations(0);
copy(LinuxDeviceConfigurationsPrivate::instance, other, true);
return other;
@@ -256,6 +260,18 @@ LinuxDeviceConfigurations::LinuxDeviceConfigurations(QObject *parent)
{
}
void LinuxDeviceConfigurations::blockCloning()
{
QTC_ASSERT(!cloningBlocked, return);
cloningBlocked = true;
}
void LinuxDeviceConfigurations::unblockCloning()
{
QTC_ASSERT(cloningBlocked, return);
cloningBlocked = false;
}
LinuxDeviceConfigurations::~LinuxDeviceConfigurations()
{
delete d;

View File

@@ -42,16 +42,24 @@ QT_FORWARD_DECLARE_CLASS(QString)
namespace RemoteLinux {
namespace Internal {
class LinuxDeviceConfigurationsPrivate;
class LinuxDeviceConfigurationsSettingsWidget;
} // namespace Internal
class REMOTELINUX_EXPORT LinuxDeviceConfigurations : public QAbstractListModel
{
Q_OBJECT
friend class Internal::LinuxDeviceConfigurationsSettingsWidget;
public:
~LinuxDeviceConfigurations();
static LinuxDeviceConfigurations *instance(QObject *parent = 0);
// If you want to edit the list of device configurations programatically
// (e.g. when doing device auto-detection), call cloneInstance() to get a copy,
// do the changes there and then call replaceInstance() to write them back.
// Callers must be prepared to deal with cloneInstance() temporarily returning null,
// which happens if the settings dialog is currently open.
// All other callers are required to do the clone/replace operation synchronously!
static void replaceInstance(const LinuxDeviceConfigurations *other);
static LinuxDeviceConfigurations *cloneInstance();
@@ -82,6 +90,9 @@ signals:
private:
LinuxDeviceConfigurations(QObject *parent);
static void blockCloning();
static void unblockCloning();
void load();
void save();
static void copy(const LinuxDeviceConfigurations *source,

View File

@@ -104,6 +104,7 @@ LinuxDeviceConfigurationsSettingsWidget::LinuxDeviceConfigurationsSettingsWidget
m_saveSettingsRequested(false),
m_additionalActionsMapper(new QSignalMapper(this))
{
LinuxDeviceConfigurations::blockCloning();
initGui();
connect(m_additionalActionsMapper, SIGNAL(mapped(QString)),
SLOT(handleAdditionalActionRequest(QString)));
@@ -116,6 +117,7 @@ LinuxDeviceConfigurationsSettingsWidget::~LinuxDeviceConfigurationsSettingsWidge
currentIndex());
LinuxDeviceConfigurations::replaceInstance(m_devConfigs.data());
}
LinuxDeviceConfigurations::unblockCloning();
delete m_ui;
}