21#include "KWDocument.h"
25#include <tqlineedit.h>
26#include <tqpushbutton.h>
28#include <tdemessagebox.h>
29#include "KWImportStyleDia.h"
33#include <tdefiledialog.h>
37#include "KWTextParag.h"
39KWImportStyleDia::KWImportStyleDia( KWDocument *_doc, KoStyleCollection* currentCollection, TQWidget *parent,
const char *name )
40 :KoImportStyleDia( currentCollection, parent, name ),
46KWImportStyleDia::~KWImportStyleDia()
51void KWImportStyleDia::loadFile()
53 KFileDialog fd( TQString(), TQString(), 0, 0,
true );
54 TQStringList lst =
"application/x-kword";
56 lst <<
"application/vnd.oasis.opendocument.text";
58 fd.setMimeFilter( lst );
59 fd.setCaption(i18n(
"Import Style"));
61 if ( fd.exec() != TQDialog::Accepted )
63 url = fd.selectedURL();
66 KMessageBox::sorry(
this,
67 i18n(
"File name is empty."),
68 i18n(
"Import Style"));
71 TQMap<TQString, TQString>insertStyle;
73 KoStore* store=KoStore::createStore(
this, url, KoStore::Read );
76 if (store->open(
"maindoc.xml") )
79 m_listStyleName->clear();
82 doc.setContent( store->device() );
83 TQDomElement word = doc.documentElement();
84 TQDomElement stylesElem = word.namedItem(
"STYLES" ).toElement();
85 if ( !stylesElem.isNull() )
95 TQValueList<TQString> followingStyles;
96 TQDomNodeList listStyles = stylesElem.elementsByTagName(
"STYLE" );
97 for (
unsigned int item = 0; item < listStyles.count(); item++)
99 TQDomElement styleElem = listStyles.item( item ).toElement();
101 KoParagStyle *sty =
new KoParagStyle( TQString() );
103 sty->loadStyle( styleElem, m_doc->syntaxVersion() );
105 TQString name = sty->displayName();
106 if ( currentCollection()->findStyle( name ) )
107 sty->setName(generateStyleName(sty->name() +
"-%1"));
110 if ( currentCollection()->findStyleByDisplayName( name ) )
111 sty->setDisplayName(generateStyleDisplayName(sty->displayName() +
"-%1"));
112 insertStyle.insert( name, sty->name() );
114 TQDomElement formatElem = styleElem.namedItem(
"FORMAT" ).toElement();
115 if ( !formatElem.isNull() )
116 sty->format() =
KWTextParag::loadFormat( formatElem, 0L, m_doc->defaultFont(), m_doc->globalLanguage(), m_doc->globalHyphenation() );
118 kdWarning(32001) <<
"No FORMAT tag in <STYLE>" << endl;
121 sty = m_styleList.addStyle(sty);
123 if( m_styleList.count() >= 0 && uint( m_styleList.count() ) > followingStyles.count() )
125 TQString following = styleElem.namedItem(
"FOLLOWING").toElement().attribute(
"name");
126 followingStyles.append( following );
129 kdWarning () <<
"Found duplicate style declaration, overwriting former " << sty->name() << endl;
132 Q_ASSERT( m_styleList.count() >= 0 && followingStyles.count() == uint( m_styleList.count() ) );
135 for( TQValueList<TQString>::Iterator it = followingStyles.begin(); it != followingStyles.end(); ++it ) {
136 TQString newName =*it;
137 if ( insertStyle.contains( *it ) )
138 newName = (insertStyle)[ *it ];
140 KoParagStyle * style = m_styleList.findStyle(newName);
142 m_styleList.styleAt(i++)->setFollowingStyle( style );
147 if(m_styleList.count() == 0) {
148 KMessageBox::error(
this,
149 i18n(
"File does not contain any styles. It may be the wrong version."),
150 i18n(
"Import Style"));
154 else if ( store->hasFile(
"content.xml" ) )
160 KMessageBox::error(
this,
161 i18n(
"This file is not a KWord file!"),
162 i18n(
"Import Style"));
169KWImportFrameTableStyleDia::KWImportFrameTableStyleDia( KWDocument *_doc,
const TQStringList &_list, StyleType _type, TQWidget *parent,
const char *name )
170 : KDialogBase( parent, name , true,
"", Ok|Cancel, Ok, true )
172 setCaption( i18n(
"Import Style") );
176 TQVBox *page = makeVBoxMainWidget();
177 new TQLabel(i18n(
"Select style to import:"), page);
178 m_listStyleName =
new TQListBox( page );
179 m_listStyleName->setSelectionMode( TQListBox::Multi );
185KWImportFrameTableStyleDia::~KWImportFrameTableStyleDia()
187 m_frameStyleList.setAutoDelete(
true);
188 m_tableStyleList.setAutoDelete(
true);
189 m_frameStyleList.clear();
190 m_tableStyleList.clear();
193TQString KWImportFrameTableStyleDia::generateStyleName(
const TQString & templateName )
199 name = templateName.arg( num );
200 exists = (m_list.findIndex( name )!=-1);
207void KWImportFrameTableStyleDia::loadFile()
209 KFileDialog fd( TQString(), TQString(), 0, 0,
true );
210 TQStringList lst =
"application/x-kword";
212 lst <<
"application/vnd.oasis.opendocument.text";
214 fd.setMimeFilter( lst );
215 fd.setCaption(i18n(
"Import Style"));
217 if ( fd.exec() != TQDialog::Accepted )
219 url = fd.selectedURL();
222 KMessageBox::sorry(
this,
223 i18n(
"File name is empty."),
224 i18n(
"Import Style"));
227 KoStore* store=KoStore::createStore(
this, url, KoStore::Read );
230 if (store->open(
"maindoc.xml") )
233 doc.setContent( store->device() );
234 TQDomElement word = doc.documentElement();
235 if ( m_typeStyle ==frameStyle )
237 TQDomNodeList listStyles = word.elementsByTagName(
"FRAMESTYLE" );
238 for (
unsigned int item = 0; item < listStyles.count(); item++) {
239 TQDomElement styleElem = listStyles.item( item ).toElement();
241 KWFrameStyle *sty =
new KWFrameStyle( styleElem );
242 TQString name =sty->name();
243 if ( m_list.findIndex( name )!=-1 )
244 sty->setDisplayName(generateStyleName( sty->displayName() + TQString(
"-%1")));
245 m_frameStyleList.append( sty);
250 TQDomNodeList listStyles = word.elementsByTagName(
"TABLESTYLE" );
251 for (
unsigned int item = 0; item < listStyles.count(); item++) {
252 TQDomElement styleElem = listStyles.item( item ).toElement();
253 KWTableStyle *sty =
new KWTableStyle( styleElem,m_doc,2 );
254 TQString name =sty->name();
255 if ( m_list.findIndex( name )!=-1 )
256 sty->setName(generateStyleName( sty->displayName() + TQString(
"-%1")));
257 m_tableStyleList.append( sty);
261 if(m_tableStyleList.count() == 0 && m_frameStyleList.count()==0) {
262 KMessageBox::error(
this,
263 i18n(
"File does not contain any styles. It may be the wrong version."),
264 i18n(
"Import Style"));
268 else if ( store->hasFile(
"content.xml" ) )
274 KMessageBox::error(
this,
275 i18n(
"This file is not a KWord file!"),
276 i18n(
"Import Style"));
285void KWImportFrameTableStyleDia::initList()
288 if ( m_typeStyle ==frameStyle )
290 for ( KWFrameStyle * p = m_frameStyleList.first(); p != 0L; p = m_frameStyleList.next() )
292 lst<<p->displayName();
297 for ( KWTableStyle * p = m_tableStyleList.first(); p != 0L; p = m_tableStyleList.next() )
299 lst<<p->displayName();
303 m_listStyleName->insertStringList(lst);
306void KWImportFrameTableStyleDia::slotOk()
308 for (uint i = 0; i< m_listStyleName->count();i++)
310 if ( !m_listStyleName->isSelected( i ))
312 TQString name = m_listStyleName->text(i );
313 if ( m_typeStyle ==frameStyle )
316 TQPtrListIterator<KWFrameStyle> styleIt( m_frameStyleList );
317 for ( ; styleIt.current(); ++styleIt )
319 if ( styleIt.current()->displayName() == name )
321 m_frameStyleList.remove(styleIt.current());
329 TQPtrListIterator<KWTableStyle> styleIt( m_tableStyleList );
330 for ( ; styleIt.current(); ++styleIt )
332 if ( styleIt.current()->displayName() == name )
334 m_tableStyleList.remove(styleIt.current());
341 KDialogBase::slotOk();
343#include "KWImportStyleDia.moc"
static KoTextFormat loadFormat(TQDomElement &formatElem, KoTextFormat *refFormat, const TQFont &defaultFont, const TQString &defaultLanguage, bool hyphanation)
Public for loading a style (KWord-1.3 XML).