libemailfunctions

networkstatus.cpp
1/*
2 This file is part of libtdepim.
3
4 Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include <tdeconfig.h>
23#include <tdeglobal.h>
24#include <kstaticdeleter.h>
25
26#include <dcopref.h>
27
28#include "networkstatus.h"
29
30using namespace KPIM;
31
32static KStaticDeleter<NetworkStatus> networkStatusDeleter;
33NetworkStatus *NetworkStatus::mSelf = 0;
34
35NetworkStatus::NetworkStatus()
36 : TQObject( 0, "NetworkStatus" ), DCOPObject( "NetworkStatus" )
37{
38 TDEConfigGroup group( TDEGlobal::config(), "NetworkStatus" );
39 if ( group.readBoolEntry( "Online", true ) == true )
40 mStatus = Online;
41 else
42 mStatus = Offline;
43
44 connectDCOPSignal( 0, 0, "onlineStatusChanged()", "onlineStatusChanged()", false );
45}
46
48{
49 TDEConfigGroup group( TDEGlobal::config(), "NetworkStatus" );
50 group.writeEntry( "Online", mStatus == Online );
51}
52
54{
55 mStatus = status;
56
57 emit statusChanged( mStatus );
58}
59
61{
62 return mStatus;
63}
64
66{
67 DCOPRef dcopCall( "kded", "networkstatus" );
68 DCOPReply reply = dcopCall.call( "onlineStatus()", true );
69 if ( reply.isValid() ) {
70 int status = reply;
71 if ( status == 3 )
72 setStatus( Online );
73 else {
74 if ( mStatus != Offline )
75 setStatus( Offline );
76 }
77 }
78}
79
81{
82 if ( !mSelf )
83 networkStatusDeleter.setObject( mSelf, new NetworkStatus );
84
85 return mSelf;
86}
87
88#include "networkstatus.moc"
This is a class for monitoring network status – basically, the machine KDE is running on going from "...
Definition: networkstatus.h:36
Status status() const
Returns the current status.
void setStatus(Status status)
Sets a new status.
void statusChanged(Status status)
Emitted whenever the status has changed.
Status
The possible states.
Definition: networkstatus.h:43
~NetworkStatus()
Destructor.
void onlineStatusChanged()
Called by the network interface watcher in KDED.
static NetworkStatus * self()
Returns the only instance of this class.
KPIM holds all kinds of functions specific to KDE PIM.
Definition: email.h:38