Move Utility to a new common static library
authorJocelyn Turcotte <jturcotte@woboq.com>
Wed, 16 Aug 2017 06:36:52 +0000 (08:36 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 5 Oct 2017 20:01:03 +0000 (22:01 +0200)
Now that csync builds as C++, this will avoid having to implement
functionalities needed by csync mandatorily in csync itself.

This library is built as part of libocsync and symbols exported
through it.
This requires a relicense of Utility as LGPL. All classes moved into
this library from src/libsync will need to be relicensed as well.

81 files changed:
CMakeLists.txt
src/cmd/simplesslerrorhandler.cpp
src/common/README [new file with mode: 0644]
src/common/common.cmake [new file with mode: 0644]
src/common/utility.cpp [new file with mode: 0644]
src/common/utility.h [new file with mode: 0644]
src/common/utility_mac.cpp [new file with mode: 0644]
src/common/utility_unix.cpp [new file with mode: 0644]
src/common/utility_win.cpp [new file with mode: 0644]
src/csync/CMakeLists.txt
src/csync/std/CMakeLists.txt
src/gui/accountmanager.cpp
src/gui/accountsettings.cpp
src/gui/accountstate.cpp
src/gui/accountstate.h
src/gui/activityitemdelegate.cpp
src/gui/activitywidget.cpp
src/gui/application.cpp
src/gui/creds/shibbolethcredentials.cpp
src/gui/folder.cpp
src/gui/folderman.cpp
src/gui/folderstatusdelegate.cpp
src/gui/folderstatusmodel.cpp
src/gui/generalsettings.cpp
src/gui/issueswidget.cpp
src/gui/main.cpp
src/gui/networksettings.cpp
src/gui/notificationwidget.cpp
src/gui/openfilemanager.cpp
src/gui/owncloudgui.cpp
src/gui/owncloudsetupwizard.cpp
src/gui/protocolwidget.cpp
src/gui/socketapi.cpp
src/gui/sslbutton.cpp
src/gui/sslerrordialog.cpp
src/gui/syncrunfilelog.cpp
src/gui/updater/ocupdater.cpp
src/gui/updater/sparkleupdater_mac.mm
src/gui/updater/updater.cpp
src/gui/wizard/owncloudconnectionmethoddialog.cpp
src/libsync/CMakeLists.txt
src/libsync/accessmanager.cpp
src/libsync/account.h
src/libsync/bandwidthmanager.cpp
src/libsync/clientproxy.h
src/libsync/configfile.cpp
src/libsync/configfile.h
src/libsync/creds/credentialscommon.cpp
src/libsync/creds/httpcredentials.cpp
src/libsync/creds/tokencredentials.cpp
src/libsync/excludedfiles.cpp
src/libsync/filesystem.cpp
src/libsync/logger.h
src/libsync/owncloudpropagator.cpp
src/libsync/owncloudtheme.cpp
src/libsync/ownsql.cpp
src/libsync/propagatedownload.cpp
src/libsync/propagateupload.cpp
src/libsync/propagateuploadng.cpp
src/libsync/propagateuploadv1.cpp
src/libsync/propagatorjobs.cpp
src/libsync/syncengine.h
src/libsync/syncjournaldb.cpp
src/libsync/syncjournaldb.h
src/libsync/syncjournalfilerecord.cpp
src/libsync/theme.cpp
src/libsync/utility.cpp [deleted file]
src/libsync/utility.h [deleted file]
src/libsync/utility_mac.cpp [deleted file]
src/libsync/utility_unix.cpp [deleted file]
src/libsync/utility_win.cpp [deleted file]
src/libsync/version.h.in [deleted file]
test/csync/csync_tests/check_csync_misc.cpp
test/testchecksumvalidator.cpp
test/testfilesystem.cpp
test/testfolder.cpp
test/testfolderman.cpp
test/testfolderwatcher.cpp
test/testinotifywatcher.cpp
test/testutility.cpp
version.h.in [new file with mode: 0644]

index 976f19aecc175cc15357bb7b62f32dcbc0fb0916..4b1d4f20384eeef0a47180bce85369bea6ff746b 100644 (file)
@@ -41,7 +41,13 @@ endif()
 include(Warnings)
 
 include(${CMAKE_SOURCE_DIR}/VERSION.cmake)
+# For config.h
 include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
+# Allows includes based on src/ like #include "common/utility.h" or #include "csync/csync.h"
+include_directories(
+    ${CMAKE_CURRENT_SOURCE_DIR}/src
+    ${CMAKE_CURRENT_BINARY_DIR}/src
+)
 
 # disable the crashreporter if libcrashreporter-qt is not available or we're building for ARM
 if( CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty/libcrashreporter-qt/CMakeLists.txt")
@@ -211,13 +217,8 @@ endif()
 file( GLOB TRANS_FILES ${CMAKE_SOURCE_DIR}/translations/client_*.ts)
 set(TRANSLATIONS ${TRANS_FILES})
 
-if(UNIT_TESTING)
-    # Make sure we set this before recursing into child folders.
-    set(WITH_TESTING ON)
-    include(CTest)
-    enable_testing()
-    add_subdirectory(test)
-endif(UNIT_TESTING)
+# Make sure we set this before recursing into child folders.
+set(WITH_TESTING ${UNIT_TESTING})
 
 add_subdirectory(src)
 if(NOT BUILD_LIBRARIES_ONLY)
@@ -227,7 +228,14 @@ add_subdirectory(doc/dev)
 add_subdirectory(admin)
 endif(NOT BUILD_LIBRARIES_ONLY)
 
+if(UNIT_TESTING)
+    include(CTest)
+    enable_testing()
+    add_subdirectory(test)
+endif(UNIT_TESTING)
+
 configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
 
 if(BUILD_OWNCLOUD_OSX_BUNDLE)
     install(FILES sync-exclude.lst DESTINATION ${OWNCLOUD_OSX_BUNDLE}/Contents/Resources/)
index 18a03293acbfa3e688519a1745cccc9381cd5576..43743850716935ab74bd736c8777599b001ebaf3 100644 (file)
@@ -12,7 +12,7 @@
  * for more details.
  */
 #include "configfile.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "account.h"
 #include "simplesslerrorhandler.h"
 
diff --git a/src/common/README b/src/common/README
new file mode 100644 (file)
index 0000000..1669858
--- /dev/null
@@ -0,0 +1,2 @@
+This folder contains code covered by the CLA being licensed as LGPL.
+This allows it to be linked together with the rest of the LGPL code in csync.
diff --git a/src/common/common.cmake b/src/common/common.cmake
new file mode 100644 (file)
index 0000000..a26e76d
--- /dev/null
@@ -0,0 +1,6 @@
+# Just list files to build as part of the csync dynamic lib.
+# Essentially they could be in the same directory but are separate to
+# help keep track of the different code licenses.
+set(common_SOURCES
+    ${CMAKE_CURRENT_LIST_DIR}/utility.cpp
+)
diff --git a/src/common/utility.cpp b/src/common/utility.cpp
new file mode 100644 (file)
index 0000000..8bc2f2d
--- /dev/null
@@ -0,0 +1,571 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
+ * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "config.h"
+
+#include "common/utility.h"
+#include "version.h"
+
+// Note:  This file must compile without QtGui
+#include <QCoreApplication>
+#include <QSettings>
+#include <QTextStream>
+#include <QDir>
+#include <QFile>
+#include <QUrl>
+#include <QProcess>
+#include <QObject>
+#include <QThread>
+#include <QDateTime>
+#include <QSysInfo>
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#include <QTextDocument>
+#else
+#include <QStandardPaths>
+#endif
+#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
+#include <QCollator>
+#endif
+#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
+#include <QSysInfo>
+#endif
+
+
+#ifdef Q_OS_UNIX
+#include <sys/statvfs.h>
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+
+#include <math.h>
+#include <stdarg.h>
+
+#if defined(Q_OS_WIN)
+#include "utility_win.cpp"
+#elif defined(Q_OS_MAC)
+#include "utility_mac.cpp"
+#else
+#include "utility_unix.cpp"
+#endif
+
+namespace OCC {
+
+Q_LOGGING_CATEGORY(lcUtility, "sync.utility", QtInfoMsg)
+
+bool Utility::writeRandomFile(const QString &fname, int size)
+{
+    int maxSize = 10 * 10 * 1024;
+    qsrand(QDateTime::currentMSecsSinceEpoch());
+
+    if (size == -1)
+        size = qrand() % maxSize;
+
+    QString randString;
+    for (int i = 0; i < size; i++) {
+        int r = qrand() % 128;
+        randString.append(QChar(r));
+    }
+
+    QFile file(fname);
+    if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+        QTextStream out(&file);
+        out << randString;
+        // optional, as QFile destructor will already do it:
+        file.close();
+        return true;
+    }
+    return false;
+}
+
+QString Utility::formatFingerprint(const QByteArray &fmhash, bool colonSeparated)
+{
+    QByteArray hash;
+    int steps = fmhash.length() / 2;
+    for (int i = 0; i < steps; i++) {
+        hash.append(fmhash[i * 2]);
+        hash.append(fmhash[i * 2 + 1]);
+        hash.append(' ');
+    }
+
+    QString fp = QString::fromLatin1(hash.trimmed());
+    if (colonSeparated) {
+        fp.replace(QChar(' '), QChar(':'));
+    }
+
+    return fp;
+}
+
+void Utility::setupFavLink(const QString &folder)
+{
+    setupFavLink_private(folder);
+}
+
+QString Utility::octetsToString(qint64 octets)
+{
+#define THE_FACTOR 1024
+    static const qint64 kb = THE_FACTOR;
+    static const qint64 mb = THE_FACTOR * kb;
+    static const qint64 gb = THE_FACTOR * mb;
+
+    QString s;
+    qreal value = octets;
+
+    // Whether we care about decimals: only for GB/MB and only
+    // if it's less than 10 units.
+    bool round = true;
+
+    // do not display terra byte with the current units, as when
+    // the MB, GB and KB units were made, there was no TB,
+    // see the JEDEC standard
+    // https://en.wikipedia.org/wiki/JEDEC_memory_standards
+    if (octets >= gb) {
+        s = QCoreApplication::translate("Utility", "%L1 GB");
+        value /= gb;
+        round = false;
+    } else if (octets >= mb) {
+        s = QCoreApplication::translate("Utility", "%L1 MB");
+        value /= mb;
+        round = false;
+    } else if (octets >= kb) {
+        s = QCoreApplication::translate("Utility", "%L1 KB");
+        value /= kb;
+    } else {
+        s = QCoreApplication::translate("Utility", "%L1 B");
+    }
+
+    if (value > 9.95)
+        round = true;
+
+    if (round)
+        return s.arg(qRound(value));
+
+    return s.arg(value, 0, 'g', 2);
+}
+
+// Qtified version of get_platforms() in csync_owncloud.c
+static QLatin1String platform()
+{
+#if defined(Q_OS_WIN)
+    return QLatin1String("Windows");
+#elif defined(Q_OS_MAC)
+    return QLatin1String("Macintosh");
+#elif defined(Q_OS_LINUX)
+    return QLatin1String("Linux");
+#elif defined(__DragonFly__) // Q_OS_FREEBSD also defined
+    return QLatin1String("DragonFlyBSD");
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_FREEBSD_KERNEL)
+    return QLatin1String("FreeBSD");
+#elif defined(Q_OS_NETBSD)
+    return QLatin1String("NetBSD");
+#elif defined(Q_OS_OPENBSD)
+    return QLatin1String("OpenBSD");
+#elif defined(Q_OS_SOLARIS)
+    return QLatin1String("Solaris");
+#else
+    return QLatin1String("Unknown OS");
+#endif
+}
+
+QByteArray Utility::userAgentString()
+{
+    QString re = QString::fromLatin1("Mozilla/5.0 (%1) mirall/%2")
+                     .arg(platform(), QLatin1String(MIRALL_VERSION_STRING));
+
+    QLatin1String appName(APPLICATION_SHORTNAME);
+
+    // this constant "ownCloud" is defined in the default OEM theming
+    // that is used for the standard client. If it is changed there,
+    // it needs to be adjusted here.
+    if (appName != QLatin1String("ownCloud")) {
+        re += QString(" (%1)").arg(appName);
+    }
+    return re.toLatin1();
+}
+
+bool Utility::hasLaunchOnStartup(const QString &appName)
+{
+    return hasLaunchOnStartup_private(appName);
+}
+
+void Utility::setLaunchOnStartup(const QString &appName, const QString &guiName, bool enable)
+{
+    setLaunchOnStartup_private(appName, guiName, enable);
+}
+
+qint64 Utility::freeDiskSpace(const QString &path)
+{
+#if defined(Q_OS_MAC) || defined(Q_OS_FREEBSD) || defined(Q_OS_FREEBSD_KERNEL) || defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD)
+    struct statvfs stat;
+    if (statvfs(path.toLocal8Bit().data(), &stat) == 0) {
+        return (qint64)stat.f_bavail * stat.f_frsize;
+    }
+#elif defined(Q_OS_UNIX)
+    struct statvfs64 stat;
+    if (statvfs64(path.toLocal8Bit().data(), &stat) == 0) {
+        return (qint64)stat.f_bavail * stat.f_frsize;
+    }
+#elif defined(Q_OS_WIN)
+    ULARGE_INTEGER freeBytes;
+    freeBytes.QuadPart = 0L;
+    if (GetDiskFreeSpaceEx(reinterpret_cast<const wchar_t *>(path.utf16()), &freeBytes, NULL, NULL)) {
+        return freeBytes.QuadPart;
+    }
+#endif
+    return -1;
+}
+
+QString Utility::compactFormatDouble(double value, int prec, const QString &unit)
+{
+    QLocale locale = QLocale::system();
+    QChar decPoint = locale.decimalPoint();
+    QString str = locale.toString(value, 'f', prec);
+    while (str.endsWith('0') || str.endsWith(decPoint)) {
+        if (str.endsWith(decPoint)) {
+            str.chop(1);
+            break;
+        }
+        str.chop(1);
+    }
+    if (!unit.isEmpty())
+        str += (QLatin1Char(' ') + unit);
+    return str;
+}
+
+QString Utility::escape(const QString &in)
+{
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+    return Qt::escape(in);
+#else
+    return in.toHtmlEscaped();
+#endif
+}
+
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+// In Qt 4,  QThread::sleep functions are protected.
+// This is a hack to make them visible in this namespace.
+struct QThread : ::QThread
+{
+    using ::QThread::sleep;
+    using ::QThread::usleep;
+};
+#endif
+
+void Utility::sleep(int sec)
+{
+    QThread::sleep(sec);
+}
+
+void Utility::usleep(int usec)
+{
+    QThread::usleep(usec);
+}
+
+bool Utility::fsCasePreserving()
+{
+#ifdef WITH_TESTING
+    QByteArray env = qgetenv("OWNCLOUD_TEST_CASE_PRESERVING");
+    if (!env.isEmpty())
+        return env.toInt();
+#endif
+
+    return isWindows() || isMac();
+}
+
+bool Utility::fileNamesEqual(const QString &fn1, const QString &fn2)
+{
+    const QDir fd1(fn1);
+    const QDir fd2(fn2);
+
+    // Attention: If the path does not exist, canonicalPath returns ""
+    // ONLY use this function with existing pathes.
+    const QString a = fd1.canonicalPath();
+    const QString b = fd2.canonicalPath();
+    bool re = !a.isEmpty() && QString::compare(a, b, fsCasePreserving() ? Qt::CaseInsensitive : Qt::CaseSensitive) == 0;
+    return re;
+}
+
+QDateTime Utility::qDateTimeFromTime_t(qint64 t)
+{
+    return QDateTime::fromMSecsSinceEpoch(t * 1000);
+}
+
+qint64 Utility::qDateTimeToTime_t(const QDateTime &t)
+{
+    return t.toMSecsSinceEpoch() / 1000;
+}
+
+namespace {
+    struct Period
+    {
+        const char *name;
+        quint64 msec;
+
+        QString description(quint64 value) const
+        {
+            return QCoreApplication::translate(
+                "Utility", name, 0, QCoreApplication::UnicodeUTF8,
+                value);
+        }
+    };
+// QTBUG-3945 and issue #4855: QT_TRANSLATE_NOOP does not work with plural form because lupdate
+// limitation unless we fake more arguments
+// (it must be in the form ("context", "source", "comment", n)
+#undef QT_TRANSLATE_NOOP
+#define QT_TRANSLATE_NOOP(ctx, str, ...) str
+    Q_DECL_CONSTEXPR Period periods[] = {
+        { QT_TRANSLATE_NOOP("Utility", "%n year(s)", 0, _), 365 * 24 * 3600 * 1000LL },
+        { QT_TRANSLATE_NOOP("Utility", "%n month(s)", 0, _), 30 * 24 * 3600 * 1000LL },
+        { QT_TRANSLATE_NOOP("Utility", "%n day(s)", 0, _), 24 * 3600 * 1000LL },
+        { QT_TRANSLATE_NOOP("Utility", "%n hour(s)", 0, _), 3600 * 1000LL },
+        { QT_TRANSLATE_NOOP("Utility", "%n minute(s)", 0, _), 60 * 1000LL },
+        { QT_TRANSLATE_NOOP("Utility", "%n second(s)", 0, _), 1000LL },
+        { 0, 0 }
+    };
+} // anonymous namespace
+
+QString Utility::durationToDescriptiveString2(quint64 msecs)
+{
+    int p = 0;
+    while (periods[p + 1].name && msecs < periods[p].msec) {
+        p++;
+    }
+
+    auto firstPart = periods[p].description(int(msecs / periods[p].msec));
+
+    if (!periods[p + 1].name) {
+        return firstPart;
+    }
+
+    quint64 secondPartNum = qRound(double(msecs % periods[p].msec) / periods[p + 1].msec);
+
+    if (secondPartNum == 0) {
+        return firstPart;
+    }
+
+    return QCoreApplication::translate("Utility", "%1 %2").arg(firstPart, periods[p + 1].description(secondPartNum));
+}
+
+QString Utility::durationToDescriptiveString1(quint64 msecs)
+{
+    int p = 0;
+    while (periods[p + 1].name && msecs < periods[p].msec) {
+        p++;
+    }
+
+    quint64 amount = qRound(double(msecs) / periods[p].msec);
+    return periods[p].description(amount);
+}
+
+QString Utility::fileNameForGuiUse(const QString &fName)
+{
+    if (isMac()) {
+        QString n(fName);
+        return n.replace(QChar(':'), QChar('/'));
+    }
+    return fName;
+}
+
+bool Utility::hasDarkSystray()
+{
+    return hasDarkSystray_private();
+}
+
+
+QString Utility::platformName()
+{
+    QString re("Windows");
+
+#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
+    if (isMac()) {
+        re = QLatin1String("MacOSX");
+    } else if (isLinux()) {
+        re = QLatin1String("Linux");
+    } else if (isBSD()) {
+        re = QLatin1String("BSD");
+    } else if (isUnix()) {
+        re = QLatin1String("Unix");
+    }
+#else
+    re = QSysInfo::prettyProductName();
+#endif
+    return re;
+}
+
+void Utility::crash()
+{
+    volatile int *a = (int *)(NULL);
+    *a = 1;
+}
+
+// read the output of the owncloud --version command from the owncloud
+// version that is on disk. This works for most versions of the client,
+// because clients that do not yet know the --version flag return the
+// version in the first line of the help output :-)
+//
+// This version only delivers output on linux, as Mac and Win get their
+// restarting from the installer.
+QByteArray Utility::versionOfInstalledBinary(const QString &command)
+{
+    QByteArray re;
+    if (isLinux()) {
+        QString binary(command);
+        if (binary.isEmpty()) {
+            binary = qApp->arguments()[0];
+        }
+        QStringList params;
+        params << QLatin1String("--version");
+        QProcess process;
+        process.start(binary, params);
+        process.waitForFinished(); // sets current thread to sleep and waits for pingProcess end
+        re = process.readAllStandardOutput();
+        int newline = re.indexOf(QChar('\n'));
+        if (newline > 0) {
+            re.truncate(newline);
+        }
+    }
+    return re;
+}
+
+QString Utility::timeAgoInWords(const QDateTime &dt, const QDateTime &from)
+{
+    QDateTime now = QDateTime::currentDateTimeUtc();
+
+    if (from.isValid()) {
+        now = from;
+    }
+
+    if (dt.daysTo(now) > 0) {
+        int dtn = dt.daysTo(now);
+        return QObject::tr("%n day(s) ago", "", dtn);
+    } else {
+        qint64 secs = dt.secsTo(now);
+        if (secs < 0) {
+            return QObject::tr("in the future");
+        }
+        if (floor(secs / 3600.0) > 0) {
+            int hours = floor(secs / 3600.0);
+            return (QObject::tr("%n hour(s) ago", "", hours));
+        } else {
+            int minutes = qRound(secs / 60.0);
+            if (minutes == 0) {
+                if (secs < 5) {
+                    return QObject::tr("now");
+                } else {
+                    return QObject::tr("Less than a minute ago");
+                }
+            }
+            return (QObject::tr("%n minute(s) ago", "", minutes));
+        }
+    }
+    return QObject::tr("Some time ago");
+}
+
+/* --------------------------------------------------------------------------- */
+
+static const char STOPWATCH_END_TAG[] = "_STOPWATCH_END";
+
+void Utility::StopWatch::start()
+{
+    _startTime = QDateTime::currentDateTime();
+    _timer.start();
+}
+
+quint64 Utility::StopWatch::stop()
+{
+    addLapTime(QLatin1String(STOPWATCH_END_TAG));
+    quint64 duration = _timer.elapsed();
+    _timer.invalidate();
+    return duration;
+}
+
+void Utility::StopWatch::reset()
+{
+    _timer.invalidate();
+    _startTime.setMSecsSinceEpoch(0);
+    _lapTimes.clear();
+}
+
+quint64 Utility::StopWatch::addLapTime(const QString &lapName)
+{
+    if (!_timer.isValid()) {
+        start();
+    }
+    quint64 re = _timer.elapsed();
+    _lapTimes[lapName] = re;
+    return re;
+}
+
+QDateTime Utility::StopWatch::startTime() const
+{
+    return _startTime;
+}
+
+QDateTime Utility::StopWatch::timeOfLap(const QString &lapName) const
+{
+    quint64 t = durationOfLap(lapName);
+    if (t) {
+        QDateTime re(_startTime);
+        return re.addMSecs(t);
+    }
+
+    return QDateTime();
+}
+
+quint64 Utility::StopWatch::durationOfLap(const QString &lapName) const
+{
+    return _lapTimes.value(lapName, 0);
+}
+
+void Utility::sortFilenames(QStringList &fileNames)
+{
+#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
+    QCollator collator;
+    collator.setNumericMode(true);
+    collator.setCaseSensitivity(Qt::CaseInsensitive);
+    qSort(fileNames.begin(), fileNames.end(), collator);
+#elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+    fileNames.sort(Qt::CaseInsensitive);
+#else
+    fileNames.sort();
+#endif
+}
+
+QUrl Utility::concatUrlPath(const QUrl &url, const QString &concatPath,
+    const QList<QPair<QString, QString>> &queryItems)
+{
+    QString path = url.path();
+    if (!concatPath.isEmpty()) {
+        // avoid '//'
+        if (path.endsWith('/') && concatPath.startsWith('/')) {
+            path.chop(1);
+        } // avoid missing '/'
+        else if (!path.endsWith('/') && !concatPath.startsWith('/')) {
+            path += QLatin1Char('/');
+        }
+        path += concatPath; // put the complete path together
+    }
+
+    QUrl tmpUrl = url;
+    tmpUrl.setPath(path);
+    if (queryItems.size() > 0) {
+        tmpUrl.setQueryItems(queryItems);
+    }
+    return tmpUrl;
+}
+
+} // namespace OCC
diff --git a/src/common/utility.h b/src/common/utility.h
new file mode 100644 (file)
index 0000000..c1063a4
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
+ * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef UTILITY_H
+#define UTILITY_H
+
+#include "ocsynclib.h"
+#include <QString>
+#include <QByteArray>
+#include <QDateTime>
+#include <QElapsedTimer>
+#include <QLoggingCategory>
+#include <QMap>
+#include <QUrl>
+#include <memory>
+
+class QSettings;
+
+namespace OCC {
+
+Q_DECLARE_LOGGING_CATEGORY(lcUtility)
+
+/** \addtogroup libsync
+ *  @{
+ */
+namespace Utility {
+    OCSYNC_EXPORT void sleep(int sec);
+    OCSYNC_EXPORT void usleep(int usec);
+    OCSYNC_EXPORT QString formatFingerprint(const QByteArray &, bool colonSeparated = true);
+    OCSYNC_EXPORT void setupFavLink(const QString &folder);
+    OCSYNC_EXPORT bool writeRandomFile(const QString &fname, int size = -1);
+    OCSYNC_EXPORT QString octetsToString(qint64 octets);
+    OCSYNC_EXPORT QByteArray userAgentString();
+    OCSYNC_EXPORT bool hasLaunchOnStartup(const QString &appName);
+    OCSYNC_EXPORT void setLaunchOnStartup(const QString &appName, const QString &guiName, bool launch);
+
+    /**
+     * Return the amount of free space available.
+     *
+     * \a path must point to a directory
+     */
+    OCSYNC_EXPORT qint64 freeDiskSpace(const QString &path);
+
+    /**
+     * @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.
+     */
+    OCSYNC_EXPORT QString compactFormatDouble(double value, int prec, const QString &unit = QString::null);
+
+    // porting methods
+    OCSYNC_EXPORT QString escape(const QString &);
+
+    // conversion function QDateTime <-> time_t   (because the ones builtin work on only unsigned 32bit)
+    OCSYNC_EXPORT QDateTime qDateTimeFromTime_t(qint64 t);
+    OCSYNC_EXPORT qint64 qDateTimeToTime_t(const QDateTime &t);
+
+    /**
+     * @brief Convert milliseconds duration to human readable string.
+     * @param quint64 msecs the milliseconds to convert to string.
+     * @return an HMS representation of the milliseconds value.
+     *
+     * durationToDescriptiveString1 describes the duration in a single
+     * unit, like "5 minutes" or "2 days".
+     *
+     * durationToDescriptiveString2 uses two units where possible, so
+     * "5 minutes 43 seconds" or "1 month 3 days".
+     */
+    OCSYNC_EXPORT QString durationToDescriptiveString1(quint64 msecs);
+    OCSYNC_EXPORT QString durationToDescriptiveString2(quint64 msecs);
+
+    /**
+     * @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.
+     */
+    OCSYNC_EXPORT bool hasDarkSystray();
+
+    // convenience OS detection methods
+    inline bool isWindows();
+    inline bool isMac();
+    inline bool isUnix();
+    inline bool isLinux(); // use with care
+    inline bool isBSD(); // use with care, does not match OS X
+
+    OCSYNC_EXPORT QString platformName();
+    // crash helper for --debug
+    OCSYNC_EXPORT void crash();
+
+    // 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.
+    OCSYNC_EXPORT bool fsCasePreserving();
+
+    // Check if two pathes that MUST exist are equal. This function
+    // uses QDir::canonicalPath() to judge and cares for the systems
+    // case sensitivity.
+    OCSYNC_EXPORT bool fileNamesEqual(const QString &fn1, const QString &fn2);
+
+    // Call the given command with the switch --version and rerun the first line
+    // of the output.
+    // If command is empty, the function calls the running application which, on
+    // Linux, might have changed while this one is running.
+    // For Mac and Windows, it returns QString()
+    OCSYNC_EXPORT QByteArray versionOfInstalledBinary(const QString &command = QString());
+
+    OCSYNC_EXPORT QString fileNameForGuiUse(const QString &fName);
+
+    /**
+     * @brief timeAgoInWords - human readable time span
+     *
+     * Use this to get a string that describes the timespan between the first and
+     * the second timestamp in a human readable and understandable form.
+     *
+     * If the second parameter is ommitted, the current time is used.
+     */
+    OCSYNC_EXPORT QString timeAgoInWords(const QDateTime &dt, const QDateTime &from = QDateTime());
+
+    class OCSYNC_EXPORT StopWatch
+    {
+    private:
+        QMap<QString, quint64> _lapTimes;
+        QDateTime _startTime;
+        QElapsedTimer _timer;
+
+    public:
+        void start();
+        quint64 stop();
+        quint64 addLapTime(const QString &lapName);
+        void reset();
+
+        // out helpers, return the measured times.
+        QDateTime startTime() const;
+        QDateTime timeOfLap(const QString &lapName) const;
+        quint64 durationOfLap(const QString &lapName) const;
+    };
+
+    /**
+     * @brief Sort a QStringList in a way that's appropriate for filenames
+     */
+    OCSYNC_EXPORT void sortFilenames(QStringList &fileNames);
+
+    /** Appends concatPath and queryItems to the url */
+    OCSYNC_EXPORT QUrl concatUrlPath(
+        const QUrl &url, const QString &concatPath,
+        const QList<QPair<QString, QString>> &queryItems = (QList<QPair<QString, QString>>()));
+
+    /**  Returns a new settings pre-set in a specific group.  The Settings will be created
+         with the given parent. If no parent is specified, the caller must destroy the settings */
+    OCSYNC_EXPORT std::unique_ptr<QSettings> settingsWithGroup(const QString &group, QObject *parent = 0);
+}
+/** @} */ // \addtogroup
+
+inline bool Utility::isWindows()
+{
+#ifdef Q_OS_WIN
+    return true;
+#else
+    return false;
+#endif
+}
+
+inline bool Utility::isMac()
+{
+#ifdef Q_OS_MAC
+    return true;
+#else
+    return false;
+#endif
+}
+
+inline bool Utility::isUnix()
+{
+#ifdef Q_OS_UNIX
+    return true;
+#else
+    return false;
+#endif
+}
+
+inline bool Utility::isLinux()
+{
+#if defined(Q_OS_LINUX)
+    return true;
+#else
+    return false;
+#endif
+}
+
+inline bool Utility::isBSD()
+{
+#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD)
+    return true;
+#else
+    return false;
+#endif
+}
+
+}
+#endif // UTILITY_H
diff --git a/src/common/utility_mac.cpp b/src/common/utility_mac.cpp
new file mode 100644 (file)
index 0000000..6c789b1
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <CoreServices/CoreServices.h>
+#include <CoreFoundation/CoreFoundation.h>
+
+namespace OCC {
+
+static void setupFavLink_private(const QString &folder)
+{
+    // Finder: Place under "Places"/"Favorites" on the left sidebar
+    CFStringRef folderCFStr = CFStringCreateWithCString(0, folder.toUtf8().data(), kCFStringEncodingUTF8);
+    CFURLRef urlRef = CFURLCreateWithFileSystemPath(0, folderCFStr, kCFURLPOSIXPathStyle, true);
+
+    LSSharedFileListRef placesItems = LSSharedFileListCreate(0, kLSSharedFileListFavoriteItems, 0);
+    if (placesItems) {
+        //Insert an item to the list.
+        LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(placesItems,
+            kLSSharedFileListItemLast, 0, 0,
+            urlRef, 0, 0);
+        if (item)
+            CFRelease(item);
+    }
+    CFRelease(placesItems);
+    CFRelease(folderCFStr);
+    CFRelease(urlRef);
+}
+
+bool hasLaunchOnStartup_private(const QString &)
+{
+    // this is quite some duplicate code with setLaunchOnStartup, at some point we should fix this FIXME.
+    bool returnValue = false;
+    QString filePath = QDir(QCoreApplication::applicationDirPath() + QLatin1String("/../..")).absolutePath();
+    CFStringRef folderCFStr = CFStringCreateWithCString(0, filePath.toUtf8().data(), kCFStringEncodingUTF8);
+    CFURLRef urlRef = CFURLCreateWithFileSystemPath(0, folderCFStr, kCFURLPOSIXPathStyle, true);
+    LSSharedFileListRef loginItems = LSSharedFileListCreate(0, kLSSharedFileListSessionLoginItems, 0);
+    if (loginItems) {
+        // We need to iterate over the items and check which one is "ours".
+        UInt32 seedValue;
+        CFArrayRef itemsArray = LSSharedFileListCopySnapshot(loginItems, &seedValue);
+        CFStringRef appUrlRefString = CFURLGetString(urlRef); // no need for release
+        for (int i = 0; i < CFArrayGetCount(itemsArray); i++) {
+            LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(itemsArray, i);
+            CFURLRef itemUrlRef = NULL;
+
+            if (LSSharedFileListItemResolve(item, 0, &itemUrlRef, NULL) == noErr) {
+                CFStringRef itemUrlString = CFURLGetString(itemUrlRef);
+                if (CFStringCompare(itemUrlString, appUrlRefString, 0) == kCFCompareEqualTo) {
+                    returnValue = true;
+                }
+                CFRelease(itemUrlRef);
+            }
+        }
+        CFRelease(itemsArray);
+    }
+    CFRelease(loginItems);
+    CFRelease(folderCFStr);
+    CFRelease(urlRef);
+    return returnValue;
+}
+
+void setLaunchOnStartup_private(const QString &appName, const QString &guiName, bool enable)
+{
+    Q_UNUSED(appName)
+    Q_UNUSED(guiName)
+    QString filePath = QDir(QCoreApplication::applicationDirPath() + QLatin1String("/../..")).absolutePath();
+    CFStringRef folderCFStr = CFStringCreateWithCString(0, filePath.toUtf8().data(), kCFStringEncodingUTF8);
+    CFURLRef urlRef = CFURLCreateWithFileSystemPath(0, folderCFStr, kCFURLPOSIXPathStyle, true);
+    LSSharedFileListRef loginItems = LSSharedFileListCreate(0, kLSSharedFileListSessionLoginItems, 0);
+
+    if (loginItems && enable) {
+        //Insert an item to the list.
+        LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems,
+            kLSSharedFileListItemLast, 0, 0,
+            urlRef, 0, 0);
+        if (item)
+            CFRelease(item);
+        CFRelease(loginItems);
+    } else if (loginItems && !enable) {
+        // We need to iterate over the items and check which one is "ours".
+        UInt32 seedValue;
+        CFArrayRef itemsArray = LSSharedFileListCopySnapshot(loginItems, &seedValue);
+        CFStringRef appUrlRefString = CFURLGetString(urlRef);
+        for (int i = 0; i < CFArrayGetCount(itemsArray); i++) {
+            LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(itemsArray, i);
+            CFURLRef itemUrlRef = NULL;
+
+            if (LSSharedFileListItemResolve(item, 0, &itemUrlRef, NULL) == noErr) {
+                CFStringRef itemUrlString = CFURLGetString(itemUrlRef);
+                if (CFStringCompare(itemUrlString, appUrlRefString, 0) == kCFCompareEqualTo) {
+                    LSSharedFileListItemRemove(loginItems, item); // remove it!
+                }
+                CFRelease(itemUrlRef);
+            }
+        }
+        CFRelease(itemsArray);
+        CFRelease(loginItems);
+    };
+
+    CFRelease(folderCFStr);
+    CFRelease(urlRef);
+}
+
+static bool hasDarkSystray_private()
+{
+    bool returnValue = false;
+    CFStringRef interfaceStyleKey = CFSTR("AppleInterfaceStyle");
+    CFStringRef interfaceStyle = NULL;
+    CFStringRef darkInterfaceStyle = CFSTR("Dark");
+    interfaceStyle = (CFStringRef)CFPreferencesCopyAppValue(interfaceStyleKey,
+        kCFPreferencesCurrentApplication);
+    if (interfaceStyle != NULL) {
+        returnValue = (kCFCompareEqualTo == CFStringCompare(interfaceStyle, darkInterfaceStyle, 0));
+        CFRelease(interfaceStyle);
+    }
+    return returnValue;
+}
+
+} // namespace OCC
diff --git a/src/common/utility_unix.cpp b/src/common/utility_unix.cpp
new file mode 100644 (file)
index 0000000..eecef17
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
+ * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#include <QStandardPaths>
+#endif
+
+namespace OCC {
+
+static void setupFavLink_private(const QString &folder)
+{
+    // Nautilus: add to ~/.gtk-bookmarks
+    QFile gtkBookmarks(QDir::homePath() + QLatin1String("/.gtk-bookmarks"));
+    QByteArray folderUrl = "file://" + folder.toUtf8();
+    if (gtkBookmarks.open(QFile::ReadWrite)) {
+        QByteArray places = gtkBookmarks.readAll();
+        if (!places.contains(folderUrl)) {
+            places += folderUrl;
+            gtkBookmarks.reset();
+            gtkBookmarks.write(places + '\n');
+        }
+    }
+}
+
+// returns the autostart directory the linux way
+// and respects the XDG_CONFIG_HOME env variable
+QString getUserAutostartDir_private()
+{
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+    QString config = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
+#else
+    QString config = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
+
+    if (config.isEmpty()) {
+        config = QDir::homePath() + QLatin1String("/.config");
+    }
+#endif
+    config += QLatin1String("/autostart/");
+    return config;
+}
+
+bool hasLaunchOnStartup_private(const QString &appName)
+{
+    QString desktopFileLocation = getUserAutostartDir_private() + appName + QLatin1String(".desktop");
+    return QFile::exists(desktopFileLocation);
+}
+
+void setLaunchOnStartup_private(const QString &appName, const QString &guiName, bool enable)
+{
+    QString userAutoStartPath = getUserAutostartDir_private();
+    QString desktopFileLocation = userAutoStartPath + appName + QLatin1String(".desktop");
+    if (enable) {
+        if (!QDir().exists(userAutoStartPath) && !QDir().mkpath(userAutoStartPath)) {
+            qCWarning(lcUtility) << "Could not create autostart folder";
+            return;
+        }
+        QFile iniFile(desktopFileLocation);
+        if (!iniFile.open(QIODevice::WriteOnly)) {
+            qCWarning(lcUtility) << "Could not write auto start entry" << desktopFileLocation;
+            return;
+        }
+        QTextStream ts(&iniFile);
+        ts.setCodec("UTF-8");
+        ts << QLatin1String("[Desktop Entry]") << endl
+           << QLatin1String("Name=") << guiName << endl
+           << QLatin1String("GenericName=") << QLatin1String("File Synchronizer") << endl
+           << QLatin1String("Exec=") << QCoreApplication::applicationFilePath() << endl
+           << QLatin1String("Terminal=") << "false" << endl
+           << QLatin1String("Icon=") << appName.toLower() << endl // always use lowercase for icons
+           << QLatin1String("Categories=") << QLatin1String("Network") << endl
+           << QLatin1String("Type=") << QLatin1String("Application") << endl
+           << QLatin1String("StartupNotify=") << "false" << endl
+           << QLatin1String("X-GNOME-Autostart-enabled=") << "true" << endl;
+    } else {
+        if (!QFile::remove(desktopFileLocation)) {
+            qCWarning(lcUtility) << "Could not remove autostart desktop file";
+        }
+    }
+}
+
+static inline bool hasDarkSystray_private()
+{
+    return true;
+}
+
+} // namespace OCC
diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp
new file mode 100644 (file)
index 0000000..f7fef10
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define _WIN32_WINNT 0x0600
+#define WINVER 0x0600
+#include <shlobj.h>
+#include <winbase.h>
+#include <windows.h>
+#include <winerror.h>
+#include <shlguid.h>
+#include <string>
+#include <QLibrary>
+
+static const char runPathC[] = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
+
+namespace OCC {
+
+static void setupFavLink_private(const QString &folder)
+{
+    // First create a Desktop.ini so that the folder and favorite link show our application's icon.
+    QFile desktopIni(folder + QLatin1String("/Desktop.ini"));
+    if (desktopIni.exists()) {
+        qCWarning(lcUtility) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon.";
+    } else {
+        qCInfo(lcUtility) << "Creating" << desktopIni.fileName() << "to set a folder icon in Explorer.";
+        desktopIni.open(QFile::WriteOnly);
+        desktopIni.write("[.ShellClassInfo]\r\nIconResource=");
+        desktopIni.write(QDir::toNativeSeparators(qApp->applicationFilePath()).toUtf8());
+        desktopIni.write(",0\r\n");
+        desktopIni.close();
+    }
+
+    // Windows Explorer: Place under "Favorites" (Links)
+    QString linkName;
+    QDir folderDir(QDir::fromNativeSeparators(folder));
+
+    /* Use new WINAPI functions */
+    PWSTR path;
+
+    if (SHGetKnownFolderPath(FOLDERID_Links, 0, NULL, &path) == S_OK) {
+        QString links = QDir::fromNativeSeparators(QString::fromWCharArray(path));
+        linkName = QDir(links).filePath(folderDir.dirName() + QLatin1String(".lnk"));
+        CoTaskMemFree(path);
+    }
+    qCInfo(lcUtility) << "Creating favorite link from" << folder << "to" << linkName;
+    if (!QFile::link(folder, linkName))
+        qCWarning(lcUtility) << "linking" << folder << "to" << linkName << "failed!";
+}
+
+
+bool hasLaunchOnStartup_private(const QString &appName)
+{
+    QString runPath = QLatin1String(runPathC);
+    QSettings settings(runPath, QSettings::NativeFormat);
+    return settings.contains(appName);
+}
+
+void setLaunchOnStartup_private(const QString &appName, const QString &guiName, bool enable)
+{
+    Q_UNUSED(guiName);
+    QString runPath = QLatin1String(runPathC);
+    QSettings settings(runPath, QSettings::NativeFormat);
+    if (enable) {
+        settings.setValue(appName, QCoreApplication::applicationFilePath().replace('/', '\\'));
+    } else {
+        settings.remove(appName);
+    }
+}
+
+static inline bool hasDarkSystray_private()
+{
+    return true;
+}
+
+} // namespace OCC
index 09f320202cc10edaa91f00f66bfba4e1c2b375e5..b9c7725070e12ed772a262186110128184d04226 100644 (file)
@@ -20,6 +20,7 @@ include(MacroCopyFile)
 find_package(SQLite3 3.8.0 REQUIRED)
 
 include(ConfigureChecks.cmake)
