File indexing completed on 2024-05-19 05:21:53
0001 /* 0002 * Copyright (C) 2003 by Tomas Pospisek <tpo@sourcepole.ch> 0003 * Copyright (C) 2019 Alexander Potashev <aspotashev@gmail.com> 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License along 0016 * with this program; if not, write to the 0017 * Free Software Foundation, Inc. 0018 * 51 Franklin Street, Fifth Floor 0019 * Boston, MA 02110-1301 USA. 0020 * 0021 */ 0022 0023 #ifndef KTIMETRACKER_DESKTOP_TRACKER_H 0024 #define KTIMETRACKER_DESKTOP_TRACKER_H 0025 0026 #include <QObject> 0027 #include <QVector> 0028 0029 #include "desktoplist.h" 0030 0031 QT_BEGIN_NAMESPACE 0032 class QTimer; 0033 QT_END_NAMESPACE 0034 0035 class Task; 0036 0037 typedef QVector<Task *> TaskVector; 0038 const int maxDesktops = 20; 0039 0040 /** A utility to associate tasks with desktops 0041 * As soon as a desktop is activated/left - an signal is emitted for 0042 * each task tracking that all tasks that want to track that desktop 0043 */ 0044 0045 class DesktopTracker : public QObject 0046 { 0047 Q_OBJECT 0048 0049 public: 0050 DesktopTracker(); 0051 /** 0052 * Start time tracking of tasks by virtual desktop. 0053 * 0054 * @returns A QString with the error message, in case of no error an empty QString. 0055 * 0056 */ 0057 QString startTracking(); 0058 void registerForDesktops( Task* task, DesktopList dl ); 0059 int numDesktops = 0; 0060 int desktopCount() const { return m_desktopCount; } 0061 0062 public Q_SLOTS: 0063 void handleDesktopChange(int desktop); 0064 0065 private Q_SLOTS: 0066 void changeTimers(); 0067 0068 Q_SIGNALS: 0069 void reachedActiveDesktop(Task *task); 0070 void leftActiveDesktop(Task *task); 0071 0072 private: 0073 // define vectors for at most 16 virtual desktops 0074 // E.g.: desktopTrackerStop[3] contains a vector with 0075 // all tasks to be notified, when switching to/from desk 3. 0076 TaskVector m_desktopTracker[maxDesktops]; 0077 int m_previousDesktop = 0; 0078 int m_desktopCount; 0079 int m_desktop = 0; 0080 QTimer *m_timer; 0081 }; 0082 0083 #endif // KTIMETRACKER_DESKTOP_TRACKER_H