summaryrefslogtreecommitdiffstats
path: root/smb4k/core/smb4kglobal_p.cpp
blob: ce30fd045d8a050a6e088650a2e862354e9a594c (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
/***************************************************************************
    smb4kglobal_p  -  This is the private helper class of the Smb4TDEGlobal
    namespace.
                             -------------------
    begin                : Di Jul 24 2007
    copyright            : (C) 2007 by Alexander Reinholdt
    email                : dustpuppy@users.berlios.de
 ***************************************************************************/

/***************************************************************************
 *   This program 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.                                   *
 *                                                                         *
 *   This program 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 this program; if not, write to the                         *
 *   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,   *
 *   MA  02110-1301 USA                                                    *
 ***************************************************************************/

// system includes
#include <errno.h>
#include <stdlib.h>

// application specific includes
#include "smb4kglobal_p.h"
#include "smb4kdefs.h"
#include "smb4kerror.h"


Smb4TDEGlobalPrivate::Smb4TDEGlobalPrivate()
{
  m_timer = new TQTimer();
  m_timer->start( TIMER_INTERVAL, false );

  // Do NOT initialize these classes here; you'll
  // get crashes.
  m_passwd_handler = NULL;
  m_options_handler = NULL;
  m_homes_handler = NULL;

  m_temp_dir = TQString();
}


Smb4TDEGlobalPrivate::~Smb4TDEGlobalPrivate()
{
  rmdir( m_temp_dir.local8Bit() );

  delete m_timer;
  delete m_passwd_handler;
  delete m_options_handler;
  delete m_homes_handler;
}


TQTimer *Smb4TDEGlobalPrivate::timer()
{
  return m_timer;
}


Smb4KHomesSharesHandler *Smb4TDEGlobalPrivate::homesHandler()
{
  return m_homes_handler ? m_homes_handler :
                          (m_homes_handler = new Smb4KHomesSharesHandler());
}


Smb4KPasswordHandler *Smb4TDEGlobalPrivate::passwordHandler()
{
#ifndef __FreeBSD__
  return m_passwd_handler ? m_passwd_handler :
                            (m_passwd_handler = new Smb4KPasswordHandler( homesHandler() ));
#else
  return m_passwd_handler ? m_passwd_handler :
                            (m_passwd_handler = new Smb4KPasswordHandler( homesHandler(), optionsHandler() ));
#endif
}


Smb4KSambaOptionsHandler *Smb4TDEGlobalPrivate::optionsHandler()
{
  return m_options_handler ? m_options_handler :
                             (m_options_handler = new Smb4KSambaOptionsHandler());
}


const TQString &Smb4TDEGlobalPrivate::tempDir()
{
  if ( m_temp_dir.isEmpty() )
  {
    char tmpd_name[] = "/tmp/smb4k.XXXXXX";

    if ( mkdtemp( tmpd_name ) == NULL )
    {
      Smb4KError::error( ERROR_CREATING_TEMP_DIR, tmpd_name, strerror( errno ) );

      return TQString();
    }

    m_temp_dir = TQString( tmpd_name );
  }

  return m_temp_dir;
}


const TQStringList Smb4TDEGlobalPrivate::homesUsers( const TQString &host )
{
  if ( !m_homes_handler )
  {
    m_homes_handler = new Smb4KHomesSharesHandler();
  }

  return m_homes_handler->homesUsers( host );
}