mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 16:39:57 +00:00
Honour RideFile::startTime
When saving the value of startTime should be checked to see if the filename/notes need to be renamed. In addition, RideItem now allows the startTime to be modified and reflected in the ride list. When importing .gc ridefiles the file is serialized with the correct startTime if the user edited it during import.
This commit is contained in:
committed by
Sean Rhea
parent
02a60735f0
commit
4e7e6cfb3a
@@ -131,6 +131,42 @@ MainWindow::saveSilent(RideItem *rideItem)
|
||||
if (currentType != "GC") convert = true;
|
||||
else convert = false;
|
||||
|
||||
// Has the date/time changed?
|
||||
QDateTime ridedatetime = rideItem->ride()->startTime();
|
||||
QChar zero = QLatin1Char ( '0' );
|
||||
QString targetnosuffix = QString ( "%1_%2_%3_%4_%5_%6" )
|
||||
.arg ( ridedatetime.date().year(), 4, 10, zero )
|
||||
.arg ( ridedatetime.date().month(), 2, 10, zero )
|
||||
.arg ( ridedatetime.date().day(), 2, 10, zero )
|
||||
.arg ( ridedatetime.time().hour(), 2, 10, zero )
|
||||
.arg ( ridedatetime.time().minute(), 2, 10, zero )
|
||||
.arg ( ridedatetime.time().second(), 2, 10, zero );
|
||||
|
||||
// When datetime changes we need to update
|
||||
// the filename & rename/delete old file
|
||||
// we also need to preserve the notes file
|
||||
if (currentFI.baseName() != targetnosuffix) {
|
||||
|
||||
// if there is a notes file we need to rename it (cpi we will ignore)
|
||||
QFile notesFile(currentFI.path() + QDir::separator() + currentFI.baseName() + ".notes");
|
||||
|
||||
if (notesFile.exists())
|
||||
notesFile.rename(notesFile.fileName(),
|
||||
rideItem->path + QDir::separator() + targetnosuffix + ".notes");
|
||||
|
||||
// we also need to update the path to the notes filename
|
||||
ride->notesFileName = targetnosuffix + ".notes";
|
||||
|
||||
// rename as backup current if converting, or just delete it if its already .gc
|
||||
if (convert) currentFile.rename(currentFile.fileName(), currentFile.fileName() + ".sav");
|
||||
else currentFile.remove();
|
||||
convert = false; // we just did it already!
|
||||
|
||||
// set the new filename & Start time everywhere
|
||||
currentFile.setFileName(rideItem->path + QDir::separator() + targetnosuffix + ".gc");
|
||||
rideItem->setFileName(QFileInfo(currentFile).path(), QFileInfo(currentFile).fileName());
|
||||
}
|
||||
|
||||
// set target filename
|
||||
if (convert) {
|
||||
// rename the source
|
||||
|
||||
Reference in New Issue
Block a user