+include(../common/common.cmake)
 
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
@@ -117,11 +118,10 @@ include_directories(
   ${CSYNC_PRIVATE_INCLUDE_DIRS}
 )
 
-add_library(${CSYNC_LIBRARY} SHARED ${csync_SRCS})
+add_library(${CSYNC_LIBRARY} SHARED ${common_SOURCES} ${csync_SRCS})
 #add_library(${CSYNC_LIBRARY}_static STATIC ${csync_SRCS})
 
 generate_export_header( ${CSYNC_LIBRARY}
-  BASE_NAME ${CSYNC_LIBRARY}
   EXPORT_MACRO_NAME OCSYNC_EXPORT
   EXPORT_FILE_NAME ocsynclib.h
 )
@@ -129,6 +129,16 @@ generate_export_header( ${CSYNC_LIBRARY}
 target_link_libraries(${CSYNC_LIBRARY} ${CSYNC_LINK_LIBRARIES})
 #target_link_libraries(${CSYNC_LIBRARY}_static ${CSYNC_LINK_LIBRARIES})
 
+find_package(Qt5Core REQUIRED)
+qt5_use_modules(${CSYNC_LIBRARY} Core)
+
+# For src/common/utility_mac.cpp
+if (APPLE)
+    find_library(FOUNDATION_LIBRARY NAMES Foundation)
+    find_library(CORESERVICES_LIBRARY NAMES CoreServices)
+    target_link_libraries(${CSYNC_LIBRARY} ${FOUNDATION_LIBRARY} ${CORESERVICES_LIBRARY})
+endif()
+
 set_target_properties(
   ${CSYNC_LIBRARY}
     PROPERTIES
index 8cfd48531c1ecd2b948a53946d3af575565fe65d..ef7a25bd3c0332a2095346961c0c6f6f214392ec 100644 (file)
@@ -36,9 +36,5 @@ include_directories(
 add_library(${CSTDLIB_LIBRARY} STATIC ${cstdlib_SRCS})
 if(NOT WIN32)
     add_definitions( -fPIC )
-    qt5_use_modules(${CSTDLIB_LIBRARY} Core)
-endif()
-if(NOT HAVE_FNMATCH AND WIN32)
-  # needed for PathMatchSpec for our fnmatch replacement
-  target_link_libraries(${CSTDLIB_LIBRARY} ${SHLWAPI_LIBRARY})
 endif()
+qt5_use_modules(${CSTDLIB_LIBRARY} Core)
index fe8d98127866bdb63e6b5a27de6131a3b6d05e34..a62e1f30fd3e7f7cd5f271cd00d1cc2415535890 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include "accountmanager.h"
+#include "configfile.h"
 #include "sslerrordialog.h"
 #include "proxyauthhandler.h"
 #include <theme.h>
@@ -47,7 +48,7 @@ AccountManager *AccountManager::instance()
 
 bool AccountManager::restore()
 {
-    auto settings = Utility::settingsWithGroup(QLatin1String(accountsC));
+    auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC));
     if (settings->status() != QSettings::NoError) {
         qCWarning(lcAccountManager) << "Could not read settings from" << settings->fileName()
                                     << settings->status();
@@ -81,7 +82,7 @@ bool AccountManager::restoreFromLegacySettings()
                              << Theme::instance()->appName();
 
     // try to open the correctly themed settings
-    auto settings = Utility::settingsWithGroup(Theme::instance()->appName());
+    auto settings = ConfigFile::settingsWithGroup(Theme::instance()->appName());
 
     // if the settings file could not be opened, the childKeys list is empty
     // then try to load settings from a very old place
@@ -134,7 +135,7 @@ bool AccountManager::restoreFromLegacySettings()
 
 void AccountManager::save(bool saveCredentials)
 {
-    auto settings = Utility::settingsWithGroup(QLatin1String(accountsC));
+    auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC));
     settings->setValue(QLatin1String(versionC), 2);
     foreach (const auto &acc, _accounts) {
         settings->beginGroup(acc->account()->id());
@@ -150,7 +151,7 @@ void AccountManager::save(bool saveCredentials)
 void AccountManager::saveAccount(Account *a)
 {
     qCInfo(lcAccountManager) << "Saving account" << a->url().toString();
-    auto settings = Utility::settingsWithGroup(QLatin1String(accountsC));
+    auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC));
     settings->beginGroup(a->id());
     saveAccountHelper(a, *settings, false); // don't save credentials they might not have been loaded yet
     settings->endGroup();
@@ -162,7 +163,7 @@ void AccountManager::saveAccount(Account *a)
 void AccountManager::saveAccountState(AccountState *a)
 {
     qCInfo(lcAccountManager) << "Saving account state" << a->account()->url().toString();
-    auto settings = Utility::settingsWithGroup(QLatin1String(accountsC));
+    auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC));
     settings->beginGroup(a->account()->id());
     a->writeToSettings(*settings);
     settings->endGroup();
@@ -308,7 +309,7 @@ void AccountManager::deleteAccount(AccountState *account)
     account->account()->credentials()->forgetSensitiveData();
     QFile::remove(account->account()->cookieJarPath());
 
-    auto settings = Utility::settingsWithGroup(QLatin1String(accountsC));
+    auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC));
     settings->remove(account->account()->id());
 
     emit accountRemoved(account);
