~ubuntu-branches/ubuntu/vivid/smb4k/vivid

« back to all changes in this revision

Viewing changes to core/smb4ksearch.h

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mfrom: (1.1.20)
  • Revision ID: package-import@ubuntu.com-20120519185434-duffny2n87214n1n
Tags: 1.0.1-1
* New upstream release.
* Update debian/compat: bump to 9.
* Update debian/control:
  - bump debhelper to 9.
  - bump kdelibs5-dev build dependency to 4:4.4.0.
  - bump Standards-Version to 3.9.3 (no changes needed).
  - Replace smbfs dependency by cifs-utils. (Closes: #638162)
* Update debian/copyright:
  - update upstream URL.
  - update upstream e-mail.
* Update debian/smb4k.lintian-overrides file.
* Update debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
    smb4ksearch  -  This class searches for custom search strings.
 
2
    smb4ksearch  -  This class does custom searches
3
3
                             -------------------
4
 
    begin                : So Apr 27 2008
5
 
    copyright            : (C) 2008 by Alexander Reinholdt
6
 
    email                : dustpuppy@users.berlios.de
 
4
    begin                : Tue Mar 08 2011
 
5
    copyright            : (C) 2011 by Alexander Reinholdt
 
6
    email                : alexander.reinholdt@kdemail.net
7
7
 ***************************************************************************/
8
8
 
9
9
/***************************************************************************
31
31
#endif
32
32
 
33
33
// Qt includes
34
 
#include <QObject>
35
 
#include <QTimerEvent>
36
 
#include <QStringList>
37
 
#include <QPair>
 
34
#include <QWidget>
38
35
 
39
36
// KDE includes
 
37
#include <kcompositejob.h>
40
38
#include <kdemacros.h>
41
 
#include <kprocess.h>
42
 
 
43
 
// application specific includes
44
 
#include <smb4kworkgroup.h>
45
 
#include <smb4khost.h>
46
 
#include <smb4kshare.h>
47
 
 
48
 
/**
49
 
 * This class searches for network items (hosts and shares) and returns them.
50
 
 * Depending on the settings, it uses nmblookup, smbclient or smbtree.
51
 
 *
52
 
 * This class belongs to the core of Smb4K.
53
 
 *
54
 
 * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
55
 
 */
56
 
 
57
 
 
58
 
typedef QPair<Smb4KHost, bool> HostEntry;
59
 
 
60
 
class KDE_EXPORT Smb4KSearch : public QObject
 
39
 
 
40
// forward declarations
 
41
class Smb4KSearchPrivate;
 
42
class Smb4KSearchJob;
 
43
class Smb4KShare;
 
44
 
 
45
 
 
46
class KDE_EXPORT Smb4KSearch : public KCompositeJob
61
47
{
62
48
  Q_OBJECT
63
49
 
 
50
  friend class Smb4KSearchPrivate;
 
51
 
64
52
  public:
65
53
    /**
66
 
     * The constructor.
67
 
     *
68
 
     * @param parent            The parent of this class
69
 
     */
70
 
    Smb4KSearch( QObject *parent = 0 );
71
 
 
72
 
    /**
73
 
     * The destructor.
74
 
     */
75
 
    ~Smb4KSearch();
76
 
 
77
 
    /**
78
 
     * Search for a given search item. This can either be a share or a host.
79
 
     * The search will be done by default by using Samba's smbtree program.
80
 
     * If you provided an IP address, nmblookup will be used automatically.
81
 
     *
82
 
     * @param string            The search item
83
 
     */
84
 
    void search( const QString &string );
85
 
 
86
 
    /**
87
 
     * Abort the search process.
88
 
     */
89
 
    void abort();
90
 
 
91
 
    /**
92
 
     * This function reports if the search is running or not.
93
 
     *
94
 
     * @returns TRUE if the search is running and FALSE otherwise.
95
 
     */
96
 
    bool isRunning() { return m_working; }
 
54
     * This function returns a static pointer to this class.
 
55
     *
 
56
     * @returns a static pointer to the Smb4KSynchronizer class.
 
57
     */
 
58
    static Smb4KSearch *self();
 
59
 
 
60
    /**
 
61
     * Searches for specific search string in the network neighborhood.
 
62
     *
 
63
     * @param string          The search string
 
64
     *
 
65
     * @param parent          The parent widget
 
66
     */
 
67
    void search( const QString &string,
 
68
                 QWidget *parent = 0 );
 
69
 
 
70
    /**
 
71
     * This function tells you whether searches are running
 
72
     * or not.
 
73
     *
 
74
     * @returns TRUE if at least one search is running
 
75
     */
 
76
    bool isRunning();
 
77
 
 
78
    /**
 
79
     * With this function you can test whether a search is already/still
 
80
     * running.
 
81
     *
 
82
     * @returns TRUE if a search is already/still running
 
83
     */
 
84
    bool isRunning( const QString &string );
 
85
 
 
86
    /**
 
87
     * This function aborts all searches at once.
 
88
     */
 
89
    void abortAll();
 
90
 
 
91
    /**
 
92
     * This function aborts the searching for a certain search string 
 
93
     * in the network neighborhood.
 
94
     *
 
95
     * @param string          The search string
 
96
     */
 
97
    void abort( const QString &string );
 
98
 
 
99
    /**
 
100
     * This function starts the composite job
 
101
     */
 
102
    void start();
97
103
 
98
104
  signals:
99
105
    /**
100
 
     * This signal emits an Smb4KHost item that matches the search
101
 
     * criterion.
102
 
     *
103
 
     * @param host              The Smb4KHost object
104
 
     *
105
 
     * @param known             TRUE if the host is known to the application
106
 
     *                          and FALSE otherwise
107
 
     */
108
 
    void result( Smb4KHost *host,
109
 
                 bool known );
110
 
 
111
 
    /**
112
 
     * This signal emits an Smb4KShare item that matches the search
113
 
     * criterion.
114
 
     *
115
 
     * @param share             The Smb4KShare object
116
 
     *
117
 
     * @param mounted           TRUE if the share is already mounted and FALSE
118
 
     *                          otherwise.
119
 
     */
120
 
    void result( Smb4KShare *share,
121
 
                 bool mounted );
122
 
 
123
 
    /**
124
 
     * This signal emits the run state.
125
 
     *
126
 
     * @param state         The so-called run state. There are several defined
127
 
     *                      in the smb4kdefs.h header file.
128
 
     */
129
 
    void state( int state );
130
 
 
131
 
    /**
132
 
     * This signal is emitted when the process finished.
133
 
     */
134
 
    void finished();
135
 
 
136
 
  protected:
137
 
    /**
138
 
     * Reimplemented from QObject
139
 
     */
140
 
    void timerEvent( QTimerEvent *e );
 
106
     * This signal is emitted when a search process is about to be started. It passes
 
107
     * the search string to the receiver.
 
108
     *
 
109
     * @param string        The search string
 
110
     */
 
111
    void aboutToStart( const QString &string );
 
112
 
 
113
    /**
 
114
     * This signal is emitted when a search process has finished. It passes the
 
115
     * search string to the receiver.
 
116
     *
 
117
     * @param string        The search string
 
118
     */
 
119
    void finished( const QString &string );
 
120
 
 
121
    /**
 
122
     * This signal is emitted when the search returned a result.
 
123
     *
 
124
     * @param item          The network item
 
125
     *
 
126
     * @param mounted       Is the item already known?
 
127
     */
 
128
    void result( Smb4KShare *share );
141
129
 
142
130
  protected slots:
143
131
    /**
144
 
     * This slot is called when output was received on stderr.
145
 
     */
146
 
    void slotReadyReadStandardError();
147
 
 
148
 
    /**
149
 
     * This slot is called when output was received on stdout. It is
150
 
     * used to process the search results.
151
 
     */
152
 
    void slotReadyReadStandardOutput();
153
 
 
154
 
    /**
155
 
     * This slot is called, when the process exited.
156
 
     *
157
 
     * @param exitCode           The exit code of the process
158
 
     *
159
 
     * @param exitStatus         The exit status of the process (@see QProcess::ExitStatus)
160
 
     */
161
 
    void slotProcessFinished( int exitCode, QProcess::ExitStatus exitStatus );
162
 
 
163
 
    /**
164
 
     * This slot is invoked when an error occurred with the process.
165
 
     *
166
 
     * @param errorCode       The error code returned by the process
167
 
     */
168
 
    void slotProcessError( QProcess::ProcessError errorCode );
169
 
 
170
 
    /**
171
 
     * Receive the IP address of a host (or for a share) from the IP
172
 
     * address scanner.
173
 
     *
174
 
     * @param host            The Smb4KHost item that carries the IP address.
175
 
     */
176
 
    void slotReceiveIPAddress( Smb4KHost *host );
 
132
     * Invoked by start() function
 
133
     */
 
134
    void slotStartJobs();
 
135
 
 
136
    /**
 
137
     * Called when a job finished
 
138
     */
 
139
    void slotJobFinished( KJob *job );
 
140
 
 
141
    /**
 
142
     * Called when an authentication error occurred
 
143
     */
 
144
    void slotAuthError( Smb4KSearchJob *job );
 
145
 
 
146
    /**
 
147
     * Called when an search result was found
 
148
     */
 
149
    void slotProcessSearchResult( Smb4KShare *share );
 
150
 
 
151
    /**
 
152
     * Called when the program is about to quit
 
153
     */
 
154
    void slotAboutToQuit();
177
155
 
178
156
  private:
179
157
    /**
180
 
     * The timer id
181
 
     */
182
 
    int m_timer_id;
183
 
 
184
 
    /**
185
 
     * Carries a list of search items that need to be processed
186
 
     */
187
 
    QStringList m_list;
188
 
 
189
 
    /**
190
 
     * Already working
191
 
     */
192
 
    bool m_working;
193
 
 
194
 
    /**
195
 
     * The process object
196
 
     */
197
 
    KProcess *m_proc;
198
 
 
199
 
    /**
200
 
     * Process error
201
 
     */
202
 
    QProcess::ProcessError m_process_error;
203
 
 
204
 
    /**
205
 
     * The master browser as reported by smbtree
206
 
     */
207
 
    Smb4KHost m_master_browser;
208
 
 
209
 
    /**
210
 
     * The workgroup string
211
 
     */
212
 
    QString m_workgroup_string;
213
 
 
214
 
    /**
215
 
     * Was the process aborted?
216
 
     */
217
 
    bool m_aborted;
218
 
 
219
 
    /**
220
 
     * Do we need to retry?
221
 
     */
222
 
    bool m_retry;
223
 
 
224
 
    /**
225
 
     * The state enumeration
226
 
     */
227
 
    enum State{ FullSearch,
228
 
                IPSearch,
229
 
                Idle };
230
 
 
231
 
    /**
232
 
     * The state
233
 
     */
234
 
    State m_state;
235
 
 
236
 
    /**
237
 
     * The list of hosts, that are discovered during one one.
238
 
     */
239
 
    QList<HostEntry> m_hosts_list;
 
158
     * Constructor
 
159
     */
 
160
    Smb4KSearch();
 
161
 
 
162
    /**
 
163
     * Destructor
 
164
     */
 
165
    ~Smb4KSearch();
240
166
};
241
167
 
242
168
#endif