You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
3.8 KiB
168 lines
3.8 KiB
15 years ago
|
/*
|
||
13 years ago
|
This file is part of tdepim.
|
||
15 years ago
|
|
||
|
Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqdatastream.h>
|
||
|
#include <tqfile.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
|
||
|
#include "todostatemapper.h"
|
||
|
|
||
15 years ago
|
TQDataStream& operator<<( TQDataStream &stream, const TodoStateMapper::TodoStateMapEntry &entry )
|
||
15 years ago
|
{
|
||
|
stream << entry.uid << entry.localState << entry.remoteState;
|
||
|
|
||
|
return stream;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDataStream& operator>>( TQDataStream &stream, TodoStateMapper::TodoStateMapEntry &entry )
|
||
15 years ago
|
{
|
||
|
stream >> entry.uid >> entry.localState >> entry.remoteState;
|
||
|
|
||
|
return stream;
|
||
|
}
|
||
|
|
||
|
TodoStateMapper::TodoStateMapper()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
TodoStateMapper::~TodoStateMapper()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void TodoStateMapper::setPath( const TQString &path )
|
||
15 years ago
|
{
|
||
|
mPath = path;
|
||
|
}
|
||
|
|
||
15 years ago
|
void TodoStateMapper::setIdentifier( const TQString &identifier )
|
||
15 years ago
|
{
|
||
|
mIdentifier = identifier;
|
||
|
}
|
||
|
|
||
|
bool TodoStateMapper::load()
|
||
|
{
|
||
15 years ago
|
TQFile file( filename() );
|
||
15 years ago
|
if ( !file.open( IO_ReadOnly ) ) {
|
||
|
kdError() << "Can't read uid map file '" << filename() << "'" << endl;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
clear();
|
||
|
|
||
15 years ago
|
TQDataStream stream;
|
||
15 years ago
|
stream.setVersion( 6 );
|
||
|
stream.setDevice( &file );
|
||
|
stream >> mTodoStateMap;
|
||
|
|
||
|
file.close();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool TodoStateMapper::save()
|
||
|
{
|
||
15 years ago
|
TQFile file( filename() );
|
||
15 years ago
|
if ( !file.open( IO_WriteOnly ) ) {
|
||
|
kdError() << "Can't write uid map file '" << filename() << "'" << endl;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDataStream stream;
|
||
15 years ago
|
stream.setVersion( 6 );
|
||
|
stream.setDevice( &file );
|
||
|
stream << mTodoStateMap;
|
||
|
|
||
|
file.close();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void TodoStateMapper::clear()
|
||
|
{
|
||
|
mTodoStateMap.clear();
|
||
|
}
|
||
|
|
||
15 years ago
|
void TodoStateMapper::addTodoState( const TQString &uid, int localState, const TQString &remoteState )
|
||
15 years ago
|
{
|
||
|
TodoStateMapEntry entry;
|
||
|
entry.uid = uid;
|
||
|
entry.localState = localState;
|
||
|
entry.remoteState = remoteState;
|
||
|
|
||
|
mTodoStateMap.insert( uid, entry );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString TodoStateMapper::remoteState( const TQString &uid, int localState )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( mTodoStateMap.find( uid ) == mTodoStateMap.end() )
|
||
15 years ago
|
kdError() << "TodoStateMapper: no entry for " << uid << " found" << endl;
|
||
|
|
||
|
TodoStateMapEntry entry = mTodoStateMap[ uid ];
|
||
|
if ( entry.localState == localState )
|
||
|
return entry.remoteState;
|
||
|
else
|
||
|
return toRemote( localState );
|
||
|
}
|
||
|
|
||
15 years ago
|
void TodoStateMapper::remove( const TQString &uid )
|
||
15 years ago
|
{
|
||
|
mTodoStateMap.remove( uid );
|
||
|
}
|
||
|
|
||
15 years ago
|
int TodoStateMapper::toLocal( const TQString &remoteState )
|
||
15 years ago
|
{
|
||
|
if ( remoteState == "offer" )
|
||
|
return 0;
|
||
|
else if ( remoteState == "ongoing" )
|
||
|
return 50;
|
||
|
else if ( remoteState == "done" || remoteState == "billed" )
|
||
|
return 100;
|
||
|
else {
|
||
15 years ago
|
TQString number( remoteState );
|
||
14 years ago
|
number.replace( "%", "" );
|
||
15 years ago
|
return number.toInt();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString TodoStateMapper::toRemote( int localState )
|
||
15 years ago
|
{
|
||
|
if ( localState == 0 )
|
||
|
return "offer";
|
||
|
else if ( localState == 50 )
|
||
|
return "ongoing";
|
||
|
else if ( localState == 100 )
|
||
|
return "done";
|
||
|
else
|
||
13 years ago
|
return TQString( "%1%" ).arg( localState );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString TodoStateMapper::filename()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString file = mPath;
|
||
15 years ago
|
if ( !file.endsWith( "/" ) ) file += "/";
|
||
|
file += mIdentifier;
|
||
|
|
||
|
return locateLocal( "data", file );
|
||
|
}
|
||
|
|