libemailfunctions

networkstatus.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of libkdepim.
00003 
00004     Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library 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 GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <kconfig.h>
00023 #include <kglobal.h>
00024 #include <kstaticdeleter.h>
00025 
00026 #include <dcopref.h>
00027 
00028 #include "networkstatus.h"
00029 
00030 using namespace KPIM;
00031 
00032 static KStaticDeleter<NetworkStatus> networkStatusDeleter;
00033 NetworkStatus *NetworkStatus::mSelf = 0;
00034 
00035 NetworkStatus::NetworkStatus()
00036   : QObject( 0, "NetworkStatus" ), DCOPObject( "NetworkStatus" )
00037 {
00038   KConfigGroup group( KGlobal::config(), "NetworkStatus" );
00039   if ( group.readBoolEntry( "Online", true ) == true )
00040     mStatus = Online;
00041   else
00042     mStatus = Offline;
00043 
00044   connectDCOPSignal( 0, 0, "onlineStatusChanged()", "onlineStatusChanged()", false );
00045 }
00046 
00047 NetworkStatus::~NetworkStatus()
00048 {
00049   KConfigGroup group( KGlobal::config(), "NetworkStatus" );
00050   group.writeEntry( "Online", mStatus == Online );
00051 }
00052 
00053 void NetworkStatus::setStatus( Status status )
00054 {
00055   mStatus = status;
00056 
00057   emit statusChanged( mStatus );
00058 }
00059 
00060 NetworkStatus::Status NetworkStatus::status() const
00061 {
00062   return mStatus;
00063 }
00064 
00065 void NetworkStatus::onlineStatusChanged()
00066 {
00067   DCOPRef dcopCall( "kded", "networkstatus" );
00068   DCOPReply reply = dcopCall.call( "onlineStatus()", true );
00069   if ( reply.isValid() ) {
00070     int status = reply;
00071     if ( status == 3 )
00072       setStatus( Online );
00073     else {
00074       if ( mStatus != Offline )
00075         setStatus( Offline );
00076     }
00077   }
00078 }
00079 
00080 NetworkStatus *NetworkStatus::self()
00081 {
00082   if ( !mSelf )
00083     networkStatusDeleter.setObject( mSelf, new NetworkStatus );
00084 
00085   return mSelf;
00086 }
00087 
00088 #include "networkstatus.moc"