Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kfileplacesitem.cpp
Show All 12 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
13 | You should have received a copy of the GNU Library General Public License | 13 | You should have received a copy of the GNU Library General Public License | ||
14 | along with this library; see the file COPYING.LIB. If not, write to | 14 | along with this library; see the file COPYING.LIB. If not, write to | ||
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
16 | Boston, MA 02110-1301, USA. | 16 | Boston, MA 02110-1301, USA. | ||
17 | 17 | | |||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "kfileplacesitem_p.h" | 20 | #include "kfileplacesitem_p.h" | ||
21 | #include "kfileplacesmodel.h" | | |||
22 | 21 | | |||
23 | #include <QtCore/QDateTime> | 22 | #include <QtCore/QDateTime> | ||
24 | #include <QIcon> | 23 | #include <QIcon> | ||
25 | 24 | | |||
26 | #include <kbookmarkmanager.h> | 25 | #include <kbookmarkmanager.h> | ||
27 | #include <kiconloader.h> | 26 | #include <kiconloader.h> | ||
28 | #include <klocalizedstring.h> | 27 | #include <klocalizedstring.h> | ||
29 | #include <KConfig> | 28 | #include <KConfig> | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 92 | if (bookmark.metaDataItem(QStringLiteral("isSystemItem")) == QLatin1String("true")) { | |||
96 | // ensures the right string is picked from the catalog. | 95 | // ensures the right string is picked from the catalog. | ||
97 | // (coles, 13th May 2009) | 96 | // (coles, 13th May 2009) | ||
98 | 97 | | |||
99 | m_text = i18nc("KFile System Bookmarks", bookmark.text().toUtf8().data()); | 98 | m_text = i18nc("KFile System Bookmarks", bookmark.text().toUtf8().data()); | ||
100 | } else { | 99 | } else { | ||
101 | m_text = bookmark.text(); | 100 | m_text = bookmark.text(); | ||
102 | } | 101 | } | ||
103 | 102 | | |||
104 | const GroupType type = groupType(); | 103 | const KFilePlacesModel::GroupType type = groupType(); | ||
105 | switch (type) { | 104 | switch (type) { | ||
ervin: Same thing the enum move could have been a separate commit. | |||||
106 | case PlacesType: | 105 | case KFilePlacesModel::PlacesType: | ||
107 | m_groupName = i18nc("@item", "Places"); | 106 | m_groupName = i18nc("@item", "Places"); | ||
108 | break; | 107 | break; | ||
109 | case RemoteType: | 108 | case KFilePlacesModel::RemoteType: | ||
110 | m_groupName = i18nc("@item", "Remote"); | 109 | m_groupName = i18nc("@item", "Remote"); | ||
111 | break; | 110 | break; | ||
112 | case RecentlySavedType: | 111 | case KFilePlacesModel::RecentlySavedType: | ||
113 | m_groupName = i18nc("@item", "Recently Saved"); | 112 | m_groupName = i18nc("@item", "Recently Saved"); | ||
114 | break; | 113 | break; | ||
115 | case SearchForType: | 114 | case KFilePlacesModel::SearchForType: | ||
116 | m_groupName = i18nc("@item", "Search For"); | 115 | m_groupName = i18nc("@item", "Search For"); | ||
117 | break; | 116 | break; | ||
118 | case DevicesType: | 117 | case KFilePlacesModel::DevicesType: | ||
119 | m_groupName = i18nc("@item", "Devices"); | 118 | m_groupName = i18nc("@item", "Devices"); | ||
120 | break; | 119 | break; | ||
121 | case RemovableDevicesType: | 120 | case KFilePlacesModel::RemovableDevicesType: | ||
122 | m_groupName = i18nc("@item", "Removable Devices"); | 121 | m_groupName = i18nc("@item", "Removable Devices"); | ||
123 | break; | 122 | break; | ||
124 | default: | 123 | default: | ||
ervin: A fallthrough would be better here. | |||||
125 | Q_UNREACHABLE(); | 124 | Q_UNREACHABLE(); | ||
126 | break; | 125 | break; | ||
127 | } | 126 | } | ||
128 | } | 127 | } | ||
129 | 128 | | |||
130 | Solid::Device KFilePlacesItem::device() const | 129 | Solid::Device KFilePlacesItem::device() const | ||
131 | { | 130 | { | ||
132 | return m_device; | 131 | return m_device; | ||
133 | } | 132 | } | ||
134 | 133 | | |||
135 | QVariant KFilePlacesItem::data(int role) const | 134 | QVariant KFilePlacesItem::data(int role) const | ||
136 | { | 135 | { | ||
137 | if (role == KFilePlacesModel::GroupRole) { | 136 | if (role == KFilePlacesModel::GroupRole) { | ||
138 | return QVariant(m_groupName); | 137 | return QVariant(m_groupName); | ||
139 | } else if (role != KFilePlacesModel::HiddenRole && | 138 | } else if (role != KFilePlacesModel::HiddenRole && | ||
140 | role != Qt::BackgroundRole && isDevice()) { | 139 | role != Qt::BackgroundRole && isDevice()) { | ||
141 | return deviceData(role); | 140 | return deviceData(role); | ||
142 | } else { | 141 | } else { | ||
143 | return bookmarkData(role); | 142 | return bookmarkData(role); | ||
144 | } | 143 | } | ||
145 | } | 144 | } | ||
146 | 145 | | |||
147 | KFilePlacesItem::GroupType KFilePlacesItem::groupType() const | 146 | KFilePlacesModel::GroupType KFilePlacesItem::groupType() const | ||
148 | { | 147 | { | ||
149 | if (!isDevice()) { | 148 | if (!isDevice()) { | ||
150 | const QString protocol = bookmark().url().scheme(); | 149 | const QString protocol = bookmark().url().scheme(); | ||
151 | if (protocol == QLatin1String("timeline")) { | 150 | if (protocol == QLatin1String("timeline")) { | ||
152 | return RecentlySavedType; | 151 | return KFilePlacesModel::RecentlySavedType; | ||
153 | } | 152 | } | ||
154 | 153 | | |||
155 | if (protocol.contains(QLatin1String("search"))) { | 154 | if (protocol.contains(QLatin1String("search"))) { | ||
156 | return SearchForType; | 155 | return KFilePlacesModel::SearchForType; | ||
157 | } | 156 | } | ||
158 | 157 | | |||
159 | if (protocol == QLatin1String("bluetooth") || | 158 | if (protocol == QLatin1String("bluetooth") || | ||
160 | protocol == QLatin1String("obexftp") || | 159 | protocol == QLatin1String("obexftp") || | ||
161 | protocol == QLatin1String("kdeconnect")) { | 160 | protocol == QLatin1String("kdeconnect")) { | ||
162 | return DevicesType; | 161 | return KFilePlacesModel::DevicesType; | ||
163 | } | 162 | } | ||
164 | 163 | | |||
165 | if (protocol == QLatin1String("remote") || | 164 | if (protocol == QLatin1String("remote") || | ||
mlaurent: Remove (...) around QLatin1String | |||||
166 | KProtocolInfo::protocolClass(protocol) != QLatin1String(":local")) { | 165 | KProtocolInfo::protocolClass(protocol) != QLatin1String(":local")) { | ||
167 | return RemoteType; | 166 | return KFilePlacesModel::RemoteType; | ||
168 | } else { | 167 | } else { | ||
169 | return PlacesType; | 168 | return KFilePlacesModel::PlacesType; | ||
170 | } | 169 | } | ||
171 | } | 170 | } | ||
172 | 171 | | |||
173 | if (m_drive && (m_drive->isHotpluggable() || m_drive->isRemovable())) { | 172 | if (m_drive && (m_drive->isHotpluggable() || m_drive->isRemovable())) { | ||
174 | return RemovableDevicesType; | 173 | return KFilePlacesModel::RemovableDevicesType; | ||
175 | } else { | 174 | } else { | ||
176 | return DevicesType; | 175 | return KFilePlacesModel::DevicesType; | ||
177 | } | 176 | } | ||
178 | } | 177 | } | ||
179 | 178 | | |||
179 | bool KFilePlacesItem::isHidden() const | ||||
180 | { | ||||
181 | return m_bookmark.metaDataItem(QStringLiteral("IsHidden")) == QLatin1String("true"); | ||||
182 | } | ||||
183 | | ||||
184 | void KFilePlacesItem::setHidden(bool hide) | ||||
185 | { | ||||
186 | if (m_bookmark.isNull() || isHidden() == hide) { | ||||
187 | return; | ||||
188 | } | ||||
189 | m_bookmark.setMetaDataItem(QStringLiteral("IsHidden"), hide ? QStringLiteral("true") : QStringLiteral("false")); | ||||
190 | } | ||||
191 | | ||||
180 | QVariant KFilePlacesItem::bookmarkData(int role) const | 192 | QVariant KFilePlacesItem::bookmarkData(int role) const | ||
181 | { | 193 | { | ||
182 | KBookmark b = bookmark(); | 194 | KBookmark b = bookmark(); | ||
183 | 195 | | |||
184 | if (b.isNull()) { | 196 | if (b.isNull()) { | ||
185 | return QVariant(); | 197 | return QVariant(); | ||
186 | } | 198 | } | ||
187 | 199 | | |||
188 | switch (role) { | 200 | switch (role) { | ||
189 | case Qt::DisplayRole: | 201 | case Qt::DisplayRole: | ||
190 | return m_text; | 202 | return m_text; | ||
ervin: Very welcome refactoring... in a separate commit | |||||
This one is for avoiding duplicate code as we create in this patch isHidden method. mlaurent: This one is for avoiding duplicate code as we create in this patch isHidden method. | |||||
That was kind of my point, isHidden could have been introduced on its own with the changes needed to remove the duplication in the same commit. ervin: That was kind of my point, isHidden could have been introduced on its own with the changes… | |||||
191 | case Qt::DecorationRole: | 203 | case Qt::DecorationRole: | ||
192 | return QIcon::fromTheme(iconNameForBookmark(b)); | 204 | return QIcon::fromTheme(iconNameForBookmark(b)); | ||
193 | case Qt::BackgroundRole: | 205 | case Qt::BackgroundRole: | ||
194 | if (b.metaDataItem(QStringLiteral("IsHidden")) == QLatin1String("true")) { | 206 | if (isHidden()) { | ||
195 | return QColor(Qt::lightGray); | 207 | return QColor(Qt::lightGray); | ||
196 | } else { | 208 | } else { | ||
197 | return QVariant(); | 209 | return QVariant(); | ||
198 | } | 210 | } | ||
199 | case KFilePlacesModel::UrlRole: | 211 | case KFilePlacesModel::UrlRole: | ||
200 | return b.url(); | 212 | return b.url(); | ||
201 | case KFilePlacesModel::SetupNeededRole: | 213 | case KFilePlacesModel::SetupNeededRole: | ||
202 | return false; | 214 | return false; | ||
203 | case KFilePlacesModel::HiddenRole: | 215 | case KFilePlacesModel::HiddenRole: | ||
204 | return b.metaDataItem(QStringLiteral("IsHidden")) == QLatin1String("true"); | 216 | return isHidden(); | ||
205 | case KFilePlacesModel::IconNameRole: | 217 | case KFilePlacesModel::IconNameRole: | ||
206 | return iconNameForBookmark(b); | 218 | return iconNameForBookmark(b); | ||
207 | default: | 219 | default: | ||
208 | return QVariant(); | 220 | return QVariant(); | ||
209 | } | 221 | } | ||
210 | } | 222 | } | ||
211 | 223 | | |||
212 | QVariant KFilePlacesItem::deviceData(int role) const | 224 | QVariant KFilePlacesItem::deviceData(int role) const | ||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |
Same thing the enum move could have been a separate commit.