index a5a5e105dc8aeaf3b18df8f452f2ce1d4dc41897..453ace4129a4f2939ed168c4f4947b52d5c2ade3 100644 (file)
@@ -21,7 +21,7 @@
 #include "folderwizard.h"
 #include "folderstatusmodel.h"
 #include "folderstatusdelegate.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "application.h"
 #include "configfile.h"
 #include "account.h"
index 63316f6d2dc77c1b0274171821700b3950495e4b..a13b8c2272b2372c2ec727502566efadb6fa0ca4 100644 (file)
@@ -356,7 +356,7 @@ void AccountState::slotCredentialsAsked(AbstractCredentials *credentials)
 
 std::unique_ptr<QSettings> AccountState::settings()
 {
-    auto s = Utility::settingsWithGroup(QLatin1String("Accounts"));
+    auto s = ConfigFile::settingsWithGroup(QLatin1String("Accounts"));
     s->beginGroup(_account->id());
     return s;
 }
index ce36c94fbe78b8307f47411bfe3e3d672aebde30..03f17795f5236c6c26de5c318aabcf3c93baf4aa 100644 (file)
@@ -17,8 +17,8 @@
 #define ACCOUNTINFO_H
 
 #include <QByteArray>
+#include <QElapsedTimer>
 #include <QPointer>
