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 &license )
00075 {
00076   mLicence = license;
00077 }
00078 
00079 QString Entry::license() 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   KURL preview = mPreviewMap[ lang ];
00165   if ( preview.isEmpty() && !mPreviewMap.isEmpty() ) {
00166     preview = *(mPreviewMap.begin());
00167   }
00168   return preview;
00169 }
00170 
00171 
00172 void Entry::setRating( int rating )
00173 {
00174   mRating = rating;
00175 }
00176 
00177 int Entry::rating()
00178 {
00179   return mRating;
00180 }
00181 
00182 
00183 void Entry::setDownloads( int downloads )
00184 {
00185   mDownloads = downloads;
00186 }
00187 
00188 int Entry::downloads()
00189 {
00190   return mDownloads;
00191 }
00192 
00193 QString Entry::fullName()
00194 {
00195   return name() + "-" + version() + "-" + QString::number( release() );
00196 }
00197 
00198 QStringList Entry::langs()
00199 {
00200   return mLangs;
00201 }
00202 
00203 void Entry::parseDomElement( const QDomElement &element )
00204 {
00205   if ( element.tagName() != "stuff" ) return;
00206   mType = element.attribute("type");
00207 
00208   QDomNode n;
00209   for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
00210     QDomElement e = n.toElement();
00211     if ( e.tagName() == "name" ) setName( e.text().stripWhiteSpace() );
00212     if ( e.tagName() == "author" ) setAuthor( e.text().stripWhiteSpace() );
00213     if ( e.tagName() == "licence" ) setLicence( e.text().stripWhiteSpace() );
00214     if ( e.tagName() == "summary" ) {
00215       QString lang = e.attribute( "lang " );
00216       setSummary( e.text().stripWhiteSpace(), lang );
00217     }
00218     if ( e.tagName() == "version" ) setVersion( e.text().stripWhiteSpace() );
00219     if ( e.tagName() == "release" ) setRelease( e.text().toInt() );
00220     if ( e.tagName() == "releasedate" ) {
00221       QDate date = QDate::fromString( e.text().stripWhiteSpace(), Qt::ISODate );
00222       setReleaseDate( date );
00223     }
00224     if ( e.tagName() == "preview" ) {
00225       QString lang = e.attribute( "lang" );
00226       setPreview( KURL( e.text().stripWhiteSpace() ), lang );
00227     }
00228     if ( e.tagName() == "payload" ) {
00229       QString lang = e.attribute( "lang" );
00230       setPayload( KURL( e.text().stripWhiteSpace() ), lang );
00231     }
00232     if ( e.tagName() == "rating" ) setRating( e.text().toInt() );
00233     if ( e.tagName() == "downloads" ) setDownloads( e.text().toInt() );
00234   }
00235 }
00236 
00237 QDomElement Entry::createDomElement( QDomDocument &doc,
00238                                               QDomElement &parent )
00239 {
00240   QDomElement entry = doc.createElement( "stuff" );
00241   entry.setAttribute("type", mType);
00242   parent.appendChild( entry );
00243 
00244   addElement( doc, entry, "name", name() );
00245   addElement( doc, entry, "author", author() );
00246   addElement( doc, entry, "licence", license() );
00247   addElement( doc, entry, "version", version() );
00248   addElement( doc, entry, "release", QString::number( release() ) );
00249   addElement( doc, entry, "rating", QString::number( rating() ) );
00250   addElement( doc, entry, "downloads", QString::number( downloads() ) );
00251 
00252   addElement( doc, entry, "releasedate",
00253               releaseDate().toString( Qt::ISODate ) );
00254 
00255   QStringList ls = langs();
00256   QStringList::ConstIterator it;
00257   for( it = ls.begin(); it != ls.end(); ++it ) {
00258     QDomElement e = addElement( doc, entry, "summary", summary( *it ) );
00259     e.setAttribute( "lang", *it );
00260     e = addElement( doc, entry, "preview", preview( *it ).url() );
00261     e.setAttribute( "lang", *it );
00262     e = addElement( doc, entry, "payload", payload( *it ).url() );
00263     e.setAttribute( "lang", *it );
00264   }
00265 
00266   return entry;
00267 }
00268 
00269 QDomElement Entry::addElement( QDomDocument &doc, QDomElement &parent,
00270                                const QString &tag, const QString &value )
00271 {
00272   QDomElement n = doc.createElement( tag );
00273   n.appendChild( doc.createTextNode( value ) );
00274   parent.appendChild( n );
00275   
00276   return n;
00277 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:27 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003