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.
172 lines
4.9 KiB
172 lines
4.9 KiB
15 years ago
|
/*
|
||
13 years ago
|
This file is part of tdepim.
|
||
15 years ago
|
Copyright (c) 2004 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.
|
||
|
*/
|
||
|
|
||
|
#include "gwconverter.h"
|
||
|
|
||
13 years ago
|
#include <libtdepim/kpimprefs.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
GWConverter::GWConverter( struct soap* soap )
|
||
|
: mSoap( soap )
|
||
|
{
|
||
|
Q_ASSERT( mSoap );
|
||
|
}
|
||
|
|
||
|
struct soap* GWConverter::soap() const
|
||
|
{
|
||
|
return mSoap;
|
||
|
}
|
||
|
|
||
14 years ago
|
std::string* GWConverter::qStringToString( const TQString &string )
|
||
15 years ago
|
{
|
||
|
std::string *str = soap_new_std__string( mSoap, -1 );
|
||
|
str->append( string.utf8() );
|
||
|
|
||
|
return str;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString GWConverter::stringToTQString( const std::string &str )
|
||
15 years ago
|
{
|
||
14 years ago
|
return TQString::fromUtf8( str.c_str() );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQString GWConverter::stringToTQString( std::string *str )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( !str ) return TQString();
|
||
14 years ago
|
return TQString::fromUtf8( str->c_str() );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
char* GWConverter::qStringToChar( const TQString &string )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQCString str = string.utf8();
|
||
15 years ago
|
|
||
|
char* charStr = (char*)soap_malloc( mSoap, str.length() + 1 );
|
||
|
memcpy( charStr, str, str.length() );
|
||
|
charStr[ str.length() ] = 0;
|
||
|
|
||
|
return charStr;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDate GWConverter::charToTQDate( const char *str )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( !str ) return TQDate(); // FIXME: Qt::ISODate is probably no good here because it expects yyyy-MM-dd not yyyyMMdd
|
||
|
return TQDate::fromString( TQString::fromUtf8( str ), Qt::ISODate );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
char *GWConverter::qDateTimeToChar( const TQDateTime &dt,
|
||
|
const TQString &timezone )
|
||
15 years ago
|
{
|
||
|
return qDateTimeToChar( KPimPrefs::localTimeToUtc( dt, timezone ) );
|
||
|
}
|
||
|
|
||
14 years ago
|
char *GWConverter::qDateTimeToChar( const TQDateTime &dt )
|
||
15 years ago
|
{
|
||
|
return qStringToChar( dt.toString( "yyyyMMddThhmmZ" ) );
|
||
|
}
|
||
|
|
||
14 years ago
|
std::string* GWConverter::qDateTimeToString( const TQDateTime &dt, const TQString &timezone )
|
||
15 years ago
|
{
|
||
|
return qDateTimeToString( KPimPrefs::localTimeToUtc( dt, timezone ) );
|
||
|
}
|
||
|
|
||
14 years ago
|
std::string* GWConverter::qDateTimeToString( const TQDateTime &dt )
|
||
15 years ago
|
{
|
||
|
return qStringToString( dt.toString( "yyyyMMddThhmmZ" ) );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDateTime GWConverter::stringToTQDateTime( const std::string* str )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDateTime dt = TQDateTime::fromString( TQString::fromUtf8( str->c_str() ), Qt::ISODate );
|
||
15 years ago
|
return dt;
|
||
|
}
|
||
|
|
||
14 years ago
|
char* GWConverter::qDateToChar( const TQDate &date )
|
||
15 years ago
|
{
|
||
|
return qStringToChar( date.toString( "yyyyMMdd" ) );
|
||
|
}
|
||
|
|
||
14 years ago
|
std::string* GWConverter::qDateToString( const TQDate &date )
|
||
15 years ago
|
{
|
||
|
return qStringToString( date.toString( "yyyyMMdd" ) );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDate GWConverter::stringToTQDate( std::string* str )
|
||
15 years ago
|
{
|
||
|
//NB this ISODate may become unnecessary, if GW stops sending in yyyy-mm-dd format again
|
||
13 years ago
|
return TQDate::fromString( TQString::fromLatin1( str->c_str() ), Qt::ISODate );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQDateTime GWConverter::charToTQDateTime( const char *str )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( !str ) return TQDateTime();
|
||
14 years ago
|
// kdDebug() << "charToTQDateTime(): " << str << endl;
|
||
14 years ago
|
// as above re Qt::ISODate
|
||
|
TQDateTime dt = TQDateTime::fromString( TQString::fromUtf8( str ), Qt::ISODate );
|
||
15 years ago
|
// kdDebug() << " " << dt.toString() << endl;
|
||
|
return dt;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDateTime GWConverter::charToTQDateTime( const char *str,
|
||
14 years ago
|
const TQString &timezone )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( !str ) return TQDateTime();
|
||
14 years ago
|
TQDateTime utc = charToTQDateTime( str );
|
||
15 years ago
|
return KPimPrefs::utcToLocalTime( utc, timezone );
|
||
|
}
|
||
|
|
||
14 years ago
|
bool GWConverter::emailsMatch( const TQString & email1, const TQString & email2 )
|
||
15 years ago
|
{
|
||
|
// eg demo3.po1.dom1@dmz1.provo.novell.com == demo3@dmz1.provo.novell.com
|
||
|
if ( email1 == email2 )
|
||
|
return true;
|
||
|
|
||
14 years ago
|
TQString shorter, longer;
|
||
15 years ago
|
if ( email1.length() < email2.length() )
|
||
|
{
|
||
|
shorter = email1;
|
||
|
longer = email2;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
shorter = email2;
|
||
|
longer = email1;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString shortStem = shorter.section( '@', 0, 0 );
|
||
|
TQString longStem = longer.section( '@', 0, 0 );
|
||
|
TQString shortHost = shorter.section( '@', 1, 1 );
|
||
|
TQString longHost = longer.section( '@', 1, 1 );
|
||
15 years ago
|
|
||
14 years ago
|
TQString extension = longStem.right( longStem.length() - shortStem.length() );
|
||
15 years ago
|
|
||
|
kdDebug() << "gwconverter::emailsMatch(): " << shorter << " = " << longer << endl;
|
||
|
kdDebug() << "shortStem: " << shortStem << ", longStem: " << longStem << ", extension: " << extension << endl;
|
||
|
|
||
|
if ( longStem.startsWith( shortStem ) && extension.startsWith( "." ) && (
|
||
|
shortHost == longHost ) )
|
||
|
{
|
||
|
kdDebug() << "Looks like a match!" << endl;
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|