lib

KoDocumentInfoDlg.cpp

00001 /* This file is part of the KDE project
00002    Copyright (c) 2000 Simon Hausmann <hausmann@kde.org>
00003 
00004    $Id: KoDocumentInfoDlg.cpp 512890 2006-02-23 21:37:08Z illissius $
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 "KoDocumentInfoDlg.h"
00023 #include "KoDocumentInfo.h"
00024 #include "koDocumentInfoAboutWidget.h"
00025 #include "koDocumentInfoAuthorWidget.h"
00026 #include "koDocumentInfoUserMetadataWidget.h"
00027 #include "KoDocument.h"
00028 
00029 #include <KoGlobal.h>
00030 #include <KoStore.h>
00031 
00032 #include <sys/stat.h>
00033 #include <unistd.h>
00034 #include <assert.h>
00035 
00036 #include <qlabel.h>
00037 #include <qbuffer.h>
00038 #include <qdom.h>
00039 #include <qdir.h>
00040 #include <qvbox.h>
00041 #include <qdatetime.h>
00042 
00043 #include <kabc/addressee.h>
00044 #include <kabc/stdaddressbook.h>
00045 #include <kdeversion.h>
00046 #include <klocale.h>
00047 #include <kmessagebox.h>
00048 #include <ktar.h>
00049 #include <kdebug.h>
00050 #include <ktempfile.h>
00051 #include <kmimetype.h>
00052 #include <qlayout.h>
00053 #include <klistview.h>
00054 #include <qgrid.h>
00055 #include <qmap.h>
00056 #include <kfilterdev.h>
00057 #include <klineedit.h>
00058 #include <ktextedit.h>
00059 #include <kiconloader.h>
00060 #include <kpushbutton.h>
00061 #include <klocale.h>
00062 
00063 class KoDocumentInfoDlg::KoDocumentInfoDlgPrivate
00064 {
00065 public:
00066   KoDocumentInfoDlgPrivate()
00067   {
00068   }
00069   ~KoDocumentInfoDlgPrivate()
00070   {
00071   }
00072 
00073   KoDocumentInfo *m_info;
00074   KoDocumentInfoAboutWidget *m_aboutWidget;
00075   KoDocumentInfoAuthorWidget *m_authorWidget;
00076   KoDocumentInfoUserMetadataWidget *m_metaWidget;
00077 
00078   bool m_bDeleteDialog;
00079   KDialogBase *m_dialog;
00080 };
00081 
00082 KoDocumentInfoDlg::KoDocumentInfoDlg( KoDocumentInfo *docInfo, QWidget *parent, const char *name,
00083                                       KDialogBase *dialog )
00084 : QObject( parent, "docinfodlg" )
00085 {
00086   d = new KoDocumentInfoDlgPrivate;
00087   d->m_info = docInfo;
00088 
00089   d->m_dialog = dialog;
00090   d->m_bDeleteDialog = false;
00091 
00092   if ( !dialog )
00093   {
00094     d->m_dialog = new KDialogBase( KDialogBase::Tabbed,
00095                                    i18n( "Document Information" ),
00096                                    KDialogBase::Ok | KDialogBase::Cancel,
00097                                    KDialogBase::Ok, parent, name, true, false );
00098     d->m_dialog->setInitialSize( QSize( 500, 500 ) );
00099     d->m_bDeleteDialog = true;
00100   }
00101 
00102   QStringList pages = docInfo->pages();
00103   QStringList::ConstIterator it = pages.begin();
00104   QStringList::ConstIterator end = pages.end();
00105   for (; it != end; ++it )
00106   {
00107     KoDocumentInfoPage *pg = docInfo->page( *it );
00108     if ( pg->inherits( "KoDocumentInfoAuthor" ) )
00109       addAuthorPage( static_cast<KoDocumentInfoAuthor *>( pg ) );
00110     else if ( pg->inherits( "KoDocumentInfoAbout" ) )
00111       addAboutPage( static_cast<KoDocumentInfoAbout *>( pg ) );
00112 /*    else if ( pg->inherits( "KoDocumentInfoUserMetadata" ) )
00113       addUserMetadataPage( static_cast<KoDocumentInfoUserMetadata *>( pg ) );*/
00114   }
00115 }
00116 
00117 KoDocumentInfoDlg::~KoDocumentInfoDlg()
00118 {
00119   if ( d->m_bDeleteDialog )
00120     delete d->m_dialog;
00121 
00122   delete d;
00123 }
00124 
00125 int KoDocumentInfoDlg::exec()
00126 {
00127   return d->m_dialog->exec();
00128 }
00129 
00130 KDialogBase *KoDocumentInfoDlg::dialog() const
00131 {
00132   return d->m_dialog;
00133 }
00134 
00135 void KoDocumentInfoDlg::loadFromKABC()
00136 {
00137   KABC::StdAddressBook *ab = static_cast<KABC::StdAddressBook*>
00138                              ( KABC::StdAddressBook::self() );
00139 
00140   if ( !ab )
00141     return;
00142 
00143   KABC::Addressee addr = ab->whoAmI();
00144   if ( addr.isEmpty() )
00145   {
00146     KMessageBox::sorry( 0L, i18n( "No personal contact data set, please use the option \
00147                                   \"Set as Personal Contact Data\" from the \"Edit\" menu in KAddressbook to set one." ) );
00148     return;
00149   }
00150 
00151   d->m_authorWidget->leFullName->setText( addr.formattedName() );
00152   d->m_authorWidget->leInitial->setText( addr.givenName()[ 0 ] + ". " +
00153                            addr.familyName()[ 0 ] + "." );
00154   d->m_authorWidget->leAuthorTitle->setText( addr.title() );
00155   d->m_authorWidget->leCompany->setText( addr.organization() );
00156   d->m_authorWidget->leEmail->setText( addr.preferredEmail() );
00157 
00158   KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Home );
00159   d->m_authorWidget->leTelephoneHome->setText( phone.number() );
00160   phone = addr.phoneNumber( KABC::PhoneNumber::Work );
00161   d->m_authorWidget->leTelephoneWork->setText( phone.number() );
00162 
00163   phone = addr.phoneNumber( KABC::PhoneNumber::Fax );
00164   d->m_authorWidget->leFax->setText( phone.number() );
00165 
00166   KABC::Address a = addr.address( KABC::Address::Home );
00167   d->m_authorWidget->leCountry->setText( a.country() );
00168   d->m_authorWidget->lePostalCode->setText( a.postalCode() );
00169   d->m_authorWidget->leCity->setText( a.locality() );
00170   d->m_authorWidget->leStreet->setText( a.street() );
00171 
00172   emit changed();
00173 }
00174 
00175 void KoDocumentInfoDlg::deleteInfo()
00176 {
00177   d->m_authorWidget->leFullName->setText( QString::null );
00178   d->m_authorWidget->leInitial->setText( QString::null );
00179   d->m_authorWidget->leAuthorTitle->setText( QString::null );
00180   d->m_authorWidget->leCompany->setText( QString::null );
00181   d->m_authorWidget->leEmail->setText( QString::null );
00182   d->m_authorWidget->leTelephoneHome->setText( QString::null );
00183   d->m_authorWidget->leTelephoneWork->setText( QString::null );
00184   d->m_authorWidget->leFax->setText( QString::null );
00185   d->m_authorWidget->leCountry->setText( QString::null );
00186   d->m_authorWidget->lePostalCode->setText( QString::null );
00187   d->m_authorWidget->leCity->setText( QString::null );
00188   d->m_authorWidget->leStreet->setText( QString::null );
00189   emit changed();
00190 }
00191 
00192 void KoDocumentInfoDlg::resetMetaData()
00193 {
00194   QString s = KGlobal::locale()->formatDateTime( QDateTime::currentDateTime() );
00195   d->m_aboutWidget->labelCreated->setText( s + ", " + d->m_info->creator() );
00196   d->m_aboutWidget->labelModified->setText( "" );
00197   d->m_aboutWidget->labelRevision->setText( "0" );
00198   emit changed();
00199 }
00200 
00201 void KoDocumentInfoDlg::addAuthorPage( KoDocumentInfoAuthor *authorInfo )
00202 {
00203   QVBox *page = d->m_dialog->addVBoxPage( i18n( "Author" ) );
00204   d->m_authorWidget = new KoDocumentInfoAuthorWidget( page );
00205   d->m_authorWidget->labelAuthor->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 48 ) );
00206   d->m_authorWidget->pbLoadKABC->setIconSet( QIconSet( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Small ) ) );
00207   d->m_authorWidget->pbDelete->setIconSet( QIconSet( KGlobal::iconLoader()->loadIcon( "eraser", KIcon::Small ) ) );
00208 
00209   d->m_authorWidget->leFullName->setText( authorInfo->fullName() );
00210   d->m_authorWidget->leInitial->setText( authorInfo->initial() );
00211   d->m_authorWidget->leAuthorTitle->setText( authorInfo->title() );
00212   d->m_authorWidget->leCompany->setText( authorInfo->company() );
00213   d->m_authorWidget->leEmail->setText( authorInfo->email() );
00214   d->m_authorWidget->leTelephoneWork->setText( authorInfo->telephoneWork() );
00215   d->m_authorWidget->leTelephoneHome->setText( authorInfo->telephoneHome() );
00216   d->m_authorWidget->leFax->setText( authorInfo->fax() );
00217   d->m_authorWidget->leCountry->setText( authorInfo->country() );
00218   d->m_authorWidget->lePostalCode->setText( authorInfo->postalCode() );
00219   d->m_authorWidget->leCity->setText( authorInfo->city() );
00220   d->m_authorWidget->leStreet->setText( authorInfo->street() );
00221   d->m_authorWidget->leAuthorPosition->setText( authorInfo->position() );
00222 
00223   connect( d->m_authorWidget->leFullName, SIGNAL( textChanged( const QString & ) ),
00224            this, SIGNAL( changed() ) );
00225   connect( d->m_authorWidget->leInitial, SIGNAL( textChanged( const QString & ) ),
00226            this, SIGNAL( changed() ) );
00227   connect( d->m_authorWidget->leAuthorTitle, SIGNAL( textChanged( const QString & ) ),
00228            this, SIGNAL( changed() ) );
00229   connect( d->m_authorWidget->leCompany, SIGNAL( textChanged( const QString & ) ),
00230            this, SIGNAL( changed() ) );
00231   connect( d->m_authorWidget->leEmail, SIGNAL( textChanged( const QString & ) ),
00232            this, SIGNAL( changed() ) );
00233   connect( d->m_authorWidget->leTelephoneWork, SIGNAL( textChanged( const QString & ) ),
00234            this, SIGNAL( changed() ) );
00235   connect( d->m_authorWidget->leTelephoneHome, SIGNAL( textChanged( const QString & ) ),
00236            this, SIGNAL( changed() ) );
00237   connect( d->m_authorWidget->leFax, SIGNAL( textChanged( const QString & ) ),
00238            this, SIGNAL( changed() ) );
00239   connect( d->m_authorWidget->leCountry, SIGNAL( textChanged( const QString & ) ),
00240            this, SIGNAL( changed() ) );
00241   connect( d->m_authorWidget->lePostalCode, SIGNAL( textChanged( const QString & ) ),
00242            this, SIGNAL( changed() ) );
00243   connect( d->m_authorWidget->leCity, SIGNAL( textChanged( const QString & ) ),
00244            this, SIGNAL( changed() ) );
00245   connect( d->m_authorWidget->leStreet, SIGNAL( textChanged( const QString & ) ),
00246            this, SIGNAL( changed() ) );
00247   connect( d->m_authorWidget->leAuthorPosition, SIGNAL( textChanged( const QString & ) ),
00248            this, SIGNAL( changed() ) );
00249   connect( d->m_authorWidget->pbLoadKABC, SIGNAL( clicked() ),
00250            this, SLOT( loadFromKABC() ) );
00251   connect( d->m_authorWidget->pbDelete, SIGNAL( clicked() ),
00252            this, SLOT( deleteInfo() ) );
00253 }
00254 
00255 void KoDocumentInfoDlg::addAboutPage( KoDocumentInfoAbout *aboutInfo )
00256 {
00257   QVBox *page = d->m_dialog->addVBoxPage( i18n( "General" ) );
00258   d->m_aboutWidget = new KoDocumentInfoAboutWidget( page );
00259   d->m_aboutWidget->pbReset->setIconSet( QIconSet( KGlobal::iconLoader()->loadIcon( "reload", KIcon::Small ) ) );
00260   KoDocument* doc = dynamic_cast< KoDocument* >( d->m_info->parent() );
00261   if ( doc )
00262   {
00263     d->m_aboutWidget->leDocFile->setText( doc->file() );
00264     d->m_aboutWidget->labelType->setText( KMimeType::mimeType( doc->mimeType() )->comment() );
00265     d->m_aboutWidget->pixmapLabel->setPixmap( KMimeType::mimeType( doc->mimeType() )->pixmap( KIcon::Desktop, 48 ) );
00266   }
00267   if ( aboutInfo->creationDate() != QString::null )
00268     d->m_aboutWidget->labelCreated->setText( aboutInfo->creationDate() + ", " + aboutInfo->initialCreator() );
00269   if ( aboutInfo->modificationDate() != QString::null )
00270     d->m_aboutWidget->labelModified->setText( aboutInfo->modificationDate() + ", " + d->m_info->creator() );
00271   d->m_aboutWidget->labelRevision->setText( aboutInfo->editingCycles() );
00272   d->m_aboutWidget->leDocTitle->setText( aboutInfo->title() );
00273   d->m_aboutWidget->leDocSubject->setText( aboutInfo->subject() );
00274   d->m_aboutWidget->leDocKeywords->setText( aboutInfo->keywords() );
00275   d->m_aboutWidget->meDocAbstract->setText( aboutInfo->abstract() );
00276 
00277   connect( d->m_aboutWidget->leDocTitle, SIGNAL( textChanged( const QString & ) ),
00278            this, SIGNAL( changed() ) );
00279   connect( d->m_aboutWidget->meDocAbstract, SIGNAL( textChanged() ),
00280            this, SIGNAL( changed() ) );
00281   connect( d->m_aboutWidget->leDocSubject, SIGNAL( textChanged( const QString & ) ),
00282            this, SIGNAL( changed() ) );
00283   connect( d->m_aboutWidget->leDocKeywords, SIGNAL( textChanged( const QString & ) ),
00284            this, SIGNAL( changed() ) );
00285   connect( d->m_aboutWidget->pbReset, SIGNAL( clicked() ),
00286            aboutInfo, SLOT( resetMetaData() ) );
00287   connect( d->m_aboutWidget->pbReset, SIGNAL( clicked() ),
00288            this, SLOT( resetMetaData() ) );
00289 }
00290 
00291 void KoDocumentInfoDlg::addUserMetadataPage( KoDocumentInfoUserMetadata *userMetadataInfo )
00292 {
00293   QVBox *page = d->m_dialog->addVBoxPage( i18n( "User-Defined Metadata" ) );
00294   d->m_metaWidget = new KoDocumentInfoUserMetadataWidget( page );
00295 
00296   d->m_metaWidget->metaListView->addColumn( "Name" );
00297   d->m_metaWidget->metaListView->setFullWidth( true );
00298 
00299   QMap<QString, QString>::iterator it;
00300     for ( it = userMetadataInfo->metadataList()->begin(); it != userMetadataInfo->metadataList()->end(); ++it )
00301     {
00302         QString name = it.key();
00303         QString value = it.data();
00304         KListViewItem* it = new KListViewItem( d->m_metaWidget->metaListView, name, value );
00305         it->setPixmap( 0, KGlobal::iconLoader()->loadIcon( "text", KIcon::Small ) );
00306     }
00307 }
00308 
00309 void KoDocumentInfoDlg::save()
00310 {
00311   QStringList pages = d->m_info->pages();
00312   QStringList::ConstIterator it = pages.begin();
00313   QStringList::ConstIterator end = pages.end();
00314   bool saveInfo=false;
00315   for (; it != end; ++it )
00316   {
00317     KoDocumentInfoPage *pg = d->m_info->page( *it );
00318     if ( pg->inherits( "KoDocumentInfoAuthor" ) )
00319     {
00320         saveInfo=true;
00321         save( static_cast<KoDocumentInfoAuthor *>( pg ) );
00322     }
00323     else if ( pg->inherits( "KoDocumentInfoAbout" ) )
00324     {
00325         saveInfo=true;
00326         save( static_cast<KoDocumentInfoAbout *>( pg ) );
00327     }
00328   }
00329   if(saveInfo)
00330       d->m_info->documentInfochanged();
00331 }
00332 
00333 void KoDocumentInfoDlg::save( KoDocumentInfoAuthor *authorInfo )
00334 {
00335   authorInfo->setFullName( d->m_authorWidget->leFullName->text() );
00336   authorInfo->setInitial( d->m_authorWidget->leInitial->text() );
00337   authorInfo->setTitle( d->m_authorWidget->leAuthorTitle->text() );
00338   authorInfo->setCompany( d->m_authorWidget->leCompany->text() );
00339   authorInfo->setEmail( d->m_authorWidget->leEmail->text() );
00340   authorInfo->setTelephoneWork( d->m_authorWidget->leTelephoneWork->text() );
00341   authorInfo->setTelephoneHome( d->m_authorWidget->leTelephoneHome->text() );
00342   authorInfo->setFax( d->m_authorWidget->leFax->text() );
00343   authorInfo->setCountry( d->m_authorWidget->leCountry->text() );
00344   authorInfo->setPostalCode( d->m_authorWidget->lePostalCode->text() );
00345   authorInfo->setCity( d->m_authorWidget->leCity->text() );
00346   authorInfo->setStreet( d->m_authorWidget->leStreet->text() );
00347   authorInfo->setPosition( d->m_authorWidget->leAuthorPosition->text() );
00348 
00349   KConfig* config = KoGlobal::kofficeConfig();
00350   KConfigGroupSaver cgs( config, "Author" );
00351   config->writeEntry("telephone", d->m_authorWidget->leTelephoneHome->text());
00352   config->writeEntry("telephone-work", d->m_authorWidget->leTelephoneWork->text());
00353   config->writeEntry("fax", d->m_authorWidget->leFax->text());
00354   config->writeEntry("country",d->m_authorWidget->leCountry->text());
00355   config->writeEntry("postal-code",d->m_authorWidget->lePostalCode->text());
00356   config->writeEntry("city",  d->m_authorWidget->leCity->text());
00357   config->writeEntry("street", d->m_authorWidget->leStreet->text());
00358   config->sync();
00359 }
00360 
00361 void KoDocumentInfoDlg::save( KoDocumentInfoAbout *aboutInfo )
00362 {
00363   aboutInfo->setTitle( d->m_aboutWidget->leDocTitle->text() );
00364   aboutInfo->setSubject( d->m_aboutWidget->leDocSubject->text() );
00365   aboutInfo->setKeywords( d->m_aboutWidget->leDocKeywords->text() );
00366   aboutInfo->setAbstract( d->m_aboutWidget->meDocAbstract->text() );
00367 }
00368 
00369 void KoDocumentInfoDlg::save( KoDocumentInfoUserMetadata* )
00370 {
00371     // FIXME
00372 }
00373 
00374 class KoDocumentInfoPropsPage::KoDocumentInfoPropsPagePrivate
00375 {
00376 public:
00377   KoDocumentInfo *m_info;
00378   KoDocumentInfoDlg *m_dlg;
00379   KURL m_url;
00380   KTarGz *m_src;
00381   KTarGz *m_dst;
00382 
00383   const KTarFile *m_docInfoFile;
00384 };
00385 
00386 KoDocumentInfoPropsPage::KoDocumentInfoPropsPage( KPropertiesDialog *props,
00387                                                   const char *,
00388                                                   const QStringList & )
00389 : KPropsDlgPlugin( props )
00390 {
00391   d = new KoDocumentInfoPropsPagePrivate;
00392   d->m_info = new KoDocumentInfo( this, "docinfo" );
00393   d->m_url = props->item()->url();
00394   d->m_dlg = 0;
00395 
00396   if ( !d->m_url.isLocalFile() )
00397     return;
00398 
00399   d->m_dst = 0;
00400 
00401 #ifdef __GNUC__
00402 #warning TODO port this to KoStore !!!
00403 #endif
00404   d->m_src = new KTarGz( d->m_url.path(), "application/x-gzip" );
00405 
00406   if ( !d->m_src->open( IO_ReadOnly ) )
00407     return;
00408 
00409   const KTarDirectory *root = d->m_src->directory();
00410   if ( !root )
00411     return;
00412 
00413   const KTarEntry *entry = root->entry( "documentinfo.xml" );
00414 
00415   if ( entry && entry->isFile() )
00416   {
00417     d->m_docInfoFile = static_cast<const KTarFile *>( entry );
00418 
00419     QBuffer buffer( d->m_docInfoFile->data() );
00420     buffer.open( IO_ReadOnly );
00421 
00422     QDomDocument doc;
00423     doc.setContent( &buffer );
00424 
00425     d->m_info->load( doc );
00426   }
00427 
00428   d->m_dlg = new KoDocumentInfoDlg( d->m_info, 0, 0, props );
00429   connect( d->m_dlg, SIGNAL( changed() ),
00430            this, SIGNAL( changed() ) );
00431 }
00432 
00433 KoDocumentInfoPropsPage::~KoDocumentInfoPropsPage()
00434 {
00435   delete d->m_info;
00436   delete d->m_src;
00437   delete d->m_dst;
00438   delete d->m_dlg;
00439   delete d;
00440 }
00441 
00442 void KoDocumentInfoPropsPage::applyChanges()
00443 {
00444   const KTarDirectory *root = d->m_src->directory();
00445   if ( !root )
00446     return;
00447 
00448   struct stat statBuff;
00449 
00450   if ( stat( QFile::encodeName( d->m_url.path() ), &statBuff ) != 0 )
00451     return;
00452 
00453   KTempFile tempFile( d->m_url.path(), QString::null, statBuff.st_mode );
00454 
00455   tempFile.setAutoDelete( true );
00456 
00457   if ( tempFile.status() != 0 )
00458     return;
00459 
00460   if ( !tempFile.close() )
00461     return;
00462 
00463   d->m_dst = new KTarGz( tempFile.name(), "application/x-gzip" );
00464 
00465   if ( !d->m_dst->open( IO_WriteOnly ) )
00466     return;
00467 
00468   KMimeType::Ptr mimeType = KMimeType::findByURL( d->m_url, 0, true );
00469   if ( mimeType && dynamic_cast<KFilterDev *>( d->m_dst->device() ) != 0 )
00470   {
00471       QCString appIdentification( "KOffice " ); // We are limited in the number of chars.
00472       appIdentification += mimeType->name().latin1();
00473       appIdentification += '\004'; // Two magic bytes to make the identification
00474       appIdentification += '\006'; // more reliable (DF)
00475       d->m_dst->setOrigFileName( appIdentification );
00476   }
00477 
00478   bool docInfoSaved = false;
00479 
00480   QStringList entries = root->entries();
00481   QStringList::ConstIterator it = entries.begin();
00482   QStringList::ConstIterator end = entries.end();
00483   for (; it != end; ++it )
00484   {
00485     const KTarEntry *entry = root->entry( *it );
00486 
00487     assert( entry );
00488 
00489     if ( entry->name() == "documentinfo.xml" ||
00490          ( !docInfoSaved && !entries.contains( "documentinfo.xml" ) ) )
00491     {
00492       d->m_dlg->save();
00493 
00494       QBuffer buffer;
00495       buffer.open( IO_WriteOnly );
00496       QTextStream str( &buffer );
00497       str << d->m_info->save();
00498       buffer.close();
00499 
00500       kdDebug( 30003 ) << "writing documentinfo.xml" << endl;
00501       d->m_dst->writeFile( "documentinfo.xml", entry->user(), entry->group(), buffer.buffer().size(),
00502                            buffer.buffer().data() );
00503 
00504       docInfoSaved = true;
00505     }
00506     else
00507       copy( QString::null, entry );
00508   }
00509 
00510   d->m_dst->close();
00511 
00512   QDir dir;
00513   dir.rename( tempFile.name(), d->m_url.path() );
00514 
00515   delete d->m_dst;
00516   d->m_dst = 0;
00517 }
00518 
00519 void KoDocumentInfoPropsPage::copy( const QString &path, const KArchiveEntry *entry )
00520 {
00521   kdDebug( 30003 ) << "copy " << entry->name() << endl;
00522   if ( entry->isFile() )
00523   {
00524     const KTarFile *file = static_cast<const KTarFile *>( entry );
00525     kdDebug( 30003 ) << "file :" << entry->name() << endl;
00526     kdDebug( 30003 ) << "full path is: " << path << entry->name() << endl;
00527     d->m_dst->writeFile( path + entry->name(), entry->user(), entry->group(),
00528                          file->size(),
00529                          file->data().data() );
00530   }
00531   else
00532   {
00533     const KTarDirectory *dir = static_cast<const KTarDirectory *>( entry );
00534     kdDebug( 30003 ) << "dir : " << entry->name() << endl;
00535     kdDebug( 30003 ) << "full path is: " << path << entry->name() << endl;
00536 
00537     QString p = path + entry->name();
00538     if ( p != "/" )
00539     {
00540       d->m_dst->writeDir( p, entry->user(), entry->group() );
00541       p.append( "/" );
00542     }
00543 
00544     QStringList entries = dir->entries();
00545     QStringList::ConstIterator it = entries.begin();
00546     QStringList::ConstIterator end = entries.end();
00547     for (; it != end; ++it )
00548       copy( p, dir->entry( *it ) );
00549   }
00550 }
00551 
00552 /* vim: sw=2 et
00553  */
00554 
00555 #include "KoDocumentInfoDlg.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys