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 <tdeversion.h>
41#include <tdefileitem.h>
42#include <kiconloader.h>
44#include <tdeio/netaccess.h>
46#include <tdemessagebox.h>
48#include <tdeparts/partmanager.h>
56#include <tqfileinfo.h>
72#define STORE_PROTOCOL "tar"
75#define INTERNAL_PROTOCOL "intern"
76#define INTERNAL_PREFIX "intern:/"
79TQPtrList<KoDocument> *KoDocument::s_documentList=0L;
82class KoViewWrapperWidget;
90const int KoDocument::s_defaultAutoSave = 300;
92class KoDocument::Private
98 m_specialOutputFlag( 0 ),
99 m_isImporting( false ), m_isExporting( false ),
100 m_numOperations( 0 ),
101 modifiedAfterAutosave( false ),
102 m_autosaving( false ),
103 m_shouldCheckAutoSaveFile( true ),
104 m_autoErrorHandlingEnabled( true ),
105 m_backupFile( true ),
106 m_backupPath( TQString() ),
107 m_doNotSaveExtDoc( false ),
109 m_storeInternal( false ),
113 m_confirmNonNativeSave[0] =
true;
114 m_confirmNonNativeSave[1] =
true;
115 if ( TDEGlobal::locale()->measureSystem() == TDELocale::Imperial ) {
116 m_unit = KoUnit::U_INCH;
118 m_unit = KoUnit::U_CM;
122 TQPtrList<KoView> m_views;
123 TQPtrList<KoDocumentChild> m_children;
124 TQPtrList<KoMainWindow> m_shells;
125 TQValueList<TQDomDocument> m_viewBuildDocuments;
127 KoViewWrapperWidget *m_wrapperWidget;
129 KoDocumentInfo *m_docInfo;
137 TQCString outputMimeType;
138 bool m_confirmNonNativeSave [2];
141 int m_specialOutputFlag;
142 bool m_isImporting, m_isExporting;
144 TQTimer m_autoSaveTimer;
145 TQString lastErrorMessage;
148 bool modifiedAfterAutosave;
149 bool m_bSingleViewMode;
151 bool m_shouldCheckAutoSaveFile;
152 bool m_autoErrorHandlingEnabled;
154 TQString m_backupPath;
155 bool m_doNotSaveExtDoc;
157 bool m_storeInternal;
160 KoOpenPane* m_startUpWidget;
161 TQString m_templateType;
165class KoViewWrapperWidget :
public TQWidget
168 KoViewWrapperWidget( TQWidget *parent,
const char *name )
169 : TQWidget( parent,
name )
171 TDEGlobal::locale()->insertCatalogue(
"koffice");
173 TDEGlobal::iconLoader()->addAppDir(
"koffice");
176 setFocusPolicy( TQWidget::ClickFocus );
179 virtual ~KoViewWrapperWidget() {
183 virtual void resizeEvent( TQResizeEvent * )
185 TQObject *wid = child( 0,
"TQWidget" );
187 static_cast<TQWidget*
>(wid)->setGeometry( 0, 0, width(), height() );
190 virtual void childEvent( TQChildEvent *ev )
192 if ( ev->type() == TQEvent::ChildInserted )
197 void setKoView(
KoView * view ) {
199 setFocusProxy( m_view );
201 KoView * koView()
const {
return m_view; }
206KoBrowserExtension::KoBrowserExtension(
KoDocument * doc,
const char * name )
209 emit enableAction(
"print",
true );
212void KoBrowserExtension::print()
215 KoViewWrapperWidget * wrapper =
static_cast<KoViewWrapperWidget *
>( doc->
widget() );
216 KoView * view = wrapper->koView();
221 if ( printer.setup( view ) )
222 view->
print( printer );
225KoDocument::KoDocument( TQWidget * parentWidget,
const char *widgetName, TQObject* parent,
const char* name,
bool singleViewMode )
226 :
KParts::ReadWritePart( parent, name )
228 if(s_documentList==0L)
229 s_documentList=
new TQPtrList<KoDocument>;
230 s_documentList->append(
this);
234 connect( &d->m_autoSaveTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( slotAutoSave() ) );
236 d->m_bSingleViewMode = singleViewMode;
242 if ( parent->inherits(
"KoDocument" ) )
243 d->m_bSingleViewMode = ((
KoDocument *)parent)->isSingleViewMode();
244 else if ( parent->inherits(
"KParts::Part" ) )
245 d->m_bSingleViewMode =
true;
248 if ( singleViewMode )
250 d->m_wrapperWidget =
new KoViewWrapperWidget( parentWidget, widgetName );
252 kdDebug(30003) <<
"creating KoBrowserExtension" << endl;
253 (void)
new KoBrowserExtension(
this );
256 d->m_docInfo =
new KoDocumentInfo(
this,
"document info" );
260 m_pageLayout.
ptTop = 0;
266 if ( !singleViewMode )
267 connect(
this, TQ_SIGNAL(
started( TDEIO::Job* ) ), TQ_SLOT( slotStarted( TDEIO::Job* ) ) );
276 d->m_autoSaveTimer.stop();
278 TQPtrListIterator<KoDocumentChild> childIt( d->m_children );
279 for (; childIt.current(); ++childIt )
280 disconnect( childIt.current(), TQ_SIGNAL( destroyed() ),
281 this, TQ_SLOT( slotChildDestroyed() ) );
285 TQPtrListIterator<KoView> vIt( d->m_views );
286 for (; vIt.current(); ++vIt )
287 vIt.current()->setDocumentDeleted();
289 delete d->m_startUpWidget;
290 d->m_startUpWidget = 0;
292 d->m_children.setAutoDelete(
true );
293 d->m_children.clear();
297 delete d->m_dcopObject;
298 delete d->filterManager;
301 s_documentList->removeRef(
this);
303 if(s_documentList->isEmpty()) {
304 delete s_documentList;
311 return d->m_bSingleViewMode;
316 return dynamic_cast<KoDocument *
>( parent() ) != 0;
321 KoView *view=createViewInstance(parent, name);
330 d->m_isExporting =
true;
341 TQString oldFile =
m_file;
344 TQCString oldMimeType =
mimeType ();
355 kdDebug(30003) <<
"Restoring KoDocument state to before export" << endl;
367 d->mimeType = oldMimeType;
371 d->m_isExporting =
false;
378 kdDebug(30003) <<
"KoDocument::saveFile() doc='" <<
url().url() <<
"'"<< endl;
383 setlocale( LC_NUMERIC,
"C" );
389 TQCString outputMimeType = d->outputMimeType;
391 if ( outputMimeType.isEmpty() )
394 TQApplication::setOverrideCursor( waitCursor );
396 if ( backupFile() ) {
397 if (
url().isLocalFile() )
398 KSaveFile::backupFile(
url().path(), d->m_backupPath );
400 TDEIO::UDSEntry entry;
401 if ( TDEIO::NetAccess::stat(
url(), entry,
shells().current() ) ) {
404 if ( d->m_backupPath.isEmpty())
407 backup = d->m_backupPath +
"/"+
url().fileName();
408 backup.setPath( backup.path() + TQString::fromLatin1(
"~") );
409 KFileItem item( entry,
url() );
410 Q_ASSERT( item.name() ==
url().fileName() );
411 TDEIO::NetAccess::file_copy(
url(), backup, item.permissions(),
true ,
false ,
shells().current() );
418 bool suppressErrorDialog =
false;
420 kdDebug(30003) <<
"Saving to format " << outputMimeType <<
" in " <<
m_file << endl;
422 if ( !d->filterManager )
426 ret = status == KoFilter::OK;
427 suppressErrorDialog = (status == KoFilter::UserCancelled || status == KoFilter::BadConversionGraph );
430 Q_ASSERT( !
m_file.isEmpty() );
441 TQApplication::restoreOverrideCursor();
444 if ( !suppressErrorDialog )
467 d->mimeType = outputMimeType;
488 d->m_specialOutputFlag = specialOutputFlag;
491TQCString KoDocument::outputMimeType()
const
493 return d->outputMimeType;
496int KoDocument::specialOutputFlag()
const
498 return d->m_specialOutputFlag;
505 return d->m_confirmNonNativeSave [ exporting ? 1 : 0 ];
508void KoDocument::setConfirmNonNativeSave(
const bool exporting,
const bool on )
510 d->m_confirmNonNativeSave [ exporting ? 1 : 0] = on;
513bool KoDocument::wantExportConfirmation()
const
520 return d->m_isImporting;
525 return d->m_isExporting;
530 d->m_shouldCheckAutoSaveFile = b;
535 d->m_autoErrorHandlingEnabled = b;
540 return d->m_autoErrorHandlingEnabled;
543void KoDocument::slotAutoSave()
545 if (
isModified() && d->modifiedAfterAutosave && !d->m_bLoading )
547 connect(
this, TQ_SIGNAL(
sigProgress(
int ) ),
shells().current(), TQ_SLOT( slotProgress(
int ) ) );
549 d->m_autosaving =
true;
553 d->modifiedAfterAutosave =
false;
554 d->m_autoSaveTimer.stop();
556 d->m_autosaving =
false;
558 disconnect(
this, TQ_SIGNAL(
sigProgress(
int ) ),
shells().current(), TQ_SLOT( slotProgress(
int ) ) );
571 Q_ASSERT( d->m_bSingleViewMode );
573 if ( !d->m_views.isEmpty() )
574 return d->m_views.getFirst()->action( element );
583 Q_ASSERT( d->m_bSingleViewMode );
584 if ( d->m_views.isEmpty() )
585 return TQDomDocument();
587 return d->m_views.getFirst()->domDocument();
592 KParts::ReadWritePart::setManager(
manager );
593 if ( d->m_bSingleViewMode && d->m_views.count() == 1 )
594 d->m_views.getFirst()->setPartManager(
manager );
598 TQPtrListIterator<KoDocumentChild> it( d->m_children );
599 for (; it.current(); ++it )
600 if ( it.current()->document() )
609 TQPtrListIterator<KoView> vIt( d->m_views );
610 for (; vIt.current(); ++vIt )
611 vIt.current()->updateReadWrite( readwrite );
613 TQPtrListIterator<KoDocumentChild> dIt( d->m_children );
614 for (; dIt.current(); ++dIt )
615 if ( dIt.current()->document() )
616 dIt.current()->document()->setReadWrite( readwrite );
623 d->m_autoSaveDelay = delay;
625 d->m_autoSaveTimer.start( d->m_autoSaveDelay * 1000 );
627 d->m_autoSaveTimer.stop();
635 d->m_views.append( view );
641 d->m_views.removeRef( view );
651 return d->m_views.count();
658 d->m_children.append(
child );
661 this, TQ_SLOT( slotChildChanged(
KoChild * ) ) );
662 connect(
child, TQ_SIGNAL( destroyed() ),
663 this, TQ_SLOT( slotChildDestroyed() ) );
677void KoDocument::slotChildChanged(
KoChild *c )
679 assert( c->inherits(
"KoDocumentChild" ) );
683void KoDocument::slotChildDestroyed()
688 d->m_children.removeRef(
child );
693 return d->m_children;
698 TQPtrListIterator<KoView> it( d->m_views );
699 for (; it.current(); ++it )
700 if (
static_cast<TQWidget *
>(it.current()) ==
widget )
702 KoView* view = it.current();
703 d->hitTestView = view;
704 TQPoint canvasPos( view->
canvas()->mapFromGlobal( globalPos ) );
719 return d->hitTestView;
725 TQPtrListIterator<KoDocumentChild> it( d->m_children );
726 for (; it.current(); ++it )
739 TQPtrListIterator<KoDocumentChild> it( d->m_children );
740 for (; it.current(); ++it )
741 if ( it.current()->document() == doc )
752void KoDocument::setViewBuildDocument(
KoView *view,
const TQDomDocument &doc )
754 if ( d->m_views.find( view ) == -1 )
757 uint viewIdx = d->m_views.at();
759 if ( d->m_viewBuildDocuments.count() == viewIdx )
760 d->m_viewBuildDocuments.append( doc );
761 else if ( d->m_viewBuildDocuments.count() > viewIdx )
762 d->m_viewBuildDocuments[ viewIdx ] = doc;
765TQDomDocument KoDocument::viewBuildDocument(
KoView *view )
769 if ( d->m_views.find( view ) == -1 )
772 uint viewIdx = d->m_views.at();
774 if ( viewIdx >= d->m_viewBuildDocuments.count() )
777 res = d->m_viewBuildDocuments[ viewIdx ];
780 d->m_viewBuildDocuments[ viewIdx ] = TQDomDocument();
787 paintContent( painter, rect, transparent, zoomX, zoomY );
793 TQPtrListIterator<KoDocumentChild> it( d->m_children );
794 for (; it.current(); ++it )
798 paintChild( it.current(), painter, view, zoomX, zoomY );
813 if ( view && view->partManager() )
828 painter.setClipping(
false );
830 painter.setPen( black );
831 painter.fillRect( -5, -5, w + 10, 5, white );
832 painter.fillRect( -5, h, w + 10, 5, white );
833 painter.fillRect( -5, -5, 5, h + 10, white );
834 painter.fillRect( w, -5, 5, h + 10, white );
835 painter.fillRect( -5, -5, w + 10, 5, BDiagPattern );
836 painter.fillRect( -5, h, w + 10, 5, BDiagPattern );
837 painter.fillRect( -5, -5, 5, h + 10, BDiagPattern );
838 painter.fillRect( w, -5, 5, h + 10, BDiagPattern );
844 if ( view->koDocument() ==
this )
848 painter.fillRect( -5, -5, 5, 5, color );
849 painter.fillRect( -5, h, 5, 5, color );
850 painter.fillRect( w, h, 5, 5, color );
851 painter.fillRect( w, -5, 5, 5, color );
852 painter.fillRect( w / 2 - 3, -5, 5, 5, color );
853 painter.fillRect( w / 2 - 3, h, 5, 5, color );
854 painter.fillRect( -5, h / 2 - 3, 5, 5, color );
855 painter.fillRect( w, h / 2 - 3, 5, 5, color );
858 painter.setClipping(
true );
871 TQPtrListIterator<KoDocumentChild> it =
children();
872 for (; it.current(); ++it )
885 TQPtrListIterator<KoDocumentChild> it(
children() );
886 for( ; it.current(); ++it ) {
887 KoDocument* childDoc = it.current()->document();
888 if (childDoc && !it.current()->isDeleted())
893 if ( !childDoc->
saveToStore( _store, TQString::number( i++ ) ) )
908 TQPtrListIterator<KoDocumentChild> it(
children() );
909 for( ; it.current(); ++it ) {
910 KoDocument* childDoc = it.current()->document();
911 if ( childDoc && !it.current()->isDeleted() )
913 if ( !it.current()->saveOasis( store, manifestWriter ) )
924 if ( d->m_doNotSaveExtDoc )
927 d->m_doNotSaveExtDoc =
false;
933 TQPtrListIterator<KoDocumentChild> it =
children();
934 for (; (ch = it.current()); ++it )
941 kdDebug(30003)<<
" save external doc='"<<
url().
url()<<
"'"<<endl;
957 d->lastErrorMessage = TQString();
960 KoStore::Backend backend = KoStore::Auto;
962 if ( d->m_specialOutputFlag == SaveAsKOffice1dot1 )
964 kdDebug(30003) <<
"Saving as KOffice-1.1 format, using a tar.gz" << endl;
965 backend = KoStore::Tar;
970 if ( d->m_specialOutputFlag == SaveAsDirectoryStore )
972 backend = KoStore::Directory;
973 kdDebug(30003) <<
"Saving as uncompressed XML, using directory store." << endl;
975 else if ( d->m_specialOutputFlag == SaveAsFlatXML )
977 kdDebug(30003) <<
"Saving as a flat XML file." << endl;
979 if ( f.open( IO_WriteOnly | IO_Translate ) )
989 kdDebug(30003) <<
"KoDocument::saveNativeFormat nativeFormatMimeType=" <<
nativeFormatMimeType() << endl;
992 TQCString
mimeType = d->outputMimeType;
1000 d->lastErrorMessage = i18n(
"Could not create the file for saving" );
1007 kdDebug(30003) <<
"Saving to OASIS format" << endl;
1013 if ( !
saveOasis( store, manifestWriter ) )
1015 kdDebug(30003) <<
"saveOasis failed" << endl;
1023 kdDebug(30003) <<
"saveChildrenOasis failed" << endl;
1028 if ( store->
open(
"meta.xml" ) )
1030 if ( !d->m_docInfo->saveOasis( store ) || !store->
close() ) {
1038 d->lastErrorMessage = i18n(
"Not able to write '%1'. Partition full?" ).arg(
"meta.xml" );
1043 if ( store->
open(
"Thumbnails/thumbnail.png" ) )
1045 if ( !saveOasisPreview( store, manifestWriter ) || !store->
close() ) {
1046 d->lastErrorMessage = i18n(
"Error while trying to write '%1'. Partition full?" ).arg(
"Thumbnails/thumbnail.png" );
1054 d->lastErrorMessage = i18n(
"Not able to write '%1'. Partition full?" ).arg(
"Thumbnails/thumbnail.png" );
1062 d->lastErrorMessage = i18n(
"Error while trying to write '%1'. Partition full?" ).arg(
"META-INF/manifest.xml" );
1074 if ( d->lastErrorMessage.isEmpty() )
1075 d->lastErrorMessage = i18n(
"Error while saving embedded documents" );
1080 kdDebug(30003) <<
"Saving root" << endl;
1081 if ( store->
open(
"root" ) )
1086 kdDebug(30003) <<
"saveToStream failed" << endl;
1093 d->lastErrorMessage = i18n(
"Not able to write '%1'. Partition full?" ).arg(
"maindoc.xml" );
1097 if ( store->
open(
"documentinfo.xml" ) )
1099 TQDomDocument doc = d->m_docInfo->save();
1102 TQCString s = doc.toCString();
1103 (void)dev.writeBlock( s.data(), s.size()-1 );
1104 (void)store->
close();
1107 if ( store->
open(
"preview.png" ) )
1110 savePreview( store );
1111 (void)store->
close();
1119 kdDebug(30003) <<
"Saving done of url: " <<
url().url() << endl;
1131 TQDomDocument doc =
saveXML();
1133 TQCString s = doc.toCString();
1136 int nwritten = dev->writeBlock( s.data(), s.size()-1 );
1137 if ( nwritten != (
int)s.size()-1 )
1138 kdWarning(30003) <<
"KoDocument::saveToStream wrote " << nwritten <<
" - expected " << s.size()-1 << endl;
1139 return nwritten == (int)s.size()-1;
1145 kdDebug(30003) <<
"Saving document to store " << _path << endl;
1148 if ( _path.startsWith( STORE_PROTOCOL ) )
1149 m_url = KURL( _path );
1151 m_url = KURL( INTERNAL_PREFIX + _path );
1162 if ( _store->
open(
"root" ) )
1170 if ( !_store->
close() )
1180 kdDebug(30003) <<
"Saved document to store" << endl;
1188 TQImage preview ( pix.convertToImage().convertDepth( 32, TQt::ColorOnly ) );
1189 if ( !preview.hasAlphaBuffer() )
1191 preview.setAlphaBuffer(
true );
1195 if ( !io.open( IO_WriteOnly ) )
1197 if ( ! preview.save( &io,
"PNG", 0 ) )
1205bool KoDocument::savePreview(
KoStore* store )
1209 const TQImage preview ( pix.convertToImage().convertDepth( 8, TQt::AvoidDither | TQt::DiffuseDither) );
1211 if ( !io.open( IO_WriteOnly ) )
1213 if ( ! preview.save( &io,
"PNG" ) )
1221 double docWidth, docHeight;
1222 int pixmapSize = TQMAX(size.width(), size.height());
1224 if (m_pageLayout.
ptWidth > 1.0) {
1225 docWidth = m_pageLayout.
ptWidth / 72 * KoGlobal::dpiX();
1226 docHeight = m_pageLayout.
ptHeight / 72 * KoGlobal::dpiY();
1234 double ratio = docWidth / docHeight;
1237 int previewWidth, previewHeight;
1240 previewWidth = (int) pixmapSize;
1241 previewHeight = (int) (pixmapSize / ratio);
1245 previewWidth = (int) (pixmapSize * ratio);
1246 previewHeight = (int) pixmapSize;
1249 pix.resize((
int)docWidth, (int)docHeight);
1251 pix.fill( TQColor( 245, 245, 245 ) );
1253 TQRect rc(0, 0, pix.width(), pix.height());
1261 pix.convertFromImage(pix.convertToImage().smoothScale(previewWidth, previewHeight));
1266TQString KoDocument::autoSaveFile(
const TQString & path )
const
1271 setlocale( LC_NUMERIC,
"C" );
1275 TQString extension = mime->property(
"X-TDE-NativeExtension" ).toString();
1276 if ( path.isEmpty() )
1281 TQString ret = TQDir::homeDirPath() +
"/." + TQString::fromLatin1(
instance()->instanceName()) +
".autosave" + extension;
1287 Q_ASSERT(
url.isLocalFile() );
1288 TQString dir =
url.directory(
false);
1289 TQString filename =
url.fileName();
1290 return dir +
"." + filename +
".autosave" + extension;
1296 TQString asf = autoSaveFile( TQString() );
1298 if ( TQFile::exists( asf ) )
1300 TQDateTime date = TQFileInfo(asf).lastModified();
1301 TQString dateStr = date.toString(TQt::LocalDate);
1303 0, i18n(
"An autosaved file for an unnamed document exists in %1.\nThis file is dated %2\nDo you want to open it?" )
1304 .arg(asf, dateStr) );
1306 case KMessageBox::Yes : {
1314 case KMessageBox::No :
1315 TQFile::remove( asf );
1328 kdDebug (30003) <<
"KoDocument::import url=" << _url.url() << endl;
1329 d->m_isImporting =
true;
1338 kdDebug (30003) <<
"KoDocument::import success, resetting url" << endl;
1343 d->m_isImporting =
false;
1350 kdDebug(30003) <<
"KoDocument::openURL url=" << _url.url() << endl;
1351 d->lastErrorMessage = TQString();
1354 if ( !_url.isValid() )
1356 d->lastErrorMessage = i18n(
"Malformed URL\n%1" ).arg( _url.url() );
1363 bool autosaveOpened =
false;
1364 d->m_bLoading =
true;
1365 if (
url.isLocalFile() && d->m_shouldCheckAutoSaveFile )
1368 TQString asf = autoSaveFile(
file );
1369 if ( TQFile::exists( asf ) )
1374 i18n(
"An autosaved file exists for this document.\nDo you want to open it instead?" ));
1376 case KMessageBox::Yes :
1378 autosaveOpened =
true;
1380 case KMessageBox::No :
1381 TQFile::remove( asf );
1384 d->m_bLoading =
false;
1392 if ( autosaveOpened )
1400 TQPtrListIterator<KoMainWindow> it( d->m_shells );
1401 for (; it.current(); ++it )
1402 it.current()->addRecentURL( _url );
1410 if ( !TQFile::exists(
m_file) )
1412 TQApplication::restoreOverrideCursor();
1413 if ( d->m_autoErrorHandlingEnabled )
1416 d->m_bLoading =
false;
1420 TQApplication::setOverrideCursor( waitCursor );
1422 d->m_specialOutputFlag = 0;
1427 TQString typeName = KMimeType::findByURL( u, 0,
true )->name();
1430 if ( typeName ==
"application/x-trash" )
1432 TQString path = u.path();
1433 TQStringList patterns = KMimeType::mimeType( typeName )->patterns();
1435 for( TQStringList::Iterator it = patterns.begin(); it != patterns.end(); ++it ) {
1437 if ( !ext.isEmpty() && ext[0] ==
'*' )
1440 if ( path.endsWith( ext ) ) {
1441 path.truncate( path.length() - ext.length() );
1446 typeName = KMimeType::findByPath( path, 0,
true )->name();
1450 if ( u.fileName() ==
"maindoc.xml" || u.fileName() ==
"content.xml" || typeName ==
"inode/directory" )
1452 typeName = _native_format;
1453 d->m_specialOutputFlag = SaveAsDirectoryStore;
1454 kdDebug(30003) <<
"KoDocument::openFile loading " << u.fileName() <<
", using directory store for " <<
m_file <<
"; typeName=" << typeName << endl;
1456 kdDebug(30003) <<
"KoDocument::openFile " <<
m_file <<
" type:" << typeName << endl;
1458 TQString importedFile =
m_file;
1461 if ( !d->filterManager )
1464 importedFile = d->filterManager->import(
m_file, status );
1465 if ( status != KoFilter::OK )
1467 TQApplication::restoreOverrideCursor();
1472 case KoFilter::OK:
break;
1474 case KoFilter::CreationError:
1475 msg = i18n(
"Creation error" );
break;
1477 case KoFilter::FileNotFound:
1478 msg = i18n(
"File not found" );
break;
1480 case KoFilter::StorageCreationError:
1481 msg = i18n(
"Cannot create storage" );
break;
1483 case KoFilter::BadMimeType:
1484 msg = i18n(
"Bad MIME type" );
break;
1486 case KoFilter::EmbeddedDocError:
1487 msg = i18n(
"Error in embedded document" );
break;
1489 case KoFilter::WrongFormat:
1490 msg = i18n(
"Format not recognized" );
break;
1492 case KoFilter::NotImplemented:
1493 msg = i18n(
"Not implemented" );
break;
1495 case KoFilter::ParsingError:
1496 msg = i18n(
"Parsing error" );
break;
1498 case KoFilter::PasswordProtected:
1499 msg = i18n(
"Document is password protected" );
break;
1501 case KoFilter::InternalError:
1502 case KoFilter::UnexpectedEOF:
1503 case KoFilter::UnexpectedOpcode:
1504 case KoFilter::StupidError:
1505 case KoFilter::UsageError:
1506 msg = i18n(
"Internal error" );
break;
1508 case KoFilter::OutOfMemory:
1509 msg = i18n(
"Out of memory" );
break;
1511 case KoFilter::UserCancelled:
1512 case KoFilter::BadConversionGraph:
1516 default: msg = i18n(
"Unknown error" );
break;
1519 if( d->m_autoErrorHandlingEnabled && !msg.isEmpty())
1521 TQString errorMsg( i18n(
"Could not open\n%2.\nReason: %1" ) );
1522 TQString docUrl =
url().prettyURL( 0, KURL::StripFileProtocol );
1526 d->m_bLoading =
false;
1529 kdDebug(30003) <<
"KoDocument::openFile - importedFile '" << importedFile
1530 <<
"', status: " <<
static_cast<int>( status ) << endl;
1533 TQApplication::restoreOverrideCursor();
1537 if (!importedFile.isEmpty())
1543 if ( d->m_autoErrorHandlingEnabled )
1550 if ( importedFile !=
m_file )
1569 if(!importedFile.isEmpty()) {
1570 TQFile::remove( importedFile );
1574 if ( ok && d->m_bSingleViewMode )
1581 if ( !d->m_views.isEmpty() )
1584 KoView* v = d->m_views.first();
1589 Q_ASSERT( d->m_views.isEmpty() );
1593 d->m_wrapperWidget->setKoView( view );
1604 setMimeTypeAfterLoading( typeName );
1606 d->m_bLoading =
false;
1611void KoDocument::setMimeTypeAfterLoading(
const TQString& mimeType )
1615 d->outputMimeType = d->mimeType;
1618 setConfirmNonNativeSave(
false, needConfirm );
1619 setConfirmNonNativeSave(
true, needConfirm );
1623bool KoDocument::oldLoadAndParse(
KoStore* store,
const TQString& filename, TQDomDocument& doc)
1627 if (!store->
open(filename))
1629 kdWarning(30003) <<
"Entry " << filename <<
" not found!" << endl;
1630 d->lastErrorMessage = i18n(
"Could not find %1" ).arg( filename );
1635 int errorLine, errorColumn;
1636 bool ok = doc.setContent( store->
device(), &errorMsg, &errorLine, &errorColumn );
1639 kdError(30003) <<
"Parsing error in " << filename <<
"! Aborting!" << endl
1640 <<
" In line: " << errorLine <<
", column: " << errorColumn << endl
1641 <<
" Error message: " << errorMsg << endl;
1642 d->lastErrorMessage = i18n(
"Parsing error in %1 at line %2, column %3\nError message: %4" )
1643 .arg( filename ).arg( errorLine ).arg( errorColumn )
1644 .arg( i18n (
"TQXml", errorMsg.utf8() ) );
1648 kdDebug(30003) <<
"File " << filename <<
" loaded and parsed" << endl;
1654 TQFileInfo fileInfo(
file );
1655 if ( !fileInfo.exists() )
1657 d->lastErrorMessage = i18n(
"The file %1 does not exist.").arg(
file);
1660 if ( !fileInfo.isFile() )
1662 d->lastErrorMessage = i18n(
"%1 is not a file." ).arg(
file);
1666 TQApplication::setOverrideCursor( waitCursor );
1668 kdDebug(30003) <<
"KoDocument::loadNativeFormat( " <<
file <<
" )" << endl;
1671 bool isRawXML =
false;
1672 if ( d->m_specialOutputFlag != SaveAsDirectoryStore )
1675 if ( !in.open( IO_ReadOnly ) )
1677 TQApplication::restoreOverrideCursor();
1678 d->lastErrorMessage = i18n(
"Could not open the file for reading (check read permissions)." );
1684 if ( in.readBlock( buf, 4 ) < 4 )
1686 TQApplication::restoreOverrideCursor();
1688 d->lastErrorMessage = i18n(
"Could not read the beginning of the file." );
1692 isRawXML = (strncasecmp( buf,
"<?xm", 4 ) == 0);
1698 if ( in.readBlock( buf , 1 ) < 1 )
1700 TQApplication::restoreOverrideCursor();
1702 d->lastErrorMessage = i18n(
"Could not read the beginning of the file." );
1705 }
while ( TQChar( buf[0] ).isSpace() );
1706 if ( buf[0] ==
'<' ) {
1707 if ( in.readBlock( buf , 4 ) < 4 )
1709 TQApplication::restoreOverrideCursor();
1711 d->lastErrorMessage = i18n(
"Could not read the beginning of the file." );
1714 isRawXML = (strncasecmp( buf,
"math", 4 ) == 0);
1728 if ( doc.setContent( &in,
true, &errorMsg, &errorLine, &errorColumn ) )
1736 kdError (30003) <<
"Parsing Error! Aborting! (in KoDocument::loadNativeFormat (TQFile))" << endl
1737 <<
" Line: " << errorLine <<
" Column: " << errorColumn << endl
1738 <<
" Message: " << errorMsg << endl;
1739 d->lastErrorMessage = i18n(
"parsing error in the main document at line %1, column %2\nError message: %3" )
1740 .arg( errorLine ).arg( errorColumn ).arg( i18n ( errorMsg.utf8() ) );
1744 TQApplication::restoreOverrideCursor();
1752 return loadNativeFormatFromStore(
file );
1756bool KoDocument::loadNativeFormatFromStore(
const TQString& file )
1758 KoStore::Backend backend = (d->m_specialOutputFlag == SaveAsDirectoryStore) ? KoStore::Directory :
KoStore::Auto;
1763 d->lastErrorMessage = i18n(
"Not a valid KOffice file: %1" ).arg(
file );
1765 TQApplication::restoreOverrideCursor();
1771 if ( store->
hasFile(
"content.xml" ) )
1780 TQApplication::restoreOverrideCursor();
1784 }
else if ( store->
hasFile(
"root" ) )
1789 bool ok = oldLoadAndParse( store,
"root", doc );
1795 TQApplication::restoreOverrideCursor();
1802 kdError(30003) <<
"ERROR: Could not load children" << endl;
1808 kdError(30003) <<
"ERROR: No maindoc.xml" << endl;
1809 d->lastErrorMessage = i18n(
"Invalid document: no file 'maindoc.xml'." );
1811 TQApplication::restoreOverrideCursor();
1815 if ( oasis && store->
hasFile(
"meta.xml" ) ) {
1816 TQDomDocument metaDoc;
1818 if ( oasisStore.loadAndParse(
"meta.xml", metaDoc, d->lastErrorMessage ) ) {
1819 d->m_docInfo->loadOasis( metaDoc );
1822 else if ( !oasis && store->
hasFile(
"documentinfo.xml" ) )
1825 if ( oldLoadAndParse( store,
"documentinfo.xml", doc ) ) {
1827 d->m_docInfo->load( doc );
1833 delete d->m_docInfo;
1834 d->m_docInfo =
new KoDocumentInfo(
this,
"document info" );
1839 TQApplication::restoreOverrideCursor();
1850 doc.setContent( _store->
device() );
1858 kdWarning() <<
"couldn't open " <<
url << endl;
1863 if (
url.startsWith( STORE_PROTOCOL ) ) {
1866 m_url = KURL( INTERNAL_PREFIX +
url );
1872 kdError(30003) <<
"ERROR: Could not load children" << endl;
1889 TQDomDocument contentDoc;
1890 TQDomDocument settingsDoc;
1892 bool ok = oasisStore.
loadAndParse(
"content.xml", contentDoc, d->lastErrorMessage );
1896 TQDomDocument stylesDoc;
1897 (void)oasisStore.
loadAndParse(
"styles.xml", stylesDoc, d->lastErrorMessage );
1910 if ( store->
hasFile(
"settings.xml" ) ) {
1911 (void)oasisStore.
loadAndParse(
"settings.xml", settingsDoc, d->lastErrorMessage );
1913 if ( !
loadOasis( contentDoc, oasisStyles, settingsDoc, store ) )
1919bool KoDocument::isInOperation()
const
1921 return d->m_numOperations > 0;
1924void KoDocument::emitBeginOperation()
1928 if (!isInOperation())
1929 emit sigBeginOperation();
1930 d->m_numOperations++;
1933void KoDocument::emitEndOperation()
1935 d->m_numOperations--;
1938 if (d->m_numOperations == 0)
1939 emit sigEndOperation();
1940 else if (d->m_numOperations < 0)
1942 d->m_numOperations = 0;
1959 if ( mod && !d->modifiedAfterAutosave ) {
1963 d->modifiedAfterAutosave = mod;
1974 TQPtrListIterator<KoDocumentChild> it =
children();
1975 for (; it.current(); ++it )
1990 d->m_doNotSaveExtDoc = on;
1993int KoDocument::queryCloseDia()
2002 if (
name.isEmpty() )
2005 if (
name.isEmpty() )
2006 name = i18n(
"Untitled" );
2009 i18n(
"<p>The document <b>'%1'</b> has been modified.</p><p>Do you want to save it?</p>" ).arg(name));
2013 case KMessageBox::Yes :
2018 case KMessageBox::No :
2028int KoDocument::queryCloseExternalChildren()
2032 TQPtrListIterator<KoDocumentChild> it(
children() );
2033 for (; it.current(); ++it )
2035 if ( !it.current()->isDeleted() )
2041 kdDebug(36001) <<
"========== isStoredExtern() returned "
2042 << foo <<
" ==========" << endl;
2047 kdDebug(30003)<<k_funcinfo<<
" found modified child: "<<doc->
url().url()<<
" extern="<<doc->
isStoredExtern()<<endl;
2048 if ( doc->queryCloseDia() == KMessageBox::Cancel )
2049 return KMessageBox::Cancel;
2052 if ( doc->queryCloseExternalChildren() == KMessageBox::Cancel )
2053 return KMessageBox::Cancel;
2057 return KMessageBox::Ok;
2070 TQPtrListIterator<KoMainWindow> it( d->m_shells );
2071 for (; it.current(); ++it )
2073 it.current()->updateCaption();
2074 it.current()->updateReloadFileAction(
this);
2075 it.current()->updateVersionsFileAction(
this);
2089 KoDocumentInfoPage * page =
documentInfo()->page( TQString::fromLatin1(
"about") );
2091 caption =
static_cast<KoDocumentInfoAbout *
>(page)->title();
2093 if ( caption.isEmpty() )
2094 caption =
url().prettyURL( 0, KURL::StripFileProtocol );
2139 TQDomImplementation impl;
2140 TQString
url = TQString(
"http://www.koffice.org/DTD/%1-%1.dtd").arg(appName).arg(version);
2141 TQDomDocumentType dtype = impl.createDocumentType( tagName,
2142 TQString(
"-//KDE//DTD %1 %1//EN").arg(appName).arg(version),
2145 TQString namespaceURN = TQString(
"http://www.koffice.org/DTD/%1").arg(appName);
2146 TQDomDocument doc = impl.createDocument( namespaceURN, tagName, dtype );
2147 doc.insertBefore( doc.createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\"" ), doc.documentElement() );
2156 writer->
addAttribute(
"xmlns:office", KoXmlNS::office );
2159 if ( qstrcmp( rootElementName,
"office:document-meta" ) != 0 ) {
2160 writer->
addAttribute(
"xmlns:config", KoXmlNS::config );
2164 writer->
addAttribute(
"xmlns:presentation", KoXmlNS::presentation );
2168 writer->
addAttribute(
"xmlns:script", KoXmlNS::script );
2170 writer->
addAttribute(
"xmlns:number", KoXmlNS::number );
2174 writer->
addAttribute(
"xmlns:koffice", KoXmlNS::koffice );
2185 kdError(30003) <<
"KoDocument::saveXML not implemented" << endl;
2186 d->lastErrorMessage = i18n(
"Internal error: saveXML not implemented" );
2187 return TQDomDocument();
2190KService::Ptr KoDocument::nativeService()
2192 if ( !m_nativeService )
2195 return m_nativeService;
2200 KService::Ptr service =
const_cast<KoDocument *
>(
this)->nativeService();
2203 TQCString nativeMimeType = service->property(
"X-TDE-NativeMimeType" ).toString().latin1();
2204 if ( nativeMimeType.isEmpty() ) {
2206 if ( !service->serviceTypes().contains(
"KOfficePart" ) )
2207 kdWarning(30003) <<
"Wrong desktop file, KOfficePart isn't mentionned" << endl;
2208 else if ( !KServiceType::serviceType(
"KOfficePart" ) )
2209 kdWarning(30003) <<
"The KOfficePart service type isn't installed!" << endl;
2211 return nativeMimeType;
2216 KService::Ptr service =
const_cast<KoDocument *
>(
this)->nativeService();
2219 return service->property(
"X-TDE-NativeOasisMimeType" ).toString().latin1();
2226 TQString instname =
instance ?
instance->instanceName() : kapp->instanceName();
2229 TQString servicepartname = instname +
"part.desktop";
2230 KService::Ptr service = KService::serviceByDesktopPath( servicepartname );
2232 kdDebug(30003) << servicepartname <<
" found." << endl;
2240 service = KService::serviceByDesktopPath( TQString::fromLatin1(
"Office/%1.desktop").arg(instname) );
2243 service = KService::serviceByDesktopName( instname );
2254 if ( service->property(
"X-TDE-NativeMimeType" ).toString().isEmpty() )
2257 if ( KServiceType::serviceType(
"KOfficePart" ) == 0L )
2258 kdError(30003) <<
"The serviceType KOfficePart is missing. Check that you have a kofficepart.desktop file in the share/servicetypes directory." << endl;
2260 TQString instname =
instance ?
instance->instanceName() : kapp->instanceName();
2261 if ( instname !=
"koshell" )
2262 kdWarning(30003) << service->desktopEntryPath() <<
": no X-TDE-NativeMimeType entry!" << endl;
2266 return service->property(
"X-TDE-NativeMimeType" ).toString().latin1();
2273 return TQStringList();
2274 return service->property(
"X-TDE-ExtraNativeMimeTypes" ).toStringList();
2279 if ( namespaceProcessing )
2281 reader.setFeature(
"http://xml.org/sax/features/namespaces",
true );
2282 reader.setFeature(
"http://xml.org/sax/features/namespace-prefixes",
false );
2286 reader.setFeature(
"http://xml.org/sax/features/namespaces",
false );
2287 reader.setFeature(
"http://xml.org/sax/features/namespace-prefixes",
true );
2289 reader.setFeature(
"http://trolltech.com/xml/features/report-whitespace-only-CharData",
true );
2306 KService::Ptr service =
const_cast<KoDocument *
>(
this)->nativeService();
2309 return service->property(
"X-TDE-ExtraNativeMimeTypes" ).toStringList();
2317 return SaveAsDirectoryStore;
2322 if ( d->m_shells.findRef( shell ) == -1 )
2325 d->m_shells.append( shell );
2332 d->m_shells.removeRef( shell );
2342 return d->m_shells.count();
2347 if ( !d->m_dcopObject )
2349 return d->m_dcopObject;
2359 d->lastErrorMessage = errMsg;
2364 return d->lastErrorMessage;
2369 if ( d->lastErrorMessage.isEmpty() )
2373 else if ( d->lastErrorMessage !=
"USER_CANCELED" )
2381 if ( d->lastErrorMessage.isEmpty() )
2383 KMessageBox::error( 0L, i18n(
"Could not open\n%1" ).arg(
url().prettyURL( 0, KURL::StripFileProtocol ) ) );
2385 else if ( d->lastErrorMessage !=
"USER_CANCELED" )
2387 KMessageBox::error( 0L, i18n(
"Could not open %1\nReason: %2" ).arg(
url().prettyURL( 0, KURL::StripFileProtocol ), d->lastErrorMessage ) );
2393 return d->m_autosaving;
2398 return d->m_bLoading;
2404 TQString asf = autoSaveFile(
m_file );
2405 if ( TQFile::exists( asf ) )
2406 TQFile::remove( asf );
2407 asf = autoSaveFile( TQString() );
2408 if ( TQFile::exists( asf ) )
2409 TQFile::remove( asf );
2412void KoDocument::setBackupFile(
bool _b )
2414 d->m_backupFile = _b;
2417bool KoDocument::backupFile()
const
2419 return d->m_backupFile;
2425 d->m_backupPath = _path;
2430 return d->m_backupPath;
2471bool KoDocument::isCurrent()
const
2473 return d->m_current;
2478 return d->m_storeInternal;
2483 d->m_storeInternal = i;
2487bool KoDocument::hasExternURL()
const
2489 return !
url().protocol().isEmpty() &&
url().protocol() != STORE_PROTOCOL &&
url().protocol() != INTERNAL_PROTOCOL;
2492void KoDocument::slotStarted( TDEIO::Job* job )
2496 job->setWindow( d->m_shells.current() );
2500static const struct {
2501 const char* localName;
2502 const char* documentType;
2504 {
"text", I18N_NOOP(
"a word processing" ) },
2505 {
"spreadsheet", I18N_NOOP(
"a spreadsheet" ) },
2506 {
"presentation", I18N_NOOP(
"a presentation" ) },
2507 {
"chart", I18N_NOOP(
"a chart" ) },
2508 {
"drawing", I18N_NOOP(
"a drawing" ) }
2510static const unsigned int numTN2DT =
sizeof( TN2DTArray ) /
sizeof( *TN2DTArray );
2514 for (
unsigned int i = 0 ; i < numTN2DT ; ++i )
2515 if ( localName == TN2DTArray[i].localName )
2516 return i18n( TN2DTArray[i].documentType );
2522 return TQValueList<KoTextDocument *>();
2527 return m_pageLayout;
2537 if ( d->m_unit !=
unit )
2552 TDEConfigGroup cfgGrp(
instance()->config(),
"TemplateChooserDialog" );
2553 TQString fullTemplateName = cfgGrp.readPathEntry(
"AlwaysUseTemplate" );
2555 if( !fullTemplateName.isEmpty() ) {
2557 shells().getFirst()->setRootDocument(
this );
2562 if(d->m_startUpWidget){
2563 d->m_startUpWidget->show();
2579 TQTimer::singleShot( 0,
this, TQ_SLOT( deleteOpenPane() ) );
2603void KoDocument::startCustomDocument() {
2608 const TQString& templateType )
2613 openPane->setCustomDocumentWidget( customDoc );
2614 connect( customDoc, TQ_SIGNAL( documentSelected() ),
this, TQ_SLOT( startCustomDocument() ) );
2620 connect( openPane, TQ_SIGNAL(
openTemplate(
const TQString& ) ),
2628 d->m_templateType = _templateType;
2633 return d->m_templateType;
2636void KoDocument::deleteOpenPane()
2638 if( d->m_startUpWidget ) {
2639 d->m_startUpWidget->hide();
2640 TQTimer::singleShot(1000,
this, TQ_SLOT(deleteOpenPaneDelayed()));
2642 shells().getFirst()->factory()->container(
"mainToolBar",
shells().getFirst())->show();
2643 shells().getFirst()->setRootDocument(
this );
2645 emit closeEmbedInitDialog();
2649void KoDocument::deleteOpenPaneDelayed()
2651 delete d->m_startUpWidget;
2652 d->m_startUpWidget = 0;
2663 pane->layout()->setMargin(0);
2666 connect(
this, TQ_SIGNAL(closeEmbedInitDialog()), &dlg, TQ_SLOT(slotOk()));
2668 bool ok = dlg.exec() == TQDialog::Accepted;
2675#include "KoDocument_p.moc"
2676#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 Part * activePart() const
virtual TQWidget * selectedWidget() const
virtual TQWidget * activeWidget() const
virtual Part * selectedPart() const
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)
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.
virtual bool isTransparent() const
It might be interesting for view updates and repainting in general whether a child is transparent or ...
virtual void transform(TQPainter &painter)
Transforms the painter (its worldmatrix and the clipping) in such a way that the painter can be passe...
virtual double xScaling() const
virtual TQRect contentRect() const
virtual double yScaling() const
Holds an embedded object.
KoDocument * document() const
bool isDeleted() const
This document (child) is deleted.
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.
double ptRight
Right margin in pt.
double ptHeight
Page height in pt.
double ptLeft
Left margin in pt.
double ptBottom
Bottom margin in pt.
double ptWidth
Page width in pt.
double ptTop
Top margin in pt.