• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

agentinstancecreatejob.cpp

00001 /*
00002     Copyright (c) 2008 Volker Krause <vkrause@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "agentinstancecreatejob.h"
00021 #include "agentmanager.h"
00022 #include "agentmanager_p.h"
00023 
00024 #include "agentinstance.h"
00025 
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028 
00029 #include <QtCore/QTimer>
00030 
00031 using namespace Akonadi;
00032 
00033 static const int safetyTimeout = 10000; // ms
00034 
00038 class AgentInstanceCreateJob::Private
00039 {
00040   public:
00041     Private( AgentInstanceCreateJob* parent ) : q( parent ),
00042       parentWidget( 0 ),
00043       safetyTimer( 0 ),
00044       doConfig( false ),
00045       tooLate( false )
00046     {
00047     }
00048 
00049     ~Private()
00050     {
00051     }
00052 
00053     void agentInstanceAdded( const AgentInstance &instance )
00054     {
00055       if ( agentInstance == instance && !tooLate ) {
00056         safetyTimer->stop();
00057         if ( doConfig ) {
00058           // return from dbus call first before doing the next one
00059           QTimer::singleShot( 0, q, SLOT( doConfigure() ) );
00060         } else {
00061           q->emitResult();
00062         }
00063       }
00064     }
00065 
00066     void doConfigure()
00067     {
00068       agentInstance.configure( parentWidget );
00069       q->emitResult();
00070     }
00071 
00072     void timeout()
00073     {
00074       tooLate = true;
00075       q->setError( KJob::UserDefinedError );
00076       q->setErrorText( i18n( "Agent instance creation timed out." ) );
00077       q->emitResult();
00078     }
00079 
00080     void emitResult()
00081     {
00082       q->emitResult();
00083     }
00084 
00085     AgentInstanceCreateJob* q;
00086     AgentType agentType;
00087     AgentInstance agentInstance;
00088     QWidget* parentWidget;
00089     QTimer *safetyTimer;
00090     bool doConfig;
00091     bool tooLate;
00092 };
00093 
00094 AgentInstanceCreateJob::AgentInstanceCreateJob(const AgentType & agentType, QObject * parent) :
00095     KJob( parent ),
00096     d( new Private( this ) )
00097 {
00098   d->agentType = agentType;
00099   connect( AgentManager::self(), SIGNAL(instanceAdded(const Akonadi::AgentInstance&)),
00100            this, SLOT(agentInstanceAdded(const Akonadi::AgentInstance&)) );
00101 
00102   d->safetyTimer = new QTimer( this );
00103   connect( d->safetyTimer, SIGNAL(timeout()), SLOT(timeout()) );
00104 }
00105 
00106 AgentInstanceCreateJob::~ AgentInstanceCreateJob()
00107 {
00108   delete d;
00109 }
00110 
00111 void AgentInstanceCreateJob::configure( QWidget *parent )
00112 {
00113   d->parentWidget = parent;
00114   d->doConfig = true;
00115 }
00116 
00117 AgentInstance AgentInstanceCreateJob::instance() const
00118 {
00119   return d->agentInstance;
00120 }
00121 
00122 void AgentInstanceCreateJob::start()
00123 {
00124   d->agentInstance = AgentManager::self()->d->createInstance( d->agentType );
00125   if ( !d->agentInstance.isValid() ) {
00126     setError( KJob::UserDefinedError );
00127     setErrorText( i18n("Unable to create agent instance." ) );
00128     QTimer::singleShot( 0, this , SLOT(emitResult()) );
00129   } else {
00130     d->safetyTimer->start( safetyTimeout );
00131   }
00132 }
00133 
00134 #include "agentinstancecreatejob.moc"

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal