1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge branch 'pr862'

Conflicts:
	src/widget/widget.cpp
This commit is contained in:
Dubslow 2014-12-01 15:37:09 -06:00
commit 4781c8cfbb
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
8 changed files with 196 additions and 34 deletions

View File

@ -70,7 +70,7 @@ win32 {
BUNDLEID = im.tox.qtox BUNDLEID = im.tox.qtox
ICON = img/icons/qtox.icns ICON = img/icons/qtox.icns
QMAKE_INFO_PLIST = osx/info.plist QMAKE_INFO_PLIST = osx/info.plist
LIBS += -L$$PWD/libs/lib/ -ltoxcore -ltoxav -ltoxencryptsave -ltoxdns -lsodium -lvpx -framework OpenAL -lopencv_core -lopencv_highgui LIBS += -L$$PWD/libs/lib/ -ltoxcore -ltoxav -ltoxencryptsave -ltoxdns -lsodium -lvpx -framework OpenAL -framework IOKit -lopencv_core -lopencv_highgui -framework CoreFoundation
} else { } else {
# If we're building a package, static link libtox[core,av] and libsodium, since they are not provided by any package # If we're building a package, static link libtox[core,av] and libsodium, since they are not provided by any package
contains(STATICPKG, YES) { contains(STATICPKG, YES) {
@ -78,10 +78,10 @@ win32 {
INSTALLS += target 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 += -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,-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 { } 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) { contains(JENKINS, YES) {
@ -155,7 +155,8 @@ HEADERS += src/widget/form/addfriendform.h \
src/autoupdate.h \ src/autoupdate.h \
src/misc/serialize.h \ src/misc/serialize.h \
src/widget/form/settings/advancedform.h \ src/widget/form/settings/advancedform.h \
src/audio.h src/audio.h \
src/platform/timer.h
SOURCES += \ SOURCES += \
src/widget/form/addfriendform.cpp \ src/widget/form/addfriendform.cpp \
@ -222,4 +223,7 @@ SOURCES += \
src/autoupdate.cpp \ src/autoupdate.cpp \
src/misc/serialize.cpp \ src/misc/serialize.cpp \
src/widget/form/settings/advancedform.cpp \ src/widget/form/settings/advancedform.cpp \
src/audio.cpp src/audio.cpp \
src/platform/timer_osx.cpp \
src/platform/timer_win.cpp \
src/platform/timer_x11.cpp

28
src/platform/timer.h Normal file
View File

@ -0,0 +1,28 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef PLATFORM_TIMER_H
#define PLATFORM_TIMER_H
#include <cstdint>
namespace Platform
{
uint32_t getIdleTime();
}
#endif // PLATFORM_TIMER_H

View File

@ -0,0 +1,50 @@
/*
Pidgin is the legal property of its developers, whose names are too numerous
to list here. Please refer to the COPYRIGHT file distributed with this
source distribution (which can be found at
<https://hg.pidgin.im/pidgin/main/file/13e4ae613a6a/COPYRIGHT> ).
Additional Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#if defined(__APPLE__) && defined(__MACH__)
#include "src/platform/timer.h"
#include <QDebug>
#include <IOKit/IOKitLib.h>
#include <CoreFoundation/CoreFoundation.h>
uint32_t Platform::getIdleTime()
{
// https://hg.pidgin.im/pidgin/main/file/13e4ae613a6a/pidgin/gtkidle.c
static io_service_t service = NULL;
CFTypeRef property;
uint64_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);
return idleTime_ns / 1000000;
}
#endif // defined(__APPLE__) && defined(__MACH__)

View File

@ -0,0 +1,31 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include <QDebug>
#ifdef Q_OS_WIN32
#include "src/platform/timer.h"
#include <Windows.h>
uint32_t Platform::getIdleTime()
{
LASTINPUTINFO info = { 0 };
if(GetLastInputInfo(&info))
return info.dwTime / 1000;
return 0;
}
#endif // Q_OS_WIN32

View File

@ -0,0 +1,52 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include <QDebug>
#ifdef Q_OS_UNIX
#include "src/platform/timer.h"
#include <X11/extensions/scrnsaver.h>
uint32_t Platform::getIdleTime()
{
uint32_t idleTime = 0;
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);
return idleTime;
}
#endif // Q_OS_UNIX

View File

@ -219,7 +219,6 @@ void GeneralForm::onAutoAwayChanged()
{ {
int minutes = bodyUI->autoAwaySpinBox->value(); int minutes = bodyUI->autoAwaySpinBox->value();
Settings::getInstance().setAutoAwayTime(minutes); Settings::getInstance().setAutoAwayTime(minutes);
Widget::getInstance()->setIdleTimer(minutes);
} }
void GeneralForm::onAutoAcceptFileChange() void GeneralForm::onAutoAcceptFileChange()

View File

@ -35,6 +35,7 @@
#include "form/inputpassworddialog.h" #include "form/inputpassworddialog.h"
#include "src/autoupdate.h" #include "src/autoupdate.h"
#include "src/audio.h" #include "src/audio.h"
#include "src/platform/timer.h"
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
@ -75,8 +76,7 @@ void Widget::init()
ui->setupUi(this); ui->setupUi(this);
idleTimer = new QTimer(); idleTimer = new QTimer();
idleTimer->setSingleShot(true); idleTimer->start(1000);
setIdleTimer(Settings::getInstance().getAutoAwayTime());
//restore window state //restore window state
restoreGeometry(Settings::getInstance().getWindowGeometry()); restoreGeometry(Settings::getInstance().getWindowGeometry());
@ -263,7 +263,7 @@ void Widget::init()
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(addFriendForm, SIGNAL(friendRequested(QString, QString)), this, SIGNAL(friendRequested(QString, QString))); 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(); coreThread->start();
@ -549,7 +549,6 @@ void Widget::onStatusSet(Status status)
{ {
case Status::Online: case Status::Online:
ui->statusButton->setProperty("status" ,"online"); ui->statusButton->setProperty("status" ,"online");
qDebug() << "Widget: something set the status to online";
break; break;
case Status::Away: case Status::Away:
ui->statusButton->setProperty("status" ,"away"); ui->statusButton->setProperty("status" ,"away");
@ -1090,21 +1089,13 @@ bool Widget::event(QEvent * e)
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::MouseButtonPress:
case QEvent::MouseButtonRelease: case QEvent::MouseButtonRelease:
case QEvent::Wheel: case QEvent::Wheel:
case QEvent::KeyPress: case QEvent::KeyPress:
case QEvent::KeyRelease: case QEvent::KeyRelease:
if (autoAwayActive && ui->statusButton->property("status").toString() == "away") if (autoAwayActive)
{ // be sure nothing else has changed the status in the meantime onUserAwayCheck(); // Just so we get back from away faster when interacting with app
qDebug() << "Widget: auto away deactivated at" << QTime::currentTime().toString();
autoAwayActive = false;
emit statusSet(Status::Online);
}
setIdleTimer(Settings::getInstance().getAutoAwayTime());
default: default:
break; break;
} }
@ -1112,22 +1103,30 @@ bool Widget::event(QEvent * e)
return QWidget::event(e); return QWidget::event(e);
} }
void Widget::setIdleTimer(int minutes) void Widget::onUserAwayCheck()
{ {
if (minutes > 0) uint32_t autoAwayTime = Settings::getInstance().getAutoAwayTime() * 60 * 1000;
idleTimer->start(minutes * 1000*60);
}
void Widget::onUserAway() if (ui->statusButton->property("status").toString() == "online")
{
if (Settings::getInstance().getAutoAwayTime() > 0
&& ui->statusButton->property("status").toString() == "online") // leave user-set statuses in place
{ {
qDebug() << "Widget: auto away activated" << QTime::currentTime().toString(); if (autoAwayTime && Platform::getIdleTime() >= autoAwayTime)
{
qDebug() << "Widget: auto away activated at" << QTime::currentTime().toString();
emit statusSet(Status::Away); emit statusSet(Status::Away);
autoAwayActive = true; autoAwayActive = true;
} }
idleTimer->stop(); }
else if (ui->statusButton->property("status").toString() == "away")
{
if (autoAwayActive && (!autoAwayTime || Platform::getIdleTime() < autoAwayTime))
{
qDebug() << "Widget: auto away deactivated at" << QTime::currentTime().toString();
emit statusSet(Status::Online);
autoAwayActive = false;
}
}
else if (autoAwayActive)
autoAwayActive = false;
} }
void Widget::setStatusOnline() void Widget::setStatusOnline()

View File

@ -62,7 +62,6 @@ public:
bool getIsWindowMinimized(); bool getIsWindowMinimized();
static QList<QString> searchProfiles(); static QList<QString> searchProfiles();
void clearContactsList(); void clearContactsList();
void setIdleTimer(int minutes);
void setTranslation(); void setTranslation();
void updateTrayIcon(); void updateTrayIcon();
Q_INVOKABLE QMessageBox::StandardButton showWarningMsgBox(const QString& title, const QString& msg, Q_INVOKABLE QMessageBox::StandardButton showWarningMsgBox(const QString& title, const QString& msg,
@ -131,7 +130,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(QSystemTrayIcon::ActivationReason); void onIconClick(QSystemTrayIcon::ActivationReason);
void onUserAway(); void onUserAwayCheck();
void getPassword(QString info, int passtype, uint8_t* salt); void getPassword(QString info, int passtype, uint8_t* salt);
void onSetShowSystemTray(bool newValue); void onSetShowSystemTray(bool newValue);
void onSplitterMoved(int pos, int index); void onSplitterMoved(int pos, int index);