40
43
#include <koView.h>
41
44
#include <koPartSelectDia.h>
42
45
#include <koFilterManager.h>
46
#include <kiconloader.h>
44
48
KoShellWindow::KoShellWindow()
45
49
: KoMainWindow( KGlobal::instance() )
47
51
m_activePage = m_lstPages.end();
49
m_pLayout = new QHBox( this );
53
m_pLayout = new QHBox( centralWidget() );
51
55
m_pKoolBar = new KoKoolBar( m_pLayout );
53
setCentralWidget( m_pLayout );
55
57
m_pFrame = new KoShellFrame( m_pLayout );
57
59
m_grpFile = m_pKoolBar->insertGroup(i18n("Parts"));
58
QValueList<KoDocumentEntry> lstComponents = KoDocumentEntry::query();
60
QValueList<KoDocumentEntry> lstComponents = KoDocumentEntry::query(false,QString());
59
61
QValueList<KoDocumentEntry>::Iterator it = lstComponents.begin();
60
62
for( ; it != lstComponents.end(); ++it )
62
//kdDebug() << "Inserting into koolbar : " << (*it).name << endl;
63
int id = m_pKoolBar->insertItem( m_grpFile,
64
//kdDebug() << "Inserting into koolbar : " << (*it).name() << endl;
66
if (!(*it).service()->genericName().isEmpty()) //skip the unavailable part
67
id = m_pKoolBar->insertItem( m_grpFile,
64
68
DesktopIcon((*it).service()->icon()),
66
70
this, SLOT( slotKoolBar( int, int ) ) );
67
74
m_mapComponents[ id ] = *it;
69
76
// Build list of patterns for all supported KOffice documents...
87
94
m_pKoolBar->setFixedWidth( 80 );
88
95
m_pKoolBar->setMinimumHeight( 300 );
97
connect( this, SIGNAL( documentSaved() ),
98
this, SLOT( slotNewDocumentName() ) );
90
100
// Not implemented yet
91
101
actionCollection()->action("view_split")->setEnabled(false);
92
102
actionCollection()->action("view_splitter_orientation")->setEnabled(false);
104
m_client = new KoShellGUIClient( this );
95
108
KoShellWindow::~KoShellWindow()
97
110
//kdDebug() << "KoShellWindow::~KoShellWindow()" << endl;
112
// Set the active part to 0 (as we do in ~KoMainWindow, but this is too
113
// late for KoShell, it gets activePartChanged signals delivered to a dead
114
// KoShellWindow object).
115
partManager()->setActivePart(0);
99
117
// Destroy all documents - queryClose has made sure we saved them first
100
118
QValueList<Page>::ConstIterator it = m_lstPages.begin();
101
119
for (; it != m_lstPages.end(); ++it )
108
126
m_lstPages.clear();
110
setRootDocumentDirect( 0L, QList<KoView>() ); // prevent our parent destructor from doing stupid things
113
QString KoShellWindow::nativeFormatName() const
115
return i18n("KOffice Documents");
118
QString KoShellWindow::nativeFormatPattern() const
120
return m_filter; // "*.kwd *.ksp *.kpr";
123
bool KoShellWindow::openDocument( const KURL & url )
125
return openDocumentInternalKoShell( 0L, url );
128
// Should be openDocumentInternal if it was virtual in KoMainWindow
129
bool KoShellWindow::openDocumentInternalKoShell( KoFilterManager * filterManager, const KURL &url )
128
setRootDocumentDirect( 0L, QPtrList<KoView>() ); // prevent our parent destructor from doing stupid things
131
bool KoShellWindow::openDocumentInternal( const KURL &url, KoDocument* )
133
// Here we have to distinguish two cases: The passed URL has a native
134
// KOffice mimetype. Then we query the trader and create the document.
135
// The file is loaded and everyone's happy.
136
// The second case is a non-native file. Here we have to create a
137
// filter manager, ask it to convert the file to the "closest" available
138
// KOffice part and open the temporary file.
131
139
KMimeType::Ptr mimeType = KMimeType::findByURL( url );
132
140
m_documentEntry = KoDocumentEntry::queryByMimeType( mimeType->name().latin1() );
133
if ( m_documentEntry.isEmpty() )
142
KTempFile* tmpFile = 0;
143
KURL tmpUrl( url ); // we might have to load a converted temp. file
145
if ( m_documentEntry.isEmpty() ) { // non-native
146
tmpFile = new KTempFile;
148
KoFilterManager *manager = new KoFilterManager( url.path() );
149
QCString mimetype; // an empty mimetype means, that the "nearest"
150
KoFilter::ConversionStatus status = manager->exp0rt( tmpFile->name(), mimetype ); // KOffice part will be chosen
153
if ( status != KoFilter::OK || mimetype.isEmpty() ) {
159
// If the conversion was successful we get the mimetype of the
160
// chosen KOffice part back.
161
m_documentEntry = KoDocumentEntry::queryByMimeType( mimetype );
162
if ( m_documentEntry.isEmpty() ) {
168
// Open the temporary file
169
tmpUrl.setPath( tmpFile->name() );
136
172
m_recent->addURL( url );
138
174
KoDocument* newdoc = m_documentEntry.createDoc();
140
// Pass the filterManager to the document (who will own it from now on)
142
newdoc->setFilterManager( filterManager );
144
176
connect(newdoc, SIGNAL(sigProgress(int)), this, SLOT(slotProgress(int)));
145
177
connect(newdoc, SIGNAL(completed()), this, SLOT(slotKSLoadCompleted()));
146
178
connect(newdoc, SIGNAL(canceled( const QString & )), this, SLOT(slotKSLoadCanceled( const QString & )));
147
if ( !newdoc || !newdoc->openURL( url ) )
179
newdoc->addShell( this ); // used by openURL
180
bool openRet = (!isImporting ()) ? newdoc->openURL(tmpUrl) : newdoc->import(tmpUrl);
181
if ( !newdoc || !openRet )
192
//if the laoded file has been a temporary file
193
//we need to correct a few document settings
194
//see description of bug #77574 for additional information
196
//correct (output) mime type: we need to set it to the non-native format
197
//to make sure the user knows about saving to a non-native mime type
198
//setConfirmNonNativeSave is set to true below
199
newdoc->setMimeType( mimeType->name().latin1() );
200
newdoc->setOutputMimeType( mimeType->name().latin1() );
202
//the next time the user saves the document he should be warned
203
//because of mime type settings done above;
204
newdoc->setConfirmNonNativeSave(true,true); //exporting,warn_on
205
newdoc->setConfirmNonNativeSave(false,true); //save/save as,warn_on
207
//correct document file (should point to URL)
208
newdoc->setFile( url.path() );
210
//correct document URL
211
newdoc->setURL( url );
213
//update caption to represent the correct URL in the window titlebar
156
223
void KoShellWindow::slotKSLoadCompleted()
158
225
KoDocument* newdoc = (KoDocument *)(sender());
227
// KoDocument::import() calls resetURL() too late...
228
// ...setRootDocument will show the URL...
229
// So let's stop this from happening and the user will never know :)
230
if (isImporting()) newdoc->resetURL ();
159
232
partManager()->addPart( newdoc, false );
160
233
setRootDocument( newdoc );
161
234
disconnect(newdoc, SIGNAL(sigProgress(int)), this, SLOT(slotProgress(int)));
232
312
if ( rootDocument()->documentInfo() )
234
KoDocumentInfoPage * page = rootDocument()->documentInfo()->page( QString::fromLatin1("about"));
236
name = static_cast<KoDocumentInfoAbout *>(page)->title();
314
name = rootDocument()->documentInfo()->title();
238
316
if ( name.isEmpty() )
239
// Fall back to document URL
240
name = rootDocument()->url().fileName();
317
// Fall back to document URL
318
name = rootDocument()->url().fileName();
242
if ( !name.isEmpty() ) // else keep No name
320
if ( !name.isEmpty() ) // else keep Untitled
244
if ( name.length() > 20 )
250
m_pKoolBar->renameItem( m_grpDocuments, (*it).m_id, name );
322
if ( name.length() > 20 )
327
m_pKoolBar->renameItem( m_grpDocuments, (*it).m_id, name );
334
426
setRootDocument( newdoc );
337
// ### This is an ugly copy of KoMainWindow::slotFileOpen, due to the fact
338
// that openDocumentInternal isn't virtual
339
429
void KoShellWindow::slotFileOpen()
341
431
KFileDialog *dialog=new KFileDialog(QString::null, QString::null, 0L, "file dialog", true);
342
dialog->setCaption( i18n("Open document") );
343
KoFilterManager * filterManager = new KoFilterManager;
344
filterManager->prepareDialog(dialog, KoFilterManager::Import,
345
KoDocument::readNativeFormatMimeType(),
346
nativeFormatPattern(), nativeFormatName(), true);
433
dialog->setCaption( i18n("Open Document") );
435
dialog->setCaption( i18n("Import Document") );
436
dialog->setMimeFilter( KoFilterManager::mimeFilter() );
348
439
if(dialog->exec()==QDialog::Accepted) {
349
440
url=dialog->selectedURL();
426
510
bool KoShellWindow::queryClose()
428
512
// Save current doc and views
429
QList<KoView> currentViews;
513
QPtrList<KoView> currentViews;
430
514
KoDocument * currentDoc = 0L;
432
516
if (m_activePage != m_lstPages.end())
434
518
currentDoc = (*m_activePage).m_pDoc;
435
519
currentViews.append((*m_activePage).m_pView);
437
521
// This one is called by slotFileQuit and by the X button.
438
522
// We have to check for unsaved docs...
440
524
QValueList<Page>::Iterator it = m_lstPages.begin();
441
525
for( ; it != m_lstPages.end(); ++it )
443
527
// This is quite a HACK
444
528
// We should ask ourselves, to get a better dialog box
445
setRootDocumentDirect( (*it).m_pDoc, QList<KoView>() );
529
setRootDocumentDirect( (*it).m_pDoc, QPtrList<KoView>() );
446
530
// Test if we can close this doc
447
531
if ( !KoMainWindow::queryClose() )
500
589
m_pView->setGeometry( 0, 0, width(), height() );
592
KoShellGUIClient::KoShellGUIClient( KoShellWindow *window ) : KXMLGUIClient()
594
setXMLFile( "koshellui.rc", true, false );
596
sidebar = new KToggleAction(i18n("Show Sidebar"), "view_choose", 0, window,
597
SLOT( slotShowSidebar() ), actionCollection(), "show_sidebar");
598
sidebar->setChecked( true );
503
601
#include "koshell_shell.moc"