summaryrefslogtreecommitdiffstats
path: root/smb4k/core/smb4kshare.cpp
blob: 7877171a7d6d635d9c1cc747e348a93a3fb39292 (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
/***************************************************************************
    smb4kshare  -  This is a container that holds information about
    a mounted remote share.
                             -------------------
    begin                : Do Mär 4 2004
    copyright            : (C) 2004 by Franck Babin
                           (C) 2005 by Alexander Reinholdt
    email                : babinfranck@yahoo.ca
                           dustpuppy@mail.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                                                    *
 ***************************************************************************/

// Qt includes
#include <qdir.h>

// KDE includes
#include <kdebug.h>

// system includes
#include <unistd.h>
#include <sys/types.h>

// application specific includes
#include "smb4kshare.h"


Smb4KShare::Smb4KShare( const QString &name, const QString &path, const QString &filesystem, const int uid, const int gid, bool broken ) :
m_name(name), m_path( path.local8Bit() ), m_filesystem( filesystem ), m_user( uid ), m_group( gid ), m_cifs_login( QString::null ), m_broken( broken ), m_total( 0 ), m_free( 0 )
{
  //FIXME should throw an exception if one of the param is empty

  if ( uid != (int)getuid() && gid != (int)getgid() )
  {
    m_foreign_mount = true;
  }
  else
  {
    m_foreign_mount = false;
  }
}


Smb4KShare::Smb4KShare( const QString &name, const QString &path, const QString &filesystem, const QString &username, bool foreign, bool broken ) :
m_name( name ), m_path( path.local8Bit() ), m_filesystem( filesystem ), m_user( (int)getuid() ), m_group( (int)getgid() ), m_cifs_login( username ), m_foreign_mount( foreign ), m_broken( broken ), m_total( 0 ), m_free( 0 )
{
}


Smb4KShare::Smb4KShare( const Smb4KShare &s ) :
m_name( s.name() ), m_path( s.path() ), m_filesystem( s.filesystem() ), m_user( s.uid() ), m_group( s.gid() ), m_cifs_login( s.cifsLogin() ), m_foreign_mount( s.isForeign() ), m_broken( s.isBroken() ), m_total( s.totalDiskSpace() ), m_free( s.freeDiskSpace() )
{
}


Smb4KShare::~Smb4KShare()
{
}



const QString &Smb4KShare::name() const
{
  return m_name;
}


const QCString &Smb4KShare::path() const
{
  return m_path;
}


const QCString Smb4KShare::canonicalPath() const
{
  return m_broken ? m_path : QDir( m_path ).canonicalPath().local8Bit();
}


int Smb4KShare::uid() const
{
  return (int)m_user.uid();
}


void Smb4KShare::setUID( int uid )
{
  m_user = KUser( uid );
}


int Smb4KShare::gid() const
{
  return (int)m_group.gid();
}


void Smb4KShare::setGID( int gid )
{
  m_group = KUserGroup( gid );
}


const QString Smb4KShare::user() const
{
  return m_user.loginName();
}


const QString Smb4KShare::group() const
{
  return m_group.name();
}


const QString &Smb4KShare::filesystem() const
{
  return m_filesystem;
}


const QString &Smb4KShare::cifsLogin() const
{
  return m_cifs_login;
}


bool Smb4KShare::isForeign() const
{
  return m_foreign_mount;
}


void Smb4KShare::setForeign( bool foreign )
{
  m_foreign_mount = foreign;
}


bool Smb4KShare::isBroken() const
{
  return m_broken;
}


void Smb4KShare::setBroken( bool broken )
{
  m_broken = broken;
}


void Smb4KShare::setTotalDiskSpace( double total )
{
  m_total = total;
}


void Smb4KShare::setFreeDiskSpace( double free )
{
  m_free = free;
}


double Smb4KShare::totalDiskSpace() const
{
  return m_total;
}


double Smb4KShare::freeDiskSpace() const
{
  return m_free;
}


double Smb4KShare::percentage() const
{
  return (m_total - m_free) / m_total * 100;
}


bool Smb4KShare::equals( const Smb4KShare &share )
{
  bool equal = false;

  if ( QString::compare( m_name, share.name() ) == 0 &&
       QString::compare( m_path, share.path() ) == 0 &&
       QString::compare( m_filesystem, share.filesystem() ) == 0 &&
       QString::compare( m_cifs_login, share.cifsLogin() ) == 0 &&
       (int)m_user.uid() == share.uid() &&
       (int)m_group.gid() == share.gid() &&
       m_broken == share.isBroken() &&
       m_foreign_mount == share.isForeign() &&
       m_total == share.totalDiskSpace() &&
       m_free == share.freeDiskSpace() )
  {
    equal = true;
  }

  return equal;
}