KDevelop API Documentation

cervisia_plugin.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Mario Scalas                                    *
00003  *   mario.scalas@libero.it                                                *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include <qvbox.h>
00013 #include <qtextedit.h>
00014 #include <klistview.h>
00015 
00016 #include <kinstance.h>
00017 #include <klocale.h>
00018 #include <kgenericfactory.h>
00019 #include <kdebug.h>
00020 #include <kaction.h>
00021 #include <kurl.h>
00022 #include <kmessagebox.h>
00023 #include <kmainwindow.h>
00024 
00025 #include <kparts/part.h>
00026 #include <klibloader.h>
00027 #include <kparts/componentfactory.h>
00028 
00029 #include <kdevmainwindow.h>
00030 #include <kdevcore.h>
00031 #include <kdevproject.h>
00032 
00033 #include "cervisia_plugin.h"
00034 
00035 #include <kdeversion.h>
00036 #if (KDE_VERSION_MINOR==0) && (KDE_VERSION_MAJOR==3)
00037 #include <kdevkurl.h>
00038 #define KURL KdevKURL
00039 #endif
00040 
00041 typedef KGenericFactory<CervisiaPlugin> CervisiaPluginFactory;
00042 K_EXPORT_COMPONENT_FACTORY( libkdevcervisia, CervisiaPluginFactory( "kdevcervisia" ) );
00043 
00044 CervisiaPlugin::CervisiaPlugin(  QObject *parent, const char *name, const QStringList &arguments )
00045     : KDevVersionControl( "CervisiaPlugin", "cervisiaplugin", parent, name ? name : "CervisiaPlugin" ),
00046     m_part( 0 )
00047 {
00048     kdDebug() << "CervisiaPlugin::CervisiaPlugin()" << endl;
00049     // we need an instance
00050     setInstance( CervisiaPluginFactory::instance() );
00051 
00052 //    setXMLFile( "kdevcervisia.rc" );
00053 
00054     m_part = KParts::ComponentFactory::createPartInstanceFromLibrary<KParts::ReadOnlyPart>(
00055         "libcervisiapart", 0, "cervisiapart", this, 0, arguments );
00056     if (!m_part)
00057     {
00058         // @todo fix this brutal return
00059         KMessageBox::error( mainWindow()->main()->centralWidget(),
00060             i18n("Could not find Cervisia KPart. This plug-in will be unusable.") );
00061         return;
00062     }
00063 
00064     // Hmmmm --- try to pilot cervisia opening the sandbox when starting ...
00065     connect( core(), SIGNAL(projectOpened()), this, SLOT(slotProjectOpened()) );
00066     connect( core(), SIGNAL(projectClosed()), this, SLOT(slotProjectClosed()) );
00067 }
00068 
00069 CervisiaPlugin::~CervisiaPlugin()
00070 {
00071     if (m_part)
00072     {
00073         mainWindow()->removeView( m_part->widget() );
00074         mainWindow()->main()->guiFactory()->removeClient( m_part );
00075         m_part->closeURL();
00076         delete m_part;
00077     }
00078 }
00079 
00080 void CervisiaPlugin::slotProjectOpened()
00081 {
00082     if (!m_part)
00083         return;
00084 
00085     // Embed cervisia GUI
00086     mainWindow()->main()->guiFactory()->addClient( m_part );
00087     mainWindow()->embedSelectView( m_part->widget(), i18n("Cervisia"), i18n("Provides CVS Access"));
00088 
00089     KURL projectUrl = KURL::fromPathOrURL( project()->projectDirectory() );
00090     m_part->openURL( projectUrl );
00091 }
00092 
00093 void CervisiaPlugin::slotProjectClosed()
00094 {
00095     if (!m_part)
00096         return;
00097 
00098     // Remove the KPart's GUI since I see no way on how to tell to cervisiapart "deactivate!" ;-)
00099     m_part->closeURL();
00100     mainWindow()->removeView( m_part->widget() );
00101     mainWindow()->main()->guiFactory()->removeClient( m_part );
00102 }
00103 
00104 #include "cervisia_plugin.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 Wed Mar 23 00:03:59 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003