~ubuntu-branches/ubuntu/vivid/smb4k/vivid

« back to all changes in this revision

Viewing changes to core/smb4kbookmark.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mfrom: (1.1.20)
  • Revision ID: package-import@ubuntu.com-20120519185434-duffny2n87214n1n
Tags: 1.0.1-1
* New upstream release.
* Update debian/compat: bump to 9.
* Update debian/control:
  - bump debhelper to 9.
  - bump kdelibs5-dev build dependency to 4:4.4.0.
  - bump Standards-Version to 3.9.3 (no changes needed).
  - Replace smbfs dependency by cifs-utils. (Closes: #638162)
* Update debian/copyright:
  - update upstream URL.
  - update upstream e-mail.
* Update debian/smb4k.lintian-overrides file.
* Update debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
    generation).
4
4
                             -------------------
5
5
    begin                : So Jun 8 2008
6
 
    copyright            : (C) 2008 by Alexander Reinholdt
7
 
    email                : dustpuppy@users.berlios.de
 
6
    copyright            : (C) 2008-2011 by Alexander Reinholdt
 
7
    email                : alexander.reinholdt@kdemail.net
8
8
 ***************************************************************************/
9
9
 
10
10
/***************************************************************************
20
20
 *                                                                         *
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, Inc., 59 Temple Place, Suite 330, Boston,   *
24
 
 *   MA  02111-1307 USA                                                    *
 
23
 *   Free Software Foundation, 51 Franklin Street, Suite 500, Boston,      *
 
24
 *   MA 02110-1335, USA                                                    *
25
25
 ***************************************************************************/
26
26
 
27
27
// Qt includes
28
28
#include <QHostAddress>
29
29
#include <QAbstractSocket>
30
30
 
 
31
// KDE includes
 
32
#include <kdebug.h>
 
33
#include <kicon.h>
 
34
 
31
35
// application specific includes
32
36
#include <smb4kbookmark.h>
33
37
#include <smb4kshare.h>
34
38
 
35
39
 
36
40
Smb4KBookmark::Smb4KBookmark( Smb4KShare *share, const QString &label )
37
 
: m_workgroup( share->workgroup() ), m_host( share->host() ), m_share( share->name() ),
38
 
  m_ip( share->hostIP() ), m_type( share->type() ), m_unc( share->unc() ), m_label( label ),
39
 
  m_profile( QString() )
 
41
: m_url( QUrl() ), m_workgroup( share->workgroupName() ), m_ip( share->hostIP() ),
 
42
  m_type( share->typeString() ), m_label( label ), m_group( QString() ), m_profile( QString() ),
 
43
  m_icon( KIcon( "folder-remote" ) )
40
44
{
 
45
  if ( !share->isHomesShare() )
 
46
  {
 
47
    m_url = share->url();
 
48
  }
 
49
  else
 
50
  {
 
51
    m_url = share->homeURL();
 
52
  }
41
53
}
42
54
 
43
55
 
44
56
Smb4KBookmark::Smb4KBookmark( const Smb4KBookmark &b )
45
 
: m_workgroup( b.workgroup() ), m_host( b.host() ), m_share( b.share() ),
46
 
  m_ip( b.hostIP() ), m_type( b.type() ), m_unc( b.unc() ), m_label( b.label() ),
47
 
  m_profile( b.profile() )
 
57
: m_url( b.url() ), m_workgroup( b.workgroupName() ), m_ip( b.hostIP() ), m_type( b.typeString() ),
 
58
  m_label( b.label() ), m_group( b.group() ), m_profile( b.profile() ), m_icon( b.icon() )
48
59
{
49
60
}
50
61
 
51
62
 
52
63
Smb4KBookmark::Smb4KBookmark()
53
 
: m_workgroup( QString() ), m_host( QString() ), m_share( QString() ),
54
 
  m_ip( QString() ), m_type( "Disk" ), m_unc( QString() ), m_label( QString() ),
