kpresenter
KPrImportStyleDia.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <klocale.h>
00022 #include "KPrDocument.h"
00023 #include <qvbox.h>
00024 #include <qlayout.h>
00025 #include <qlineedit.h>
00026 #include <qpushbutton.h>
00027 #include <qlistbox.h>
00028 #include <kmessagebox.h>
00029 #include "KPrImportStyleDia.h"
00030 #include <KoStore.h>
00031 #include <qfile.h>
00032 #include <kfiledialog.h>
00033 #include <kdebug.h>
00034 #include <qlabel.h>
00035 #include "KPrTextObject.h"
00036
00037 KPrImportStyleDia::KPrImportStyleDia( KPrDocument *_doc, KoStyleCollection* currentCollection,
00038 QWidget *parent, const char *name )
00039 :KoImportStyleDia( currentCollection, parent, name ),
00040 m_doc(_doc)
00041 {
00042 }
00043
00044 KPrImportStyleDia::~KPrImportStyleDia()
00045 {
00046 }
00047
00048 void KPrImportStyleDia::loadFile()
00049 {
00050 KFileDialog fd( QString::null, QString::null, 0, 0, TRUE );
00051 QStringList lst = "application/x-kpresenter";
00052 #if 0 //For the future
00053 lst << "application/vnd.oasis.opendocument.presentation";
00054 #endif
00055 fd.setMimeFilter( lst );
00056 fd.setCaption(i18n("Import Style"));
00057 KURL url;
00058 if ( fd.exec() != QDialog::Accepted )
00059 return;
00060 url = fd.selectedURL();
00061 if( url.isEmpty() )
00062 {
00063 KMessageBox::sorry( this,
00064 i18n("File name is empty."),
00065 i18n("Import Style"));
00066 return;
00067 }
00068 QMap<QString, QString>insertStyle;
00069 KoStore* store=KoStore::createStore( this, url.path(), KoStore::Read );
00070 if (store )
00071 {
00072 if (store->open("maindoc.xml") )
00073 {
00074 clear();
00075 m_listStyleName->clear();
00076
00077 QDomDocument doc;
00078 doc.setContent( store->device() );
00079 QDomElement word = doc.documentElement();
00080
00081 QDomElement stylesElem = word.namedItem( "STYLES" ).toElement();
00082 if ( !stylesElem.isNull() )
00083 {
00084
00085
00086 QValueList<QString> followingStyles;
00087 QDomNodeList listStyles = stylesElem.elementsByTagName( "STYLE" );
00088 for (unsigned int item = 0; item < listStyles.count(); item++)
00089 {
00090 QDomElement styleElem = listStyles.item( item ).toElement();
00091
00092 KoParagStyle *sty = new KoParagStyle( QString::null );
00093
00094 sty->loadStyle( styleElem );
00095
00096 if ( currentCollection()->findStyle( sty->name() ) )
00097 sty->setName(generateStyleName(sty->name() + "-%1"));
00098 QString name = sty->displayName();
00099
00100
00101 if ( currentCollection()->findStyleByDisplayName( name ) )
00102 sty->setDisplayName(generateStyleDisplayName(sty->displayName() + "-%1"));
00103 insertStyle.insert( name, sty->name() );
00104
00105 QDomElement formatElem = styleElem.namedItem( "FORMAT" ).toElement();
00106 if ( !formatElem.isNull() )
00107 sty->format() = KPrTextObject::loadFormat( formatElem, 0L, m_doc->defaultFont(),
00108 m_doc->globalLanguage(), m_doc->globalHyphenation() );
00109 else
00110 kdWarning(33001) << "No FORMAT tag in <STYLE>" << endl;
00111
00112
00113
00114 sty = m_styleList.addStyle(sty);
00115
00116 if( m_styleList.count() >= 0 && uint( m_styleList.count() ) > followingStyles.count() )
00117 {
00118 QString following = styleElem.namedItem("FOLLOWING").toElement().attribute("name");
00119 followingStyles.append( following );
00120 }
00121 else
00122 kdWarning(33001) << "Found duplicate style declaration, overwriting former " << sty->name() << endl;
00123 }
00124
00125 Q_ASSERT( m_styleList.count() >= 0 && followingStyles.count() == uint( m_styleList.count() ) );
00126
00127 unsigned int i=0;
00128 for( QValueList<QString>::Iterator it = followingStyles.begin(); it != followingStyles.end(); ++it ) {
00129 QString newName =*it;
00130 if ( insertStyle.contains( *it ) )
00131 newName = (insertStyle)[ *it ];
00132
00133 KoParagStyle * style = m_styleList.findStyle(newName);
00134 if ( style )
00135 m_styleList.styleAt(i++)->setFollowingStyle( style );
00136 }
00137
00138 }
00139 initList();
00140 }
00141 else if ( store->hasFile( "content.xml" ) )
00142 {
00143
00144 }
00145 else
00146 {
00147 KMessageBox::error( this,
00148 i18n("File is not a KPresenter file!"),
00149 i18n("Import Style"));
00150 }
00151 store->close();
00152 }
00153 delete store;
00154 }
00155
00156
00157 #include "KPrImportStyleDia.moc"
|