-#include "utility.h"
 #include "connectionvalidator.h"
 #include "creds/abstractcredentials.h"
 #include <memory>
index 8de739eb794d420d8fc815e73c3ba7cdc9c3267f..ee59e422dfe67a4c9b8116e90526a070b4d795b9 100644 (file)
@@ -18,7 +18,6 @@
 #include "folderstatusmodel.h"
 #include "folderman.h"
 #include "accountstate.h"
-#include "utility.h"
 #include <theme.h>
 #include <account.h>
 
index c4e82884b11073e1c60e7566ce22243c26e53164..d9acc999f08004bfb7f6223fde5a4662cf197b86 100644 (file)
@@ -21,7 +21,6 @@
 #include "activitywidget.h"
 #include "syncresult.h"
 #include "logger.h"
-#include "utility.h"
 #include "theme.h"
 #include "folderman.h"
 #include "syncfileitem.h"
index f06054b3f31c9855bb28b24ec1d28c2f8133095f..37d24cec7f61587aebebdb61d64a50810b73952b 100644 (file)
@@ -30,7 +30,6 @@
 #include "socketapi.h"
 #include "sslerrordialog.h"
 #include "theme.h"
-#include "utility.h"
 #include "clientproxy.h"
 #include "sharedialog.h"
 #include "accountmanager.h"
index b7fca6dd3d5043deb129d20d511c02854208a9a8..44c0e217a9315daec460fc5bf088326b2dcd20b9 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "accessmanager.h"
 #include "account.h"
+#include "configfile.h"
 #include "theme.h"
 #include "cookiejar.h"
 #include "owncloudgui.h"
@@ -131,7 +132,7 @@ void ShibbolethCredentials::fetchFromKeychain()
     } else {
         _url = _account->url();
         ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
-        job->setSettings(Utility::settingsWithGroup(Theme::instance()->appName(), job).release());
+        job->setSettings(ConfigFile::settingsWithGroup(Theme::instance()->appName(), job).release());
         job->setInsecureFallback(false);
         job->setKey(keychainKey(_account->url().toString(), user()));
         connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotReadJobDone(QKeychain::Job *)));
@@ -250,7 +251,7 @@ void ShibbolethCredentials::slotReadJobDone(QKeychain::Job *job)
             addToCookieJar(_shibCookie);
         }
         // access
-        job->setSettings(Utility::settingsWithGroup(Theme::instance()->appName(), job).release());
+        job->setSettings(ConfigFile::settingsWithGroup(Theme::instance()->appName(), job).release());
 
         _ready = true;
         _stillValid = true;
@@ -309,7 +310,7 @@ QByteArray ShibbolethCredentials::shibCookieName()
 void ShibbolethCredentials::storeShibCookie(const QNetworkCookie &cookie)
 {
     WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName());
-    job->setSettings(Utility::settingsWithGroup(Theme::instance()->appName(), job).release());
+    job->setSettings(ConfigFile::settingsWithGroup(Theme::instance()->appName(), job).release());
     // we don't really care if it works...
     //connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotWriteJobDone(QKeychain::Job*)));
     job->setKey(keychainKey(_account->url().toString(), user()));
@@ -320,7 +321,7 @@ void ShibbolethCredentials::storeShibCookie(const QNetworkCookie &cookie)
 void ShibbolethCredentials::removeShibCookie()
 {
     DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
-    job->setSettings(Utility::settingsWithGroup(Theme::instance()->appName(), job).release());
+    job->setSettings(ConfigFile::settingsWithGroup(Theme::instance()->appName(), job).release());
     job->setKey(keychainKey(_account->url().toString(), user()));
     job->start();
 }
index 4ca5de844fb4b63c0d95f8a5b5d693668007c5f5..6446a06ed3afb3628b6f6d58ab7c218a759cc3a3 100644 (file)
@@ -24,7 +24,6 @@
 #include "networkjobs.h"
 #include "syncjournalfilerecord.h"
 #include "syncresult.h"
-#include "utility.h"
 #include "clientproxy.h"
 #include "syncengine.h"
 #include "syncrunfilelog.h"
