]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitem.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on KFilePlacesItem from kdelibs: *
5 * Copyright (C) 2007 Kevin Ottens <ervin@kde.org> *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
23 #include "placesitem.h"
28 #include "placesitemstorageaccesslistener.h"
29 #include <Solid/Block>
31 PlacesItem::PlacesItem(PlacesItem
* parent
) :
32 KStandardItem(parent
),
41 PlacesItem::PlacesItem(const KBookmark
& bookmark
, PlacesItem
* parent
) :
42 KStandardItem(parent
),
49 setHidden(bookmark
.metaDataItem("IsHidden") == QLatin1String("true"));
51 const QString udi
= bookmark
.metaDataItem("UDI");
53 setIcon(bookmark
.icon());
54 setText(bookmark
.text());
55 setUrl(bookmark
.url());
56 setDataValue("address", bookmark
.address());
57 setGroup(i18nc("@item", "Places"));
59 initializeDevice(udi
);
63 PlacesItem::PlacesItem(const QString
& udi
, PlacesItem
* parent
) :
64 KStandardItem(parent
),
71 initializeDevice(udi
);
74 PlacesItem::PlacesItem(const PlacesItem
& item
) :
84 PlacesItem::~PlacesItem()
86 delete m_accessListener
;
90 void PlacesItem::setUrl(const KUrl
& url
)
92 setDataValue("url", url
);
95 KUrl
PlacesItem::url() const
97 return dataValue("url").value
<KUrl
>();
100 void PlacesItem::setUdi(const QString
& udi
)
102 setDataValue("udi", udi
);
105 QString
PlacesItem::udi() const
107 return dataValue("udi").toString();
110 void PlacesItem::setHidden(bool hidden
)
112 setDataValue("isHidden", hidden
);
115 bool PlacesItem::isHidden() const
117 return dataValue("isHidden").toBool();
120 Solid::Device
PlacesItem::device() const
125 void PlacesItem::initializeDevice(const QString
& udi
)
127 m_device
= Solid::Device(udi
);
128 if (!m_device
.isValid()) {
132 m_access
= m_device
.as
<Solid::StorageAccess
>();
133 m_volume
= m_device
.as
<Solid::StorageVolume
>();
134 m_disc
= m_device
.as
<Solid::OpticalDisc
>();
136 setText(m_device
.description());
137 setIcon(m_device
.icon());
138 setIconOverlays(m_device
.emblems());
140 setGroup(i18nc("@item", "Devices"));
143 setUrl(m_access
->filePath());
145 // The access listener takes care to call PlacesItem::onAccessibilityChanged()
146 // in case if the accessibility of m_access has been changed.
147 Q_ASSERT(!m_accessListener
);
148 m_accessListener
= new PlacesItemStorageAccessListener(this);
149 } else if (m_disc
&& (m_disc
->availableContent() & Solid::OpticalDisc::Audio
) != 0) {
150 const QString device
= m_device
.as
<Solid::Block
>()->device();
151 setUrl(QString("audiocd:/?device=%1").arg(device
));
155 void PlacesItem::onAccessibilityChanged()
157 setIconOverlays(m_device
.emblems());