summaryrefslogtreecommitdiffstats
path: root/smb4k/core/smb4kpreviewitem.h
blob: 352d32d089b1f3e7729434e536181f1f44a22795 (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
/***************************************************************************
    smb4kpreviewitem  -  A container for previews of a remote share
                             -------------------
    begin                : Mo Mai 28 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                                                    *
 ***************************************************************************/

#ifndef SMB4KPREVIEWITEM_H
#define SMB4KPREVIEWITEM_H

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

// TQt includes
#include <tqstring.h>
#include <tqmap.h>
#include <tqpair.h>

#include <kdemacros.h>

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

typedef TQPair<int, TQString> ContentsItem;

/**
 * This class provides a container for the preview of the contents of a remote
 * SMB share.
 *
 * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
 */

class TDE_EXPORT Smb4KPreviewItem
{
  public:
    /**
     * The default constructor.
     *
     * @param item              The share for that a preview should be collected.
     *
     * @param ip                The IP address of the host where the share
     *                          is located.
     *
     * @param path              The path for that the preview should be collected.
     */
    Smb4KPreviewItem( Smb4KShareItem *item, const TQString &ip = TQString(), const TQString &path = TQString() );

    /**
     * The empty constructor.
     */
    Smb4KPreviewItem() {}

    /**
     * The destructor.
     */
    ~Smb4KPreviewItem();

    /**
     * Returns the workgroup where the host is located
     */
    const TQString &workgroup() const { return m_workgroup; }

    /**
     * Return the name of the host where the share is located.
     */
    const TQString &host() const { return m_host; }

    /**
     * Return the name of the share that is to be previewed.
     */
    const TQString &share() const { return m_share; }

    /**
     * With this function you can set the share name if this item
     * represents a homes share. In all other cases it will do just
     * nothing.
     *
     * @param share             The new share name
     */
    void setShare( const TQString &share );

    /**
     * Return the path that is to be previewed.
     */
    const TQString &path() const { return m_path; }

    /**
     * Returns the IP address of the host where the share
     * is located.
     */
    const TQString &ip() const { return m_ip; }

    /**
     * Set the IP address of the host.
     *
     * @param ip                The IP address of the host.
     */
    void setIP( const TQString &ip );

    /**
     * Set the path for which the preview.
     *
     * @param path              The path
     *
     * @note As soon as this function is used, the list of files and directories
     * will be cleared.
     */
    void setPath( const TQString &path );

    /**
     * Returns the current location in the form //HOST/SHARE/PATH.
     * It can be used for displaying in a preview dialog or for checks.
     *
     * @returns                 The current location
     */
    const TQString &location() const { return m_location; }

    /**
     * This enumeration is used for the contents. It determines if
     * an item is a file, a hidden file, a directory, or a hidden
     * directory.
     */
    enum Contents { File, HiddenFile, Directory, HiddenDirectory };

    /**
     * Returns the contents of the location.
     *
     * @returns a map of (hidden) files and (hidden) directories.
     */
    const TQValueList<ContentsItem> &contents() const { return m_contents; }

    /**
     * Add a file or directory to the contents.
     *
     * @param item              A ContentsItem object. This is a TQPair<int,TQString>
     *                          with the integer being a value from the Contents
     *                          enumeration and the string being the full path of
     *                          the file or directory.
     *
     * @see Smb4KPreviewItem::setPath() or Smb4KPreviewItem::clearContents() for how
     * the list of files and directories is cleared.
     */
    void addContents( const ContentsItem &item );

    /**
     * Clears the contents.
     */
    void clearContents();

  private:
    /**
     * The workgroup of the host
     */
    TQString m_workgroup;

    /**
     * The host's name
     */
    TQString m_host;

    /**
     * The share name
     */
    TQString m_share;

    /**
     * The IP address of the host
     */
    TQString m_ip;

    /**
     * The path that has to be previewed.
     */
    TQString m_path;

    /**
     * The current location
     */
    TQString m_location;

    /**
     * This map stores the contents of the current
     * location.
     */
    TQValueList<ContentsItem> m_contents;

    /**
     * This function checks if the IP address is valid, i.e. the
     * IP address is either IP v4 or IP v6. It returns either TRUE
     * or FALSE.
     *
     * @param ip            The IP address that's going to be checked.
     *
     * @returns TRUE if the IP address is valid and FALSE otherwise.
     */
    bool ipIsValid( const TQString &ip );
};

#endif