kword

kwmailmerge_kspread_config.cpp
1/*
2 This file is part of the KDE project
3 Copyright (C) 2004 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21
22#include <tqlabel.h>
23#include <tqlayout.h>
24
25#include <kcombobox.h>
26#include <klineedit.h>
27#include <tdelocale.h>
28#include <kurlrequester.h>
29
30#include <kspread_map.h>
31
32#include "kwmailmerge_kspread.h"
33#include "kwmailmerge_kspread_config.h"
34
35using namespace KSpread;
36
37KWMailMergeKSpreadConfig::KWMailMergeKSpreadConfig( TQWidget *parent, KWMailMergeKSpread *object )
38 : KDialogBase( Plain, i18n( "Mail Merge - Editor" ),
39 Ok | Cancel, Ok, parent, "", true ),
40 _document( 0 ), _initialPage( 1 )
41{
42 _object = object;
43
44 initGUI();
45
46 _urlRequester->setURL( _object->url().url() );
47 _initialPage = _object->spreadSheetNumber();
48
49 connect( _urlRequester, TQ_SIGNAL( urlSelected( const TQString& ) ),
50 TQ_SLOT( loadDocument() ) );
51
52 loadDocument();
53 slotTextChanged( _urlRequester->lineEdit()->text() );
54}
55
56
57KWMailMergeKSpreadConfig::~KWMailMergeKSpreadConfig()
58{
59}
60
61void KWMailMergeKSpreadConfig::slotOk()
62{
63 _object->setURL( _urlRequester->url() );
64 _object->setSpreadSheetNumber( _pageNumber->currentText().toInt() );
65
66 KDialogBase::slotOk();
67}
68
69void KWMailMergeKSpreadConfig::loadDocument()
70{
71 delete _document;
72 _document = 0;
73
74 _pageNumber->setEnabled( false );
75
76 if ( !_urlRequester->url().isEmpty() ) {
77 _document = new Doc();
78 connect( _document, TQ_SIGNAL( completed() ), TQ_SLOT( documentLoaded() ) );
79
80 _document->openURL( _urlRequester->url() );
81 }
82}
83
84void KWMailMergeKSpreadConfig::documentLoaded()
85{
86 _pageNumber->clear();
87
88 TQPtrListIterator<Sheet> it( _document->map()->sheetList() );
89 int counter = 1;
90 for ( it.toFirst(); it.current(); ++it ) {
91 _pageNumber->insertItem( TQString::number( counter ) );
92 counter++;
93 }
94
95 _pageNumber->setEnabled( true );
96 _pageNumber->setCurrentText( TQString::number( _initialPage ) );
97}
98
99void KWMailMergeKSpreadConfig::initGUI()
100{
101 TQFrame *page = plainPage();
102
103 TQGridLayout *layout = new TQGridLayout( page, 2, 2, marginHint(), spacingHint() );
104
105 TQLabel *label = new TQLabel( i18n( "URL:" ), page );
106 layout->addWidget( label, 0, 0 );
107
108 _urlRequester = new KURLRequester( page );
109 layout->addWidget( _urlRequester, 0, 1 );
110
111 label = new TQLabel( i18n( "Page number:" ), page );
112 layout->addWidget( label, 1, 0 );
113
114 _pageNumber = new KComboBox( page );
115 _pageNumber->setEnabled( false );
116 layout->addWidget( _pageNumber, 1, 1 );
117 connect( _urlRequester->lineEdit() , TQ_SIGNAL( textChanged ( const TQString & ) ), this, TQ_SLOT( slotTextChanged( const TQString & ) ) );
118}
119
120void KWMailMergeKSpreadConfig::slotTextChanged( const TQString & _text )
121{
122 enableButtonOK( !_text.isEmpty() );
123}
124
125#include "kwmailmerge_kspread_config.moc"