21#include "KoMainWindow.h"
22#include "KoDocument.h"
24#include "KoFilterManager.h"
25#include "KoDocumentInfo.h"
26#include "KoDocumentInfoDlg.h"
27#include "KoQueryTrader.h"
28#include "KoMainWindowIface.h"
30#include "KoFileDialog.h"
31#include "Koversiondialog.h"
35#include <tdeaboutdata.h>
37#include <kstdaction.h>
38#include <tdeapplication.h>
39#include <tdemessagebox.h>
40#include <kstandarddirs.h>
41#include <tdeio/netaccess.h>
42#include <kkeydialog.h>
43#include <kedittoolbar.h>
45#include <kpushbutton.h>
47#include <tdetempfile.h>
48#include <tderecentdocument.h>
49#include <tdeparts/partmanager.h>
50#include <tdeparts/plugin.h>
51#include <tdeparts/event.h>
53#include <kstatusbar.h>
54#include <tdeglobalsettings.h>
55#include <ksharedptr.h>
57#include <tqobjectlist.h>
65 KoPartManager( TQWidget * parent,
const char * name = 0L )
76 virtual bool eventFilter( TQObject *obj, TQEvent *ev )
78 if ( !obj->isWidgetType() || ::tqt_cast<KoFrame *>( obj ) )
80 return KParts::PartManager::eventFilter( obj, ev );
84class KoMainWindowPrivate
92 bMainWindowGUIBuilt =
false;
100 m_toolbarList.setAutoDelete(
true );
107 m_paPrintPreview = 0;
116 m_isImporting =
false;
117 m_isExporting =
false;
118 m_windowSizeDirty =
false;
119 m_lastExportSpecialOutputFlag = 0;
124 m_koSpeaker = kospeaker;
126 m_koSpeaker =
new KoSpeaker();
130 ~KoMainWindowPrivate()
135 KoDocument *m_rootDoc;
136 KoDocument *m_docToOpen;
137 TQPtrList<KoView> m_rootViews;
138 KParts::PartManager *m_manager;
140 KParts::Part *m_activePart;
141 KoView *m_activeView;
143 TQLabel * statusBarLabel;
144 KProgress *m_progress;
146 TQPtrList<TDEAction> m_splitViewActionList;
149 TQPtrList<TDEAction> m_veryHackyActionList;
150 TQSplitter *m_splitter;
151 TDESelectAction *m_orientation;
152 TDEAction *m_removeView;
153 KoMainWindowIface *m_dcopObject;
155 TQPtrList <TDEAction> m_toolbarList;
157 bool bMainWindowGUIBuilt;
161 bool m_windowSizeDirty;
163 TDEAction *m_paDocInfo;
165 TDEAction *m_paSaveAs;
166 TDEAction *m_paPrint;
167 TDEAction *m_paPrintPreview;
168 TDEAction *m_sendfile;
169 TDEAction *m_paCloseFile;
170 TDEAction *m_reloadfile;
171 TDEAction *m_versionsfile;
172 TDEAction *m_importFile;
173 TDEAction *m_exportFile;
178 KURL m_lastExportURL;
179 TQCString m_lastExportFormat;
180 int m_lastExportSpecialOutputFlag;
182 TDESharedPtr<KoSpeaker> m_koSpeaker;
190 d =
new KoMainWindowPrivate;
192 d->m_manager =
new KoPartManager(
this );
194 connect( d->m_manager, TQ_SIGNAL( activePartChanged(
KParts::Part * ) ),
195 this, TQ_SLOT( slotActivePartChanged(
KParts::Part * ) ) );
203 TQStringList allFiles = TDEGlobal::dirs()->findAllResources(
"data",
"koffice/koffice_shell.rc" );
204 setXMLFile( findMostRecentXMLFile( allFiles, doc ) );
205 setLocalXMLFile( locateLocal(
"data",
"koffice/koffice_shell.rc" ) );
219 d->m_reloadfile =
new TDEAction( i18n(
"Reload"), 0,
223 d->m_versionsfile =
new TDEAction( i18n(
"Versions..."), 0,
227 d->m_importFile =
new TDEAction( i18n(
"I&mport..." ), 0,
230 d->m_exportFile =
new TDEAction( i18n(
"E&xport..." ), 0,
236 d->m_paDocInfo =
new TDEAction( i18n(
"&Document Information" ),
"documentinfo", 0,
243 d->m_paDocInfo->setEnabled(
false );
244 d->m_paSaveAs->setEnabled(
false );
245 d->m_reloadfile->setEnabled(
false );
246 d->m_versionsfile->setEnabled(
false );
247 d->m_importFile->setEnabled(
true );
248 d->m_exportFile->setEnabled(
false );
249 d->m_paSave->setEnabled(
false );
250 d->m_paPrint->setEnabled(
false );
251 d->m_paPrintPreview->setEnabled(
false );
252 d->m_sendfile->setEnabled(
false);
253 d->m_paCloseFile->setEnabled(
false);
255 d->m_splitter=
new TQSplitter(TQt::Vertical,
this,
"mw-splitter");
256 setCentralWidget( d->m_splitter );
260 d->m_veryHackyActionList.append(
261 new TDEAction(i18n(
"&Close All Views"),
"window-close",
266 d->m_splitViewActionList.append(
new TDEAction(i18n(
"&Split View"),
"view_split", 0,
269 d->m_removeView=
new TDEAction(i18n(
"&Remove View"),
"view_remove", 0,
270 this, TQ_SLOT(slotRemoveView()),
272 d->m_splitViewActionList.append(d->m_removeView);
273 d->m_removeView->setEnabled(
false);
274 d->m_orientation=
new TDESelectAction(i18n(
"Splitter &Orientation"),
"view_orientation", 0,
275 this, TQ_SLOT(slotSetOrientation()),
278 items << i18n(
"&Vertical")
279 << i18n(
"&Horizontal");
280 d->m_orientation->setItems(items);
281 d->m_orientation->setCurrentItem(
static_cast<int>(d->m_splitter->orientation()));
282 d->m_splitViewActionList.append(d->m_orientation);
283 d->m_splitViewActionList.append(
new TDEActionSeparator(
this));
287 m_recent->loadEntries( config );
290 d->bMainWindowGUIBuilt =
true;
295 const int deskWidth = TDEGlobalSettings::desktopGeometry(
this).width();
296 if (deskWidth > 1100)
305 config->setGroup(
"MainWindow" );
318 d->m_rootDoc->removeShell(
this);
321 if (d->m_docToOpen) {
322 d->m_docToOpen->removeShell(
this);
323 delete d->m_docToOpen;
328 d->m_manager->setActivePart(0);
330 if(d->m_rootViews.findRef(d->m_activeView)==-1) {
331 delete d->m_activeView;
334 d->m_rootViews.setAutoDelete(
true );
335 d->m_rootViews.clear();
340 if ( d->m_rootDoc && d->m_rootDoc->viewCount() == 0 &&
341 !d->m_rootDoc->isEmbedded())
356 if ( d->m_rootDoc == doc )
359 if (d->m_docToOpen && d->m_docToOpen != doc) {
360 d->m_docToOpen->removeShell(
this);
361 delete d->m_docToOpen;
368 TQPtrList<KoView> oldRootViews = d->m_rootViews;
369 d->m_rootViews.clear();
381 d->m_rootViews.append( doc->
createView( d->m_splitter,
"view" ) );
382 d->m_rootViews.current()->setPartManager( d->m_manager );
384 d->m_rootViews.current()->show();
386 if ( !d->m_rootDoc->shells().contains(
this ) )
387 d->m_rootDoc->addShell(
this );
388 d->m_removeView->setEnabled(
false);
389 d->m_orientation->setEnabled(
false);
392 bool enable = d->m_rootDoc != 0 ? true :
false;
393 d->m_paDocInfo->setEnabled( enable );
394 d->m_paSave->setEnabled( enable );
395 d->m_paSaveAs->setEnabled( enable );
396 d->m_importFile->setEnabled( enable );
397 d->m_exportFile->setEnabled( enable );
398 d->m_paPrint->setEnabled( enable );
399 d->m_paPrintPreview->setEnabled( enable );
400 d->m_sendfile->setEnabled( enable);
401 d->m_paCloseFile->setEnabled( enable);
404 d->m_manager->setActivePart( d->m_rootDoc, d->m_rootViews.current() );
406 oldRootViews.setAutoDelete(
true );
407 oldRootViews.clear();
409 if ( oldRootDoc && oldRootDoc->
viewCount() == 0 )
416void KoMainWindow::updateReloadFileAction(
KoDocument *doc)
421void KoMainWindow::updateVersionsFileAction(
KoDocument *doc)
424 d->m_versionsfile->setEnabled( doc && !doc->
url().isEmpty()&&doc->
isModified());
431 d->m_rootViews = views;
432 bool enable = d->m_rootDoc != 0 ? true :
false;
433 d->m_paDocInfo->setEnabled( enable );
434 d->m_paSave->setEnabled( enable );
435 d->m_paSaveAs->setEnabled( enable );
436 d->m_exportFile->setEnabled( enable );
437 d->m_paPrint->setEnabled( enable );
438 d->m_paPrintPreview->setEnabled( enable );
439 d->m_sendfile->setEnabled( enable);
440 d->m_paCloseFile->setEnabled( enable );
445 kdDebug(30003) <<
"KoMainWindow::addRecentURL url=" << url.prettyURL() << endl;
448 if ( !url.isEmpty() )
451 if ( url.isLocalFile() )
453 TQString path = url.path( -1 );
454 TQStringList tmpDirs = TDEGlobal::dirs()->resourceDirs(
"tmp" );
455 for ( TQStringList::Iterator it = tmpDirs.begin() ; ok && it != tmpDirs.end() ; ++it )
456 if ( path.contains( *it ) )
459 TDERecentDocument::add(path);
462 TDERecentDocument::add(url.url(-1),
true);
465 m_recent->addURL( url );
473 TDEConfig * config =
instance() ?
instance()->config() : TDEGlobal::config();
474 kdDebug(30003) <<
this <<
" Saving recent files list into config. instance()=" <<
instance() << endl;
475 m_recent->saveEntries( config );
489 TDEConfig * config =
instance() ?
instance()->config() : TDEGlobal::config();
490 m_recent->loadEntries( config );
512 caption =
static_cast<KoDocumentInfoAbout *
>(page)->title();
514 const TQString url =
rootDocument()->
url().prettyURL( 0, KURL::StripFileProtocol );
515 if ( !caption.isEmpty() && !url.isEmpty() )
516 caption = TQString(
"%1 - %2" ).arg( caption ).arg( url );
517 else if ( caption.isEmpty() )
522 d->m_paSave->setToolTip( i18n(
"Save as %1").arg(
rootDocument()->url().fileName(
false)) );
524 d->m_paSave->setToolTip( i18n(
"Save") );
539KoView *KoMainWindow::rootView()
const
541 if(d->m_rootViews.find(d->m_activeView)!=-1)
542 return d->m_activeView;
543 return d->m_rootViews.first();
553 if ( !TDEIO::NetAccess::exists(url,
true,0) )
556 m_recent->removeURL(url);
560 return openDocumentInternal( url );
566 if (!TDEIO::NetAccess::exists(url,
true,0) )
575 TQString mime = KMimeType::findByURL(url)->name();
576 if ( mime.isEmpty() || mime == KMimeType::defaultMimeType() )
578 if ( url.isLocalFile() )
580 newdoc->setMimeTypeAfterLoading( mime );
584 return openDocumentInternal( url, newdoc );
588bool KoMainWindow::openDocumentInternal(
const KURL & url,
KoDocument *newdoc )
598 connect(newdoc, TQ_SIGNAL(sigProgress(
int)),
this, TQ_SLOT(slotProgress(
int)));
599 connect(newdoc, TQ_SIGNAL(completed()),
this, TQ_SLOT(slotLoadCompleted()));
600 connect(newdoc, TQ_SIGNAL(canceled(
const TQString & )),
this, TQ_SLOT(slotLoadCanceled(
const TQString & )));
609 updateReloadFileAction(newdoc);
610 updateVersionsFileAction( newdoc );
615void KoMainWindow::slotLoadCompleted()
617 kdDebug(30003) <<
"KoMainWindow::slotLoadCompleted" << endl;
619 KoDocument* newdoc = (KoDocument *)(sender());
626 else if ( doc && !doc->
isEmpty() )
641 disconnect(newdoc, TQ_SIGNAL(sigProgress(
int)),
this, TQ_SLOT(slotProgress(
int)));
642 disconnect(newdoc, TQ_SIGNAL(completed()),
this, TQ_SLOT(slotLoadCompleted()));
643 disconnect(newdoc, TQ_SIGNAL(canceled(
const TQString & )),
this, TQ_SLOT(slotLoadCanceled(
const TQString & )));
646void KoMainWindow::slotLoadCanceled(
const TQString & errMsg )
648 kdDebug(30003) <<
"KoMainWindow::slotLoadCanceled" << endl;
649 if ( !errMsg.isEmpty() )
653 KoDocument* newdoc = (KoDocument *)(sender());
654 disconnect(newdoc, TQ_SIGNAL(sigProgress(
int)),
this, TQ_SLOT(slotProgress(
int)));
655 disconnect(newdoc, TQ_SIGNAL(completed()),
this, TQ_SLOT(slotLoadCompleted()));
656 disconnect(newdoc, TQ_SIGNAL(canceled(
const TQString & )),
this, TQ_SLOT(slotLoadCanceled(
const TQString & )));
662void KoMainWindow::slotSaveCanceled(
const TQString &errMsg )
664 kdDebug(30003) <<
"KoMainWindow::slotSaveCanceled" << endl;
665 if ( !errMsg.isEmpty() )
670void KoMainWindow::slotSaveCompleted()
672 kdDebug(30003) <<
"KoMainWindow::slotSaveCompleted" << endl;
673 KoDocument* pDoc = (KoDocument *)(sender());
674 disconnect(pDoc, TQ_SIGNAL(sigProgress(
int)),
this, TQ_SLOT(slotProgress(
int)));
675 disconnect(pDoc, TQ_SIGNAL(completed()),
this, TQ_SLOT(slotSaveCompleted()));
676 disconnect(pDoc, TQ_SIGNAL(canceled(
const TQString & )),
677 this, TQ_SLOT(slotSaveCanceled(
const TQString & )));
681bool KoMainWindow::exportConfirmation(
const TQCString &outputFormat )
683 if (!
rootDocument()->wantExportConfirmation())
return true;
684 KMimeType::Ptr mime = KMimeType::mimeType( outputFormat );
686 const bool neverHeardOfIt = ( mime->name() == KMimeType::defaultMimeType() );
687 TQString comment = neverHeardOfIt ?
688 i18n(
"%1 (unknown file type)" ).arg( outputFormat.data() )
698 i18n(
"<qt>Saving as a %1 may result in some loss of formatting."
699 "<p>Do you still want to save in this format?</qt>" )
700 .arg( TQString(
"<b>%1</b>" ).arg( comment ) ),
701 i18n(
"Confirm Save" ),
702 KStdGuiItem::save (),
703 "NonNativeSaveConfirmation",
712 i18n(
"<qt>Exporting as a %1 may result in some loss of formatting."
713 "<p>Do you still want to export to this format?</qt>" )
714 .arg( TQString(
"<b>%1</b>" ).arg( comment ) ),
715 i18n(
"Confirm Export" ),
717 "NonNativeExportConfirmation",
722 return (ret == KMessageBox::Continue);
732 if ( pDoc->
url().isEmpty() )
741 connect(pDoc, TQ_SIGNAL(sigProgress(
int)),
this, TQ_SLOT(slotProgress(
int)));
742 connect(pDoc, TQ_SIGNAL(completed()),
this, TQ_SLOT(slotSaveCompleted()));
743 connect(pDoc, TQ_SIGNAL(canceled(
const TQString & )),
744 this, TQ_SLOT(slotSaveCanceled(
const TQString & )));
746 KURL oldURL = pDoc->
url();
747 TQString oldFile = pDoc->
file();
749 TQCString oldOutputFormat = pDoc->outputMimeType();
750 int oldSpecialOutputFlag = pDoc->specialOutputFlag();
751 KURL suggestedURL = pDoc->
url();
754 if (mimeFilter.findIndex (oldOutputFormat) < 0 && !
isExporting())
756 kdDebug(30003) <<
"KoMainWindow::saveDocument no export filter for '" << oldOutputFormat <<
"'" << endl;
762 TQString suggestedFilename = suggestedURL.fileName ();
763 if ( !suggestedFilename.isEmpty () )
765 int c = suggestedFilename.findRev (
'.');
767 KMimeType::Ptr mime = KMimeType::mimeType( _native_format );
768 TQString ext = mime->property(
"X-TDE-NativeExtension" ).toString();
772 suggestedFilename += ext;
774 suggestedFilename = suggestedFilename.left (c) + ext;
781 suggestedFilename = suggestedFilename.left (c);
785 suggestedURL.setFileName (suggestedFilename);
794 if ( pDoc->
url().isEmpty() || saveas )
798 bool justChangingFilterOptions =
false;
801 TQString(),
this,
"file dialog",
true);
804 dialog->setCaption( i18n(
"Save Document As") );
806 dialog->setCaption( i18n(
"Export Document As") );
808 dialog->setOperationMode( KFileDialog::Saving );
809 dialog->setSpecialMimeFilter( mimeFilter,
811 isExporting() ? d->m_lastExportSpecialOutputFlag : oldSpecialOutputFlag,
816 TQCString outputFormat = _native_format;
817 int specialOutputFlag = 0;
821 if(dialog->exec()==TQDialog::Accepted) {
822 newURL=dialog->selectedURL();
823 outputFormat=dialog->currentMimeFilter().latin1();
824 specialOutputFlag = dialog->specialEntrySelected();
825 kdDebug(30003) <<
"KoMainWindow::saveDocument outputFormat = " << outputFormat << endl;
828 justChangingFilterOptions = (newURL == pDoc->
url()) &&
829 (outputFormat == pDoc->
mimeType()) &&
830 (specialOutputFlag == oldSpecialOutputFlag);
832 justChangingFilterOptions = (newURL == d->m_lastExportURL) &&
833 (outputFormat == d->m_lastExportFormat) &&
834 (specialOutputFlag == d->m_lastExportSpecialOutputFlag);
842 if ( newURL.isEmpty() )
849 if ( specialOutputFlag == KoDocument::SaveAsDirectoryStore ) {
850 TQString fileName = newURL.fileName();
851 if ( fileName !=
"content.xml" ) {
852 newURL.addPath(
"content.xml" );
858 if ( TDEIO::NetAccess::exists( newURL,
false ,
this ) && !justChangingFilterOptions )
861 i18n(
"A document with this name already exists.\n"\
862 "Do you want to overwrite it?"),
863 i18n(
"Warning") ) == KMessageBox::Yes;
871 bool wantToSave =
true;
876 wantToSave = exportConfirmation( outputFormat );
909 ret = pDoc->
saveAs( newURL );
913 kdDebug(30003) <<
"Successful Save As!" << endl;
918 kdDebug(30003) <<
"Failed Save As!" << endl;
925 ret = pDoc->
exp0rt( newURL );
930 d->m_lastExportURL = newURL;
931 d->m_lastExportFormat = outputFormat;
932 d->m_lastExportSpecialOutputFlag = specialOutputFlag;
949 (needConfirm && exportConfirmation( oldOutputFormat ))
957 kdDebug(30003) <<
"Failed Save!" << endl;
978 if ( wasModified && pDoc->outputMimeType() != _native_format )
983 if (!ret && reset_url)
990void KoMainWindow::closeEvent(TQCloseEvent *e) {
992 saveWindowSettings();
998void KoMainWindow::saveWindowSettings()
1003 instance()->config()->setGroup(
"MainWindow" );
1006 d->m_windowSizeDirty =
false;
1010 TDEGlobal::config()->sync();
1015void KoMainWindow::resizeEvent( TQResizeEvent * e )
1017 d->m_windowSizeDirty =
true;
1018 KParts::MainWindow::resizeEvent( e );
1027 if ( !d->m_forQuit &&
rootDocument()->shellCount() > 1 )
1032 if ( d->m_rootDoc->isEmbedded() )
1036 if ( d->m_rootDoc->isModified() )
1043 if ( name.isEmpty() )
1046 if ( name.isEmpty() )
1047 name = i18n(
"Untitled" );
1050 i18n(
"<p>The document <b>'%1'</b> has been modified.</p><p>Do you want to save it?</p>" ).arg(name),
1052 KStdGuiItem::save(),
1053 KStdGuiItem::discard());
1056 case KMessageBox::Yes : {
1057 d->m_rootDoc->setDoNotSaveExtDoc();
1058 bool isNative = ( d->m_rootDoc->outputMimeType() == d->m_rootDoc->nativeFormatMimeType() );
1063 case KMessageBox::No :
1072 if ( d->m_rootDoc->queryCloseExternalChildren() == KMessageBox::Cancel )
1090 connect(newdoc, TQ_SIGNAL(sigProgress(
int)),
this, TQ_SLOT(slotProgress(
int)));
1091 disconnect(newdoc, TQ_SIGNAL(sigProgress(
int)),
this, TQ_SLOT(slotProgress(
int)));
1093 if ( ( !doc && ( initDocFlags == KoDocument::InitDocFileNew ) ) || ( doc && !doc->
isEmpty() ) )
1104 delete d->m_rootDoc;
1119 KFileDialog *dialog =
new KFileDialog(
":OpenDialog", TQString(),
this,
"file dialog",
true);
1121 dialog->setCaption( i18n(
"Open Document") );
1123 dialog->setCaption( i18n(
"Import Document") );
1127 KoFilterManager::Import,
1129 dialog->setMimeFilter( mimeFilter );
1130 if(dialog->exec()!=TQDialog::Accepted) {
1134 KURL url( dialog->selectedURL() );
1137 if ( url.isEmpty() )
1170 KoDocumentInfoDlg *dlg =
new KoDocumentInfoDlg( docInfo,
this,
"documentInfoDlg" );
1185 saveWindowSettings();
1187 delete d->m_rootDoc;
1201 kdDebug(30003) <<
"KoMainWindow::slotFilePrint : No root view!" << endl;
1205 KPrinter printer(
true );
1206 TQString title = rootView()->koDocument()->documentInfo()->title();
1207 TQString fileName = rootView()->koDocument()->url().fileName();
1210 KMimeType::Ptr mime = KMimeType::mimeType( rootView()->koDocument()->outputMimeType() );
1212 TQString extension = mime->property(
"X-TDE-NativeExtension" ).toString();
1214 if ( fileName.endsWith( extension ) )
1215 fileName.truncate( fileName.length() - extension.length() );
1218 if ( title.isEmpty() )
1220 if ( title.isEmpty() ) {
1225 printer.setDocName( title );
1226 printer.setDocFileName( fileName );
1227 printer.setDocDirectory( rootView()->koDocument()->url().directory() );
1231 rootView()->setupPrinter( printer );
1233 if ( quick || printer.setup(
this ) )
1234 rootView()->print( printer );
1247 kdWarning() <<
"KoMainWindow::slotFilePrint : No root view!" << endl;
1250 KPrinter printer(
false );
1256 printer.setFromTo( printer.minPage(), printer.maxPage() );
1257 printer.setPreviewOnly(
true );
1258 rootView()->setupPrinter( printer );
1260 TQString oldFileName = printer.outputFileName();
1261 printer.setOutputFileName( tmpFile.name() );
1262 int oldNumCopies = printer.numCopies();
1263 printer.setNumCopies( 1 );
1266 TQString oldKDEPreview = printer.option(
"kde-preview" );
1267 printer.setOption(
"kde-preview",
"0" );
1269 rootView()->print(printer);
1273 printer.setOutputFileName( oldFileName );
1274 printer.setNumCopies( oldNumCopies );
1275 printer.setOption(
"kde-preview", oldKDEPreview );
1280 guiFactory()->configureShortcuts();
1299 if( !d->m_activeView )
1303 factory->plugActionList(d->m_activeView,
"view_closeallviews",
1304 d->m_veryHackyActionList);
1307 if(d->m_rootViews.findRef(d->m_activeView)!=-1)
1308 factory->plugActionList(d->m_activeView,
"view_split",
1309 d->m_splitViewActionList );
1329 kdWarning(30003) <<
"slotToolbarToggled : Toolbar " << sender()->name() <<
" not found!" << endl;
1334 TQWidget *tb =
toolBar( tbName);
1335 return !tb->isHidden();
1340 TQWidget * tb =
toolBar( tbName );
1343 kdWarning(30003) <<
"KoMainWindow: toolbar " << tbName <<
" not found." << endl;
1352 TQPtrListIterator<TDEAction> it( d->m_toolbarList );
1353 for ( ; it.current() ; ++it )
1354 if ( !strcmp( it.current()->name(), tbName ) )
1364 d->m_rootViews.append(d->m_rootDoc->createView(d->m_splitter,
"splitted-view"));
1365 d->m_rootViews.current()->show();
1366 d->m_rootViews.current()->setPartManager( d->m_manager );
1367 d->m_manager->setActivePart( d->m_rootDoc, d->m_rootViews.current() );
1368 d->m_removeView->setEnabled(
true);
1369 d->m_orientation->setEnabled(
true);
1378 if(d->m_rootDoc && d->m_rootDoc->isEmbedded()) {
1380 d->m_rootDoc->removeShell(
this);
1381 TQPtrListIterator<KoMainWindow> it(d->m_rootDoc->shells());
1382 while (it.current()) {
1383 it.current()->hide();
1384 delete it.current();
1397void KoMainWindow::slotRemoveView() {
1399 if(d->m_rootViews.findRef(d->m_activeView)!=-1)
1400 view=d->m_rootViews.current();
1402 view=d->m_rootViews.first();
1404 if ( !d->m_rootViews.removeRef(view) )
1405 kdWarning() <<
"view not found in d->m_rootViews!" << endl;
1407 if(d->m_rootViews.count()==1)
1413 d->m_manager->setActivePart( 0, 0 );
1418 d->m_rootViews.first()->setPartManager( d->m_manager );
1419 d->m_manager->setActivePart( d->m_rootDoc, d->m_rootViews.first() );
1421 if(d->m_rootViews.count()==1)
1422 d->m_splitted=
false;
1425void KoMainWindow::slotSetOrientation() {
1426 d->m_splitter->setOrientation(
static_cast<TQt::Orientation
>
1427 (d->m_orientation->currentItem()));
1430void KoMainWindow::slotProgress(
int value) {
1433 if ( d->m_progress )
1435 statusBar()->removeWidget(d->m_progress);
1436 delete d->m_progress;
1439 d->m_firstTime=
true;
1446 TQObjectList *l = queryList(
"TQStatusBar" );
1447 if ( !l || !l->first() ) {
1449 TQApplication::sendPostedEvents(
this, TQEvent::ChildInserted );
1454 if ( d->m_progress )
1456 statusBar()->removeWidget(d->m_progress);
1457 delete d->m_progress;
1461 d->m_progress=
new KProgress(
statusBar());
1463 statusBar()->addWidget( d->m_progress, 0,
true );
1464 d->m_progress->show();
1465 d->m_firstTime=
false;
1467 d->m_progress->setProgress(value);
1468 kapp->processEvents();
1472void KoMainWindow::slotActivePartChanged(
KParts::Part *newPart )
1482 if ( d->m_activePart && d->m_activePart == newPart && !d->m_splitted )
1488 KXMLGUIFactory *
factory = guiFactory();
1490 setUpdatesEnabled(
false );
1492 if ( d->m_activeView )
1494 KParts::GUIActivateEvent ev(
false );
1495 TQApplication::sendEvent( d->m_activePart, &ev );
1496 TQApplication::sendEvent( d->m_activeView, &ev );
1499 factory->removeClient( d->m_activeView );
1502 d->m_toolbarList.clear();
1505 if ( !d->bMainWindowGUIBuilt )
1512 if ( newPart && d->m_manager->activeWidget() && d->m_manager->activeWidget()->inherits(
"KoView" ) )
1514 d->m_activeView = (KoView *)d->m_manager->activeWidget();
1515 d->m_activePart = newPart;
1518 factory->addClient( d->m_activeView );
1522 factory->plugActionList(d->m_activeView,
"view_closeallviews",
1523 d->m_veryHackyActionList);
1525 if(d->m_rootViews.findRef(d->m_activeView)!=-1)
1526 factory->plugActionList(d->m_activeView,
"view_split", d->m_splitViewActionList );
1533 TQPtrList<TQWidget> toolBarList =
factory->containers(
"ToolBar" );
1534 TQPtrListIterator<TQWidget> it( toolBarList );
1535 for ( ; it.current() ; ++it )
1537 if ( it.current()->inherits(
"TDEToolBar") )
1539 TDEToolBar * tb =
static_cast<TDEToolBar *
>(it.current());
1540 TDEToggleAction * act =
new TDEToggleAction( i18n(
"Show %1 Toolbar").arg( tb->
text() ), 0,
1543 connect( act, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT(
slotToolbarToggled(
bool ) ) );
1545 d->m_toolbarList.append( act );
1548 kdWarning(30003) <<
"Toolbar list contains a " << it.current()->className() <<
" which is not a toolbar!" << endl;
1554 KParts::GUIActivateEvent ev(
true );
1555 TQApplication::sendEvent( d->m_activePart, &ev );
1556 TQApplication::sendEvent( d->m_activeView, &ev );
1560 d->m_activeView = 0L;
1561 d->m_activePart = 0L;
1563 setUpdatesEnabled(
true );
1568 if ( !d->statusBarLabel )
1570 d->statusBarLabel =
new TQLabel(
statusBar() );
1571 statusBar()->addWidget( d->statusBarLabel, 1,
true );
1573 return d->statusBarLabel;
1578 m_recent->setMaxItems( _number );
1583 if ( !d->m_dcopObject )
1585 d->m_dcopObject =
new KoMainWindowIface(
this );
1588 return d->m_dcopObject;
1599 TQString theSubject;
1608 TQCString
const tmp_mimetype =
rootDocument()->outputMimeType();
1611 u.setPath(tmpfile.name());
1618 fileURL = tmpfile.name();
1619 theSubject = i18n(
"Document");
1620 urls.append( fileURL );
1629 theSubject = i18n(
"Document - %1").arg(
rootDocument()->url().fileName(
false));
1630 urls.append( fileURL );
1633 kdDebug(30003) <<
"(" << fileURL <<
")" << endl;
1635 if (!fileURL.isEmpty())
1637 kapp->invokeMailer(TQString(), TQString(), TQString(), theSubject,
1646 KoVersionDialog *dlg =
new KoVersionDialog(
this );
1658 i18n(
"You will lose all your changes!\n"
1659 "Do you want to continue?"),
1660 i18n(
"Warning") ) == KMessageBox::Yes;
1664 KURL url = pDoc->
url();
1665 if ( pDoc && !pDoc->
isEmpty() )
1668 delete d->m_rootDoc;
1678 kdDebug(30003) <<
"slotImportFile()" << endl;
1680 d->m_isImporting =
true;
1682 d->m_isImporting =
false;
1687 kdDebug(30003) <<
"slotExportFile()" << endl;
1689 d->m_isExporting =
true;
1691 d->m_isExporting =
false;
1696 return d->m_isImporting;
1701 return d->m_isExporting;
1706 d->m_docToOpen = doc;
1709#include <KoMainWindow.moc>
This file is part of the KDE/KOffice project.
KKbdAccessExtensions is an object that improves accessibility for motor impaired users who may not be...
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
static int questionYesNo(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)
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)
static int warningContinueCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonContinue=KStdGuiItem::cont(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
MainWindow(TQWidget *parent, const char *name=0L, WFlags f=(WFlags)(WType_TopLevel|WDestructiveClose))
virtual void setInstance(TDEInstance *instance)
void setIgnoreScrollBars(bool ignore)
PartManager(TQWidget *parent, const char *name=0L)
void setActivationButtonMask(short int buttonMask)
void setSelectionPolicy(SelectionPolicy policy)
void setAllowNestedParts(bool allow)
virtual void setSelectable(bool selectable)
static void loadPlugins(TQObject *parent, const TDEInstance *instance)
virtual bool saveAs(const KURL &url)
void plugActionList(const TQString &name, const TQPtrList< TDEAction > &actionList)
void unplugActionList(const TQString &name)
virtual TDEInstance * instance() const
virtual void setXMLFile(const TQString &file, bool merge=false, bool setXMLDoc=true)
KXMLGUIFactory * factory() const
virtual TDEActionCollection * actionCollection() const
Represents an available KOffice component that supports the document interface.
KoDocument * createDoc(KoDocument *parent=0, const char *name=0) const
Uses the factory of the component to create a document.
The KOffice document class.
void resetURL()
Sets the document URL to empty URL KParts doesn't allow this, but KOffice apps have e....
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...
bool checkAutoSaveFile()
Called by koApplication to check for an autosave file in $HOME.
KoView * createView(TQWidget *parent=0, const char *name=0)
Create a new view for the document.
static TQCString readNativeFormatMimeType(TDEInstance *instance=0)
Used by KoApplication, and by KoMainWindow, when no document exists yet.
virtual TQStringList extraNativeMimeTypes() const
Returns a list of the mimetypes considered "native", i.e.
bool isNativeFormat(const TQCString &mimetype) const
Checks whether a given mimetype can be handled natively.
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.
static TQStringList readExtraNativeMimeTypes(TDEInstance *instance=0)
Used by KoMainWindow, when no document exists yet.
TQCString mimeType() const
Returns the actual mimetype of the document.
bool isEmbedded() const
Is the document embedded?
bool import(const KURL &url)
Opens the document given by url, without storing the URL in the KoDocument.
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 ...
virtual void addShell(KoMainWindow *shell)
Appends the shell to the list of shells which show this document as their root document.
virtual void setModified(bool _mod)
Sets the modified flag on the document.
virtual void initEmpty()
Initialize an empty document using default values.
virtual bool openURL(const KURL &url)
Reimplemented from KParts::ReadWritePart for internal reasons (for the autosave functionality).
KoDocumentInfo * documentInfo() const
virtual TQCString nativeFormatMimeType() const
To be preferred when a document exists.
bool exp0rt(const KURL &url)
Saves the document as url without changing the state of the KoDocument (URL, modified flag etc....
void setURL(const KURL &url)
Sets the document URL to url KParts doesn't really allow this, but it is needed for undo of setStoreI...
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.
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 setFile(const TQString &file)
Only use these functions to restore m_file (in KoMainWindow) after a failed save (remember to use set...
virtual void setTitleModified()
Tells the document that its title has been modified, either because the modified status changes (this...
Extension to KFileDialog in order to add special entries to the filter combo, like "save as koffice-1...
static TQStringList mimeFilter()
The same method as KoFilterManager::mimeFilter but suited for KoShell.
bool isImporting() const
Returns whether or not the current slotFileOpen() or openDocument() call is actually an import operat...
KoMainWindow(TDEInstance *instance, const char *_name=0)
Constructor.
virtual void slotToolbarToggled(bool toggle)
Shows or hides a toolbar.
void slotEmailFile()
Slot for eMailing the document using KMail.
virtual void slotConfigureKeys()
Configure key bindings.
void slotFilePrintPreview()
Show a print preview.
virtual void slotConfigureToolbars()
Configure toolbars.
virtual void slotNewToolbarConfig()
Post toolbar config.
virtual void slotDocumentInfo()
Show a dialog with author and document information.
void setRootDocumentDirect(KoDocument *doc, const TQPtrList< KoView > &views)
Special method for KOShell, to allow switching the root document (and its views) among a set of them.
virtual void slotFileClose()
Closes the document.
void slotImportFile()
File --> Import.
void saveRecentFiles()
Save the list of recent files.
bool isExporting() const
Returns whether or not the current slotFileSave[As]() or saveDocument() call is actually an export op...
void slotReloadFile()
Reload file.
virtual bool saveDocument(bool saveas=false, bool silent=false)
Saves the document, asking for a filename if necessary.
void print(bool quick)
Prints the document.
virtual void slotSplitView()
View splitting stuff.
void setDocToOpen(KoDocument *doc)
This is used to handle the document used at start up before it actually added as root document.
virtual bool queryClose()
Ask user about saving changes to the document upon exit.
virtual void setRootDocument(KoDocument *doc)
Called when a document is assigned to this mainwindow.
void slotExportFile()
File --> Export.
TQLabel * statusBarLabel()
Get hold of the label in the statusbar, to write messages to it.
virtual void slotFileOpen()
Slot for opening a saved file.
~KoMainWindow()
Destructor.
virtual void slotFilePrint()
Prints the actual document.
virtual void slotFileSave()
Saves the current document with the current name.
virtual KoDocument * createDoc() const
Create a new empty document.
virtual void slotCloseAllViews()
Close all views.
void saveDialogShown()
This signals is emmitted before the save dialog is shown.
virtual void slotFileSaveAs()
Saves the current document with a new name.
virtual void slotFileOpenRecent(const KURL &)
Slot for opening a file among the recently opened files.
void slotVersionsFile()
This will call a dialogbox to add version to list of files.
void showToolbar(const char *tbName, bool shown)
The application should call this to show or hide a toolbar.
virtual KoDocument * rootDocument() const
Retrieves the document that is displayed in the mainwindow.
bool toolbarIsVisible(const char *tbName)
void setMaxRecentItems(uint _number)
Sets the maximum number of recent documents entries.
virtual bool openDocument(const KURL &url)
Load the desired document and show it.
void addRecentURL(const KURL &url)
The document opened a URL -> store into recent documents list.
virtual void slotFileQuit()
Closes the shell.
void reloadRecentFileList()
Reloads the recent documents list.
virtual void updateCaption()
Update caption from document info - call when document info (title in the about page) changes.
void chooseNewDocument(int initDocFlags)
Helper method for slotFileNew and slotFileClose.
void documentSaved()
This signal is emitted if the document has been saved successfully.
virtual void slotFileNew()
Slot for opening a new document.
static bool isKttsdInstalled()
Returns whether the KTTSD deamon is installed in the system.
This class is used to display a KoDocument.
virtual void setEnabled(bool enable)
TDEToolBar * toolBar(const char *name=0)
void setStandardToolBarMenuEnabled(bool enable)
virtual void setCaption(const TQString &caption)
bool initialGeometrySet() const
void saveMainWindowSettings(TDEConfig *config, const TQString &groupName=TQString::null)
void resetAutoSaveSettings()
void saveWindowSize(TDEConfig *config) const
static TQPtrList< TDEMainWindow > * memberList
virtual void closeEvent(TQCloseEvent *)
void restoreWindowSize(TDEConfig *config)
void setAutoSaveSettings(const TQString &groupName=TQString::fromLatin1("MainWindow"), bool saveWindowSize=true)
void applyMainWindowSettings(TDEConfig *config, const TQString &groupName, bool force)
TDEMainWindow(TQWidget *parent=0, const char *name=0, WFlags f=(WFlags)(WType_TopLevel|WDestructiveClose))
void setCheckedState(const KGuiItem &checkedItem)
virtual void setChecked(bool)
This file is part of the KDE/KOffice project.
TDEAction * close(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * save(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDERecentFilesAction * openRecent(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * configureToolbars(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * mail(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * open(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * quit(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * printPreview(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * openNew(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * saveAs(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * print(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
const char * name(StdAction id)
TDEAction * keyBindings(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)