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

« back to all changes in this revision

Viewing changes to core/smb4ksambaoptionshandler.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
 
/***************************************************************************
2
 
    smb4ksambaoptionshandler  -  This class handles the Samba options.
3
 
                             -------------------
4
 
    begin                : So Mai 14 2006
5
 
    copyright            : (C) 2006-2008 by Alexander Reinholdt
6
 
    email                : dustpuppy@users.berlios.de
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *   This program is free software; you can redistribute it and/or modify  *
11
 
 *   it under the terms of the GNU General Public License as published by  *
12
 
 *   the Free Software Foundation; either version 2 of the License, or     *
13
 
 *   (at your option) any later version.                                   *
14
 
 *                                                                         *
15
 
 *   This program is distributed in the hope that it will be useful, but   *
16
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
17
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
18
 
 *   General Public License for more details.                              *
19
 
 *                                                                         *
20
 
 *   You should have received a copy of the GNU General Public License     *
21
 
 *   along with this program; if not, write to the                         *
22
 
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,   *
23
 
 *   MA  02111-1307 USA                                                    *
24
 
 ***************************************************************************/
25
 
 
26
 
#ifndef SMB4KSAMBAOPTIONSHANDLER_H
27
 
#define SMB4KSAMBAOPTIONSHANDLER_H
28
 
 
29
 
#ifdef HAVE_CONFIG_H
30
 
#include <config.h>
31
 
#endif
32
 
 
33
 
// Qt includes
34
 
#include <QObject>
35
 
#include <QMap>
36
 
#include <QList>
37
 
 
38
 
// KDE includes
39
 
#include <kdemacros.h>
40
 
 
41
 
// application includes
42
 
#include <smb4kshare.h>
43
 
 
44
 
// forward declarations
45
 
class Smb4KSambaOptionsInfo;
46
 
class Smb4KWorkgroup;
47
 
class Smb4KHost;
48
 
 
49
 
 
50
 
/**
51
 
 * This class belongs to the core classes of Smb4K and handles the global
52
 
 * and the custom Samba options.
53
 
 *
54
 
 * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
55
 
 */
56
 
 
57
 
class KDE_EXPORT Smb4KSambaOptionsHandler : public QObject
58
 
