21#include "KoDocument.h"
23#include "KoDocument_p.h"
24#include "KoDocumentIface.h"
25#include "KoDocumentChild.h"
27#include "KoMainWindow.h"
28#include "KoFilterManager.h"
29#include "KoDocumentInfo.h"
30#include "KoOasisStyles.h"
31#include "KoOasisStore.h"
33#include "KoOpenPane.h"
35#include <KoStoreDevice.h>
36#include <KoXmlWriter.h>
38#include <tdeapplication.h>
40#include <tdefileitem.h>
41#include <kiconloader.h>
43#include <tdeio/netaccess.h>
45#include <tdemessagebox.h>
47#include <tdeparts/partmanager.h>
55#include <tqfileinfo.h>
71#define STORE_PROTOCOL "tar"
74#define INTERNAL_PROTOCOL "intern"
75#define INTERNAL_PREFIX "intern:/"
78TQPtrList<KoDocument> *KoDocument::s_documentList=0L;
81class KoViewWrapperWidget;
89const int KoDocument::s_defaultAutoSave = 300;
91class KoDocument::Private
97 m_specialOutputFlag( 0 ),
98 m_isImporting( false ), m_isExporting( false ),
100 modifiedAfterAutosave( false ),
101 m_autosaving( false ),
102 m_shouldCheckAutoSaveFile( true ),
103 m_autoErrorHandlingEnabled( true ),
104 m_backupFile( true ),
105 m_backupPath( TQString() ),
106 m_doNotSaveExtDoc( false ),
108 m_storeInternal( false ),
112 m_confirmNonNativeSave[0] =
true;
113 m_confirmNonNativeSave[1] =
true;
114 if ( TDEGlobal::locale()->measureSystem() == TDELocale::Imperial ) {
115 m_unit = KoUnit::U_INCH;
117 m_unit = KoUnit::U_CM;
121 TQPtrList<KoView> m_views;
122 TQPtrList<KoDocumentChild> m_children;
123 TQPtrList<KoMainWindow> m_shells;
124 TQValueList<TQDomDocument> m_viewBuildDocuments;
126 KoViewWrapperWidget *m_wrapperWidget;
127 KoDocumentIface * m_dcopObject;
128 KoDocumentInfo *m_docInfo;
133 KoFilterManager * filterManager;
136 TQCString outputMimeType;
137 bool m_confirmNonNativeSave [2];
140 int m_specialOutputFlag;
141 bool m_isImporting, m_isExporting;
143 TQTimer m_autoSaveTimer;
144 TQString lastErrorMessage;
147 bool modifiedAfterAutosave;
148 bool m_bSingleViewMode;
150 bool m_shouldCheckAutoSaveFile;
151 bool m_autoErrorHandlingEnabled;
153 TQString m_backupPath;
154 bool m_doNotSaveExtDoc;
156 bool m_storeInternal;
159 KoOpenPane* m_startUpWidget;
160 TQString m_templateType;
164class KoViewWrapperWidget :
public TQWidget
167 KoViewWrapperWidget( TQWidget *parent,
const char *name )
168 : TQWidget( parent,
name )
170 TDEGlobal::locale()->insertCatalogue(
"koffice");
172 TDEGlobal::iconLoader()->addAppDir(
"koffice");
175 setFocusPolicy( TQWidget::ClickFocus );
178 virtual ~KoViewWrapperWidget() {
182 virtual void resizeEvent( TQResizeEvent * )
184 TQObject *wid = child( 0,
"TQWidget" );
186 static_cast<TQWidget*
>(wid)->setGeometry( 0, 0, width(), height() );
189 virtual void childEvent( TQChildEvent *ev )
191 if ( ev->type() == TQEvent::ChildInserted )
196 void setKoView( KoView * view ) {
198 setFocusProxy( m_view );
200 KoView * koView()
const {
return m_view; }
205KoBrowserExtension::KoBrowserExtension(
KoDocument * doc,
const char * name )
208 emit enableAction(
"print",
true );
211void KoBrowserExtension::print()
214 KoViewWrapperWidget * wrapper =
static_cast<KoViewWrapperWidget *
>( doc->
widget() );
215 KoView * view = wrapper->koView();
220 if ( printer.setup( view ) )
221 view->
print( printer );
224KoDocument::KoDocument( TQWidget * parentWidget,
const char *widgetName, TQObject* parent,
const char* name,
bool singleViewMode )
227 if(s_documentList==0L)
228 s_documentList=
new TQPtrList<KoDocument>;
229 s_documentList->append(
this);
233 connect( &d->m_autoSaveTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( slotAutoSave() ) );
235 d->m_bSingleViewMode = singleViewMode;
241 if ( parent->inherits(
"KoDocument" ) )
242 d->m_bSingleViewMode = ((
KoDocument *)parent)->isSingleViewMode();
243 else if ( parent->inherits(
"KParts::Part" ) )
244 d->m_bSingleViewMode =
true;
247 if ( singleViewMode )
249 d->m_wrapperWidget =
new KoViewWrapperWidget( parentWidget, widgetName );
251 kdDebug(30003) <<
"creating KoBrowserExtension" << endl;
252 (void)
new KoBrowserExtension(
this );
255 d->m_docInfo =
new KoDocumentInfo(
this,
"document info" );
257 m_pageLayout.ptWidth = 0;
258 m_pageLayout.ptHeight = 0;
259 m_pageLayout.ptTop = 0;
260 m_pageLayout.ptBottom = 0;
261 m_pageLayout.ptLeft = 0;
262 m_pageLayout.ptRight = 0;
265 if ( !singleViewMode )
266 connect(
this, TQ_SIGNAL(
started( TDEIO::Job* ) ), TQ_SLOT( slotStarted( TDEIO::Job* ) ) );
275 d->m_autoSaveTimer.stop();
277 TQPtrListIterator<KoDocumentChild> childIt( d->m_children );
278 for (; childIt.current(); ++childIt )
279 disconnect( childIt.current(), TQ_SIGNAL( destroyed() ),
280 this, TQ_SLOT( slotChildDestroyed() ) );
284 TQPtrListIterator<KoView> vIt( d->m_views );
285 for (; vIt.current(); ++vIt )
286 vIt.current()->setDocumentDeleted();
288 delete d->m_startUpWidget;
289 d->m_startUpWidget = 0;
291 d->m_children.setAutoDelete(
true );
292 d->m_children.clear();
296 delete d->m_dcopObject;
297 delete d->filterManager;
300 s_documentList->removeRef(
this);
302 if(s_documentList->isEmpty()) {
303 delete s_documentList;
310 return d->m_bSingleViewMode;
315 return dynamic_cast<KoDocument *
>( parent() ) != 0;
320 KoView *view=createViewInstance(parent, name);
329 d->m_isExporting =
true;
340 TQString oldFile =
m_file;
343 TQCString oldMimeType =
mimeType ();
354 kdDebug(30003) <<
"Restoring KoDocument state to before export" << endl;
366 d->mimeType = oldMimeType;
370 d->m_isExporting =
false;
377 kdDebug(30003) <<
"KoDocument::saveFile() doc='" <<
url().url() <<
"'"<< endl;
382 setlocale( LC_NUMERIC,
"C" );
388 TQCString outputMimeType = d->outputMimeType;
390 if ( outputMimeType.isEmpty() )
393 TQApplication::setOverrideCursor( waitCursor );
395 if ( backupFile() ) {
396 if (
url().isLocalFile() )
397 KSaveFile::backupFile(
url().path(), d->m_backupPath );
399 TDEIO::UDSEntry entry;
400 if ( TDEIO::NetAccess::stat(
url(), entry,
shells().current() ) ) {
403 if ( d->m_backupPath.isEmpty())
406 backup = d->m_backupPath +
"/"+
url().fileName();
407 backup.setPath( backup.path() + TQString::fromLatin1(
"~") );
408 KFileItem item( entry,
url() );
409 Q_ASSERT( item.name() ==
url().fileName() );
410 TDEIO::NetAccess::file_copy(
url(), backup, item.permissions(),
true ,
false ,
shells().current() );
417 bool suppressErrorDialog =
false;
419 kdDebug(30003) <<
"Saving to format " << outputMimeType <<
" in " <<
m_file << endl;
421 if ( !d->filterManager )
425 ret = status == KoFilter::OK;
426 suppressErrorDialog = (status == KoFilter::UserCancelled || status == KoFilter::BadConversionGraph );
429 Q_ASSERT( !
m_file.isEmpty() );
440 TQApplication::restoreOverrideCursor();
443 if ( !suppressErrorDialog )
466 d->mimeType = outputMimeType;
487 d->m_specialOutputFlag = specialOutputFlag;
490TQCString KoDocument::outputMimeType()
const
492 return d->outputMimeType;
495int KoDocument::specialOutputFlag()
const
497 return d->m_specialOutputFlag;
504 return d->m_confirmNonNativeSave [ exporting ? 1 : 0 ];
507void KoDocument::setConfirmNonNativeSave(
const bool exporting,
const bool on )
509 d->m_confirmNonNativeSave [ exporting ? 1 : 0] = on;
512bool KoDocument::wantExportConfirmation()
const
519 return d->m_isImporting;
524 return d->m_isExporting;
529 d->m_shouldCheckAutoSaveFile = b;
534 d->m_autoErrorHandlingEnabled = b;
539 return d->m_autoErrorHandlingEnabled;
542void KoDocument::slotAutoSave()
544 if (
isModified() && d->modifiedAfterAutosave && !d->m_bLoading )
546 connect(
this, TQ_SIGNAL(
sigProgress(
int ) ),
shells().current(), TQ_SLOT( slotProgress(
int ) ) );
548 d->m_autosaving =
true;
552 d->modifiedAfterAutosave =
false;
553 d->m_autoSaveTimer.stop();
555 d->m_autosaving =
false;
557 disconnect(
this, TQ_SIGNAL(
sigProgress(
int ) ),
shells().current(), TQ_SLOT( slotProgress(
int ) ) );
570 Q_ASSERT( d->m_bSingleViewMode );
572 if ( !d->m_views.isEmpty() )
573 return d->m_views.getFirst()->action( element );
582 Q_ASSERT( d->m_bSingleViewMode );
583 if ( d->m_views.isEmpty() )
584 return TQDomDocument();
586 return d->m_views.getFirst()->domDocument();
591 KParts::ReadWritePart::setManager(
manager );
592 if ( d->m_bSingleViewMode && d->m_views.count() == 1 )
593 d->m_views.getFirst()->setPartManager(
manager );
597 TQPtrListIterator<KoDocumentChild> it( d->m_children );
598 for (; it.current(); ++it )
599 if ( it.current()->document() )
608 TQPtrListIterator<KoView> vIt( d->m_views );
609 for (; vIt.current(); ++vIt )
610 vIt.current()->updateReadWrite( readwrite );
612 TQPtrListIterator<KoDocumentChild> dIt( d->m_children );
613 for (; dIt.current(); ++dIt )
614 if ( dIt.current()->document() )
615 dIt.current()->document()->setReadWrite( readwrite );
622 d->m_autoSaveDelay = delay;
624 d->m_autoSaveTimer.start( d->m_autoSaveDelay * 1000 );
626 d->m_autoSaveTimer.stop();
634 d->m_views.append( view );
640 d->m_views.removeRef( view );
650 return d->m_views.count();
657 d->m_children.append(
child );
660 this, TQ_SLOT( slotChildChanged(
KoChild * ) ) );
661 connect(
child, TQ_SIGNAL( destroyed() ),
662 this, TQ_SLOT( slotChildDestroyed() ) );
676void KoDocument::slotChildChanged(
KoChild *c )
678 assert( c->inherits(
"KoDocumentChild" ) );
682void KoDocument::slotChildDestroyed()
686 const KoDocumentChild *
child =
static_cast<const KoDocumentChild *
>( sender() );
687 d->m_children.removeRef(
child );
692 return d->m_children;
697 TQPtrListIterator<KoView> it( d->m_views );
698 for (; it.current(); ++it )
699 if (
static_cast<TQWidget *
>(it.current()) ==
widget )
701 KoView* view = it.current();
702 d->hitTestView = view;
703 TQPoint canvasPos( view->
canvas()->mapFromGlobal( globalPos ) );
718 return d->hitTestView;
724 TQPtrListIterator<KoDocumentChild> it( d->m_children );
725 for (; it.current(); ++it )
738 TQPtrListIterator<KoDocumentChild> it( d->m_children );
739 for (; it.current(); ++it )
740 if ( it.current()->document() == doc )
751void KoDocument::setViewBuildDocument(
KoView *view,
const TQDomDocument &doc )
753 if ( d->m_views.find( view ) == -1 )
756 uint viewIdx = d->m_views.at();
758 if ( d->m_viewBuildDocuments.count() == viewIdx )
759 d->m_viewBuildDocuments.append( doc );
760 else if ( d->m_viewBuildDocuments.count() > viewIdx )
761 d->m_viewBuildDocuments[ viewIdx ] = doc;
764TQDomDocument KoDocument::viewBuildDocument(
KoView *view )
768 if ( d->m_views.find( view ) == -1 )
771 uint viewIdx = d->m_views.at();
773 if ( viewIdx >= d->m_viewBuildDocuments.count() )
776 res = d->m_viewBuildDocuments[ viewIdx ];
779 d->m_viewBuildDocuments[ viewIdx ] = TQDomDocument();
786 paintContent( painter, rect, transparent, zoomX, zoomY );
792 TQPtrListIterator<KoDocumentChild> it( d->m_children );
793 for (; it.current(); ++it )
797 paintChild( it.current(), painter, view, zoomX, zoomY );
804 if (
child->isDeleted() )
809 child->transform( painter );
810 child->document()->paintEverything( painter,
child->contentRect(),
child->isTransparent(), view, zoomX, zoomY );
812 if ( view && view->partManager() )
817 painter.scale( 1.0 /
child->xScaling(), 1.0 /
child->yScaling() );
819 int w = int( (
double)
child->contentRect().width() *
child->xScaling() );
820 int h = int( (
double)
child->contentRect().height() *
child->yScaling() );
822 manager->selectedWidget() == (TQWidget *)view ) ||
824 manager->activeWidget() == (TQWidget *)view ) )
827 painter.setClipping(
false );
829 painter.setPen( black );
830 painter.fillRect( -5, -5, w + 10, 5, white );
831 painter.fillRect( -5, h, w + 10, 5, white );
832 painter.fillRect( -5, -5, 5, h + 10, white );
833 painter.fillRect( w, -5, 5, h + 10, white );
834 painter.fillRect( -5, -5, w + 10, 5, BDiagPattern );
835 painter.fillRect( -5, h, w + 10, 5, BDiagPattern );
836 painter.fillRect( -5, -5, 5, h + 10, BDiagPattern );
837 painter.fillRect( w, -5, 5, h + 10, BDiagPattern );
840 manager->selectedWidget() == (TQWidget *)view )
843 if ( view->koDocument() ==
this )
847 painter.fillRect( -5, -5, 5, 5, color );
848 painter.fillRect( -5, h, 5, 5, color );
849 painter.fillRect( w, h, 5, 5, color );
850 painter.fillRect( w, -5, 5, 5, color );
851 painter.fillRect( w / 2 - 3, -5, 5, 5, color );
852 painter.fillRect( w / 2 - 3, h, 5, 5, color );
853 painter.fillRect( -5, h / 2 - 3, 5, 5, color );
854 painter.fillRect( w, h / 2 - 3, 5, 5, color );
857 painter.setClipping(
true );
870 TQPtrListIterator<KoDocumentChild> it =
children();
871 for (; it.current(); ++it )
884 TQPtrListIterator<KoDocumentChild> it(
children() );
885 for( ; it.current(); ++it ) {
886 KoDocument* childDoc = it.current()->document();
887 if (childDoc && !it.current()->isDeleted())
892 if ( !childDoc->
saveToStore( _store, TQString::number( i++ ) ) )
907 TQPtrListIterator<KoDocumentChild> it(
children() );
908 for( ; it.current(); ++it ) {
909 KoDocument* childDoc = it.current()->document();
910 if ( childDoc && !it.current()->isDeleted() )
912 if ( !it.current()->saveOasis( store, manifestWriter ) )
923 if ( d->m_doNotSaveExtDoc )
926 d->m_doNotSaveExtDoc =
false;
932 TQPtrListIterator<KoDocumentChild> it =
children();
933 for (; (ch = it.current()); ++it )
935 if ( !ch->isDeleted() )
940 kdDebug(30003)<<
" save external doc='"<<
url().url()<<
"'"<<endl;
956 d->lastErrorMessage = TQString();
959 KoStore::Backend backend = KoStore::Auto;
961 if ( d->m_specialOutputFlag == SaveAsKOffice1dot1 )
963 kdDebug(30003) <<
"Saving as KOffice-1.1 format, using a tar.gz" << endl;
964 backend = KoStore::Tar;
969 if ( d->m_specialOutputFlag == SaveAsDirectoryStore )
971 backend = KoStore::Directory;
972 kdDebug(30003) <<
"Saving as uncompressed XML, using directory store." << endl;
974 else if ( d->m_specialOutputFlag == SaveAsFlatXML )
976 kdDebug(30003) <<
"Saving as a flat XML file." << endl;
978 if ( f.open( IO_WriteOnly | IO_Translate ) )
988 kdDebug(30003) <<
"KoDocument::saveNativeFormat nativeFormatMimeType=" <<
nativeFormatMimeType() << endl;
991 TQCString
mimeType = d->outputMimeType;
999 d->lastErrorMessage = i18n(
"Could not create the file for saving" );
1006 kdDebug(30003) <<
"Saving to OASIS format" << endl;
1012 if ( !
saveOasis( store, manifestWriter ) )
1014 kdDebug(30003) <<
"saveOasis failed" << endl;
1022 kdDebug(30003) <<
"saveChildrenOasis failed" << endl;
1027 if ( store->
open(
"meta.xml" ) )
1029 if ( !d->m_docInfo->saveOasis( store ) || !store->
close() ) {
1037 d->lastErrorMessage = i18n(
"Not able to write '%1'. Partition full?" ).arg(
"meta.xml" );
1042 if ( store->
open(
"Thumbnails/thumbnail.png" ) )
1044 if ( !saveOasisPreview( store, manifestWriter ) || !store->
close() ) {
1045 d->lastErrorMessage = i18n(
"Error while trying to write '%1'. Partition full?" ).arg(
"Thumbnails/thumbnail.png" );
1053 d->lastErrorMessage = i18n(
"Not able to write '%1'. Partition full?" ).arg(
"Thumbnails/thumbnail.png" );
1061 d->lastErrorMessage = i18n(
"Error while trying to write '%1'. Partition full?" ).arg(
"META-INF/manifest.xml" );
1073 if ( d->lastErrorMessage.isEmpty() )
1074 d->lastErrorMessage = i18n(
"Error while saving embedded documents" );
1079 kdDebug(30003) <<
"Saving root" << endl;
1080 if ( store->
open(
"root" ) )
1085 kdDebug(30003) <<
"saveToStream failed" << endl;
1092 d->lastErrorMessage = i18n(
"Not able to write '%1'. Partition full?" ).arg(
"maindoc.xml" );
1096 if ( store->
open(
"documentinfo.xml" ) )
1098 TQDomDocument doc = d->m_docInfo->save();
1101 TQCString s = doc.toCString();
1102 (void)dev.writeBlock( s.data(), s.size()-1 );
1103 (void)store->
close();
1106 if ( store->
open(
"preview.png" ) )
1109 savePreview( store );
1110 (void)store->
close();
1118 kdDebug(30003) <<
"Saving done of url: " <<
url().url() << endl;
1130 TQDomDocument doc =
saveXML();
1132 TQCString s = doc.toCString();
1135 int nwritten = dev->writeBlock( s.data(), s.size()-1 );
1136 if ( nwritten != (
int)s.size()-1 )
1137 kdWarning(30003) <<
"KoDocument::saveToStream wrote " << nwritten <<
" - expected " << s.size()-1 << endl;
1138 return nwritten == (int)s.size()-1;
1144 kdDebug(30003) <<
"Saving document to store " << _path << endl;
1147 if ( _path.startsWith( STORE_PROTOCOL ) )
1148 m_url = KURL( _path );
1150 m_url = KURL( INTERNAL_PREFIX + _path );
1161 if ( _store->
open(
"root" ) )
1169 if ( !_store->
close() )
1179 kdDebug(30003) <<
"Saved document to store" << endl;
1187 TQImage preview ( pix.convertToImage().convertDepth( 32, TQt::ColorOnly ) );
1188 if ( !preview.hasAlphaBuffer() )
1190 preview.setAlphaBuffer(
true );
1193 KoStoreDevice io ( store );
1194 if ( !io.open( IO_WriteOnly ) )
1196 if ( ! preview.save( &io,
"PNG", 0 ) )
1204bool KoDocument::savePreview(
KoStore* store )
1208 const TQImage preview ( pix.convertToImage().convertDepth( 8, TQt::AvoidDither | TQt::DiffuseDither) );
1209 KoStoreDevice io ( store );
1210 if ( !io.open( IO_WriteOnly ) )
1212 if ( ! preview.save( &io,
"PNG" ) )
1220 double docWidth, docHeight;
1221 int pixmapSize = TQMAX(size.width(), size.height());
1223 if (m_pageLayout.ptWidth > 1.0) {
1224 docWidth = m_pageLayout.ptWidth / 72 * KoGlobal::dpiX();
1225 docHeight = m_pageLayout.ptHeight / 72 * KoGlobal::dpiY();
1233 double ratio = docWidth / docHeight;
1236 int previewWidth, previewHeight;
1239 previewWidth = (int) pixmapSize;
1240 previewHeight = (int) (pixmapSize / ratio);
1244 previewWidth = (int) (pixmapSize * ratio);
1245 previewHeight = (int) pixmapSize;
1248 pix.resize((
int)docWidth, (
int)docHeight);
1250 pix.fill( TQColor( 245, 245, 245 ) );
1252 TQRect rc(0, 0, pix.width(), pix.height());
1260 pix.convertFromImage(pix.convertToImage().smoothScale(previewWidth, previewHeight));
1265TQString KoDocument::autoSaveFile(
const TQString & path )
const
1270 setlocale( LC_NUMERIC,
"C" );
1274 TQString extension = mime->property(
"X-TDE-NativeExtension" ).toString();
1275 if ( path.isEmpty() )
1280 TQString ret = TQDir::homeDirPath() +
"/." + TQString::fromLatin1(
instance()->instanceName()) +
".autosave" + extension;
1286 Q_ASSERT(
url.isLocalFile() );
1287 TQString dir =
url.directory(
false);
1288 TQString filename =
url.fileName();
1289 return dir +
"." + filename +
".autosave" + extension;
1295 TQString asf = autoSaveFile( TQString() );
1297 if ( TQFile::exists( asf ) )
1299 TQDateTime date = TQFileInfo(asf).lastModified();
1300 TQString dateStr = date.toString(TQt::LocalDate);
1302 0, i18n(
"An autosaved file for an unnamed document exists in %1.\nThis file is dated %2\nDo you want to open it?" )
1303 .arg(asf, dateStr) );
1305 case KMessageBox::Yes : {
1313 case KMessageBox::No :
1314 TQFile::remove( asf );
1327 kdDebug (30003) <<
"KoDocument::import url=" << _url.url() << endl;
1328 d->m_isImporting =
true;
1337 kdDebug (30003) <<
"KoDocument::import success, resetting url" << endl;
1342 d->m_isImporting =
false;
1349 kdDebug(30003) <<
"KoDocument::openURL url=" << _url.url() << endl;
1350 d->lastErrorMessage = TQString();
1353 if ( !_url.isValid() )
1355 d->lastErrorMessage = i18n(
"Malformed URL\n%1" ).arg( _url.url() );
1362 bool autosaveOpened =
false;
1363 d->m_bLoading =
true;
1364 if (
url.isLocalFile() && d->m_shouldCheckAutoSaveFile )
1367 TQString asf = autoSaveFile(
file );
1368 if ( TQFile::exists( asf ) )
1373 i18n(
"An autosaved file exists for this document.\nDo you want to open it instead?" ));
1375 case KMessageBox::Yes :
1377 autosaveOpened =
true;
1379 case KMessageBox::No :
1380 TQFile::remove( asf );
1383 d->m_bLoading =
false;
1391 if ( autosaveOpened )
1399 TQPtrListIterator<KoMainWindow> it( d->m_shells );
1400 for (; it.current(); ++it )
1401 it.current()->addRecentURL( _url );
1409 if ( !TQFile::exists(
m_file) )
1411 TQApplication::restoreOverrideCursor();
1412 if ( d->m_autoErrorHandlingEnabled )
1415 d->m_bLoading =
false;
1419 TQApplication::setOverrideCursor( waitCursor );
1421 d->m_specialOutputFlag = 0;
1426 TQString typeName = KMimeType::findByURL( u, 0,
true )->name();
1429 if ( typeName ==
"application/x-trash" )
1431 TQString path = u.path();
1432 TQStringList patterns = KMimeType::mimeType( typeName )->patterns();
1434 for( TQStringList::Iterator it = patterns.begin(); it != patterns.end(); ++it ) {
1436 if ( !ext.isEmpty() && ext[0] ==
'*' )
1439 if ( path.endsWith( ext ) ) {
1440 path.truncate( path.length() - ext.length() );
1445 typeName = KMimeType::findByPath( path, 0,
true )->name();
1449 if ( u.fileName() ==
"maindoc.xml" || u.fileName() ==
"content.xml" || typeName ==
"inode/directory" )
1451 typeName = _native_format;
1452 d->m_specialOutputFlag = SaveAsDirectoryStore;
1453 kdDebug(30003) <<
"KoDocument::openFile loading " << u.fileName() <<
", using directory store for " <<
m_file <<
"; typeName=" << typeName << endl;
1455 kdDebug(30003) <<
"KoDocument::openFile " <<
m_file <<
" type:" << typeName << endl;
1457 TQString importedFile =
m_file;
1460 if ( !d->filterManager )
1463 importedFile = d->filterManager->import(
m_file, status );
1464 if ( status != KoFilter::OK )
1466 TQApplication::restoreOverrideCursor();
1471 case KoFilter::OK:
break;
1473 case KoFilter::CreationError:
1474 msg = i18n(
"Creation error" );
break;
1476 case KoFilter::FileNotFound:
1477 msg = i18n(
"File not found" );
break;
1479 case KoFilter::StorageCreationError:
1480 msg = i18n(
"Cannot create storage" );
break;
1482 case KoFilter::BadMimeType:
1483 msg = i18n(
"Bad MIME type" );
break;
1485 case KoFilter::EmbeddedDocError:
1486 msg = i18n(
"Error in embedded document" );
break;
1488 case KoFilter::WrongFormat:
1489 msg = i18n(
"Format not recognized" );
break;
1491 case KoFilter::NotImplemented:
1492 msg = i18n(
"Not implemented" );
break;
1494 case KoFilter::ParsingError:
1495 msg = i18n(
"Parsing error" );
break;
1497 case KoFilter::PasswordProtected:
1498 msg = i18n(
"Document is password protected" );
break;
1500 case KoFilter::InternalError:
1501 case KoFilter::UnexpectedEOF:
1502 case KoFilter::UnexpectedOpcode:
1503 case KoFilter::StupidError:
1504 case KoFilter::UsageError:
1505 msg = i18n(
"Internal error" );
break;
1507 case KoFilter::OutOfMemory:
1508 msg = i18n(
"Out of memory" );
break;
1510 case KoFilter::UserCancelled:
1511 case KoFilter::BadConversionGraph:
1515 default: msg = i18n(
"Unknown error" );
break;
1518 if( d->m_autoErrorHandlingEnabled && !msg.isEmpty())
1520 TQString errorMsg( i18n(
"Could not open\n%2.\nReason: %1" ) );
1521 TQString docUrl =
url().prettyURL( 0, KURL::StripFileProtocol );
1525 d->m_bLoading =
false;
1528 kdDebug(30003) <<
"KoDocument::openFile - importedFile '" << importedFile
1529 <<
"', status: " <<
static_cast<int>( status ) << endl;
1532 TQApplication::restoreOverrideCursor();
1536 if (!importedFile.isEmpty())
1542 if ( d->m_autoErrorHandlingEnabled )
1549 if ( importedFile !=
m_file )
1568 if(!importedFile.isEmpty()) {
1569 TQFile::remove( importedFile );
1573 if ( ok && d->m_bSingleViewMode )
1580 if ( !d->m_views.isEmpty() )
1583 KoView* v = d->m_views.first();
1588 Q_ASSERT( d->m_views.isEmpty() );
1592 d->m_wrapperWidget->setKoView( view );
1603 setMimeTypeAfterLoading( typeName );
1605 d->m_bLoading =
false;
1610void KoDocument::setMimeTypeAfterLoading(
const TQString& mimeType )
1614 d->outputMimeType = d->mimeType;
1617 setConfirmNonNativeSave(
false, needConfirm );
1618 setConfirmNonNativeSave(
true, needConfirm );
1622bool KoDocument::oldLoadAndParse(
KoStore* store,
const TQString& filename, TQDomDocument& doc)
1626 if (!store->
open(filename))
1628 kdWarning(30003) <<
"Entry " << filename <<
" not found!" << endl;
1629 d->lastErrorMessage = i18n(
"Could not find %1" ).arg( filename );
1634 int errorLine, errorColumn;
1635 bool ok = doc.setContent( store->
device(), &errorMsg, &errorLine, &errorColumn );
1638 kdError(30003) <<
"Parsing error in " << filename <<
"! Aborting!" << endl
1639 <<
" In line: " << errorLine <<
", column: " << errorColumn << endl
1640 <<
" Error message: " << errorMsg << endl;
1641 d->lastErrorMessage = i18n(
"Parsing error in %1 at line %2, column %3\nError message: %4" )
1642 .arg( filename ).arg( errorLine ).arg( errorColumn )
1643 .arg( i18n (
"TQXml", errorMsg.utf8() ) );
1647 kdDebug(30003) <<
"File " << filename <<
" loaded and parsed" << endl;
1653 TQFileInfo fileInfo(
file );
1654 if ( !fileInfo.exists() )
1656 d->lastErrorMessage = i18n(
"The file %1 does not exist.").arg(
file);
1659 if ( !fileInfo.isFile() )
1661 d->lastErrorMessage = i18n(
"%1 is not a file." ).arg(
file);
1665 TQApplication::setOverrideCursor( waitCursor );
1667 kdDebug(30003) <<
"KoDocument::loadNativeFormat( " <<
file <<
" )" << endl;
1670 bool isRawXML =
false;
1671 if ( d->m_specialOutputFlag != SaveAsDirectoryStore )
1674 if ( !in.open( IO_ReadOnly ) )
1676 TQApplication::restoreOverrideCursor();
1677 d->lastErrorMessage = i18n(
"Could not open the file for reading (check read permissions)." );
1683 if ( in.readBlock( buf, 4 ) < 4 )
1685 TQApplication::restoreOverrideCursor();
1687 d->lastErrorMessage = i18n(
"Could not read the beginning of the file." );
1691 isRawXML = (strncasecmp( buf,
"<?xm", 4 ) == 0);
1697 if ( in.readBlock( buf , 1 ) < 1 )
1699 TQApplication::restoreOverrideCursor();
1701 d->lastErrorMessage = i18n(
"Could not read the beginning of the file." );
1704 }
while ( TQChar( buf[0] ).isSpace() );
1705 if ( buf[0] ==
'<' ) {
1706 if ( in.readBlock( buf , 4 ) < 4 )
1708 TQApplication::restoreOverrideCursor();
1710 d->lastErrorMessage = i18n(
"Could not read the beginning of the file." );
1713 isRawXML = (strncasecmp( buf,
"math", 4 ) == 0);
1727 if ( doc.setContent( &in,
true, &errorMsg, &errorLine, &errorColumn ) )
1735 kdError (30003) <<
"Parsing Error! Aborting! (in KoDocument::loadNativeFormat (TQFile))" << endl
1736 <<
" Line: " << errorLine <<
" Column: " << errorColumn << endl
1737 <<
" Message: " << errorMsg << endl;
1738 d->lastErrorMessage = i18n(
"parsing error in the main document at line %1, column %2\nError message: %3" )
1739 .arg( errorLine ).arg( errorColumn ).arg( i18n ( errorMsg.utf8() ) );
1743 TQApplication::restoreOverrideCursor();
1751 return loadNativeFormatFromStore(
file );
1755bool KoDocument::loadNativeFormatFromStore(
const TQString& file )
1757 KoStore::Backend backend = (d->m_specialOutputFlag == SaveAsDirectoryStore) ? KoStore::Directory :
KoStore::Auto;
1762 d->lastErrorMessage = i18n(
"Not a valid KOffice file: %1" ).arg(
file );
1764 TQApplication::restoreOverrideCursor();
1770 if ( store->
hasFile(
"content.xml" ) )
1774 KoOasisStore oasisStore( store );
1779 TQApplication::restoreOverrideCursor();
1783 }
else if ( store->
hasFile(
"root" ) )
1788 bool ok = oldLoadAndParse( store,
"root", doc );
1794 TQApplication::restoreOverrideCursor();
1801 kdError(30003) <<
"ERROR: Could not load children" << endl;
1807 kdError(30003) <<
"ERROR: No maindoc.xml" << endl;
1808 d->lastErrorMessage = i18n(
"Invalid document: no file 'maindoc.xml'." );
1810 TQApplication::restoreOverrideCursor();
1814 if ( oasis && store->
hasFile(
"meta.xml" ) ) {
1815 TQDomDocument metaDoc;
1816 KoOasisStore oasisStore( store );
1817 if ( oasisStore.loadAndParse(
"meta.xml", metaDoc, d->lastErrorMessage ) ) {
1818 d->m_docInfo->loadOasis( metaDoc );
1821 else if ( !oasis && store->
hasFile(
"documentinfo.xml" ) )
1824 if ( oldLoadAndParse( store,
"documentinfo.xml", doc ) ) {
1826 d->m_docInfo->load( doc );
1832 delete d->m_docInfo;
1833 d->m_docInfo =
new KoDocumentInfo(
this,
"document info" );
1838 TQApplication::restoreOverrideCursor();
1849 doc.setContent( _store->
device() );
1857 kdWarning() <<
"couldn't open " <<
url << endl;
1862 if (
url.startsWith( STORE_PROTOCOL ) ) {
1865 m_url = KURL( INTERNAL_PREFIX +
url );
1871 kdError(30003) <<
"ERROR: Could not load children" << endl;
1888 TQDomDocument contentDoc;
1889 TQDomDocument settingsDoc;
1891 bool ok = oasisStore.
loadAndParse(
"content.xml", contentDoc, d->lastErrorMessage );
1895 TQDomDocument stylesDoc;
1896 (void)oasisStore.
loadAndParse(
"styles.xml", stylesDoc, d->lastErrorMessage );
1909 if ( store->
hasFile(
"settings.xml" ) ) {
1910 (void)oasisStore.
loadAndParse(
"settings.xml", settingsDoc, d->lastErrorMessage );
1912 if ( !
loadOasis( contentDoc, oasisStyles, settingsDoc, store ) )
1918bool KoDocument::isInOperation()
const
1920 return d->m_numOperations > 0;
1923void KoDocument::emitBeginOperation()
1927 if (!isInOperation())
1928 emit sigBeginOperation();
1929 d->m_numOperations++;
1932void KoDocument::emitEndOperation()
1934 d->m_numOperations--;
1937 if (d->m_numOperations == 0)
1938 emit sigEndOperation();
1939 else if (d->m_numOperations < 0)
1941 d->m_numOperations = 0;
1958 if ( mod && !d->modifiedAfterAutosave ) {
1962 d->modifiedAfterAutosave = mod;
1973 TQPtrListIterator<KoDocumentChild> it =
children();
1974 for (; it.current(); ++it )
1989 d->m_doNotSaveExtDoc = on;
1992int KoDocument::queryCloseDia()
2001 if (
name.isEmpty() )
2004 if (
name.isEmpty() )
2005 name = i18n(
"Untitled" );
2008 i18n(
"<p>The document <b>'%1'</b> has been modified.</p><p>Do you want to save it?</p>" ).arg(name));
2012 case KMessageBox::Yes :
2017 case KMessageBox::No :
2027int KoDocument::queryCloseExternalChildren()
2031 TQPtrListIterator<KoDocumentChild> it(
children() );
2032 for (; it.current(); ++it )
2034 if ( !it.current()->isDeleted() )
2040 kdDebug(36001) <<
"========== isStoredExtern() returned "
2041 << foo <<
" ==========" << endl;
2046 kdDebug(30003)<<k_funcinfo<<
" found modified child: "<<doc->
url().url()<<
" extern="<<doc->
isStoredExtern()<<endl;
2047 if ( doc->queryCloseDia() == KMessageBox::Cancel )
2048 return KMessageBox::Cancel;
2051 if ( doc->queryCloseExternalChildren() == KMessageBox::Cancel )
2052 return KMessageBox::Cancel;
2056 return KMessageBox::Ok;
2069 TQPtrListIterator<KoMainWindow> it( d->m_shells );
2070 for (; it.current(); ++it )
2072 it.current()->updateCaption();
2073 it.current()->updateReloadFileAction(
this);
2074 it.current()->updateVersionsFileAction(
this);
2088 KoDocumentInfoPage * page =
documentInfo()->page( TQString::fromLatin1(
"about") );
2090 caption =
static_cast<KoDocumentInfoAbout *
>(page)->title();
2092 if ( caption.isEmpty() )
2093 caption =
url().prettyURL( 0, KURL::StripFileProtocol );
2138 TQDomImplementation impl;
2139 TQString
url = TQString(
"http://www.koffice.org/DTD/%1-%1.dtd").arg(appName).arg(version);
2140 TQDomDocumentType dtype = impl.createDocumentType( tagName,
2141 TQString(
"-//KDE//DTD %1 %1//EN").arg(appName).arg(version),
2144 TQString namespaceURN = TQString(
"http://www.koffice.org/DTD/%1").arg(appName);
2145 TQDomDocument doc = impl.createDocument( namespaceURN, tagName, dtype );
2146 doc.insertBefore( doc.createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\"" ), doc.documentElement() );
2155 writer->
addAttribute(
"xmlns:office", KoXmlNS::office );
2158 if ( qstrcmp( rootElementName,
"office:document-meta" ) != 0 ) {
2159 writer->
addAttribute(
"xmlns:config", KoXmlNS::config );
2163 writer->
addAttribute(
"xmlns:presentation", KoXmlNS::presentation );
2167 writer->
addAttribute(
"xmlns:script", KoXmlNS::script );
2169 writer->
addAttribute(
"xmlns:number", KoXmlNS::number );
2173 writer->
addAttribute(
"xmlns:koffice", KoXmlNS::koffice );
2184 kdError(30003) <<
"KoDocument::saveXML not implemented" << endl;
2185 d->lastErrorMessage = i18n(
"Internal error: saveXML not implemented" );
2186 return TQDomDocument();
2189KService::Ptr KoDocument::nativeService()
2191 if ( !m_nativeService )
2194 return m_nativeService;
2199 KService::Ptr service =
const_cast<KoDocument *
>(
this)->nativeService();
2202 TQCString nativeMimeType = service->property(
"X-TDE-NativeMimeType" ).toString().latin1();
2203 if ( nativeMimeType.isEmpty() ) {
2205 if ( !service->serviceTypes().contains(
"KOfficePart" ) )
2206 kdWarning(30003) <<
"Wrong desktop file, KOfficePart isn't mentionned" << endl;
2207 else if ( !KServiceType::serviceType(
"KOfficePart" ) )
2208 kdWarning(30003) <<
"The KOfficePart service type isn't installed!" << endl;
2210 return nativeMimeType;
2215 KService::Ptr service =
const_cast<KoDocument *
>(
this)->nativeService();
2218 return service->property(
"X-TDE-NativeOasisMimeType" ).toString().latin1();
2225 TQString instname =
instance ?
instance->instanceName() : kapp->instanceName();
2228 TQString servicepartname = instname +
"part.desktop";
2229 KService::Ptr service = KService::serviceByDesktopPath( servicepartname );
2231 kdDebug(30003) << servicepartname <<
" found." << endl;
2239 service = KService::serviceByDesktopPath( TQString::fromLatin1(
"Office/%1.desktop").arg(instname) );
2242 service = KService::serviceByDesktopName( instname );
2253 if ( service->property(
"X-TDE-NativeMimeType" ).toString().isEmpty() )
2256 if ( KServiceType::serviceType(
"KOfficePart" ) == 0L )
2257 kdError(30003) <<
"The serviceType KOfficePart is missing. Check that you have a kofficepart.desktop file in the share/servicetypes directory." << endl;
2259 TQString instname =
instance ?
instance->instanceName() : kapp->instanceName();
2260 if ( instname !=
"koshell" )
2261 kdWarning(30003) << service->desktopEntryPath() <<
": no X-TDE-NativeMimeType entry!" << endl;
2265 return service->property(
"X-TDE-NativeMimeType" ).toString().latin1();
2272 return TQStringList();
2273 return service->property(
"X-TDE-ExtraNativeMimeTypes" ).toStringList();
2278 if ( namespaceProcessing )
2280 reader.setFeature(
"http://xml.org/sax/features/namespaces",
true );
2281 reader.setFeature(
"http://xml.org/sax/features/namespace-prefixes",
false );
2285 reader.setFeature(
"http://xml.org/sax/features/namespaces",
false );
2286 reader.setFeature(
"http://xml.org/sax/features/namespace-prefixes",
true );
2288 reader.setFeature(
"http://trolltech.com/xml/features/report-whitespace-only-CharData",
true );
2305 KService::Ptr service =
const_cast<KoDocument *
>(
this)->nativeService();
2308 return service->property(
"X-TDE-ExtraNativeMimeTypes" ).toStringList();
2316 return SaveAsDirectoryStore;
2321 if ( d->m_shells.findRef( shell ) == -1 )
2324 d->m_shells.append( shell );
2331 d->m_shells.removeRef( shell );
2341 return d->m_shells.count();
2346 if ( !d->m_dcopObject )
2348 return d->m_dcopObject;
2358 d->lastErrorMessage = errMsg;
2363 return d->lastErrorMessage;
2368 if ( d->lastErrorMessage.isEmpty() )
2372 else if ( d->lastErrorMessage !=
"USER_CANCELED" )
2380 if ( d->lastErrorMessage.isEmpty() )
2382 KMessageBox::error( 0L, i18n(
"Could not open\n%1" ).arg(
url().prettyURL( 0, KURL::StripFileProtocol ) ) );
2384 else if ( d->lastErrorMessage !=
"USER_CANCELED" )
2386 KMessageBox::error( 0L, i18n(
"Could not open %1\nReason: %2" ).arg(
url().prettyURL( 0, KURL::StripFileProtocol ), d->lastErrorMessage ) );
2392 return d->m_autosaving;
2397 return d->m_bLoading;
2403 TQString asf = autoSaveFile(
m_file );
2404 if ( TQFile::exists( asf ) )
2405 TQFile::remove( asf );
2406 asf = autoSaveFile( TQString() );
2407 if ( TQFile::exists( asf ) )
2408 TQFile::remove( asf );
2411void KoDocument::setBackupFile(
bool _b )
2413 d->m_backupFile = _b;
2416bool KoDocument::backupFile()
const
2418 return d->m_backupFile;
2424 d->m_backupPath = _path;
2429 return d->m_backupPath;
2470bool KoDocument::isCurrent()
const
2472 return d->m_current;
2477 return d->m_storeInternal;
2482 d->m_storeInternal = i;
2486bool KoDocument::hasExternURL()
const
2488 return !
url().protocol().isEmpty() &&
url().protocol() != STORE_PROTOCOL &&
url().protocol() != INTERNAL_PROTOCOL;
2491void KoDocument::slotStarted( TDEIO::Job* job )
2495 job->setWindow( d->m_shells.current() );
2499static const struct {
2500 const char* localName;
2501 const char* documentType;
2503 {
"text", I18N_NOOP(
"a word processing" ) },
2504 {
"spreadsheet", I18N_NOOP(
"a spreadsheet" ) },
2505 {
"presentation", I18N_NOOP(
"a presentation" ) },
2506 {
"chart", I18N_NOOP(
"a chart" ) },
2507 {
"drawing", I18N_NOOP(
"a drawing" ) }
2509static const unsigned int numTN2DT =
sizeof( TN2DTArray ) /
sizeof( *TN2DTArray );
2513 for (
unsigned int i = 0 ; i < numTN2DT ; ++i )
2514 if ( localName == TN2DTArray[i].localName )
2515 return i18n( TN2DTArray[i].documentType );
2521 return TQValueList<KoTextDocument *>();
2526 return m_pageLayout;
2536 if ( d->m_unit !=
unit )
2551 TDEConfigGroup cfgGrp(
instance()->config(),
"TemplateChooserDialog" );
2552 TQString fullTemplateName = cfgGrp.readPathEntry(
"AlwaysUseTemplate" );
2554 if( !fullTemplateName.isEmpty() ) {
2556 shells().getFirst()->setRootDocument(
this );
2561 if(d->m_startUpWidget){
2562 d->m_startUpWidget->show();
2578 TQTimer::singleShot( 0,
this, TQ_SLOT( deleteOpenPane() ) );
2602void KoDocument::startCustomDocument() {
2612 openPane->setCustomDocumentWidget( customDoc );
2613 connect( customDoc, TQ_SIGNAL( documentSelected() ),
this, TQ_SLOT( startCustomDocument() ) );
2619 connect( openPane, TQ_SIGNAL(
openTemplate(
const TQString& ) ),
2627 d->m_templateType = _templateType;
2632 return d->m_templateType;
2635void KoDocument::deleteOpenPane()
2637 if( d->m_startUpWidget ) {
2638 d->m_startUpWidget->hide();
2639 TQTimer::singleShot(1000,
this, TQ_SLOT(deleteOpenPaneDelayed()));
2641 shells().getFirst()->factory()->container(
"mainToolBar",
shells().getFirst())->show();
2642 shells().getFirst()->setRootDocument(
this );
2644 emit closeEmbedInitDialog();
2648void KoDocument::deleteOpenPaneDelayed()
2650 delete d->m_startUpWidget;
2651 d->m_startUpWidget = 0;
2662 pane->layout()->setMargin(0);
2665 connect(
this, TQ_SIGNAL(closeEmbedInitDialog()), &dlg, TQ_SLOT(slotOk()));
2667 bool ok = dlg.exec() == TQDialog::Accepted;
2674#include "KoDocument_p.moc"
2675#include "KoDocument.moc"
void setMainWidget(TQWidget *widget)
TQSize configDialogSize(const TQString &groupName) const
void saveDialogSize(const TQString &groupName, bool global=false)
void setInitialSize(const TQSize &s, bool noResize=false)
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
static int warningYesNoCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonYes=KStdGuiItem::yes(), const KGuiItem &buttonNo=KStdGuiItem::no(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
virtual void addPart(Part *part, bool setActive=true)
virtual void setWidget(TQWidget *widget)
virtual TQWidget * widget()
PartManager * manager() const
virtual bool openURL(const KURL &url)
void started(TDEIO::Job *)
virtual void setReadWrite(bool readwrite=true)
virtual bool saveAs(const KURL &url)
ReadWritePart(TQObject *parent=0, const char *name=0)
virtual void setModified()
virtual TDEInstance * instance() const
KXMLGUIFactory * factory() const
TDEAction * action(const char *name) const
void removeClient(KXMLGUIClient *client)
void addClient(KXMLGUIClient *client)
TQWidget * container(const TQString &containerName, KXMLGUIClient *client, bool useTagName=false)
KoChild is an abstract base class that represents the geometry associated with an embedded document.
Holds an embedded object.
DCOP interface for any KOffice document Use KoApplicationIface to get hold of an existing document's ...
The KOffice document class.
KoDocument(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, bool singleViewMode=false)
Constructor.
bool isLoading() const
Returns true during loading (openURL can be asynchronous).
virtual void openTemplate(const TQString &file)
This slot loads a template and deletes the start up widget.
TQString templateType() const
Template type used.
static TQString tagNameToDocumentType(const TQString &localName)
The first thing to do in loadOasis is get hold of the office:body tag, then its child.
void resetURL()
Sets the document URL to empty URL KParts doesn't allow this, but KOffice apps have e....
KoView * hitTestView()
Temporary API for accessing the view that calls hitTest.
virtual bool saveToStream(TQIODevice *dev)
Save the document.
virtual TQDomDocument saveXML()
Reimplement this to save the contents of the KOffice document into a TQDomDocument.
bool isAutoErrorHandlingEnabled() const
Checks whether error message boxes should be shown.
void removeAutoSaveFiles()
Performs a cleanup of unneeded backup files.
virtual int supportedSpecialFormats() const
Return the set of SupportedSpecialFormats that the application wants to offer in the "Save" file dial...
virtual bool showEmbedInitDialog(TQWidget *parent)
Shows the init dialog when embeding.
virtual TQWidget * createCustomDocumentWidget(TQWidget *parent)
Override this method in your derived class to show a widget in the startup 'dialog'.
virtual bool isStoredExtern() const
Return true if url() is a real filename, false if url() is an internal url in the store,...
bool isImporting() const
Returns whether or not the current openURL() or openFile() call is actually an import operation (like...
virtual bool loadOasis(const TQDomDocument &doc, KoOasisStyles &oasisStyles, const TQDomDocument &settings, KoStore *store)=0
Reimplement this method to load the contents of your KOffice document, from the XML document ("conten...
TQString backupPath() const
virtual TQValueList< KoTextDocument * > allTextDocuments() const
virtual bool loadNativeFormat(const TQString &file)
Loads a document in the native format from a given URL.
bool checkAutoSaveFile()
Called by koApplication to check for an autosave file in $HOME.
virtual KParts::Part * hitTest(TQWidget *widget, const TQPoint &globalPos)
Reimplemented from KParts::Part.
virtual TDEAction * action(const TQDomElement &element) const
Returns the action described action object.
TQString errorMessage() const
Return the last error message.
virtual bool completeLoading(KoStore *store)
Overload this function if you have to load additional files from a store.
virtual void paintChildren(TQPainter &painter, const TQRect &rect, KoView *view, double zoomX=1.0, double zoomY=1.0)
Paints all of the documents children into the given painter object.
KoDocumentChild * child(KoDocument *doc)
KoView * createView(TQWidget *parent=0, const char *name=0)
Create a new view for the document.
virtual bool saveToStore(KoStore *store, const TQString &path)
Saves a document to a store.
bool storeInternal() const
void setMimeType(const TQCString &mimeType)
Sets the mime type for the document.
static TQCString readNativeFormatMimeType(TDEInstance *instance=0)
Used by KoApplication, and by KoMainWindow, when no document exists yet.
void setAutoErrorHandlingEnabled(bool b)
Set whether the next openURL call should show error message boxes in case of errors.
virtual TQStringList extraNativeMimeTypes() const
Returns a list of the mimetypes considered "native", i.e.
virtual bool saveChildren(KoStore *store)
Saves all internal children (only!).
bool isNativeFormat(const TQCString &mimetype) const
Checks whether a given mimetype can be handled natively.
virtual bool loadChildren(KoStore *)
OLD XML method.
virtual void setReadWrite(bool readwrite=true)
Sets whether the document can be edited or is read only.
TQString & file()
Only use these functions to restore m_file (in KoMainWindow) after a failed save (remember to use set...
virtual void removeShell(KoMainWindow *shell)
Removes the shell from the list.
virtual bool openFile()
Loads a document from KReadOnlyPart::m_file (KParts takes care of downloading remote documents).
static TQStringList readExtraNativeMimeTypes(TDEInstance *instance=0)
Used by KoMainWindow, when no document exists yet.
virtual bool saveOasis(KoStore *store, KoXmlWriter *manifestWriter)=0
Reimplement this method to save the contents of your KOffice document, using the OASIS format.
TQString unitName() const
Returns the name of the unit used to display all measures/distances.
const TQPtrList< KoMainWindow > & shells() const
virtual void setEmpty()
Sets the document to empty.
void showSavingErrorDialog()
Show the last error message in a message box.
void sigStatusBarMessage(const TQString &text)
Emitted e.g.
void unitChanged(KoUnit::Unit)
This signal is emitted when the unit is changed by setUnit() It is common to connect views to it,...
TQCString mimeType() const
Returns the actual mimetype of the document.
virtual TQPixmap generatePreview(const TQSize &size)
Generates a preview picture of the document.
virtual bool saveFile()
Saves a document to KReadOnlyPart::m_file (KParts takes care of uploading remote documents) Applies a...
virtual DCOPObject * dcopObject()
Return a DCOP interface for this document.
static void setupXmlReader(TQXmlSimpleReader &reader, bool namespaceProcessing=false)
setup the XML reader, so that we don't have to duplicate the code.
void setDoNotSaveExtDoc(bool on=true)
Set when we do not want to save external children when saving our 'main' doc.
void sigClearStatusBarMessage()
Emitted e.g.
bool isEmbedded() const
Is the document embedded?
virtual bool saveExternalChildren()
Saves all externally stored children.
TQCString nativeOasisMimeType() const
Returns the OASIS OpenDocument mimetype of the document, if supported This comes from the X-TDE-Nativ...
void modified(bool)
Emitted when the document is modified.
virtual bool saveNativeFormat(const TQString &file)
Saves the document in native format, to a given file You should never have to reimplement.
virtual void addView(KoView *view)
Adds a view to the document.
void setCurrent(bool on=true)
Indicates that this document is currently viewed and thus should control the title caption.
void childChanged(KoDocumentChild *child)
This signal is emitted when a direct or indirect child document changes and needs to be updated in al...
bool import(const KURL &url)
Opens the document given by url, without storing the URL in the KoDocument.
bool isSingleViewMode() const
Tells whether this document is in singleview mode.
void setErrorMessage(const TQString &errMsg)
Sets the error message to be shown to the user (use i18n()!) when loading or saving fails.
const TQPtrList< KoDocumentChild > & children() const
virtual TQDomDocument domDocument() const
Returns the DOM document which describes the GUI of the first view.
TQDomDocument createDomDocument(const TQString &tagName, const TQString &version) const
Return a correctly created TQDomDocument for this KoDocument, including processing instruction,...
virtual void paintChild(KoDocumentChild *child, TQPainter &painter, KoView *view, double zoomX=1.0, double zoomY=1.0)
Paint a given child.
bool confirmNonNativeSave(const bool exporting) const
Returns true if this document was the result of opening a foreign file format and if the user hasn't ...
void sigProgress(int value)
Progress info while loading or saving.
void setUnit(KoUnit::Unit u)
Sets the unit used to display all measures/distances.
virtual void addShell(KoMainWindow *shell)
Appends the shell to the list of shells which show this document as their root document.
virtual ~KoDocument()
Destructor.
virtual void setModified(bool _mod)
Sets the modified flag on the document.
virtual void initEmpty()
Initialize an empty document using default values.
TQCString dcopObjectId() const
void setTemplateType(const TQString &_templateType)
Set the template type used.
virtual void paintContent(TQPainter &painter, const TQRect &rect, bool transparent=false, double zoomX=1.0, double zoomY=1.0)=0
Paints the data itself.
virtual bool completeSaving(KoStore *store)
If you want to write additional files to a store, then you must do it here.
virtual bool openURL(const KURL &url)
Reimplemented from KParts::ReadWritePart for internal reasons (for the autosave functionality).
void setCheckAutoSaveFile(bool b)
Set whether the next openURL call should check for an auto-saved file and offer to open it.
virtual bool loadFromStore(KoStore *store, const TQString &url)
Loads a document from a store.
void setStoreInternal(bool i)
Set when you want an external embedded document to be stored internally.
KoUnit::Unit unit() const
Returns the unit used to display all measures/distances.
KoDocumentInfo * documentInfo() const
virtual void removeView(KoView *view)
Removes a view of the document.
void forceCurrent(bool on)
Sets current flag for this document and all its parents.
virtual void insertChild(KoDocumentChild *child)
Inserts the new child in the list of children and emits the childChanged() signal.
KoOpenPane * createOpenPane(TQWidget *parent, TDEInstance *instance, const TQString &templateType=TQString())
Creates the open widget showed at application start up.
void setAutoSave(int delay)
Activate/deactivate/configure the autosave feature.
virtual TQCString nativeFormatMimeType() const
To be preferred when a document exists.
virtual bool loadXML(TQIODevice *, const TQDomDocument &doc)=0
Reimplement this method to load the contents of your KOffice document, from the XML document.
bool exp0rt(const KURL &url)
Saves the document as url without changing the state of the KoDocument (URL, modified flag etc....
bool isModified() const
Returns true if this document or any of its internal child documents are modified.
void setOutputMimeType(const TQCString &mimeType, int specialOutputFlag=0)
Set the format in which the document should be saved.
virtual void paintEverything(TQPainter &painter, const TQRect &rect, bool transparent=false, KoView *view=0L, double zoomX=1.0, double zoomY=1.0)
Paints the whole document into the given painter object.
virtual KoPageLayout pageLayout(int pageNumber=0) const
virtual bool loadOasisFromStore(KoStore *store)
Loads an OASIS document from a store.
bool isAutosaving() const
Checks whether the document is currently in the process of autosaving.
bool isExporting() const
Returns whether or not the current saveFile() call is actually an export operation (like File --> Exp...
const TQPtrList< KoView > & views() const
static KService::Ptr readNativeService(TDEInstance *instance=0)
With the help of instance or TDEApplication::instance() this method figures out which ....
virtual void showStartUpWidget(KoMainWindow *parent, bool alwaysShow=false)
Creates and shows the start up widget.
virtual bool isEmpty() const
void setBackupPath(const TQString &_path)
Sets the backup path of the document.
virtual bool saveChildrenOasis(KoStore *store, KoXmlWriter *manifestWriter)
Saves all internal children (only!), to the store, using the OASIS format.
virtual void setTitleModified()
Tells the document that its title has been modified, either because the modified status changes (this...
static KoXmlWriter * createOasisXmlWriter(TQIODevice *dev, const char *rootElementName)
Return an XML writer for saving Oasis XML into the device dev, including the XML processing instructi...
void showLoadingErrorDialog()
Show the last error message in a message box.
virtual void openExistingFile(const TQString &file)
This slot loads an existing file and deletes the start up widget.
The class managing all the filters.
ConversionStatus
This enum is used to signal the return state of your filter.
Main window for a KOffice application.
void setDocToOpen(KoDocument *doc)
This is used to handle the document used at start up before it actually added as root document.
Helper class around KoStore for writing out OASIS files.
bool closeManifestWriter()
Close the manifest writer, writing its contents to manifest.xml.
KoXmlWriter * manifestWriter(const char *mimeType)
Create and return a manifest writer. It will write to a memory buffer.
bool loadAndParse(const TQString &fileName, TQDomDocument &doc, TQString &errorMessage)
A completely unrelated method, for loading a file from an oasis store.
Repository of styles used during loading of OASIS/OOo file.
void createStyleMap(const TQDomDocument &doc, bool stylesDotXml)
Look into doc for styles and remember them.
This class implements a TQIODevice around KoStore, so that it can be used to create a TQDomDocument f...
Saves and loads KOffice documents using various backends.
bool close()
Close the file inside the store.
bool hasFile(const TQString &fileName) const
void pushDirectory()
Stacks the current directory.
void popDirectory()
Restores the previously pushed directory.
TQIODevice * device() const
Get a device for reading a file from the store directly (slightly faster than read() calls) You need ...
bool open(const TQString &name)
Open a new file inside the store.
static KoStore * createStore(const TQString &fileName, Mode mode, const TQCString &appIdentification="", Backend backend=Auto)
Open a store (i.e.
void disallowNameExpansion(void)
Do not expand file and directory names Useful when using KoStore on non-KOffice files.
bool enterDirectory(const TQString &directory)
Enters one or multiple directories.
Unit
Length units supported by KOffice.
static TQString unitName(Unit _unit)
Get the name of a unit.
This class is used to display a KoDocument.
virtual TQWidget * canvas() const
Overload this function if the content will be displayed on some child widget instead of the view dire...
virtual int canvasYOffset() const
Overload this function if the content will be displayed with an offset relative to the upper left cor...
virtual int canvasXOffset() const
Overload this function if the content will be displayed with an offset relative to the upper left cor...
virtual void print(KPrinter &printer)
Overload this method with your own printing code.
virtual KoDocument * hitTest(const TQPoint &pos)
Retrieves the document that is hit.
virtual void setupPrinter(KPrinter &printer)
Overload this method to setup KPrinter before the actual printing.
virtual void updateReadWrite(bool readwrite)=0
You have to implement this method and disable/enable certain functionality (actions for example) in y...
A class for writing out XML (to any TQIODevice), with a special attention on performance.
void startElement(const char *tagName, bool indentInside=true)
Start a new element, as a child of the current element.
void startDocument(const char *rootElemName, const char *publicId=0, const char *systemId=0)
Start the XML document.
void addManifestEntry(const TQString &fullPath, const TQString &mediaType)
Special helper for writing "manifest" files This is equivalent to startElement/2*addAttribute/endElem...
void addAttribute(const char *attrName, const TQString &value)
Overloaded version of addAttribute( const char*, const char* ), which is a bit slower because it need...
const char * name(StdAction id)
This structure defines the page layout, including its size in pt, its format (e.g.