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:
commit
4781c8cfbb
14
qtox.pro
14
qtox.pro
|
@ -70,7 +70,7 @@ win32 {
|
|||
BUNDLEID = im.tox.qtox
|
||||
ICON = img/icons/qtox.icns
|
||||
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 {
|
||||
# If we're building a package, static link libtox[core,av] and libsodium, since they are not provided by any package
|
||||
contains(STATICPKG, YES) {
|
||||
|
@ -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/timer.h
|
||||
|
||||
SOURCES += \
|
||||
src/widget/form/addfriendform.cpp \
|
||||
|
@ -222,4 +223,7 @@ SOURCES += \
|
|||
src/autoupdate.cpp \
|
||||
src/misc/serialize.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
28
src/platform/timer.h
Normal 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
|
50
src/platform/timer_osx.cpp
Normal file
50
src/platform/timer_osx.cpp
Normal 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__)
|
31
src/platform/timer_win.cpp
Normal file
31
src/platform/timer_win.cpp
Normal 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
|
52
src/platform/timer_x11.cpp
Normal file
52
src/platform/timer_x11.cpp
Normal 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
|
|
@ -219,7 +219,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/timer.h"
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
@ -75,8 +76,7 @@ void Widget::init()
|
|||
ui->setupUi(this);
|
||||
|
||||
idleTimer = new QTimer();
|
||||
idleTimer->setSingleShot(true);
|
||||
setIdleTimer(Settings::getInstance().getAutoAwayTime());
|
||||
idleTimer->start(1000);
|
||||
|
||||
//restore window state
|
||||
restoreGeometry(Settings::getInstance().getWindowGeometry());
|
||||
|
@ -263,7 +263,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();
|
||||
|
||||
|
@ -549,7 +549,6 @@ void Widget::onStatusSet(Status status)
|
|||
{
|
||||
case Status::Online:
|
||||
ui->statusButton->setProperty("status" ,"online");
|
||||
qDebug() << "Widget: something set the status to online";
|
||||
break;
|
||||
case Status::Away:
|
||||
ui->statusButton->setProperty("status" ,"away");
|
||||
|
@ -1090,21 +1089,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;
|
||||
}
|
||||
|
@ -1112,22 +1103,30 @@ 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);
|
||||
}
|
||||
uint32_t autoAwayTime = Settings::getInstance().getAutoAwayTime() * 60 * 1000;
|
||||
|
||||
void Widget::onUserAway()
|
||||
{
|
||||
if (Settings::getInstance().getAutoAwayTime() > 0
|
||||
&& ui->statusButton->property("status").toString() == "online") // leave user-set statuses in place
|
||||
if (ui->statusButton->property("status").toString() == "online")
|
||||
{
|
||||
qDebug() << "Widget: auto away activated" << QTime::currentTime().toString();
|
||||
emit statusSet(Status::Away);
|
||||
autoAwayActive = true;
|
||||
if (autoAwayTime && Platform::getIdleTime() >= autoAwayTime)
|
||||
{
|
||||
qDebug() << "Widget: auto away activated at" << QTime::currentTime().toString();
|
||||
emit statusSet(Status::Away);
|
||||
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()
|
||||
|
|
|
@ -62,7 +62,6 @@ public:
|
|||
bool getIsWindowMinimized();
|
||||
static QList<QString> searchProfiles();
|
||||
void clearContactsList();
|
||||
void setIdleTimer(int minutes);
|
||||
void setTranslation();
|
||||
void updateTrayIcon();
|
||||
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 playRingtone();
|
||||
void onIconClick(QSystemTrayIcon::ActivationReason);
|
||||
void onUserAway();
|
||||
void onUserAwayCheck();
|
||||
void getPassword(QString info, int passtype, uint8_t* salt);
|
||||
void onSetShowSystemTray(bool newValue);
|
||||
void onSplitterMoved(int pos, int index);
|
||||
|
|
Loading…
Reference in New Issue
Block a user