1
/***************************************************************************
2
smb4ksambaoptionshandler - This class handles the Samba options.
5
copyright : (C) 2006-2008 by Alexander Reinholdt
6
email : dustpuppy@users.berlios.de
7
***************************************************************************/
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. *
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. *
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, *
24
***************************************************************************/
26
#ifndef SMB4KSAMBAOPTIONSHANDLER_H
27
#define SMB4KSAMBAOPTIONSHANDLER_H
39
#include <kdemacros.h>
41
// application includes
42
#include <smb4kshare.h>
44
// forward declarations
45
class Smb4KSambaOptionsInfo;
51
* This class belongs to the core classes of Smb4K and handles the global
52
* and the custom Samba options.
54
* @author Alexander Reinholdt <dustpuppy@users.berlios.de>
57
class KDE_EXPORT Smb4KSambaOptionsHandler : public QObject
61
friend class Smb4KSambaOptionsHandlerPrivate;
65
* Returns a static pointer to this class.
67
static Smb4KSambaOptionsHandler *self();
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.
74
* @returns the list of all shares that have custom options defined.
76
const QList<Smb4KSambaOptionsInfo *> &customOptionsList() { return m_list; }
79
* Get only those shares that are to be remounted.
81
* @returns a list of those shares that are to be remounted.
83
QList<Smb4KSambaOptionsInfo *> sharesToRemount();
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.
91
* @param share The Smb4KShare object that represents the share
93
* @param yes TRUE if you want the share to be remounted and FALSE
96
void remount( Smb4KShare *share, bool yes );
99
* Commit the whole list of shares with custom options to the configuration
100
* file. You should call this if you exit the application.
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.
109
* @param share The name of the share.
111
* @returns a list of arguments for use with the 'smbclient' program.
113
const QString smbclientOptions( const Smb4KShare &share = Smb4KShare() );
116
* This function returns the "global" options for nmblookup, i.e. the domain
117
* the client is in, if Kerberos should be used, etc.
119
* @param with_broadcast Return the global broadcast address if defined.
121
* @returns a string with the "global" options for nmblookup
123
const QString nmblookupOptions( bool with_broadcast = true );
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.
130
* @returns a list of the options defined in smb.conf.
132
const QMap<QString,QString> &globalSambaOptions();
135
* This function returns the WINS server the system is using.
137
* @returns the name or IP of the WINS server
139
const QString &winsServer();
142
* This enumeration is for use with the netOptions() function. It tells which
145
enum NetCommand { Share,
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.
156
* Known values for @p command: Share, LookupHost, LookupMaster
158
* @param command One of the entries of the NetCommand enumeration.
160
* @param host The Smb4KHost item.
162
* @returns the list of arguments for the net command or an empty string if
165
const QString netOptions( NetCommand command,
166
const Smb4KHost &host );
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
174
* Known values for @p command: LookupHost, LookupMaster
176
* @param command One of the entries of the NetCommand enumeration.
178
* @param workgroup The Smb4KWorkgroup item.
180
* @returns the list of arguments for the net command or an empty string if
183
const QString netOptions( NetCommand command,
184
const Smb4KWorkgroup &workgroup );
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.
191
* Known values for @p command: ServerDomain, Domain
193
* @param command One of the entries of the NetCommand enumeration.
195
* @returns the list of arguments for the net command or an empty string if
198
const QString netOptions( NetCommand command );
201
* This function returns the options for smbmount/mount.cifs under Linux
202
* and similar operating systems or for mount_smbfs under FreeBSD.
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.
207
* @param share The share that is to be mounted.
209
const QString mountOptions( const QString &share );
212
* Find a network item in the list.
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.
217
* @param item The name of the network item to find.
219
* @param exactMatch The name has to match exactly the result that's returned.
221
* @returns the network item.
223
Smb4KSambaOptionsInfo *findItem( const QString &item,
224
bool exactMatch = false ) { return find_item( item, exactMatch ); }
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.
230
* @param info The Smb4KSambaOptionsInfo object
232
* @param sync If TRUE, the list is sync'ed with the config file.
234
void addItem( Smb4KSambaOptionsInfo *info,
238
* Remove an item from the list.
240
* @param unc The UNC of the item.
242
* @param sync If TRUE, the list is sync'ed with the config file.
244
void removeItem( const QString &unc,
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.
252
* @param master The name of the local workgroup master browser.
254
* @returns the options for smbtree.
256
const QString smbtreeOptions( const QString &master = QString() );
259
* This function updates the list of custom options.
261
* @param list The list that is used for the update.
263
void updateCustomOptions( const QList<Smb4KSambaOptionsInfo *> &list );
269
Smb4KSambaOptionsHandler();
274
~Smb4KSambaOptionsHandler();
277
* The list of network items that have custom options defined.
279
QList<Smb4KSambaOptionsInfo *> m_list;
282
* Read the options from the configuration file.
284
void readCustomOptions();
287
* Write the options to the configuration file.
289
void writeCustomOptions();
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!
299
* @param item The name of the network item.
301
* @param exactMatch The name has to match exactly the result that's returned.
303
* @returns The Smb4KSambaOptionsInfo object associated with the network item.
305
Smb4KSambaOptionsInfo *find_item( const QString &item, bool exactMatch = false );
308
* This function reads the entries of the global section of Samba's configuration
309
* file smb.conf and puts them into a map.
311
void read_smb_conf();
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
318
QMap<QString,QString> m_samba_options;
323
QString m_wins_server;
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.
329
* @param item The item that is to be checked.
331
* @returns TRUE if the item contains entries that deviate from the global settings and
334
void has_custom_options( Smb4KSambaOptionsInfo *item );