Blokkal
an Extendable KDE Blogging Client
SourceForge.net Logo

blokkalprotocol.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2006 - 2007 by Martin Müller                            *
00003  *   orvio@orvio.de                                                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include "blokkalprotocol.h"
00021 #include "blokkalprotocol.moc"
00022 
00023 #include "blokkalaccountmanager.h"
00024 #include "blokkalaccount.h"
00025 #include "blokkalui/formattingbackend.h"
00026 
00027 #include <kdebug.h>
00028 
00029 Blokkal::Protocol::Protocol( const KComponentData & instance, QObject * parent ):
00030 Plugin( instance, parent )
00031 {}
00032 
00033 Blokkal::Protocol::~Protocol( void )
00034 {}
00035 
00036 void Blokkal::Protocol::prepareToUnload( void )
00037 {
00038         AccountList accounts = Blokkal::AccountManager::self()->accounts();
00039         if( accounts.isEmpty() ) {
00040                 emit readyToUnload( this );
00041                 return;
00042         }
00043 
00044         bool allAccountsWhereDisconnected = TRUE;
00045         for( AccountList::Iterator it = accounts.begin();
00046              it != accounts.end();
00047              ++it )
00048         {
00049                 if( (*it)->connectionStatus() != Blokkal::Account::Disconnected
00050                     && (*it)->protocol() == this )
00051                 {
00052                         allAccountsWhereDisconnected = FALSE;
00053                         connect( *it ,
00054                                  SIGNAL( connectionStatusChanged( Blokkal::Account * ) ),
00055                                  SLOT( checkAccountStates( void ) ) );
00056                         (*it)->disconnectAccount();
00057                 }
00058         }
00059 
00060         if( allAccountsWhereDisconnected ) {
00061                 checkAccountStates();
00062         }
00063 }
00064 
00065 void Blokkal::Protocol::checkAccountStates( void )
00066 {
00067         //check remaining acccounts
00068         AccountList accounts = Blokkal::AccountManager::self()->accounts();
00069         if( accounts.isEmpty() ) {
00070                 emit readyToUnload( this );
00071                 return;
00072         }
00073 
00074         bool isReadyToUnload = TRUE;
00075         for( AccountList::ConstIterator it = accounts.begin();
00076              it != accounts.end();
00077              ++it )
00078         {
00079                 if( (*it)->connectionStatus() != Blokkal::Account::Disconnected
00080                     && (*it)->protocol() == this )
00081                 {
00082                         isReadyToUnload = FALSE; //found remaining account that is still not disconnected
00083                         break;
00084 
00085                 }
00086         }
00087 
00088         if( isReadyToUnload ) {
00089                 //kDebug() << pluginName() << " ready to unload" << endl;
00090                 emit readyToUnload( this );
00091         }
00092 }
00093 
00094 Blokkal::Ui::FormattingBackend * Blokkal::Protocol::createFormattingBackend( Blokkal::Ui::EditEntryWidget * widget )
00095 {
00096         return new Blokkal::Ui::FormattingBackend( widget );
00097 }