From 23fff35aeb4143b73666471d7f79f30d808e2cf2 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sat, 5 May 2012 21:38:01 +0200 Subject: Places Panel: Provide access to devices --- src/panels/places/placesitem.cpp | 103 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/panels/places/placesitem.cpp (limited to 'src/panels/places/placesitem.cpp') diff --git a/src/panels/places/placesitem.cpp b/src/panels/places/placesitem.cpp new file mode 100644 index 000000000..11a7462c4 --- /dev/null +++ b/src/panels/places/placesitem.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (C) 2012 by Peter Penz * + * * + * Based on KFilePlacesItem from kdelibs: * + * Copyright (C) 2007 Kevin Ottens * + * * + * 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 +#include +#include +#include + +PlacesItem::PlacesItem(PlacesItem* parent) : + KStandardItem(parent) +{ +} + +PlacesItem::PlacesItem(const KBookmark& bookmark, const QString& udi, PlacesItem* parent) : + KStandardItem(parent), + m_device(udi), + m_access(), + m_volume(), + m_disc() +{ + setHidden(bookmark.metaDataItem("IsHidden") == QLatin1String("true")); + + if (udi.isEmpty()) { + setIcon(bookmark.icon()); + setText(bookmark.text()); + setUrl(bookmark.url()); + setDataValue("address", bookmark.address()); + setGroup(i18nc("@item", "Places")); + } else if (m_device.isValid()) { + m_access = m_device.as(); + m_volume = m_device.as(); + m_disc = m_device.as(); + + 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()->device(); + setUrl(QString("audiocd:/?device=%1").arg(device)); + } + } +} + +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(); +} + +void PlacesItem::setHidden(bool hidden) +{ + setDataValue("isHidden", hidden); +} + +bool PlacesItem::isHidden() const +{ + return dataValue("isHidden").toBool(); +} + + -- cgit v1.3