F:/KPlato/koffice/libs/kofficecore/KoDocumentInfoDlg.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (c) 2000 Simon Hausmann <hausmann@kde.org>
00003                  2006 Martin Pfeiffer <hubipete@gmx.net>
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., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KoDocumentInfoDlg.h"
00022 
00023 #include "ui_koDocumentInfoAboutWidget.h"
00024 #include "ui_koDocumentInfoAuthorWidget.h"
00025 #include "KoDocumentInfo.h"
00026 #include "KoDocument.h"
00027 #include <kmimetype.h>
00028 #include <klocale.h>
00029 #include <kglobal.h>
00030 #include <kabc/addressee.h>
00031 #include <kabc/stdaddressbook.h>
00032 #include <KoGlobal.h>
00033 #include <kiconloader.h>
00034 #include <kmessagebox.h>
00035 
00036 #include <QLabel>
00037 #include <QLineEdit>
00038 #include <QTextEdit>
00039 #include <QPixmap>
00040 #include <QDateTime>
00041 
00042 class KoDocumentInfoDlg::KoDocumentInfoDlgPrivate
00043 {
00044 public:
00045     KoDocumentInfoDlgPrivate()
00046     {}
00047     ~KoDocumentInfoDlgPrivate()
00048     {}
00049 
00050     KoDocumentInfo* m_info;
00051     Ui::KoDocumentInfoAboutWidget* m_aboutUi;
00052     Ui::KoDocumentInfoAuthorWidget* m_authorUi;
00053 };
00054 
00055 
00056 
00057 
00058 KoDocumentInfoDlg::KoDocumentInfoDlg( QWidget* parent, KoDocumentInfo* docInfo )
00059     : KPageDialog( parent )
00060 {
00061     d = new KoDocumentInfoDlgPrivate;
00062     d->m_info = docInfo;
00063 
00064     setCaption( i18n( "Document Information" ) );
00065     setInitialSize( QSize( 500, 500 ) );
00066     setFaceType( KPageDialog::Tabbed );
00067     setButtons( KDialog::Ok|KDialog::Cancel );
00068     setDefaultButton( KDialog::Ok );
00069 
00070     d->m_aboutUi = new Ui::KoDocumentInfoAboutWidget();
00071     QWidget *infodlg = new QWidget();
00072     d->m_aboutUi->setupUi( infodlg );
00073     addPage( infodlg, i18n( "General" ) );
00074 
00075     initAboutTab();
00076 
00077     d->m_authorUi = new Ui::KoDocumentInfoAuthorWidget();
00078     QWidget *authordlg = new QWidget();
00079     d->m_authorUi->setupUi( authordlg );
00080     addPage( authordlg, i18n( "Author" ) );
00081 
00082     initAuthorTab();
00083 
00084     connect( this, SIGNAL( okClicked() ), this, SLOT( slotApply() ) );
00085 }
00086 
00087 KoDocumentInfoDlg::~KoDocumentInfoDlg()
00088 {
00089     delete d->m_authorUi;
00090     delete d->m_aboutUi;
00091     delete d;
00092 }
00093 
00094 void KoDocumentInfoDlg::initAboutTab()
00095 {
00096     KoDocument* doc = dynamic_cast< KoDocument* >( d->m_info->parent() );
00097     if( !doc )
00098         return;
00099 
00100     d->m_aboutUi->leFileName->setText( doc->file() );
00101     d->m_aboutUi->leFileName->setReadOnly( true );
00102     
00103     KMimeType::Ptr mime = KMimeType::mimeType( doc->mimeType() );
00104     if ( ! mime )
00105         mime = KMimeType::defaultMimeTypePtr();
00106     QPixmap p = mime->pixmap( K3Icon::Desktop, 48 );
00107     d->m_aboutUi->lblPixmap->setPixmap( p );
00108 
00109     d->m_aboutUi->leTitle->setText( d->m_info->aboutInfo( "title" ) );
00110     d->m_aboutUi->leSubject->setText( d->m_info->aboutInfo( "subject" ) );
00111 
00112     d->m_aboutUi->leKeywords->setToolTip( i18n("Use ';' (Example: Office;KDE;KOffice)" ) );
00113     if( !d->m_info->aboutInfo( "keyword" ).isEmpty() )
00114         d->m_aboutUi->leKeywords->setText( d->m_info->aboutInfo( "keyword" ) );
00115 
00116     d->m_aboutUi->meComments->setPlainText( d->m_info->aboutInfo( "comments" ) );
00117     if ( !doc->mimeType().isEmpty() ) {
00118         KMimeType::Ptr docmime = KMimeType::mimeType( doc->mimeType() );
00119         if (docmime)
00120             d->m_aboutUi->lblType->setText( docmime->comment() );
00121     }
00122     if ( !d->m_info->aboutInfo( "creation-date" ).isEmpty() )
00123     {
00124         QDateTime t = QDateTime::fromString( d->m_info->aboutInfo( "creation-date" ),
00125                 Qt::ISODate );
00126         QString s = KGlobal::locale()->formatDateTime( t );
00127         d->m_aboutUi->lblCreated->setText( s + ", " +
00128                 d->m_info->aboutInfo( "initial-creator" ) );
00129     }
00130 
00131     if ( !d->m_info->aboutInfo( "date" ).isEmpty() )
00132     {
00133         QDateTime t = QDateTime::fromString( d->m_info->aboutInfo( "date" ), Qt::ISODate );
00134         QString s = KGlobal::locale()->formatDateTime( t );
00135         d->m_aboutUi->lblModified->setText( s + ", " + d->m_info->authorInfo( "creator" ) );
00136     }
00137 
00138     d->m_aboutUi->lblRevision->setText( d->m_info->aboutInfo( "editing-cycles" ) );
00139 
00140     connect( d->m_aboutUi->pbReset, SIGNAL( clicked() ),
00141             this, SLOT( slotResetMetaData() ) );
00142 }
00143 
00144 void KoDocumentInfoDlg::initAuthorTab()
00145 {
00146     QPixmap p = KGlobal::iconLoader()->loadIcon( "personal", K3Icon::Desktop, 48 );
00147     d->m_authorUi->lblAuthor->setPixmap( p );
00148     p = KGlobal::iconLoader()->loadIcon( "kaddressbook", K3Icon::Small );
00149     d->m_authorUi->pbLoadKABC->setIcon( QIcon( p ) );
00150     p= KGlobal::iconLoader()->loadIcon( "eraser", K3Icon::Small );
00151     d->m_authorUi->pbDelete->setIcon( QIcon( p ) );
00152 
00153     d->m_authorUi->leFullName->setText( d->m_info->authorInfo( "creator" ) );
00154     d->m_authorUi->leInitials->setText( d->m_info->authorInfo( "initial" ) );
00155     d->m_authorUi->leTitle->setText( d->m_info->authorInfo( "author-title" ) );
00156     d->m_authorUi->leCompany->setText( d->m_info->authorInfo( "company" ) );
00157     d->m_authorUi->leEmail->setText( d->m_info->authorInfo( "email" ) );
00158     d->m_authorUi->lePhoneWork->setText( d->m_info->authorInfo( "telephone-work" ) );
00159     d->m_authorUi->lePhoneHome->setText( d->m_info->authorInfo( "telephone" ) );
00160     d->m_authorUi->leFax->setText( d->m_info->authorInfo( "fax" ) );
00161     d->m_authorUi->leCountry->setText( d->m_info->authorInfo( "country" ) );
00162     d->m_authorUi->lePostal->setText( d->m_info->authorInfo( "postal-code" ) );
00163     d->m_authorUi->leCity->setText( d->m_info->authorInfo( "city" ) );
00164     d->m_authorUi->leStreet->setText( d->m_info->authorInfo( "street" ) );
00165     d->m_authorUi->lePosition->setText( d->m_info->authorInfo( "position" ) );
00166 
00167     connect( d->m_authorUi->pbLoadKABC, SIGNAL( clicked() ),
00168             this, SLOT( slotLoadFromKABC() ) );
00169     connect( d->m_authorUi->pbDelete, SIGNAL( clicked() ),
00170             this, SLOT( slotDeleteAuthorInfo() ) );
00171 }
00172 
00173 void KoDocumentInfoDlg::slotApply()
00174 {
00175     saveAboutData();
00176     saveAuthorData();
00177 }
00178 
00179 void KoDocumentInfoDlg::saveAboutData()
00180 {
00181     d->m_info->setAboutInfo( "keyword", d->m_aboutUi->leKeywords->text() );
00182     d->m_info->setAboutInfo( "title", d->m_aboutUi->leTitle->text() );
00183     d->m_info->setAboutInfo( "subject", d->m_aboutUi->leSubject->text() );
00184     d->m_info->setAboutInfo( "comments", d->m_aboutUi->meComments->toPlainText() );
00185 }
00186 
00187 void KoDocumentInfoDlg::saveAuthorData()
00188 {
00189     d->m_info->setAuthorInfo( "creator", d->m_authorUi->leFullName->text() );
00190     d->m_info->setAuthorInfo( "initial", d->m_authorUi->leInitials->text() );
00191     d->m_info->setAuthorInfo( "title", d->m_authorUi->leTitle->text() );
00192     d->m_info->setAuthorInfo( "company", d->m_authorUi->leCompany->text() );
00193     d->m_info->setAuthorInfo( "email", d->m_authorUi->leEmail->text() );
00194     d->m_info->setAuthorInfo( "telephone-work", d->m_authorUi->lePhoneWork->text() );
00195     d->m_info->setAuthorInfo( "telephone", d->m_authorUi->lePhoneHome->text() );
00196     d->m_info->setAuthorInfo( "fax", d->m_authorUi->leFax->text() );
00197     d->m_info->setAuthorInfo( "country", d->m_authorUi->leCountry->text() );
00198     d->m_info->setAuthorInfo( "postal-code", d->m_authorUi->lePostal->text() );
00199     d->m_info->setAuthorInfo( "city", d->m_authorUi->leCity->text() );
00200     d->m_info->setAuthorInfo( "street", d->m_authorUi->leStreet->text() );
00201     d->m_info->setAuthorInfo( "position", d->m_authorUi->lePosition->text() );
00202 
00203     KConfig* config = KoGlobal::kofficeConfig();
00204     KConfigGroup cgs( config, "Author" );
00205     config->writeEntry("telephone", d->m_authorUi->lePhoneHome->text());
00206     config->writeEntry("telephone-work", d->m_authorUi->lePhoneWork->text());
00207     config->writeEntry("fax", d->m_authorUi->leFax->text());
00208     config->writeEntry("country",d->m_authorUi->leCountry->text());
00209     config->writeEntry("postal-code",d->m_authorUi->lePostal->text());
00210     config->writeEntry("city",  d->m_authorUi->leCity->text());
00211     config->writeEntry("street", d->m_authorUi->leStreet->text());
00212     config->sync();
00213 }
00214 
00215 void KoDocumentInfoDlg::slotResetMetaData()
00216 {
00217     d->m_info->resetMetaData();
00218 
00219     if ( !d->m_info->aboutInfo( "creation-date" ).isEmpty() )
00220     {
00221         QDateTime t = QDateTime::fromString( d->m_info->aboutInfo( "creation-date" ),
00222                 Qt::ISODate );
00223         QString s = KGlobal::locale()->formatDateTime( t );
00224         d->m_aboutUi->lblCreated->setText( s + ", " +
00225                 d->m_info->aboutInfo( "initial-creator" ) );
00226     }
00227 
00228     if ( !d->m_info->aboutInfo( "date" ).isEmpty() )
00229     {
00230         QDateTime t = QDateTime::fromString( d->m_info->aboutInfo( "date" ), Qt::ISODate );
00231         QString s = KGlobal::locale()->formatDateTime( t );
00232         d->m_aboutUi->lblModified->setText( s + ", " + d->m_info->authorInfo( "creator" ) );
00233     }
00234 
00235     d->m_aboutUi->lblRevision->setText( d->m_info->aboutInfo( "editing-cycles" ) );
00236 }
00237 
00238 void KoDocumentInfoDlg::slotDeleteAuthorInfo()
00239 {
00240     d->m_authorUi->leFullName->clear();
00241     d->m_authorUi->leInitials->clear();
00242     d->m_authorUi->leTitle->clear();
00243     d->m_authorUi->leCompany->clear();
00244     d->m_authorUi->leEmail->clear();
00245     d->m_authorUi->lePhoneHome->clear();
00246     d->m_authorUi->lePhoneWork->clear();
00247     d->m_authorUi->leFax->clear();
00248     d->m_authorUi->leCountry->clear();
00249     d->m_authorUi->lePostal->clear();
00250     d->m_authorUi->leCity->clear();
00251     d->m_authorUi->leStreet->clear();
00252 }
00253 
00254 void KoDocumentInfoDlg::slotLoadFromKABC()
00255 {
00256     KABC::StdAddressBook *ab = static_cast<KABC::StdAddressBook*>
00257         ( KABC::StdAddressBook::self() );
00258     if ( !ab )
00259         return;
00260 
00261     KABC::Addressee addr = ab->whoAmI();
00262     if ( addr.isEmpty() )
00263     {
00264         KMessageBox::sorry( 0L, i18n( "No personal contact data set, please use the option \
00265                     \"Set as Personal Contact Data\" from the \"Edit\"     menu in KAddressbook to set one." ) );
00266         return;
00267     }
00268 
00269     d->m_authorUi->leFullName->setText( addr.formattedName() );
00270     d->m_authorUi->leInitials->setText( addr.givenName()[ 0 ] + ". " +
00271             addr.familyName()[ 0 ] + '.' );
00272     d->m_authorUi->leTitle->setText( addr.title() );
00273     d->m_authorUi->leCompany->setText( addr.organization() );
00274     d->m_authorUi->leEmail->setText( addr.preferredEmail() );
00275 
00276     KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Home );
00277     d->m_authorUi->lePhoneHome->setText( phone.number() );
00278     phone = addr.phoneNumber( KABC::PhoneNumber::Work );
00279     d->m_authorUi->lePhoneWork->setText( phone.number() );
00280 
00281     phone = addr.phoneNumber( KABC::PhoneNumber::Fax );
00282     d->m_authorUi->leFax->setText( phone.number() );
00283 
00284     KABC::Address a = addr.address( KABC::Address::Home );
00285     d->m_authorUi->leCountry->setText( a.country() );
00286     d->m_authorUi->lePostal->setText( a.postalCode() );
00287     d->m_authorUi->leCity->setText( a.locality() );
00288     d->m_authorUi->leStreet->setText( a.street() );
00289 }
00290 
00291 #include "KoDocumentInfoDlg.moc"

Généré le Wed Nov 22 23:41:02 2006 pour KPlato par  doxygen 1.5.1-p1