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, *
23
* Free Software Foundation, 51 Franklin Street, Suite 500, Boston, *
24
* MA 02110-1335, USA *
25
25
***************************************************************************/
28
28
#include <QHostAddress>
29
29
#include <QAbstractSocket>
31
35
// application specific includes
32
36
#include <smb4kbookmark.h>
33
37
#include <smb4kshare.h>
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" ) )
45
if ( !share->isHomesShare() )
51
m_url = share->homeURL();
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() )
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" ) )
65
void Smb4KBookmark::setWorkgroup( const QString &workgroup )
76
void Smb4KBookmark::setWorkgroupName( const QString &workgroup )
67
78
m_workgroup = workgroup;
71
void Smb4KBookmark::setHost( const QString &host )
74
m_unc = "//"+host+"/"+m_share;
78
void Smb4KBookmark::setShare( const QString &share )
81
m_unc = "//"+m_host+"/"+share;
82
void Smb4KBookmark::setHostName( const QString &host )
84
m_url.setHost( host );
86
if ( m_url.scheme().isEmpty() )
88
m_url.setScheme( "smb" );
97
void Smb4KBookmark::setShareName( const QString &share )
99
m_url.setPath( share );
103
QString Smb4KBookmark::shareName() const
105
if ( m_url.path().startsWith( "/" ) )
107
return m_url.path().remove( 0, 1 );
97
130
void Smb4KBookmark::setUNC( const QString &unc )
101
// Extract host and share from the UNC
102
if ( !unc.contains( "@" ) )
104
m_host = m_unc.section( "/", 2, 2 ).trimmed();
108
m_host = m_unc.section( "@", 1, 1 ).section( "/", 0, 0 ).trimmed();
111
m_share = m_unc.section( "/", 3, 3 ).trimmed();
133
m_url.setUrl( unc, QUrl::TolerantMode );
135
if ( m_url.scheme().isEmpty() )
137
m_url.setScheme( "smb" );
146
QString Smb4KBookmark::unc( QUrl::FormattingOptions options ) const
150
if ( (options & QUrl::RemoveUserInfo) || m_url.userName().isEmpty() )
152
unc = m_url.toString( options ).replace( "//"+m_url.host(), "//"+hostName() );
156
unc = m_url.toString( options ).replace( "@"+m_url.host(), "@"+hostName() );
163
QString Smb4KBookmark::hostUNC( QUrl::FormattingOptions options ) const
167
if ( (options & QUrl::RemoveUserInfo) || m_url.userName().isEmpty() )
169
unc = m_url.toString( options|QUrl::RemovePath ).replace( "//"+m_url.host(), "//"+hostName() );
173
unc = m_url.toString( options|QUrl::RemovePath ).replace( "@"+m_url.host(), "@"+hostName() );
186
void Smb4KBookmark::setLogin( const QString &login )
188
m_url.setUserName( login );
192
void Smb4KBookmark::setGroup( const QString &name )
121
198
void Smb4KBookmark::setProfile( const QString &profile )
123
200
m_profile = profile;
204
bool Smb4KBookmark::equals( Smb4KBookmark *bookmark ) const
207
QUrl url( bookmark->unc( QUrl::None ) );
219
if ( QString::compare( m_workgroup, bookmark->workgroupName(), Qt::CaseInsensitive ) != 0 )
229
if ( QString::compare( m_ip, bookmark->hostIP() ) != 0 )
239
if ( QString::compare( m_type, bookmark->typeString() ) != 0 )
249
if ( QString::compare( m_label, bookmark->label() ) != 0 )
259
if ( QString::compare( m_group, bookmark->group() ) != 0 )
269
if ( QString::compare( m_profile, bookmark->profile() ) != 0 )
278
// The icon is not used here.
284
void Smb4KBookmark::setIcon( const QIcon &icon )
127
290
const QString &Smb4KBookmark::ipIsValid( const QString &ip )
129
292
QHostAddress ip_address( ip );