{
59
 
  Q_OBJECT
60
 
 
61
 
  friend class Smb4KSambaOptionsHandlerPrivate;
62
 
 
63
 
  public:
64
 
    /**
65
 
     * Returns a static pointer to this class.
66
 
     */
67
 
    static Smb4KSambaOptionsHandler *self();
68
 
 
69
 
    /**
70
 
     * Retrieve the list of shares that have custom options defined.
71
 
     * You will only get those options that have different ports etc.
72
 
     * defined but also all shares that are to be remounted.
73
 
     *
74
 
     * @returns the list of all shares that have custom options defined.
75
 
     */
76
 
    const QList<Smb4KSambaOptionsInfo *> &customOptionsList() { return m_list; }
77
 
 
78
 
    /**
79
 
     * Get only those shares that are to be remounted.
80
 
     *
81
 
     * @returns a list of those shares that are to be remounted.
82
 
     */
83
 
    QList<Smb4KSambaOptionsInfo *> sharesToRemount();
84
 
 
85
 
    /**
86
 
     * This functions sets the remount flag of the share @p share to TRUE or FALSE.
87
 
     * In case the share is not yet in the list of shares that are to be remounted,
88
 
     * it will be added. If you set the remount flag to FALSE on an existing entry,
89
 
     * it will stay in the list even if no other custom options were defined.
90
 
     *
91
 
     * @param share             The Smb4KShare object that represents the share
92
 
     *
93
 
     * @param yes               TRUE if you want the share to be remounted and FALSE
94
 
     *                          otherwise
95
 
     */
96
 
    void remount( Smb4KShare *share, bool yes );
97
 
 
98
 
    /**
99
 
     * Commit the whole list of shares with custom options to the configuration
100
 
     * file. You should call this if you exit the application.
101
 
     */
102
 
    void sync();
103
 
 
104
 
    /**
105
 
     * This function returns the line of arguments for the 'smbclient' program.
106
 
     * The arguments are spcific to the share that is defined by @p share. You have
107
 
     * to provide the name of the shares - as always - in the form //HOST/SHARE.
108
 
     *
109
 
     * @param share             The name of the share.
110
 
     *
111
 
     * @returns a list of arguments for use with the 'smbclient' program.
112
 
     */
113
 
    const QString smbclientOptions( const Smb4KShare &share = Smb4KShare() );
114
 
 
115
 
    /**
116
 
     * This function returns the "global" options for nmblookup, i.e. the domain
117
 
     * the client is in, if Kerberos should be used, etc.
118
 
     *
119
 
     * @param with_broadcast    Return the global broadcast address if defined.
120
 
     *
121
 
     * @returns a string with the "global" options for nmblookup
122
 
     */
123
 
    const QString nmblookupOptions( bool with_broadcast = true );
124
 
 
125
 
    /**
126
 
     * This function returns the options defined in the global section of the smb.conf
127
 
     * file. All option names have been converted to lower case and you can find each
128
 
     * entry by providing the option name in lowercase (!) as key.
129
 
     *
130
 
     * @returns a list of the options defined in smb.conf.
131
 
     */
132
 
    const QMap<QString,QString> &globalSambaOptions();
133
 
 
134
 
    /**
135
 
     * This function returns the WINS server the system is using.
136
 
     *
137
 
     * @returns the name or IP of the WINS server
138
 
     */
139
 
    const QString &winsServer();
140
 
 
141
 
    /**
142
 
     * This enumeration is for use with the netOptions() function. It tells which
143
 
     * command to use.
144
 
     */
145
 
    enum NetCommand { Share, 
146
 
                      ServerDomain, 
147
 
                      LookupHost, 
148
 
                      LookupMaster, 
149
 
                      Domain };
150
 
 
151
 
    /**
152
 
     * This function returns the options for the net command. It only knows
153
 
     * host related actions. If you need to scan for workgroup masters, etc.,
154
 
     * use the function below.
155
 
     *
156
 
     * Known values for @p command: Share, LookupHost, LookupMaster
157
 
     *
158
 
     * @param command           One of the entries of the NetCommand enumeration.
159
 
     *
160
 
     * @param host              The Smb4KHost item.
161
 
     *
162
 
     * @returns the list of arguments for the net command or an empty string if
163
 
     * an error occurred.
164
 
     */
165
 
    const QString netOptions( NetCommand command, 
166
 
                              const Smb4KHost &host );
167
 
 
168
 
    /**
169
 
     * This is an overloaded function and behaves essentially the same way as the
170
 
     * one above. It returns the options for the net command and only knows
171
 
     * workgroup related actions. If you need to scan for shares, etc.,use the
172
 
     * function above.
173
 
     *
174
 
     * Known values for @p command: LookupHost, LookupMaster
175
 
     *
176
 
     * @param command           One of the entries of the NetCommand enumeration.
177
 
     *
178
 
     * @param workgroup         The Smb4KWorkgroup item.
179
 
     *
180
 
     * @returns the list of arguments for the net command or an empty string if
181
 
     * an error occurred.
182
 
     */
183
 
    const QString netOptions( NetCommand command, 
184
 
                              const Smb4KWorkgroup &workgroup );
185
 
 
186
 
    /**
187
 
     * This is an overloaded function and behaves essentially the same way as the
188
 
     * others above. It returns the options for the net command. In contrast to the
189
 
     * other functions it only takes one argument.
190
 
     *
191
 
     * Known values for @p command: ServerDomain, Domain
192
 
     *
193
 
     * @param command          One of the entries of the NetCommand enumeration.
194
 
     *
195
 
     * @returns the list of arguments for the net command or an empty string if
196
 
     * an error occurred.
197
 
     */
198
 
    const QString netOptions( NetCommand command );
199
 
 
200
 
    /**
201
 
     * This function returns the options for smbmount/mount.cifs under Linux
202
 
     * and similar operating systems or for mount_smbfs under FreeBSD.
203
 
     *
204
 
     * Note: Under Linux etc. this is a comma-separated list which ends with
205
 
     * a comma, so remember this when you build up the command line.
206
 
     *
207
 
     * @param share             The share that is to be mounted.
208
 
     */
209
 
    const QString mountOptions( const QString &share );
210
 
 
211
 
    /**
212
 
     * Find a network item in the list.
213
 
     *
214
 
     * If you provide @p exactMatch, NULL will be returned if item is not in the list.
215
 
     * Otherwise this function returns the closest match if available.
216
 
     *
217
 
     * @param item              The name of the network item to find.
218
 
     *
219
 
     * @param exactMatch        The name has to match exactly the result that's returned.
220
 
     *
221
 
     * @returns                 the network item.
222
 
     */
223
 
    Smb4KSambaOptionsInfo *findItem( const QString &item,
224
 
                                     bool exactMatch = false ) { return find_item( item, exactMatch ); }
225
 
 
226
 
    /**
227
 
     * Add a new Smb4KSambaOptionsInfo object to the list of custom options. If the item already exists,
228
 
     * the old options will be replaced by the new ones.
229
 
     *
230
 
     * @param info              The Smb4KSambaOptionsInfo object
231
 
     *
232
 
     * @param sync              If TRUE, the list is sync'ed with the config file.
233
 
     */
234
 
    void addItem( Smb4KSambaOptionsInfo *info,
235
 
                  bool sync );
236
 
 
237
 
    /**
238
 
     * Remove an item from the list.
239
 
     *
240
 
     * @param unc               The UNC of the item.
241
 
     *
242
 
     * @param sync              If TRUE, the list is sync'ed with the config file.
243
 
     */
244
 
    void removeItem( const QString &unc,
245
 
                     bool sync );
246
 
 
247
 
    /**
248
 
     * This function returns the options for the smbtree program. Optionally,
249
 
     * you can provide the name of the current local workgroup master browser,
250
 
     * so that options defined for it can be used instead of the global ones.
251
 
     *
252
 
     * @param master            The name of the local workgroup master browser.
253
 
     *
254
 
     * @returns the options for smbtree.
255
 
     */
256
 
    const QString smbtreeOptions( const QString &master = QString() );
257
 
 
258
 
    /**
259
 
     * This function updates the list of custom options.
260
 
     *
261
 
     * @param list              The list that is used for the update.
262
 
     */
263
 
    void updateCustomOptions( const QList<Smb4KSambaOptionsInfo *> &list );
264
 
 
265
 
  private:
266
 
    /**
267
 
     * The constructor
268
 
     */
269
 
    Smb4KSambaOptionsHandler();
270
 
 
271
 
    /**
272
 
     * The destructor
273
 
     */
274
 
    ~Smb4KSambaOptionsHandler();
275
 
 
276
 
    /**
277
 
     * The list of network items that have custom options defined.
278
 
     */
279
 
    QList<Smb4KSambaOptionsInfo *> m_list;
280
 
 
281
 
    /**
282
 
     * Read the options from the configuration file.
283
 
     */
284
 
    void readCustomOptions();
285
 
 
286
 
    /**
287
 
     * Write the options to the configuration file.
288
 
     */
289
 
    void writeCustomOptions();
290
 
 
291
 
    /**
292
 
     * This function searches a particular network item in the list. If this item is a share
293
 
     * and it is not found, @p exactMatch determines if NULL or the values of the item that
294
 
     * matches @p item closest are returned (i.e. the host, or another share that's located
295
 
     * on the host). In most cases you want @p exactMatch to be FALSE.
296
 
     * Please note: Do not delete the pointer that's returned by this function or you will
297
 
     * remove an item from the list!
298
 
     *
299
 
     * @param item              The name of the network item.
300
 
     *
301
 
     * @param exactMatch        The name has to match exactly the result that's returned.
302
 
     *
303
 
     * @returns                 The Smb4KSambaOptionsInfo object associated with the network item.
304
 
     */
305
 
    Smb4KSambaOptionsInfo *find_item( const QString &item, bool exactMatch = false );
306
 
 
307
 
    /**
308
 
     * This function reads the entries of the global section of Samba's configuration
309
 
     * file smb.conf and puts them into a map.
310
 
     */
311
 
    void read_smb_conf();
312
 
 
313
 
    /**
314
 
     * This map carries the options defined in the [global] section of Samba's configuration
315
 
     * file smb.conf. You can access a certain value by providing the lower case option name
316
 
     * as key.
317
 
     */
318
 
    QMap<QString,QString> m_samba_options;
319
 
 
320
 
    /**
321
 
     * The WINS server
322
 
     */
323
 
    QString m_wins_server;
324
 
 
325
 
    /**
326
 
     * Check whether the item has entries that deviate from the global settings and return
327
 
     * TRUE if this is the case. Please note that this function ignores the remount flag.
328
 
     *
329
 
     * @param item              The item that is to be checked.
330
 
     *
331
 
     * @returns TRUE if the item contains entries that deviate from the global settings and
332
 
     * FALSE otherwise.
333
 
     */
334
 
    void has_custom_options( Smb4KSambaOptionsInfo *item );
335
 
};
336
 
 
337
 
 
338
 
#endif