File: smb4kbookmark.cpp

package info (click to toggle)
smb4k 4.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,320 kB
  • sloc: cpp: 19,431; xml: 967; makefile: 7; sh: 5
file content (187 lines) | stat: -rw-r--r-- 3,421 bytes parent folder | download | duplicates (2)
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
/*
    This is the bookmark container for Smb4K (next generation).

    SPDX-FileCopyrightText: 2008-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
    SPDX-License-Identifier: GPL-2.0-or-later
*/

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

// Qt includes
#include <QDebug>
#include <QHostAddress>

// KDE includes
#include <KIconLoader>
#include <KLocalizedString>

using namespace Smb4KGlobal;

class Smb4KBookmarkPrivate
{
public:
    QUrl url;
    QString workgroup;
    QHostAddress ip;
    QString label;
    QString category;
    QString profile;
    QIcon icon;
    Smb4KGlobal::ShareType type;
};

Smb4KBookmark::Smb4KBookmark(Smb4KShare *share, const QString &label)
    : d(new Smb4KBookmarkPrivate)
{
    setShare(share);
    d->label = label;
}

Smb4KBookmark::Smb4KBookmark(const Smb4KBookmark &b)
    : d(new Smb4KBookmarkPrivate)
{
    *d = *b.d;
}

Smb4KBookmark::Smb4KBookmark()
    : d(new Smb4KBookmarkPrivate)
{
    d->type = FileShare;
    d->icon = KDE::icon(QStringLiteral("folder-network"));
}

Smb4KBookmark::~Smb4KBookmark()
{
}

void Smb4KBookmark::setShare(Smb4KShare *share) const
{
    if (!share->isHomesShare()) {
        d->url = share->url();
    } else {
        d->url = share->homeUrl();
    }

    d->workgroup = share->workgroupName();
    d->type = share->shareType();
    d->icon = KDE::icon(QStringLiteral("folder-network"));
    d->ip.setAddress(share->hostIpAddress());
}

void Smb4KBookmark::setWorkgroupName(const QString &workgroup) const
{
    d->workgroup = workgroup;
}

QString Smb4KBookmark::workgroupName() const
{
    return d->workgroup;
}

QString Smb4KBookmark::hostName() const
{
    return d->url.host().toUpper();
}

QString Smb4KBookmark::shareName() const
{
    if (d->url.path().startsWith(QStringLiteral("/"))) {
        return d->url.path().remove(0, 1);
    }

    return d->url.path();
}

void Smb4KBookmark::setHostIpAddress(const QString &ip) const
{
    d->ip.setAddress(ip);
}

QString Smb4KBookmark::hostIpAddress() const
{
    return d->ip.toString();
}

void Smb4KBookmark::setShareType(Smb4KGlobal::ShareType type) const
{
    d->type = type;
}

Smb4KGlobal::ShareType Smb4KBookmark::shareType() const
{
    return d->type;
}

void Smb4KBookmark::setLabel(const QString &label) const
{
    d->label = label;
}

QString Smb4KBookmark::label() const
{
    return d->label;
}

void Smb4KBookmark::setUserName(const QString &name) const
{
    d->url.setUserName(name);
}

QString Smb4KBookmark::userName() const
{
    return d->url.userName();
}

void Smb4KBookmark::setUrl(const QUrl &url) const
{
    d->url = url;
    d->url.setScheme(QStringLiteral("smb"));
}

QUrl Smb4KBookmark::url() const
{
    return d->url;
}

void Smb4KBookmark::setCategoryName(const QString &name) const
{
    d->category = name;
}

QString Smb4KBookmark::categoryName() const
{
    return d->category;
}

void Smb4KBookmark::setProfile(const QString &profile) const
{
    d->profile = profile;
}

QString Smb4KBookmark::profile() const
{
    return d->profile;
}

void Smb4KBookmark::setIcon(const QIcon &icon) const
{
    d->icon = icon;
}

QIcon Smb4KBookmark::icon() const
{
    return d->icon;
}

QString Smb4KBookmark::displayString() const
{
    return i18n("%1 on %2", shareName(), hostName());
}

Smb4KBookmark &Smb4KBookmark::operator=(const Smb4KBookmark &other)
{
    *d = *other.d;
    return *this;
}