Trk: Setting correct date and time when closing remote file.

Reviewed-by: Friedemann Kleint
This commit is contained in:
Robert Loehning
2009-12-02 14:42:03 +01:00
parent 7057584f98
commit e494864b08
3 changed files with 19 additions and 1 deletions

View File

@@ -467,7 +467,7 @@ void Launcher::closeRemoteFile(bool failed)
{ {
QByteArray ba; QByteArray ba;
appendInt(&ba, d->m_copyState.copyFileHandle, TargetByteOrder); appendInt(&ba, d->m_copyState.copyFileHandle, TargetByteOrder);
appendInt(&ba, QDateTime::currentDateTime().toTime_t(), TargetByteOrder); appendDateTime(&ba, QDateTime::currentDateTime(), TargetByteOrder);
d->m_device->sendTrkMessage(TrkCloseFile, d->m_device->sendTrkMessage(TrkCloseFile,
failed ? TrkCallback() : TrkCallback(this, &Launcher::handleFileCopied), failed ? TrkCallback() : TrkCallback(this, &Launcher::handleFileCopied),
ba); ba);

View File

@@ -32,6 +32,9 @@
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QDate>
#include <QtCore/QDateTime>
#include <QtCore/QTime>
#define logMessage(s) do { qDebug() << "TRKCLIENT: " << s; } while (0) #define logMessage(s) do { qDebug() << "TRKCLIENT: " << s; } while (0)
@@ -400,6 +403,18 @@ void appendString(QByteArray *ba, const QByteArray &str, Endianness endian, bool
ba->append('\0'); ba->append('\0');
} }
void appendDateTime(QByteArray *ba, QDateTime dateTime, Endianness endian)
{
// convert the QDateTime to UTC and append its representation to QByteArray
// format is the same as in FAT file system
dateTime = dateTime.toUTC();
const QTime utcTime = dateTime.time();
const QDate utcDate = dateTime.date();
uint fatDateTime = (utcTime.hour() << 11 | utcTime.minute() << 5 | utcTime.second()/2) << 16;
fatDateTime |= (utcDate.year()-1980) << 9 | utcDate.month() << 5 | utcDate.day();
appendInt(ba, fatDateTime, endian);
}
QByteArray errorMessage(byte code) QByteArray errorMessage(byte code)
{ {
switch (code) { switch (code) {

View File

@@ -37,6 +37,8 @@
typedef unsigned char byte; typedef unsigned char byte;
class QDateTime;
namespace trk { namespace trk {
enum Command { enum Command {
@@ -92,6 +94,7 @@ void appendByte(QByteArray *ba, byte b);
void appendShort(QByteArray *ba, ushort s, Endianness = TargetByteOrder); void appendShort(QByteArray *ba, ushort s, Endianness = TargetByteOrder);
void appendInt(QByteArray *ba, uint i, Endianness = TargetByteOrder); void appendInt(QByteArray *ba, uint i, Endianness = TargetByteOrder);
void appendString(QByteArray *ba, const QByteArray &str, Endianness = TargetByteOrder, bool appendNullTerminator = true); void appendString(QByteArray *ba, const QByteArray &str, Endianness = TargetByteOrder, bool appendNullTerminator = true);
void appendDateTime(QByteArray *ba, QDateTime dateTime, Endianness = TargetByteOrder);
struct Library struct Library
{ {