diff options
Diffstat (limited to 'prototype_2016/third_party/fluid/src')
-rw-r--r-- | prototype_2016/third_party/fluid/src/CMakeLists.txt | 79 | ||||
-rw-r--r-- | prototype_2016/third_party/fluid/src/FluidConfig.cmake.in | 11 | ||||
-rw-r--r-- | prototype_2016/third_party/fluid/src/dateutils.cpp | 82 | ||||
-rw-r--r-- | prototype_2016/third_party/fluid/src/dateutils.h | 44 | ||||
-rw-r--r-- | prototype_2016/third_party/fluid/src/src.pri | 5 |
5 files changed, 221 insertions, 0 deletions
diff --git a/prototype_2016/third_party/fluid/src/CMakeLists.txt b/prototype_2016/third_party/fluid/src/CMakeLists.txt new file mode 100644 index 0000000..dacd2e0 --- /dev/null +++ b/prototype_2016/third_party/fluid/src/CMakeLists.txt | |||
@@ -0,0 +1,79 @@ | |||
1 | include(GenerateExportHeader) | ||
2 | include(CMakePackageConfigHelpers) | ||
3 | include(ECMSetupVersion) | ||
4 | include(ECMGenerateHeaders) | ||
5 | |||
6 | ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX FLUID | ||
7 | VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/Fluid/fluid/fluidversion.h" | ||
8 | PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/FluidConfigVersion.cmake" | ||
9 | SOVERSION ${PROJECT_SOVERSION}) | ||
10 | |||
11 | set(FLUID_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/Fluid") | ||
12 | |||
13 | set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/Fluid") | ||
14 | |||
15 | configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/FluidConfig.cmake.in" | ||
16 | "${CMAKE_CURRENT_BINARY_DIR}/FluidConfig.cmake" | ||
17 | INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}) | ||
18 | |||
19 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/FluidConfig.cmake" | ||
20 | "${CMAKE_CURRENT_BINARY_DIR}/FluidConfigVersion.cmake" | ||
21 | DESTINATION "${CMAKECONFIG_INSTALL_DIR}" | ||
22 | COMPONENT Devel) | ||
23 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Fluid/fluid/fluidversion.h | ||
24 | DESTINATION ${FLUID_INCLUDEDIR}/fluid COMPONENT Devel) | ||
25 | |||
26 | ################################### | ||
27 | |||
28 | add_definitions(-DQT_NO_KEYWORDS) | ||
29 | |||
30 | set(SOURCES | ||
31 | dateutils.cpp | ||
32 | ) | ||
33 | |||
34 | add_library(Fluid SHARED ${SOURCES}) | ||
35 | |||
36 | target_link_libraries(Fluid | ||
37 | PUBLIC | ||
38 | Qt5::Core | ||
39 | ) | ||
40 | |||
41 | ################################################## | ||
42 | |||
43 | generate_export_header(Fluid EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/Fluid/fluid/fluid_export.h) | ||
44 | |||
45 | target_include_directories(Fluid INTERFACE "$<INSTALL_INTERFACE:${FLUID_INCLUDEDIR}>") | ||
46 | |||
47 | set_target_properties(Fluid PROPERTIES | ||
48 | VERSION ${PROJECT_VERSION} | ||
49 | SOVERSION ${PROJECT_SOVERSION}) | ||
50 | |||
51 | ecm_generate_headers(Fluid_CamelCase_HEADERS | ||
52 | HEADER_NAMES | ||
53 | DateUtils | ||
54 | REQUIRED_HEADERS | ||
55 | Fluid_HEADERS | ||
56 | PREFIX | ||
57 | Fluid | ||
58 | OUTPUT_DIR | ||
59 | ${CMAKE_CURRENT_BINARY_DIR}/Fluid | ||
60 | ) | ||
61 | install(FILES ${Fluid_CamelCase_HEADERS} | ||
62 | DESTINATION ${FLUID_INCLUDEDIR}/Fluid | ||
63 | COMPONENT Devel) | ||
64 | |||
65 | install(TARGETS Fluid EXPORT FluidTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) | ||
66 | |||
67 | install( | ||
68 | FILES | ||
69 | ${CMAKE_CURRENT_BINARY_DIR}/Fluid/fluid/fluid_export.h | ||
70 | dateutils.h | ||
71 | DESTINATION | ||
72 | ${FLUID_INCLUDEDIR}/fluid | ||
73 | COMPONENT | ||
74 | Devel | ||
75 | ) | ||
76 | |||
77 | install(EXPORT FluidTargets | ||
78 | DESTINATION "${CMAKECONFIG_INSTALL_DIR}" | ||
79 | FILE FluidTargets.cmake NAMESPACE Fluid::) | ||
diff --git a/prototype_2016/third_party/fluid/src/FluidConfig.cmake.in b/prototype_2016/third_party/fluid/src/FluidConfig.cmake.in new file mode 100644 index 0000000..8cbfe85 --- /dev/null +++ b/prototype_2016/third_party/fluid/src/FluidConfig.cmake.in | |||
@@ -0,0 +1,11 @@ | |||
1 | @PACKAGE_INIT@ | ||
2 | |||
3 | find_dependency(Qt5Core @REQUIRED_QT_VERSION@) | ||
4 | find_dependency(Qt5Gui @REQUIRED_QT_VERSION@) | ||
5 | find_dependency(Qt5Qml @REQUIRED_QT_VERSION@) | ||
6 | find_dependency(Qt5Quick @REQUIRED_QT_VERSION@) | ||
7 | find_dependency(Qt5QuickControls2 @REQUIRED_QT_VERSION@) | ||
8 | |||
9 | set(FLUID_CMAKE_MODULES_DIR "${CMAKE_CURRENT_LIST_DIR}") | ||
10 | |||
11 | include("${FLUID_CMAKE_MODULES_DIR}/FluidTargets.cmake") | ||
diff --git a/prototype_2016/third_party/fluid/src/dateutils.cpp b/prototype_2016/third_party/fluid/src/dateutils.cpp new file mode 100644 index 0000000..62e6903 --- /dev/null +++ b/prototype_2016/third_party/fluid/src/dateutils.cpp | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * This file is part of Fluid. | ||
3 | * | ||
4 | * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> | ||
5 | * Copyright (C) 2017 Michael Spencer <sonrisesoftware@gmail.com> | ||
6 | * | ||
7 | * $BEGIN_LICENSE:MPL2$ | ||
8 | * | ||
9 | * This Source Code Form is subject to the terms of the Mozilla Public | ||
10 | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
11 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
12 | * | ||
13 | * $END_LICENSE$ | ||
14 | */ | ||
15 | |||
16 | #include "dateutils.h" | ||
17 | |||
18 | using namespace Fluid; | ||
19 | |||
20 | QString DateUtils::formatDuration(qlonglong duration, DurationFormat format, DurationType type) | ||
21 | { | ||
22 | int hours = duration / (1000 * 60 * 60); | ||
23 | int minutes = duration / (1000 * 60) - 60 * hours; | ||
24 | int seconds = duration / 1000 - 60 * minutes - 60 * 60 * hours; | ||
25 | |||
26 | QString string; | ||
27 | |||
28 | if (type == Any || type == Seconds) { | ||
29 | if (format == Short) | ||
30 | string = QStringLiteral("%1").arg(seconds, 2, 10, QChar('0')); | ||
31 | else | ||
32 | string = QStringLiteral("%1s").arg(seconds); | ||
33 | } | ||
34 | |||
35 | if (type == Seconds || type == Minutes || (type == Any && (minutes >= 1 || hours >= 1))) { | ||
36 | if (format == Short) { | ||
37 | if (string.length() > 0) | ||
38 | string = QStringLiteral("%1:%2").arg(minutes, 2, 10, QChar('0')).arg(string); | ||
39 | else | ||
40 | string = QStringLiteral("%1").arg(minutes, 2, 10, QChar('0')); | ||
41 | } else { | ||
42 | string = QStringLiteral("%1m %2").arg(minutes).arg(string); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | if (type == Seconds || type == Minutes || type == Hours || (type == Any && (hours >= 1))) { | ||
47 | if (format == Short) { | ||
48 | if (string.length() > 0) | ||
49 | string = QStringLiteral("%1:%2").arg(hours).arg(string); | ||
50 | else | ||
51 | string = QStringLiteral("%1").arg(hours); | ||
52 | } else { | ||
53 | string = QStringLiteral("%1h %2").arg(hours).arg(string); | ||
54 | } | ||
55 | } | ||
56 | |||
57 | return string.trimmed(); | ||
58 | } | ||
59 | |||
60 | QString DateUtils::friendlyTime(const QDateTime &time, bool standalone) | ||
61 | { | ||
62 | QDateTime now = QDateTime::currentDateTime(); | ||
63 | qint64 minutes = qRound64(time.secsTo(now) / 60.0f); | ||
64 | if (minutes < 1) | ||
65 | return standalone ? tr("Now") : "now"; | ||
66 | else if (minutes == 1) | ||
67 | return tr("1 minute ago"); | ||
68 | else if (minutes < 60) | ||
69 | return tr("%1 minutes ago").arg(minutes); | ||
70 | qint64 hours = qRound64(minutes / 60.0f); | ||
71 | if (hours == 1) | ||
72 | return tr("1 hour ago"); | ||
73 | else if (hours < 24) | ||
74 | return tr("%1 hours ago").arg(hours); | ||
75 | qint64 days = qRound64(hours / 24.0f); | ||
76 | if (days == 1) | ||
77 | return tr("1 day ago"); | ||
78 | else if (days <= 10) | ||
79 | return tr("%1 days ago").arg(days); | ||
80 | QString string = time.toString(); | ||
81 | return standalone ? string : tr("on %1").arg(string); | ||
82 | } | ||
diff --git a/prototype_2016/third_party/fluid/src/dateutils.h b/prototype_2016/third_party/fluid/src/dateutils.h new file mode 100644 index 0000000..e49cbac --- /dev/null +++ b/prototype_2016/third_party/fluid/src/dateutils.h | |||
@@ -0,0 +1,44 @@ | |||
1 | /* | ||
2 | * This file is part of Fluid. | ||
3 | * | ||
4 | * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> | ||
5 | * Copyright (C) 2017 Michael Spencer <sonrisesoftware@gmail.com> | ||
6 | * | ||
7 | * $BEGIN_LICENSE:MPL2$ | ||
8 | * | ||
9 | * This Source Code Form is subject to the terms of the Mozilla Public | ||
10 | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
11 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
12 | * | ||
13 | * $END_LICENSE$ | ||
14 | */ | ||
15 | |||
16 | #pragma once | ||
17 | |||
18 | #ifdef FLUID_LOCAL | ||
19 | #define FLUID_EXPORT | ||
20 | #else | ||
21 | #include <Fluid/fluid/fluid_export.h> | ||
22 | #endif | ||
23 | #include <QtCore/QObject> | ||
24 | #include <QtCore/QDateTime> | ||
25 | |||
26 | namespace Fluid { | ||
27 | |||
28 | class FLUID_EXPORT DateUtils : public QObject | ||
29 | { | ||
30 | Q_OBJECT | ||
31 | |||
32 | public: | ||
33 | enum DurationFormat { Long, Short }; | ||
34 | Q_ENUM(DurationFormat) | ||
35 | |||
36 | enum DurationType { Seconds, Minutes, Hours, Any }; | ||
37 | Q_ENUM(DurationType) | ||
38 | |||
39 | static QString formatDuration(qlonglong duration, DurationFormat format = Short, | ||
40 | DurationType type = Any); | ||
41 | static QString friendlyTime(const QDateTime &time, bool standalone); | ||
42 | }; | ||
43 | |||
44 | } // namespace Fluid | ||
diff --git a/prototype_2016/third_party/fluid/src/src.pri b/prototype_2016/third_party/fluid/src/src.pri new file mode 100644 index 0000000..6b73833 --- /dev/null +++ b/prototype_2016/third_party/fluid/src/src.pri | |||
@@ -0,0 +1,5 @@ | |||
1 | HEADERS += \ | ||
2 | $$PWD/dateutils.h | ||
3 | |||
4 | SOURCES += \ | ||
5 | $$PWD/dateutils.cpp | ||