KoApplicationIface.cc
00001 /* This file is part of the KDE project 00002 Copyright (C) 2000 David Faure <faure@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include "KoApplicationIface.h" 00021 #include "koApplication.h" 00022 #include "koDocument.h" 00023 #include "koMainWindow.h" 00024 #include "koView.h" 00025 #include "koQueryTrader.h" 00026 #include "KoDocumentIface.h" 00027 #include <dcopclient.h> 00028 #include <kdebug.h> 00029 #include <stdlib.h> 00030 00031 KoApplicationIface::KoApplicationIface() 00032 : DCOPObject( "KoApplicationIface" ) 00033 { 00034 } 00035 00036 KoApplicationIface::~KoApplicationIface() 00037 { 00038 } 00039 00040 DCOPRef KoApplicationIface::createDocument( const QString &nativeFormat ) 00041 { 00042 KoDocumentEntry entry = KoDocumentEntry::queryByMimeType( nativeFormat ); 00043 if ( entry.isEmpty() ) 00044 { 00045 kdError(30003) << "Unknown KOffice MimeType " << nativeFormat << ". Check your installation !" << endl; 00046 ::exit(1); 00047 } 00048 KoDocument* doc = entry.createDoc( 0 ); 00049 return DCOPRef( kapp->dcopClient()->appId(), doc->dcopObject()->objId() ); 00050 } 00051 00052 QValueList<DCOPRef> KoApplicationIface::getDocuments() 00053 { 00054 QValueList<DCOPRef> lst; 00055 QPtrList<KoDocument> *documents = KoDocument::documentList(); 00056 if ( documents ) 00057 { 00058 QPtrListIterator<KoDocument> it( *documents ); 00059 for (; it.current(); ++it ) 00060 lst.append( DCOPRef( kapp->dcopClient()->appId(), it.current()->dcopObject()->objId() ) ); 00061 } 00062 return lst; 00063 } 00064 00065 QValueList<DCOPRef> KoApplicationIface::getViews() 00066 { 00067 QValueList<DCOPRef> lst; 00068 QPtrList<KoDocument> *documents = KoDocument::documentList(); 00069 if ( documents ) 00070 { 00071 QPtrListIterator<KoDocument> it( *documents ); 00072 for (; it.current(); ++it ) 00073 { 00074 QPtrListIterator<KoView> itview( it.current()->views() ); 00075 for ( ; itview.current(); ++itview ) 00076 lst.append( DCOPRef( kapp->dcopClient()->appId(), itview.current()->dcopObject()->objId() ) ); 00077 } 00078 } 00079 return lst; 00080 } 00081 00082 QValueList<DCOPRef> KoApplicationIface::getWindows() 00083 { 00084 QValueList<DCOPRef> lst; 00085 QPtrList<KMainWindow> *mainWindows = KMainWindow::memberList; 00086 if ( mainWindows ) 00087 { 00088 QPtrListIterator<KMainWindow> it( *mainWindows ); 00089 for (; it.current(); ++it ) 00090 lst.append( DCOPRef( kapp->dcopClient()->appId(), 00091 static_cast<KoMainWindow *>(it.current())->dcopObject()->objId() ) ); 00092 } 00093 return lst; 00094 }