Index: mailtransport/socket.cpp
===================================================================
--- mailtransport/socket.cpp	(wersja 809610)
+++ mailtransport/socket.cpp	(kopia robocza)
@@ -102,7 +102,7 @@
     return;
   }
 
-  static QString msg;
+  QString msg;
   msg += QLatin1String( socket->readAll() );
 
   if ( !msg.endsWith( QLatin1Char( '\n' ) ) ) {
Index: mailtransport/transportmanager.h
===================================================================
--- mailtransport/transportmanager.h	(wersja 809610)
+++ mailtransport/transportmanager.h	(kopia robocza)
@@ -46,8 +46,11 @@
   Q_CLASSINFO( "D-Bus Interface", "org.kde.pim.TransportManager" )
 
   friend class Transport;
+  friend class Private;
 
   public:
+    class Private;
+
     /**
       Destructor.
     */
@@ -221,9 +224,9 @@
     */
     void loadPasswords();
 
+    TransportManager();
+
   private:
-    class Private;
-    TransportManager(Private *priv);
     void readConfig();
     void writeConfig();
     void emitChangesCommitted();
Index: mailtransport/smtpjob.cpp
===================================================================
--- mailtransport/smtpjob.cpp	(wersja 809610)
+++ mailtransport/smtpjob.cpp	(kopia robocza)
@@ -36,20 +36,29 @@
 
 using namespace MailTransport;
 
-static int slavePoolRef = 0;
-static QHash<int,KIO::Slave*> slavePool;
+struct SlavePool
+{
+  SlavePool() : ref( 0 ) {}
+  int ref;
+  QHash<int,KIO::Slave*> slaves;
+  QHash<KIO::Slave*,int> keys;
 
-static void removeSlaveFromPool( KIO::Slave *slave, bool disconnect = false )
-{
-  const int slaveKey = slavePool.key( slave );
-  if ( slaveKey > 0 ) {
-    slavePool.remove( slaveKey );
-    if ( disconnect ) {
-      KIO::Scheduler::disconnectSlave( slave );
+  void removeSlave( KIO::Slave *slave, bool disconnect = false )
+  {
+    const int slaveKey = keys.value( slave );
+    if ( slaveKey != 0 ) {
+      slaves.remove( slaveKey );
+      keys.remove( slave );
+      if ( disconnect ) {
+        KIO::Scheduler::disconnectSlave( slave );
+      }
     }
   }
-}
+};
 
+K_GLOBAL_STATIC( SlavePool, s_slavePool )
+
+
 /**
  * Private class that helps to provide binary compatibility between releases.
  * @internal
@@ -70,27 +79,28 @@
   d->currentState = SmtpJobPrivate::Idle;
   d->slave = 0;
   d->finished = false;
-  slavePoolRef++;
+  s_slavePool->ref++;
   KIO::Scheduler::connect( SIGNAL(slaveError(KIO::Slave*,int,QString)),
                            this, SLOT(slaveError(KIO::Slave*,int,QString)) );
 }
 
 SmtpJob::~SmtpJob()
 {
-  slavePoolRef--;
-  if ( slavePoolRef == 0 ) {
-    kDebug() << "clearing SMTP slave pool" << slavePool.count();
-    foreach ( KIO::Slave *slave, slavePool.values() ) {
+  s_slavePool->ref--;
+  if ( s_slavePool->ref == 0 ) {
+    kDebug() << "clearing SMTP slave pool" << s_slavePool->slaves.count();
+    foreach ( KIO::Slave *slave, s_slavePool->slaves.values() ) {
       KIO::Scheduler::disconnectSlave( slave );
     }
-    slavePool.clear();
+    s_slavePool->slaves.clear();
+    s_slavePool->keys.clear();
   }
   delete d;
 }
 
 void SmtpJob::doStart()
 {
-  if ( slavePool.contains( transport()->id() ) ||
+  if ( s_slavePool->slaves.contains( transport()->id() ) ||
        transport()->precommand().isEmpty() ) {
     d->currentState = SmtpJobPrivate::Smtp;
     startSmtpJob();
@@ -174,7 +184,7 @@
 
   destination.setPath( QLatin1String( "/send" ) );
 
-  d->slave = slavePool.value( transport()->id() );
+  d->slave = s_slavePool->slaves.value( transport()->id() );
   if ( !d->slave ) {
     kDebug() << "creating new SMTP slave";
     KIO::MetaData slaveConfig;
@@ -185,7 +195,8 @@
       slaveConfig.insert( QLatin1String( "sasl" ), transport()->authenticationTypeString() );
     }
     d->slave = KIO::Scheduler::getConnectedSlave( destination, slaveConfig );
-    slavePool.insert( transport()->id(), d->slave );
+    s_slavePool->slaves.insert( transport()->id(), d->slave );
+    s_slavePool->keys.insert( d->slave, transport()->id() );
   } else {
     kDebug() << "re-using existing slave";
   }
@@ -219,7 +230,7 @@
     KIO::SimpleJob *job = static_cast<KIO::SimpleJob*>( subjobs().first() );
     clearSubjobs();
     KIO::Scheduler::cancelJob( job );
-    removeSlaveFromPool( d->slave );
+    s_slavePool->removeSlave( d->slave );
     return true;
   }
   return false;
@@ -242,7 +253,7 @@
 
   TransportJob::slotResult( job );
   if ( error() && d->currentState == SmtpJobPrivate::Smtp ) {
-    removeSlaveFromPool( d->slave, error() != KIO::ERR_SLAVE_DIED );
+    s_slavePool->removeSlave( d->slave, error() != KIO::ERR_SLAVE_DIED );
     return;
   }
   if ( !error() && d->currentState == SmtpJobPrivate::Precommand ) {
@@ -269,7 +280,7 @@
 
 void SmtpJob::slaveError( KIO::Slave *slave, int errorCode, const QString &errorMsg )
 {
-  removeSlaveFromPool( slave, errorCode != KIO::ERR_SLAVE_DIED );
+  s_slavePool->removeSlave( slave, errorCode != KIO::ERR_SLAVE_DIED );
   if ( d->slave == slave && !d->finished ) {
     setError( errorCode );
     setErrorText( KIO::buildErrorString( errorCode, errorMsg ) );
Index: mailtransport/transportmanager.cpp
===================================================================
--- mailtransport/transportmanager.cpp	(wersja 809610)
+++ mailtransport/transportmanager.cpp	(kopia robocza)
@@ -49,9 +49,12 @@
 class TransportManager::Private
 {
   public:
+    Private() {}
     ~Private() {
-        cleanupTransportManager();
+      delete config;
+      qDeleteAll( transports );
     }
+
     KConfig *config;
     QList<Transport *> transports;
     bool myOwnChange;
@@ -61,19 +64,26 @@
     int defaultTransportId;
     bool isMainInstance;
     QList<TransportJob *> walletQueue;
+};
 
-    static TransportManager *sSelf;
-    static void cleanupTransportManager()
-    {
-      delete sSelf;
-      sSelf = 0;
-    }
+class StaticTransportManager : public TransportManager
+{
+  public:
+    StaticTransportManager() : TransportManager() {}
 };
-TransportManager *TransportManager::Private::sSelf = 0;
 
-TransportManager::TransportManager(Private *priv)
-  : QObject(), d( priv )
+K_GLOBAL_STATIC( StaticTransportManager, sSelf )
+
+static void cleanup()
 {
+  sSelf.destroy();
+}
+
+
+TransportManager::TransportManager()
+  : QObject(), d( new Private )
+{
+  qAddPostRoutine( cleanup );
   d->myOwnChange = false;
   d->wallet = 0;
   d->walletOpenFailed = false;
@@ -94,22 +104,18 @@
   connect( QDBusConnection::sessionBus().interface(),
            SIGNAL(serviceOwnerChanged(QString,QString,QString)),
            SLOT(dbusServiceOwnerChanged(QString,QString,QString)) );
+  readConfig();
 }
 
 TransportManager::~TransportManager()
 {
-  delete d->config;
-  qDeleteAll( d->transports );
+  qRemovePostRoutine( cleanup );
+  delete d;
 }
 
 TransportManager *TransportManager::self()
 {
-  static TransportManager::Private p;
-  if( !p.sSelf ) {
-    p.sSelf = new TransportManager( &p );
-    p.sSelf->readConfig();
-  }
-  return p.sSelf;
+  return sSelf;
 }
 
 Transport *TransportManager::transportById( int id, bool def ) const
Index: akonadi/control.h
===================================================================
--- akonadi/control.h	(wersja 809610)
+++ akonadi/control.h	(kopia robocza)
@@ -44,9 +44,10 @@
      */
     static bool start();
 
-  private:
+  protected:
     Control();
 
+  private:
     class Private;
     Private* const d;
 
Index: akonadi/control.cpp
===================================================================
--- akonadi/control.cpp	(wersja 809610)
+++ akonadi/control.cpp	(kopia robocza)
@@ -20,7 +20,7 @@
 #include "control.h"
 
 #include <kdebug.h>
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 
 #include <QtCore/QEventLoop>
 #include <QtCore/QProcess>
@@ -33,8 +33,6 @@
 
 using namespace Akonadi;
 
-static K3StaticDeleter<Control> sControlDeleter;
-
 class Control::Private
 {
   public:
@@ -45,25 +43,21 @@
 
     bool startInternal();
     void serviceOwnerChanged( const QString&, const QString&, const QString& );
-    static Control* self();
 
     Control *mParent;
     QEventLoop *mEventLoop;
     bool mSuccess;
-
-    static Control* mInstance;
 };
 
-Control* Control::Private::mInstance = 0;
-
-Control* Control::Private::self()
+class StaticControl : public Control
 {
-  if ( !mInstance )
-    sControlDeleter.setObject( mInstance, new Control() );
+  public:
+    StaticControl() : Control() {}
+};
 
-  return mInstance;
-}
+K_GLOBAL_STATIC( StaticControl, s_instance )
 
+
 bool Control::Private::startInternal()
 {
   if ( QDBusConnection::sessionBus().interface()->isServiceRegistered( AKONADI_CONTROL_SERVICE ) || mEventLoop )
@@ -122,7 +116,7 @@
 
 bool Control::start()
 {
-  return Private::self()->d->startInternal();
+  return s_instance->d->startInternal();
 }
 
 #include "control.moc"
Index: akonadi/attributefactory.h
===================================================================
--- akonadi/attributefactory.h	(wersja 809610)
+++ akonadi/attributefactory.h	(kopia robocza)
@@ -48,6 +48,10 @@
 class AKONADI_EXPORT AttributeFactory
 {
   public:
+    //@cond PRIVATE
+    ~AttributeFactory();
+    //@endcond
+
     /**
      * Register a custom attribute of type T.
      */
@@ -63,11 +67,11 @@
      */
     static Attribute* createAttribute( const QByteArray &type );
 
-  private:
+  protected:
     //@cond PRIVATE
     AttributeFactory();
-    ~AttributeFactory();
 
+  private:
     static AttributeFactory* self();
     void registerAttribute( Attribute *attribute );
 
Index: akonadi/collectionpropertiesdialog.cpp
===================================================================
--- akonadi/collectionpropertiesdialog.cpp	(wersja 809610)
+++ akonadi/collectionpropertiesdialog.cpp	(kopia robocza)
@@ -34,22 +34,12 @@
 
 AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY(CollectionGeneralPropertiesPageFactory, CollectionGeneralPropertiesPage)
 
-// FIXME: we leak d->pages!
-
 class CollectionPropertiesDialog::Private
 {
   public:
-    Private( CollectionPropertiesDialog *parent ) : q( parent )
-    {
-      if ( pages.isEmpty() )
-        registerBuiltinPages();
-    }
+    Private( CollectionPropertiesDialog *parent );
 
-    static void registerBuiltinPages()
-    {
-      pages.append( new CollectionGeneralPropertiesPageFactory() );
-      pages.append( new CachePolicyPageFactory() );
-    }
+    static void registerBuiltinPages();
 
     void save()
     {
@@ -72,13 +62,27 @@
     }
 
     Collection collection;
-    static QList<CollectionPropertiesPageFactory*> pages;
     QTabWidget* tabWidget;
     CollectionPropertiesDialog *q;
 };
 
-QList<CollectionPropertiesPageFactory*> CollectionPropertiesDialog::Private::pages;
+typedef QList<CollectionPropertiesPageFactory*> CollectionPropertiesPageFactoryList;
 
+K_GLOBAL_STATIC( CollectionPropertiesPageFactoryList, s_pages )
+
+CollectionPropertiesDialog::Private::Private( CollectionPropertiesDialog *parent ) : q( parent )
+{
+  if ( s_pages->isEmpty() )
+    registerBuiltinPages();
+}
+
+void CollectionPropertiesDialog::Private::registerBuiltinPages()
+{
+  s_pages->append( new CollectionGeneralPropertiesPageFactory() );
+  s_pages->append( new CachePolicyPageFactory() );
+}
+
+
 CollectionPropertiesDialog::CollectionPropertiesDialog(const Collection & collection, QWidget * parent) :
     KDialog( parent ),
     d( new Private( this ) )
@@ -90,7 +94,7 @@
   d->tabWidget = new QTabWidget( mainWidget() );
   layout->addWidget( d->tabWidget );
 
-  foreach ( CollectionPropertiesPageFactory *factory, d->pages ) {
+  foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
     CollectionPropertiesPage *page = factory->createWidget( d->tabWidget );
     if ( page->canHandle( d->collection ) ) {
       d->tabWidget->addTab( page, page->pageTitle() );
@@ -111,9 +115,9 @@
 
 void CollectionPropertiesDialog::registerPage(CollectionPropertiesPageFactory * factory)
 {
-  if ( Private::pages.isEmpty() )
+  if ( s_pages->isEmpty() )
     Private::registerBuiltinPages();
-  Private::pages.append( factory );
+  s_pages->append( factory );
 }
 
 #include "collectionpropertiesdialog.moc"
Index: akonadi/itemserializer.cpp
===================================================================
--- akonadi/itemserializer.cpp	(wersja 809610)
+++ akonadi/itemserializer.cpp	(kopia robocza)
@@ -26,6 +26,7 @@
 // KDE core
 #include <kdebug.h>
 #include <kmimetype.h>
+#include <kglobal.h>
 
 // Qt
 #include <QtCore/QBuffer>
@@ -43,20 +44,10 @@
 
 class DefaultItemSerializerPlugin;
 
-static DefaultItemSerializerPlugin * s_p = 0;
-
 class DefaultItemSerializerPlugin : public ItemSerializerPlugin
 {
-private:
-    DefaultItemSerializerPlugin() { }
 public:
-    static DefaultItemSerializerPlugin * instance()
-    {
-        if ( !s_p ) {
-            s_p = new DefaultItemSerializerPlugin;
-        }
-        return s_p;
-    }
+    DefaultItemSerializerPlugin() { }
 
     bool deserialize( Item& item, const QByteArray& label, QIODevice& data, int )
     {
@@ -75,8 +66,11 @@
 
 };
 
+K_GLOBAL_STATIC( DefaultItemSerializerPlugin, s_defaultItemSerializerPlugin )
+
 }
 
+
 using namespace Akonadi;
 
 class PluginEntry
@@ -103,7 +97,7 @@
                          << "plugin" << mIdentifier << "is not valid!" << endl;
 
         // we try to use the default in that case
-        mPlugin = DefaultItemSerializerPlugin::instance();
+        mPlugin = s_defaultItemSerializerPlugin;
       }
 
       mPlugin = qobject_cast<ItemSerializerPlugin*>( object );
@@ -112,7 +106,7 @@
                          << "plugin" << mIdentifier << "doesn't provide interface ItemSerializerPlugin!" << endl;
 
         // we try to use the default in that case
-        mPlugin = DefaultItemSerializerPlugin::instance();
+        mPlugin = s_defaultItemSerializerPlugin;
       }
 
       Q_ASSERT( mPlugin );
@@ -227,7 +221,7 @@
     kDebug( 5250 ) << "No plugin for mimetype " << mimetype << " found!";
     kDebug( 5250 ) << "Available plugins are: " << all->keys();
 
-    ItemSerializerPlugin *plugin = DefaultItemSerializerPlugin::instance();
+    ItemSerializerPlugin *plugin = s_defaultItemSerializerPlugin;
     Q_ASSERT(plugin);
     return *plugin;
 }
Index: akonadi/attributefactory.cpp
===================================================================
--- akonadi/attributefactory.cpp	(wersja 809610)
+++ akonadi/attributefactory.cpp	(kopia robocza)
@@ -21,6 +21,8 @@
 
 #include "collectionrightsattribute.h"
 
+#include <KGlobal>
+
 #include <QtCore/QHash>
 
 using namespace Akonadi;
@@ -50,21 +52,29 @@
 {
   public:
     QHash<QByteArray, Attribute*> attributes;
-    static AttributeFactory* mInstance;
 };
 
-AttributeFactory* AttributeFactory::Private::mInstance = 0;
+class StaticAttributeFactory : public AttributeFactory
+{
+  public:
+    StaticAttributeFactory() : AttributeFactory(), initialized( false ) {}
+    void init() {
+      if ( initialized )
+        return;
+      // Register built-in attributes
+      AttributeFactory::registerAttribute<CollectionRightsAttribute>();
+      initialized = true;
+    }
+    bool initialized;
+};
 
+K_GLOBAL_STATIC( StaticAttributeFactory, s_instance )
+
+
 AttributeFactory* AttributeFactory::self()
 {
-  if ( !Private::mInstance ) {
-    Private::mInstance = new AttributeFactory();
-
-    // Register built-in attributes
-    AttributeFactory::registerAttribute<CollectionRightsAttribute>();
-  }
-
-  return Private::mInstance;
+  s_instance->init();
+  return s_instance;
 }
 
 AttributeFactory::AttributeFactory()
Index: akonadi/agentinstancewidget.cpp
===================================================================
--- akonadi/agentinstancewidget.cpp	(wersja 809610)
+++ akonadi/agentinstancewidget.cpp	(kopia robocza)
@@ -24,6 +24,7 @@
 #include "agentinstancemodel.h"
 
 #include <KIcon>
+#include <KGlobal>
 
 #include <QtCore/QUrl>
 #include <QtGui/QAbstractTextDocumentLayout>
@@ -35,6 +36,19 @@
 
 using namespace Akonadi;
 
+struct Icons
+{
+  Icons()
+   : readyPixmap( KIcon( QLatin1String("user-online") ).pixmap( QSize( 16, 16 ) ) )
+   , syncPixmap( KIcon( QLatin1String("network-connect") ).pixmap( QSize( 16, 16 ) ) )
+   , errorPixmap( KIcon( QLatin1String("dialog-error") ).pixmap( QSize( 16, 16 ) ) )
+  {
+  }
+  QPixmap readyPixmap, syncPixmap, errorPixmap;
+};
+
+K_GLOBAL_STATIC( Icons, s_icons )
+
 class AgentInstanceWidgetDelegate : public QAbstractItemDelegate
 {
   public:
@@ -165,16 +179,12 @@
                            qvariant_cast<QIcon>( data ).pixmap( QSize( 64, 64 ) ) );
   }
 
-  static QPixmap readyPixmap = KIcon( QLatin1String("user-online") ).pixmap( QSize( 16, 16 ) );
-  static QPixmap syncPixmap = KIcon( QLatin1String("network-connect") ).pixmap( QSize( 16, 16 ) );
-  static QPixmap errorPixmap = KIcon( QLatin1String("dialog-error") ).pixmap( QSize( 16, 16 ) );
-
   if ( status == 0 )
-    document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "status_icon" ) ), readyPixmap );
+    document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "status_icon" ) ), s_icons->readyPixmap );
   else if ( status == 1 )
