summaryrefslogtreecommitdiffstats
path: root/networkstatus/connectionmanager.h
blob: 43d7e98bd943dd5cf8a506bade719046c4ef6e31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*  This file is part of kdepim.
    Copyright (C) 2005,2007 Will Stephenson <wstephenson@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library.  If not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

    As a special exception, permission is given to link this library
    with any edition of TQt, and distribute the resulting executable,
    without including the source code for TQt in the source distribution.
*/

#ifndef KDE_CONNECTION_MANAGER_H
#define KDE_CONNECTION_MANAGER_H

#include <dcopobject.h>
#include <kdemacros.h>

#include <networkstatuscommon.h>

class ConnectionManagerPrivate;

class KDE_EXPORT ConnectionManager : public TQObject, virtual public DCOPObject
{
Q_OBJECT
K_DCOP
k_dcop:
    void slotStatusChanged( int status );
public:
    /**
     * This defines application policy in response to networking connect/disconnect events
     * Manual - the app only disconnects when the user does so
     * OnNextChange - the app should connect or disconnect the next time the network changes state, thereafter
     * Manual
     * Managed - the app should disconnect when the ConnectionManager thinks the system is
     * offline
     */
    enum ConnectionPolicy { Manual, OnNextChange, Managed };
    /**
     * Set a policy to manage the application's connect behaviour
     */
    void setConnectPolicy( ConnectionPolicy );
    /**
     * Retrieve a policy managing the application's connect behaviour
     */
    ConnectionPolicy connectPolicy() const;

    /**
     * Set a policy to manage the application's disconnect behaviour
     */
    void setDisconnectPolicy( ConnectionPolicy );

    /**
     * Retrieve a policy managing the application's disconnect behaviour
     */
    ConnectionPolicy disconnectPolicy() const;

    /*
     * We'll get logic of the form
     * onStatusChange() {
     *   if ( ConnectionManager::self()->policy( ConnectionManager::ConnectBehaviour ) == ConnectionManager::OnNextChange || 
     *        ConnectionManager::self()->policy( ConnectionManager::ConnectBehaviour ) == ConnectionManager::Managed ) 
     *   {
     *        // do connect
     *
     *        // reset the policy
     *        if ( ConnectionManager::self()->policy( ConnectionManager::ConnectBehaviour ) == ConnectionManager::OnNextChange )
     *          ConnectionManager::self()->setPolicy( ConnectionManager::ConnectionManager,
     *          ConnectionManager::Manual );
     *   }
     * 
     * Do we just use the CM for policy storage, or do we try to factor the logic to implement the
     * policy into the CM too?
     *
     * could signal doConnect(), then reset the policy
     * or could register a connect slot
     *  registerConnectMethod( TQObject * receiver, const char * member );
     *  unregisterConnectMethod();
     * etc.
     * 
     * The problem with automatically controlled behaviour, where policy may change as a result of a
     * connect, is that if it is also manually altered, the CM needs to be updated.  But the CM needs to
     * be updated in any case.
     * CM need
     */
    /**
     * Lazy-method to set Manual on both policies
     */
    void setManualConnectionPolicies();
    /**
     * Lazy-method to set Managed on both policies
     */
    void setManagedConnectionPolicies();

    /**
     * Record a slot to call on a given receiving TQObject when 
     * 1) the network connection is online,
     * 2) the policy mandates that the app connect
     *
     * Only one slot may be registered at any one time. If a second slot is 
     * registered, the first slot is forgotten
     * @param receiver the TQObject where the slot is located
     * @param member the slot to call. Set up member using the TQT_SLOT() macro.
     */
    void registerConnectSlot( TQObject * receiver, const char * member );

    /**
     * Forget any connect slot previously registered
     */
    void forgetConnectSlot();

    /**
     * Has any slot been registered to be called on connect?
     */
    bool isConnectSlotRegistered() const;

    /**
     * Record a slot to call on a given receiving TQObject when 
     * 1) the network connection goes offline (in any way ),
     * 2) the policy mandates that the app disconnect
     *
     * Only one slot may be registered at any one time. If a second slot is 
     * registered, the first slot is forgotten
     * @param receiver the TQObject where the slot is located
     * @param member the slot to call. Set up member using the TQT_SLOT() macro.
     */
    void registerDisconnectSlot( TQObject * receiver, const char * member );

    /**
     * Forget any disconnect slot previously registered
     */
    void forgetDisconnectSlot();

    /**
     * Has any slot been registered to be called on disconnect?
     */
    bool isDisconnectSlotRegistered() const;

    /// existing API

    static ConnectionManager* self();
    virtual ~ConnectionManager();
    NetworkStatus::Status status();
signals:
    // signal that the network for a hostname is up/down
    void statusChanged( NetworkStatus::Status status );
private:
    // sets up internal state
    void initialise();
    // reread the desktop status from the daemon and update internal state
    ConnectionManager( TQObject *parent, const char * name );
    ConnectionManagerPrivate * d;
    static ConnectionManager * s_self;
};

#endif