lib Library API Documentation

koDocumentInfo.cc

00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include <koDocumentInfo.h> 00021 #include <koDocument.h> 00022 #include <qdom.h> 00023 #include <qobjectlist.h> 00024 #include <kconfig.h> 00025 #include <kdebug.h> 00026 #include <koApplication.h> 00027 00028 /***************************************** 00029 * 00030 * KoDocumentInfo 00031 * 00032 *****************************************/ 00033 00034 KoDocumentInfo::KoDocumentInfo( QObject* parent, const char* name ) 00035 : QObject( parent, name ) 00036 { 00037 (void)new KoDocumentInfoLog( this ); 00038 (void)new KoDocumentInfoAuthor( this ); 00039 (void)new KoDocumentInfoAbout( this ); 00040 } 00041 00042 KoDocumentInfo::~KoDocumentInfo() 00043 { 00044 } 00045 00046 bool KoDocumentInfo::load( const QDomDocument& doc ) 00047 { 00048 QStringList lst = pages(); 00049 QStringList::ConstIterator it = lst.begin(); 00050 for( ; it != lst.end(); ++it ) 00051 { 00052 KoDocumentInfoPage* p = page( *it ); 00053 Q_ASSERT( p ); 00054 if ( !p->load( doc.documentElement() ) ) 00055 return false; 00056 } 00057 00058 return true; 00059 } 00060 00061 QDomDocument KoDocumentInfo::save() 00062 { 00063 QDomDocument doc = KoDocument::createDomDocument( "document-info" /*DTD name*/, "document-info" /*tag name*/, "1.1" ); 00064 QDomElement e = doc.documentElement(); 00065 00066 QStringList lst = pages(); 00067 QStringList::ConstIterator it = lst.begin(); 00068 for( ; it != lst.end(); ++it ) 00069 { 00070 KoDocumentInfoPage* p = page( *it ); 00071 Q_ASSERT( p ); 00072 QDomElement s = p->save( doc ); 00073 if ( s.isNull() ) 00074 return QDomDocument(); 00075 e.appendChild( s ); 00076 } 00077 00078 return doc; 00079 } 00080 00081 KoDocumentInfoPage* KoDocumentInfo::page( const QString& name ) const 00082 { 00083 QObject* obj = const_cast<KoDocumentInfo*>(this)->child( name.latin1() ); 00084 00085 return (KoDocumentInfoPage*)obj; 00086 } 00087 00088 QStringList KoDocumentInfo::pages() const 00089 { 00090 QStringList ret; 00091 00092 const QObjectList *list = children(); 00093 if ( list ) 00094 { 00095 QObjectListIt it( *list ); 00096 QObject *obj; 00097 while ( ( obj = it.current() ) ) 00098 { 00099 ret.append( obj->name() ); 00100 ++it; 00101 } 00102 } 00103 00104 return ret; 00105 } 00106 00107 QString KoDocumentInfo::title() const 00108 { 00109 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(page( "about" )); 00110 if ( !aboutPage ) { 00111 kdWarning() << "'About' page not found in documentInfo !" << endl; 00112 return QString::null; 00113 } 00114 else 00115 return aboutPage->title(); 00116 } 00117 00118 /***************************************** 00119 * 00120 * KoDocumentInfoPage 00121 * 00122 *****************************************/ 00123 00124 KoDocumentInfoPage::KoDocumentInfoPage( QObject* parent, const char* name ) 00125 : QObject( parent, name ) 00126 { 00127 } 00128 00129 /***************************************** 00130 * 00131 * KoDocumentInfoLog 00132 * 00133 *****************************************/ 00134 00135 KoDocumentInfoLog::KoDocumentInfoLog( KoDocumentInfo* info ) 00136 : KoDocumentInfoPage( info, "log" ) 00137 { 00138 } 00139 00140 bool KoDocumentInfoLog::load( const QDomElement& e ) 00141 { 00142 m_newLog = QString::null; 00143 00144 QDomElement n = e.namedItem( "log" ).firstChild().toElement(); 00145 for( ; !n.isNull(); n = n.nextSibling().toElement() ) 00146 { 00147 if ( n.tagName() == "text" ) 00148 m_oldLog = n.text(); 00149 } 00150 00151 return true; 00152 } 00153 00154 QDomElement KoDocumentInfoLog::save( QDomDocument& doc ) 00155 { 00156 QString text = m_oldLog; 00157 if ( !m_newLog.isEmpty() ) 00158 { 00159 text += "\n"; 00160 text += m_newLog; 00161 } 00162 00163 QDomElement e = doc.createElement( "log" ); 00164 QDomElement t = doc.createElement( "text" ); 00165 e.appendChild( t ); 00166 t.appendChild( doc.createTextNode( m_newLog ) ); 00167 00168 return e; 00169 } 00170 00171 void KoDocumentInfoLog::setNewLog( const QString& log ) 00172 { 00173 m_newLog = log; 00174 } 00175 00176 void KoDocumentInfoLog::setOldLog( const QString& log ) 00177 { 00178 m_oldLog = log; 00179 } 00180 00181 QString KoDocumentInfoLog::oldLog() const 00182 { 00183 return m_oldLog; 00184 } 00185 00186 QString KoDocumentInfoLog::newLog() const 00187 { 00188 return m_newLog; 00189 } 00190 00191 /***************************************** 00192 * 00193 * KoDocumentInfoAuthor 00194 * 00195 *****************************************/ 00196 00197 KoDocumentInfoAuthor::KoDocumentInfoAuthor( KoDocumentInfo* info ) 00198 : KoDocumentInfoPage( info, "author" ) 00199 { 00200 initParameters(); 00201 } 00202 00203 void KoDocumentInfoAuthor::initParameters() 00204 { 00205 KConfig* config = KoGlobal::kofficeConfig(); 00206 if ( config->hasGroup( "Author" ) ) { 00207 KConfigGroupSaver cgs( config, "Author" ); 00208 m_telephone=config->readEntry( "telephone" ); 00209 m_fax=config->readEntry( "fax" ); 00210 m_country=config->readEntry( "country" ); 00211 m_postalCode=config->readEntry( "postal-code" ); 00212 m_city=config->readEntry( "city" ); 00213 m_street=config->readEntry( "street" ); 00214 } 00215 } 00216 00217 bool KoDocumentInfoAuthor::load( const QDomElement& e ) 00218 { 00219 QDomElement n = e.namedItem( "author" ).firstChild().toElement(); 00220 for( ; !n.isNull(); n = n.nextSibling().toElement() ) 00221 { 00222 if ( n.tagName() == "full-name" ) 00223 m_fullName = n.text(); 00224 else if ( n.tagName() == "initial" ) 00225 m_initial = n.text(); 00226 else if ( n.tagName() == "title" ) 00227 m_title = n.text(); 00228 else if ( n.tagName() == "company" ) 00229 m_company = n.text(); 00230 else if ( n.tagName() == "email" ) 00231 m_email = n.text(); 00232 else if ( n.tagName() == "telephone" ) 00233 m_telephone = n.text(); 00234 else if ( n.tagName() == "fax" ) 00235 m_fax = n.text(); 00236 else if ( n.tagName() == "country" ) 00237 m_country = n.text(); 00238 else if ( n.tagName() == "postal-code" ) 00239 m_postalCode = n.text(); 00240 else if ( n.tagName() == "city" ) 00241 m_city = n.text(); 00242 else if ( n.tagName() == "street" ) 00243 m_street = n.text(); 00244 } 00245 return true; 00246 } 00247 00248 QDomElement KoDocumentInfoAuthor::save( QDomDocument& doc ) 00249 { 00250 QDomElement e = doc.createElement( "author" ); 00251 00252 QDomElement t = doc.createElement( "full-name" ); 00253 e.appendChild( t ); 00254 t.appendChild( doc.createTextNode( m_fullName ) ); 00255 00256 t = doc.createElement( "initial" ); 00257 e.appendChild( t ); 00258 t.appendChild( doc.createTextNode( m_initial ) ); 00259 00260 00261 t = doc.createElement( "title" ); 00262 e.appendChild( t ); 00263 t.appendChild( doc.createTextNode( m_title ) ); 00264 00265 t = doc.createElement( "company" ); 00266 e.appendChild( t ); 00267 t.appendChild( doc.createTextNode( m_company ) ); 00268 00269 t = doc.createElement( "email" ); 00270 e.appendChild( t ); 00271 t.appendChild( doc.createTextNode( m_email ) ); 00272 00273 t = doc.createElement( "telephone" ); 00274 e.appendChild( t ); 00275 t.appendChild( doc.createTextNode( m_telephone ) ); 00276 00277 t = doc.createElement( "fax" ); 00278 e.appendChild( t ); 00279 t.appendChild( doc.createTextNode( m_fax ) ); 00280 00281 t = doc.createElement( "country" ); 00282 e.appendChild( t ); 00283 t.appendChild( doc.createTextNode( m_country ) ); 00284 00285 t = doc.createElement( "postal-code" ); 00286 e.appendChild( t ); 00287 t.appendChild( doc.createTextNode( m_postalCode ) ); 00288 00289 t = doc.createElement( "city" ); 00290 e.appendChild( t ); 00291 t.appendChild( doc.createTextNode( m_city ) ); 00292 00293 t = doc.createElement( "street" ); 00294 e.appendChild( t ); 00295 t.appendChild( doc.createTextNode( m_street ) ); 00296 00297 return e; 00298 } 00299 00300 QString KoDocumentInfoAuthor::fullName() const 00301 { 00302 return m_fullName; 00303 } 00304 00305 QString KoDocumentInfoAuthor::initial() const 00306 { 00307 return m_initial; 00308 } 00309 00310 QString KoDocumentInfoAuthor::title() const 00311 { 00312 return m_title; 00313 } 00314 00315 QString KoDocumentInfoAuthor::company() const 00316 { 00317 return m_company; 00318 } 00319 00320 QString KoDocumentInfoAuthor::email() const 00321 { 00322 return m_email; 00323 } 00324 00325 QString KoDocumentInfoAuthor::telephone() const 00326 { 00327 return m_telephone; 00328 } 00329 00330 QString KoDocumentInfoAuthor::fax() const 00331 { 00332 return m_fax; 00333 } 00334 00335 QString KoDocumentInfoAuthor::country() const 00336 { 00337 return m_country; 00338 } 00339 00340 QString KoDocumentInfoAuthor::postalCode() const 00341 { 00342 return m_postalCode; 00343 } 00344 00345 QString KoDocumentInfoAuthor::city() const 00346 { 00347 return m_city; 00348 } 00349 00350 QString KoDocumentInfoAuthor::street() const 00351 { 00352 return m_street; 00353 } 00354 00355 void KoDocumentInfoAuthor::setFullName( const QString& n ) 00356 { 00357 m_fullName = n; 00358 } 00359 00360 void KoDocumentInfoAuthor::setInitial( const QString& n ) 00361 { 00362 m_initial = n; 00363 } 00364 00365 00366 void KoDocumentInfoAuthor::setTitle( const QString& n ) 00367 { 00368 m_title = n; 00369 } 00370 00371 void KoDocumentInfoAuthor::setCompany( const QString& n ) 00372 { 00373 m_company = n; 00374 } 00375 00376 void KoDocumentInfoAuthor::setEmail( const QString& n ) 00377 { 00378 m_email = n; 00379 } 00380 00381 void KoDocumentInfoAuthor::setTelephone( const QString& n ) 00382 { 00383 m_telephone = n; 00384 } 00385 00386 void KoDocumentInfoAuthor::setFax( const QString& n ) 00387 { 00388 m_fax = n; 00389 } 00390 00391 void KoDocumentInfoAuthor::setCountry( const QString& n ) 00392 { 00393 m_country = n; 00394 } 00395 00396 void KoDocumentInfoAuthor::setPostalCode( const QString& n ) 00397 { 00398 m_postalCode = n; 00399 } 00400 00401 void KoDocumentInfoAuthor::setCity( const QString& n ) 00402 { 00403 m_city = n; 00404 } 00405 00406 void KoDocumentInfoAuthor::setStreet( const QString& n ) 00407 { 00408 m_street = n; 00409 } 00410 00411 /***************************************** 00412 * 00413 * KoDocumentInfoAbout 00414 * 00415 *****************************************/ 00416 00417 KoDocumentInfoAbout::KoDocumentInfoAbout( KoDocumentInfo* info ) 00418 : KoDocumentInfoPage( info, "about" ) 00419 { 00420 } 00421 00422 bool KoDocumentInfoAbout::load( const QDomElement& e ) 00423 { 00424 QDomElement n = e.namedItem( "about" ).firstChild().toElement(); 00425 for( ; !n.isNull(); n = n.nextSibling().toElement() ) 00426 { 00427 if ( n.tagName() == "abstract" ) 00428 m_abstract = n.text(); 00429 else if ( n.tagName() == "title" ) 00430 m_title = n.text(); 00431 } 00432 00433 return true; 00434 } 00435 00436 QDomElement KoDocumentInfoAbout::save( QDomDocument& doc ) 00437 { 00438 QDomElement e = doc.createElement( "about" ); 00439 00440 QDomElement t = doc.createElement( "abstract" ); 00441 e.appendChild( t ); 00442 t.appendChild( doc.createCDATASection( m_abstract ) ); 00443 00444 t = doc.createElement( "title" ); 00445 e.appendChild( t ); 00446 t.appendChild( doc.createTextNode( m_title ) ); 00447 00448 return e; 00449 } 00450 00451 QString KoDocumentInfoAbout::title() const 00452 { 00453 return m_title; 00454 } 00455 00456 QString KoDocumentInfoAbout::abstract() const 00457 { 00458 return m_abstract; 00459 } 00460 00461 void KoDocumentInfoAbout::setTitle( const QString& n ) 00462 { 00463 m_title = n; 00464 } 00465 00466 void KoDocumentInfoAbout::setAbstract( const QString& n ) 00467 { 00468 m_abstract = n; 00469 } 00470 00471 #include <koDocumentInfo.moc>
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Nov 17 06:54:15 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003