-    document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "status_icon" ) ), syncPixmap );
+    document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "status_icon" ) ), s_icons->syncPixmap );
   else
-    document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "status_icon" ) ), errorPixmap );
+    document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "status_icon" ) ), s_icons->errorPixmap );
 
 
   QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
Index: akonadi/collection.cpp
===================================================================
--- akonadi/collection.cpp	(wersja 809610)
+++ akonadi/collection.cpp	(kopia robocza)
@@ -31,7 +31,8 @@
 #include <QtCore/QString>
 #include <QtCore/QStringList>
 
-#include <kurl.h>
+#include <KUrl>
+#include <KGlobal>
 
 using namespace Akonadi;
 
@@ -75,29 +76,29 @@
       EntityPrivate::resetChangeLog();
     }
 
-    static Collection newRoot()
-    {
-      Collection root( 0 );
-      QStringList types;
-      types << Collection::mimeType();
-      root.setContentMimeTypes( types );
-      return root;
-    }
-
     Collection::Id parentId;
     QString name;
     QString parentRemoteId;
     QString resource;
     CollectionStatistics statistics;
     QStringList contentTypes;
-    static const Collection root;
     CachePolicy cachePolicy;
     bool contentTypesChanged;
     bool cachePolicyChanged;
 };
 
-const Collection Akonadi::CollectionPrivate::root = CollectionPrivate::newRoot();
+class CollectionRoot : public Collection
+{
+  public:
+    CollectionRoot() : Collection( 0 ) {
+      QStringList types;
+      types << Collection::mimeType();
+      setContentMimeTypes( types );
+    }
+};
 
+K_GLOBAL_STATIC( CollectionRoot, s_root )
+
 Collection::Collection() :
     Entity( new CollectionPrivate )
 {
@@ -214,7 +215,7 @@
 
 Collection Collection::root()
 {
-  return CollectionPrivate::root;
+  return *s_root;
 }
 
 QString Collection::mimeType( )
