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

« back to all changes in this revision

Viewing changes to smb4k/core/smb4kcore.h

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2005-03-29 12:15:53 UTC
  • Revision ID: james.westby@ubuntu.com-20050329121553-s5ohipujfw3wmo25
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          smb4kcore  -  description
 
3
                             -------------------
 
4
    begin                : Do Apr 8 2004
 
5
    copyright            : (C) 2004 by Alexander Reinholdt
 
6
    email                : dustpuppy@mail.berlios.de
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#ifndef SMB4KCORE_H
 
19
#define SMB4KCORE_H
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
 
 
25
// Qt includes
 
26
#include <qobject.h>
 
27
#include <qmap.h>
 
28
#include <qtimer.h>
 
29
 
 
30
// KDE includes
 
31
#include <kconfig.h>
 
32
 
 
33
// application specific includes
 
34
#include "smb4kscanner.h"
 
35
#include "smb4kmounter.h"
 
36
#include "smb4kpasswdreader.h"
 
37
#include "smb4kfileio.h"
 
38
#include "smb4kipfinder.h"
 
39
#include "smb4kbookmarkhandler.h"
 
40
#include "smb4kprint.h"
 
41
#include "smb4kshellio.h"
 
42
 
 
43
 
 
44
/**
 
45
 * This is the top-level core class. It inherits all other core classes 
 
46
 * except the containers.
 
47
 */
 
48
 
 
49
class Smb4KCore : public QObject
 
