~ubuntu-branches/ubuntu/utopic/smb4k/utopic-proposed

« back to all changes in this revision

Viewing changes to core/smb4kipaddressscanner.h

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: package-import@ubuntu.com-20120519185434-kpqpdrg5i47zm7tl
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
    smb4kipaddressscanner  -  This class scans for IP addresses. It
3
 
    belongs to the core classes of Smb4K.
 
2
    smb4kipaddressscanner  -  This class scans for IP addresses.
4
3
                             -------------------
5
 
    begin                : Di Apr 22 2008
6
 
    copyright            : (C) 2008 by Alexander Reinholdt
7
 
    email                : dustpuppy@users.berlios.de
 
4
    begin                : Fri Mar 18 2011
 
5
    copyright            : (C) 2011 by Alexander Reinholdt
 
6
    email                : alexander.reinholdt@kdemail.net
8
7
 ***************************************************************************/
9
8
 
10
9
/***************************************************************************
20
19
 *                                                                         *
21
20
 *   You should have received a copy of the GNU General Public License     *
22
21
 *   along with this program; if not, write to the                         *
23
 
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,   *
24
 
 *   MA  02111-1307 USA                                                    *
 
22
 *   Free Software Foundation, 51 Franklin Street, Suite 500, Boston,      *
 
23
 *   MA 02110-1335, USA                                                    *
25
24
 ***************************************************************************/
26
25
 
27
26
#ifndef SMB4KIPADDRESSSCANNER_H
31
30
#include <config.h>
32
31
#endif
33
32
 
34
 
// Qt includes
35
 
#include <QObject>
36
 
#include <QTimerEvent>
37
 
#include <QList>
38
 
 
39
33
// KDE includes
 
34
#include <kcompositejob.h>
40
35
#include <kdemacros.h>
41
 
#include <kprocess.h>
 
36
 
 
37
// application specific includes
 
38
#include <smb4kworkgroup.h>
 
39
#include <smb4khost.h>
42
40
 
43
41
// forward declarations
44
 
class Smb4KHost;
45
 
class Smb4KWorkgroup;
46
 
 
47
 
/**
48
 
 * This class scans for IP addresses of hosts found in the network. It
49
 
 * operates on the global host list.
50
 
 *
51
 
 * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
52
 
 */
53
 
 
54
 
class KDE_EXPORT Smb4KIPAddressScanner : public QObject
 
42
class Smb4KIPAddressScannerPrivate;
 
