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
|
/***************************************************************************
* Copyright (C) 2012 by Peter Penz <[email protected]> *
* *
* Based on KFilePlacesItem from kdelibs: *
* Copyright (C) 2007 Kevin Ottens <[email protected]> *
* *
* 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 *
***************************************************************************/
#include "placesitem.h"
#include <KBookmark>
#include <KIcon>
#include <KLocale>
#include <Solid/Block>
PlacesItem::PlacesItem(PlacesItem* parent) :
KStandardItem(parent)
{
}
PlacesItem::PlacesItem(const KBookmark& bookmark, PlacesItem* parent) :
KStandardItem(parent),
m_device(),
m_access(),
m_volume(),
m_disc()
{
setHidden(bookmark.metaDataItem("IsHidden") == QLatin1String("true"));
const QString udi = bookmark.metaDataItem("UDI");
if (udi.isEmpty()) {
setIcon(bookmark.icon());
setText(bookmark.text());
setUrl(bookmark.url());
setDataValue("address", bookmark.address());
setGroup(i18nc("@item", "Places"));
} else {
initializeDevice(udi);
}
}
PlacesItem::PlacesItem(const QString& udi, PlacesItem* parent) :
KStandardItem(parent),
m_device(),
m_access(),
m_volume(),
m_disc()
{
initializeDevice(udi);
}
PlacesItem::PlacesItem(const PlacesItem& item) :
KStandardItem(item),
m_device(),
m_access(),
m_volume(),
m_disc()
{
}
PlacesItem::~PlacesItem()
{
}
void PlacesItem::setUrl(const KUrl& url)
{
setDataValue("url", url);
}
KUrl PlacesItem::url() const
{
return dataValue("url").value<KUrl>();
}
void PlacesItem::setHidden(bool hidden)
{
setDataValue("isHidden", hidden);
}
bool PlacesItem::isHidden() const
{
return dataValue("isHidden").toBool();
}
Solid::Device PlacesItem::device() const
{
return m_device;
}
void PlacesItem::initializeDevice(const QString& udi)
{
m_device = Solid::Device(udi);
if (!m_device.isValid()) {
return;
}
m_access = m_device.as<Solid::StorageAccess>();
m_volume = m_device.as<Solid::StorageVolume>();
m_disc = m_device.as<Solid::OpticalDisc>();
setText(m_device.description());
setIcon(m_device.icon());
setIconOverlays(m_device.emblems());
setDataValue("udi", udi);
setGroup(i18nc("@item", "Devices"));
if (m_access) {
setUrl(m_access->filePath());
} else if (m_disc && (m_disc->availableContent() & Solid::OpticalDisc::Audio) != 0) {
const QString device = m_device.as<Solid::Block>()->device();
setUrl(QString("audiocd:/?device=%1").arg(device));
}
}
|