plugin.cpp

Go to the documentation of this file.
00001 /* ============================================================
00002  * File   : plugin.cpp
00003  * Authors: KIPI team developers (see AUTHORS files for details)
00004  *          
00005  * Date   : 2004-02
00006  * Description :
00007  *
00008  * Copyright 2004 by the KIPI team
00009  * 
00010  * This program is free software; you can redistribute it
00011  * and/or modify it under the terms of the GNU Library General
00012  * Public License as published by the Free Software Foundation;
00013  * either version 2, or (at your option)
00014  * any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Library General Public License for more details.
00020  *
00021  * ============================================================ */
00022 
00023 // Qt includes.
00024  
00025 #include <qwidget.h>
00026 
00027 // KDE includes.
00028 
00029 #include <kaction.h>
00030 #include <kinstance.h>
00031 #include <kdebug.h>
00032 
00033 // Local includes.
00034 
00035 #include "plugin.h"
00036 
00037 
00038 struct KIPI::Plugin::Private {
00039     QMap<QWidget*, KActionCollection*> m_actionCollection;
00040     KInstance* m_instance;
00041     QMap<QWidget*, KActionPtrList> m_actions;
00042     QWidget* m_defaultWidget;
00043 };
00044 
00045 
00046 KIPI::Plugin::Plugin( KInstance* instance, QObject *parent, const char* name)
00047             : QObject( parent, name)
00048 {
00049     d=new Private;
00050     d->m_instance=instance;
00051 }
00052 
00053 KIPI::Plugin::~Plugin()
00054 {
00055     delete d;
00056 }
00057 
00058 KActionCollection* KIPI::Plugin::actionCollection( QWidget* widget )
00059 {
00060     if ( widget == 0 )
00061         widget = d->m_defaultWidget;
00062 
00063     if (!d->m_actionCollection.contains( widget ))
00064         kdWarning( 51000 ) << "Error in the plugin. The plugin needs to call Plugin::setup( QWidget* ) "
00065                            << "as the very first line when overriding the setup method." << endl;
00066     return d->m_actionCollection[widget];
00067 }
00068 
00069 void KIPI::Plugin::addAction( KAction* action )
00070 {
00071     d->m_actions[d->m_defaultWidget].append( action );
00072 }
00073 
00074 KActionPtrList KIPI::Plugin::actions( QWidget* widget )
00075 {
00076     if ( widget == 0 )
00077         widget = d->m_defaultWidget;
00078 
00079     return d->m_actions[widget];
00080 }
00081 
00082 void KIPI::Plugin::setup( QWidget* widget )
00083 {
00084     d->m_defaultWidget = widget;
00085     d->m_actions.insert( widget, KActionPtrList() );
00086     QString name = QString( "action collection for %1" ).arg( widget->name() );
00087     d->m_actionCollection.insert( widget, new KActionCollection( widget, widget, name.latin1(), d->m_instance ) );
00088 }
00089 
00090 
00091 

Generated on Mon Nov 27 23:42:22 2006 for libKipi by  doxygen 1.5.0