Commit b0707f40 authored by Frank Osterfeld's avatar Frank Osterfeld
Browse files

Add the possibility to have disabled plugins shown grayed out in the sidebar.

Configurable by non-gui option.
KoWi W1-10

svn path=/branches/kdepim/enterprise/kdepim/; revision=657618
parent 8303783e
......@@ -37,6 +37,8 @@
#include <qtooltip.h>
#include <kpopupmenu.h>
#include <kpixmapeffect.h>
#include <kplugininfo.h>
#include <kapplication.h>
#include <kdialog.h>
#include <klocale.h>
......@@ -52,55 +54,161 @@
#include "prefs.h"
#include "iconsidepane.h"
namespace Kontact
{
namespace Kontact {
//ugly wrapper class for adding an operator< to the Plugin class
// wrapper class to uniformly handle loaded plugins and disabled plugins where we
// only have the plugin info available, not the plugin itself
class PluginProxy
{
public:
PluginProxy()
: mPlugin( 0 )
{ }
PluginProxy( Plugin *plugin )
: mPlugin( plugin )
: mPlugin( 0 ), mWeight( 0 ), mShowInSideBar( false )
{ }
PluginProxy & operator=( Plugin *plugin )
explicit PluginProxy( Plugin *plugin )
: mPlugin( plugin ), mIcon( plugin->icon() ), mTitle( plugin->title() ), mIdentifier( plugin->identifier() ), mWeight( plugin->weight() ), mShowInSideBar( plugin->showInSideBar() )
{
mPlugin = plugin;
return *this;
}
bool operator<( PluginProxy &rhs ) const
explicit PluginProxy( KPluginInfo* info ) : mPlugin( 0 ), mIcon( info->icon() ), mTitle( info->name() ), mIdentifier( info->pluginName() ), mWeight( 1000 ), mShowInSideBar( true )
{
return mPlugin->weight() < rhs.mPlugin->weight();
const QVariant hasPart = info->property( "X-KDE-KontactPluginHasPart" );
if ( hasPart.isValid() )
mShowInSideBar = hasPart.toBool();
}
Plugin *plugin() const
{
Plugin* plugin() const {
return mPlugin;
}
bool isPluginEnabled() const {
return mPlugin != 0L;
}
bool operator<( PluginProxy &rhs ) const {
return weight() < rhs.weight();
}
QString icon() const {
return mIcon;
}
QString title() const {
return mTitle;
}
void processDropEvent( QDropEvent* event ) {
if ( mPlugin )
processDropEvent( event );
}
bool canDecodeDrag( QMimeSource * source ) const {
return mPlugin ? mPlugin->canDecodeDrag( source ) : false;
}
QString identifier() const {
return mIdentifier;
}
int weight() const {
return mWeight;
}
bool showInSideBar() const {
return mShowInSideBar;
}
private:
Plugin *mPlugin;
QString mIcon;
QString mTitle;
QString mIdentifier;
int mWeight;
bool mShowInSideBar;
};
/**
A QListBoxPixmap Square Box with an optional icon and a text
underneath.
*/
class EntryItem : public QListBoxItem
{
public:
EntryItem( Navigator *, const PluginProxy& );
~EntryItem();
Kontact::PluginProxy pluginProxy() const { return mPluginProxy; }
Navigator* navigator() const;
void setHover( bool );
void setPaintActive( bool );
bool paintActive() const { return mPaintActive; }
/**
returns the width of this item.
*/
virtual int width( const QListBox * ) const;
/**
returns the height of this item.
*/
virtual int height( const QListBox * ) const;
protected:
void reloadPixmap();
//
virtual void paint( QPainter *p );
private:
Kontact::PluginProxy mPluginProxy;
QPixmap mPixmap;
bool mHasHover;
bool mPaintActive;
};
} //namespace
/**
* Tooltip that changes text depending on the item it is above.
* Compliments of "Practical Qt" by Dalheimer, Petersen et al.
*/
class EntryItemToolTip : public QToolTip
{
public:
EntryItemToolTip( QListBox* parent )
: QToolTip( parent->viewport() ), mListBox( parent )
{}
protected:
void maybeTip( const QPoint& p ) {
// We only show tooltips when there are no texts shown
if ( Prefs::self()->sidePaneShowText() ) return;
if ( !mListBox ) return;
QListBoxItem* item = mListBox->itemAt( p );
if ( !item ) return;
const QRect itemRect = mListBox->itemRect( item );
if ( !itemRect.isValid() ) return;
const EntryItem *entryItem = static_cast<EntryItem*>( item );
QString tipStr = entryItem->text();
tip( itemRect, tipStr );
}
private:
QListBox* mListBox;
};
} // namespace Kontact
using namespace Kontact;
EntryItem::EntryItem( Navigator *parent, Kontact::Plugin *plugin )
EntryItem::EntryItem( Navigator *parent, const PluginProxy &proxy )
: QListBoxItem( parent ),
mPlugin( plugin ),
mPluginProxy( proxy ),
mHasHover( false ),
mPaintActive( false )
{
reloadPixmap();
setCustomHighlighting( true );
setText( plugin->title() );
setText( proxy.title() );
}
EntryItem::~EntryItem()
......@@ -111,8 +219,8 @@ void EntryItem::reloadPixmap()
{
int size = (int)navigator()->viewMode();
if ( size != 0 )
mPixmap = KGlobal::iconLoader()->loadIcon( mPlugin->icon(),
KIcon::Desktop, size );
mPixmap = KGlobal::iconLoader()->loadIcon( mPluginProxy.icon(),
KIcon::Desktop, size, pluginProxy().isPluginEnabled() ? KIcon::DefaultState : KIcon::DisabledState );
else
mPixmap = QPixmap();
}
......@@ -164,8 +272,9 @@ void EntryItem::paint( QPainter *p )
int y = iconAboveText ? 2 :
( ( height( box ) - mPixmap.height() ) / 2 );
const bool isEnabled = pluginProxy().isPluginEnabled();
// draw selected
if ( isCurrent() || isSelected() || mHasHover || mPaintActive ) {
if ( isEnabled && ( isCurrent() || isSelected() || mHasHover || mPaintActive ) ) {
int h = height( box );
QBrush brush;
......@@ -190,6 +299,7 @@ void EntryItem::paint( QPainter *p )
if ( !mPixmap.isNull() && navigator()->showIcons() ) {
int x = iconAboveText ? ( ( w - mPixmap.width() ) / 2 ) :
KDialog::marginHint();
p->drawPixmap( x, y, mPixmap );
}
......@@ -219,7 +329,10 @@ void EntryItem::paint( QPainter *p )
y += mPixmap.height()/2 - fm.height()/2 + fm.ascent();
}
if ( isCurrent() || isSelected() || mHasHover ) {
if ( !pluginProxy().isPluginEnabled() ) {
p->setPen( qApp->palette().disabled().text() );
}
else if ( isCurrent() || isSelected() || mHasHover ) {
p->setPen( box->colorGroup().highlight().dark(115) );
p->drawText( x + ( QApplication::reverseLayout() ? -1 : 1),
y + 1, text() );
......@@ -305,11 +418,12 @@ void Navigator::setSelected( QListBoxItem *item, bool selected )
// an confirm from MainWindow::selectPlugin()
if ( selected ) {
EntryItem *entry = static_cast<EntryItem*>( item );
emit pluginActivated( entry->plugin() );
emit pluginActivated( entry->pluginProxy().plugin() );
}
}
void Navigator::updatePlugins( QValueList<Kontact::Plugin*> plugins_ )
void Navigator::updatePlugins( const QValueList<Kontact::Plugin*> &plugins_,
const QValueList<KPluginInfo*> &disabled_ )
{
QValueList<Kontact::PluginProxy> plugins;
QValueList<Kontact::Plugin*>::ConstIterator end_ = plugins_.end();
......@@ -317,6 +431,12 @@ void Navigator::updatePlugins( QValueList<Kontact::Plugin*> plugins_ )
for ( ; it_ != end_; ++it_ )
plugins += PluginProxy( *it_ );
QValueList<KPluginInfo*>::ConstIterator end2_ = disabled_.end();
QValueList<KPluginInfo*>::ConstIterator it2_ = disabled_.begin();
for ( ; it2_ != end2_; ++it2_ )
plugins += PluginProxy( *it2_ );
clear();
mActions.setAutoDelete( true );
......@@ -329,17 +449,17 @@ void Navigator::updatePlugins( QValueList<Kontact::Plugin*> plugins_ )
QValueList<Kontact::PluginProxy>::ConstIterator end = plugins.end();
QValueList<Kontact::PluginProxy>::ConstIterator it = plugins.begin();
for ( ; it != end; ++it ) {
Kontact::Plugin *plugin = ( *it ).plugin();
if ( !plugin->showInSideBar() )
if ( !(*it).showInSideBar() )
continue;
EntryItem *item = new EntryItem( this, plugin );
EntryItem *item = new EntryItem( this, *it );
item->setSelectable( (*it).isPluginEnabled() );
if ( item->width( this ) > minWidth )
minWidth = item->width( this );
QString name = QString( "CTRL+%1" ).arg( counter + 1 );
KAction *action = new KAction( plugin->title(), plugin->icon(), KShortcut( name ),
KAction *action = new KAction( (*it).title(), (*it).icon(), KShortcut( name ),
mMapper, SLOT( map() ),
mSidePane->actionCollection(), name.latin1() );
mActions.append( action );
......@@ -372,9 +492,9 @@ void Navigator::dragMoveEvent( QDragMoveEvent *event )
EntryItem *entry = static_cast<EntryItem*>( item );
kdDebug(5600) << " PLUGIN: " << entry->plugin()->identifier() << endl;
kdDebug(5600) << " PLUGIN: " << entry->pluginProxy().identifier() << endl;
event->accept( entry->plugin()->canDecodeDrag( event ) );
event->accept( entry->pluginProxy().canDecodeDrag( event ) );
}
void Navigator::dropEvent( QDropEvent *event )
......@@ -389,9 +509,9 @@ void Navigator::dropEvent( QDropEvent *event )
EntryItem *entry = static_cast<EntryItem*>( item );
kdDebug(5600) << " PLUGIN: " << entry->plugin()->identifier() << endl;
kdDebug(5600) << " PLUGIN: " << entry->pluginProxy().identifier() << endl;
entry->plugin()->processDropEvent( event );
entry->pluginProxy().processDropEvent( event );
}
void Navigator::resizeEvent( QResizeEvent *event )
......@@ -421,7 +541,7 @@ void Navigator::slotExecuted( QListBoxItem *item )
EntryItem *entry = static_cast<EntryItem*>( item );
emit pluginActivated( entry->plugin() );
emit pluginActivated( entry->pluginProxy().plugin() );
}
IconViewMode Navigator::sizeIntToEnum(int size) const
......@@ -552,9 +672,10 @@ IconSidePane::~IconSidePane()
{
}
void IconSidePane::updatePlugins()
void IconSidePane::updatePlugins( const QValueList<Kontact::Plugin*> &plugins,
const QValueList<KPluginInfo*> &disabled )
{
mNavigator->updatePlugins( core()->pluginList() );
mNavigator->updatePlugins( plugins, disabled );
}
void IconSidePane::selectPlugin( Kontact::Plugin *plugin )
......@@ -564,7 +685,7 @@ void IconSidePane::selectPlugin( Kontact::Plugin *plugin )
for ( uint i = 0; i < mNavigator->count(); ++i ) {
EntryItem *item = static_cast<EntryItem*>( mNavigator->item( i ) );
if ( item->plugin() == plugin ) {
if ( item->pluginProxy().plugin() == plugin ) {
mNavigator->setCurrentItem( i );
break;
}
......@@ -580,20 +701,21 @@ void IconSidePane::selectPlugin( const QString &name )
for ( uint i = 0; i < mNavigator->count(); ++i ) {
EntryItem *item = static_cast<EntryItem*>( mNavigator->item( i ) );
if ( item->plugin()->identifier() == name ) {
if ( item->pluginProxy().identifier() == name ) {
mNavigator->setCurrentItem( i );
break;
}
}
blockSignals( blocked );
}
void IconSidePane::indicateForegrunding( Kontact::Plugin *plugin )
{
for ( uint i = 0; i < mNavigator->count(); ++i ) {
EntryItem *item = static_cast<EntryItem*>( mNavigator->item( i ) );
if ( item->plugin() == plugin ) {
if ( item->pluginProxy().plugin() == plugin ) {
mNavigator->highlightItem( item );
break;
}
......
......@@ -42,74 +42,7 @@ class Navigator;
enum IconViewMode { LargeIcons = 48, NormalIcons = 32, SmallIcons = 22, ShowText = 3, ShowIcons = 5 };
/**
A QListBoxPixmap Square Box with an optional icon and a text
underneath.
*/
class EntryItem : public QListBoxItem
{
public:
EntryItem( Navigator *, Kontact::Plugin * );
~EntryItem();
Kontact::Plugin *plugin() const { return mPlugin; }
const QPixmap *pixmap() const { return &mPixmap; }
Navigator* navigator() const;
void setHover( bool );
void setPaintActive( bool );
bool paintActive() const { return mPaintActive; }
/**
returns the width of this item.
*/
virtual int width( const QListBox * ) const;
/**
returns the height of this item.
*/
virtual int height( const QListBox * ) const;
protected:
void reloadPixmap();
virtual void paint( QPainter *p );
private:
Kontact::Plugin *mPlugin;
QPixmap mPixmap;
bool mHasHover;
bool mPaintActive;
};
/**
* Tooltip that changes text depending on the item it is above.
* Compliments of "Practical Qt" by Dalheimer, Petersen et al.
*/
class EntryItemToolTip : public QToolTip
{
public:
EntryItemToolTip( QListBox* parent )
: QToolTip( parent->viewport() ), mListBox( parent )
{}
protected:
void maybeTip( const QPoint& p ) {
// We only show tooltips when there are no texts shown
if ( Prefs::self()->sidePaneShowText() ) return;
if ( !mListBox ) return;
QListBoxItem* item = mListBox->itemAt( p );
if ( !item ) return;
const QRect itemRect = mListBox->itemRect( item );
if ( !itemRect.isValid() ) return;
const EntryItem *entryItem = static_cast<EntryItem*>( item );
QString tipStr = entryItem->text();
tip( itemRect, tipStr );
}
private:
QListBox* mListBox;
};
class EntryItem;
/**
Navigation pane showing all parts relevant to the user
......@@ -122,7 +55,8 @@ class Navigator : public KListBox
virtual void setSelected( QListBoxItem *, bool );
void updatePlugins( QValueList<Kontact::Plugin*> plugins );
void updatePlugins( const QValueList<Kontact::Plugin*> &plugins,
const QValueList<KPluginInfo*> &disabled );
QSize sizeHint() const;
......@@ -179,7 +113,9 @@ class IconSidePane : public SidePaneBase
virtual void indicateForegrunding( Kontact::Plugin* );
public slots:
virtual void updatePlugins();
virtual void updatePlugins( const QValueList<Kontact::Plugin*> &plugins,
const QValueList<KPluginInfo*> &infos );
virtual void selectPlugin( Kontact::Plugin* );
virtual void selectPlugin( const QString &name );
const QPtrList<KAction> & actions() { return mNavigator->actions(); }
......
......@@ -14,6 +14,13 @@
<label>Always start with specified component:</label>
<whatsthis>Usually Kontact will come up with the component used before shutdown. Check this box if you would like a specific component to come up on start instead.</whatsthis>
</entry>
<entry type="Bool" name="ShowDisabledPluginsInSideBar">
<default>false</default>
<label>Show disabled plugins in the side bar</label>
<whatsthis>Usually the side bar does not display disabled Kontact plugins. Enable this option to make disabled plugins appear in the side bar with
a greyed out icon.</whatsthis>
</entry>
<entry type="String" name="ForcedStartupPlugin">
</entry>
......
......@@ -128,6 +128,17 @@ void MainWindow::initGUI()
setAutoSaveSettings();
}
QValueList<KPluginInfo*> MainWindow::disabledPlugins()
{
QValueList<KPluginInfo*> disabled;
KPluginInfo::List::Iterator it;
for ( it = mPluginInfos.begin(); it != mPluginInfos.end(); ++it ) {
if ( !isPluginLoaded( *it ) ) {
disabled.append( *it );
}
}
return disabled;
}
void MainWindow::initObject()
{
......@@ -150,7 +161,8 @@ void MainWindow::initObject()
loadPlugins();
if ( mSidePane ) {
mSidePane->updatePlugins();
const QValueList<KPluginInfo*> disabled = Prefs::showDisabledPluginsInSideBar() ? disabledPlugins() : QValueList<KPluginInfo*>();
mSidePane->updatePlugins( pluginList(), disabled );
plugActionList( "navigator_actionlist", mSidePane->actions() );
}
......@@ -740,7 +752,8 @@ void MainWindow::pluginsChanged()
unplugActionList( "navigator_actionlist" );
unloadPlugins();
loadPlugins();
mSidePane->updatePlugins();
const QValueList<KPluginInfo*> disabled = Prefs::showDisabledPluginsInSideBar() ? disabledPlugins() : QValueList<KPluginInfo*>();
mSidePane->updatePlugins( pluginList(), disabled );
plugActionList( "navigator_actionlist", mSidePane->actions() );
}
......
......@@ -122,6 +122,9 @@ class MainWindow : public Kontact::Core, public KDCOPServiceStarter
void paintAboutScreen( const QString& msg );
static QString introductionString();
private:
QValueList<KPluginInfo*> disabledPlugins();
private slots:
void pluginsChanged();
......
......@@ -23,6 +23,8 @@
#include <qvbox.h>
class KPluginInfo;
namespace KParts { class Part; }
namespace Kontact
......@@ -51,7 +53,8 @@ class SidePaneBase : public QVBox
This method is called by the core whenever the count
of plugins has changed.
*/
virtual void updatePlugins() = 0;
virtual void updatePlugins( const QValueList<Kontact::Plugin*> &plugins,
const QValueList<KPluginInfo*> &disabled ) = 0;
/**
Select the current plugin without emmiting a signal.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment