mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-13 13:55:50 +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:
@ -59,6 +59,8 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString filePath)
|
||||
m_manager = new QNetworkAccessManager(nullptr);
|
||||
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||
|
||||
connect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest()));
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +70,7 @@ ExtQuotes::~ExtQuotes()
|
||||
|
||||
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||
disconnect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest()));
|
||||
|
||||
m_manager->deleteLater();
|
||||
delete ui;
|
||||
@ -125,15 +128,11 @@ void ExtQuotes::readConfiguration()
|
||||
|
||||
QVariantHash ExtQuotes::run()
|
||||
{
|
||||
if ((!isActive()) || (m_isRunning))
|
||||
if (!canRun())
|
||||
return m_values;
|
||||
|
||||
if (m_times == 1) {
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
if (m_times == 1)
|
||||
sendRequest();
|
||||
|
||||
// update value
|
||||
if (m_times >= interval())
|
||||
@ -245,6 +244,20 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::sendRequest()
|
||||
{
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
bool ExtQuotes::canRun() const
|
||||
{
|
||||
return ((isActive()) && (!m_isRunning) && (socket().isEmpty()));
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::initUrl()
|
||||
{
|
||||
// init query
|
||||
|
Reference in New Issue
Block a user