KDevelop API Documentation

qeditor_factory.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
00004 
00005    Based on KHTML Factory from Simon Hausmann <hausmann@kde.org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License version 2 as published by the Free Software Foundation.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 // $Id: qeditor_factory.cpp,v 1.7 2003/02/18 22:44:36 falkbr Exp $
00023 
00024 #include "qeditor_factory.h"
00025 #include "qeditor_part.h"
00026 #include "qeditor_view.h"
00027 
00028 #include <klocale.h>
00029 #include <kinstance.h>
00030 #include <kaboutdata.h>
00031 #include <kdebug.h>
00032 
00033 #include <assert.h>
00034 
00035 template class QPtrList<QEditorPart>;
00036 template class QPtrList<QEditorView>;
00037 
00038 QEditorPartFactory *QEditorPartFactory::s_self = 0;
00039 unsigned long int QEditorPartFactory::s_refcnt = 0;
00040 KInstance *QEditorPartFactory::s_instance = 0;
00041 KAboutData *QEditorPartFactory::s_about = 0;
00042 QPtrList<QEditorPart> *QEditorPartFactory::s_documents = 0;
00043 QPtrList<QEditorView> *QEditorPartFactory::s_views = 0;
00044 KTrader::OfferList *QEditorPartFactory::s_plugins = 0;
00045 
00046 extern "C"
00047 {
00048   void *init_libqeditorpart()
00049   {
00050     return new QEditorPartFactory( true );
00051   }
00052 }
00053 
00054 QEditorPartFactory::QEditorPartFactory( bool clone )
00055 {
00056   if ( clone )
00057   {
00058     ref();
00059     return;
00060   }
00061 }
00062 
00063 QEditorPartFactory::~QEditorPartFactory()
00064 {
00065   if ( s_self == this )
00066   {
00067         assert( !s_refcnt );
00068 
00069         if ( s_instance )
00070             delete s_instance;
00071 
00072         if ( s_about )
00073             delete s_about;
00074 
00075         if ( s_documents )
00076         {
00077             assert( s_documents->isEmpty() );
00078             delete s_documents;
00079         }
00080 
00081         if ( s_views )
00082         {
00083             assert( s_views->isEmpty() );
00084             delete s_views;
00085         }
00086 
00087     if ( s_plugins )
00088       delete s_plugins;
00089 
00090         s_instance = 0;
00091         s_about = 0;
00092         s_documents = 0;
00093         s_views = 0;
00094     s_plugins = 0;
00095     }
00096     else
00097         deref();
00098 }
00099 
00100 void QEditorPartFactory::ref()
00101 {
00102     if ( !s_refcnt && !s_self )
00103     {
00104       s_self = new QEditorPartFactory;
00105     }
00106 
00107     s_refcnt++;
00108 }
00109 
00110 void QEditorPartFactory::deref()
00111 {
00112     if ( !--s_refcnt && s_self )
00113     {
00114         delete s_self;
00115         s_self = 0;
00116     }
00117 }
00118 
00119 KParts::Part *QEditorPartFactory::createPartObject( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const char *classname, const QStringList & args )
00120 {
00121   bool bWantSingleView = !( classname == QString("KTextEditor::Document") );
00122   bool bWantBrowserView = ( classname == QString("Browser/View") );
00123   bool bWantReadOnly = (bWantBrowserView || ( classname == QString("KParts::ReadOnlyPart") ));
00124 
00125   KParts::ReadWritePart *part = new QEditorPart (
00126       /*bWantSingleView, bWantBrowserView, bWantReadOnly, */
00127       parentWidget, widgetName, parent, name, args);
00128   part->setReadWrite( !bWantReadOnly );
00129 
00130   return part;
00131 }
00132 
00133 void QEditorPartFactory::registerDocument ( QEditorPart *doc )
00134 {
00135     if ( !s_documents )
00136         s_documents = new QPtrList<QEditorPart>;
00137 
00138     if ( !s_documents->containsRef( doc ) )
00139     {
00140         s_documents->append( doc );
00141         ref();
00142     }
00143 }
00144 
00145 void QEditorPartFactory::deregisterDocument ( QEditorPart *doc )
00146 {
00147     assert( s_documents );
00148 
00149     if ( s_documents->removeRef( doc ) )
00150     {
00151         if ( s_documents->isEmpty() )
00152         {
00153             delete s_documents;
00154             s_documents = 0;
00155         }
00156 
00157         deref();
00158     }
00159 }
00160 
00161 void QEditorPartFactory::registerView ( QEditorView *view )
00162 {
00163     if ( !s_views )
00164         s_views = new QPtrList<QEditorView>;
00165 
00166     if ( !s_views->containsRef( view ) )
00167     {
00168         s_views->append( view );
00169         ref();
00170     }
00171 }
00172 
00173 void QEditorPartFactory::deregisterView ( QEditorView *view )
00174 {
00175     assert( s_views );
00176 
00177     if ( s_views->removeRef( view ) )
00178     {
00179         if ( s_views->isEmpty() )
00180         {
00181             delete s_views;
00182             s_views = 0;
00183         }
00184 
00185         deref();
00186     }
00187 }
00188 
00189 KTrader::OfferList *QEditorPartFactory::plugins ()
00190 {
00191   if ( !s_plugins )
00192    s_plugins = new QValueList<KService::Ptr> (KTrader::self()->query("KTextEditor/Plugin"));
00193 
00194   return s_plugins;
00195 }
00196 
00197 KInstance *QEditorPartFactory::instance()
00198 {
00199     assert( s_self );
00200 
00201     if ( !s_instance )
00202     {
00203         s_about = new KAboutData("qeditorpart", I18N_NOOP("QEditor (based on the editor of Qt-Designer)"), "0.1");
00204     
00205         s_about->addAuthor("Roberto Raggi", 0, "roberto@kdevelop.org");
00206         s_about->addAuthor("Trolltech AS", 0, "info@trolltech.com");
00207         s_about->addAuthor("The Kate authors", 0, "kwrite-devel@kde.org");
00208     s_about->addAuthor("F@lk Brettschneider", 0, "falk@kdevelop.org");
00209         s_about->addAuthor("Milo Hoffman", 0, "Milo@NG-Projekt.ORG");
00210 
00211         s_instance = new KInstance( s_about );
00212     }
00213 
00214     return s_instance;
00215 }
00216 
00217 const QPtrList<class QEditorPart>& QEditorPartFactory::documents()
00218 {
00219     return *s_documents;
00220 }
00221 
00222 const QPtrList<class QEditorView>& QEditorPartFactory::views()
00223 {
00224     return *s_views;
00225 }
00226 #include "qeditor_factory.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:24 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003