kword

kwmailmerge_kspread_config.cpp

00001 /*
00002    This file is part of the KDE project
00003    Copyright (C) 2004 Tobias Koenig <tokoe@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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 
00025 #include <kcombobox.h>
00026 #include <klineedit.h>
00027 #include <klocale.h>
00028 #include <kurlrequester.h>
00029 
00030 #include <kspread_map.h>
00031 
00032 #include "kwmailmerge_kspread.h"
00033 #include "kwmailmerge_kspread_config.h"
00034 
00035 using namespace KSpread;
00036 
00037 KWMailMergeKSpreadConfig::KWMailMergeKSpreadConfig( QWidget *parent, KWMailMergeKSpread *object )
00038   : KDialogBase( Plain, i18n( "Mail Merge - Editor" ),
00039                  Ok | Cancel, Ok, parent, "", true ),
00040     _document( 0 ), _initialPage( 1 )
00041 {
00042   _object = object;
00043 
00044   initGUI();
00045 
00046   _urlRequester->setURL( _object->url().url() );
00047   _initialPage = _object->spreadSheetNumber();
00048 
00049   connect( _urlRequester, SIGNAL( urlSelected( const QString& ) ),
00050            SLOT( loadDocument() ) );
00051 
00052   loadDocument();
00053   slotTextChanged( _urlRequester->lineEdit()->text() );
00054 }
00055 
00056 
00057 KWMailMergeKSpreadConfig::~KWMailMergeKSpreadConfig()
00058 {
00059 }
00060 
00061 void KWMailMergeKSpreadConfig::slotOk()
00062 {
00063   _object->setURL( _urlRequester->url() );
00064   _object->setSpreadSheetNumber( _pageNumber->currentText().toInt() );
00065 
00066   KDialogBase::slotOk();
00067 }
00068 
00069 void KWMailMergeKSpreadConfig::loadDocument()
00070 {
00071   delete _document;
00072   _document = 0;
00073 
00074   _pageNumber->setEnabled( false );
00075 
00076   if ( !_urlRequester->url().isEmpty() ) {
00077     _document = new Doc();
00078     connect( _document, SIGNAL( completed() ), SLOT( documentLoaded() ) );
00079 
00080     _document->openURL( _urlRequester->url() );
00081   }
00082 }
00083 
00084 void KWMailMergeKSpreadConfig::documentLoaded()
00085 {
00086   _pageNumber->clear();
00087 
00088   QPtrListIterator<Sheet> it( _document->map()->sheetList() );
00089   int counter = 1;
00090   for ( it.toFirst(); it.current(); ++it ) {
00091     _pageNumber->insertItem( QString::number( counter ) );
00092     counter++;
00093   }
00094 
00095   _pageNumber->setEnabled( true );
00096   _pageNumber->setCurrentText( QString::number( _initialPage ) );
00097 }
00098 
00099 void KWMailMergeKSpreadConfig::initGUI()
00100 {
00101   QFrame *page = plainPage();
00102 
00103   QGridLayout *layout = new QGridLayout( page, 2, 2, marginHint(), spacingHint() );
00104 
00105   QLabel *label = new QLabel( i18n( "URL:" ), page );
00106   layout->addWidget( label, 0, 0 );
00107 
00108   _urlRequester = new KURLRequester( page );
00109   layout->addWidget( _urlRequester, 0, 1 );
00110 
00111   label = new QLabel( i18n( "Page number:" ), page );
00112   layout->addWidget( label, 1, 0 );
00113 
00114   _pageNumber = new KComboBox( page );
00115   _pageNumber->setEnabled( false );
00116   layout->addWidget( _pageNumber, 1, 1 );
00117   connect( _urlRequester->lineEdit() , SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotTextChanged( const QString & ) ) );
00118 }
00119 
00120 void KWMailMergeKSpreadConfig::slotTextChanged( const QString & _text )
00121 {
00122     enableButtonOK( !_text.isEmpty() );
00123 }
00124 
00125 #include "kwmailmerge_kspread_config.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys