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
|
|
|
|
|
2014-04-29 17:30:19 +04:00
|
|
|
#include "owncloudlib.h"
|
2012-12-14 00:36:44 +04:00
|
|
|
#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
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
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
|
|
|
{
|
2014-04-29 17:30:19 +04:00
|
|
|
OWNCLOUDSYNC_EXPORT void sleep(int sec);
|
|
|
|
OWNCLOUDSYNC_EXPORT void usleep(int usec);
|
|
|
|
OWNCLOUDSYNC_EXPORT QString formatFingerprint( const QByteArray&, bool colonSeparated = true );
|
|
|
|
OWNCLOUDSYNC_EXPORT void setupFavLink( const QString &folder );
|
|
|
|
OWNCLOUDSYNC_EXPORT bool writeRandomFile( const QString& fname, int size = -1);
|
|
|
|
OWNCLOUDSYNC_EXPORT QString octetsToString( qint64 octets );
|
|
|
|
OWNCLOUDSYNC_EXPORT QString platform();
|
|
|
|
OWNCLOUDSYNC_EXPORT QByteArray userAgentString();
|
|
|
|
OWNCLOUDSYNC_EXPORT bool hasLaunchOnStartup(const QString &appName);
|
|
|
|
OWNCLOUDSYNC_EXPORT void setLaunchOnStartup(const QString &appName, const QString& guiName, bool launch);
|
|
|
|
OWNCLOUDSYNC_EXPORT qint64 freeDiskSpace(const QString &path, bool *ok = 0);
|
|
|
|
OWNCLOUDSYNC_EXPORT QString toCSyncScheme(const QString &urlStr);
|
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
|
|
|
|
2014-10-22 15:29:28 +04:00
|
|
|
OWNCLOUDSYNC_EXPORT bool doesSetContainPrefix(const QSet<QString> &l, const QString &p);
|
2014-10-13 19:23:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-04-29 17:30:19 +04:00
|
|
|
OWNCLOUDSYNC_EXPORT QString compactFormatDouble(double value, int prec, const QString& unit = QString::null);
|
2013-08-24 16:57:55 +04:00
|
|
|
|
|
|
|
// porting methods
|
2014-04-29 17:30:19 +04:00
|
|
|
OWNCLOUDSYNC_EXPORT QString escape(const QString&);
|
2013-08-24 16:57:55 +04:00
|
|
|
|
2014-01-29 14:39:14 +04:00
|
|
|
// conversion function QDateTime <-> time_t (because the ones builtin work on only unsigned 32bit)
|
2014-04-29 17:30:19 +04:00
|
|
|
OWNCLOUDSYNC_EXPORT QDateTime qDateTimeFromTime_t(qint64 t);
|
|
|
|
OWNCLOUDSYNC_EXPORT qint64 qDateTimeToTime_t(const QDateTime &t);
|
2014-01-29 14:39:14 +04:00
|
|
|
|
2014-05-14 11:55:04 +04:00
|
|
|
/**
|
|
|
|
* @brief Convert milliseconds to HMS string.
|
|
|
|
* @param quint64 msecs the milliseconds to convert to string.
|
|
|
|
* @param uint precision the amount of sub dviving scale to include in the result.
|
|
|
|
* @return an HMS representation of the milliseconds value.
|
|
|
|
*/
|
2014-06-30 16:13:45 +04:00
|
|
|
OWNCLOUDSYNC_EXPORT QString timeToDescriptiveString(QList<QPair<QString,quint32> > &timeMapping, quint64 msecs, quint8 precision, QString separator, bool specific);
|
|
|
|
OWNCLOUDSYNC_EXPORT QString timeToDescriptiveString(quint64 msecs, quint8 precision, QString separator, bool specific);
|
2014-10-24 23:52:41 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief hasDarkSystray - determines whether the systray is dark or light.
|
|
|
|
*
|
|
|
|
* Use this to check if the OS has a dark or a light systray.
|
|
|
|
*
|
|
|
|
* The value might change during the execution of the program
|
|
|
|
* (e.g. on OS X 10.10).
|
|
|
|
*
|
|
|
|
* @return bool which is true for systems with dark systray.
|
|
|
|
*/
|
|
|
|
OWNCLOUDSYNC_EXPORT bool hasDarkSystray();
|
|
|
|
|
2013-10-02 20:16:24 +04:00
|
|
|
// convinience OS detection methods
|
2014-04-29 17:30:19 +04:00
|
|
|
OWNCLOUDSYNC_EXPORT bool isWindows();
|
|
|
|
OWNCLOUDSYNC_EXPORT bool isMac();
|
|
|
|
OWNCLOUDSYNC_EXPORT bool isUnix();
|
|
|
|
OWNCLOUDSYNC_EXPORT bool isLinux(); // use with care
|
2015-01-09 00:40:47 +03:00
|
|
|
OWNCLOUDSYNC_EXPORT bool isBSD(); // use with care, does not match OS X
|
2014-03-26 21:00:02 +04:00
|
|
|
|
2014-08-26 17:46:24 +04:00
|
|
|
// crash helper for --debug
|
|
|
|
OWNCLOUDSYNC_EXPORT void crash();
|
|
|
|
|
2014-05-23 17:59:29 +04:00
|
|
|
// Case preserving file system underneath?
|
|
|
|
// if this function returns true, the file system is case preserving,
|
|
|
|
// that means "test" means the same as "TEST" for filenames.
|
|
|
|
// if false, the two cases are two different files.
|
|
|
|
OWNCLOUDSYNC_EXPORT bool fsCasePreserving();
|
2014-03-26 21:00:02 +04:00
|
|
|
|
2014-07-11 00:58:58 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT StopWatch {
|
2014-03-26 21:00:02 +04:00
|
|
|
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();
|
2014-12-04 19:57:29 +03:00
|
|
|
quint64 stop();
|
2014-03-26 21:00:02 +04:00
|
|
|
quint64 addLapTime( const QString& lapName );
|
2014-04-15 18:10:46 +04:00
|
|
|
void reset();
|
2014-03-26 21:00:02 +04:00
|
|
|
|
|
|
|
// 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
|