21#include "KPrDocument.h"
24#include <tqlineedit.h>
25#include <tqpushbutton.h>
27#include <tdemessagebox.h>
28#include "KPrImportStyleDia.h"
31#include <tdefiledialog.h>
34#include "KPrTextObject.h"
36KPrImportStyleDia::KPrImportStyleDia( KPrDocument *_doc, KoStyleCollection* currentCollection,
37 TQWidget *parent,
const char *name )
38 :KoImportStyleDia( currentCollection, parent, name ),
43KPrImportStyleDia::~KPrImportStyleDia()
47void KPrImportStyleDia::loadFile()
49 KFileDialog fd( TQString(), TQString(), 0, 0,
true );
50 TQStringList lst =
"application/x-kpresenter";
52 lst <<
"application/vnd.oasis.opendocument.presentation";
54 fd.setMimeFilter( lst );
55 fd.setCaption(i18n(
"Import Style"));
57 if ( fd.exec() != TQDialog::Accepted )
59 url = fd.selectedURL();
62 KMessageBox::sorry(
this,
63 i18n(
"File name is empty."),
64 i18n(
"Import Style"));
67 TQMap<TQString, TQString>insertStyle;
68 KoStore* store=KoStore::createStore(
this, url.path(), KoStore::Read );
71 if (store->open(
"maindoc.xml") )
74 m_listStyleName->clear();
77 doc.setContent( store->device() );
78 TQDomElement word = doc.documentElement();
80 TQDomElement stylesElem = word.namedItem(
"STYLES" ).toElement();
81 if ( !stylesElem.isNull() )
85 TQValueList<TQString> followingStyles;
86 TQDomNodeList listStyles = stylesElem.elementsByTagName(
"STYLE" );
87 for (
unsigned int item = 0; item < listStyles.count(); item++)
89 TQDomElement styleElem = listStyles.item( item ).toElement();
91 KoParagStyle *sty =
new KoParagStyle( TQString() );
93 sty->loadStyle( styleElem );
95 if ( currentCollection()->findStyle( sty->name() ) )
96 sty->setName(generateStyleName(sty->name() +
"-%1"));
97 TQString name = sty->displayName();
100 if ( currentCollection()->findStyleByDisplayName( name ) )
101 sty->setDisplayName(generateStyleDisplayName(sty->displayName() +
"-%1"));
102 insertStyle.insert( name, sty->name() );
104 TQDomElement formatElem = styleElem.namedItem(
"FORMAT" ).toElement();
105 if ( !formatElem.isNull() )
106 sty->format() = KPrTextObject::loadFormat( formatElem, 0L, m_doc->defaultFont(),
107 m_doc->globalLanguage(), m_doc->globalHyphenation() );
109 kdWarning(33001) <<
"No FORMAT tag in <STYLE>" << endl;
113 sty = m_styleList.addStyle(sty);
115 if( m_styleList.count() >= 0 && uint( m_styleList.count() ) > followingStyles.count() )
117 TQString following = styleElem.namedItem(
"FOLLOWING").toElement().attribute(
"name");
118 followingStyles.append( following );
121 kdWarning(33001) <<
"Found duplicate style declaration, overwriting former " << sty->name() << endl;
124 Q_ASSERT( m_styleList.count() >= 0 && followingStyles.count() == uint( m_styleList.count() ) );
127 for( TQValueList<TQString>::Iterator it = followingStyles.begin(); it != followingStyles.end(); ++it ) {
128 TQString newName =*it;
129 if ( insertStyle.contains( *it ) )
130 newName = (insertStyle)[ *it ];
132 KoParagStyle * style = m_styleList.findStyle(newName);
134 m_styleList.styleAt(i++)->setFollowingStyle( style );
140 else if ( store->hasFile(
"content.xml" ) )
146 KMessageBox::error(
this,
147 i18n(
"File is not a KPresenter file!"),
148 i18n(
"Import Style"));
156#include "KPrImportStyleDia.moc"