• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdenewstuff
 

tdenewstuff

entry.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
00004     Copyright (c) 2014 Timothy Pearson <kb9vqf@pearsoncomputing.net>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "entry.h"
00023 
00024 #include <tqptrdict.h>
00025 #include <tqwindowdefs.h>
00026 
00027 #include <tdeglobal.h>
00028 #include <tdelocale.h>
00029 
00030 using namespace KNS;
00031 
00032 // BCI for KDE 3.5 only
00033 
00034 class EntryPrivate
00035 {
00036   public:
00037   EntryPrivate(){}
00038   TQString mEmail;
00039   TQMap<TQString,TQString> mNameMap;
00040 };
00041 
00042 static TQPtrDict<EntryPrivate> *d_ptr = 0;
00043 
00044 static EntryPrivate *d(const Entry *e)
00045 {
00046   if(!d_ptr)
00047   {
00048     d_ptr = new TQPtrDict<EntryPrivate>();
00049     d_ptr->setAutoDelete(true);
00050   }
00051   EntryPrivate *ret = d_ptr->find((void*)e);
00052   if(!ret)
00053   {
00054     ret = new EntryPrivate();
00055     d_ptr->replace((void*)e, ret);
00056   }
00057   return ret;
00058 }
00059 
00060 TQString Entry::authorEmail() const
00061 {
00062   return d(this)->mEmail;
00063 }
00064 
00065 void Entry::setAuthorEmail( const TQString& email )
00066 {
00067   d(this)->mEmail = email;
00068 }
00069 
00070 TQString Entry::name( const TQString &lang ) const
00071 {
00072   if ( d(this)->mNameMap.isEmpty() ) return TQString::null;
00073 
00074   if ( !d(this)->mNameMap[ lang ].isEmpty() ) return d(this)->mNameMap[ lang ];
00075   else {
00076     TQStringList langs = TDEGlobal::locale()->languageList();
00077     for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
00078       if( !d(this)->mNameMap[ *it ].isEmpty() ) return d(this)->mNameMap[ *it ];
00079   }
00080   if ( !d(this)->mNameMap[ TQString::null ].isEmpty() ) return d(this)->mNameMap[ TQString::null ];
00081   else return *(mSummaryMap.begin());
00082 }
00083 
00084 void Entry::setName( const TQString &name, const TQString &lang )
00085 {
00086   d(this)->mNameMap.insert( lang, name );
00087 
00088   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
00089 }
00090 
00091 // BCI part ends here
00092 
00093 Entry::Entry() :
00094   mRelease( 0 ), mReleaseDate( TQDate::currentDate() ), mRating( 0 ),
00095   mDownloads( 0 )
00096 {
00097 }
00098 
00099 Entry::Entry( const TQDomElement &e ) :
00100   mRelease( 0 ), mRating( 0 ), mDownloads( 0 )
00101 {
00102   parseDomElement( e );
00103 }
00104 
00105 Entry::~Entry()
00106 {
00107     if (d_ptr)
00108     {
00109         EntryPrivate *p = d_ptr->find(this);
00110         if (p)
00111             d_ptr->remove(p);
00112 
00113         if (d_ptr->isEmpty())
00114         {
00115             delete d_ptr;
00116             d_ptr = 0L;
00117         }
00118     }
00119 }
00120 
00121 
00122 void Entry::setName( const TQString &name )
00123 {
00124   mName = name;
00125 }
00126 
00127 TQString Entry::name() const
00128 {
00129   return mName;
00130 }
00131 
00132 
00133 void Entry::setType( const TQString &type )
00134 {
00135   mType = type;
00136 }
00137 
00138 TQString Entry::type() const
00139 {
00140   return mType;
00141 }
00142 
00143 
00144 void Entry::setAuthor( const TQString &author )
00145 {
00146   mAuthor = author;
00147 }
00148 
00149 TQString Entry::author() const
00150 {
00151   return mAuthor;
00152 }
00153 
00154 
00155 void Entry::setLicence( const TQString &license )
00156 {
00157   mLicence = license;
00158 }
00159 
00160 TQString Entry::license() const
00161 {
00162   return mLicence;
00163 }
00164 
00165 
00166 void Entry::setSummary( const TQString &text, const TQString &lang )
00167 {
00168   mSummaryMap.insert( lang, text );
00169 
00170   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
00171 }
00172 
00173 TQString Entry::summary( const TQString &lang ) const
00174 {
00175   if ( mSummaryMap.isEmpty() ) return TQString::null;
00176 
00177   if ( !mSummaryMap[ lang ].isEmpty() ) return mSummaryMap[ lang ];
00178   else {
00179     TQStringList langs = TDEGlobal::locale()->languageList();
00180     for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
00181       if( !mSummaryMap[ *it ].isEmpty() ) return mSummaryMap[ *it ];
00182   }
00183   if ( !mSummaryMap[ TQString::null ].isEmpty() ) return mSummaryMap[ TQString::null ];
00184   else return *(mSummaryMap.begin());
00185 }
00186 
00187 
00188 void Entry::setVersion( const TQString &version )
00189 {
00190   mVersion = version;
00191 }
00192 
00193 TQString Entry::version() const
00194 {
00195   return mVersion;
00196 }
00197 
00198 
00199 void Entry::setRelease( int release )
00200 {
00201   mRelease = release;
00202 }
00203 
00204 int Entry::release() const
00205 {
00206   return mRelease;
00207 }
00208 
00209 
00210 void Entry::setReleaseDate( const TQDate &d )
00211 {
00212   mReleaseDate = d;
00213 }
00214 
00215 TQDate Entry::releaseDate() const
00216 {
00217   return mReleaseDate;
00218 }
00219 
00220 
00221 void Entry::setPayload( const KURL &url, const TQString &lang )
00222 {
00223   mPayloadMap.insert( lang, url );
00224 
00225   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
00226 }
00227 
00228 KURL Entry::payload( const TQString &lang ) const
00229 {
00230   KURL payload = mPayloadMap[ lang ];
00231   if ( payload.isEmpty() ) {
00232     TQStringList langs = TDEGlobal::locale()->languageList();
00233     for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
00234       if( !mPayloadMap[ *it ].isEmpty() ) return mPayloadMap[ *it ];
00235   }
00236   if ( payload.isEmpty() ) payload = mPayloadMap [ TQString::null ];
00237   if ( payload.isEmpty() && !mPayloadMap.isEmpty() ) {
00238     payload = *(mPayloadMap.begin());
00239   }
00240   return payload;
00241 }
00242 
00243 
00244 void Entry::setPreview( const KURL &url, const TQString &lang )
00245 {
00246   mPreviewMap.insert( lang, url );
00247   
00248   if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
00249 }
00250 
00251 KURL Entry::preview( const TQString &lang ) const
00252 {
00253   KURL preview = mPreviewMap[ lang ];
00254   if ( preview.isEmpty() ) {
00255     TQStringList langs = TDEGlobal::locale()->languageList();
00256     for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
00257       if( !mPreviewMap[ *it ].isEmpty() ) return mPreviewMap[ *it ];
00258   }
00259   if ( preview.isEmpty() ) preview = mPreviewMap [ TQString::null ];
00260   if ( preview.isEmpty() && !mPreviewMap.isEmpty() ) {
00261     preview = *(mPreviewMap.begin());
00262   }
00263   return preview;
00264 }
00265 
00266 
00267 void Entry::setRating( int rating )
00268 {
00269   mRating = rating;
00270 }
00271 
00272 int Entry::rating()
00273 {
00274   return mRating;
00275 }
00276 
00277 
00278 void Entry::setDownloads( int downloads )
00279 {
00280   mDownloads = downloads;
00281 }
00282 
00283 int Entry::downloads()
00284 {
00285   return mDownloads;
00286 }
00287 
00288 TQString Entry::fullName()
00289 {
00290   if ( version().isEmpty() )
00291     return name();
00292   else
00293     return name() + "-" + version() + "-" + TQString::number( release() );
00294 }
00295 
00296 TQStringList Entry::langs()
00297 {
00298   return mLangs;
00299 }
00300 
00301 // FIXME
00302 // It appears that OCS has removed the ability to retrieve author EMail;
00303 // further confirmation is needed before removing EMail-related code
00304 // NOTE
00305 // OCS also removed the ability to have individually localized names and summaries for a single item
00306 // As this would be a useful feature to add to the OCS system I'm keeping the lang code skeleton in at this time
00307 // Note that the "language" XML tag refers to the intended language of the content, not the language of the entry!
00308 void Entry::parseDomElement( const TQDomElement &element )
00309 {
00310   if ( element.tagName() != "content" ) return;
00311   mType = element.attribute("type");
00312 
00313   TQDomNode n;
00314   TQString lang;
00315   for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
00316     TQDomElement e = n.toElement();
00317     if ( e.tagName() == "name" )
00318     {
00319       setName( e.text().stripWhiteSpace(), lang );
00320       setName( e.text().stripWhiteSpace() ); /* primary key - no i18n */
00321     }
00322     if ( e.tagName() == "personid" ) {
00323       setAuthor( e.text().stripWhiteSpace() );
00324 //       TQString email = e.attribute( "email" );
00325 //       setAuthorEmail( email );
00326     }
00327 //     if ( e.tagName() == "email" ) setAuthorEmail( e.text().stripWhiteSpace() ); /* kde-look; change on server! */
00328     if ( e.tagName() == "licence" ) setLicence( e.text().stripWhiteSpace() );
00329     if ( e.tagName() == "description" ) {
00330       setSummary( e.text().stripWhiteSpace(), lang );
00331     }
00332     if ( e.tagName() == "version" ) setVersion( e.text().stripWhiteSpace() );
00333 //     if ( e.tagName() == "release" ) setRelease( e.text().toInt() );
00334     if ( e.tagName() == "created" ) {
00335       TQDate date = TQT_TQDATE_OBJECT(TQDate::fromString( e.text().stripWhiteSpace(), Qt::ISODate ));
00336       setReleaseDate( date );
00337     }
00338     if ( e.tagName() == "smallpreviewpic1" ) {
00339       setPreview( KURL( e.text().stripWhiteSpace() ), lang );
00340     }
00341     if ( e.tagName() == "downloadlink1" ) {
00342       setPayload( KURL( e.text().stripWhiteSpace() ), lang );
00343     }
00344     if ( e.tagName() == "score" ) setRating( e.text().toInt() );
00345     if ( e.tagName() == "downloads" ) setDownloads( e.text().toInt() );
00346 //     if ( e.tagName() == "typename" ) setType( e.text() );
00347   }
00348 }
00349 
00350 TQDomElement Entry::createDomElement( TQDomDocument &doc,
00351                                               TQDomElement &parent )
00352 {
00353   TQDomElement entry = doc.createElement( "content" );
00354   entry.setAttribute("type", mType);
00355   parent.appendChild( entry );
00356 
00357   addElement( doc, entry, "language", langs().first() );
00358 
00359   addElement( doc, entry, "name", name() );
00360   addElement( doc, entry, "personid", author() );
00361 //   addElement( doc, entry, "email", authorEmail() );
00362   addElement( doc, entry, "licence", license() );
00363   addElement( doc, entry, "version", version() );
00364 //   addElement( doc, entry, "release", TQString::number( release() ) );
00365   addElement( doc, entry, "score", TQString::number( rating() ) );
00366   addElement( doc, entry, "downloads", TQString::number( downloads() ) );
00367 
00368   addElement( doc, entry, "created",
00369               releaseDate().toString( Qt::ISODate ) );
00370 
00371   addElement( doc, entry, "description", summary() );
00372   addElement( doc, entry, "preview", preview().url() );
00373   addElement( doc, entry, "payload", payload().url() );
00374 
00375   return entry;
00376 }
00377 
00378 TQDomElement Entry::addElement( TQDomDocument &doc, TQDomElement &parent,
00379                                const TQString &tag, const TQString &value )
00380 {
00381   TQDomElement n = doc.createElement( tag );
00382   n.appendChild( doc.createTextNode( value ) );
00383   parent.appendChild( n );
00384 
00385   return n;
00386 }

tdenewstuff

Skip menu "tdenewstuff"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdenewstuff

Skip menu "tdenewstuff"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdenewstuff by doxygen 1.6.3
This website is maintained by Timothy Pearson.