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

« back to all changes in this revision

Viewing changes to core/smb4kglobal_p.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-06-15 16:27:38 UTC
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20140615162738-t1426an8s5beix1b
Tags: upstream-1.1.2
ImportĀ upstreamĀ versionĀ 1.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
    namespace.
4
4
                             -------------------
5
5
    begin                : Di Jul 24 2007
6
 
    copyright            : (C) 2007-2011 by Alexander Reinholdt
 
6
    copyright            : (C) 2007-2014 by Alexander Reinholdt
7
7
    email                : alexander.reinholdt@kdemail.net
8
8
 ***************************************************************************/
9
9
 
20
20
 *                                                                         *
21
21
 *   You should have received a copy of the GNU General Public License     *
22
22
 *   along with this program; if not, write to the                         *
23
 
 *   Free Software Foundation, 51 Franklin Street, Suite 500, Boston,      *
 
23
 *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
24
24
 *   MA 02110-1335, USA                                                    *
25
25
 ***************************************************************************/
26
26
 
 
27
#ifdef HAVE_CONFIG_H
 
28
#include <config.h>
 
29
#endif
 
30
 
 
31
// application specific includes
 
32
#include "smb4kglobal_p.h"
 
33
#include "smb4knotification.h"
 
34
#include "smb4ksettings.h"
 
35
 
27
36
// Qt includes
28
 
#include <QDir>
29
 
#include <QTextStream>
30
 
#include <QTextCodec>
31
 
#include <QFile>
 
37
#include <QtCore/QDir>
 
38
#include <QtCore/QTextStream>
 
39
#include <QtCore/QTextCodec>
 
40
#include <QtCore/QFile>
 
41
#include <QtCore/QCoreApplication>
 
42
#include <QtNetwork/QHostAddress>
 
43
#include <QtNetwork/QAbstractSocket>
32
44
 
33
45
// system specific includes
34
46
#include <unistd.h>
35
47
#include <sys/types.h>
36
48
#include <errno.h>
37
49
 
38
 
// application specific includes
39
 
#include "smb4kglobal_p.h"
40
 
#include <smb4knotification.h>
41
 
 
42
50
 
43
51
Smb4KGlobalPrivate::Smb4KGlobalPrivate()
44
52
{
45
53
  onlyForeignShares = false;
 
54
  coreInitialized = false;
46
55
}
47
56
 
48
57
 
132
141
      // Process the file contents.
133
142
      for ( int i = contents.indexOf( "[global]", 0 ); i < contents.size(); ++i )
134
143
      {
135
 
        if ( contents.at( i ).trimmed().startsWith( "#" ) ||
136
 
            contents.at( i ).trimmed().startsWith( ";" ) )
 
144
        if ( i == -1 )
 
145
        {
 
146
          // The smb.conf file does not contain a global section.
 
147
          break;
 
148
        }
 
149
        else
 
150
        {
 
151
          // Do nothing
 
152
        }
 
153
        
 
154
        if ( contents.at( i ).trimmed().startsWith( '#' ) ||
 
155
             contents.at( i ).trimmed().startsWith( ';' ) )
137
156
        {
138
157
          // This is a comment. We do not need it.
139
158
          continue;
140
159
        }
141
 
        else if ( contents.at( i ).trimmed().startsWith( "include" ) )
 
160
        else if ( contents.at( i ).trimmed().startsWith( QLatin1String( "include" ) ) )
142
161
        {
143
162
          // Look for the include file and put its contents into the
144
163
          // m_samba_options map.
145
 
          file.setFileName( contents.at( i ).section( "=", 1, 1 ).trimmed() );
 
164
          file.setFileName( contents.at( i ).section( '=', 1, 1 ).trimmed() );
146
165
 
147
166
          if ( file.exists() )
148
167
          {
159
178
              {
160
179
                buffer = ts.readLine( 0 ).trimmed();
161
180
 
162
 
                if ( buffer.startsWith( "#" ) || buffer.startsWith( ";" ) )
 
181
                if ( buffer.startsWith( '#' ) || buffer.startsWith( ';' ) )
163
182
                {
164
183
                  continue;
165
184
                }
166
185
                else
167
186
                {
168
 
                  QString key = buffer.section( "=", 0, 0 ).trimmed().toLower();
169
 
                  m_samba_options[key] = buffer.section( "=", 1, 1 ).trimmed().toUpper();
 
187
                  QString key = buffer.section( '=', 0, 0 ).trimmed().toLower();
 
188
                  m_samba_options[key] = buffer.section( '=', 1, 1 ).trimmed().toUpper();
170
189
 
171
190
                  continue;
172
191
                }
180
199
            }
181
200
          }
182
201
        }
183
 
        else if ( contents.at( i ).startsWith( "[" ) &&
 
202
        else if ( contents.at( i ).startsWith( '[' ) &&
184
203
                  !contents.at( i ).contains( "[global]", Qt::CaseSensitive ) )
185
204
        {
186
205
          // We reached the end of the [global] section. Stop here.
190
209
        {
191
210
          // Put the entries of the [global] section into the m_samba_options
192
211
          // map.
193
 
          QString key = contents.at( i ).section( "=", 0, 0 ).trimmed().toLower();
194
 
          m_samba_options[key] = contents.at( i ).section( "=", 1, 1 ).trimmed().toUpper();
 
212
          QString key = contents.at( i ).section( '=', 0, 0 ).trimmed().toLower();
 
213
          m_samba_options[key] = contents.at( i ).section( '=', 1, 1 ).trimmed().toUpper();
195
214
        }
196
215
      }
197
216
    }
231
250
}
232
251
 
