korganizer Library API Documentation

entry.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include "entry.h"
00022 
00023 using namespace KNS;
00024 
00025 Entry::Entry() :
00026   mRelease( 0 ), mReleaseDate( QDate::currentDate() ), mRating( 0 ),
00027   mDownloads( 0 )
00028 {
00029 }
00030 
00031 Entry::Entry( const QDomElement &e )
00032 {
00033   parseDomElement( e );
00034 }
00035 
00036 Entry::~Entry()
00037 {
00038 }
00039 
00040 
00041 void Entry::setName( const QString &name )
00042 {
00043   mName = name;
00044 }
00045 
00046 QString Entry::name() const
00047 {
00048   return mName;
00049 }
00050 
00051 
00052 void Entry::setType( const QString &type )
00053 {
00054   mType = type;
00055 }
00056 
00057 QString Entry::type() const
00058 {
00059   return mType;
00060 }
00061 
00062 
00063 void Entry::setAuthor( const QString &author )
00064 {
00065   mAuthor = author;
00066 }
00067 
00068 QString Entry::author() const
00069 {
00070   return mAuthor;
00071 }
00072 
00073 
00074 void Entry::setLicence( const QString &licence )
00075 {
00076   mLicence = licence;
00077 }
00078 
00079 QString Entry::licence() const
00080 {
00081   return mLicence;
00082 }
00083 
00084 
00085 void Entry::setSummary( const QString &text, const QString &lang )
00086 {
00087   mSummaryMap.insert( lang, text );
00088 
00089   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
00090 }
00091 
00092 QString Entry::summary( const QString &lang ) const
00093 {
00094   if ( mSummaryMap.isEmpty() ) return QString::null;
00095 
00096   if ( lang.isEmpty() ) {
00097     if ( !mSummaryMap[ lang ].isEmpty() ) return mSummaryMap[ lang ];
00098     else return *(mSummaryMap.begin());
00099   } else {
00100     return mSummaryMap[ lang ];
00101   }
00102 }
00103 
00104 
00105 void Entry::setVersion( const QString &version )
00106 {
00107   mVersion = version;
00108 }
00109 
00110 QString Entry::version() const
00111 {
00112   return mVersion;
00113 }
00114 
00115 
00116 void Entry::setRelease( int release )
00117 {
00118   mRelease = release;
00119 }
00120 
00121 int Entry::release() const
00122 {
00123   return mRelease;
00124 }
00125 
00126 
00127 void Entry::setReleaseDate( const QDate &d )
00128 {
00129   mReleaseDate = d;
00130 }
00131 
00132 QDate Entry::releaseDate() const
00133 {
00134   return mReleaseDate;
00135 }
00136 
00137 
00138 void Entry::setPayload( const KURL &url, const QString &lang )
00139 {
00140   mPayloadMap.insert( lang, url );
00141 
00142   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
00143 }
00144 
00145 KURL Entry::payload( const QString &lang ) const
00146 {
00147   KURL payload = mPayloadMap[ lang ];
00148   if ( payload.isEmpty() && !mPayloadMap.isEmpty() ) {
00149     payload = *(mPayloadMap.begin());
00150   }
00151   return payload;
00152 }
00153 
00154 
00155 void Entry::setPreview( const KURL &url, const QString &lang )
00156 {
00157   mPreviewMap.insert( lang, url );
00158   
00159   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
00160 }
00161 
00162 KURL Entry::preview( const QString &lang ) const
00163 {
00164   return mPayloadMap[ lang ];
00165 }
00166 
00167 
00168 void Entry::setRating( int rating )
00169 {
00170   mRating = rating;
00171 }
00172 
00173 int Entry::rating()
00174 {
00175   return mRating;
00176 }
00177 
00178 
00179 void Entry::setDownloads( int downloads )
00180 {
00181   mDownloads = downloads;
00182 }
00183 
00184 int Entry::downloads()
00185 {
00186   return mDownloads;
00187 }
00188 
00189 QString Entry::fullName()
00190 {
00191   return name() + "-" + version() + "-" + QString::number( release() );
00192 }
00193 
00194 QStringList Entry::langs()
00195 {
00196   return mLangs;
00197 }
00198 
00199 void Entry::parseDomElement( const QDomElement &element )
00200 {
00201   if ( element.tagName() != "stuff" ) return;
00202 
00203   QDomNode n;
00204   for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
00205     QDomElement e = n.toElement();
00206     if ( e.tagName() == "name" ) setName( e.text().stripWhiteSpace() );
00207     if ( e.tagName() == "author" ) setAuthor( e.text().stripWhiteSpace() );
00208     if ( e.tagName() == "licence" ) setLicence( e.text().stripWhiteSpace() );
00209     if ( e.tagName() == "summary" ) {
00210       QString lang = e.attribute( "lang " );
00211       setSummary( e.text().stripWhiteSpace(), lang );
00212     }
00213     if ( e.tagName() == "version" ) setVersion( e.text().stripWhiteSpace() );
00214     if ( e.tagName() == "release" ) setRelease( e.text().toInt() );
00215     if ( e.tagName() == "releasedate" ) {
00216       QDate date = QDate::fromString( e.text().stripWhiteSpace(), Qt::ISODate );
00217       setReleaseDate( date );
00218     }
00219     if ( e.tagName() == "preview" ) {
00220       QString lang = e.attribute( "lang" );
00221       setPreview( e.text().stripWhiteSpace(), lang );
00222     }
00223     if ( e.tagName() == "payload" ) {
00224       QString lang = e.attribute( "lang" );
00225       setPayload( e.text().stripWhiteSpace(), lang );
00226     }
00227     if ( e.tagName() == "rating" ) setRating( e.text().toInt() );
00228     if ( e.tagName() == "downloads" ) setDownloads( e.text().toInt() );
00229   }
00230 }
00231 
00232 QDomElement Entry::createDomElement( QDomDocument &doc,
00233                                               QDomElement &parent )
00234 {
00235   QDomElement entry = doc.createElement( "stuff" );
00236   parent.appendChild( entry );
00237 
00238   addElement( doc, entry, "name", name() );
00239   addElement( doc, entry, "author", author() );
00240   addElement( doc, entry, "licence", licence() );
00241   addElement( doc, entry, "version", version() );
00242   addElement( doc, entry, "release", QString::number( release() ) );
00243   addElement( doc, entry, "rating", QString::number( rating() ) );
00244   addElement( doc, entry, "downloads", QString::number( downloads() ) );
00245 
00246   addElement( doc, entry, "releasedate",
00247               releaseDate().toString( Qt::ISODate ) );
00248 
00249   QStringList ls = langs();
00250   QStringList::ConstIterator it;
00251   for( it = ls.begin(); it != ls.end(); ++it ) {
00252     QDomElement e = addElement( doc, entry, "summary", summary( *it ) );
00253     e.setAttribute( "lang", *it );
00254     e = addElement( doc, entry, "preview", preview( *it ).url() );
00255     e.setAttribute( "lang", *it );
00256     e = addElement( doc, entry, "payload", payload( *it ).url() );
00257     e.setAttribute( "lang", *it );
00258   }
00259 
00260   return entry;
00261 }
00262 
00263 QDomElement Entry::addElement( QDomDocument &doc, QDomElement &parent,
00264                                const QString &tag, const QString &value )
00265 {
00266   QDomElement n = doc.createElement( tag );
00267   n.appendChild( doc.createTextNode( value ) );
00268   parent.appendChild( n );
00269   
00270   return n;
00271 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001