summaryrefslogtreecommitdiffstats
path: root/filesharing/advanced/kcm_sambaconf/sambashare.h
blob: 39107505b88f4b9fdf53834aa7e9e065f34b61de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/***************************************************************************
                          sambashare.h  -  description
                             -------------------
    begin                : Mon 12 2002
    copyright            : (C) 2002 by Jan Schäfer
    email                : janschaefer@users.sourceforge.net
 ***************************************************************************/

/******************************************************************************
 *                                                                            *
 *  This file is part of KSambaPlugin.                                          *
 *                                                                            *
 *  KSambaPlugin is free software; you can redistribute it and/or modify            *
 *  it under the terms of the GNU General Public License as published by      *
 *  the Free Software Foundation; either version 2 of the License, or         *
 *  (at your option) any later version.                                       *
 *                                                                            *
 *  KSambaPlugin is distributed in the hope that it will be useful,                 *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
 *  GNU General Public License for more details.                              *
 *                                                                            *
 *  You should have received a copy of the GNU General Public License         *
 *  along with KSambaPlugin; if not, write to the Free Software                     *
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA  *
 *                                                                            *
 ******************************************************************************/

#ifndef SAMBASHARE_H
#define SAMBASHARE_H

#include <tqdict.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqptrlist.h>

class SambaConfigFile;
class QStringList;

/**
 * A class which represents a Samba share
 * @author Jan Sch&auml;fer
 **/
class SambaShare :public TQDict<TQString>
{
public:

	/**
   * Creates a new SambaShare with an empty name
   **/
	SambaShare(SambaConfigFile* sambaFile);

	/**
   * Creates a new SambaShare with the given name
   * @param name the name of the share
   **/
  SambaShare(const TQString & name, SambaConfigFile* sambaFile);

  /** 
   * Returns the name of the share
   **/
  const TQString& getName() const;


  /**
   * Sets the name of the share
   * returns false if the name already exists and the testWetherExists
   * parameter is set to true
   **/
  bool setName(const TQString & name, bool testWetherExists=true);

  /**
   * Tests wether or not the given option is supported by Samba.
   * It does this by testing the output of testparm for this option
   **/
  bool optionSupported(const TQString & name);
  
  /**
   * Returns the value of the given parameter
   * if the parameter doesn't exists, the
	 * global and then the default value is returned.
   * @param name the name of the parameter
   * @param gobalValue if the gobal value should be returend
   * @param defaultValue if the default value should be returned or a null string
   **/
  TQString getValue(const TQString & name, bool globalValue=true, bool defaultValue=true);

  /**
   * Same as above but for boolean parameters
   * Don't use defaultValue = false with this function
   * because you can't distinguish an unset parameter
   * from a false parameter
   **/
  bool getBoolValue(const TQString & name, bool globalValue=true, bool defaultValue=true);

  /**
   * Returns the value from the [globals] section
   **/
	TQString getGlobalValue(const TQString & name, bool defaultValue=true);

  /**
   * Sets the parameter name to the given value
   * @param value the value of the parameter
   * @param name the name of the parameter
   * @param globalValue if true then the value is only set if it is different to the global value
   * @param defaultValue if true then the value is only set if it is different to the default value
   *                     if globalValue and defaultValue is true then the value is set when a global value
   *                     exists and it it is different to it. If no global value exists then it is only
   *                     set if different to the default value.
   **/
  void setValue(const TQString & name,const TQString & value, bool globalValue=true, bool defaultValue=true);

  /**
   * Same as above but for boolean parameters
   **/
  void setValue(const TQString & name, bool value, bool globalValue=true, bool defaultValue=true);

  /**
   * Same as above but for integer parameters
   **/
  void setValue(const TQString & name, int value, bool globalValue=true, bool defaultValue=true);

  /**
   * Returns the default value of the parameter
   * @param name the name of the parameter
   **/
	TQString getDefaultValue(const TQString & name);

  /**
   * Same as above but for booleans
   **/
  bool getDefaultBoolValue(const TQString & name);

  /**
 	 * Returns the default synonym for the given parameter
 	 * if no synonym exists the original parameter in lower
 	 * case is returned
 	 **/
	TQString getSynonym(const TQString & name) const;

  /**
   * Returns the comments of the share
   * e.g. the text above the [...] section
   **/
  TQStringList getComments();

  /**
   * Sets the comments for the share
   * e.g. the text above the [...] section
   **/
  void setComments(const TQStringList & commentList);
  
  /**
   * Sets the comments for the passed option
   **/
  void setComments(const TQString & name, const TQStringList & commentList);

  /**
   * Returns the comments of the passed option
   **/
  TQStringList getComments(const TQString & name);

  /**
   * Returns true if the passed option has comments
   * otherwise returns false
   **/
  bool hasComments(const TQString & name);

  /**
   * Returns the list of all options
   * the order of the options is exactly the
   * order of the insertion of the options
   **/
  TQStringList getOptionList();
  
	/**
   * Returns true if this share is a printer
   * that's if printable = true
   **/
  bool isPrinter();

  /**
   * Returns true if the share name is
   * global, printers or homes
   **/
  bool isSpecialSection();

protected:
	/**
   * The name of the share
   * could be also printers, global and homes
   **/
	TQString _name;
  SambaConfigFile* _sambaFile;

  /**
   * This attribute stores all option comments.
   * the comments which stood above the option name
   * are stored in this QStringList
   **/
  TQDict<TQStringList> _commentList;

  /**
   * The comments for this share
   **/
  TQStringList _comments;

  /**
   * An extra list which holds
   * all stored options
   * You might say, hey for what is this ?
   * We have them already stored in the TQDict.
   * That's right, but there is a problem :
   * TQDict doesn't preserve the order of
   * the inserted items, but when saving
   * the options back to the smb.conf
   * we want to have exactly the same order
   * so this TQStringList is only for saving
   * the order of the options.
   * On the other side we need a very fast lookup
   * of the options, because we lookup very frequently
   * so this is the best way to do both.
   **/
  TQStringList _optionList;

};

typedef TQPtrList<SambaShare> SambaShareList;


#endif