knewstuff Library: entry.cpp Source File (knewstuff Library)

| # knewstuff Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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 #include <kglobal.h>
    00024 #include <klocale.h>
    00025
    00026 using namespace KNS;
    00027
    00028 Entry::Entry() :
    00029   mRelease( 0 ), mReleaseDate( QDate::currentDate() ), mRating( 0 ),
    00030   mDownloads( 0 )
    00031 {
    00032 }
    00033
    00034 Entry::Entry( const QDomElement &e ) :
    00035   mRelease( 0 ), mRating( 0 ), mDownloads( 0 )
    00036 {
    00037   parseDomElement( e );
    00038 }
    00039
    00040 Entry::~Entry()
    00041 {
    00042 }
    00043
    00044
    00045 void Entry::setName( const QString &name )
    00046 {
    00047   mName = name;
    00048 }
    00049
    00050 QString Entry::name() const
    00051 {
    00052   return mName;
    00053 }
    00054
    00055
    00056 void Entry::setType( const QString &type )
    00057 {
    00058   mType = type;
    00059 }
    00060
    00061 QString Entry::type() const
    00062 {
    00063   return mType;
    00064 }
    00065
    00066
    00067 void Entry::setAuthor( const QString &author )
    00068 {
    00069   mAuthor = author;
    00070 }
    00071
    00072 QString Entry::author() const
    00073 {
    00074   return mAuthor;
    00075 }
    00076
    00077
    00078 void Entry::setLicence( const QString &license )
    00079 {
    00080   mLicence = license;
    00081 }
    00082
    00083 QString Entry::license() const
    00084 {
    00085   return mLicence;
    00086 }
    00087
    00088
    00089 void Entry::setSummary( const QString &text, const QString &lang )
    00090 {
    00091   mSummaryMap.insert( lang, text );
    00092
    00093   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
    00094 }
    00095
    00096 QString Entry::summary( const QString &lang ) const
    00097 {
    00098   if ( mSummaryMap.isEmpty() ) return QString::null;
    00099
    00100   if ( !mSummaryMap[ lang ].isEmpty() ) return mSummaryMap[ lang ];
    00101   else {
    00102     QStringList langs = KGlobal::locale()->languageList();
    00103     for(QStringList::Iterator it = langs.begin(); it != langs.end(); it++)
    00104       if( !mSummaryMap[ *it ].isEmpty() ) return mSummaryMap[ *it ];
    00105   }
    00106   if ( !mSummaryMap[ QString::null ].isEmpty() ) return mSummaryMap[ QString::null ];
    00107   else return *(mSummaryMap.begin());
    00108 }
    00109
    00110
    00111 void Entry::setVersion( const QString &version )
    00112 {
    00113   mVersion = version;
    00114 }
    00115
    00116 QString Entry::version() const
    00117 {
    00118   return mVersion;
    00119 }
    00120
    00121
    00122 void Entry::setRelease( int release )
    00123 {
    00124   mRelease = release;
    00125 }
    00126
    00127 int Entry::release() const
    00128 {
    00129   return mRelease;
    00130 }
    00131
    00132
    00133 void Entry::setReleaseDate( const QDate &d )
    00134 {
    00135   mReleaseDate = d;
    00136 }
    00137
    00138 QDate Entry::releaseDate() const
    00139 {
    00140   return mReleaseDate;
    00141 }
    00142
    00143
    00144 void Entry::setPayload( const KURL &url, const QString &lang )
    00145 {
    00146   mPayloadMap.insert( lang, url );
    00147
    00148   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
    00149 }
    00150
    00151 KURL Entry::payload( const QString &lang ) const
    00152 {
    00153   KURL payload = mPayloadMap[ lang ];
    00154   if ( payload.isEmpty() ) {
    00155     QStringList langs = KGlobal::locale()->languageList();
    00156     for(QStringList::Iterator it = langs.begin(); it != langs.end(); it++)
    00157       if( !mPayloadMap[ *it ].isEmpty() ) return mPayloadMap[ *it ];
    00158   }
    00159   if ( payload.isEmpty() ) payload = mPayloadMap [ QString::null ];
    00160   if ( payload.isEmpty() && !mPayloadMap.isEmpty() ) {
    00161     payload = *(mPayloadMap.begin());
    00162   }
    00163   return payload;
    00164 }
    00165
    00166
    00167 void Entry::setPreview( const KURL &url, const QString &lang )
    00168 {
    00169   mPreviewMap.insert( lang, url );
    00170
    00171   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
    00172 }
    00173
    00174 KURL Entry::preview( const QString &lang ) const
    00175 {
    00176   KURL preview = mPreviewMap[ lang ];
    00177   if ( preview.isEmpty() ) {
    00178     QStringList langs = KGlobal::locale()->languageList();
    00179     for(QStringList::Iterator it = langs.begin(); it != langs.end(); it++)
    00180       if( !mPreviewMap[ *it ].isEmpty() ) return mPreviewMap[ *it ];
    00181   }
    00182   if ( preview.isEmpty() ) preview = mPreviewMap [ QString::null ];
    00183   if ( preview.isEmpty() && !mPreviewMap.isEmpty() ) {
    00184     preview = *(mPreviewMap.begin());
    00185   }
    00186   return preview;
    00187 }
    00188
    00189
    00190 void Entry::setRating( int rating )
    00191 {
    00192   mRating = rating;
    00193 }
    00194
    00195 int Entry::rating()
    00196 {
    00197   return mRating;
    00198 }
    00199
    00200
    00201 void Entry::setDownloads( int downloads )
    00202 {
    00203   mDownloads = downloads;
    00204 }
    00205
    00206 int Entry::downloads()
    00207 {
    00208   return mDownloads;
    00209 }
    00210
    00211 QString Entry::fullName()
    00212 {
    00213   return name() + "-" + version() + "-" + QString::number( release() );
    00214 }
    00215
    00216 QStringList Entry::langs()
    00217 {
    00218   return mLangs;
    00219 }
    00220
    00221 void Entry::parseDomElement( const QDomElement &element )
    00222 {
    00223   if ( element.tagName() != "stuff" ) return;
    00224   mType = element.attribute("type");
    00225
    00226   QDomNode n;
    00227   for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    00228     QDomElement e = n.toElement();
    00229     if ( e.tagName() == "name" ) setName( e.text().stripWhiteSpace() );
    00230     if ( e.tagName() == "author" ) setAuthor( e.text().stripWhiteSpace() );
    00231     if ( e.tagName() == "licence" ) setLicence( e.text().stripWhiteSpace() );
    00232     if ( e.tagName() == "summary" ) {
    00233       QString lang = e.attribute( "lang" );
    00234       setSummary( e.text().stripWhiteSpace(), lang );
    00235     }
    00236     if ( e.tagName() == "version" ) setVersion( e.text().stripWhiteSpace() );
    00237     if ( e.tagName() == "release" ) setRelease( e.text().toInt() );
    00238     if ( e.tagName() == "releasedate" ) {
    00239       QDate date = QDate::fromString( e.text().stripWhiteSpace(), Qt::ISODate );
    00240       setReleaseDate( date );
    00241     }
    00242     if ( e.tagName() == "preview" ) {
    00243       QString lang = e.attribute( "lang" );
    00244       setPreview( KURL( e.text().stripWhiteSpace() ), lang );
    00245     }
    00246     if ( e.tagName() == "payload" ) {
    00247       QString lang = e.attribute( "lang" );
    00248       setPayload( KURL( e.text().stripWhiteSpace() ), lang );
    00249     }
    00250     if ( e.tagName() == "rating" ) setRating( e.text().toInt() );
    00251     if ( e.tagName() == "downloads" ) setDownloads( e.text().toInt() );
    00252   }
    00253 }
    00254
    00255 QDomElement Entry::createDomElement( QDomDocument &doc,
    00256                                               QDomElement &parent )
    00257 {
    00258   QDomElement entry = doc.createElement( "stuff" );
    00259   entry.setAttribute("type", mType);
    00260   parent.appendChild( entry );
    00261
    00262   addElement( doc, entry, "name", name() );
    00263   addElement( doc, entry, "author", author() );
    00264   addElement( doc, entry, "licence", license() );
    00265   addElement( doc, entry, "version", version() );
    00266   addElement( doc, entry, "release", QString::number( release() ) );
    00267   addElement( doc, entry, "rating", QString::number( rating() ) );
    00268   addElement( doc, entry, "downloads", QString::number( downloads() ) );
    00269
    00270   addElement( doc, entry, "releasedate",
    00271               releaseDate().toString( Qt::ISODate ) );
    00272
    00273   QStringList ls = langs();
    00274   QStringList::ConstIterator it;
    00275   for( it = ls.begin(); it != ls.end(); ++it ) {
    00276     QDomElement e = addElement( doc, entry, "summary", summary( *it ) );
    00277     e.setAttribute( "lang", *it );
    00278     e = addElement( doc, entry, "preview", preview( *it ).url() );
    00279     e.setAttribute( "lang", *it );
    00280     e = addElement( doc, entry, "payload", payload( *it ).url() );
    00281     e.setAttribute( "lang", *it );
    00282   }
    00283
    00284   return entry;
    00285 }
    00286
    00287 QDomElement Entry::addElement( QDomDocument &doc, QDomElement &parent,
    00288                                const QString &tag, const QString &value )
    00289 {
    00290   QDomElement n = doc.createElement( tag );
    00291   n.appendChild( doc.createTextNode( value ) );
    00292   parent.appendChild( n );
    00293
    00294   return n;
    00295 }

This file is part of the documentation for knewstuff Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:28:34 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003