55
 
  m_profile( QString() )
 
64
: m_url( QUrl() ), m_workgroup( QString() ), m_ip( QString() ), m_type( "Disk" ),
 
65
  m_label( QString() ), m_group( QString() ), m_profile( QString() ), 
 
66
  m_icon( KIcon( "folder-remote" ) )
56
67
{
57
68
}
58
69
 
62
73
}
63
74
 
64
75
 
65
 
void Smb4KBookmark::setWorkgroup( const QString &workgroup )
 
76
void Smb4KBookmark::setWorkgroupName( const QString &workgroup )
66
77
{
67
78
  m_workgroup = workgroup;
68
79
}
69
80
 
70
81
 
71
 
void Smb4KBookmark::setHost( const QString &host )
72
 
{
73
 
  m_host = host;
74
 
  m_unc = "//"+host+"/"+m_share;
75
 
}
76
 
 
77
 
 
78
 
void Smb4KBookmark::setShare( const QString &share )
79
 
{
80
 
  m_share = share;
81
 
  m_unc = "//"+m_host+"/"+share;
 
82
void Smb4KBookmark::setHostName( const QString &host )
 
83
{
 
84
  m_url.setHost( host );
 
85
  
 
86
  if ( m_url.scheme().isEmpty() )
 
87
  {
 
88
    m_url.setScheme( "smb" );
 
89
  }
 
90
  else
 
91
  {
 
92
    // Do nothing
 
93
  }
 
94
}
 
95
 
 
96
 
 
97
void Smb4KBookmark::setShareName( const QString &share )
 
98
{
 
99
  m_url.setPath( share );
 
100
}
 
101
 
 
102
 
 
103
QString Smb4KBookmark::shareName() const
 
104
{
 
105
  if ( m_url.path().startsWith( "/" ) )
 
106
  {
 
107
    return m_url.path().remove( 0, 1 );
 
108
  }
 
109
  else
 
110
  {
 
111
    // Do nothing
 
112
  }
 
113
 
 
114
  return m_url.path();
82
115
}
83
116
 
84
117
 
88
121
}
89
122
 
90
123
 
91
 
void Smb4KBookmark::setType( const QString &type )
 
124
void Smb4KBookmark::setTypeString( const QString &type )
92
125
{
93
126
  m_type = type;
94
127
}
96
129
 
97
130
void Smb4KBookmark::setUNC( const QString &unc )
98
131
{
99
 
  m_unc = unc;
100
 
 
101
 
  // Extract host and share from the UNC
102
 
  if ( !unc.contains( "@" ) )
103
 
  {
104
 
    m_host = m_unc.section( "/", 2, 2 ).trimmed();
105
 
  }
106
 
  else
107
 
  {
108
 
    m_host = m_unc.section( "@", 1, 1 ).section( "/", 0, 0 ).trimmed();
109
 
  }
110
 
 
111
 
  m_share = m_unc.section( "/", 3, 3 ).trimmed();
 
132
  // Set the UNC.
 
133
  m_url.setUrl( unc, QUrl::TolerantMode );
 
134
 
 
135
  if ( m_url.scheme().isEmpty() )
 
136
  {
 
137
    m_url.setScheme( "smb" );
 
138
  }
 
139
  else
 
140
  {
 
141
    // Do nothing
 
142
  }
 
143
}
 
144
 
 
145
 
 
146
QString Smb4KBookmark::unc( QUrl::FormattingOptions options ) const
 
147
{
 
148
  QString unc;
 
149
  
 
150
  if ( (options & QUrl::RemoveUserInfo) || m_url.userName().isEmpty() )
 
151
  {
 
152
    unc = m_url.toString( options ).replace( "//"+m_url.host(), "//"+hostName() );
 
153
  }
 
154
  else
 
155
  {
 
156
    unc = m_url.toString( options ).replace( "@"+m_url.host(), "@"+hostName() );
 
157
  }
 
158
  
 
159
  return unc;
 
160
}
 