233
252
 
 
253
void Smb4KGlobalPrivate::setDefaultSettings()
 
254
{
 
255
  // Samba options that have to be dynamically imported from smb.conf:
 
256
  QMap<QString, QString> opts = globalSambaOptions( true );
 
257
 
 
258
  if ( !opts["netbios name"].isEmpty() )
 
259
  {
 
260
    Smb4KSettings::self()->netBIOSNameItem()->setDefaultValue( opts["netbios name"] );
 
261
 
 
262
    if ( Smb4KSettings::netBIOSName().isEmpty() )
 
263
    {
 
264
      Smb4KSettings::self()->netBIOSNameItem()->setDefault();
 
265
    }
 
266
  }
 
267
 
 
268
  if ( !opts["workgroup"].isEmpty() )
 
269
  {
 
270
    Smb4KSettings::self()->domainNameItem()->setDefaultValue( opts["workgroup"] );
 
271
 
 
272
    if ( Smb4KSettings::domainName().isEmpty() )
 
273
    {
 
274
      Smb4KSettings::self()->domainNameItem()->setDefault();
 
275
    }
 
276
  }
 
277
 
 
278
  if ( !opts["socket options"].isEmpty() )
 
279
  {
 
280
    Smb4KSettings::self()->socketOptionsItem()->setDefaultValue( opts["socket options"] );
 
281
 
 
282
    if ( Smb4KSettings::socketOptions().isEmpty() )
 
283
    {
 
284
      Smb4KSettings::self()->socketOptionsItem()->setDefault();
 
285
    }
 
286
  }
 
287
 
 
288
  if ( !opts["netbios scope"].isEmpty() )
 
289
  {
 
290
    Smb4KSettings::self()->netBIOSScopeItem()->setDefaultValue( opts["netbios scope"] );
 
291
 
 
292
    if ( Smb4KSettings::netBIOSScope().isEmpty() )
 
293
    {
 
294
      Smb4KSettings::self()->netBIOSScopeItem()->setDefault();
 
295
    }
 
296
  }
 
297
 
 
298
  if ( !opts["name resolve order"].isEmpty() )
 
299
  {
 
300
    Smb4KSettings::self()->nameResolveOrderItem()->setDefaultValue( opts["name resolve order"] );
 
301
 
 
302
    if ( Smb4KSettings::nameResolveOrder().isEmpty() )
 
303
    {
 
304
      Smb4KSettings::self()->nameResolveOrderItem()->setDefault();
 
305
    }
 
306
  }
 
307
 
 
308
  QHostAddress address( opts["interfaces"].section( ' ', 0, 0 ) );
 
309
 
 
310
  if ( address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol )
 
311
  {
 
312
    Smb4KSettings::self()->broadcastAddressItem()->setDefaultValue( address.toString() );
 
313
 
 
314
    if ( Smb4KSettings::broadcastAddress().isEmpty() )
 
315
    {
 
316
      Smb4KSettings::self()->broadcastAddressItem()->setDefault();
 
317
    }
 
318
  }
 
319
}
 
320
 
 
321
 
 
322
void Smb4KGlobalPrivate::makeConnections()
 
323
{
 
324
  connect( QCoreApplication::instance(), SIGNAL(aboutToQuit()), SLOT(slotAboutToQuit()) );
 
325
}
 
326
 
 
327
 
 
328
void Smb4KGlobalPrivate::slotAboutToQuit()
 
329
{
 
330
  Smb4KSettings::self()->writeConfig();
 
331
}
 
332
 
 
333
 
 
334
#include "smb4kglobal_p.moc"
 
335
 
 
336