50
{
 
51
  Q_OBJECT
 
52
  
 
53
  public:
 
54
    /**
 
55
     * The constructor.
 
56
     */
 
57
    Smb4KCore( QObject *parent = 0, const char *name = 0 );
 
58
    /**
 
59
     * The destructor.
 
60
     */
 
61
    ~Smb4KCore();
 
62
    /**
 
63
     * Returns the state the scanner is in.
 
64
     */
 
65
    int scannerState() { return m_scanner_state; }
 
66
    /**
 
67
     * Returns TRUE, if the scanner is running, otherwise FALSE.
 
68
     */
 
69
    bool scannerIsRunning() { return m_scanner_running; }
 
70
    /**
 
71
     * Returns the state the mounter is in.
 
72
     */
 
73
    int mounterState() { return m_mounter_state; }
 
74
    /**
 
75
     * Returns TRUE, if the mounter is running, otherwise FALSE.
 
76
     */
 
77
    bool mounterIsRunning() { return m_mounter_running; }
 
78
    /**
 
79
     * Returns the state the IP finder is in.
 
80
     */
 
81
    int ipFinderState() { return m_ipfinder_state; }
 
82
    /**
 
83
     * Returns TRUE, if the IP finder is running, otherwise FALSE.
 
84
     */
 
85
    bool ipFinderIsRunning() { return m_ipfinder_running; }
 
86
    /**
 
87
     * Returns the state the print object is in.
 
88
     */
 
89
    int printState() { return m_print_state; }
 
90
    /**
 
91
     * Returns TRUE, if the print object is running, otherwise FALSE.
 
92
     */
 
93
    bool printIsRunning() { return m_print_running; }
 
94
    /**
 
95
     * Returns TRUE if one of the core classes is doing something.
 
96
     */
 
97
    bool isRunning();
 
98
    /**
 
99
     * Returns the current state the core class is in.
 
100
     */
 
101
    int currentState() { return m_current_state; }
 
102
    /**
 
103
     * Returns a pointer to the scanner object.
 
104
     */
 
105
    Smb4KScanner *scanner() { return m_scanner; }
 
106
    /**
 
107
     * Returns a pointer to the mounter object.
 
108
     */
 
109
    Smb4KMounter *mounter() { return m_mounter; }
 
110
    /**
 
111
     * Returns a pointer to the bookmark handler object.
 
112
     */
 
113
    Smb4KBookmarkHandler *bookmarkHandler() { return m_bookmarkHandler; }
 
114
    /**
 
115
     * Returns a pointer to the file IO object.
 
116
     */
 
117
    Smb4KFileIO *fileIO() { return m_fileIO; }
 
118
    /**
 
119
     * Returns a pointer to the IP finder object.
 
120
     */
 
121
    Smb4KIPFinder *ipFinder() { return m_finder; }
 
122
    /**
 
123
     * Returns a pointer to the password reader object.
 
124
     */
 
125
    Smb4KPasswdReader *passwdReader() { return m_passwdReader; }
 
126
    /**
 
127
     * Returns a pointer to the printer handler object.
 
128
     */
 
129
    Smb4KPrint *print() { return m_print; }
 
130
    /**
 
131
     * Returns the pointer ti the shell IO object.
 
132
     */
 
133
    Smb4KShellIO *shellIO() { return m_shellIO; }
 
134
    /**
 
135
     * Aborts any action of the core.
 
136
     */
 
137
    void abort();
 
138
    /**
 
139
     * Opens the mount point of a share. This function is used to run the file manager.
 
140
     *
 
141
     * @param share The share to be opened.
 
142
     */
 
143
    void open( Smb4KShare *share );
 
144
    /**
 
145
     * This function returns the UMASK as integer. It is provided 
 
146
     * for convenience.
 
147
     */
 
148
    int getUMASK();
 
149
    /**
 
150
     * This function returns the Kernel version string. It is provided 
 
151
     * for convenience.
 
152
     */
 
153
    const QString getKernelVersion();
 
154
    /**
 
155
     * This function returns the system name. It is provided 
 
156
     * for convenience.
 
157
     */
 
158
    const QString getSystemName();
 
159
    /**
 
160
     * This function will return Samba's version string.
 
161
     */
 
162
    const QString getSambaVersion() { return m_samba_version; }
 
163
    /**
 
164
     * This function returns the global options of the smb.conf file. You 
 
165
     * can reach the value of each option by providing the lowercase option 
 
166
     * name as key, if it was defined in the global section of the smb.conf.
 
167
     */
 
168
    const QMap<QString, QString> getGlobalSambaOptions() { return m_fileIO->readSMBOptions(); }
 
169
    /**
 
170
     * This function returns the WINS server the system is using.
 
171
     */
 
172
    const QString getWINSServer();
 
173
    /**
 
174
     * Sets the share for which the usage should be returned. You may also pass
 
175
     * the NULL pointer. In this case, the usage() signal will return empty values.
 
176
     * @param share The share object.
 
177
     */
 
178
    void setShareForUsageInfo( Smb4KShare *share );
 
179
    
 
180
  signals:
 
181
    /**
 
182
     * This signal is emitted, if one of the core objects
 
183
     * starts or stops running.
 
184
     */
 
185
    void runStateChanged();
 
186
    /**
 
187
     * This signal emits the usage info for a share.
 
188
     *
 
189
     * @param mountpoint    The mountpoint/path that usage should be determined.
 
190
     *
 
191
     * @param total         The total space that's available on the filesystem (in kB).
 
192
     *
 
193
     * @param used          The space that's used (in kB).
 
194
     *
 
195
     * @param free          The space that's free (in kB).
 
196
     *
 
197
     * @param percent       The percentage the used space eats up (in kB).
 
198
     * 
 
199
     * @param dirs          The number of directories present in the mount point. The items
 
200
     *                      '.' and '..' are ignored.
 
201
     * 
 
202
     * @param files         The number of files present in the mount point.
 
203
     */
 
204
    void usage( const QString &mountpoint, double total, double used, double free, double percent, int dirs, int files );
 
205
    
 
206
  protected slots:
 
207
    /**
 
208
     * This slot is called, if the scanner is running. 
 
209
     */
 
210
    void slotScannerIsRunning( int state, bool on );
 
211
    /**
 
212
     * This slot is called, if the mounter is running.
 
213
     */
 
214
    void slotMounterIsRunning( int state, bool on );
 
215
    /**
 
216
     * This slot is called, if the mounter is running.
 
217
     */
 
218
    void slotIPFinderIsRunning( int state, bool on );
 
219
    /**
 
220
     * This slot is called, if the printer handler is running.
 
221
     */
 
222
    void slotPrinterHandlerIsRunning( int state, bool on );
 
223
    /**
 
224
     * This slot is called if an error in the core classes
 
225
     * occurred.
 
226
     */
 
227
    void slotShowErrorMessage( int error_code, const QString &error_message = QString::null );
 
228
    /**
 
229
     * This slot is called by the KApplication::shutDown() signal. Here all actions are
 
230
     * taken to exit the core savely.
 
231
     */
 
232
    void slotShutdown();
 
233
    /**
 
234
     * This slot receives the sambaVersion() signal by Smb4KShellIO and writes 
 
235
     * Samba's version to the config file.
 
236
     * @param version Samba's version string.
 
237
     */
 
238
    void slotReceiveSambaVersion( const QString &version );
 
239
    /**
 
240
     * This slot will invoke Smb4KShellIO::getSambaVersion(). It is
 
241
     * reimplemented for convenience. Connect to Smb4KCore::sambaVersion() to
 
242
     * get the result.
 
243
     */
 
244
    void slotGetSambaVersion();
 
245
    /**
 
246
     * This slot is connected to the timer. It is used to determine the usage
 
247
     * of a share and emits this data via the usage() signal.
 
248
     */
 
249
    void slotGetUsage();
 
250
      
 
251
  private:
 
252
    /**
 
253
     * The scanner object.
 
254
     */
 
255
    Smb4KScanner *m_scanner;
 
256
    /**
 
257
     * The mounter object.
 
258
     */
 
259
    Smb4KMounter *m_mounter;
 
260
    /**
 
261
     * The bookmark handler object.
 
262
     */
 
263
    Smb4KBookmarkHandler *m_bookmarkHandler;
 
264
    /**
 
265
     * The FileIO object.
 
266
     */
 
267
    Smb4KFileIO *m_fileIO;
 
268
    /**
 
269
     * The IP finder object.
 
270
     */
 
271
    Smb4KIPFinder *m_finder;
 
272
    /**
 
273
     * The password reader object.
 
274
     */
 
275
    Smb4KPasswdReader *m_passwdReader;
 
276
    /**
 
277
     * The printer handler object.
 
278
     */
 
279
    Smb4KPrint *m_print;
 
280
    /**
 
281
     * The shell IO object.
 
282
     */
 
283
    Smb4KShellIO *m_shellIO;
 
284
    /**
 
285
     * The state the sanner is in.
 
286
     */
 
287
    int m_scanner_state;
 
288
    /**
 
289
     * Is TRUE when the scanner is running, otherwise it is FALSE.
 
290
     */
 
291
    bool m_scanner_running;
 
292
    /**
 
293
     * The state the mounter is in.
 
294
     */
 
295
    int m_mounter_state;
 
296
    /**
 
297
     * Is TRUE when the mounter is running, otherwise it is FALSE.
 
298
     */
 
299
    bool m_mounter_running;
 
300
    /**
 
301
     * The state the IP finder is in.
 
302
     */
 
303
    int m_ipfinder_state;
 
304
    /**
 
305
     * Is TRUE when the IP finder is running, otherwise it is FALSE.
 
306
     */
 
307
    bool m_ipfinder_running;
 
308
    /**
 
309
     * Holds the current state.
 
310
     */
 
311
    int m_current_state;
 
312
    /**
 
313
     * The state the printer handler is in.
 
314
     */
 
315
    int m_print_state;
 
316
    /**
 
317
     * Is TRUE when the printer handler is running, otherwise it is FALSE.
 
318
     */
 
319
    bool m_print_running;
 
320
    /**
 
321
     * The advanced options for smbclient.
 
322
     */
 
323
    QString m_advancedSMBOptions;
 
324
    /**
 
325
     * The KConfig object.
 
326
     */
 
327
    KConfig *m_config;
 
328
    /**
 
329
     * Stores Samba's version string.
 
330
     */
 
331
    QString m_samba_version;
 
332
    /**
 
333
     * This function is used to set the current state of the core.
 
334
     * @param state One of the states defined in smb4kdefs.h
 
335
     */
 
336
    void setCurrentState( int state );
 
337
    /**
 
338
     * Searches for the needed programs and emits an error
 
339
     * if mandatory ones are missing.
 
340
     */
 
341
    void searchPrograms();
 
342
    /**
 
343
     * The path for which the disk usage should be determined.
 
344
     */
 
345
    QString m_path;
 
346
    /**
 
347
     * The timer for retrieving the usage periodically.
 
348
     */
 
349
    QTimer *m_timer;
 
350
};
 
351
 
 
352
#endif