Blokkal
an Extendable KDE Blogging Client
SourceForge.net Logo

blokkalaccount.h

00001 /***************************************************************************
00002  *   Copyright (C) 2006 - 2008 by Martin Mueller                           *
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 #ifndef BLOKKALACCOUNT_H
00021 #define BLOKKALACCOUNT_H
00022 
00023 #include <QtCore/QObject>
00024 
00025 #include "blokkal_export.h"
00026 
00027 class QAction;
00028 
00029 class KUrl;
00030 class QDomElement;
00031 class KIcon;
00032 
00033 namespace KWallet {
00034 class Wallet;
00035 }
00036 
00037 namespace Blokkal  {
00038 class Protocol;
00039 class AccountConfig;
00040 class Blog;
00041 class BlogConfig;
00042 namespace Io {
00043 class CategoryManager;
00044 }
00045 
00052 class BLOKKAL_EXPORT Account : public QObject
00053 {
00054 Q_OBJECT
00055 public:
00059         enum ConnectionStatus {
00060                 Connected = 1, 
00061                 Connecting = 2, 
00062                 Disconnected = 3, 
00063         };
00064 
00068         enum DisconnectReason {
00069                 UserDisconnect = 1, 
00070                 IOErrorDisconnect = 2, 
00071                 OtherDisconnect = 3, 
00072                 AuthenticationDisconnect = 4, 
00073         };
00074 
00080         virtual ~Account( void );
00081 
00086         Blokkal::Protocol * protocol( void ) const;
00087                 
00095         QString serverName( void ) const;
00096 
00101         void setServerName( const QString & serverName );
00102 
00107         KUrl connectAddress( void ) const;
00108 
00113         void setConnectAddress( const QString & address );
00114         
00121         bool usesDefaultConnectAddress( void ) const;
00122 
00128         void setUsesDefaultConnectAddress( bool useDefault );
00129 
00134         bool autoConnect( void ) const;
00135 
00140         void setAutoConnect( bool enable ) const;
00141 
00146         QString id( void ) const;
00147 
00154         QString userName( void ) const;
00155 
00160         void setUserName( const QString & user );
00161 
00166         virtual KIcon icon( void ) const;
00167 
00173         virtual void removeAccount( void );
00174 
00180         Blokkal::Account::ConnectionStatus connectionStatus( void ) const;
00181 
00186         bool isConnected( void ) const;
00187 
00192         bool isDisconnected( void ) const;
00193 
00198         QList< Blokkal::Blog * > blogs( void ) const;
00199 
00205         Blokkal::Blog * blog( const QString & id ) const;
00206 
00212         QString dataDirectory( void ) const;
00213 
00219         virtual QList<QAction*> actionList( void );
00220 
00221 public Q_SLOTS:
00229         virtual void connectAccount( void ) = 0;
00230 
00242         virtual void disconnectAccount( Blokkal::Account::DisconnectReason reason = UserDisconnect,
00243                                         const QString & reasonString = 0 );
00244 
00248         void restoreBlogs( void );
00249 
00254         Blokkal::Io::CategoryManager * categoryManager( void ) const;
00255 
00256 Q_SIGNALS:
00260         void accountDestroyed( Blokkal::Account * account );
00261 
00266         void connectionStatusChanged( Blokkal::Account * account );
00267 
00271         void blogRegistered( Blokkal::Blog * blog );
00272 
00276         void blogUnregistered( Blokkal::Blog * blog );
00277 
00278 protected:
00284         Account( Blokkal::Protocol * protocol, const QString & id = 0 );
00285         
00291         void setConnectionStatus( Blokkal::Account::ConnectionStatus status );
00292 
00297         Blokkal::AccountConfig * config( void ) const;
00298         
00307         QDomElement blogNode( const QString & id );
00308         
00317         virtual Blokkal::Blog * restoreBlog( Blokkal::BlogConfig * config ) = 0;
00318         
00319 protected Q_SLOTS:
00328         Blokkal::Blog * registerBlog( Blokkal::Blog * blog );
00329 
00335         void unregisterBlog( Blokkal::Blog * blog );
00336 
00337 private:
00338         class Private;
00339         Private * const d;
00340         friend class BlogConfig;
00341 };
00342 
00350 class BLOKKAL_EXPORT PasswordedAccount : public Blokkal::Account
00351 {
00352 Q_OBJECT
00353 public: 
00359         virtual ~PasswordedAccount( void );
00360 
00366         virtual void removeAccount( void );
00367 
00368 public Q_SLOTS:
00373         virtual void connectAccount( void );
00374 
00382         virtual void disconnectAccount( Blokkal::Account::DisconnectReason reason = UserDisconnect,
00383                                         const QString & reasonString = 0 );
00384         
00385 protected:
00391         PasswordedAccount( Blokkal::Protocol * protocol, const QString & id = 0 );
00392 
00397         const QString & password( void ) const;
00398 
00399 protected Q_SLOTS:
00407         virtual void connectInner( void ) = 0;
00408 
00409 private Q_SLOTS:
00410         void slotWalletOpened( KWallet::Wallet * wallet );
00411         
00412 private:
00413         QString promptUser( bool & success, KWallet::Wallet * wallet );
00414         
00415         class Private;
00416         Private * const d;
00417 
00418 };
00419 
00420 } //Blokkal
00421 
00422 
00423 
00424 
00425 #endif