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.
393 lines
9.5 KiB
393 lines
9.5 KiB
15 years ago
|
/*
|
||
|
This file is part of KOrganizer.
|
||
|
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||
10 years ago
|
Copyright (c) 2014 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||
15 years ago
|
|
||
|
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 "entry.h"
|
||
|
|
||
15 years ago
|
#include <tqptrdict.h>
|
||
|
#include <tqwindowdefs.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeglobal.h>
|
||
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
|
using namespace KNS;
|
||
|
|
||
|
// BCI for KDE 3.5 only
|
||
|
|
||
|
class EntryPrivate
|
||
|
{
|
||
|
public:
|
||
|
EntryPrivate(){}
|
||
15 years ago
|
TQString mEmail;
|
||
|
TQMap<TQString,TQString> mNameMap;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
static TQPtrDict<EntryPrivate> *d_ptr = 0;
|
||
15 years ago
|
|
||
|
static EntryPrivate *d(const Entry *e)
|
||
|
{
|
||
|
if(!d_ptr)
|
||
|
{
|
||
15 years ago
|
d_ptr = new TQPtrDict<EntryPrivate>();
|
||
15 years ago
|
d_ptr->setAutoDelete(true);
|
||
|
}
|
||
13 years ago
|
EntryPrivate *ret = d_ptr->find((void*)e);
|
||
15 years ago
|
if(!ret)
|
||
|
{
|
||
|
ret = new EntryPrivate();
|
||
13 years ago
|
d_ptr->replace((void*)e, ret);
|
||
15 years ago
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Entry::authorEmail() const
|
||
15 years ago
|
{
|
||
|
return d(this)->mEmail;
|
||
|
}
|
||
|
|
||
15 years ago
|
void Entry::setAuthorEmail( const TQString& email )
|
||
15 years ago
|
{
|
||
|
d(this)->mEmail = email;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Entry::name( const TQString &lang ) const
|
||
15 years ago
|
{
|
||
15 years ago
|
if ( d(this)->mNameMap.isEmpty() ) return TQString::null;
|
||
15 years ago
|
|
||
|
if ( !d(this)->mNameMap[ lang ].isEmpty() ) return d(this)->mNameMap[ lang ];
|
||
|
else {
|
||
12 years ago
|
TQStringList langs = TDEGlobal::locale()->languageList();
|
||
15 years ago
|
for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
|
||
15 years ago
|
if( !d(this)->mNameMap[ *it ].isEmpty() ) return d(this)->mNameMap[ *it ];
|
||
|
}
|
||
15 years ago
|
if ( !d(this)->mNameMap[ TQString::null ].isEmpty() ) return d(this)->mNameMap[ TQString::null ];
|
||
15 years ago
|
else return *(mSummaryMap.begin());
|
||
|
}
|
||
|
|
||
15 years ago
|
void Entry::setName( const TQString &name, const TQString &lang )
|
||
15 years ago
|
{
|
||
|
d(this)->mNameMap.insert( lang, name );
|
||
|
|
||
13 years ago
|
if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
|
||
15 years ago
|
}
|
||
|
|
||
|
// BCI part ends here
|
||
|
|
||
|
Entry::Entry() :
|
||
14 years ago
|
mRelease( 0 ), mReleaseDate( TQDate::currentDate() ), mRating( 0 ),
|
||
15 years ago
|
mDownloads( 0 )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
Entry::Entry( const TQDomElement &e ) :
|
||
15 years ago
|
mRelease( 0 ), mRating( 0 ), mDownloads( 0 )
|
||
|
{
|
||
|
parseDomElement( e );
|
||
|
}
|
||
|
|
||
|
Entry::~Entry()
|
||
|
{
|
||
|
if (d_ptr)
|
||
|
{
|
||
13 years ago
|
EntryPrivate *p = d_ptr->find(this);
|
||
15 years ago
|
if (p)
|
||
|
d_ptr->remove(p);
|
||
|
|
||
|
if (d_ptr->isEmpty())
|
||
|
{
|
||
|
delete d_ptr;
|
||
|
d_ptr = 0L;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void Entry::setName( const TQString &name )
|
||
15 years ago
|
{
|
||
|
mName = name;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Entry::name() const
|
||
15 years ago
|
{
|
||
|
return mName;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void Entry::setType( const TQString &type )
|
||
15 years ago
|
{
|
||
|
mType = type;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Entry::type() const
|
||
15 years ago
|
{
|
||
|
return mType;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void Entry::setAuthor( const TQString &author )
|
||
15 years ago
|
{
|
||
|
mAuthor = author;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Entry::author() const
|
||
15 years ago
|
{
|
||
|
return mAuthor;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void Entry::setLicence( const TQString &license )
|
||
15 years ago
|
{
|
||
|
mLicence = license;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Entry::license() const
|
||
15 years ago
|
{
|
||
|
return mLicence;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void Entry::setSummary( const TQString &text, const TQString &lang )
|
||
15 years ago
|
{
|
||
|
mSummaryMap.insert( lang, text );
|
||
|
|
||
13 years ago
|
if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString Entry::summary( const TQString &lang ) const
|
||
15 years ago
|
{
|
||
15 years ago
|
if ( mSummaryMap.isEmpty() ) return TQString::null;
|
||
15 years ago
|
|
||
|
if ( !mSummaryMap[ lang ].isEmpty() ) return mSummaryMap[ lang ];
|
||
|
else {
|
||
12 years ago
|
TQStringList langs = TDEGlobal::locale()->languageList();
|
||
15 years ago
|
for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
|
||
15 years ago
|
if( !mSummaryMap[ *it ].isEmpty() ) return mSummaryMap[ *it ];
|
||
|
}
|
||
15 years ago
|
if ( !mSummaryMap[ TQString::null ].isEmpty() ) return mSummaryMap[ TQString::null ];
|
||
15 years ago
|
else return *(mSummaryMap.begin());
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void Entry::setVersion( const TQString &version )
|
||
15 years ago
|
{
|
||
|
mVersion = version;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Entry::version() const
|
||
15 years ago
|
{
|
||
|
return mVersion;
|
||
|
}
|
||
|
|
||
|
|
||
|
void Entry::setRelease( int release )
|
||
|
{
|
||
|
mRelease = release;
|
||
|
}
|
||
|
|
||
|
int Entry::release() const
|
||
|
{
|
||
|
return mRelease;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void Entry::setReleaseDate( const TQDate &d )
|
||
15 years ago
|
{
|
||
|
mReleaseDate = d;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDate Entry::releaseDate() const
|
||
15 years ago
|
{
|
||
|
return mReleaseDate;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void Entry::setPayload( const KURL &url, const TQString &lang )
|
||
15 years ago
|
{
|
||
|
mPayloadMap.insert( lang, url );
|
||
|
|
||
13 years ago
|
if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
KURL Entry::payload( const TQString &lang ) const
|
||
15 years ago
|
{
|
||
|
KURL payload = mPayloadMap[ lang ];
|
||
|
if ( payload.isEmpty() ) {
|
||
12 years ago
|
TQStringList langs = TDEGlobal::locale()->languageList();
|
||
15 years ago
|
for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
|
||
15 years ago
|
if( !mPayloadMap[ *it ].isEmpty() ) return mPayloadMap[ *it ];
|
||
|
}
|
||
15 years ago
|
if ( payload.isEmpty() ) payload = mPayloadMap [ TQString::null ];
|
||
15 years ago
|
if ( payload.isEmpty() && !mPayloadMap.isEmpty() ) {
|
||
|
payload = *(mPayloadMap.begin());
|
||
|
}
|
||
|
return payload;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void Entry::setPreview( const KURL &url, const TQString &lang )
|
||
15 years ago
|
{
|
||
|
mPreviewMap.insert( lang, url );
|
||
|
|
||
13 years ago
|
if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
KURL Entry::preview( const TQString &lang ) const
|
||
15 years ago
|
{
|
||
|
KURL preview = mPreviewMap[ lang ];
|
||
|
if ( preview.isEmpty() ) {
|
||
12 years ago
|
TQStringList langs = TDEGlobal::locale()->languageList();
|
||
15 years ago
|
for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
|
||
15 years ago
|
if( !mPreviewMap[ *it ].isEmpty() ) return mPreviewMap[ *it ];
|
||
|
}
|
||
15 years ago
|
if ( preview.isEmpty() ) preview = mPreviewMap [ TQString::null ];
|
||
15 years ago
|
if ( preview.isEmpty() && !mPreviewMap.isEmpty() ) {
|
||
|
preview = *(mPreviewMap.begin());
|
||
|
}
|
||
|
return preview;
|
||
|
}
|
||
|
|
||
|
|
||
|
void Entry::setRating( int rating )
|
||
|
{
|
||
|
mRating = rating;
|
||
|
}
|
||
|
|
||
|
int Entry::rating()
|
||
|
{
|
||
|
return mRating;
|
||
|
}
|
||
|
|
||
|
|
||
|
void Entry::setDownloads( int downloads )
|
||
|
{
|
||
|
mDownloads = downloads;
|
||
|
}
|
||
|
|
||
|
int Entry::downloads()
|
||
|
{
|
||
|
return mDownloads;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Entry::fullName()
|
||
15 years ago
|
{
|
||
|
if ( version().isEmpty() )
|
||
|
return name();
|
||
|
else
|
||
15 years ago
|
return name() + "-" + version() + "-" + TQString::number( release() );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQStringList Entry::langs()
|
||
15 years ago
|
{
|
||
|
return mLangs;
|
||
|
}
|
||
|
|
||
10 years ago
|
// FIXME
|
||
|
// It appears that OCS has removed the ability to retrieve author EMail;
|
||
|
// further confirmation is needed before removing EMail-related code
|
||
15 years ago
|
void Entry::parseDomElement( const TQDomElement &element )
|
||
15 years ago
|
{
|
||
10 years ago
|
if ( element.tagName() != "content" ) return;
|
||
15 years ago
|
mType = element.attribute("type");
|
||
|
|
||
15 years ago
|
TQDomNode n;
|
||
10 years ago
|
TQString lang;
|
||
|
for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||
|
TQDomElement e = n.toElement();
|
||
|
if ( e.tagName() == "language" )
|
||
|
{
|
||
|
lang = e.text();
|
||
|
}
|
||
|
}
|
||
|
if (lang == "") {
|
||
|
lang = TQString::null;
|
||
|
}
|
||
|
|
||
15 years ago
|
for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||
15 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
if ( e.tagName() == "name" )
|
||
|
{
|
||
|
setName( e.text().stripWhiteSpace(), lang );
|
||
10 years ago
|
setName( e.text().stripWhiteSpace() ); /* primary key - no i18n */
|
||
15 years ago
|
}
|
||
10 years ago
|
if ( e.tagName() == "personid" ) {
|
||
15 years ago
|
setAuthor( e.text().stripWhiteSpace() );
|
||
10 years ago
|
// TQString email = e.attribute( "email" );
|
||
|
// setAuthorEmail( email );
|
||
15 years ago
|
}
|
||
10 years ago
|
// if ( e.tagName() == "email" ) setAuthorEmail( e.text().stripWhiteSpace() ); /* kde-look; change on server! */
|
||
15 years ago
|
if ( e.tagName() == "licence" ) setLicence( e.text().stripWhiteSpace() );
|
||
10 years ago
|
if ( e.tagName() == "description" ) {
|
||
15 years ago
|
setSummary( e.text().stripWhiteSpace(), lang );
|
||
|
}
|
||
|
if ( e.tagName() == "version" ) setVersion( e.text().stripWhiteSpace() );
|
||
10 years ago
|
// if ( e.tagName() == "release" ) setRelease( e.text().toInt() );
|
||
|
if ( e.tagName() == "created" ) {
|
||
14 years ago
|
TQDate date = TQT_TQDATE_OBJECT(TQDate::fromString( e.text().stripWhiteSpace(), Qt::ISODate ));
|
||
15 years ago
|
setReleaseDate( date );
|
||
|
}
|
||
10 years ago
|
if ( e.tagName() == "smallpreviewpic1" ) {
|
||
15 years ago
|
setPreview( KURL( e.text().stripWhiteSpace() ), lang );
|
||
|
}
|
||
10 years ago
|
if ( e.tagName() == "downloadlink1" ) {
|
||
15 years ago
|
setPayload( KURL( e.text().stripWhiteSpace() ), lang );
|
||
|
}
|
||
10 years ago
|
if ( e.tagName() == "score" ) setRating( e.text().toInt() );
|
||
15 years ago
|
if ( e.tagName() == "downloads" ) setDownloads( e.text().toInt() );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDomElement Entry::createDomElement( TQDomDocument &doc,
|
||
|
TQDomElement &parent )
|
||
15 years ago
|
{
|
||
10 years ago
|
TQDomElement entry = doc.createElement( "content" );
|
||
15 years ago
|
entry.setAttribute("type", mType);
|
||
|
parent.appendChild( entry );
|
||
|
|
||
10 years ago
|
addElement( doc, entry, "language", langs().first() );
|
||
|
|
||
15 years ago
|
addElement( doc, entry, "name", name() );
|
||
10 years ago
|
addElement( doc, entry, "personid", author() );
|
||
|
// addElement( doc, entry, "email", authorEmail() );
|
||
15 years ago
|
addElement( doc, entry, "licence", license() );
|
||
|
addElement( doc, entry, "version", version() );
|
||
10 years ago
|
// addElement( doc, entry, "release", TQString::number( release() ) );
|
||
|
addElement( doc, entry, "score", TQString::number( rating() ) );
|
||
15 years ago
|
addElement( doc, entry, "downloads", TQString::number( downloads() ) );
|
||
15 years ago
|
|
||
10 years ago
|
addElement( doc, entry, "created",
|
||
15 years ago
|
releaseDate().toString( Qt::ISODate ) );
|
||
|
|
||
10 years ago
|
addElement( doc, entry, "description", summary() );
|
||
|
addElement( doc, entry, "preview", preview().url() );
|
||
|
addElement( doc, entry, "payload", payload().url() );
|
||
15 years ago
|
|
||
|
return entry;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDomElement Entry::addElement( TQDomDocument &doc, TQDomElement &parent,
|
||
|
const TQString &tag, const TQString &value )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement n = doc.createElement( tag );
|
||
15 years ago
|
n.appendChild( doc.createTextNode( value ) );
|
||
|
parent.appendChild( n );
|
||
|
|
||
|
return n;
|
||
|
}
|