noo/client/helper.h

109 lines
2.6 KiB
C
Raw Normal View History

2018-09-24 22:25:14 +03:00
#ifndef HELPER_H
#define HELPER_H
#include <QString>
#include <QObject>
2019-07-28 20:49:34 +03:00
#include "config.h"
2018-09-24 22:25:14 +03:00
2018-10-05 18:20:40 +03:00
class Settings;
2018-12-21 23:11:26 +02:00
namespace helper
2018-10-05 18:20:40 +03:00
{
2018-12-21 23:11:26 +02:00
class theme
{
public:
static void applyCurrent(Settings& settings);
};
2019-01-13 14:11:00 +03:00
// date is always local. year, month & day number is natural (NO start from zero, NO delta with 1900 year etc.)
2018-12-21 23:11:26 +02:00
struct date
{
int mYear = -1, mMonth = -1, mDay = -1;
2019-01-13 14:11:00 +03:00
date();
date(int y, int m, int d);
// Timestamp is always UTC! But date is always local!
time_t toTimestamp() const;
enum
{
To_LocalTime,
To_GmtTime
};
static date fromTimestamp(time_t timestamp, int options);
static date today();
static date fromTm(struct tm& t);
static int daysInMonth(int y, int m);
2019-03-26 21:30:03 +02:00
bool operator < (const date& rhs);
bool operator > (const date& rhs);
bool operator == (const date& rhs);
bool operator >= (const date& rhs);
2018-12-21 23:11:26 +02:00
};
struct time
{
int mHour = 0, mMinute = 0, mSecond = 0;
time() = default;
time(int h, int m, int s);
std::string toString(bool showSeconds = true) const;
static time fromTimestamp(time_t timestamp, int options);
};
2018-12-21 23:11:26 +02:00
class chrono
{
public:
// Seconds is number of seconds in a day. It is NOT a UNIX timestamp.
2018-12-21 23:11:26 +02:00
static std::string secondsToDisplay(int seconds, bool showSeconds);
static std::string timeToStr(time_t timestamp);
static time_t strToTime(const std::string& s);
2019-01-13 14:11:00 +03:00
static struct tm localtime(time_t timestamp);
static int daysInMonth(int m, int y);
2018-12-21 23:11:26 +02:00
};
class path
{
public:
static QString pathToDatabase();
static QString pathToDesktop();
static QString pathToSettings();
static QString pathToDatabaseTemplate();
static QString pathToLog();
};
class activityTracker
{
public:
static bool ensureSmartTrackingIsPossible();
};
class EscapeKeyEventFilter: public QObject
{
Q_OBJECT
public:
explicit EscapeKeyEventFilter(QObject* parent = 0);
bool eventFilter(QObject *obj, QEvent * event);
signals:
void escapePressed(QObject* obj);
};
// Keychain helper class
class password
{
public:
static QString loadFromKeychain();
static bool saveToKeychain(const QString& password);
};
2019-07-28 20:49:34 +03:00
extern std::string app_version();
2018-12-21 23:11:26 +02:00
}
2018-09-24 22:25:14 +03:00
#endif