• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

akonadi/clients

agentwidget.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of Akonadi.
00003 
00004     Copyright (c) 2006 Tobias Koenig <tokoe@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019     USA.
00020 */
00021 
00022 #include "agentwidget.h"
00023 
00024 #include <akonadi/agenttypewidget.h>
00025 #include <akonadi/agentinstancewidget.h>
00026 #include <akonadi/agentmanager.h>
00027 #include <akonadi/agentinstancecreatejob.h>
00028 
00029 #include <KLocale>
00030 
00031 #include <QtGui/QDialog>
00032 #include <QtGui/QDialogButtonBox>
00033 #include <QtGui/QGridLayout>
00034 #include <QtGui/QMenu>
00035 #include <QtGui/QPushButton>
00036 #include <QtGui/QVBoxLayout>
00037 
00038 using namespace Akonadi;
00039 
00040 class Dialog : public QDialog
00041 {
00042   public:
00043     Dialog( QWidget *parent = 0 )
00044       : QDialog( parent )
00045     {
00046       QVBoxLayout *layout = new QVBoxLayout( this );
00047 
00048       mWidget = new Akonadi::AgentTypeWidget( this );
00049 
00050       QDialogButtonBox *box = new QDialogButtonBox( this );
00051 
00052       layout->addWidget( mWidget );
00053       layout->addWidget( box );
00054 
00055       QPushButton *ok = box->addButton( QDialogButtonBox::Ok );
00056       connect( ok, SIGNAL( clicked() ), this, SLOT( accept() ) );
00057 
00058       QPushButton *cancel = box->addButton( QDialogButtonBox::Cancel );
00059       connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00060 
00061       resize( 450, 320 );
00062     }
00063 
00064     virtual void done( int result )
00065     {
00066       if ( result == Accepted )
00067         mAgentType = mWidget->currentAgentType();
00068       else
00069         mAgentType = AgentType();
00070 
00071       QDialog::done( result );
00072     }
00073 
00074     AgentType agentType() const
00075     {
00076       return mAgentType;
00077     }
00078 
00079   private:
00080     Akonadi::AgentTypeWidget *mWidget;
00081     AgentType mAgentType;
00082 };
00083 
00084 AgentWidget::AgentWidget( QWidget *parent )
00085   : QWidget( parent )
00086 {
00087   QGridLayout *layout = new QGridLayout( this );
00088 
00089   mWidget = new Akonadi::AgentInstanceWidget( this );
00090   connect( mWidget, SIGNAL( doubleClicked( const Akonadi::AgentInstance& ) ), SLOT( configureAgent() ) );
00091 
00092   layout->addWidget( mWidget, 0, 0, 1, 6 );
00093 
00094   QPushButton *button = new QPushButton( "Add...", this );
00095   connect( button, SIGNAL( clicked() ), this, SLOT( addAgent() ) );
00096   layout->addWidget( button, 1, 1 );
00097 
00098   button = new QPushButton( "Remove", this );
00099   connect( button, SIGNAL( clicked() ), this, SLOT( removeAgent() ) );
00100   layout->addWidget( button, 1, 2 );
00101 
00102   button = new QPushButton( "Configure...", this );
00103   connect( button, SIGNAL( clicked() ), this, SLOT( configureAgent() ) );
00104   layout->addWidget( button, 1, 3 );
00105 
00106   QMenu *syncMenu = new QMenu( this );
00107   syncMenu->addAction( i18n("Synchronize All"), this, SLOT(synchronizeAgent()) );
00108   syncMenu->addAction( i18n("Synchronize Collection Tree"), this, SLOT(synchronizeTree()) );
00109   button = new QPushButton( "Synchronize", this );
00110   button->setMenu( syncMenu );
00111   connect( button, SIGNAL( clicked() ), this, SLOT( synchronizeAgent() ) );
00112   layout->addWidget( button, 1, 4 );
00113 
00114   button = new QPushButton( "Toggle Online/Offline", this );
00115   connect( button, SIGNAL(clicked()), SLOT(toggleOnline()) );
00116   layout->addWidget( button, 1, 5 );
00117 }
00118 
00119 void AgentWidget::addAgent()
00120 {
00121   Dialog dlg( this );
00122   if ( dlg.exec() ) {
00123     const AgentType agentType = dlg.agentType();
00124 
00125     if ( agentType.isValid() ) {
00126       AgentInstanceCreateJob *job = new AgentInstanceCreateJob( agentType, this );
00127       job->configure( this );
00128       job->start(); // TODO: check result
00129     }
00130   }
00131 }
00132 
00133 void AgentWidget::removeAgent()
00134 {
00135   const AgentInstance agent = mWidget->currentAgentInstance();
00136   if ( agent.isValid() )
00137     AgentManager::self()->removeInstance( agent );
00138 }
00139 
00140 void AgentWidget::configureAgent()
00141 {
00142   AgentInstance agent = mWidget->currentAgentInstance();
00143   if ( agent.isValid() )
00144     agent.configure( this );
00145 }
00146 
00147 void AgentWidget::synchronizeAgent()
00148 {
00149   AgentInstance agent = mWidget->currentAgentInstance();
00150   if ( agent.isValid() )
00151     agent.synchronize();
00152 }
00153 
00154 void AgentWidget::toggleOnline()
00155 {
00156   AgentInstance agent = mWidget->currentAgentInstance();
00157   if ( agent.isValid() )
00158     agent.setIsOnline( !agent.isOnline() );
00159 }
00160 
00161 void AgentWidget::synchronizeTree()
00162 {
00163   AgentInstance agent = mWidget->currentAgentInstance();
00164   if ( agent.isValid() )
00165     agent.synchronizeCollectionTree();
00166 }
00167 
00168 #include "agentwidget.moc"

akonadi/clients

Skip menu "akonadi/clients"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
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