1
0
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:
dubslow 2014-10-16 04:47:58 -05:00
parent 63671ae3ff
commit e3cf2cac20
4 changed files with 69 additions and 8 deletions

View File

@ -115,7 +115,8 @@ void Settings::load()
useProxy = s.value("useProxy", false).toBool();
proxyAddr = s.value("proxyAddr", "").toString();
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.beginGroup("Widgets");
@ -221,6 +222,7 @@ void Settings::save(QString path)
s.setValue("proxyAddr", proxyAddr);
s.setValue("proxyPort", proxyPort);
s.setValue("currentProfile", currentProfile);
s.setValue("autoAwayTime", autoAwayTime);
s.endGroup();
s.beginGroup("Widgets");
@ -442,6 +444,18 @@ void Settings::setEncryptLogs(bool 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)
{
widgetSettings[uniqueName] = data;

View File

@ -76,6 +76,9 @@ public:
bool getEncryptLogs() const;
void setEncryptLogs(bool newValue);
int getAutoAwayTime() const;
void setAutoAwayTime(int newValue);
QPixmap getSavedAvatar(const QString& ownerId);
void saveAvatar(QPixmap& pic, const QString& ownerId);
@ -184,6 +187,8 @@ private:
bool enableLogging;
bool encryptLogs;
int autoAwayTime;
QHash<QString, QByteArray> widgetSettings;
// GUI

View File

@ -42,6 +42,7 @@
#include <QThread>
#include <QFileDialog>
#include <QInputDialog>
#include <QTimer>
#include <tox/tox.h>
Widget *Widget::instance{nullptr};
@ -107,6 +108,11 @@ Widget::Widget(QWidget *parent)
// Disable some widgets until we're connected to the DHT
ui->statusButton->setEnabled(false);
idleTimer = new QTimer();
int mins = Settings::getInstance().getAutoAwayTime();
if (mins > 0)
idleTimer->start(mins * 1000*60);
qRegisterMetaType<Status>("Status");
qRegisterMetaType<vpx_image>("vpx_image");
qRegisterMetaType<uint8_t>("uint8_t");
@ -169,6 +175,7 @@ Widget::Widget(QWidget *parent)
connect(setStatusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
connect(setStatusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
connect(&friendForm, SIGNAL(friendRequested(QString,QString)), this, SIGNAL(friendRequested(QString,QString)));
connect(idleTimer, &QTimer::timeout, this, &Widget::onUserAway);
coreThread->start();
@ -782,18 +789,49 @@ bool Widget::isFriendWidgetCurActiveWidget(Friend* f)
bool Widget::event(QEvent * e)
{
if (e->type() == QEvent::WindowActivate)
{
if (activeChatroomWidget != nullptr)
{
activeChatroomWidget->resetEventFlags();
activeChatroomWidget->updateStatusLight();
}
switch(e->type()) {
case QEvent::WindowActivate:
if (activeChatroomWidget != nullptr)
{
activeChatroomWidget->resetEventFlags();
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);
}
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()
{
core->setStatus(Status::Online);

View File

@ -40,6 +40,7 @@ class Core;
class Camera;
class FriendListWidget;
class MaskablePixmapWidget;
class QTimer;
class Widget : public QMainWindow
{
@ -109,6 +110,7 @@ private slots:
void onGroupSendResult(int groupId, const QString& message, int result);
void playRingtone();
void onIconClick();
void onUserAway();
private:
void hideMainForms();
@ -132,6 +134,8 @@ private:
FriendListWidget* contactListWidget;
MaskablePixmapWidget* profilePicture;
bool notify(QObject *receiver, QEvent *event);
bool autoAwayActive = false;
QTimer* idleTimer;
};
#endif // WIDGET_H