diff --git a/plugins/telemetry/kis_tickets.cpp b/plugins/telemetry/kis_tickets.cpp index b2186a28f8..2c0dab340a 100644 --- a/plugins/telemetry/kis_tickets.cpp +++ b/plugins/telemetry/kis_tickets.cpp @@ -1,68 +1,78 @@ /* This file is part of the KDE project Copyright (C) 2017 Alexey Kapustin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_tickets.h" #include +#include KisTimeTicket::KisTimeTicket(QString id) : KisTicket(id) { m_start = QDateTime::currentDateTime(); } void KisTimeTicket::setStartTime(QDateTime& time) { m_start = time; } -void KisTimeTicket::setEndTime(QDateTime &time) +void KisTimeTicket::setEndTime(QDateTime& time) { m_end = time; } QDateTime KisTimeTicket::startTime() const { return m_start; } QDateTime KisTimeTicket::endTime() const { return m_end; } -int KisTimeTicket::useTimeSeconds() const +int KisTimeTicket::useTimeMSeconds() const { - int timeUse = m_end.toSecsSinceEpoch()- m_start.toSecsSinceEpoch(); + int timeUse = static_cast(m_end.toMSecsSinceEpoch() - m_start.toMSecsSinceEpoch()); return timeUse; } -void KisTimeTicket::addSecs(int seconds) +void KisTimeTicket::addMSecs(int seconds) { - m_end.addSecs(seconds); + if(seconds<0){ + seconds = std::numeric_limits::max(); + } + m_end.addMSecs(seconds); } KisTicket::KisTicket(QString id) : m_id(id) { } -QString KisTicket::ticketId() const { return m_id; } +QString KisTicket::ticketId() const +{ + return m_id; +} -void KisTicket::setTickedId(QString id) { m_id = id; } +void KisTicket::setTickedId(QString id) +{ + m_id = id; +} diff --git a/plugins/telemetry/kis_tickets.h b/plugins/telemetry/kis_tickets.h index 952eb78083..0c15c14c01 100644 --- a/plugins/telemetry/kis_tickets.h +++ b/plugins/telemetry/kis_tickets.h @@ -1,51 +1,51 @@ /* This file is part of the KDE project Copyright (C) 2017 Alexey Kapustin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIS_TICKETS_H #define KIS_TICKETS_H #include class KisTicket { public: KisTicket(){} KisTicket(QString id); QString ticketId() const; void setTickedId(QString id); virtual ~KisTicket(){} protected: QString m_id; }; class KisTimeTicket: public KisTicket{ public: KisTimeTicket(QString id); void setStartTime(QDateTime &time); void setEndTime(QDateTime &time); QDateTime startTime() const; QDateTime endTime() const; - int useTimeSeconds() const; - void addSecs(int seconds); + int useTimeMSeconds() const; + void addMSecs(int seconds); private: QDateTime m_start; QDateTime m_end; }; #endif diff --git a/plugins/telemetry/kis_toolsinfosource.cpp b/plugins/telemetry/kis_toolsinfosource.cpp index 95b0bf301a..e966b927d0 100644 --- a/plugins/telemetry/kis_toolsinfosource.cpp +++ b/plugins/telemetry/kis_toolsinfosource.cpp @@ -1,90 +1,103 @@ /* This file is part of the KDE project Copyright (C) 2017 Alexey Kapustin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_toolsinfosource.h" #include #include #include #include +#include #include using namespace KisUserFeedback; using namespace KUserFeedback; ToolsInfoSource::ToolsInfoSource() : AbstractDataSource(QStringLiteral("Tools"), Provider::DetailedSystemInformation) { } QString ToolsInfoSource::description() const { return QObject::tr("Inforamation about tools"); } QVariant ToolsInfoSource::data() { + static int countCalls = 0; + countCalls++; + if (!countCalls % 2) { //kuserfeedback feature + m_tools.clear(); + } + foreach (QString id, m_currentTools.keys()) { + deactivateTool(id); + } foreach (QSharedPointer tool, m_toolsMap) { - KisTicket* ticket = tool.data(); KisTimeTicket* timeTicket = nullptr; timeTicket = dynamic_cast(ticket); if (timeTicket) { - int timeUse = timeTicket->useTimeSeconds(); + int timeUse = timeTicket->useTimeMSeconds(); QVariantMap m; m.insert(QStringLiteral("toolname"), ticket->ticketId()); m.insert(QStringLiteral("timeUseSeconds"), timeUse); std::cout << "Time use" << timeUse << std::endl; m_tools.push_back(m); } } + m_toolsMap.clear(); + m_currentTools.clear(); + return m_tools; } void ToolsInfoSource::activateTool(QSharedPointer ticket) { QMutexLocker locker(&m_mutex); m_currentTools.insert(ticket->ticketId(), ticket); if (!m_toolsMap.count(ticket->ticketId())) m_toolsMap.insert(ticket->ticketId(), ticket); std::cout << "ACTIVATE TOOL " << ticket->ticketId().toStdString() << std::endl; } void ToolsInfoSource::deactivateTool(QString id) { QMutexLocker locker(&m_mutex); KisTicket* ticket = m_currentTools.value(id).data(); KisTimeTicket* timeTicket = dynamic_cast(ticket); + std::cout << "SIZES current:" << m_currentTools.size() << " all" << m_toolsMap.size() << std::endl; if (timeTicket) { QDateTime deactivateTime = QDateTime::currentDateTime(); timeTicket->setEndTime(deactivateTime); KisTicket* mainTicket = m_toolsMap[id].data(); KisTimeTicket* mainTimeTicket = dynamic_cast(mainTicket); - if (mainTicket) { - mainTimeTicket->addSecs(timeTicket->useTimeSeconds()); + if (mainTimeTicket) { + std::cout << "AdditionalTIme " << timeTicket->useTimeMSeconds() << std::endl; + mainTimeTicket->addMSecs(timeTicket->useTimeMSeconds()); } - m_currentTools.remove(id); std::cout << "DE_ACTIVATE TOOL " << ticket->ticketId().toStdString() << std::endl; } + m_currentTools.remove(id); }