mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
auto away; needs UI
This commit is contained in:
parent
63671ae3ff
commit
e3cf2cac20
|
@ -115,7 +115,8 @@ void Settings::load()
|
||||||
useProxy = s.value("useProxy", false).toBool();
|
useProxy = s.value("useProxy", false).toBool();
|
||||||
proxyAddr = s.value("proxyAddr", "").toString();
|
proxyAddr = s.value("proxyAddr", "").toString();
|
||||||
proxyPort = s.value("proxyPort", 0).toInt();
|
proxyPort = s.value("proxyPort", 0).toInt();
|
||||||
currentProfile = s.value("currentProfile", "").toString();
|
currentProfile = s.value("currentProfile", "").toString();
|
||||||
|
autoAwayTime = s.value("autoAwayTime", 10).toInt();
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
s.beginGroup("Widgets");
|
s.beginGroup("Widgets");
|
||||||
|
@ -221,6 +222,7 @@ void Settings::save(QString path)
|
||||||
s.setValue("proxyAddr", proxyAddr);
|
s.setValue("proxyAddr", proxyAddr);
|
||||||
s.setValue("proxyPort", proxyPort);
|
s.setValue("proxyPort", proxyPort);
|
||||||
s.setValue("currentProfile", currentProfile);
|
s.setValue("currentProfile", currentProfile);
|
||||||
|
s.setValue("autoAwayTime", autoAwayTime);
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
s.beginGroup("Widgets");
|
s.beginGroup("Widgets");
|
||||||
|
@ -442,6 +444,18 @@ void Settings::setEncryptLogs(bool newValue)
|
||||||
encryptLogs = newValue;
|
encryptLogs = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Settings::getAutoAwayTime() const
|
||||||
|
{
|
||||||
|
return autoAwayTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setAutoAwayTime(int newValue)
|
||||||
|
{
|
||||||
|
if (newValue < 0)
|
||||||
|
newValue = 10;
|
||||||
|
autoAwayTime = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
|
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
|
||||||
{
|
{
|
||||||
widgetSettings[uniqueName] = data;
|
widgetSettings[uniqueName] = data;
|
||||||
|
|
|
@ -76,6 +76,9 @@ public:
|
||||||
bool getEncryptLogs() const;
|
bool getEncryptLogs() const;
|
||||||
void setEncryptLogs(bool newValue);
|
void setEncryptLogs(bool newValue);
|
||||||
|
|
||||||
|
int getAutoAwayTime() const;
|
||||||
|
void setAutoAwayTime(int newValue);
|
||||||
|
|
||||||
QPixmap getSavedAvatar(const QString& ownerId);
|
QPixmap getSavedAvatar(const QString& ownerId);
|
||||||
void saveAvatar(QPixmap& pic, const QString& ownerId);
|
void saveAvatar(QPixmap& pic, const QString& ownerId);
|
||||||
|
|
||||||
|
@ -184,6 +187,8 @@ private:
|
||||||
bool enableLogging;
|
bool enableLogging;
|
||||||
bool encryptLogs;
|
bool encryptLogs;
|
||||||
|
|
||||||
|
int autoAwayTime;
|
||||||
|
|
||||||
QHash<QString, QByteArray> widgetSettings;
|
QHash<QString, QByteArray> widgetSettings;
|
||||||
|
|
||||||
// GUI
|
// GUI
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QTimer>
|
||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
|
|
||||||
Widget *Widget::instance{nullptr};
|
Widget *Widget::instance{nullptr};
|
||||||
|
@ -107,6 +108,11 @@ Widget::Widget(QWidget *parent)
|
||||||
// Disable some widgets until we're connected to the DHT
|
// Disable some widgets until we're connected to the DHT
|
||||||
ui->statusButton->setEnabled(false);
|
ui->statusButton->setEnabled(false);
|
||||||
|
|
||||||
|
idleTimer = new QTimer();
|
||||||
|
int mins = Settings::getInstance().getAutoAwayTime();
|
||||||
|
if (mins > 0)
|
||||||
|
idleTimer->start(mins * 1000*60);
|
||||||
|
|
||||||
qRegisterMetaType<Status>("Status");
|
qRegisterMetaType<Status>("Status");
|
||||||
qRegisterMetaType<vpx_image>("vpx_image");
|
qRegisterMetaType<vpx_image>("vpx_image");
|
||||||
qRegisterMetaType<uint8_t>("uint8_t");
|
qRegisterMetaType<uint8_t>("uint8_t");
|
||||||
|
@ -169,6 +175,7 @@ Widget::Widget(QWidget *parent)
|
||||||
connect(setStatusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
|
connect(setStatusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
|
||||||
connect(setStatusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
|
connect(setStatusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
|
||||||
connect(&friendForm, SIGNAL(friendRequested(QString,QString)), this, SIGNAL(friendRequested(QString,QString)));
|
connect(&friendForm, SIGNAL(friendRequested(QString,QString)), this, SIGNAL(friendRequested(QString,QString)));
|
||||||
|
connect(idleTimer, &QTimer::timeout, this, &Widget::onUserAway);
|
||||||
|
|
||||||
coreThread->start();
|
coreThread->start();
|
||||||
|
|
||||||
|
@ -782,18 +789,49 @@ bool Widget::isFriendWidgetCurActiveWidget(Friend* f)
|
||||||
|
|
||||||
bool Widget::event(QEvent * e)
|
bool Widget::event(QEvent * e)
|
||||||
{
|
{
|
||||||
if (e->type() == QEvent::WindowActivate)
|
switch(e->type()) {
|
||||||
{
|
case QEvent::WindowActivate:
|
||||||
if (activeChatroomWidget != nullptr)
|
if (activeChatroomWidget != nullptr)
|
||||||
{
|
{
|
||||||
activeChatroomWidget->resetEventFlags();
|
activeChatroomWidget->resetEventFlags();
|
||||||
activeChatroomWidget->updateStatusLight();
|
activeChatroomWidget->updateStatusLight();
|
||||||
}
|
}
|
||||||
|
// http://qt-project.org/faq/answer/how_can_i_detect_a_period_of_no_user_interaction
|
||||||
|
// Detecting global inactivity, like Skype, is possible but not via Qt:
|
||||||
|
// http://stackoverflow.com/a/21905027/1497645
|
||||||
|
case QEvent::MouseButtonPress:
|
||||||
|
case QEvent::MouseButtonRelease:
|
||||||
|
case QEvent::Wheel:
|
||||||
|
case QEvent::KeyPress:
|
||||||
|
case QEvent::KeyRelease:
|
||||||
|
if (autoAwayActive)
|
||||||
|
{
|
||||||
|
qDebug() << "Widget: auto away deactivated";
|
||||||
|
autoAwayActive = false;
|
||||||
|
emit statusSet(Status::Online);
|
||||||
|
int mins = Settings::getInstance().getAutoAwayTime();
|
||||||
|
if (mins > 0)
|
||||||
|
idleTimer->start(mins * 1000*60);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QWidget::event(e);
|
return QWidget::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::onUserAway()
|
||||||
|
{
|
||||||
|
if (Settings::getInstance().getAutoAwayTime() > 0
|
||||||
|
&& ui->statusButton->property("status").toString() == "online") // leave user-set statuses in place
|
||||||
|
{
|
||||||
|
qDebug() << "Widget: auto away activated";
|
||||||
|
emit statusSet(Status::Away);
|
||||||
|
autoAwayActive = true;
|
||||||
|
}
|
||||||
|
idleTimer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::setStatusOnline()
|
void Widget::setStatusOnline()
|
||||||
{
|
{
|
||||||
core->setStatus(Status::Online);
|
core->setStatus(Status::Online);
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Core;
|
||||||
class Camera;
|
class Camera;
|
||||||
class FriendListWidget;
|
class FriendListWidget;
|
||||||
class MaskablePixmapWidget;
|
class MaskablePixmapWidget;
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
class Widget : public QMainWindow
|
class Widget : public QMainWindow
|
||||||
{
|
{
|
||||||
|
@ -109,6 +110,7 @@ private slots:
|
||||||
void onGroupSendResult(int groupId, const QString& message, int result);
|
void onGroupSendResult(int groupId, const QString& message, int result);
|
||||||
void playRingtone();
|
void playRingtone();
|
||||||
void onIconClick();
|
void onIconClick();
|
||||||
|
void onUserAway();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void hideMainForms();
|
void hideMainForms();
|
||||||
|
@ -132,6 +134,8 @@ private:
|
||||||
FriendListWidget* contactListWidget;
|
FriendListWidget* contactListWidget;
|
||||||
MaskablePixmapWidget* profilePicture;
|
MaskablePixmapWidget* profilePicture;
|
||||||
bool notify(QObject *receiver, QEvent *event);
|
bool notify(QObject *receiver, QEvent *event);
|
||||||
|
bool autoAwayActive = false;
|
||||||
|
QTimer* idleTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WIDGET_H
|
#endif // WIDGET_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user