00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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();
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"