summaryrefslogtreecommitdiffstats
path: root/smb4k/core/smb4kshare.h
blob: 2c8ee5b863c9762635ba844cac5fabc1e3f10112 (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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/***************************************************************************
    smb4kshare  -  This is a container that holds information about
    a mounted remote share.
                             -------------------
    begin                : Do M� 4 2004
    copyright            : (C) 2004 by Franck Babin
                           (C) 2005-2007 by Alexander Reinholdt
    email                : babinfranck@yahoo.ca
                           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                                                    *
 ***************************************************************************/

#ifndef SMB4KSHARE_H
#define SMB4KSHARE_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// TQt includes
#include <tqstring.h>
#include <tqcstring.h>

// KDE includes
#include <kuser.h>


/**
 * This class is a container that holds information about a remote share
 * that was mounted on the system. It belongs to the core classes of
 * Smb4K.
 *
 * @author Franck Babin,
 * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
 */

class Smb4KShare
{
  public:
    /**
     * The default constructor.
     *
     * @param name        The name of the share: //HOST/SHARE or //USER\@HOST/SHARE (FreeBSD).
     *
     * @param path        The path where the share is mounted to.
     *
     * @param filesystem  The filesystem that was used. If you use this constructor it should be "smbfs".
     *
     * @param uid         The UID of the user.
     *
     * @param gid         The GID of the user.
     *
     * @param broken      Determines whether the share is broken. "Broken" means that the share is unaccessible.
     */
    Smb4KShare( const TQString &name, const TQString &path, const TQString &filesystem, const int uid = 0, const int gid = 0, bool broken = false );

    /**
     * The constructor for CIFS shares. It does not take the UID and GID, but the
     * user name with which the login was done.
     *
     * @param name        The name of the share: //HOST/SHARE or //USER@HOST/SHARE (FreeBSD).
     *
     * @param path        The path where the share is mounted to.
     *
     * @param filesystem  The filesystem that was used. If you use this constructor it should be "cifs".
     *
     * @param username    The the user name that had to be used for authentication. It can be different from the local user name.
     *
     * @param foreign     Determines whether the share was mounted by another user (i.e. is a foreign share).
     *
     * @param broken      Determines whether the share is broken. "Broken" means that the share is unaccessible.
     */
    Smb4KShare( const TQString &name, const TQString &path, const TQString &filesystem, const TQString &username, bool foreign = false, bool broken = false );

    /**
     * Empty constructor.
     */
    Smb4KShare() {}

    /**
     * Copy constructor.
     *
     * @param share       The share that is to be copied.
     */
    Smb4KShare( const Smb4KShare &share );

    /**
     * The destructor
     */
    ~Smb4KShare();

    /**
     * Returns the name of the share as it has been gathered by the mounter.
     *
     * @returns           The name of the share.
     */
    const TQString &name() const;

    /**
     * Returns the mount point aka path of the share as it has been gathered
     * by the mounter. This is a C-type string.
     *
     * @returns           The path of the share.
     */
    const TQCString &path() const;

    /**
     * This function returns the canonical path of the share. In contrast to
     * Smb4KShare::path(), it will return the absolute path without symlinks. However,
     * should the share be broken (i.e. Smb4KShare::isBroken() returns TRUE),
     * only Smb4KShare::path() is returned.
     *
     * @returns           Returns the canonical path of the share.
     */
    const TQCString canonicalPath() const;

    /**
     * Returns the UID of the mounted share.
     */
    int uid() const;

    /**
     * Set the UID of the mounted share.
     *
     * @param uid         The UID of the share
     */
    void setUID( int uid );

    /**
     * Returns the GID of the mounted share.
     */
    int gid() const;

    /**
     * Set the GID of the mounted share.
     *
     * @param gid         The GID of the share
     */
    void setGID( int gid );

    /**
     * Returns the name of the user of the share.
     */
    const TQString user() const;

    /**
     * Returns the name of the group of the share.
     */
    const TQString group() const;

    /**
     * Returns the file system of the share.
     */
    const TQString &filesystem() const;

    /**
     * Returns the CIFS login (user name).
     */
    const TQString &cifsLogin() const;

    /**
     * Is TRUE if the share is/seems to be mounted by another
     * user.
     *
     * @returns           TRUE if another user mounted the share and FALSE otherwise.
     */
    bool isForeign() const;

    /**
     * This function sets the share to be foreign.
     *
     * @param foreign     TRUE if share is foreign and FALSE otherwise.
     */
    void setForeign( bool foreign );

    /**
     * Returns TRUE if the share is broken and FALSE otherwise.
     */
    bool isBroken() const;

    /**
     * Sets the share to be broken.
     *
     * @param broken      TRUE if the share is broken and FALSE otherwise.
     */
    void setBroken( bool broken );

    /**
     * This function sets the value of the total disk usage. The value has to
     * be provided in kilobytes. If the disk usage could not be determined,
     * total has to be set to -1.
     *
     * @param total       The total disk usage in kB.
     */
    void setTotalDiskSpace( double total );

    /**
     * This function sets the value of the free space on the share. The value
     * has to be provided in kilobytes. If the free space could not be determined,
     * free has to be set to -1.
     *
     * @param free        The free disk space in kB.
     */
    void setFreeDiskSpace( double free );

    /**
     * This function returns the total disk space of the share.
     *
     * @returns           The total disk space in kB.
     */
    double totalDiskSpace() const;

    /**
     * This function returns the free disk space available on the share in kB.
     *
     * @returns           the free disk space in kB.
     */
    double freeDiskSpace() const;

    /**
     * This function returns the percentage of used disk space on the
     * share.
     *
     * @returns           the percentage of disk space used on the share.
     */
    double percentage() const;

    /**
     * Compare another Smb4KShare object with this one and return TRUE if both
     * carry the same data.
     *
     * @param share       The Smb4KShare object that is compared to this one
     *
     * @returns           TRUE if the values match.
     */
    bool equals( const Smb4KShare &share );


  private:
    /**
     * The name of the share.
     */
    TQString m_name;

    /**
     * The mount point / path of the share
     */
    TQCString m_path;

    /**
     * The filesystem string
     */
    TQString m_filesystem;

    /**
     * The user ID of the share.
     */
    KUser m_user;

    /**
     * The group ID of the share.
     */
    KUserGroup m_group;

    /**
     * The CIFS login name
     */
    TQString m_cifs_login;
    bool m_foreign_mount;
    bool m_broken;
    double m_total;
    double m_free;
};

#endif