161
 
 
162
 
 
163
QString Smb4KBookmark::hostUNC( QUrl::FormattingOptions options ) const
 
164
{
 
165
  QString unc;
 
166
  
 
167
  if ( (options & QUrl::RemoveUserInfo) || m_url.userName().isEmpty() )
 
168
  {
 
169
    unc = m_url.toString( options|QUrl::RemovePath ).replace( "//"+m_url.host(), "//"+hostName() );
 
170
  }
 
171
  else
 
172
  {
 
173
    unc = m_url.toString( options|QUrl::RemovePath ).replace( "@"+m_url.host(), "@"+hostName() );
 
174
  }
 
175
  
 
176
  return unc;
112
177
}
113
178
 
114
179
 
118
183
}
119
184
 
120
185
 
 
186
void Smb4KBookmark::setLogin( const QString &login )
 
187
{
 
188
  m_url.setUserName( login );
 
189
}
 
190
 
 
191
 
 
192
void Smb4KBookmark::setGroup( const QString &name )
 
193
{
 
194
  m_group = name;
 
195
}
 
196
 
 
197
 
121
198
void Smb4KBookmark::setProfile( const QString &profile )
122
199
{
123
200
  m_profile = profile;
124
201
}
125
202
 
126
203
 
 
204
bool Smb4KBookmark::equals( Smb4KBookmark *bookmark ) const
 
205
{
 
206
  // URL
 
207
  QUrl url( bookmark->unc( QUrl::None ) );
 
208
  
 
209
  if ( m_url != url )
 
210
  {
 
211
    return false;
 
212
  }
 
213
  else
 
214
  {
 
215
    // Do nothing
 
216
  }
 
217
  
 
218
  // Workgroup
 
219
  if ( QString::compare( m_workgroup, bookmark->workgroupName(), Qt::CaseInsensitive ) != 0 )
 
220
  {
 
221
    return false;
 
222
  }
 
223
  else
 
224
  {
 
225
    // Do nothing
 
226
  }
 
227
  
 
228
  // IP address
 
229
  if ( QString::compare( m_ip, bookmark->hostIP() ) != 0 )
 
230
  {
 
231
    return false;
 
232
  }
 
233
  else
 
234
  {
 
235
    // Do nothing
 
236
  }
 
237
  
 
238
  // Type string
 
239
  if ( QString::compare( m_type, bookmark->typeString() ) != 0 )
 
240
  {
 
241
    return false;
 
242
  }
 
243
  else
 
244
  {
 
245
    // Do nothing
 
246
  }
 
247
  
 
248
  // Label
 
249
  if ( QString::compare( m_label, bookmark->label() ) != 0 )
 
250
  {
 
251
    return false;
 
252
  }
 
253
  else
 
254
  {
 
255
    // Do nothing
 
256
  }
 
257
  
 
258
  // Group
 
259
  if ( QString::compare( m_group, bookmark->group() ) != 0 )
 
260
  {
 
261
    return false;
 
262
  }
 
263
  else
 
264
  {
 
265
    // Do nothing
 
266
  }
 
267
  
 
268
  // Profile
 
269
  if ( QString::compare( m_profile, bookmark->profile() ) != 0 )
 
270
  {
 
271
    return false;
 
272
  }
 
273
  else
 
274
  {
 
275
    // Do nothing
 
276
  }
 
277
 
 
278
  // The icon is not used here.
 
279
 
 
280
  return true;
 
281
}
 
282
 
 
283
 
 
284
void Smb4KBookmark::setIcon( const QIcon &icon )
 
285
{
 
286
  m_icon = icon;
 
287
}
 
288
 
 
289
 
127
290
const QString &Smb4KBookmark::ipIsValid( const QString &ip )
128
291
{
129
292
  QHostAddress ip_address( ip );