43
 
 
44
class KDE_EXPORT Smb4KIPAddressScanner : public KCompositeJob
55
45
{
56
46
  Q_OBJECT
57
47
 
59
49
 
60
50
  public:
61
51
    /**
62
 
     * Returns a static pointer to this class.
 
52
     * This function returns a static pointer to this class.
 
53
     *
 
54
     * @returns a static pointer to the Smb4KPrint class.
63
55
     */
64
56
    static Smb4KIPAddressScanner *self();
65
57
 
66
58
    /**
67
 
     * Triggers a scan for IP addresses. This function calls lookupIPAddresses(),
68
 
     * except the scanner is in auto scan mode. In this case it will return immediately
69
 
     * without doing anything.
70
 
     */
71
 
    void triggerScan();
72
 
 
73
 
    /**
74
 
     * Sets the scanner in automatic scan mode, if @p interval is non-zero.
75
 
     *
76
 
     * @param interval        The interval between the scans in milliseconds.
77
 
     */
78
 
    void setAutoScan( int interval );
79
 
 
80
 
    /**
81
 
     * Returns TRUE if the scanner is in auto scan mode and FALSE otherwise.
82
 
     *
83
 
     * @returns TRUE if the scanner is in auto scan mode.
84
 
     */
85
 
    bool autoScan() { return m_auto_scan; }
86
 
 
87
 
    /**
88
 
     * Lookup the IP address of a certain host. You need to connect to the
89
 
     * ipAddress() signal to get the result. The IP address scan will be
90
 
     * executed when the scanner is idle the next time.
91
 
     *
92
 
     * Please make sure that the pointer to @p host stays valid until the
93
 
     * search for the IP address finished and the ipAddress() signal is
94
 
     * emitted.
95
 
     *
96
 
     * @param host            The Smb4KHost item for which the IP address
97
 
     *                        should be looked up.
 
59
     * Starts a IP address lookup for all hosts currently present 
 
60
     * in the global hosts list. If @p force is TRUE, the all IP 
 
61
     * addresses will be looked up regardless whether the host already
 
62
     * has got one.
 
63
     * 
 
64
     * @param force         Force the lookup
 
65
     *
 
66
     * @param parent        The parent widget
 
67
     */
 
68
    void lookup( bool force = false,
 
69
                 QWidget *parent = 0 );
 
70
 
 
71
    /**
 
72
     * Get the IP address for the master browser of @p workgroup. This is
 
73
     * a convenience function and only searches Smb4KGlobal::hostList()
 
74
     * for the right host and copies the IP address. If you want to do an
 
75
     * IP address lookup, use the lookup() function.
 
76
     *
 
77
     * @param host          The Smb4KHost object
 
78
     */
 
79
    void getIPAddress( Smb4KWorkgroup *workgroup );
 
80
    
 
81
    /**
 
82
     * Get the IP address for @p host. This is a convenience function and
 
83
     * only searches  Smb4KGlobal::hostList() for the right host and copies
 
84
     * the IP address to @p host. If you want to do an IP address lookup, use
 
85
     * the lookup() function.
 
86
     *
 
87
     * @param host          The Smb4KHost object
98
88
     */
99
89
    void getIPAddress( Smb4KHost *host );
100
90
 
 
91
    /**
 
92
     * This function tells you if at least one IP address lookup job is
 
93
     * currently running.
 
94
     *
 
95
     * @returns TRUE if at least one lookup job is running
 
96
     */
 
97
    bool isRunning();
 
98
 
 
99
    /**
 
100
     * This function aborts all searches at once.
 
101
     */
 
102
    void abortAll();
 
103
 
 
104
    /**
 
105
     * This function starts the composite job
 
106
     */
 
107
    void start();
 
108
 
101
109
  signals:
102
110
    /**
103
 
     * This signal is emitted, when an IP address was found for a host. It passed
104
 
     * the associated Smb4KHost object.
105
 
     *
106
 
     * @param host            The Smb4KHost object that carries the discovered
107
 
     *                        IP address.
 
111
     * This signal is emitted when a lookup process is about to be started.
 
112
     * It passes the host to the receiver.
 
113
     *
 
114
     * @param host          The host
 
115
     */
 
116
    void aboutToStart( Smb4KHost *host );
 
117
 
 
118
    /**
 
119
     * This signal is emitted when a lookup process has finished. It passes
 
120
     * the host to the receiver.
 
121
     *
 
122
     * @param host          The host
 
123
     */
 
124
    void finished( Smb4KHost *host );
 
125
 
 
126
    /**
 
127
     * This signal is emitted when an IP address was successfully looked
 
128
     * up.
 
129
     *
 
130
     * @param host          The host
108
131
     */
109
132
    void ipAddress( Smb4KHost *host );
110
133
 
111
 
  protected:
112
 
    /**
113
 
     * Reimplemented from QObject.
114
 
     */
115
 
    void timerEvent( QTimerEvent *e );
116
 
 
117
134
  protected slots:
118
135
    /**
119
 
     * This slot is connected to the KProcess::readyReadStandardOutput()
120
 
     * signal and collects the IP addresses from the output.
121
 
     */
122
 
    void slotReceivedIPAddresses();
123
 
 
124
 
    /**
125
 
     * This slot is called, when the process exited.
126
 
     *
127
 
     * @param exitCode            The exit code of the process
128
 
     *
129
 
     * @param exitStatus          The exit status of the process (@see QProcess::ExitStatus)
130
 
     */
131
 
    void slotProcessFinished( int exitCode, QProcess::ExitStatus exitStatus );
132
 
 
133
 
    /**
134
 
     * This slot is invoked when an error occurred with the process.
135
 
     *
136
 
     * @param errorCode       The error code returned by the process
137
 
     */
138
 
    void slotProcessError( QProcess::ProcessError errorCode );
 
136
     * Invoked by start() function
 
137
     */
 
138
    void slotStartJobs();
 
139
 
 
140
    /**
 
141
     * Processes the host if it is a master browser.
 
142
     */
 
143
    void slotProcessIPAddress( Smb4KHost *host );
 
144
 
 
145
    /**
 
146
     * Invoked by KJob::result() signal
 
147
     */
 
148
    void slotJobFinished( KJob *job );
 
149
 
 
150
    /**
 
151
     * Called when the program is about to quit
 
152
     */
 
153
    void slotAboutToQuit();
139
154
 
140
155
  private:
141
156
    /**
142
 
     * The constructor
 
157
     * Constructor
143
158
     */
144
159
    Smb4KIPAddressScanner();
145
160
 
146
161
    /**
147
 
     * The destructor
 
162
     * Destructor
148
163
     */
149
164
    ~Smb4KIPAddressScanner();
150
 
 
151
 
    /**
152
 
     * This function loops through the global hosts list and initiates
153
 
     * an IP address lookup process for every host, that has not been
154
 
     * checked before.
155
 
     */
156
 
    void lookupIPAddresses();
157
 
 
158
 
    /**
159
 
     * Auto scan mode
160
 
     */
161
 
    bool m_auto_scan;
162
 
 
163
 
    /**
164
 
     * The id of the timer
165
 
     */
166
 
    int m_timer_id;
167
 
 
168
 
    /**
169
 
     * The scanner is working
170
 
     */
171
 
    bool m_working;
172
 
 
173
 
    /**
174
 
     * The process object
175
 
     */
176
 
    KProcess *m_proc;
177
 
 
178
 
    /**
179
 
     * The process error code
180
 
     */
181
 
    QProcess::ProcessError m_process_error;
182
 
 
183
 
    /**
184
 
     * The queue for buffering scan requests that were received
185
 
     * through the getIPAddress() function.
186
 
     */
187
 
    QList<Smb4KHost> m_queue;
188
165
};
189
166
 
190
167
#endif