2012-12-14 00:36:44 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
2013-10-02 21:06:33 +04:00
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
2012-12-14 00:36:44 +04:00
|
|
|
*
|
|
|
|
* This program is free 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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 GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UTILITY_H
|
|
|
|
#define UTILITY_H
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QByteArray>
|
2014-01-29 14:39:14 +04:00
|
|
|
#include <QDateTime>
|
2014-03-26 21:00:02 +04:00
|
|
|
#include <QElapsedTimer>
|
2014-03-28 13:26:42 +04:00
|
|
|
#include <QHash>
|
2012-12-14 00:36:44 +04:00
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
class QWidget;
|
2012-12-14 00:36:44 +04:00
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
namespace Mirall {
|
2012-12-14 00:36:44 +04:00
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
namespace Utility
|
2012-12-14 00:36:44 +04:00
|
|
|
{
|
2013-09-10 13:35:30 +04:00
|
|
|
void sleep(int sec);
|
2013-12-10 16:47:44 +04:00
|
|
|
void usleep(int usec);
|
2013-07-04 21:59:40 +04:00
|
|
|
QString formatFingerprint( const QByteArray& );
|
|
|
|
void setupFavLink( const QString &folder );
|
2014-01-08 17:34:51 +04:00
|
|
|
bool writeRandomFile( const QString& fname, int size = -1);
|
2013-07-04 21:59:40 +04:00
|
|
|
QString octetsToString( qint64 octets );
|
|
|
|
QString platform();
|
|
|
|
QByteArray userAgentString();
|
|
|
|
void raiseDialog(QWidget *);
|
2013-07-07 00:38:33 +04:00
|
|
|
bool hasLaunchOnStartup(const QString &appName);
|
|
|
|
void setLaunchOnStartup(const QString &appName, const QString& guiName, bool launch);
|
2013-07-07 03:23:25 +04:00
|
|
|
qint64 freeDiskSpace(const QString &path, bool *ok = 0);
|
2013-08-05 21:45:16 +04:00
|
|
|
QString toCSyncScheme(const QString &urlStr);
|
2013-10-02 13:55:36 +04:00
|
|
|
void showInFileManager(const QString &localPath);
|
2013-07-10 11:19:41 +04:00
|
|
|
/** Like QLocale::toString(double, 'f', prec), but drops trailing zeros after the decimal point */
|
2013-07-24 16:36:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief compactFormatDouble - formats a double value human readable.
|
|
|
|
*
|
|
|
|
* @param value the value to format.
|
|
|
|
* @param prec the precision.
|
|
|
|
* @param unit an optional unit that is appended if present.
|
|
|
|
* @return the formatted string.
|
|
|
|
*/
|
|
|
|
QString compactFormatDouble(double value, int prec, const QString& unit = QString::null);
|
2013-08-24 16:57:55 +04:00
|
|
|
|
|
|
|
// porting methods
|
|
|
|
QString escape(const QString&);
|
|
|
|
QString dataLocation();
|
|
|
|
|
2014-01-29 14:39:14 +04:00
|
|
|
// conversion function QDateTime <-> time_t (because the ones builtin work on only unsigned 32bit)
|
|
|
|
QDateTime qDateTimeFromTime_t(qint64 t);
|
|
|
|
qint64 qDateTimeToTime_t(const QDateTime &t);
|
|
|
|
|
|
|
|
|
2013-10-02 20:16:24 +04:00
|
|
|
// convinience OS detection methods
|
|
|
|
bool isWindows();
|
|
|
|
bool isMac();
|
|
|
|
bool isUnix();
|
2014-01-15 14:08:42 +04:00
|
|
|
bool isLinux(); // use with care
|
2014-03-26 21:00:02 +04:00
|
|
|
|
|
|
|
class StopWatch {
|
|
|
|
private:
|
2014-03-28 12:50:13 +04:00
|
|
|
QHash<QString, quint64> _lapTimes;
|
2014-03-26 21:00:02 +04:00
|
|
|
QDateTime _startTime;
|
|
|
|
QElapsedTimer _timer;
|
|
|
|
public:
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
quint64 addLapTime( const QString& lapName );
|
|
|
|
|
|
|
|
// out helpers, return the masured times.
|
2014-03-28 12:39:32 +04:00
|
|
|
QDateTime startTime() const;
|
|
|
|
QDateTime timeOfLap( const QString& lapName ) const;
|
|
|
|
quint64 durationOfLap( const QString& lapName ) const;
|
2014-03-26 21:00:02 +04:00
|
|
|
};
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
2012-12-14 00:36:44 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif // UTILITY_H
|