mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-17 23:59:58 +00:00
add socket activation for extensions (#118)
Option `X-AW-Socket` is used. Any message received by this socket will trigger extension update. If the option is set, `X-AW-Interval` will be ignored
This commit is contained in:
@ -18,6 +18,7 @@
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QLocalServer>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QTime>
|
||||
@ -41,6 +42,12 @@ AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath)
|
||||
AbstractExtItem::~AbstractExtItem()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (m_socket) {
|
||||
m_socket->close();
|
||||
m_socket->removeServer(socket());
|
||||
delete m_socket;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -65,6 +72,7 @@ void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
|
||||
_other->setComment(comment());
|
||||
_other->setInterval(interval());
|
||||
_other->setName(name());
|
||||
_other->setSocket(socket());
|
||||
}
|
||||
|
||||
|
||||
@ -125,6 +133,12 @@ int AbstractExtItem::number() const
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::socket() const
|
||||
{
|
||||
return m_socketFile;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::tag(const QString _type) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Tag type" << _type;
|
||||
@ -196,6 +210,44 @@ void AbstractExtItem::setNumber(int _number)
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setSocket(const QString _socket)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Socket" << _socket;
|
||||
// remove old socket first
|
||||
deinitSocket();
|
||||
|
||||
m_socketFile = _socket;
|
||||
if (socket().isEmpty())
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::deinitSocket()
|
||||
{
|
||||
if (!m_socket)
|
||||
return;
|
||||
|
||||
m_socket->close();
|
||||
m_socket->removeServer(socket());
|
||||
delete m_socket;
|
||||
disconnect(m_socket, SIGNAL(newConnection()), this,
|
||||
SLOT(newConnectionReceived()));
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::initSocket()
|
||||
{
|
||||
// remove old socket first
|
||||
deinitSocket();
|
||||
|
||||
m_socket = new QLocalServer(this);
|
||||
bool listening = m_socket->listen(socket());
|
||||
qCInfo(LOG_LIB) << "Server listening on" << socket() << listening;
|
||||
connect(m_socket, SIGNAL(newConnection()), this,
|
||||
SLOT(newConnectionReceived()));
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::readConfiguration()
|
||||
{
|
||||
QSettings settings(m_fileName, QSettings::IniFormat);
|
||||
@ -210,6 +262,7 @@ void AbstractExtItem::readConfiguration()
|
||||
== QString("true"));
|
||||
setInterval(settings.value(QString("X-AW-Interval"), interval()).toInt());
|
||||
setNumber(settings.value(QString("X-AW-Number"), number()).toInt());
|
||||
setSocket(settings.value(QString("X-AW-Socket"), socket()).toString());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
@ -236,7 +289,14 @@ void AbstractExtItem::writeConfiguration() const
|
||||
settings.setValue(QString("X-AW-Active"), QVariant(isActive()).toString());
|
||||
settings.setValue(QString("X-AW-Interval"), interval());
|
||||
settings.setValue(QString("X-AW-Number"), number());
|
||||
settings.setValue(QString("X-AW-Socket"), socket());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::newConnectionReceived()
|
||||
{
|
||||
emit(socketActivated());
|
||||
}
|
||||
|
Reference in New Issue
Block a user