mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 01:13:19 +00:00
Remove unused code, move logic from .h to their .cpp, clean some things
This commit is contained in:
parent
924e35ecc4
commit
cb6c663833
41 changed files with 492 additions and 978 deletions
|
@ -1,22 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="vyn.mirai" android:installLocation="auto" android:versionCode="-- %%INSERT_VERSION_CODE%% --" android:versionName="-- %%INSERT_VERSION_NAME%% --">
|
|
||||||
<!-- %%INSERT_PERMISSIONS -->
|
|
||||||
<!-- %%INSERT_FEATURES -->
|
|
||||||
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
|
|
||||||
<application android:name="org.qtproject.qt.android.bindings.QtApplication" android:hardwareAccelerated="true" android:label="-- %%INSERT_APP_NAME%% --" android:requestLegacyExternalStorage="true" android:allowBackup="true" android:fullBackupOnly="false">
|
|
||||||
<activity android:name="org.qtproject.qt.android.bindings.QtActivity" android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:launchMode="singleTop" android:screenOrientation="unspecified" android:exported="true" android:label="">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
|
||||||
</intent-filter>
|
|
||||||
<meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
|
|
||||||
<meta-data android:name="android.app.arguments" android:value="-- %%INSERT_APP_ARGUMENTS%% --"/>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.qtprovider" android:exported="false" android:grantUriPermissions="true">
|
|
||||||
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/qtprovider_paths"/>
|
|
||||||
</provider>
|
|
||||||
</application>
|
|
||||||
|
|
||||||
|
|
||||||
</manifest>
|
|
|
@ -1,82 +0,0 @@
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
google()
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath 'com.android.tools.build:gradle:7.4.1'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
google()
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'com.android.application'
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
|
||||||
implementation 'androidx.core:core:1.10.1'
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
/*******************************************************
|
|
||||||
* The following variables:
|
|
||||||
* - androidBuildToolsVersion,
|
|
||||||
* - androidCompileSdkVersion
|
|
||||||
* - qtAndroidDir - holds the path to qt android files
|
|
||||||
* needed to build any Qt application
|
|
||||||
* on Android.
|
|
||||||
*
|
|
||||||
* are defined in gradle.properties file. This file is
|
|
||||||
* updated by QtCreator and androiddeployqt tools.
|
|
||||||
* Changing them manually might break the compilation!
|
|
||||||
*******************************************************/
|
|
||||||
|
|
||||||
compileSdkVersion androidCompileSdkVersion
|
|
||||||
buildToolsVersion androidBuildToolsVersion
|
|
||||||
ndkVersion androidNdkVersion
|
|
||||||
|
|
||||||
// Extract native libraries from the APK
|
|
||||||
packagingOptions.jniLibs.useLegacyPackaging true
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
manifest.srcFile 'AndroidManifest.xml'
|
|
||||||
java.srcDirs = [qtAndroidDir + '/src', 'src', 'java']
|
|
||||||
aidl.srcDirs = [qtAndroidDir + '/src', 'src', 'aidl']
|
|
||||||
res.srcDirs = [qtAndroidDir + '/res', 'res']
|
|
||||||
resources.srcDirs = ['resources']
|
|
||||||
renderscript.srcDirs = ['src']
|
|
||||||
assets.srcDirs = ['assets']
|
|
||||||
jniLibs.srcDirs = ['libs']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
|
||||||
options.incremental = true
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
|
|
||||||
lintOptions {
|
|
||||||
abortOnError false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not compress Qt binary resources file
|
|
||||||
aaptOptions {
|
|
||||||
noCompress 'rcc'
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
resConfig "en"
|
|
||||||
minSdkVersion qtMinSdkVersion
|
|
||||||
targetSdkVersion qtTargetSdkVersion
|
|
||||||
ndk.abiFilters = qtTargetAbiList.split(",")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Project-wide Gradle settings.
|
|
||||||
# For more details on how to configure your build environment visit
|
|
||||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
|
||||||
# Specifies the JVM arguments used for the daemon process.
|
|
||||||
# The setting is particularly useful for tweaking memory settings.
|
|
||||||
org.gradle.jvmargs=-Xmx2500m -XX:MaxMetaspaceSize=768m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
|
||||||
|
|
||||||
# Enable building projects in parallel
|
|
||||||
org.gradle.parallel=true
|
|
||||||
|
|
||||||
# Gradle caching allows reusing the build artifacts from a previous
|
|
||||||
# build with the same inputs. However, over time, the cache size will
|
|
||||||
# grow. Uncomment the following line to enable it.
|
|
||||||
#org.gradle.caching=true
|
|
||||||
#org.gradle.configuration-cache=true
|
|
||||||
|
|
||||||
# Allow AndroidX usage
|
|
||||||
android.useAndroidX=true
|
|
BIN
android/gradle/wrapper/gradle-wrapper.jar
vendored
BIN
android/gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
|
@ -1,7 +0,0 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
|
|
||||||
networkTimeout=10000
|
|
||||||
validateDistributionUrl=true
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
249
android/gradlew
vendored
249
android/gradlew
vendored
|
@ -1,249 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright © 2015-2021 the original authors.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
#
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Gradle start up script for POSIX generated by Gradle.
|
|
||||||
#
|
|
||||||
# Important for running:
|
|
||||||
#
|
|
||||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
|
||||||
# noncompliant, but you have some other compliant shell such as ksh or
|
|
||||||
# bash, then to run this script, type that shell name before the whole
|
|
||||||
# command line, like:
|
|
||||||
#
|
|
||||||
# ksh Gradle
|
|
||||||
#
|
|
||||||
# Busybox and similar reduced shells will NOT work, because this script
|
|
||||||
# requires all of these POSIX shell features:
|
|
||||||
# * functions;
|
|
||||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
|
||||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
|
||||||
# * compound commands having a testable exit status, especially «case»;
|
|
||||||
# * various built-in commands including «command», «set», and «ulimit».
|
|
||||||
#
|
|
||||||
# Important for patching:
|
|
||||||
#
|
|
||||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
|
||||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
|
||||||
#
|
|
||||||
# The "traditional" practice of packing multiple parameters into a
|
|
||||||
# space-separated string is a well documented source of bugs and security
|
|
||||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
|
||||||
# options in "$@", and eventually passing that to Java.
|
|
||||||
#
|
|
||||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
|
||||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
|
||||||
# see the in-line comments for details.
|
|
||||||
#
|
|
||||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
|
||||||
# Darwin, MinGW, and NonStop.
|
|
||||||
#
|
|
||||||
# (3) This script is generated from the Groovy template
|
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
|
||||||
# within the Gradle project.
|
|
||||||
#
|
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
app_path=$0
|
|
||||||
|
|
||||||
# Need this for daisy-chained symlinks.
|
|
||||||
while
|
|
||||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
|
||||||
[ -h "$app_path" ]
|
|
||||||
do
|
|
||||||
ls=$( ls -ld "$app_path" )
|
|
||||||
link=${ls#*' -> '}
|
|
||||||
case $link in #(
|
|
||||||
/*) app_path=$link ;; #(
|
|
||||||
*) app_path=$APP_HOME$link ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# This is normally unused
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
APP_BASE_NAME=${0##*/}
|
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD=maximum
|
|
||||||
|
|
||||||
warn () {
|
|
||||||
echo "$*"
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
die () {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
nonstop=false
|
|
||||||
case "$( uname )" in #(
|
|
||||||
CYGWIN* ) cygwin=true ;; #(
|
|
||||||
Darwin* ) darwin=true ;; #(
|
|
||||||
MSYS* | MINGW* ) msys=true ;; #(
|
|
||||||
NONSTOP* ) nonstop=true ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
|
||||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
|
||||||
else
|
|
||||||
JAVACMD=$JAVA_HOME/bin/java
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD=java
|
|
||||||
if ! command -v java >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|
||||||
case $MAX_FD in #(
|
|
||||||
max*)
|
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC3045
|
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
|
||||||
warn "Could not query maximum file descriptor limit"
|
|
||||||
esac
|
|
||||||
case $MAX_FD in #(
|
|
||||||
'' | soft) :;; #(
|
|
||||||
*)
|
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC3045
|
|
||||||
ulimit -n "$MAX_FD" ||
|
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Collect all arguments for the java command, stacking in reverse order:
|
|
||||||
# * args from the command line
|
|
||||||
# * the main class name
|
|
||||||
# * -classpath
|
|
||||||
# * -D...appname settings
|
|
||||||
# * --module-path (only if needed)
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if "$cygwin" || "$msys" ; then
|
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
|
||||||
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
for arg do
|
|
||||||
if
|
|
||||||
case $arg in #(
|
|
||||||
-*) false ;; # don't mess with options #(
|
|
||||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
|
||||||
[ -e "$t" ] ;; #(
|
|
||||||
*) false ;;
|
|
||||||
esac
|
|
||||||
then
|
|
||||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
|
||||||
fi
|
|
||||||
# Roll the args list around exactly as many times as the number of
|
|
||||||
# args, so each arg winds up back in the position where it started, but
|
|
||||||
# possibly modified.
|
|
||||||
#
|
|
||||||
# NB: a `for` loop captures its iteration list before it begins, so
|
|
||||||
# changing the positional parameters here affects neither the number of
|
|
||||||
# iterations, nor the values presented in `arg`.
|
|
||||||
shift # remove old arg
|
|
||||||
set -- "$@" "$arg" # push replacement arg
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
|
||||||
|
|
||||||
set -- \
|
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
|
||||||
-classpath "$CLASSPATH" \
|
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
|
||||||
"$@"
|
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
|
||||||
if ! command -v xargs >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "xargs is not available"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
|
||||||
#
|
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
|
||||||
#
|
|
||||||
# In Bash we could simply go:
|
|
||||||
#
|
|
||||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
|
||||||
# set -- "${ARGS[@]}" "$@"
|
|
||||||
#
|
|
||||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
|
||||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
|
||||||
# character that might be a shell metacharacter, then use eval to reverse
|
|
||||||
# that process (while maintaining the separation between arguments), and wrap
|
|
||||||
# the whole thing up as a single "set" statement.
|
|
||||||
#
|
|
||||||
# This will of course break if any of these variables contains a newline or
|
|
||||||
# an unmatched quote.
|
|
||||||
#
|
|
||||||
|
|
||||||
eval "set -- $(
|
|
||||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
|
||||||
xargs -n1 |
|
|
||||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
|
||||||
tr '\n' ' '
|
|
||||||
)" '"$@"'
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
|
92
android/gradlew.bat
vendored
92
android/gradlew.bat
vendored
|
@ -1,92 +0,0 @@
|
||||||
@rem
|
|
||||||
@rem Copyright 2015 the original author or authors.
|
|
||||||
@rem
|
|
||||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
@rem you may not use this file except in compliance with the License.
|
|
||||||
@rem You may obtain a copy of the License at
|
|
||||||
@rem
|
|
||||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
@rem
|
|
||||||
@rem Unless required by applicable law or agreed to in writing, software
|
|
||||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
@rem See the License for the specific language governing permissions and
|
|
||||||
@rem limitations under the License.
|
|
||||||
@rem
|
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
|
||||||
@rem ##########################################################################
|
|
||||||
@rem
|
|
||||||
@rem Gradle startup script for Windows
|
|
||||||
@rem
|
|
||||||
@rem ##########################################################################
|
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
|
||||||
@rem This is normally unused
|
|
||||||
set APP_BASE_NAME=%~n0
|
|
||||||
set APP_HOME=%DIRNAME%
|
|
||||||
|
|
||||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
||||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
set DEFAULT_JVM_OPTS=-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"
|
|
||||||
|
|
||||||
@rem Find java.exe
|
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:execute
|
|
||||||
@rem Setup the command line
|
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
||||||
|
|
||||||
:end
|
|
||||||
@rem End local scope for the variables with windows NT shell
|
|
||||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
|
||||||
|
|
||||||
:fail
|
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
||||||
rem the _cmd.exe /c_ return code!
|
|
||||||
set EXIT_CODE=%ERRORLEVEL%
|
|
||||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
|
||||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
|
||||||
exit /b %EXIT_CODE%
|
|
||||||
|
|
||||||
:mainEnd
|
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
|
||||||
|
|
||||||
:omega
|
|
|
@ -1,21 +0,0 @@
|
||||||
<?xml version='1.0' encoding='utf-8'?>
|
|
||||||
<resources>
|
|
||||||
<!-- DO NOT EDIT THIS: This file is populated automatically by the deployment tool. -->
|
|
||||||
|
|
||||||
<array name="bundled_libs">
|
|
||||||
<!-- %%INSERT_EXTRA_LIBS%% -->
|
|
||||||
</array>
|
|
||||||
|
|
||||||
<array name="qt_libs">
|
|
||||||
<!-- %%INSERT_QT_LIBS%% -->
|
|
||||||
</array>
|
|
||||||
|
|
||||||
<array name="load_local_libs">
|
|
||||||
<!-- %%INSERT_LOCAL_LIBS%% -->
|
|
||||||
</array>
|
|
||||||
|
|
||||||
<string name="static_init_classes"><!-- %%INSERT_INIT_CLASSES%% --></string>
|
|
||||||
<string name="use_local_qt_libs"><!-- %%USE_LOCAL_QT_LIBS%% --></string>
|
|
||||||
<string name="bundle_local_qt_libs"><!-- %%BUNDLE_LOCAL_QT_LIBS%% --></string>
|
|
||||||
<string name="system_libs_prefix"><!-- %%SYSTEM_LIBS_PREFIX%% --></string>
|
|
||||||
</resources>
|
|
|
@ -1,4 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<files-path name="files_path" path="/"/>
|
|
||||||
</paths>
|
|
4
external/mirai-core/CMakeLists.txt
vendored
4
external/mirai-core/CMakeLists.txt
vendored
|
@ -14,12 +14,12 @@ add_library(mirai-core
|
||||||
src/Event.cpp
|
src/Event.cpp
|
||||||
src/DateTime.cpp
|
src/DateTime.cpp
|
||||||
src/EventEmitter.cpp
|
src/EventEmitter.cpp
|
||||||
src/BaseResource.cpp
|
src/BaseSource.cpp
|
||||||
|
src/StdFileSource.cpp
|
||||||
src/TasksView.cpp
|
src/TasksView.cpp
|
||||||
src/TodoMd.cpp
|
src/TodoMd.cpp
|
||||||
src/utils.cpp
|
src/utils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
target_include_directories(mirai-core PRIVATE "external")
|
target_include_directories(mirai-core PRIVATE "external")
|
||||||
target_include_directories(mirai-core PRIVATE "include/mirai-core")
|
target_include_directories(mirai-core PRIVATE "include/mirai-core")
|
||||||
|
|
|
@ -4,29 +4,27 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MIRAI_BASE_FILE_RESOURCE_H
|
#pragma once
|
||||||
#define MIRAI_BASE_FILE_RESOURCE_H
|
|
||||||
|
|
||||||
#include "BaseResource.h"
|
#include "BaseSource.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mirai
|
namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
struct BaseFileResourceConstructor {
|
struct BaseFileSourceConstructor {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string path;
|
std::string path;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BaseFileResource : public BaseResource
|
class BaseFileSource : public BaseSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BaseFileResource(BaseFileResourceConstructor data)
|
BaseFileSource(BaseFileSourceConstructor data) : BaseSource(data.name), path(data.path) {};
|
||||||
: BaseResource(data.name), path(data.path) {};
|
|
||||||
|
|
||||||
BaseFileResource(BaseFileResource &) = delete;
|
BaseFileSource(BaseFileSource &) = delete;
|
||||||
BaseFileResource(BaseFileResource &&) = delete;
|
BaseFileSource(BaseFileSource &&) = delete;
|
||||||
~BaseFileResource() override = default;
|
~BaseFileSource() override = default;
|
||||||
|
|
||||||
const std::string &getPath() const
|
const std::string &getPath() const
|
||||||
{
|
{
|
||||||
|
@ -37,4 +35,3 @@ class BaseFileResource : public BaseResource
|
||||||
std::string path;
|
std::string path;
|
||||||
};
|
};
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
#endif
|
|
|
@ -4,8 +4,7 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MIRAI_BASE_RESOURCE_H
|
#pragma once
|
||||||
#define MIRAI_BASE_RESOURCE_H
|
|
||||||
|
|
||||||
#include "DateTime.h"
|
#include "DateTime.h"
|
||||||
#include "Day.h"
|
#include "Day.h"
|
||||||
|
@ -19,7 +18,7 @@
|
||||||
namespace mirai
|
namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
class BaseResource
|
class BaseSource
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -28,23 +27,16 @@ class BaseResource
|
||||||
Tags tags;
|
Tags tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseResource(std::string name) : name_(name) {};
|
BaseSource(std::string name) : name_(name) {};
|
||||||
BaseResource(BaseResource &) = delete;
|
BaseSource(BaseSource &) = delete;
|
||||||
BaseResource(BaseResource &&) = delete;
|
BaseSource(BaseSource &&) = delete;
|
||||||
|
|
||||||
virtual ~BaseResource() = default;
|
virtual ~BaseSource() = default;
|
||||||
virtual void save() = 0;
|
virtual void save() = 0;
|
||||||
virtual void load() = 0;
|
virtual void load() = 0;
|
||||||
|
|
||||||
void setName(std::string name)
|
void setName(std::string name);
|
||||||
{
|
const std::string &getName() const;
|
||||||
this->name_ = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string &getName() const
|
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addDay(const DayData &dayData);
|
void addDay(const DayData &dayData);
|
||||||
Day *day(const Date &date);
|
Day *day(const Date &date);
|
||||||
|
@ -56,10 +48,7 @@ class BaseResource
|
||||||
void setDirty(bool shouldBeDirty);
|
void setDirty(bool shouldBeDirty);
|
||||||
bool isDirty() const;
|
bool isDirty() const;
|
||||||
|
|
||||||
int id() const
|
int id() const;
|
||||||
{
|
|
||||||
return id_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int nextId_;
|
static int nextId_;
|
||||||
|
@ -70,4 +59,3 @@ class BaseResource
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
#endif
|
|
|
@ -16,78 +16,28 @@ namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Date {
|
struct Date {
|
||||||
explicit Date(int year, unsigned month, unsigned day) : year(year), month(month), day(day)
|
explicit Date(int year, unsigned month, unsigned day);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit Date(std::chrono::time_point<std::chrono::system_clock> tp)
|
explicit Date(std::chrono::time_point<std::chrono::system_clock> tp);
|
||||||
{
|
explicit Date(std::chrono::year_month_day chronoDate);
|
||||||
auto chronoDate = std::chrono::year_month_day(std::chrono::floor<std::chrono::days>(tp));
|
|
||||||
year = static_cast<int>(chronoDate.year());
|
|
||||||
month = static_cast<unsigned>(chronoDate.month());
|
|
||||||
day = static_cast<unsigned>(chronoDate.day());
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit Date(std::chrono::year_month_day chronoDate)
|
bool operator==(const Date &other) const;
|
||||||
{
|
bool operator<(const Date &other) const;
|
||||||
year = static_cast<int>(chronoDate.year());
|
bool operator>(const Date &other) const;
|
||||||
month = static_cast<unsigned>(chronoDate.month());
|
|
||||||
day = static_cast<unsigned>(chronoDate.day());
|
|
||||||
}
|
|
||||||
|
|
||||||
int year;
|
int year;
|
||||||
unsigned month;
|
unsigned month;
|
||||||
unsigned day;
|
unsigned day;
|
||||||
|
|
||||||
bool operator==(const Date &other) const
|
|
||||||
{
|
|
||||||
return other.year == year && other.month == month && other.day == day;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator<(const Date &other) const
|
|
||||||
{
|
|
||||||
if (year < other.year) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (year == other.year && month < other.month) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (year == other.year && month == other.month && day < other.day) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator>(const Date &other) const
|
|
||||||
{
|
|
||||||
return !(*this < other) && !(*this == other);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Time {
|
struct Time {
|
||||||
|
|
||||||
|
bool operator==(const Time &other) const;
|
||||||
|
bool operator<(const Time &other) const;
|
||||||
|
bool operator>(const Time &other) const;
|
||||||
|
|
||||||
int hour;
|
int hour;
|
||||||
int minute;
|
int minute;
|
||||||
|
|
||||||
bool operator==(const Time &other) const
|
|
||||||
{
|
|
||||||
return other.hour == hour && other.minute == minute;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator<(const Time &other) const
|
|
||||||
{
|
|
||||||
if (hour < other.hour) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (hour == other.hour && minute < other.minute) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator>(const Time &other) const
|
|
||||||
{
|
|
||||||
return !(*this < other) && !(*this == other);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::optional<mirai::Date> stringToDate(const std::string &dateStr);
|
std::optional<mirai::Date> stringToDate(const std::string &dateStr);
|
||||||
|
|
22
external/mirai-core/include/mirai-core/Day.h
vendored
22
external/mirai-core/include/mirai-core/Day.h
vendored
|
@ -17,7 +17,7 @@
|
||||||
namespace mirai
|
namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
class BaseResource;
|
class BaseSource;
|
||||||
|
|
||||||
struct DayData {
|
struct DayData {
|
||||||
Date date;
|
Date date;
|
||||||
|
@ -28,7 +28,7 @@ struct DayData {
|
||||||
class Day
|
class Day
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Day(BaseResource *source, const DayData &data);
|
Day(BaseSource *source, const DayData &data);
|
||||||
void setDate(const Date &date);
|
void setDate(const Date &date);
|
||||||
|
|
||||||
Event *createEvent(const EventData &eventData);
|
Event *createEvent(const EventData &eventData);
|
||||||
|
@ -40,25 +40,13 @@ class Day
|
||||||
|
|
||||||
const Date &getDate() const;
|
const Date &getDate() const;
|
||||||
|
|
||||||
Event *getEventById(int eventId)
|
Event *getEventById(int eventId);
|
||||||
{
|
BaseSource *source();
|
||||||
for (auto &event : events_) {
|
|
||||||
if (event->id() == eventId) {
|
|
||||||
return event.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseResource *source()
|
|
||||||
{
|
|
||||||
return source_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onChange();
|
void onChange();
|
||||||
|
|
||||||
BaseResource *source_;
|
BaseSource *source_;
|
||||||
std::vector<std::unique_ptr<Event>> events_;
|
std::vector<std::unique_ptr<Event>> events_;
|
||||||
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
||||||
DayData data_;
|
DayData data_;
|
||||||
|
|
24
external/mirai-core/include/mirai-core/Event.h
vendored
24
external/mirai-core/include/mirai-core/Event.h
vendored
|
@ -16,7 +16,7 @@
|
||||||
namespace mirai
|
namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
class BaseResource;
|
class BaseSource;
|
||||||
|
|
||||||
struct EventData {
|
struct EventData {
|
||||||
std::string description;
|
std::string description;
|
||||||
|
@ -33,14 +33,9 @@ class Event
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
public:
|
public:
|
||||||
Event(BaseResource *source, Day *parent, const EventData &data);
|
Event(BaseSource *source, Day *parent, const EventData &data);
|
||||||
|
|
||||||
Event &operator=(const EventData &newData)
|
Event &operator=(const EventData &newData);
|
||||||
{
|
|
||||||
data = newData;
|
|
||||||
onChange();
|
|
||||||
return *this;
|
|
||||||
};
|
|
||||||
|
|
||||||
void setText(const std::string &text);
|
void setText(const std::string &text);
|
||||||
void setStartTime(const Time &time);
|
void setStartTime(const Time &time);
|
||||||
|
@ -57,15 +52,8 @@ class Event
|
||||||
const Tags &getTags() const;
|
const Tags &getTags() const;
|
||||||
bool hasTag(const std::string &tag) const;
|
bool hasTag(const std::string &tag) const;
|
||||||
|
|
||||||
int id() const
|
int id() const;
|
||||||
{
|
Day *day();
|
||||||
return id_;
|
|
||||||
}
|
|
||||||
|
|
||||||
Day *day()
|
|
||||||
{
|
|
||||||
return day_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onChange();
|
void onChange();
|
||||||
|
@ -75,6 +63,6 @@ class Event
|
||||||
Day *day_;
|
Day *day_;
|
||||||
EventData data;
|
EventData data;
|
||||||
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
||||||
BaseResource *source_;
|
BaseSource *source_;
|
||||||
};
|
};
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
30
external/mirai-core/include/mirai-core/Mirai.h
vendored
30
external/mirai-core/include/mirai-core/Mirai.h
vendored
|
@ -4,11 +4,10 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MIRAI_MIRAI_H
|
#pragma once
|
||||||
#define MIRAI_MIRAI_H
|
|
||||||
|
|
||||||
#include "BaseFileResource.h"
|
#include "BaseFileSource.h"
|
||||||
#include "BaseResource.h"
|
#include "BaseSource.h"
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include "TodoMd.h"
|
#include "TodoMd.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -25,31 +24,22 @@ class Mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void loadResource(std::unique_ptr<BaseResource> &&resource);
|
void loadSource(std::unique_ptr<BaseSource> &&resource);
|
||||||
void unloadAllResources();
|
void unloadAllSources();
|
||||||
void save();
|
void save();
|
||||||
void removeTask(const TaskItem *taskItem);
|
void deleteTask(const TaskItem &taskItem);
|
||||||
std::optional<std::reference_wrapper<BaseResource>> getResourceByName(const std::string &name);
|
std::optional<std::reference_wrapper<BaseSource>> getSourceByName(const std::string &name);
|
||||||
|
|
||||||
std::vector<std::unique_ptr<BaseResource>> &getResources();
|
std::vector<std::unique_ptr<BaseSource>> &getSources();
|
||||||
const std::vector<std::string> &getTags();
|
const std::vector<std::string> &getTags();
|
||||||
|
|
||||||
void reloadTags();
|
void reloadTags();
|
||||||
|
|
||||||
// new stuff
|
|
||||||
|
|
||||||
// Returns a non owning pointer to the requested resource or nullptr if not found.
|
// Returns a non owning pointer to the requested resource or nullptr if not found.
|
||||||
BaseResource *getResourceById(int id)
|
BaseSource *getSourceById(int id);
|
||||||
{
|
|
||||||
if (id >= resources_.size()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return resources_.at(id).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<BaseResource>> resources_;
|
std::vector<std::unique_ptr<BaseSource>> sources_;
|
||||||
std::vector<std::string> tags_;
|
std::vector<std::string> tags_;
|
||||||
};
|
};
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
* Mirai. Copyright (C) 2024 Vyn
|
|
||||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MIRAI_STD_FILE_RESOURCE_H
|
|
||||||
#define MIRAI_STD_FILE_RESOURCE_H
|
|
||||||
|
|
||||||
#include "BaseFileResource.h"
|
|
||||||
#include "TodoMd.h"
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <ostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace mirai
|
|
||||||
{
|
|
||||||
|
|
||||||
class StdFileResource : public BaseFileResource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
StdFileResource(BaseFileResourceConstructor data) : BaseFileResource(data) {};
|
|
||||||
StdFileResource(StdFileResource &) = delete;
|
|
||||||
StdFileResource(StdFileResource &&) = delete;
|
|
||||||
StdFileResource operator=(StdFileResource &) = delete;
|
|
||||||
StdFileResource operator=(StdFileResource &&) = delete;
|
|
||||||
|
|
||||||
~StdFileResource() override = default;
|
|
||||||
|
|
||||||
void save() override
|
|
||||||
{
|
|
||||||
std::ofstream file(getPath());
|
|
||||||
if (!file.is_open()) {
|
|
||||||
throw std::runtime_error("can't create " + getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string content = TodoMdFormat::stringify(getName(), *days());
|
|
||||||
|
|
||||||
file << content;
|
|
||||||
file.close();
|
|
||||||
};
|
|
||||||
|
|
||||||
void load() override
|
|
||||||
{
|
|
||||||
std::ifstream file(getPath());
|
|
||||||
if (!file.is_open()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string content = "";
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
while (std::getline(file, line)) {
|
|
||||||
content += line + "\n";
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
auto result = TodoMdFormat::parse(content);
|
|
||||||
for (const auto &dayData : result.days) {
|
|
||||||
Day *newDay = day(dayData.date);
|
|
||||||
for (const auto &eventData : dayData.events) {
|
|
||||||
Event *newEvent = newDay->createEvent(eventData);
|
|
||||||
for (const auto &taskData : eventData.tasks) {
|
|
||||||
TaskItem *newTask = newEvent->createTask(taskData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const auto &taskData : dayData.tasks) {
|
|
||||||
TaskItem *newTask = newDay->createTask(taskData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setName(result.name);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
} // namespace mirai
|
|
||||||
#endif
|
|
29
external/mirai-core/include/mirai-core/StdFileSource.h
vendored
Normal file
29
external/mirai-core/include/mirai-core/StdFileSource.h
vendored
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Mirai. Copyright (C) 2024 Vyn
|
||||||
|
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||||
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BaseFileSource.h"
|
||||||
|
|
||||||
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
|
class StdFileSource : public BaseFileSource
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StdFileSource(BaseFileSourceConstructor data) : BaseFileSource(data) {};
|
||||||
|
StdFileSource(StdFileSource &) = delete;
|
||||||
|
StdFileSource(StdFileSource &&) = delete;
|
||||||
|
StdFileSource operator=(StdFileSource &) = delete;
|
||||||
|
StdFileSource operator=(StdFileSource &&) = delete;
|
||||||
|
|
||||||
|
~StdFileSource() override = default;
|
||||||
|
|
||||||
|
void save() override;
|
||||||
|
void load() override;
|
||||||
|
;
|
||||||
|
};
|
||||||
|
} // namespace mirai
|
|
@ -4,8 +4,7 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MIRAI_TASKITEM_H
|
#pragma once
|
||||||
#define MIRAI_TASKITEM_H
|
|
||||||
|
|
||||||
#include "using.h"
|
#include "using.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -14,7 +13,7 @@
|
||||||
namespace mirai
|
namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
class BaseResource;
|
class BaseSource;
|
||||||
class Day;
|
class Day;
|
||||||
|
|
||||||
enum TaskItemState { TODO, DONE };
|
enum TaskItemState { TODO, DONE };
|
||||||
|
@ -28,20 +27,13 @@ struct TaskItemData {
|
||||||
class TaskItem
|
class TaskItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TaskItem(BaseResource *source, Day *day, const TaskItemData data);
|
TaskItem(BaseSource *source, Day *day, const TaskItemData data);
|
||||||
|
|
||||||
TaskItem &operator=(const TaskItemData &newData)
|
TaskItem &operator=(const TaskItemData &newData);
|
||||||
{
|
|
||||||
data = newData;
|
|
||||||
onChange();
|
|
||||||
return *this;
|
|
||||||
};
|
|
||||||
|
|
||||||
void markAsDone();
|
void markAsDone();
|
||||||
|
|
||||||
void markAsUndone();
|
void markAsUndone();
|
||||||
void setDate(const std::string &date);
|
void setDate(const std::string &date);
|
||||||
|
|
||||||
void setText(const std::string &text);
|
void setText(const std::string &text);
|
||||||
|
|
||||||
const std::string &getLine() const;
|
const std::string &getLine() const;
|
||||||
|
@ -50,20 +42,9 @@ class TaskItem
|
||||||
const Tags &getTags() const;
|
const Tags &getTags() const;
|
||||||
bool hasTag(const std::string &tag) const;
|
bool hasTag(const std::string &tag) const;
|
||||||
|
|
||||||
int id() const
|
int id() const;
|
||||||
{
|
BaseSource *source();
|
||||||
return id_;
|
Day *day();
|
||||||
}
|
|
||||||
|
|
||||||
BaseResource *source()
|
|
||||||
{
|
|
||||||
return source_;
|
|
||||||
}
|
|
||||||
|
|
||||||
Day *day()
|
|
||||||
{
|
|
||||||
return day_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onChange();
|
void onChange();
|
||||||
|
@ -72,10 +53,8 @@ class TaskItem
|
||||||
int id_ = nextId++;
|
int id_ = nextId++;
|
||||||
TaskItemData data;
|
TaskItemData data;
|
||||||
|
|
||||||
BaseResource *source_;
|
BaseSource *source_;
|
||||||
Day *day_;
|
Day *day_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MIRAI_TASKSVIEW_H
|
#pragma once
|
||||||
#define MIRAI_TASKSVIEW_H
|
|
||||||
#include "Mirai.h"
|
#include "Mirai.h"
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include "using.h"
|
#include "using.h"
|
||||||
|
@ -39,41 +38,14 @@ class TasksView
|
||||||
void update();
|
void update();
|
||||||
void addTagFilter(const std::string &tag);
|
void addTagFilter(const std::string &tag);
|
||||||
void removeTagFilter(const std::string &tag);
|
void removeTagFilter(const std::string &tag);
|
||||||
void addResourceFilter(const std::string &fileName);
|
void addSourceFilter(const std::string &fileName);
|
||||||
void removeResourceFilter(const std::string &fileName);
|
void removeSourceFilter(const std::string &fileName);
|
||||||
void removeFilters();
|
void removeFilters();
|
||||||
const Tags &getActiveTagsFilter();
|
const Tags &getActiveTagsFilter();
|
||||||
const std::vector<std::string> &getActiveFilesFilter();
|
const std::vector<std::string> &getActiveFilesFilter();
|
||||||
|
|
||||||
void hideCompletedTasks(bool hide)
|
void hideCompletedTasks(bool hide);
|
||||||
{
|
bool shouldHideCompletedTasks() const;
|
||||||
shouldHideCompletedTasks_ = hide;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool shouldHideCompletedTasks() const
|
|
||||||
{
|
|
||||||
return shouldHideCompletedTasks_;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*auto begin()*/ // TODO REWORK
|
|
||||||
/*{*/
|
|
||||||
/*return tasksToShow.begin();*/
|
|
||||||
/*}*/
|
|
||||||
|
|
||||||
/*auto begin() const*/
|
|
||||||
/*{*/
|
|
||||||
/*return tasksToShow.cbegin();*/
|
|
||||||
/*}*/
|
|
||||||
|
|
||||||
/*auto end() const*/
|
|
||||||
/*{*/
|
|
||||||
/*return tasksToShow.cend();*/
|
|
||||||
/*}*/
|
|
||||||
|
|
||||||
/*auto end()*/
|
|
||||||
/*{*/
|
|
||||||
/*return tasksToShow.end();*/
|
|
||||||
/*}*/
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<FilteredDay> filteredDays;
|
std::vector<FilteredDay> filteredDays;
|
||||||
|
@ -84,4 +56,3 @@ class TasksView
|
||||||
bool shouldHideCompletedTasks_ = true;
|
bool shouldHideCompletedTasks_ = true;
|
||||||
};
|
};
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
#endif
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MIRAI_TODOMD_H
|
#pragma once
|
||||||
#define MIRAI_TODOMD_H
|
|
||||||
|
|
||||||
#include "DateTime.h"
|
#include "DateTime.h"
|
||||||
#include "Day.h"
|
#include "Day.h"
|
||||||
|
@ -44,5 +43,3 @@ class TodoMdFormat
|
||||||
static Tags extractTagsFromMetadata(std::string metadata);
|
static Tags extractTagsFromMetadata(std::string metadata);
|
||||||
};
|
};
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MIRAI_TODOTXT_H
|
#pragma once
|
||||||
#define MIRAI_TODOTXT_H
|
|
||||||
|
|
||||||
/*#include "TaskItem.h"*/
|
/*#include "TaskItem.h"*/
|
||||||
/*#include "utils.h"*/
|
/*#include "utils.h"*/
|
||||||
|
@ -90,5 +89,3 @@
|
||||||
/*}*/
|
/*}*/
|
||||||
/*};*/
|
/*};*/
|
||||||
/*}*/
|
/*}*/
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MIRAI_USING_H
|
#pragma once
|
||||||
#define MIRAI_USING_H
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -15,5 +14,3 @@ namespace mirai
|
||||||
{
|
{
|
||||||
using Tags = std::vector<std::string>;
|
using Tags = std::vector<std::string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MIRAI_UTILS_H
|
#pragma once
|
||||||
#define MIRAI_UTILS_H
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
@ -21,5 +20,3 @@ namespace vectorUtils = cpputils::vector;
|
||||||
|
|
||||||
bool isDate(const std::string &dateStr);
|
bool isDate(const std::string &dateStr);
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BaseResource.h"
|
#include "BaseSource.h"
|
||||||
#include "Day.h"
|
#include "Day.h"
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -16,17 +16,17 @@
|
||||||
namespace mirai
|
namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
void BaseResource::setDirty(bool shouldBeDirty)
|
void BaseSource::setDirty(bool shouldBeDirty)
|
||||||
{
|
{
|
||||||
isDirty_ = shouldBeDirty;
|
isDirty_ = shouldBeDirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseResource::isDirty() const
|
bool BaseSource::isDirty() const
|
||||||
{
|
{
|
||||||
return isDirty_;
|
return isDirty_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Day *BaseResource::day(const Date &date)
|
Day *BaseSource::day(const Date &date)
|
||||||
{
|
{
|
||||||
auto dayFound = std::find_if(days_.begin(), days_.end(), [&](std::unique_ptr<Day> &day) {
|
auto dayFound = std::find_if(days_.begin(), days_.end(), [&](std::unique_ptr<Day> &day) {
|
||||||
return day->getDate().day == date.day && day->getDate().month == date.month &&
|
return day->getDate().day == date.day && day->getDate().month == date.month &&
|
||||||
|
@ -41,18 +41,18 @@ Day *BaseResource::day(const Date &date)
|
||||||
return dayFound->get();
|
return dayFound->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Day>> *BaseResource::days()
|
std::vector<std::unique_ptr<Day>> *BaseSource::days()
|
||||||
{
|
{
|
||||||
return &days_;
|
return &days_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseResource::addDay(const DayData &dayData)
|
void BaseSource::addDay(const DayData &dayData)
|
||||||
{
|
{
|
||||||
days_.push_back(std::make_unique<Day>(this, dayData));
|
days_.push_back(std::make_unique<Day>(this, dayData));
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskItem *BaseResource::getTaskById(int taskId)
|
TaskItem *BaseSource::getTaskById(int taskId)
|
||||||
{
|
{
|
||||||
for (auto &day : days_) {
|
for (auto &day : days_) {
|
||||||
for (auto &task : *day->tasks()) {
|
for (auto &task : *day->tasks()) {
|
||||||
|
@ -71,7 +71,7 @@ TaskItem *BaseResource::getTaskById(int taskId)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseResource::deleteTask(const TaskItem &taskToDelete)
|
void BaseSource::deleteTask(const TaskItem &taskToDelete)
|
||||||
{
|
{
|
||||||
for (auto &day : days_) {
|
for (auto &day : days_) {
|
||||||
for (auto &task : *day->tasks()) {
|
for (auto &task : *day->tasks()) {
|
||||||
|
@ -91,7 +91,7 @@ void BaseResource::deleteTask(const TaskItem &taskToDelete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Event *BaseResource::getEventById(int eventId)
|
Event *BaseSource::getEventById(int eventId)
|
||||||
{
|
{
|
||||||
for (auto &day : days_) {
|
for (auto &day : days_) {
|
||||||
for (auto &event : *day->events()) {
|
for (auto &event : *day->events()) {
|
||||||
|
@ -103,6 +103,21 @@ Event *BaseResource::getEventById(int eventId)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseSource::setName(std::string name)
|
||||||
|
{
|
||||||
|
this->name_ = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &BaseSource::getName() const
|
||||||
|
{
|
||||||
|
return name_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BaseSource::id() const
|
||||||
|
{
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
|
||||||
/*void BaseResource::addTask(TaskItemData taskItem)*/
|
/*void BaseResource::addTask(TaskItemData taskItem)*/
|
||||||
/*{*/
|
/*{*/
|
||||||
/*tasks.push_back(std::make_unique<TaskItem>(this, taskItem));*/
|
/*tasks.push_back(std::make_unique<TaskItem>(this, taskItem));*/
|
||||||
|
@ -122,6 +137,6 @@ Event *BaseResource::getEventById(int eventId)
|
||||||
/*setDirty(true);*/
|
/*setDirty(true);*/
|
||||||
/*}*/
|
/*}*/
|
||||||
|
|
||||||
int BaseResource::nextId_ = 0;
|
int BaseSource::nextId_ = 0;
|
||||||
|
|
||||||
} // namespace mirai
|
} // namespace mirai
|
68
external/mirai-core/src/DateTime.cpp
vendored
68
external/mirai-core/src/DateTime.cpp
vendored
|
@ -34,4 +34,72 @@ std::optional<mirai::Date> stringToDate(const std::string &dateStr)
|
||||||
auto day = dateSplit[2];
|
auto day = dateSplit[2];
|
||||||
return mirai::Date(year, static_cast<unsigned>(month), static_cast<unsigned>(day));
|
return mirai::Date(year, static_cast<unsigned>(month), static_cast<unsigned>(day));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Date::Date(int year, unsigned month, unsigned day) : year(year), month(month), day(day)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Date::Date(std::chrono::time_point<std::chrono::system_clock> tp)
|
||||||
|
{
|
||||||
|
auto chronoDate = std::chrono::year_month_day(std::chrono::floor<std::chrono::days>(tp));
|
||||||
|
year = static_cast<int>(chronoDate.year());
|
||||||
|
month = static_cast<unsigned>(chronoDate.month());
|
||||||
|
day = static_cast<unsigned>(chronoDate.day());
|
||||||
|
}
|
||||||
|
|
||||||
|
Date::Date(std::chrono::year_month_day chronoDate)
|
||||||
|
{
|
||||||
|
year = static_cast<int>(chronoDate.year());
|
||||||
|
month = static_cast<unsigned>(chronoDate.month());
|
||||||
|
day = static_cast<unsigned>(chronoDate.day());
|
||||||
|
}
|
||||||
|
|
||||||
|
int year;
|
||||||
|
unsigned month;
|
||||||
|
unsigned day;
|
||||||
|
|
||||||
|
bool Date::operator==(const Date &other) const
|
||||||
|
{
|
||||||
|
return other.year == year && other.month == month && other.day == day;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Date::operator<(const Date &other) const
|
||||||
|
{
|
||||||
|
if (year < other.year) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (year == other.year && month < other.month) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (year == other.year && month == other.month && day < other.day) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Date::operator>(const Date &other) const
|
||||||
|
{
|
||||||
|
return !(*this < other) && !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Time::operator==(const Time &other) const
|
||||||
|
{
|
||||||
|
return other.hour == hour && other.minute == minute;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Time::operator<(const Time &other) const
|
||||||
|
{
|
||||||
|
if (hour < other.hour) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (hour == other.hour && minute < other.minute) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Time::operator>(const Time &other) const
|
||||||
|
{
|
||||||
|
return !(*this < other) && !(*this == other);
|
||||||
|
}
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
19
external/mirai-core/src/Day.cpp
vendored
19
external/mirai-core/src/Day.cpp
vendored
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Day.h"
|
#include "Day.h"
|
||||||
#include "BaseResource.h"
|
#include "BaseSource.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
namespace mirai
|
namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
Day::Day(BaseResource *source, const DayData &data) : source_(source), data_(data)
|
Day::Day(BaseSource *source, const DayData &data) : source_(source), data_(data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,4 +86,19 @@ std::vector<std::unique_ptr<TaskItem>> *Day::tasks()
|
||||||
{
|
{
|
||||||
return &tasks_;
|
return &tasks_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Event *Day::getEventById(int eventId)
|
||||||
|
{
|
||||||
|
for (auto &event : events_) {
|
||||||
|
if (event->id() == eventId) {
|
||||||
|
return event.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseSource *Day::source()
|
||||||
|
{
|
||||||
|
return source_;
|
||||||
|
}
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
21
external/mirai-core/src/Event.cpp
vendored
21
external/mirai-core/src/Event.cpp
vendored
|
@ -5,14 +5,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "BaseResource.h"
|
#include "BaseSource.h"
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
namespace mirai
|
namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
Event::Event(BaseResource *source, Day *parent, const EventData &data)
|
Event::Event(BaseSource *source, Day *parent, const EventData &data)
|
||||||
: source_(source), day_(parent), data(data)
|
: source_(source), day_(parent), data(data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,23 @@ void Event::onChange()
|
||||||
source_->setDirty(true);
|
source_->setDirty(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Event &Event::operator=(const EventData &newData)
|
||||||
|
{
|
||||||
|
data = newData;
|
||||||
|
onChange();
|
||||||
|
return *this;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Event::id() const
|
||||||
|
{
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
Day *Event::day()
|
||||||
|
{
|
||||||
|
return day_;
|
||||||
|
}
|
||||||
|
|
||||||
int Event::nextId = 0;
|
int Event::nextId = 0;
|
||||||
|
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
38
external/mirai-core/src/Mirai.cpp
vendored
38
external/mirai-core/src/Mirai.cpp
vendored
|
@ -19,21 +19,21 @@
|
||||||
namespace mirai
|
namespace mirai
|
||||||
{
|
{
|
||||||
|
|
||||||
void Mirai::loadResource(std::unique_ptr<BaseResource> &&resource)
|
void Mirai::loadSource(std::unique_ptr<BaseSource> &&resource)
|
||||||
{
|
{
|
||||||
resource->load();
|
resource->load();
|
||||||
resources_.push_back(std::move(resource));
|
sources_.push_back(std::move(resource));
|
||||||
reloadTags();
|
reloadTags();
|
||||||
};
|
};
|
||||||
|
|
||||||
void Mirai::unloadAllResources()
|
void Mirai::unloadAllSources()
|
||||||
{
|
{
|
||||||
resources_.clear();
|
sources_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mirai::save()
|
void Mirai::save()
|
||||||
{
|
{
|
||||||
for (auto &resource : resources_) {
|
for (auto &resource : sources_) {
|
||||||
if (resource->isDirty()) {
|
if (resource->isDirty()) {
|
||||||
resource->save();
|
resource->save();
|
||||||
resource->setDirty(false);
|
resource->setDirty(false);
|
||||||
|
@ -42,27 +42,26 @@ void Mirai::save()
|
||||||
reloadTags();
|
reloadTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mirai::removeTask(const TaskItem *taskItem)
|
void Mirai::deleteTask(const TaskItem &taskItem)
|
||||||
{
|
{
|
||||||
for (auto &resource : resources_) {
|
for (auto &resource : sources_) {
|
||||||
// resource->removeTask(taskItem); // TODO REWORK
|
resource->deleteTask(taskItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::unique_ptr<BaseResource>> &Mirai::getResources()
|
std::vector<std::unique_ptr<BaseSource>> &Mirai::getSources()
|
||||||
{
|
{
|
||||||
return resources_;
|
return sources_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::reference_wrapper<BaseResource>> Mirai::getResourceByName(const std::string &name
|
std::optional<std::reference_wrapper<BaseSource>> Mirai::getSourceByName(const std::string &name)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
auto resourceIterator =
|
auto resourceIterator =
|
||||||
std::ranges::find_if(resources_, [&](const std::unique_ptr<BaseResource> &resource) {
|
std::ranges::find_if(sources_, [&](const std::unique_ptr<BaseSource> &resource) {
|
||||||
return resource->getName() == name;
|
return resource->getName() == name;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (resourceIterator == resources_.end()) {
|
if (resourceIterator == sources_.end()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
return *(resourceIterator->get());
|
return *(resourceIterator->get());
|
||||||
|
@ -75,7 +74,8 @@ const std::vector<std::string> &Mirai::getTags()
|
||||||
|
|
||||||
void Mirai::reloadTags()
|
void Mirai::reloadTags()
|
||||||
{
|
{
|
||||||
/*cpputils::debug::Timer reloadingTagsDuration;*/ // TODO REWORK
|
// TODO TAGS
|
||||||
|
/*cpputils::debug::Timer reloadingTagsDuration;*/
|
||||||
/*tags.clear();*/
|
/*tags.clear();*/
|
||||||
/*for (auto &resource : resources) {*/
|
/*for (auto &resource : resources) {*/
|
||||||
/*for (auto &task : resource->getTasks()) {*/
|
/*for (auto &task : resource->getTasks()) {*/
|
||||||
|
@ -89,4 +89,12 @@ void Mirai::reloadTags()
|
||||||
/*reloadingTagsDuration.printTimeElapsed("ReloadingTags");*/
|
/*reloadingTagsDuration.printTimeElapsed("ReloadingTags");*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BaseSource *Mirai::getSourceById(int id)
|
||||||
|
{
|
||||||
|
if (id >= sources_.size()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return sources_.at(id).get();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
58
external/mirai-core/src/StdFileSource.cpp
vendored
Normal file
58
external/mirai-core/src/StdFileSource.cpp
vendored
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Mirai. Copyright (C) 2024 Vyn
|
||||||
|
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||||
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StdFileSource.h"
|
||||||
|
#include "TodoMd.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
|
void StdFileSource::save()
|
||||||
|
{
|
||||||
|
std::ofstream file(getPath());
|
||||||
|
if (!file.is_open()) {
|
||||||
|
throw std::runtime_error("can't create " + getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string content = TodoMdFormat::stringify(getName(), *days());
|
||||||
|
|
||||||
|
file << content;
|
||||||
|
file.close();
|
||||||
|
};
|
||||||
|
|
||||||
|
void StdFileSource::load()
|
||||||
|
{
|
||||||
|
std::ifstream file(getPath());
|
||||||
|
if (!file.is_open()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string content = "";
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(file, line)) {
|
||||||
|
content += line + "\n";
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
auto result = TodoMdFormat::parse(content);
|
||||||
|
for (const auto &dayData : result.days) {
|
||||||
|
Day *newDay = day(dayData.date);
|
||||||
|
for (const auto &eventData : dayData.events) {
|
||||||
|
Event *newEvent = newDay->createEvent(eventData);
|
||||||
|
for (const auto &taskData : eventData.tasks) {
|
||||||
|
TaskItem *newTask = newEvent->createTask(taskData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto &taskData : dayData.tasks) {
|
||||||
|
TaskItem *newTask = newDay->createTask(taskData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setName(result.name);
|
||||||
|
};
|
||||||
|
} // namespace mirai
|
26
external/mirai-core/src/TaskItem.cpp
vendored
26
external/mirai-core/src/TaskItem.cpp
vendored
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include "BaseResource.h"
|
#include "BaseSource.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -14,7 +14,14 @@ namespace mirai
|
||||||
|
|
||||||
int TaskItem::nextId = 0;
|
int TaskItem::nextId = 0;
|
||||||
|
|
||||||
TaskItem::TaskItem(BaseResource *source, Day *day, TaskItemData data)
|
TaskItem &TaskItem::operator=(const TaskItemData &newData)
|
||||||
|
{
|
||||||
|
data = newData;
|
||||||
|
onChange();
|
||||||
|
return *this;
|
||||||
|
};
|
||||||
|
|
||||||
|
TaskItem::TaskItem(BaseSource *source, Day *day, TaskItemData data)
|
||||||
: source_(source), day_(day), data(data)
|
: source_(source), day_(day), data(data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -62,4 +69,19 @@ void TaskItem::onChange()
|
||||||
source()->setDirty(true);
|
source()->setDirty(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TaskItem::id() const
|
||||||
|
{
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseSource *TaskItem::source()
|
||||||
|
{
|
||||||
|
return source_;
|
||||||
|
}
|
||||||
|
|
||||||
|
Day *TaskItem::day()
|
||||||
|
{
|
||||||
|
return day_;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
25
external/mirai-core/src/TasksView.cpp
vendored
25
external/mirai-core/src/TasksView.cpp
vendored
|
@ -46,7 +46,7 @@ void TasksView::update()
|
||||||
auto todayDate = std::format("{:%Y-%m-%d}", std::chrono::system_clock::now());
|
auto todayDate = std::format("{:%Y-%m-%d}", std::chrono::system_clock::now());
|
||||||
filteredDays.clear();
|
filteredDays.clear();
|
||||||
|
|
||||||
for (auto &file : mirai->getResources()) {
|
for (auto &file : mirai->getSources()) {
|
||||||
if (resourcesFilter.size() > 0 &&
|
if (resourcesFilter.size() > 0 &&
|
||||||
!vectorUtils::contains(resourcesFilter, file->getName())) {
|
!vectorUtils::contains(resourcesFilter, file->getName())) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -55,9 +55,8 @@ void TasksView::update()
|
||||||
FilteredDay filteredDay{.day = day.get()};
|
FilteredDay filteredDay{.day = day.get()};
|
||||||
for (auto &task : *day->tasks()) {
|
for (auto &task : *day->tasks()) {
|
||||||
auto taskDate = std::format(
|
auto taskDate = std::format(
|
||||||
"{}-0{}-{}", day->getDate().year, // TODO REWORK REMOVE 0{}
|
"{:04d}-{:02d}-{:02d}", day->getDate().year, day->getDate().month,
|
||||||
day->getDate().month,
|
day->getDate().day
|
||||||
day->getDate().day // TODO REWORK CLEAN THIS MESS
|
|
||||||
);
|
);
|
||||||
if (shouldHideCompletedTasks() && task->getState() == DONE &&
|
if (shouldHideCompletedTasks() && task->getState() == DONE &&
|
||||||
taskDate < todayDate) {
|
taskDate < todayDate) {
|
||||||
|
@ -72,8 +71,8 @@ void TasksView::update()
|
||||||
for (auto &event : *day->events()) {
|
for (auto &event : *day->events()) {
|
||||||
FilteredEvent filteredEvent{.event = event.get()};
|
FilteredEvent filteredEvent{.event = event.get()};
|
||||||
auto eventDate = std::format(
|
auto eventDate = std::format(
|
||||||
// TODO REWORK
|
"{:04d}-{:02d}-{:02d}", day->getDate().year, day->getDate().month,
|
||||||
"{}-0{}-{}", day->getDate().year, day->getDate().month, day->getDate().day
|
day->getDate().day
|
||||||
);
|
);
|
||||||
for (auto &task : *event->tasks()) {
|
for (auto &task : *event->tasks()) {
|
||||||
|
|
||||||
|
@ -141,13 +140,13 @@ void TasksView::removeTagFilter(const std::string &tag)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TasksView::addResourceFilter(const std::string &fileName)
|
void TasksView::addSourceFilter(const std::string &fileName)
|
||||||
{
|
{
|
||||||
resourcesFilter.push_back(fileName);
|
resourcesFilter.push_back(fileName);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TasksView::removeResourceFilter(const std::string &fileName)
|
void TasksView::removeSourceFilter(const std::string &fileName)
|
||||||
{
|
{
|
||||||
resourcesFilter.erase(std::remove_if(
|
resourcesFilter.erase(std::remove_if(
|
||||||
resourcesFilter.begin(), resourcesFilter.end(),
|
resourcesFilter.begin(), resourcesFilter.end(),
|
||||||
|
@ -173,4 +172,14 @@ const std::vector<std::string> &TasksView::getActiveFilesFilter()
|
||||||
{
|
{
|
||||||
return resourcesFilter;
|
return resourcesFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TasksView::hideCompletedTasks(bool hide)
|
||||||
|
{
|
||||||
|
shouldHideCompletedTasks_ = hide;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TasksView::shouldHideCompletedTasks() const
|
||||||
|
{
|
||||||
|
return shouldHideCompletedTasks_;
|
||||||
|
}
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
212
src/UiState.cpp
212
src/UiState.cpp
|
@ -34,18 +34,18 @@
|
||||||
|
|
||||||
UiState::UiState(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance), view_(miraiInstance)
|
UiState::UiState(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance), view_(miraiInstance)
|
||||||
{
|
{
|
||||||
resources_ = std::make_shared<slint::VectorModel<slint::SharedString>>();
|
sources_ = std::make_shared<slint::VectorModel<slint::SharedString>>();
|
||||||
days_ = std::make_shared<slint::VectorModel<Day>>();
|
days_ = std::make_shared<slint::VectorModel<Day>>();
|
||||||
tags_ = std::make_shared<slint::VectorModel<slint::SharedString>>();
|
tags_ = std::make_shared<slint::VectorModel<slint::SharedString>>();
|
||||||
|
|
||||||
taskEditWindow_->global<Backend>().set_resources(resources_);
|
taskWindow_->global<Backend>().set_sources(sources_);
|
||||||
taskEditWindow_->global<Backend>().set_tags(tags_);
|
taskWindow_->global<Backend>().set_tags(tags_);
|
||||||
eventWindow_->global<Backend>().set_resources(resources_);
|
eventWindow_->global<Backend>().set_sources(sources_);
|
||||||
eventWindow_->global<Backend>().set_tags(tags_);
|
eventWindow_->global<Backend>().set_tags(tags_);
|
||||||
|
|
||||||
view_.update();
|
view_.update();
|
||||||
|
|
||||||
reloadResources();
|
reloadSources();
|
||||||
reloadTags();
|
reloadTags();
|
||||||
reloadTasks();
|
reloadTasks();
|
||||||
|
|
||||||
|
@ -73,6 +73,59 @@ std::optional<Date> stringToDate(const std::string &dateStr)
|
||||||
return Date{.year = year, .month = month, .day = day};
|
return Date{.year = year, .month = month, .day = day};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiState::setupTaskWindowCallbacks()
|
||||||
|
{
|
||||||
|
taskWindow_->on_save([&](SaveTaskData newTaskData) {
|
||||||
|
auto source = miraiInstance_->getSourceById(newTaskData.sourceId);
|
||||||
|
assert(source);
|
||||||
|
auto task = source->getTaskById(newTaskData.id);
|
||||||
|
assert(task);
|
||||||
|
const Date &date = newTaskData.date;
|
||||||
|
const std::string dateStr = SlintDateToStdString(date);
|
||||||
|
auto taskData =
|
||||||
|
mirai::TodoMdFormat::stringToTask("- [ ] " + std::string(newTaskData.title), dateStr);
|
||||||
|
|
||||||
|
task->setText(taskData.text);
|
||||||
|
if (task->day()->getDate() != SlintDateToMiraiDate(date)) {
|
||||||
|
auto newDate = source->day(SlintDateToMiraiDate(date));
|
||||||
|
newDate->createTask({
|
||||||
|
.text = taskData.text,
|
||||||
|
.state = task->getState(),
|
||||||
|
.tags = taskData.tags,
|
||||||
|
});
|
||||||
|
auto oldDate = task->day();
|
||||||
|
source->deleteTask(*task);
|
||||||
|
}
|
||||||
|
miraiInstance_->save();
|
||||||
|
view_.update();
|
||||||
|
reloadTasks();
|
||||||
|
taskWindow_->hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
taskWindow_->on_create([&](NewTaskData newTaskData) {
|
||||||
|
const Date &date = newTaskData.date;
|
||||||
|
const std::string dateStr = SlintDateToStdString(date);
|
||||||
|
auto source = miraiInstance_->getSourceById(newTaskData.sourceId);
|
||||||
|
auto task =
|
||||||
|
mirai::TodoMdFormat::stringToTask("- [ ] " + std::string(newTaskData.title), dateStr);
|
||||||
|
|
||||||
|
if (newTaskData.eventId == -1) {
|
||||||
|
auto day = source->day(SlintDateToMiraiDate(date));
|
||||||
|
assert(day);
|
||||||
|
day->createTask(task);
|
||||||
|
} else {
|
||||||
|
auto event = source->getEventById(newTaskData.eventId);
|
||||||
|
assert(event);
|
||||||
|
event->createTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
miraiInstance_->save();
|
||||||
|
view_.update();
|
||||||
|
reloadTasks();
|
||||||
|
taskWindow_->hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void UiState::setupEventWindowCallbacks()
|
void UiState::setupEventWindowCallbacks()
|
||||||
{
|
{
|
||||||
mainWindow_->global<Backend>().on_open_new_event_form([&]() {
|
mainWindow_->global<Backend>().on_open_new_event_form([&]() {
|
||||||
|
@ -92,11 +145,11 @@ void UiState::setupEventWindowCallbacks()
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow_->global<Backend>().on_open_edit_event_form([&](int sourceId, int eventId) {
|
mainWindow_->global<Backend>().on_open_edit_event_form([&](int sourceId, int eventId) {
|
||||||
auto resource = miraiInstance_->getResourceById(sourceId);
|
auto source = miraiInstance_->getSourceById(sourceId);
|
||||||
assert(resource);
|
assert(source);
|
||||||
auto event = resource->getEventById(eventId);
|
auto event = source->getEventById(eventId);
|
||||||
assert(event);
|
assert(event);
|
||||||
eventWindow_->global<Backend>().set_resources(resources_);
|
eventWindow_->global<Backend>().set_sources(sources_);
|
||||||
eventWindow_->global<Backend>().set_tags(tags_);
|
eventWindow_->global<Backend>().set_tags(tags_);
|
||||||
|
|
||||||
eventWindow_->set_sourceId(sourceId);
|
eventWindow_->set_sourceId(sourceId);
|
||||||
|
@ -109,9 +162,9 @@ void UiState::setupEventWindowCallbacks()
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow_->global<Backend>().on_delete_event_clicked([&](int sourceId, int eventId) {
|
mainWindow_->global<Backend>().on_delete_event_clicked([&](int sourceId, int eventId) {
|
||||||
auto resource = miraiInstance_->getResourceById(sourceId);
|
auto source = miraiInstance_->getSourceById(sourceId);
|
||||||
assert(resource);
|
assert(source);
|
||||||
auto event = resource->getEventById(eventId);
|
auto event = source->getEventById(eventId);
|
||||||
assert(event);
|
assert(event);
|
||||||
auto day = event->day();
|
auto day = event->day();
|
||||||
assert(day);
|
assert(day);
|
||||||
|
@ -124,9 +177,9 @@ void UiState::setupEventWindowCallbacks()
|
||||||
eventWindow_->on_create([&](NewEventParams newEventParams) {
|
eventWindow_->on_create([&](NewEventParams newEventParams) {
|
||||||
const Date &date = newEventParams.date;
|
const Date &date = newEventParams.date;
|
||||||
const std::string dateStr = SlintDateToStdString(date);
|
const std::string dateStr = SlintDateToStdString(date);
|
||||||
auto resource = miraiInstance_->getResourceById(newEventParams.sourceId);
|
auto source = miraiInstance_->getSourceById(newEventParams.sourceId);
|
||||||
|
|
||||||
auto day = resource->day(SlintDateToMiraiDate(date));
|
auto day = source->day(SlintDateToMiraiDate(date));
|
||||||
day->createEvent({
|
day->createEvent({
|
||||||
.description = std::string(newEventParams.title),
|
.description = std::string(newEventParams.title),
|
||||||
.date = SlintDateToMiraiDate(newEventParams.date),
|
.date = SlintDateToMiraiDate(newEventParams.date),
|
||||||
|
@ -142,9 +195,9 @@ void UiState::setupEventWindowCallbacks()
|
||||||
eventWindow_->on_save([&](SaveEventParams newEventParams) {
|
eventWindow_->on_save([&](SaveEventParams newEventParams) {
|
||||||
const Date &date = newEventParams.date;
|
const Date &date = newEventParams.date;
|
||||||
const std::string dateStr = SlintDateToStdString(date);
|
const std::string dateStr = SlintDateToStdString(date);
|
||||||
auto resource = miraiInstance_->getResourceById(newEventParams.sourceId);
|
auto source = miraiInstance_->getSourceById(newEventParams.sourceId);
|
||||||
assert(resource);
|
assert(source);
|
||||||
auto event = resource->getEventById(newEventParams.id);
|
auto event = source->getEventById(newEventParams.id);
|
||||||
assert(event);
|
assert(event);
|
||||||
event->setText(std::string(newEventParams.title));
|
event->setText(std::string(newEventParams.title));
|
||||||
event->setStartTime(SlintTimeToMiraiTime(newEventParams.startsAt));
|
event->setStartTime(SlintTimeToMiraiTime(newEventParams.startsAt));
|
||||||
|
@ -174,22 +227,22 @@ void UiState::setupUtilsCallbacks()
|
||||||
void UiState::setupCallbacks()
|
void UiState::setupCallbacks()
|
||||||
{
|
{
|
||||||
mainWindow_->global<Backend>().on_task_clicked([&](int sourceId, int taskId) {
|
mainWindow_->global<Backend>().on_task_clicked([&](int sourceId, int taskId) {
|
||||||
auto resource = miraiInstance_->getResourceById(sourceId);
|
auto source = miraiInstance_->getSourceById(sourceId);
|
||||||
assert(resource);
|
assert(source);
|
||||||
auto task = resource->getTaskById(taskId);
|
auto task = source->getTaskById(taskId);
|
||||||
assert(task);
|
assert(task);
|
||||||
task->getState() == mirai::DONE ? task->markAsUndone() : task->markAsDone();
|
task->getState() == mirai::DONE ? task->markAsUndone() : task->markAsDone();
|
||||||
miraiInstance_->save();
|
miraiInstance_->save();
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow_->global<Backend>().on_source_clicked([&](int index) {
|
mainWindow_->global<Backend>().on_source_clicked([&](int index) {
|
||||||
const auto &source = miraiInstance_->getResourceById(index);
|
const auto &source = miraiInstance_->getSourceById(index);
|
||||||
const auto &sourceName = source->getName();
|
const auto &sourceName = source->getName();
|
||||||
if (std::ranges::find(view_.getActiveFilesFilter(), sourceName) ==
|
if (std::ranges::find(view_.getActiveFilesFilter(), sourceName) ==
|
||||||
view_.getActiveFilesFilter().end()) {
|
view_.getActiveFilesFilter().end()) {
|
||||||
view_.addResourceFilter(sourceName);
|
view_.addSourceFilter(sourceName);
|
||||||
} else {
|
} else {
|
||||||
view_.removeResourceFilter(sourceName);
|
view_.removeSourceFilter(sourceName);
|
||||||
}
|
}
|
||||||
view_.update();
|
view_.update();
|
||||||
reloadTasks();
|
reloadTasks();
|
||||||
|
@ -208,110 +261,58 @@ void UiState::setupCallbacks()
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow_->global<Backend>().on_delete_task_clicked([&](int sourceId, int taskId) {
|
mainWindow_->global<Backend>().on_delete_task_clicked([&](int sourceId, int taskId) {
|
||||||
auto resource = miraiInstance_->getResourceById(sourceId);
|
auto source = miraiInstance_->getSourceById(sourceId);
|
||||||
assert(resource);
|
assert(source);
|
||||||
auto task = resource->getTaskById(taskId);
|
auto task = source->getTaskById(taskId);
|
||||||
assert(task);
|
assert(task);
|
||||||
resource->deleteTask(*task);
|
source->deleteTask(*task);
|
||||||
miraiInstance_->save();
|
miraiInstance_->save();
|
||||||
view_.update();
|
view_.update();
|
||||||
reloadTasks();
|
reloadTasks();
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow_->global<Backend>().on_open_edit_task_form([&](int sourceId, int taskId) {
|
mainWindow_->global<Backend>().on_open_edit_task_form([&](int sourceId, int taskId) {
|
||||||
auto resource = miraiInstance_->getResourceById(sourceId);
|
auto source = miraiInstance_->getSourceById(sourceId);
|
||||||
assert(resource);
|
assert(source);
|
||||||
auto task = resource->getTaskById(taskId);
|
auto task = source->getTaskById(taskId);
|
||||||
assert(task);
|
assert(task);
|
||||||
|
|
||||||
taskEditWindow_->set_taskResourceIndex(sourceId);
|
taskWindow_->set_taskSourceIndex(sourceId);
|
||||||
taskEditWindow_->set_taskId(task->id());
|
taskWindow_->set_taskId(task->id());
|
||||||
taskEditWindow_->set_taskTitle(slint::SharedString(task->getText()));
|
taskWindow_->set_taskTitle(slint::SharedString(task->getText()));
|
||||||
taskEditWindow_->set_taskDate(MiraiDateToSlintDate(task->day()->getDate()));
|
taskWindow_->set_taskDate(MiraiDateToSlintDate(task->day()->getDate()));
|
||||||
|
|
||||||
taskEditWindow_->on_save([&](SaveTaskData newTaskData) {
|
taskWindow_->show();
|
||||||
auto resource = miraiInstance_->getResourceById(newTaskData.sourceId);
|
|
||||||
assert(resource);
|
|
||||||
auto task = resource->getTaskById(newTaskData.id);
|
|
||||||
assert(task);
|
|
||||||
const Date &date = newTaskData.date;
|
|
||||||
const std::string dateStr = SlintDateToStdString(date);
|
|
||||||
auto taskData = mirai::TodoMdFormat::stringToTask(
|
|
||||||
"- [ ] " + std::string(newTaskData.title), dateStr
|
|
||||||
);
|
|
||||||
|
|
||||||
task->setText(taskData.text);
|
|
||||||
if (task->day()->getDate() != SlintDateToMiraiDate(date)) {
|
|
||||||
auto newDate = resource->day(SlintDateToMiraiDate(date));
|
|
||||||
newDate->createTask({
|
|
||||||
.text = taskData.text,
|
|
||||||
.state = task->getState(),
|
|
||||||
.tags = taskData.tags,
|
|
||||||
});
|
|
||||||
auto oldDate = task->day();
|
|
||||||
resource->deleteTask(*task);
|
|
||||||
}
|
|
||||||
miraiInstance_->save();
|
|
||||||
view_.update();
|
|
||||||
reloadTasks();
|
|
||||||
taskEditWindow_->hide();
|
|
||||||
});
|
|
||||||
taskEditWindow_->show();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow_->global<Backend>().on_open_new_task_form([&](OpenNewTaskFormParams params) {
|
mainWindow_->global<Backend>().on_open_new_task_form([&](OpenNewTaskFormParams params) {
|
||||||
taskEditWindow_->global<Backend>().set_resources(resources_);
|
taskWindow_->global<Backend>().set_sources(sources_);
|
||||||
taskEditWindow_->global<Backend>().set_tags(tags_);
|
taskWindow_->global<Backend>().set_tags(tags_);
|
||||||
|
|
||||||
auto todayDate = std::chrono::year_month_day{
|
auto todayDate = std::chrono::year_month_day{
|
||||||
std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now())
|
std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now())
|
||||||
};
|
};
|
||||||
taskEditWindow_->set_taskId(-1);
|
taskWindow_->set_taskId(-1);
|
||||||
taskEditWindow_->set_eventId(params.eventId);
|
taskWindow_->set_eventId(params.eventId);
|
||||||
taskEditWindow_->set_taskResourceIndex(
|
taskWindow_->set_taskSourceIndex(params.eventSourceId == -1 ? 0 : params.eventSourceId);
|
||||||
params.eventSourceId == -1 ? 0 : params.eventSourceId
|
taskWindow_->set_taskTitle("");
|
||||||
);
|
|
||||||
taskEditWindow_->set_taskTitle("");
|
|
||||||
|
|
||||||
if (params.eventId == -1) {
|
if (params.eventId == -1) {
|
||||||
taskEditWindow_->set_taskDate({
|
taskWindow_->set_taskDate({
|
||||||
.year = static_cast<int>(todayDate.year()),
|
.year = static_cast<int>(todayDate.year()),
|
||||||
// Try to directly use `unsigned`
|
// Try to directly use `unsigned`
|
||||||
.month = static_cast<int>(static_cast<unsigned>(todayDate.month())),
|
.month = static_cast<int>(static_cast<unsigned>(todayDate.month())),
|
||||||
.day = static_cast<int>(static_cast<unsigned>(todayDate.day())),
|
.day = static_cast<int>(static_cast<unsigned>(todayDate.day())),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
auto resource = miraiInstance_->getResourceById(params.eventSourceId);
|
auto source = miraiInstance_->getSourceById(params.eventSourceId);
|
||||||
assert(resource);
|
assert(source);
|
||||||
auto event = resource->getEventById(params.eventId);
|
auto event = source->getEventById(params.eventId);
|
||||||
assert(event);
|
assert(event);
|
||||||
taskEditWindow_->set_taskDate(MiraiDateToSlintDate(event->getDate()));
|
taskWindow_->set_taskDate(MiraiDateToSlintDate(event->getDate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
taskEditWindow_->on_create([&](NewTaskData newTaskData) {
|
taskWindow_->show();
|
||||||
const Date &date = newTaskData.date;
|
|
||||||
const std::string dateStr = SlintDateToStdString(date);
|
|
||||||
auto resource = miraiInstance_->getResourceById(newTaskData.sourceId);
|
|
||||||
auto task = mirai::TodoMdFormat::stringToTask(
|
|
||||||
"- [ ] " + std::string(newTaskData.title), dateStr
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newTaskData.eventId == -1) {
|
|
||||||
auto day = resource->day(SlintDateToMiraiDate(date));
|
|
||||||
assert(day);
|
|
||||||
day->createTask(task);
|
|
||||||
} else {
|
|
||||||
auto event = resource->getEventById(newTaskData.eventId);
|
|
||||||
assert(event);
|
|
||||||
event->createTask(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
miraiInstance_->save();
|
|
||||||
view_.update();
|
|
||||||
reloadTasks();
|
|
||||||
taskEditWindow_->hide();
|
|
||||||
});
|
|
||||||
taskEditWindow_->show();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow_->global<Backend>().on_toggle_show_completed_tasks([&] {
|
mainWindow_->global<Backend>().on_toggle_show_completed_tasks([&] {
|
||||||
|
@ -320,10 +321,11 @@ void UiState::setupCallbacks()
|
||||||
reloadTasks();
|
reloadTasks();
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow_->global<Backend>().set_resources(resources_);
|
mainWindow_->global<Backend>().set_sources(sources_);
|
||||||
mainWindow_->global<Backend>().set_tags(tags_);
|
mainWindow_->global<Backend>().set_tags(tags_);
|
||||||
mainWindow_->global<Backend>().set_visible_tasks(days_);
|
mainWindow_->global<Backend>().set_visible_tasks(days_);
|
||||||
|
|
||||||
|
setupTaskWindowCallbacks();
|
||||||
setupEventWindowCallbacks();
|
setupEventWindowCallbacks();
|
||||||
setupUtilsCallbacks();
|
setupUtilsCallbacks();
|
||||||
}
|
}
|
||||||
|
@ -341,7 +343,7 @@ stdToSlintStringVector(const std::vector<std::string> &stdVector)
|
||||||
void UiState::reloadTasks()
|
void UiState::reloadTasks()
|
||||||
{
|
{
|
||||||
days_->clear();
|
days_->clear();
|
||||||
if (miraiInstance_->getResources().size() == 0) {
|
if (miraiInstance_->getSources().size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto todayDate = mirai::Date(std::chrono::system_clock::now());
|
auto todayDate = mirai::Date(std::chrono::system_clock::now());
|
||||||
|
@ -411,11 +413,11 @@ void UiState::reloadTasks()
|
||||||
mainWindow_->global<Backend>().set_visible_tasks(days_);
|
mainWindow_->global<Backend>().set_visible_tasks(days_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiState::reloadResources()
|
void UiState::reloadSources()
|
||||||
{
|
{
|
||||||
resources_->clear();
|
sources_->clear();
|
||||||
for (const auto &resource : miraiInstance_->getResources()) {
|
for (const auto &source : miraiInstance_->getSources()) {
|
||||||
resources_->push_back(slint::SharedString(resource->getName()));
|
sources_->push_back(slint::SharedString(source->getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,21 +19,22 @@ class UiState
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
void reloadResources();
|
void reloadSources();
|
||||||
void reloadTags();
|
void reloadTags();
|
||||||
void reloadTasks();
|
void reloadTasks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupCallbacks();
|
void setupCallbacks();
|
||||||
|
void setupTaskWindowCallbacks();
|
||||||
void setupEventWindowCallbacks();
|
void setupEventWindowCallbacks();
|
||||||
void setupUtilsCallbacks();
|
void setupUtilsCallbacks();
|
||||||
|
|
||||||
std::shared_ptr<slint::VectorModel<slint::SharedString>> resources_;
|
std::shared_ptr<slint::VectorModel<slint::SharedString>> sources_;
|
||||||
std::shared_ptr<slint::VectorModel<slint::SharedString>> tags_;
|
std::shared_ptr<slint::VectorModel<slint::SharedString>> tags_;
|
||||||
std::shared_ptr<slint::VectorModel<Day>> days_;
|
std::shared_ptr<slint::VectorModel<Day>> days_;
|
||||||
|
|
||||||
slint::ComponentHandle<AppWindow> mainWindow_ = AppWindow::create();
|
slint::ComponentHandle<AppWindow> mainWindow_ = AppWindow::create();
|
||||||
slint::ComponentHandle<TaskEdit> taskEditWindow_ = TaskEdit::create();
|
slint::ComponentHandle<TaskWindow> taskWindow_ = TaskWindow::create();
|
||||||
slint::ComponentHandle<EventWindow> eventWindow_ = EventWindow::create();
|
slint::ComponentHandle<EventWindow> eventWindow_ = EventWindow::create();
|
||||||
|
|
||||||
mirai::Mirai *miraiInstance_;
|
mirai::Mirai *miraiInstance_;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "UiState.h"
|
#include "UiState.h"
|
||||||
#include "mirai-core/Config.h"
|
#include "mirai-core/Config.h"
|
||||||
#include "mirai-core/Mirai.h"
|
#include "mirai-core/Mirai.h"
|
||||||
#include "mirai-core/StdFileResource.h"
|
#include "mirai-core/StdFileSource.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@ int main(int argc, char **argv)
|
||||||
mirai::Mirai mirai;
|
mirai::Mirai mirai;
|
||||||
|
|
||||||
for (const auto &sourceFilePath : config.sources()) {
|
for (const auto &sourceFilePath : config.sources()) {
|
||||||
auto file = std::make_unique<mirai::StdFileResource>(
|
auto file = std::make_unique<mirai::StdFileSource>(
|
||||||
mirai::BaseFileResourceConstructor{.name = sourceFilePath, .path = sourceFilePath}
|
mirai::BaseFileSourceConstructor{.name = sourceFilePath, .path = sourceFilePath}
|
||||||
);
|
);
|
||||||
mirai.loadResource(std::move(file));
|
mirai.loadSource(std::move(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
UiState uiState{&mirai};
|
UiState uiState{&mirai};
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "core/BaseFileResource.h"
|
#include "core/BaseFileSource.h"
|
||||||
#include "core/Mirai.h"
|
#include "core/Mirai.h"
|
||||||
#include "core/StdFileResource.h"
|
#include "core/StdFileSource.h"
|
||||||
#include "core/TaskItem.h"
|
#include "core/TaskItem.h"
|
||||||
#include "core/TodoMd.h"
|
#include "core/TodoMd.h"
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
@ -18,8 +18,8 @@ TEST_CASE("Saving data")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mirai::Mirai mirai;
|
mirai::Mirai mirai;
|
||||||
auto fileResource = std::make_unique<mirai::StdFileResource>(
|
auto fileResource = std::make_unique<mirai::StdFileSource>(
|
||||||
mirai::BaseFileResourceConstructor{.name = "Testing", .path = "testing.md"}
|
mirai::BaseFileSourceConstructor{.name = "Testing", .path = "testing.md"}
|
||||||
);
|
);
|
||||||
mirai.loadResource(std::move(fileResource));
|
mirai.loadResource(std::move(fileResource));
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ TEST_CASE("Saving data")
|
||||||
|
|
||||||
{
|
{
|
||||||
mirai::Mirai mirai;
|
mirai::Mirai mirai;
|
||||||
auto fileResource = std::make_unique<mirai::StdFileResource>(
|
auto fileResource = std::make_unique<mirai::StdFileSource>(
|
||||||
mirai::BaseFileResourceConstructor{.name = "Testing", .path = "testing.md"}
|
mirai::BaseFileSourceConstructor{.name = "Testing", .path = "testing.md"}
|
||||||
);
|
);
|
||||||
mirai.loadResource(std::move(fileResource));
|
mirai.loadResource(std::move(fileResource));
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ struct OpenNewTaskFormParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
export global Backend {
|
export global Backend {
|
||||||
in-out property<[string]> resources;
|
in-out property<[string]> sources;
|
||||||
in-out property<[string]> tags;
|
in-out property<[string]> tags;
|
||||||
in-out property<[Day]> visible_tasks;
|
in-out property<[Day]> visible_tasks;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ export component SideBar inherits Rectangle {
|
||||||
}
|
}
|
||||||
VerticalLayout {
|
VerticalLayout {
|
||||||
spacing: 4px;
|
spacing: 4px;
|
||||||
for item[index] in Backend.resources: ToggleButton {
|
for item[index] in Backend.sources: ToggleButton {
|
||||||
text: item;
|
text: item;
|
||||||
text-alignment: left;
|
text-alignment: left;
|
||||||
clicked => { Backend.source_clicked(index) }
|
clicked => { Backend.source_clicked(index) }
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Backend } from "Backend.slint";
|
||||||
import { Button, VerticalBox, CheckBox, Palette } from "std-widgets.slint";
|
import { Button, VerticalBox, CheckBox, Palette } from "std-widgets.slint";
|
||||||
import { SideBar } from "SideBar.slint";
|
import { SideBar } from "SideBar.slint";
|
||||||
import { MainView } from "MainView.slint";
|
import { MainView } from "MainView.slint";
|
||||||
import { TaskEdit } from "windows/TaskEdit.slint";
|
import { TaskWindow } from "windows/TaskWindow.slint";
|
||||||
import { EventWindow } from "windows/EventWindow.slint";
|
import { EventWindow } from "windows/EventWindow.slint";
|
||||||
|
|
||||||
export component AppWindow inherits Window {
|
export component AppWindow inherits Window {
|
||||||
|
@ -23,4 +23,4 @@ export component AppWindow inherits Window {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Backend, TaskEdit, EventWindow } // Export to make it visible to the C++ backend
|
export { Backend, TaskWindow, EventWindow } // Export to make it visible to the C++ backend
|
||||||
|
|
|
@ -29,7 +29,7 @@ export component EventWindow inherits Window {
|
||||||
default-font-size: 16px;
|
default-font-size: 16px;
|
||||||
background: Palette.background;
|
background: Palette.background;
|
||||||
|
|
||||||
in-out property<int> sourceId <=> resourceInput.current-index;
|
in-out property<int> sourceId <=> sourceInput.current-index;
|
||||||
in-out property<int> eventId: -1;
|
in-out property<int> eventId: -1;
|
||||||
in-out property<Date> taskDate <=> taskDateInput.date;
|
in-out property<Date> taskDate <=> taskDateInput.date;
|
||||||
in-out property<string> taskTitle <=> taskTitleInput.text;
|
in-out property<string> taskTitle <=> taskTitleInput.text;
|
||||||
|
@ -46,8 +46,8 @@ export component EventWindow inherits Window {
|
||||||
text: eventId == -1 ? "New event" : "Edit event";
|
text: eventId == -1 ? "New event" : "Edit event";
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceInput := ComboBox {
|
sourceInput := ComboBox {
|
||||||
model: Backend.resources;
|
model: Backend.sources;
|
||||||
enabled: eventId == -1;
|
enabled: eventId == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ export struct SaveTaskData {
|
||||||
date: Date,
|
date: Date,
|
||||||
}
|
}
|
||||||
|
|
||||||
export component TaskEdit inherits Window {
|
export component TaskWindow inherits Window {
|
||||||
title: "Mirai - " + (taskId == -1 ? "New task" : "Edit task");
|
title: "Mirai - " + (taskId == -1 ? "New task" : "Edit task");
|
||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
max-width: 1920px;
|
max-width: 1920px;
|
||||||
|
@ -30,7 +30,7 @@ export component TaskEdit inherits Window {
|
||||||
in-out property<int> eventId: -1;
|
in-out property<int> eventId: -1;
|
||||||
in-out property<Date> taskDate <=> taskDateInput.date;
|
in-out property<Date> taskDate <=> taskDateInput.date;
|
||||||
in-out property<string> taskTitle <=> taskTitleInput.text;
|
in-out property<string> taskTitle <=> taskTitleInput.text;
|
||||||
in-out property<int> taskResourceIndex <=> resourceInput.current-index;
|
in-out property<int> taskSourceIndex <=> sourceInput.current-index;
|
||||||
|
|
||||||
callback create(NewTaskData);
|
callback create(NewTaskData);
|
||||||
callback save(SaveTaskData);
|
callback save(SaveTaskData);
|
||||||
|
@ -42,8 +42,8 @@ export component TaskEdit inherits Window {
|
||||||
text: taskId == -1 ? "New task" : "Edit task";
|
text: taskId == -1 ? "New task" : "Edit task";
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceInput := ComboBox {
|
sourceInput := ComboBox {
|
||||||
model: Backend.resources;
|
model: Backend.sources;
|
||||||
enabled: taskId == -1 && eventId == -1;
|
enabled: taskId == -1 && eventId == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,14 +63,14 @@ export component TaskEdit inherits Window {
|
||||||
clicked => {
|
clicked => {
|
||||||
if (taskId == -1) {
|
if (taskId == -1) {
|
||||||
create({
|
create({
|
||||||
sourceId: taskResourceIndex,
|
sourceId: taskSourceIndex,
|
||||||
eventId: eventId,
|
eventId: eventId,
|
||||||
title: taskTitle,
|
title: taskTitle,
|
||||||
date: taskDate,
|
date: taskDate,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
save({
|
save({
|
||||||
sourceId: taskResourceIndex,
|
sourceId: taskSourceIndex,
|
||||||
id: taskId,
|
id: taskId,
|
||||||
title: taskTitle,
|
title: taskTitle,
|
||||||
date: taskDate,
|
date: taskDate,
|
Loading…
Add table
Add a link
Reference in a new issue