Permalink
Browse files

Disable target buttons when communication is active. Prevents spammin…

…g the buttons.
  • Loading branch information...
1 parent 16275ec commit 429ab806194a8648e242abc7e58f918d7feaa886 @bmcdorman bmcdorman committed Jan 24, 2013
@@ -34,6 +34,8 @@ namespace Kiss
CommunicationManager();
~CommunicationManager();
+ bool isIdle() const;
+
quint64 admit(const CommunicationEntryPtr &entry);
signals:
@@ -51,7 +53,7 @@ namespace Kiss
quint64 m_id;
QList<CommunicationEntryPtr> m_running;
CommunicationQueue m_queue;
- QMutex m_queueMutex;
+ mutable QMutex m_queueMutex;
};
}
}
@@ -13,7 +13,7 @@ namespace Kiss
{
public:
Response();
- Response(quint64 id, const QString &type, const QVariant &data);
+ Response(quint64 id, const QString &type, const QVariant &data = QVariant());
const quint64 &id() const;
const QString &type() const;
@@ -43,9 +43,6 @@ namespace Kiss
static QString menuName();
- public slots:
- void update();
-
protected:
void activated();
void deactivated();
@@ -42,6 +42,9 @@ namespace Kiss
static QString menuName();
+ public slots:
+ void update();
+
protected:
void activated();
void deactivated();
View
@@ -23,8 +23,9 @@ void ActivatableObject::activated()
qWarning() << "?";
return;
}
+ qDebug() << "Activated" << us->metaObject()->className() << "on" << meta->className();
m_connected = connect;
-
+
QMetaObject::invokeMethod(us, "update");
QObject::connect(m_connected, SIGNAL(updateActivatable()), us, SLOT(update()));
}
@@ -34,6 +34,14 @@ CommunicationManager::~CommunicationManager()
{
}
+bool CommunicationManager::isIdle() const
+{
+ m_queueMutex.lock();
+ bool ret = m_running.isEmpty() && m_queue.isEmpty();
+ m_queueMutex.unlock();
+ return ret;
+}
+
quint64 CommunicationManager::admit(const CommunicationEntryPtr &entry)
{
entry->setId(++m_id);
@@ -79,14 +79,6 @@ void SourceFileMenu::deactivated()
menuManager()->removeActivation(this);
}
-void SourceFileMenu::update()
-{
- Widget::SourceFile* sourceFile = dynamic_cast<Widget::SourceFile*>(active());
- if(!sourceFile) return;
- // breakpoint->rawAction->setEnabled(sourceFile->breakpointOnLine(sourceFile->currentLine()));
- // convertToProject->rawAction->setEnabled(!sourceFile->hasProject());
-}
-
QString SourceFileMenu::menuName()
{
return "Source";
View
@@ -24,6 +24,7 @@
#include "documentation.hpp"
#include "main_window.hpp"
#include "interface.hpp"
+#include "communication_manager.hpp"
using namespace Kiss::Menu;
@@ -42,6 +43,10 @@ TargetMenu::TargetMenu()
m_targetMenu->children.append(node(activeAction("computer", "Change Target", QKeySequence("Alt+T"), this, "changeTarget")));
m_targetMenu->children.append(Node::separator());
+ compileNode->hideOnDisable = false;
+ downloadNode->hideOnDisable = false;
+ runNode->hideOnDisable = false;
+
m_actions.append(m_targetMenu);
}
@@ -53,13 +58,24 @@ void TargetMenu::refresh()
void TargetMenu::activated()
{
+ ActivatableObject::activated();
menuManager()->addActivation(this);
refresh();
}
void TargetMenu::deactivated()
{
menuManager()->removeActivation(this);
+ ActivatableObject::deactivated();
+}
+
+void TargetMenu::update()
+{
+ const bool enabled = Target::CommunicationManager::ref().isIdle();
+ compileNode->rawAction->setEnabled(enabled);
+ downloadNode->rawAction->setEnabled(enabled);
+ runNode->rawAction->setEnabled(enabled);
+ refresh();
}
QString TargetMenu::menuName()
View
@@ -37,6 +37,7 @@
#include "log.hpp"
#include "target_dialog.hpp"
#include "interface_manager.hpp"
+#include "communication_manager.hpp"
#include "resource_helper.hpp"
#include "interface.hpp"
#include "output_helper.hpp"
@@ -98,6 +99,9 @@ SourceFile::SourceFile(MainWindow *parent)
connect(ui_editor, SIGNAL(textChanged()), this, SLOT(updateMargins()));
connect(ui_editor, SIGNAL(modificationChanged(bool)), this, SLOT(sourceModified(bool)));
+ connect(&Target::CommunicationManager::ref(), SIGNAL(admitted(CommunicationEntryPtr)), SIGNAL(updateActivatable()));
+ connect(&Target::CommunicationManager::ref(), SIGNAL(queueFinished()), SIGNAL(updateActivatable()));
+
ui_find->hide();
refreshSettings();
@@ -122,6 +126,8 @@ void SourceFile::activate()
mainWindow()->activateMenuable(Menu::SourceFileMenu::menuName(), this);
mainWindow()->activateMenuable(Menu::TargetMenu::menuName(), this);
+
+ emit updateActivatable();
}
bool SourceFile::beginSetup()

0 comments on commit 429ab80

Please sign in to comment.