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
***************************************************************************/
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
***************************************************************************/
31
// application specific includes
32
#include "smb4kglobal_p.h"
33
#include "smb4knotification.h"
34
#include "smb4ksettings.h"
29
#include <QTextStream>
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>
33
45
// system specific includes
34
46
#include <unistd.h>
35
47
#include <sys/types.h>
38
// application specific includes
39
#include "smb4kglobal_p.h"
40
#include <smb4knotification.h>
43
51
Smb4KGlobalPrivate::Smb4KGlobalPrivate()
45
53
onlyForeignShares = false;
54
coreInitialized = false;
132
141
// Process the file contents.
133
142
for ( int i = contents.indexOf( "[global]", 0 ); i < contents.size(); ++i )
135
if ( contents.at( i ).trimmed().startsWith( "#" ) ||
136
contents.at( i ).trimmed().startsWith( ";" ) )
146
// The smb.conf file does not contain a global section.
154
if ( contents.at( i ).trimmed().startsWith( '#' ) ||
155
contents.at( i ).trimmed().startsWith( ';' ) )
138
157
// This is a comment. We do not need it.
141
else if ( contents.at( i ).trimmed().startsWith( "include" ) )
160
else if ( contents.at( i ).trimmed().startsWith( QLatin1String( "include" ) ) )
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() );
147
166
if ( file.exists() )
160
179
buffer = ts.readLine( 0 ).trimmed();
162
if ( buffer.startsWith( "#" ) || buffer.startsWith( ";" ) )
181
if ( buffer.startsWith( '#' ) || buffer.startsWith( ';' ) )
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();
183
else if ( contents.at( i ).startsWith( "[" ) &&
202
else if ( contents.at( i ).startsWith( '[' ) &&
184
203
!contents.at( i ).contains( "[global]", Qt::CaseSensitive ) )
186
205
// We reached the end of the [global] section. Stop here.
191
210
// Put the entries of the [global] section into the m_samba_options
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();
253
void Smb4KGlobalPrivate::setDefaultSettings()
255
// Samba options that have to be dynamically imported from smb.conf:
256
QMap<QString, QString> opts = globalSambaOptions( true );
258
if ( !opts["netbios name"].isEmpty() )
260
Smb4KSettings::self()->netBIOSNameItem()->setDefaultValue( opts["netbios name"] );
262
if ( Smb4KSettings::netBIOSName().isEmpty() )
264
Smb4KSettings::self()->netBIOSNameItem()->setDefault();
268
if ( !opts["workgroup"].isEmpty() )
270
Smb4KSettings::self()->domainNameItem()->setDefaultValue( opts["workgroup"] );
272
if ( Smb4KSettings::domainName().isEmpty() )
274
Smb4KSettings::self()->domainNameItem()->setDefault();
278
if ( !opts["socket options"].isEmpty() )
280
Smb4KSettings::self()->socketOptionsItem()->setDefaultValue( opts["socket options"] );
282
if ( Smb4KSettings::socketOptions().isEmpty() )
284
Smb4KSettings::self()->socketOptionsItem()->setDefault();
288
if ( !opts["netbios scope"].isEmpty() )
290
Smb4KSettings::self()->netBIOSScopeItem()->setDefaultValue( opts["netbios scope"] );
292
if ( Smb4KSettings::netBIOSScope().isEmpty() )
294
Smb4KSettings::self()->netBIOSScopeItem()->setDefault();
298
if ( !opts["name resolve order"].isEmpty() )
300
Smb4KSettings::self()->nameResolveOrderItem()->setDefaultValue( opts["name resolve order"] );
302
if ( Smb4KSettings::nameResolveOrder().isEmpty() )
304
Smb4KSettings::self()->nameResolveOrderItem()->setDefault();
308
QHostAddress address( opts["interfaces"].section( ' ', 0, 0 ) );
310
if ( address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol )
312
Smb4KSettings::self()->broadcastAddressItem()->setDefaultValue( address.toString() );
314
if ( Smb4KSettings::broadcastAddress().isEmpty() )
316
Smb4KSettings::self()->broadcastAddressItem()->setDefault();
322
void Smb4KGlobalPrivate::makeConnections()
324
connect( QCoreApplication::instance(), SIGNAL(aboutToQuit()), SLOT(slotAboutToQuit()) );
328
void Smb4KGlobalPrivate::slotAboutToQuit()
330
Smb4KSettings::self()->writeConfig();
334
#include "smb4kglobal_p.moc"