mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Global auto-away
This commit is contained in:
parent
a560909b6d
commit
99fa5d9e19
10
qtox.pro
10
qtox.pro
|
@ -78,10 +78,10 @@ win32 {
|
|||
INSTALLS += target
|
||||
LIBS += -L$$PWD/libs/lib/ -lopus -lvpx -lopenal -Wl,-Bstatic -ltoxcore -ltoxav -ltoxencryptsave -ltoxdns -lsodium -lopencv_highgui -lopencv_imgproc -lopencv_core -lz -Wl,-Bdynamic
|
||||
LIBS += -Wl,-Bstatic -ljpeg -ltiff -lpng -ljasper -lIlmImf -lIlmThread -lIex -ldc1394 -lraw1394 -lHalf -lz -llzma -ljbig
|
||||
LIBS += -Wl,-Bdynamic -lv4l1 -lv4l2 -lavformat -lavcodec -lavutil -lswscale -lusb-1.0
|
||||
LIBS += -Wl,-Bdynamic -lv4l1 -lv4l2 -lavformat -lavcodec -lavutil -lswscale -lusb-1.0 -lX11 -lXss
|
||||
|
||||
} else {
|
||||
LIBS += -L$$PWD/libs/lib/ -ltoxcore -ltoxav -ltoxencryptsave -ltoxdns -lvpx -lsodium -lopenal -lopencv_core -lopencv_highgui -lopencv_imgproc
|
||||
LIBS += -L$$PWD/libs/lib/ -ltoxcore -ltoxav -ltoxencryptsave -ltoxdns -lvpx -lsodium -lopenal -lopencv_core -lopencv_highgui -lopencv_imgproc -lX11 -lXss
|
||||
}
|
||||
|
||||
contains(JENKINS, YES) {
|
||||
|
@ -155,7 +155,8 @@ HEADERS += src/widget/form/addfriendform.h \
|
|||
src/autoupdate.h \
|
||||
src/misc/serialize.h \
|
||||
src/widget/form/settings/advancedform.h \
|
||||
src/audio.h
|
||||
src/audio.h \
|
||||
src/platform.h
|
||||
|
||||
SOURCES += \
|
||||
src/widget/form/addfriendform.cpp \
|
||||
|
@ -222,4 +223,5 @@ SOURCES += \
|
|||
src/autoupdate.cpp \
|
||||
src/misc/serialize.cpp \
|
||||
src/widget/form/settings/advancedform.cpp \
|
||||
src/audio.cpp
|
||||
src/audio.cpp \
|
||||
src/platform.cpp
|
||||
|
|
67
src/platform.cpp
Normal file
67
src/platform.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "platform.h"
|
||||
#include <QDebug>
|
||||
#if defined(Q_OS_WIN)
|
||||
#include <Windows.h>
|
||||
#elif defined(Q_OS_DARWIN) && defined(HAVE_IOKIT)
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#else // Q_OS_UNIX
|
||||
#include <X11/extensions/scrnsaver.h>
|
||||
#endif
|
||||
|
||||
u_int32_t Platform::getIdleTime()
|
||||
{
|
||||
// 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
|
||||
// https://hg.pidgin.im/pidgin/main/file/13e4ae613a6a/pidgin/gtkidle.c
|
||||
u_int32_t idleTime = 0;
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
LASTINPUTINFO info = { 0 };
|
||||
if(GetLastInputInfo(&info))
|
||||
idleTime = info.dwTime / 1000;
|
||||
#elif defined(Q_OS_DARWIN) && defined(HAVE_IOKIT)
|
||||
static io_service_t service = NULL;
|
||||
CFTypeRef property;
|
||||
u_int64_t idleTime_ns = 0;
|
||||
|
||||
if (!service)
|
||||
{
|
||||
mach_port_t master;
|
||||
IOMasterPort(MACH_PORT_NULL, &master);
|
||||
service = IOServiceGetMatchingService(master, IOServiceMatching("IOHIDSystem"));
|
||||
}
|
||||
|
||||
property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
|
||||
CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idleTime_ns);
|
||||
CFRelease(property);
|
||||
|
||||
idleTime = idleTime_ns / 1000000;
|
||||
#else // Q_OS_UNIX
|
||||
Display *display = XOpenDisplay(NULL);
|
||||
if(!display)
|
||||
{
|
||||
qDebug() << "XOpenDisplay(NULL) failed";
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t x11event = 0, x11error = 0;
|
||||
static int32_t hasExtension = XScreenSaverQueryExtension(display, &x11event, &x11error);
|
||||
if(hasExtension)
|
||||
{
|
||||
XScreenSaverInfo *info = XScreenSaverAllocInfo();
|
||||
if(info)
|
||||
{
|
||||
XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
|
||||
idleTime = info->idle;
|
||||
XFree(info);
|
||||
}
|
||||
else
|
||||
qDebug() << "XScreenSaverAllocInfo() failed";
|
||||
}
|
||||
XCloseDisplay(display);
|
||||
#endif
|
||||
return idleTime;
|
||||
}
|
||||
|
13
src/platform.h
Normal file
13
src/platform.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef PLATFORM_H
|
||||
#define PLATFORM_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Platform-dependent code */
|
||||
|
||||
namespace Platform
|
||||
{
|
||||
u_int32_t getIdleTime();
|
||||
}
|
||||
|
||||
#endif // PLATFORM_H
|
|
@ -204,7 +204,6 @@ void GeneralForm::onAutoAwayChanged()
|
|||
{
|
||||
int minutes = bodyUI->autoAwaySpinBox->value();
|
||||
Settings::getInstance().setAutoAwayTime(minutes);
|
||||
Widget::getInstance()->setIdleTimer(minutes);
|
||||
}
|
||||
|
||||
void GeneralForm::onAutoAcceptFileChange()
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "form/inputpassworddialog.h"
|
||||
#include "src/autoupdate.h"
|
||||
#include "src/audio.h"
|
||||
#include "src/platform.h"
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
@ -124,8 +125,7 @@ void Widget::init()
|
|||
ui->menubar->hide();
|
||||
|
||||
idleTimer = new QTimer();
|
||||
idleTimer->setSingleShot(true);
|
||||
setIdleTimer(Settings::getInstance().getAutoAwayTime());
|
||||
idleTimer->start(10000);
|
||||
|
||||
//restore window state
|
||||
restoreGeometry(Settings::getInstance().getWindowGeometry());
|
||||
|
@ -262,7 +262,7 @@ void Widget::init()
|
|||
connect(setStatusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
|
||||
connect(setStatusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
|
||||
connect(addFriendForm, SIGNAL(friendRequested(QString, QString)), this, SIGNAL(friendRequested(QString, QString)));
|
||||
connect(idleTimer, &QTimer::timeout, this, &Widget::onUserAway);
|
||||
connect(idleTimer, &QTimer::timeout, this, &Widget::onUserAwayCheck);
|
||||
|
||||
coreThread->start();
|
||||
|
||||
|
@ -1064,21 +1064,13 @@ bool Widget::event(QEvent * e)
|
|||
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 && ui->statusButton->property("status").toString() == "away")
|
||||
{ // be sure nothing else has changed the status in the meantime
|
||||
qDebug() << "Widget: auto away deactivated at" << QTime::currentTime().toString();
|
||||
autoAwayActive = false;
|
||||
emit statusSet(Status::Online);
|
||||
}
|
||||
setIdleTimer(Settings::getInstance().getAutoAwayTime());
|
||||
if (autoAwayActive)
|
||||
onUserAwayCheck(); // Just so we get back from away faster when interacting with app
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1086,22 +1078,35 @@ bool Widget::event(QEvent * e)
|
|||
return QWidget::event(e);
|
||||
}
|
||||
|
||||
void Widget::setIdleTimer(int minutes)
|
||||
void Widget::onUserAwayCheck()
|
||||
{
|
||||
if (minutes > 0)
|
||||
idleTimer->start(minutes * 1000*60);
|
||||
}
|
||||
|
||||
void Widget::onUserAway()
|
||||
{
|
||||
if (Settings::getInstance().getAutoAwayTime() > 0
|
||||
&& ui->statusButton->property("status").toString() == "online") // leave user-set statuses in place
|
||||
u_int32_t autoAwayTime = Settings::getInstance().getAutoAwayTime() * 60 * 1000;
|
||||
if(ui->statusButton->property("status").toString() == "online")
|
||||
{
|
||||
qDebug() << "Widget: auto away activated" << QTime::currentTime().toString();
|
||||
emit statusSet(Status::Away);
|
||||
autoAwayActive = true;
|
||||
if(autoAwayTime)
|
||||
{
|
||||
if (Platform::getIdleTime() >= autoAwayTime)
|
||||
{
|
||||
qDebug() << "Widget: auto away activated" << QTime::currentTime().toString();
|
||||
emit statusSet(Status::Away);
|
||||
autoAwayActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
idleTimer->stop();
|
||||
else if(ui->statusButton->property("status").toString() == "away")
|
||||
{
|
||||
if(autoAwayActive)
|
||||
{
|
||||
if(!autoAwayTime || Platform::getIdleTime() < autoAwayTime)
|
||||
{
|
||||
qDebug() << "Widget: auto away deactivated" << QTime::currentTime().toString();
|
||||
emit statusSet(Status::Online);
|
||||
autoAwayActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(autoAwayActive)
|
||||
autoAwayActive = false;
|
||||
}
|
||||
|
||||
void Widget::setStatusOnline()
|
||||
|
|
|
@ -62,7 +62,6 @@ public:
|
|||
bool getIsWindowMinimized();
|
||||
static QList<QString> searchProfiles();
|
||||
void clearContactsList();
|
||||
void setIdleTimer(int minutes);
|
||||
void setTranslation();
|
||||
Q_INVOKABLE QMessageBox::StandardButton showWarningMsgBox(const QString& title, const QString& msg,
|
||||
QMessageBox::StandardButtons buttonss = QMessageBox::Ok);
|
||||
|
@ -129,7 +128,7 @@ private slots:
|
|||
void onGroupSendResult(int groupId, const QString& message, int result);
|
||||
void playRingtone();
|
||||
void onIconClick(QSystemTrayIcon::ActivationReason);
|
||||
void onUserAway();
|
||||
void onUserAwayCheck();
|
||||
void getPassword(QString info, int passtype, uint8_t* salt);
|
||||
void onSetShowSystemTray(bool newValue);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user