File indexing completed on 2024-04-21 16:35:01

0001 /*
0002     SPDX-FileCopyrightText: 2006 Tom Albers <toma@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef RSIGLOBALS_H
0008 #define RSIGLOBALS_H
0009 
0010 #include <QBitArray>
0011 #include <QObject>
0012 #include <QStringList>
0013 #include <qmap.h>
0014 
0015 #include <kformat.h>
0016 #include <kpassivepopup.h>
0017 
0018 class RSIStats;
0019 
0020 enum RSIStat {
0021     TOTAL_TIME = 0,
0022     ACTIVITY,
0023     IDLENESS,
0024     ACTIVITY_PERC,
0025     ACTIVITY_PERC_MINUTE,
0026     ACTIVITY_PERC_HOUR,
0027     ACTIVITY_PERC_6HOUR,
0028     MAX_IDLENESS,
0029     CURRENT_IDLE_TIME,
0030     IDLENESS_CAUSED_SKIP_TINY,
0031     IDLENESS_CAUSED_SKIP_BIG,
0032     TINY_BREAKS,
0033     TINY_BREAKS_SKIPPED,
0034     TINY_BREAKS_POSTPONED,
0035     LAST_TINY_BREAK,
0036     BIG_BREAKS,
0037     BIG_BREAKS_SKIPPED,
0038     BIG_BREAKS_POSTPONED,
0039     LAST_BIG_BREAK,
0040     PAUSE_SCORE,
0041     STAT_COUNT
0042 };
0043 
0044 enum RSIInterval {
0045     TINY_BREAK_INTERVAL = 0,
0046     TINY_BREAK_DURATION,
0047     TINY_BREAK_THRESHOLD,
0048     BIG_BREAK_INTERVAL,
0049     BIG_BREAK_DURATION,
0050     BIG_BREAK_THRESHOLD,
0051     POSTPONE_BREAK_INTERVAL,
0052     PATIENCE_INTERVAL,
0053     SHORT_INPUT_INTERVAL,
0054     INTERVAL_COUNT
0055 };
0056 
0057 /**
0058  * @class RSIGlobals
0059  * This class consists of a few commonly used routines and values.
0060  * @author Tom Albers <toma.org>
0061  */
0062 class RSIGlobals : public QObject
0063 {
0064     Q_OBJECT
0065 public:
0066     /** Default constructor. */
0067     explicit RSIGlobals(QObject *parent = nullptr);
0068 
0069     /** Default destructor. */
0070     ~RSIGlobals();
0071 
0072     /**
0073      * Returns an instance of RSIGlobals. Never create your own instance
0074      * of RSIGlobals, but use this method instead to get the one and only
0075      * instance.
0076      */
0077     static RSIGlobals *instance();
0078 
0079     /**
0080      * Returns the one and only statistics component.
0081      *
0082      * @see RSIStats
0083      */
0084     static RSIStats *stats()
0085     {
0086         return m_stats;
0087     }
0088 
0089     /**
0090      * Converts @p seconds to a reasonable string.
0091      * @param seconds the amount of seconds
0092      * @returns a formatted string.
0093      */
0094     QString formatSeconds(const int seconds);
0095 
0096     /**
0097      * Returns a reference to the mapping containing all intervals.
0098      * These intervals define when a tiny or big break should occur and for how
0099      * long.
0100      */
0101     const QVector<int> &intervals() const
0102     {
0103         return m_intervals;
0104     }
0105 
0106     /**
0107      * Returns true if tiny breaks are to be made at all.
0108      */
0109     bool useTinyBreaks() const
0110     {
0111         return m_intervals[TINY_BREAK_INTERVAL] != 0;
0112     }
0113 
0114     /**
0115      * This function returns a color ranging from green to red.
0116      * The more red, the more the user needs a tiny break.
0117      */
0118     QColor getTinyBreakColor(int secsToBreak) const;
0119 
0120     /**
0121      * This function returns a color ranging from green to red.
0122      * The more red, the more the user needs a tiny break.
0123      */
0124     QColor getBigBreakColor(int secsToBreak) const;
0125 
0126     /**
0127      * Returns the array which keeps track per second for 24 hours when the
0128      * user was active or idle. Activity = 1, idle = 0.
0129      * The RSIStatBitArrayItem can read and write a certain interval of this
0130      * array, for example to measure the activity in 60 seconds or 1 hour.
0131      *
0132      * @see RSIStatBitArrayItem
0133      */
0134     QBitArray *usageArray()
0135     {
0136         return &m_usageArray;
0137     }
0138 
0139     /**
0140      * Resets the usage array, with all values to 0.
0141      */
0142     void resetUsage();
0143 
0144     /**
0145      *
0146      * Hook to KDE's Notifying system at start/end of a break.
0147      * @param start when true the start commands are executed, false executes
0148      *              the ones at the end of a break.
0149      * @param big   true for big breaks, false for short ones.
0150      */
0151     void NotifyBreak(bool start, bool big);
0152 
0153 public slots:
0154     /**
0155      * Reads the configuration.
0156      */
0157     void slotReadConfig();
0158 
0159 private:
0160     static RSIGlobals *m_instance;
0161     static RSIStats *m_stats;
0162     QVector<int> m_intervals;
0163     QBitArray m_usageArray;
0164     KFormat m_format;
0165 };
0166 
0167 #endif // RSIGLOBALS_H