index a1f1286a9e04d00702e4c0b25bd481ef544d9785..bb56db2ef3722c1e69d742663fbcaa95b34ab9fe 100644 (file)
@@ -199,7 +199,7 @@ int FolderMan::setupFolders()
 {
     unloadAndDeleteAllFolders();
 
-    auto settings = Utility::settingsWithGroup(QLatin1String("Accounts"));
+    auto settings = ConfigFile::settingsWithGroup(QLatin1String("Accounts"));
     const auto accountsWithSettings = settings->childGroups();
     if (accountsWithSettings.isEmpty()) {
         int r = setupFoldersMigration();
index da41cbf939bcb58fb87173c321b13c0da4ebd576..1d5ad0a14982aa271bf68a2a1cc29f351adceada 100644 (file)
@@ -18,7 +18,6 @@
 #include "folderstatusmodel.h"
 #include "folderman.h"
 #include "accountstate.h"
-#include "utility.h"
 #include <theme.h>
 #include <account.h>
 
index ac32dc865dfa5ecc4aad4986acb83feb6d7ac223..59ad76589ea943bc0f4c877b9f0a2193d2fade23 100644 (file)
@@ -15,7 +15,6 @@
 #include "folderstatusmodel.h"
 #include "folderman.h"
 #include "accountstate.h"
-#include "utility.h"
 #include "asserts.h"
 #include <theme.h>
 #include <account.h>
index 853fd730b8c6063dc062e54f09ac8e93d968065b..a79036771ce060ffd5df621aabd8a42276832abd 100644 (file)
@@ -18,7 +18,6 @@
 #include "theme.h"
 #include "configfile.h"
 #include "application.h"
-#include "utility.h"
 #include "configfile.h"
 #include "owncloudsetupwizard.h"
 #include "accountmanager.h"
index 4803f17a4fae99c15e651cca49d23f7c3b2452f2..f434f3cd276261040bd7d8efaa67cb3b0be2f1ee 100644 (file)
@@ -21,7 +21,6 @@
 #include "configfile.h"
 #include "syncresult.h"
 #include "logger.h"
-#include "utility.h"
 #include "theme.h"
 #include "folderman.h"
 #include "syncfileitem.h"
index 4c5970a57968b44f8a82de0509e57661de05d3b2..4ee4201abc846b4b351188ff72b4bff583c522c0 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "application.h"
 #include "theme.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "cocoainitializer.h"
 
 #include "updater/updater.h"
index ff99524e187a8f36b61606124930d0aa2f895b69..2f35614a1c8c3dc49920d7314e500a94ad628327 100644 (file)
@@ -18,7 +18,6 @@
 #include "theme.h"
 #include "configfile.h"
 #include "application.h"
-#include "utility.h"
 #include "configfile.h"
 #include "folderman.h"
 
index 7d1132c6ae1cf35853e494a2bf61d37263f4d037..0457857b86f1039dab14ff118bce4106d197686a 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "notificationwidget.h"
 #include "QProgressIndicator.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "asserts.h"
 
 #include <QPushButton>
index d06402eca4e6951f7c0a41343f61fda3e376455e..e466bdc49c0b5ee7b83668aa6422c415425d6f4e 100644 (file)
@@ -14,7 +14,7 @@
  */
 
 #include "openfilemanager.h"
-#include "utility.h"
+#include "common/utility.h"
 #include <QProcess>
 #include <QSettings>
 #include <QDir>
index 65350f3677649e8439a5a5cf2c1c82d304c331be..cb0cafbd8fc8c650fe63e3fb78683b994c0f09e7 100644 (file)
@@ -17,7 +17,6 @@
 #include "theme.h"
 #include "folderman.h"
 #include "configfile.h"
-#include "utility.h"
 #include "progressdispatcher.h"
 #include "owncloudsetupwizard.h"
 #include "sharedialog.h"
index dcd510f78d7b81f1b61318dad1e5eaf281dcb247..3ee02c73a2dec49c063813a2eaf99f345f53caeb 100644 (file)
@@ -24,7 +24,6 @@
 #include "owncloudsetupwizard.h"
 #include "configfile.h"
 #include "folderman.h"
-#include "utility.h"
 #include "accessmanager.h"
 #include "account.h"
 #include "networkjobs.h"
index 2f177a1c64bcf1749be8779882282e2ea9f77aa3..c55ab67899d42bfd81f47787c5e39a65e58511a2 100644 (file)
@@ -21,7 +21,6 @@
 #include "configfile.h"
 #include "syncresult.h"
 #include "logger.h"
-#include "utility.h"
 #include "theme.h"
 #include "folderman.h"
 #include "syncfileitem.h"
index f2616d3780a32818dbb65cffdf1cde776ee18e7c..11a9711288e8fa0b084a2246a9fd59061f71513e 100644 (file)
@@ -20,7 +20,6 @@
 #include "configfile.h"
 #include "folderman.h"
 #include "folder.h"
-#include "utility.h"
 #include "theme.h"
 #include "syncjournalfilerecord.h"
 #include "syncengine.h"
index 89401c31e8c78d1118e2c857695371afd669c999..cf6a2af7d69e0d220a5052c12c53661fc495faee 100644 (file)
@@ -15,7 +15,6 @@
 #include "sslbutton.h"
 #include "account.h"
 #include "accountstate.h"
-#include "utility.h"
 #include "theme.h"
 
 #include <QMenu>
index 4f6be75d6e490ec4e7a25c65f375d35b2887e317..809be80aa60aae8229e439012aa92540d7e5132f 100644 (file)
@@ -12,7 +12,6 @@
  * for more details.
  */
 #include "configfile.h"
-#include "utility.h"
 #include "sslerrordialog.h"
 
 #include <QtGui>
index d0a5259f14f2ab1793849e6f6e639f77595f3b60..79099cd6660543220e8d7a5e897c41176252a68b 100644 (file)
@@ -15,7 +15,7 @@
 #include <QRegExp>
 
 #include "syncrunfilelog.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "filesystem.h"
 #include <qfileinfo.h>
 
index bac0da50388d9d1a2a126355afb0500970bc38ae..b904ed189a7e0b1de55cb278666797f9befcb6b9 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "theme.h"
 #include "configfile.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "accessmanager.h"
 
 #include "updater/ocupdater.h"
index 96704e81faf2221074569d9e1c229ec3b13b2f71..1b0a48648dfccb46d57565f89ee65b9be5e6f58c 100644 (file)
@@ -20,8 +20,6 @@
 
 #include "updater/sparkleupdater.h"
 
-#include "utility.h"
-
 // Does not work yet
 @interface DelegateObject : NSObject <SUUpdaterDelegate>
 - (BOOL)updaterMayCheckForUpdates:(SUUpdater *)bundle;
index 2529b261ae08b62cb7862e1c11662def1d34b3e4..8294bb4be92e3102ee33557e089c7c6256f3114c 100644 (file)
@@ -19,9 +19,9 @@
 #include "updater/sparkleupdater.h"
 #include "updater/ocupdater.h"
 
-#include "version.h"
 #include "theme.h"
-#include "utility.h"
+#include "common/utility.h"
+#include "version.h"
 
 #include "config.h"
 
index f0d670480e86010d9d2e9d2d7390958c86f6ea97..6bb865ffeecb64c5806b609be2f222517d32ac1f 100644 (file)
@@ -14,7 +14,6 @@
  */
 
 #include "wizard/owncloudconnectionmethoddialog.h"
-#include "utility.h"
 #include <QUrl>
 
 namespace OCC {
index 865dad895e876bcc57b53fd35c0509c253ed5607..a475aa3c0d294ed1df24e4f535d777f6a3af84dd 100644 (file)
@@ -1,8 +1,6 @@
 project(libsync)
 set(CMAKE_AUTOMOC TRUE)
 
-configure_file( version.h.in "${CMAKE_CURRENT_BINARY_DIR}/version.h" )
-
 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
 # csync is required.
 include_directories(${CMAKE_SOURCE_DIR}/src/csync
@@ -59,7 +57,6 @@ set(libsync_SRCS
     syncjournalfilerecord.cpp
     syncresult.cpp
     theme.cpp
-    utility.cpp
     ownsql.cpp
     checksums.cpp
     excludedfiles.cpp
index fb131b02c212795ede4939acfc1c5419edbae99f..67603f623fc585be7564a0c699f007ef712ff1e0 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "cookiejar.h"
 #include "accessmanager.h"
-#include "utility.h"
+#include "common/utility.h"
 
 namespace OCC {
 
index de1cd0293c9322f6f21c29e02052a54e0fe62445..fa2ccb8f98df04d62cc34a360c65970f5fbd5bb1 100644 (file)
@@ -28,7 +28,7 @@
 #include <QSharedPointer>
 #include <QPixmap>
 
-#include "utility.h"
+#include "common/utility.h"
 #include <memory>
 #include "capabilities.h"
 
index 2cd8d70a61ed8d0cdfbd808edd3fe00a62cf028f..97cbddd213697dc6dc9e56c677e68ce83388ac06 100644 (file)
@@ -16,7 +16,7 @@
 #include "propagatedownload.h"
 #include "propagateupload.h"
 #include "propagatorjobs.h"
-#include "utility.h"
+#include "common/utility.h"
 
 #ifdef Q_OS_WIN
 #include <windef.h>
index 923f060f78899b5535e55f7b4b991e84649aa61d..169e1fb6e8cc1640e949008e9658f7ea1bfb6fac 100644 (file)
@@ -21,7 +21,8 @@
 #include <QUrl>
 
 #include <csync.h>
-#include "utility.h"
+#include "common/utility.h"
+#include "owncloudlib.h"
 
 namespace OCC {
 
index a3bab5f1c50308a478094f0cf2543376a10f5163..0fa6b77ff18efdc38f57cb77868bc9c927d643ab 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "configfile.h"
 #include "theme.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "asserts.h"
 
 #include "creds/abstractcredentials.h"
@@ -703,4 +703,19 @@ void ConfigFile::setCertificatePasswd(const QString &cPasswd)
     settings.setValue(QLatin1String(certPasswd), cPasswd);
     settings.sync();
 }
+
+Q_GLOBAL_STATIC(QString, g_configFileName)
+
+std::unique_ptr<QSettings> ConfigFile::settingsWithGroup(const QString &group, QObject *parent)
+{
+    if (g_configFileName()->isEmpty()) {
+        // cache file name
+        ConfigFile cfg;
+        *g_configFileName() = cfg.configFile();
+    }
+    std::unique_ptr<QSettings> settings(new QSettings(*g_configFileName(), QSettings::IniFormat, parent));
+    settings->beginGroup(group);
+    return settings;
+}
+
 }
index 912b66a04b1e7e6acdff30fcd547e25795ee3e7c..b9eda8eb0cd46543a35ad4ae462257391008fb5a 100644 (file)
@@ -16,7 +16,9 @@
 #define CONFIGFILE_H
 
 #include "owncloudlib.h"
+#include <memory>
 #include <QSharedPointer>
+#include <QSettings>
 #include <QString>
 #include <QVariant>
 
@@ -137,6 +139,10 @@ public:
     QString certificatePasswd() const;
     void setCertificatePasswd(const QString &cPasswd);
 
+    /**  Returns a new settings pre-set in a specific group.  The Settings will be created
+         with the given parent. If no parent is specified, the caller must destroy the settings */
+    static std::unique_ptr<QSettings> settingsWithGroup(const QString &group, QObject *parent = 0);
+
 protected:
     QVariant getPolicySetting(const QString &policy, const QVariant &defaultValue = QVariant()) const;
     void storeData(const QString &group, const QString &key, const QVariant &value);
index 58b3cc24fa5d6da2d9f9fb3e9f66eefc6cb3a0b5..b56b8193dee1cb7b292c4653ddff6e95528882d0 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "creds/credentialscommon.h"
 
-#include "utility.h"
+#include "common/utility.h"
 #include "account.h"
 #include "syncengine.h"
 
index 0f71f445ee78ee96cf09c6f4445787590fb2a982..53215de2afd2fea4be255b8745e5b9cb998eb85e 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "account.h"
 #include "accessmanager.h"
-#include "utility.h"
+#include "configfile.h"
 #include "theme.h"
 #include "syncengine.h"
 #include "creds/credentialscommon.h"
@@ -94,7 +94,7 @@ private:
 static void addSettingsToJob(Account *account, QKeychain::Job *job)
 {
     Q_UNUSED(account);
-    auto settings = Utility::settingsWithGroup(Theme::instance()->appName());
+    auto settings = ConfigFile::settingsWithGroup(Theme::instance()->appName());
     settings->setParent(job); // make the job parent to make setting deleted properly
     job->setSettings(settings.release());
 }
index 2008542f55d007eae34ebee988c993589d30f306..c7e43bf8cecb6ed60e6448d7823bc041ab51ab6c 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "account.h"
 #include "accessmanager.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "theme.h"
 #include "creds/credentialscommon.h"
 #include "creds/tokencredentials.h"
index 289164efb78888fc778e93fd6561608992bea06e..62c4711addcdfce572459441ec9013a54e2bc683 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "config.h"
 #include "excludedfiles.h"
-#include "utility.h"
+#include "common/utility.h"
 
 #include <QFileInfo>
 
index 8299fcc04d7d0b9f89c3ea002e6dc9518ee49718..4625eed048ed5c14f58d7f041e971d211cdc0e41 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "filesystem.h"
 
-#include "utility.h"
+#include "common/utility.h"
 #include <QFile>
 #include <QFileInfo>
 #include <QLoggingCategory>
index 555abe52fbaedd71f6a0be72796f863e6db49292..bf73009a94fea598418b3856c33da5c07a96c304 100644 (file)
@@ -22,7 +22,9 @@
 #include <QTextStream>
 #include <qmutex.h>
 
-#include "utility.h"
+#include "common/utility.h"
+#include "logger.h"
+#include "owncloudlib.h"
 
 namespace OCC {
 
index 17ab9facab3855d95c245b741d0be2702e68d19e..2dcc7a26d5e7940dc698c34a96745ad14f3d3ce0 100644 (file)
@@ -23,7 +23,7 @@
 #include "propagateremotemkdir.h"
 #include "propagatorjobs.h"
 #include "configfile.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "account.h"
 #include "asserts.h"
 
index 4f30571b2423958e88d2bdcee81d82f2a3195579..9a932eefcd88eedacf92718ef110c4453b857e35 100644 (file)
@@ -24,9 +24,9 @@
 #endif
 #include <QCoreApplication>
 
-#include "version.h"
 #include "config.h"
-#include "utility.h"
+#include "common/utility.h"
+#include "version.h"
 
 namespace OCC {
 
index 69dae784776b887fa3ba8ac8182f90426a89fe09..759f1981dcad6502d9c5031afadeefdbd98fe6a1 100644 (file)
@@ -21,7 +21,7 @@
 #include <QDir>
 
 #include "ownsql.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "asserts.h"
 
 #define SQLITE_SLEEP_TIME_USEC 100000
index 2a6ca14394dc0f9cc2073e7eb63568d2f5c8d6b2..f5b1990249b0c97d5b874f90e146787e0ff3fec6 100644 (file)
@@ -19,7 +19,7 @@
 #include "account.h"
 #include "syncjournaldb.h"
 #include "syncjournalfilerecord.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "filesystem.h"
 #include "propagatorjobs.h"
 #include "checksums.h"
index 3032bb65faf8a831f4361d721627310b41c9db5a..ac6c6825950ee504aef513907c87f306bfd856d4 100644 (file)
@@ -19,7 +19,7 @@
 #include "account.h"
 #include "syncjournaldb.h"
 #include "syncjournalfilerecord.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "filesystem.h"
 #include "propagatorjobs.h"
 #include "checksums.h"
index 7717203a145e8772e0caad994f4b067f7d33fba5..00e3d0524a889c278c6a6672fd4639fa8495ade6 100644 (file)
@@ -19,7 +19,7 @@
 #include "account.h"
 #include "syncjournaldb.h"
 #include "syncjournalfilerecord.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "filesystem.h"
 #include "propagatorjobs.h"
 #include "syncengine.h"
index 74a5f6e52e1aba38c0fe6af185360cd695537298..c1182bb70fbbac48b8637f35e78d03466f638084 100644 (file)
@@ -19,7 +19,7 @@
 #include "account.h"
 #include "syncjournaldb.h"
 #include "syncjournalfilerecord.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "filesystem.h"
 #include "propagatorjobs.h"
 #include "checksums.h"
index 65d7ef86ad43d824b3b55968e25442082a900a9b..1bdee68aef5218ced8b2aac3d702c4a26e60ff63 100644 (file)
@@ -16,7 +16,7 @@
 #include "propagatorjobs.h"
 #include "owncloudpropagator_p.h"
 #include "propagateremotemove.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "syncjournaldb.h"
 #include "syncjournalfilerecord.h"
 #include "filesystem.h"
index a275618a43e6d352106367f869384def89c858bb..50e52f6f4477e4d388dac324ace9d126c6091e8a 100644 (file)
@@ -34,7 +34,7 @@
 #include "excludedfiles.h"
 #include "syncfileitem.h"
 #include "progressdispatcher.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "syncfilestatustracker.h"
 #include "accountfwd.h"
 #include "discoveryphase.h"
index e46d35db615c22090319eb78287a237b39bf32b9..6706fb65e23166b72e3bde0c7e76efa2bf90f1e9 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "syncjournaldb.h"
 #include "syncjournalfilerecord.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "version.h"
 #include "filesystem.h"
 #include "asserts.h"
index 62295f62e10816645ffe0604fa3bf6d13de89fe5..931588dfa66e13ef2244bceee63f000744db8ea5 100644 (file)
@@ -20,7 +20,7 @@
 #include <QDateTime>
 #include <QHash>
 
-#include "utility.h"
+#include "common/utility.h"
 #include "ownsql.h"
 #include "syncjournalfilerecord.h"
 
index 024c3274607d5abd78371f815f6575b7a7dbb198..9c68e646c6eb6eaa2da01bc55971693fe9c07e0e 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "syncjournalfilerecord.h"
 #include "syncfileitem.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "filesystem.h"
 
 #include <QLoggingCategory>
index 1d1391b1fc2df2f32780679cc857fe4c2fd0a2af..978efc9cb7341e7c4542636c63566feea7e684c4 100644 (file)
@@ -13,9 +13,9 @@
  */
 
 #include "theme.h"
-#include "version.h"
 #include "config.h"
-#include "utility.h"
+#include "common/utility.h"
+#include "version.h"
 
 #include <QtCore>
 #ifndef TOKEN_AUTH_ONLY
diff --git a/src/libsync/utility.cpp b/src/libsync/utility.cpp
deleted file mode 100644 (file)
index c73b48d..0000000
+++ /dev/null
@@ -1,628 +0,0 @@
-/*
- * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
- * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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.
- */
-#include "config.h"
-
-#include "utility.h"
-
-#include "version.h"
-#include "configfile.h"
-
-// Note:  This file must compile without QtGui
-#include <QCoreApplication>
-#include <QSettings>
-#include <QTextStream>
-#include <QDir>
-#include <QFile>
-#include <QUrl>
-#include <QProcess>
-#include <QObject>
-#include <QThread>
-#include <QDateTime>
-#include <QSysInfo>
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-#include <QTextDocument>
-#else
-#include <QStandardPaths>
-#endif
-#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
-#include <QCollator>
-#endif
-#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
-#include <QSysInfo>
-#endif
-
-
-#ifdef Q_OS_UNIX
-#include <sys/statvfs.h>
-#include <sys/types.h>
-#include <unistd.h>
-#endif
-
-#include <math.h>
-#include <stdarg.h>
-
-#if defined(Q_OS_WIN)
-#include "utility_win.cpp"
-#elif defined(Q_OS_MAC)
-#include "utility_mac.cpp"
-#else
-#include "utility_unix.cpp"
-#endif
-
-namespace OCC {
-
-Q_LOGGING_CATEGORY(lcUtility, "sync.utility", QtInfoMsg)
-
-bool Utility::writeRandomFile(const QString &fname, int size)
-{
-    int maxSize = 10 * 10 * 1024;
-    qsrand(QDateTime::currentMSecsSinceEpoch());
-
-    if (size == -1)
-        size = qrand() % maxSize;
-
-    QString randString;
-    for (int i = 0; i < size; i++) {
-        int r = qrand() % 128;
-        randString.append(QChar(r));
-    }
-
-    QFile file(fname);
-    if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
-        QTextStream out(&file);
-        out << randString;
-        // optional, as QFile destructor will already do it:
-        file.close();
-        return true;
-    }
-    return false;
-}
-
-QString Utility::formatFingerprint(const QByteArray &fmhash, bool colonSeparated)
-{
-    QByteArray hash;
-    int steps = fmhash.length() / 2;
-    for (int i = 0; i < steps; i++) {
-        hash.append(fmhash[i * 2]);
-        hash.append(fmhash[i * 2 + 1]);
-        hash.append(' ');
-    }
-
-    QString fp = QString::fromLatin1(hash.trimmed());
-    if (colonSeparated) {
-        fp.replace(QChar(' '), QChar(':'));
-    }
-
-    return fp;
-}
-
-void Utility::setupFavLink(const QString &folder)
-{
-    setupFavLink_private(folder);
-}
-
-QString Utility::octetsToString(qint64 octets)
-{
-#define THE_FACTOR 1024
-    static const qint64 kb = THE_FACTOR;
-    static const qint64 mb = THE_FACTOR * kb;
-    static const qint64 gb = THE_FACTOR * mb;
-
-    QString s;
-    qreal value = octets;
-
-    // Whether we care about decimals: only for GB/MB and only
-    // if it's less than 10 units.
-    bool round = true;
-
-    // do not display terra byte with the current units, as when
-    // the MB, GB and KB units were made, there was no TB,
-    // see the JEDEC standard
-    // https://en.wikipedia.org/wiki/JEDEC_memory_standards
-    if (octets >= gb) {
-        s = QCoreApplication::translate("Utility", "%L1 GB");
-        value /= gb;
-        round = false;
-    } else if (octets >= mb) {
-        s = QCoreApplication::translate("Utility", "%L1 MB");
-        value /= mb;
-        round = false;
-    } else if (octets >= kb) {
-        s = QCoreApplication::translate("Utility", "%L1 KB");
-        value /= kb;
-    } else {
-        s = QCoreApplication::translate("Utility", "%L1 B");
-    }
-
-    if (value > 9.95)
-        round = true;
-
-    if (round)
-        return s.arg(qRound(value));
-
-    return s.arg(value, 0, 'g', 2);
-}
-
-// Qtified version of get_platforms() in csync_owncloud.c
-static QLatin1String platform()
-{
-#if defined(Q_OS_WIN)
-    return QLatin1String("Windows");
-#elif defined(Q_OS_MAC)
-    return QLatin1String("Macintosh");
-#elif defined(Q_OS_LINUX)
-    return QLatin1String("Linux");
-#elif defined(__DragonFly__) // Q_OS_FREEBSD also defined
-    return QLatin1String("DragonFlyBSD");
-#elif defined(Q_OS_FREEBSD) || defined(Q_OS_FREEBSD_KERNEL)
-    return QLatin1String("FreeBSD");
-#elif defined(Q_OS_NETBSD)
-    return QLatin1String("NetBSD");
-#elif defined(Q_OS_OPENBSD)
-    return QLatin1String("OpenBSD");
-#elif defined(Q_OS_SOLARIS)
-    return QLatin1String("Solaris");
-#else
-    return QLatin1String("Unknown OS");
-#endif
-}
-
-QByteArray Utility::userAgentString()
-{
-    QString re = QString::fromLatin1("Mozilla/5.0 (%1) mirall/%2")
-                     .arg(platform(), QLatin1String(MIRALL_VERSION_STRING));
-
-    QLatin1String appName(APPLICATION_SHORTNAME);
-
-    // this constant "ownCloud" is defined in the default OEM theming
-    // that is used for the standard client. If it is changed there,
-    // it needs to be adjusted here.
-    if (appName != QLatin1String("ownCloud")) {
-        re += QString(" (%1)").arg(appName);
-    }
-    return re.toLatin1();
-}
-
-bool Utility::hasLaunchOnStartup(const QString &appName)
-{
-    return hasLaunchOnStartup_private(appName);
-}
-
-void Utility::setLaunchOnStartup(const QString &appName, const QString &guiName, bool enable)
-{
-    setLaunchOnStartup_private(appName, guiName, enable);
-}
-
-qint64 Utility::freeDiskSpace(const QString &path)
-{
-#if defined(Q_OS_MAC) || defined(Q_OS_FREEBSD) || defined(Q_OS_FREEBSD_KERNEL) || defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD)
-    struct statvfs stat;
-    if (statvfs(path.toLocal8Bit().data(), &stat) == 0) {
-        return (qint64)stat.f_bavail * stat.f_frsize;
-    }
-#elif defined(Q_OS_UNIX)
-    struct statvfs64 stat;
-    if (statvfs64(path.toLocal8Bit().data(), &stat) == 0) {
-        return (qint64)stat.f_bavail * stat.f_frsize;
-    }
-#elif defined(Q_OS_WIN)
-    ULARGE_INTEGER freeBytes;
-    freeBytes.QuadPart = 0L;
-    if (GetDiskFreeSpaceEx(reinterpret_cast<const wchar_t *>(path.utf16()), &freeBytes, NULL, NULL)) {
-        return freeBytes.QuadPart;
-    }
-#endif
-    return -1;
-}
-
-QString Utility::compactFormatDouble(double value, int prec, const QString &unit)
-{
-    QLocale locale = QLocale::system();
-    QChar decPoint = locale.decimalPoint();
-    QString str = locale.toString(value, 'f', prec);
-    while (str.endsWith('0') || str.endsWith(decPoint)) {
-        if (str.endsWith(decPoint)) {
-            str.chop(1);
-            break;
-        }
-        str.chop(1);
-    }
-    if (!unit.isEmpty())
-        str += (QLatin1Char(' ') + unit);
-    return str;
-}
-
-QString Utility::escape(const QString &in)
-{
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-    return Qt::escape(in);
-#else
-    return in.toHtmlEscaped();
-#endif
-}
-
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-// In Qt 4,  QThread::sleep functions are protected.
-// This is a hack to make them visible in this namespace.
-struct QThread : ::QThread
-{
-    using ::QThread::sleep;
-    using ::QThread::usleep;
-};
-#endif
-
-void Utility::sleep(int sec)
-{
-    QThread::sleep(sec);
-}
-
-void Utility::usleep(int usec)
-{
-    QThread::usleep(usec);
-}
-
-bool Utility::fsCasePreserving()
-{
-#ifdef WITH_TESTING
-    QByteArray env = qgetenv("OWNCLOUD_TEST_CASE_PRESERVING");
-    if (!env.isEmpty())
-        return env.toInt();
-#endif
-
-    return isWindows() || isMac();
-}
-
-bool Utility::fileNamesEqual(const QString &fn1, const QString &fn2)
-{
-    const QDir fd1(fn1);
-    const QDir fd2(fn2);
-
-    // Attention: If the path does not exist, canonicalPath returns ""
-    // ONLY use this function with existing pathes.
-    const QString a = fd1.canonicalPath();
-    const QString b = fd2.canonicalPath();
-    bool re = !a.isEmpty() && QString::compare(a, b, fsCasePreserving() ? Qt::CaseInsensitive : Qt::CaseSensitive) == 0;
-    return re;
-}
-
-QDateTime Utility::qDateTimeFromTime_t(qint64 t)
-{
-    return QDateTime::fromMSecsSinceEpoch(t * 1000);
-}
-
-qint64 Utility::qDateTimeToTime_t(const QDateTime &t)
-{
-    return t.toMSecsSinceEpoch() / 1000;
-}
-
-namespace {
-    struct Period
-    {
-        const char *name;
-        quint64 msec;
-
-        QString description(quint64 value) const
-        {
-            return QCoreApplication::translate(
-                "Utility", name, 0, QCoreApplication::UnicodeUTF8,
-                value);
-        }
-    };
-// QTBUG-3945 and issue #4855: QT_TRANSLATE_NOOP does not work with plural form because lupdate
-// limitation unless we fake more arguments
-// (it must be in the form ("context", "source", "comment", n)
-#undef QT_TRANSLATE_NOOP
-#define QT_TRANSLATE_NOOP(ctx, str, ...) str
-    Q_DECL_CONSTEXPR Period periods[] = {
-        { QT_TRANSLATE_NOOP("Utility", "%n year(s)", 0, _), 365 * 24 * 3600 * 1000LL },
-        { QT_TRANSLATE_NOOP("Utility", "%n month(s)", 0, _), 30 * 24 * 3600 * 1000LL },
-        { QT_TRANSLATE_NOOP("Utility", "%n day(s)", 0, _), 24 * 3600 * 1000LL },
-        { QT_TRANSLATE_NOOP("Utility", "%n hour(s)", 0, _), 3600 * 1000LL },
-        { QT_TRANSLATE_NOOP("Utility", "%n minute(s)", 0, _), 60 * 1000LL },
-        { QT_TRANSLATE_NOOP("Utility", "%n second(s)", 0, _), 1000LL },
-        { 0, 0 }
-    };
-} // anonymous namespace
-
-QString Utility::durationToDescriptiveString2(quint64 msecs)
-{
-    int p = 0;
-    while (periods[p + 1].name && msecs < periods[p].msec) {
-        p++;
-    }
-
-    auto firstPart = periods[p].description(int(msecs / periods[p].msec));
-
-    if (!periods[p + 1].name) {
-        return firstPart;
-    }
-
-    quint64 secondPartNum = qRound(double(msecs % periods[p].msec) / periods[p + 1].msec);
-
-    if (secondPartNum == 0) {
-        return firstPart;
-    }
-
-    return QCoreApplication::translate("Utility", "%1 %2").arg(firstPart, periods[p + 1].description(secondPartNum));
-}
-
-QString Utility::durationToDescriptiveString1(quint64 msecs)
-{
-    int p = 0;
-    while (periods[p + 1].name && msecs < periods[p].msec) {
-        p++;
-    }
-
-    quint64 amount = qRound(double(msecs) / periods[p].msec);
-    return periods[p].description(amount);
-}
-
-QString Utility::fileNameForGuiUse(const QString &fName)
-{
-    if (isMac()) {
-        QString n(fName);
-        return n.replace(QChar(':'), QChar('/'));
-    }
-    return fName;
-}
-
-bool Utility::hasDarkSystray()
-{
-    return hasDarkSystray_private();
-}
-
-
-bool Utility::isWindows()
-{
-#ifdef Q_OS_WIN
-    return true;
-#else
-    return false;
-#endif
-}
-
-bool Utility::isMac()
-{
-#ifdef Q_OS_MAC
-    return true;
-#else
-    return false;
-#endif
-}
-
-bool Utility::isUnix()
-{
-#ifdef Q_OS_UNIX
-    return true;
-#else
-    return false;
-#endif
-}
-
-bool Utility::isLinux()
-{
-#if defined(Q_OS_LINUX)
-    return true;
-#else
-    return false;
-#endif
-}
-
-bool Utility::isBSD()
-{
-#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD)
-    return true;
-#else
-    return false;
-#endif
-}
-
-QString Utility::platformName()
-{
-    QString re("Windows");
-
-#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
-    if (isMac()) {
-        re = QLatin1String("MacOSX");
-    } else if (isLinux()) {
-        re = QLatin1String("Linux");
-    } else if (isBSD()) {
-        re = QLatin1String("BSD");
-    } else if (isUnix()) {
-        re = QLatin1String("Unix");
-    }
-#else
-    re = QSysInfo::prettyProductName();
-#endif
-    return re;
-}
-
-void Utility::crash()
-{
-    volatile int *a = (int *)(NULL);
-    *a = 1;
-}
-
-// read the output of the owncloud --version command from the owncloud
-// version that is on disk. This works for most versions of the client,
-// because clients that do not yet know the --version flag return the
-// version in the first line of the help output :-)
-//
-// This version only delivers output on linux, as Mac and Win get their
-// restarting from the installer.
-QByteArray Utility::versionOfInstalledBinary(const QString &command)
-{
-    QByteArray re;
-    if (isLinux()) {
-        QString binary(command);
-        if (binary.isEmpty()) {
-            binary = qApp->arguments()[0];
-        }
-        QStringList params;
-        params << QLatin1String("--version");
-        QProcess process;
-        process.start(binary, params);
-        process.waitForFinished(); // sets current thread to sleep and waits for pingProcess end
-        re = process.readAllStandardOutput();
-        int newline = re.indexOf(QChar('\n'));
-        if (newline > 0) {
-            re.truncate(newline);
-        }
-    }
-    return re;
-}
-
-QString Utility::timeAgoInWords(const QDateTime &dt, const QDateTime &from)
-{
-    QDateTime now = QDateTime::currentDateTimeUtc();
-
-    if (from.isValid()) {
-        now = from;
-    }
-
-    if (dt.daysTo(now) > 0) {
-        int dtn = dt.daysTo(now);
-        return QObject::tr("%n day(s) ago", "", dtn);
-    } else {
-        qint64 secs = dt.secsTo(now);
-        if (secs < 0) {
-            return QObject::tr("in the future");
-        }
-        if (floor(secs / 3600.0) > 0) {
-            int hours = floor(secs / 3600.0);
-            return (QObject::tr("%n hour(s) ago", "", hours));
-        } else {
-            int minutes = qRound(secs / 60.0);
-            if (minutes == 0) {
-                if (secs < 5) {
-                    return QObject::tr("now");
-                } else {
-                    return QObject::tr("Less than a minute ago");
-                }
-            }
-            return (QObject::tr("%n minute(s) ago", "", minutes));
-        }
-    }
-    return QObject::tr("Some time ago");
-}
-
-/* --------------------------------------------------------------------------- */
-
-static const char STOPWATCH_END_TAG[] = "_STOPWATCH_END";
-
-void Utility::StopWatch::start()
-{
-    _startTime = QDateTime::currentDateTime();
-    _timer.start();
-}
-
-quint64 Utility::StopWatch::stop()
-{
-    addLapTime(QLatin1String(STOPWATCH_END_TAG));
-    quint64 duration = _timer.elapsed();
-    _timer.invalidate();
-    return duration;
-}
-
-void Utility::StopWatch::reset()
-{
-    _timer.invalidate();
-    _startTime.setMSecsSinceEpoch(0);
-    _lapTimes.clear();
-}
-
-quint64 Utility::StopWatch::addLapTime(const QString &lapName)
-{
-    if (!_timer.isValid()) {
-        start();
-    }
-    quint64 re = _timer.elapsed();
-    _lapTimes[lapName] = re;
-    return re;
-}
-
-QDateTime Utility::StopWatch::startTime() const
-{
-    return _startTime;
-}
-
-QDateTime Utility::StopWatch::timeOfLap(const QString &lapName) const
-{
-    quint64 t = durationOfLap(lapName);
-    if (t) {
-        QDateTime re(_startTime);
-        return re.addMSecs(t);
-    }
-
-    return QDateTime();
-}
-
-quint64 Utility::StopWatch::durationOfLap(const QString &lapName) const
-{
-    return _lapTimes.value(lapName, 0);
-}
-
-void Utility::sortFilenames(QStringList &fileNames)
-{
-#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
-    QCollator collator;
-    collator.setNumericMode(true);
-    collator.setCaseSensitivity(Qt::CaseInsensitive);
-    qSort(fileNames.begin(), fileNames.end(), collator);
-#elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
-    fileNames.sort(Qt::CaseInsensitive);
-#else
-    fileNames.sort();
-#endif
-}
-
-QUrl Utility::concatUrlPath(const QUrl &url, const QString &concatPath,
-    const QList<QPair<QString, QString>> &queryItems)
-{
-    QString path = url.path();
-    if (!concatPath.isEmpty()) {
-        // avoid '//'
-        if (path.endsWith('/') && concatPath.startsWith('/')) {
-            path.chop(1);
-        } // avoid missing '/'
-        else if (!path.endsWith('/') && !concatPath.startsWith('/')) {
-            path += QLatin1Char('/');
-        }
-        path += concatPath; // put the complete path together
-    }
-
-    QUrl tmpUrl = url;
-    tmpUrl.setPath(path);
-    if (queryItems.size() > 0) {
-        tmpUrl.setQueryItems(queryItems);
-    }
-    return tmpUrl;
-}
-
-Q_GLOBAL_STATIC(QString, g_configFileName)
-
-std::unique_ptr<QSettings> Utility::settingsWithGroup(const QString &group, QObject *parent)
-{
-    if (g_configFileName()->isEmpty()) {
-        // cache file name
-        ConfigFile cfg;
-        *g_configFileName() = cfg.configFile();
-    }
-    std::unique_ptr<QSettings> settings(new QSettings(*g_configFileName(), QSettings::IniFormat, parent));
-    settings->beginGroup(group);
-    return settings;
-}
-
-} // namespace OCC
diff --git a/src/libsync/utility.h b/src/libsync/utility.h
deleted file mode 100644 (file)
index 7c26f2a..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
- * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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 "owncloudlib.h"
-#include <QString>
-#include <QByteArray>
-#include <QDateTime>
-#include <QElapsedTimer>
-#include <QLoggingCategory>
-#include <QMap>
-#include <QUrl>
-#include <memory>
-
-class QSettings;
-
-namespace OCC {
-
-Q_DECLARE_LOGGING_CATEGORY(lcUtility)
-
-/** \addtogroup libsync
- *  @{
- */
-namespace Utility {
-    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 QByteArray userAgentString();
-    OWNCLOUDSYNC_EXPORT bool hasLaunchOnStartup(const QString &appName);
-    OWNCLOUDSYNC_EXPORT void setLaunchOnStartup(const QString &appName, const QString &guiName, bool launch);
-
-    /**
-     * Return the amount of free space available.
-     *
-     * \a path must point to a directory
-     */
-    OWNCLOUDSYNC_EXPORT qint64 freeDiskSpace(const QString &path);
-
-    /**
-     * @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.
-     */
-    OWNCLOUDSYNC_EXPORT QString compactFormatDouble(double value, int prec, const QString &unit = QString::null);
-
-    // porting methods
-    OWNCLOUDSYNC_EXPORT QString escape(const QString &);
-
-    // conversion function QDateTime <-> time_t   (because the ones builtin work on only unsigned 32bit)
-    OWNCLOUDSYNC_EXPORT QDateTime qDateTimeFromTime_t(qint64 t);
-    OWNCLOUDSYNC_EXPORT qint64 qDateTimeToTime_t(const QDateTime &t);
-
-    /**
-     * @brief Convert milliseconds duration to human readable string.
-     * @param quint64 msecs the milliseconds to convert to string.
-     * @return an HMS representation of the milliseconds value.
-     *
-     * durationToDescriptiveString1 describes the duration in a single
-     * unit, like "5 minutes" or "2 days".
-     *
-     * durationToDescriptiveString2 uses two units where possible, so
-     * "5 minutes 43 seconds" or "1 month 3 days".
-     */
-    OWNCLOUDSYNC_EXPORT QString durationToDescriptiveString1(quint64 msecs);
-    OWNCLOUDSYNC_EXPORT QString durationToDescriptiveString2(quint64 msecs);
-
-    /**
-     * @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();
-
-    // convenience OS detection methods
-    OWNCLOUDSYNC_EXPORT bool isWindows();
-    OWNCLOUDSYNC_EXPORT bool isMac();
-    OWNCLOUDSYNC_EXPORT bool isUnix();
-    OWNCLOUDSYNC_EXPORT bool isLinux(); // use with care
-    OWNCLOUDSYNC_EXPORT bool isBSD(); // use with care, does not match OS X
-
-    OWNCLOUDSYNC_EXPORT QString platformName();
-    // crash helper for --debug
-    OWNCLOUDSYNC_EXPORT void crash();
-
-    // 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();
-
-    // Check if two pathes that MUST exist are equal. This function
-    // uses QDir::canonicalPath() to judge and cares for the systems
-    // case sensitivity.
-    OWNCLOUDSYNC_EXPORT bool fileNamesEqual(const QString &fn1, const QString &fn2);
-
-    // Call the given command with the switch --version and rerun the first line
-    // of the output.
-    // If command is empty, the function calls the running application which, on
-    // Linux, might have changed while this one is running.
-    // For Mac and Windows, it returns QString()
-    OWNCLOUDSYNC_EXPORT QByteArray versionOfInstalledBinary(const QString &command = QString());
-
-    OWNCLOUDSYNC_EXPORT QString fileNameForGuiUse(const QString &fName);
-
-    /**
-     * @brief timeAgoInWords - human readable time span
-     *
-     * Use this to get a string that describes the timespan between the first and
-     * the second timestamp in a human readable and understandable form.
-     *
-     * If the second parameter is ommitted, the current time is used.
-     */
-    OWNCLOUDSYNC_EXPORT QString timeAgoInWords(const QDateTime &dt, const QDateTime &from = QDateTime());
-
-    class OWNCLOUDSYNC_EXPORT StopWatch
-    {
-    private:
-        QMap<QString, quint64> _lapTimes;
-        QDateTime _startTime;
-        QElapsedTimer _timer;
-
-    public:
-        void start();
-        quint64 stop();
-        quint64 addLapTime(const QString &lapName);
-        void reset();
-
-        // out helpers, return the measured times.
-        QDateTime startTime() const;
-        QDateTime timeOfLap(const QString &lapName) const;
-        quint64 durationOfLap(const QString &lapName) const;
-    };
-
-    /**
-     * @brief Sort a QStringList in a way that's appropriate for filenames
-     */
-    OWNCLOUDSYNC_EXPORT void sortFilenames(QStringList &fileNames);
-
-    /** Appends concatPath and queryItems to the url */
-    OWNCLOUDSYNC_EXPORT QUrl concatUrlPath(
-        const QUrl &url, const QString &concatPath,
-        const QList<QPair<QString, QString>> &queryItems = (QList<QPair<QString, QString>>()));
-
-    /**  Returns a new settings pre-set in a specific group.  The Settings will be created
-         with the given parent. If no parent is specified, the caller must destroy the settings */
-    OWNCLOUDSYNC_EXPORT std::unique_ptr<QSettings> settingsWithGroup(const QString &group, QObject *parent = 0);
-}
-/** @} */ // \addtogroup
-}
-#endif // UTILITY_H
diff --git a/src/libsync/utility_mac.cpp b/src/libsync/utility_mac.cpp
deleted file mode 100644 (file)
index 5a71aa2..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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.
- */
-
-#include <CoreServices/CoreServices.h>
-#include <CoreFoundation/CoreFoundation.h>
-
-namespace OCC {
-
-static void setupFavLink_private(const QString &folder)
-{
-    // Finder: Place under "Places"/"Favorites" on the left sidebar
-    CFStringRef folderCFStr = CFStringCreateWithCString(0, folder.toUtf8().data(), kCFStringEncodingUTF8);
-    CFURLRef urlRef = CFURLCreateWithFileSystemPath(0, folderCFStr, kCFURLPOSIXPathStyle, true);
-
-    LSSharedFileListRef placesItems = LSSharedFileListCreate(0, kLSSharedFileListFavoriteItems, 0);
-    if (placesItems) {
-        //Insert an item to the list.
-        LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(placesItems,
-            kLSSharedFileListItemLast, 0, 0,
-            urlRef, 0, 0);
-        if (item)
-            CFRelease(item);
-    }
-    CFRelease(placesItems);
-    CFRelease(folderCFStr);
-    CFRelease(urlRef);
-}
-
-bool hasLaunchOnStartup_private(const QString &)
-{
-    // this is quite some duplicate code with setLaunchOnStartup, at some point we should fix this FIXME.
-    bool returnValue = false;
-    QString filePath = QDir(QCoreApplication::applicationDirPath() + QLatin1String("/../..")).absolutePath();
-    CFStringRef folderCFStr = CFStringCreateWithCString(0, filePath.toUtf8().data(), kCFStringEncodingUTF8);
-    CFURLRef urlRef = CFURLCreateWithFileSystemPath(0, folderCFStr, kCFURLPOSIXPathStyle, true);
-    LSSharedFileListRef loginItems = LSSharedFileListCreate(0, kLSSharedFileListSessionLoginItems, 0);
-    if (loginItems) {
-        // We need to iterate over the items and check which one is "ours".
-        UInt32 seedValue;
-        CFArrayRef itemsArray = LSSharedFileListCopySnapshot(loginItems, &seedValue);
-        CFStringRef appUrlRefString = CFURLGetString(urlRef); // no need for release
-        for (int i = 0; i < CFArrayGetCount(itemsArray); i++) {
-            LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(itemsArray, i);
-            CFURLRef itemUrlRef = NULL;
-
-            if (LSSharedFileListItemResolve(item, 0, &itemUrlRef, NULL) == noErr) {
-                CFStringRef itemUrlString = CFURLGetString(itemUrlRef);
-                if (CFStringCompare(itemUrlString, appUrlRefString, 0) == kCFCompareEqualTo) {
-                    returnValue = true;
-                }
-                CFRelease(itemUrlRef);
-            }
-        }
-        CFRelease(itemsArray);
-    }
-    CFRelease(loginItems);
-    CFRelease(folderCFStr);
-    CFRelease(urlRef);
-    return returnValue;
-}
-
-void setLaunchOnStartup_private(const QString &appName, const QString &guiName, bool enable)
-{
-    Q_UNUSED(appName)
-    Q_UNUSED(guiName)
-    QString filePath = QDir(QCoreApplication::applicationDirPath() + QLatin1String("/../..")).absolutePath();
-    CFStringRef folderCFStr = CFStringCreateWithCString(0, filePath.toUtf8().data(), kCFStringEncodingUTF8);
-    CFURLRef urlRef = CFURLCreateWithFileSystemPath(0, folderCFStr, kCFURLPOSIXPathStyle, true);
-    LSSharedFileListRef loginItems = LSSharedFileListCreate(0, kLSSharedFileListSessionLoginItems, 0);
-
-    if (loginItems && enable) {
-        //Insert an item to the list.
-        LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems,
-            kLSSharedFileListItemLast, 0, 0,
-            urlRef, 0, 0);
-        if (item)
-            CFRelease(item);
-        CFRelease(loginItems);
-    } else if (loginItems && !enable) {
-        // We need to iterate over the items and check which one is "ours".
-        UInt32 seedValue;
-        CFArrayRef itemsArray = LSSharedFileListCopySnapshot(loginItems, &seedValue);
-        CFStringRef appUrlRefString = CFURLGetString(urlRef);
-        for (int i = 0; i < CFArrayGetCount(itemsArray); i++) {
-            LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(itemsArray, i);
-            CFURLRef itemUrlRef = NULL;
-
-            if (LSSharedFileListItemResolve(item, 0, &itemUrlRef, NULL) == noErr) {
-                CFStringRef itemUrlString = CFURLGetString(itemUrlRef);
-                if (CFStringCompare(itemUrlString, appUrlRefString, 0) == kCFCompareEqualTo) {
-                    LSSharedFileListItemRemove(loginItems, item); // remove it!
-                }
-                CFRelease(itemUrlRef);
-            }
-        }
-        CFRelease(itemsArray);
-        CFRelease(loginItems);
-    };
-
-    CFRelease(folderCFStr);
-    CFRelease(urlRef);
-}
-
-static bool hasDarkSystray_private()
-{
-    bool returnValue = false;
-    CFStringRef interfaceStyleKey = CFSTR("AppleInterfaceStyle");
-    CFStringRef interfaceStyle = NULL;
-    CFStringRef darkInterfaceStyle = CFSTR("Dark");
-    interfaceStyle = (CFStringRef)CFPreferencesCopyAppValue(interfaceStyleKey,
-        kCFPreferencesCurrentApplication);
-    if (interfaceStyle != NULL) {
-        returnValue = (kCFCompareEqualTo == CFStringCompare(interfaceStyle, darkInterfaceStyle, 0));
-        CFRelease(interfaceStyle);
-    }
-    return returnValue;
-}
-
-} // namespace OCC
diff --git a/src/libsync/utility_unix.cpp b/src/libsync/utility_unix.cpp
deleted file mode 100644 (file)
index e21c1cc..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
- * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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.
- */
-
-#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
-#include <QStandardPaths>
-#endif
-
-namespace OCC {
-
-static void setupFavLink_private(const QString &folder)
-{
-    // Nautilus: add to ~/.gtk-bookmarks
-    QFile gtkBookmarks(QDir::homePath() + QLatin1String("/.gtk-bookmarks"));
-    QByteArray folderUrl = "file://" + folder.toUtf8();
-    if (gtkBookmarks.open(QFile::ReadWrite)) {
-        QByteArray places = gtkBookmarks.readAll();
-        if (!places.contains(folderUrl)) {
-            places += folderUrl;
-            gtkBookmarks.reset();
-            gtkBookmarks.write(places + '\n');
-        }
-    }
-}
-
-// returns the autostart directory the linux way
-// and respects the XDG_CONFIG_HOME env variable
-QString getUserAutostartDir_private()
-{
-#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
-    QString config = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
-#else
-    QString config = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
-
-    if (config.isEmpty()) {
-        config = QDir::homePath() + QLatin1String("/.config");
-    }
-#endif
-    config += QLatin1String("/autostart/");
-    return config;
-}
-
-bool hasLaunchOnStartup_private(const QString &appName)
-{
-    QString desktopFileLocation = getUserAutostartDir_private() + appName + QLatin1String(".desktop");
-    return QFile::exists(desktopFileLocation);
-}
-
-void setLaunchOnStartup_private(const QString &appName, const QString &guiName, bool enable)
-{
-    QString userAutoStartPath = getUserAutostartDir_private();
-    QString desktopFileLocation = userAutoStartPath + appName + QLatin1String(".desktop");
-    if (enable) {
-        if (!QDir().exists(userAutoStartPath) && !QDir().mkpath(userAutoStartPath)) {
-            qCWarning(lcUtility) << "Could not create autostart folder";
-            return;
-        }
-        QFile iniFile(desktopFileLocation);
-        if (!iniFile.open(QIODevice::WriteOnly)) {
-            qCWarning(lcUtility) << "Could not write auto start entry" << desktopFileLocation;
-            return;
-        }
-        QTextStream ts(&iniFile);
-        ts.setCodec("UTF-8");
-        ts << QLatin1String("[Desktop Entry]") << endl
-           << QLatin1String("Name=") << guiName << endl
-           << QLatin1String("GenericName=") << QLatin1String("File Synchronizer") << endl
-           << QLatin1String("Exec=") << QCoreApplication::applicationFilePath() << endl
-           << QLatin1String("Terminal=") << "false" << endl
-           << QLatin1String("Icon=") << appName.toLower() << endl // always use lowercase for icons
-           << QLatin1String("Categories=") << QLatin1String("Network") << endl
-           << QLatin1String("Type=") << QLatin1String("Application") << endl
-           << QLatin1String("StartupNotify=") << "false" << endl
-           << QLatin1String("X-GNOME-Autostart-enabled=") << "true" << endl;
-    } else {
-        if (!QFile::remove(desktopFileLocation)) {
-            qCWarning(lcUtility) << "Could not remove autostart desktop file";
-        }
-    }
-}
-
-static inline bool hasDarkSystray_private()
-{
-    return true;
-}
-
-} // namespace OCC
diff --git a/src/libsync/utility_win.cpp b/src/libsync/utility_win.cpp
deleted file mode 100644 (file)
index 3762808..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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.
- */
-
-#define _WIN32_WINNT 0x0600
-#define WINVER 0x0600
-#include <shlobj.h>
-#include <winbase.h>
-#include <windows.h>
-#include <winerror.h>
-#include <shlguid.h>
-#include <string>
-#include <QLibrary>
-
-static const char runPathC[] = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
-
-namespace OCC {
-
-static void setupFavLink_private(const QString &folder)
-{
-    // First create a Desktop.ini so that the folder and favorite link show our application's icon.
-    QFile desktopIni(folder + QLatin1String("/Desktop.ini"));
-    if (desktopIni.exists()) {
-        qCWarning(lcUtility) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon.";
-    } else {
-        qCInfo(lcUtility) << "Creating" << desktopIni.fileName() << "to set a folder icon in Explorer.";
-        desktopIni.open(QFile::WriteOnly);
-        desktopIni.write("[.ShellClassInfo]\r\nIconResource=");
-        desktopIni.write(QDir::toNativeSeparators(qApp->applicationFilePath()).toUtf8());
-        desktopIni.write(",0\r\n");
-        desktopIni.close();
-    }
-
-    // Windows Explorer: Place under "Favorites" (Links)
-    QString linkName;
-    QDir folderDir(QDir::fromNativeSeparators(folder));
-
-    /* Use new WINAPI functions */
-    PWSTR path;
-
-    if (SHGetKnownFolderPath(FOLDERID_Links, 0, NULL, &path) == S_OK) {
-        QString links = QDir::fromNativeSeparators(QString::fromWCharArray(path));
-        linkName = QDir(links).filePath(folderDir.dirName() + QLatin1String(".lnk"));
-        CoTaskMemFree(path);
-    }
-    qCInfo(lcUtility) << "Creating favorite link from" << folder << "to" << linkName;
-    if (!QFile::link(folder, linkName))
-        qCWarning(lcUtility) << "linking" << folder << "to" << linkName << "failed!";
-}
-
-
-bool hasLaunchOnStartup_private(const QString &appName)
-{
-    QString runPath = QLatin1String(runPathC);
-    QSettings settings(runPath, QSettings::NativeFormat);
-    return settings.contains(appName);
-}
-
-void setLaunchOnStartup_private(const QString &appName, const QString &guiName, bool enable)
-{
-    Q_UNUSED(guiName);
-    QString runPath = QLatin1String(runPathC);
-    QSettings settings(runPath, QSettings::NativeFormat);
-    if (enable) {
-        settings.setValue(appName, QCoreApplication::applicationFilePath().replace('/', '\\'));
-    } else {
-        settings.remove(appName);
-    }
-}
-
-static inline bool hasDarkSystray_private()
-{
-    return true;
-}
-
-} // namespace OCC
diff --git a/src/libsync/version.h.in b/src/libsync/version.h.in
deleted file mode 100644 (file)
index c05c224..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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 VERSION_H
-#define VERSION_H
-
-#cmakedefine GIT_SHA1 "@GIT_SHA1@"
-
-#define MIRALL_STRINGIFY(s) MIRALL_TOSTRING(s)
-#define MIRALL_TOSTRING(s) #s
-
-/* MIRALL version */
-#define MIRALL_VERSION_MAJOR @MIRALL_VERSION_MAJOR@
-#define MIRALL_VERSION_MINOR @MIRALL_VERSION_MINOR@
-#define MIRALL_VERSION_PATCH @MIRALL_VERSION_PATCH@
-#define MIRALL_VERSION_BUILD @MIRALL_VERSION_BUILD@
-
-#define MIRALL_VERSION       @MIRALL_VERSION@
-#define MIRALL_VERSION_FULL  @MIRALL_VERSION_FULL@
-
-#define MIRALL_VERSION_STRING "@MIRALL_VERSION_STRING@"
-
-#endif // VERSION_H
index 80736b8251a61089b11bb6de65f6ca71b62eea6e..64f95694b05e9689c803599849c913da91e8cb3a 100644 (file)
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "torture.h"
-
 #include "csync_misc.h"
 #include <stdlib.h>
+#include "torture.h"
 
 static void check_csync_normalize_etag(void **state)
 {
index 88c3b1d343a7af00ff541840f52fd3d041c02db0..fd1988eabba9f8acb4f2432bd9c929cf7426fd95 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "checksums.h"
 #include "networkjobs.h"
-#include "utility.h"
+#include "common/utility.h"
 #include "filesystem.h"
 #include "propagatorjobs.h"
 
index a9b3f2b9fc5b73acefe6a975054d5155b7e07f84..0b8b612467d24f93283a09651b24f8364d0ba88c 100644 (file)
@@ -8,7 +8,7 @@
 #include <QDebug>
 
 #include "filesystem.h"
-#include "utility.h"
+#include "common/utility.h"
 
 using namespace OCC::Utility;
 using namespace OCC::FileSystem;
index e8775ac06f1522b7e49cf42b28db159221f74463..986c588ebdbd6f6afa10e6d4579bd59a6556c22f 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <QtTest>
 
-#include "utility.h"
+#include "common/utility.h"
 #include "folder.h"
 
 using namespace OCC;
index b6e6478f5ae8bb92aae90171984e7a516a820e14..78a2dd71a10ada0fe2f16a7d05c2b56538fec63b 100644 (file)
@@ -11,7 +11,7 @@
 #endif
 #include <QtTest>
 
-#include "utility.h"
+#include "common/utility.h"
 #include "folderman.h"
 #include "account.h"
 #include "accountstate.h"
index 1cb231cf654debab9faa068b1ff141f81ab0788b..0f8551db6703dc6815fd90eb87fff7145c84c302 100644 (file)
@@ -8,7 +8,7 @@
 #include <QtTest>
 
 #include "folderwatcher.h"
-#include "utility.h"
+#include "common/utility.h"
 
 void touch(const QString &file)
 {
index 799b09da96234c22da87874ad24f950fe1265f60..2d8cf937d10bc096676e628fcbc15ef6de66d7a1 100644 (file)
@@ -7,7 +7,7 @@
 #include <QtTest>
 
 #include "folderwatcher_linux.h"
-#include "utility.h"
+#include "common/utility.h"
 
 using namespace OCC;
 
index 5093ce76de7093fd08ad34d2a3947f583684054a..5e86a336e1ef0651fff422b5b06fa9f81beaea94 100644 (file)
@@ -9,7 +9,7 @@
 #include <QTemporaryDir>
 #endif
 
-#include "utility.h"
+#include "common/utility.h"
 
 using namespace OCC::Utility;
 
diff --git a/version.h.in b/version.h.in
new file mode 100644 (file)
index 0000000..064309f
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef VERSION_H
+#define VERSION_H
+
+#cmakedefine GIT_SHA1 "@GIT_SHA1@"
+
+#define MIRALL_STRINGIFY(s) MIRALL_TOSTRING(s)
+#define MIRALL_TOSTRING(s) #s
+
+/* MIRALL version */
+#define MIRALL_VERSION_MAJOR @MIRALL_VERSION_MAJOR@
+#define MIRALL_VERSION_MINOR @MIRALL_VERSION_MINOR@
+#define MIRALL_VERSION_PATCH @MIRALL_VERSION_PATCH@
+#define MIRALL_VERSION_BUILD @MIRALL_VERSION_BUILD@
+
+#define MIRALL_VERSION       @MIRALL_VERSION@
+#define MIRALL_VERSION_FULL  @MIRALL_VERSION_FULL@
+
+#define MIRALL_VERSION_STRING "@MIRALL_VERSION_STRING@"
+
+#endif // VERSION_H