blogbrowsingdriver.cpp
00001 /*************************************************************************** 00002 * Copyright (C) 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 #include "blogbrowsingdriver.h" 00021 #include "blogbrowsingdriver.moc" 00022 00023 #include "../blokkalblog.h" 00024 #include "../blokkalaccount.h" 00025 #include "../blokkalpluginmanager.h" 00026 00027 #include "../blokkalui/browseentryviewfactory.h" 00028 00029 class Blokkal::Io::BlogBrowsingDriver::Private { 00030 public: 00031 Private( Blokkal::Blog * blog ): 00032 blog( blog ) {} 00033 00034 Blokkal::Blog * const blog; 00035 QList<Ui::BrowseEntryDialog*> dialogList; 00036 }; 00037 00038 Blokkal::Io::BlogBrowsingDriver::BlogBrowsingDriver( Blokkal::Blog * parent ): 00039 QObject( parent ), 00040 d( new Private( parent ) ) 00041 { 00042 connect( blog()->account(), 00043 SIGNAL( connectionStatusChanged( Blokkal::Account* ) ), 00044 SLOT( slotAccountStatusChanged( Blokkal::Account* ) ) ); 00045 } 00046 00047 Blokkal::Io::BlogBrowsingDriver::~BlogBrowsingDriver( void ) 00048 { 00049 for( int i = 0; i < d->dialogList.size(); ++i ) { 00050 d->dialogList[i]->close(); 00051 delete d->dialogList.takeAt(i); 00052 } 00053 delete d; 00054 } 00055 00056 unsigned int Blokkal::Io::BlogBrowsingDriver::recentLimit( void ) const 00057 { 00058 return 0; 00059 } 00060 00061 unsigned int Blokkal::Io::BlogBrowsingDriver::supportedOperations( void ) const 00062 { 00063 return 0; 00064 } 00065 00066 Blokkal::Io::LoadEntryJob * Blokkal::Io::BlogBrowsingDriver::createLoadEntryJob( const QStringList & idList ) 00067 { 00068 Q_UNUSED( idList ); 00069 return 0; 00070 } 00071 00072 Blokkal::Io::LoadEntryJob * Blokkal::Io::BlogBrowsingDriver::createLoadEntryJob( const QDate & date ) 00073 { 00074 Q_UNUSED( date ); 00075 return 0; 00076 } 00077 00078 Blokkal::Io::LoadEntryJob * Blokkal::Io::BlogBrowsingDriver::createLoadEntryJob( unsigned int n ) 00079 { 00080 Q_UNUSED( n ); 00081 return 0; 00082 } 00083 00084 Blokkal::Io::LoadIndexJob * Blokkal::Io::BlogBrowsingDriver::createLoadIndexJob( const QDate & from, const QDate & to ) 00085 { 00086 Q_UNUSED( from ); 00087 Q_UNUSED( to ); 00088 return 0; 00089 } 00090 00091 Blokkal::Blog * Blokkal::Io::BlogBrowsingDriver::blog( void ) const 00092 { 00093 return d->blog; 00094 } 00095 00096 unsigned int Blokkal::Io::BlogBrowsingDriver::supportedBrowseModes( void ) const 00097 { 00098 return BrowseEdit|BrowseLink; 00099 } 00100 00101 Blokkal::Ui::BrowseEntryDialog * Blokkal::Io::BlogBrowsingDriver::browseBlogDialog( BrowseMode mode ) 00102 { 00103 if( mode == BrowseEdit ) { 00104 for( int i = 0; i < d->dialogList.size(); ++i ) { 00105 if( d->dialogList[i]->mode() == mode ) { 00106 return d->dialogList[i]; 00107 } 00108 } 00109 } 00110 00111 for( int i = 0; i < d->dialogList.size(); ++i ) { 00112 if( !d->dialogList[i]->isVisible() ) { 00113 d->dialogList[i]->setMode( mode ); 00114 return d->dialogList[i]; 00115 } 00116 } 00117 00118 Ui::BrowseEntryDialog * const browseView = Blokkal::PluginManager::self()->browseEntryViewFactory()->createView( blog() ); 00119 browseView->setMode( mode ); 00120 d->dialogList.append( browseView ); 00121 connect( browseView, 00122 SIGNAL( destroyed( QObject * ) ), 00123 SLOT( slotBrowseViewDestroyed( QObject * ) ) ); 00124 connect( browseView, 00125 SIGNAL( finished( void ) ), 00126 SLOT( slotBrowseViewFinished( void ) ) ); 00127 return browseView; 00128 } 00129 00130 void Blokkal::Io::BlogBrowsingDriver::slotBrowseViewDestroyed( QObject * object ) 00131 { 00132 for( int i = 0; i < d->dialogList.size(); ++i ) { 00133 if( d->dialogList[i] == object ) { 00134 d->dialogList.takeAt( i ); 00135 i--; 00136 } 00137 } 00138 } 00139 00140 void Blokkal::Io::BlogBrowsingDriver::slotAccountStatusChanged( Blokkal::Account * account ) 00141 { 00142 if( account->isConnected() ) { 00143 return; 00144 } 00145 00146 for( int i = 0; i < d->dialogList.size(); ++i ) { 00147 d->dialogList[i]->close(); 00148 } 00149 } 00150 00151 void Blokkal::Io::BlogBrowsingDriver::slotBrowseViewFinished( void ) 00152 { 00153 for( int i = 0; i < d->dialogList.size() && d->dialogList.size() > 1; ++i ) { 00154 if( !d->dialogList[i]->isVisible() ) { 00155 d->dialogList.takeAt( i )->deleteLater(); 00156 i--; 00157 } 00158 } 00159 } 00160 00161 QList< Blokkal::Ui::BrowseOptionWidget * > Blokkal::Io::BlogBrowsingDriver::customBrowseOptionWidgets( QWidget * parent ) 00162 { 00163 Q_UNUSED( parent ); 00164 return QList< Blokkal::Ui::BrowseOptionWidget * >(); 00165 }