]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitem.cpp
Create items for devices that have not been added as bookmarks yet
[dolphin.git] / src / panels / places / placesitem.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * Based on KFilePlacesItem from kdelibs: *
5 * Copyright (C) 2007 Kevin Ottens <ervin@kde.org> *
6 * *
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. *
11 * *
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. *
16 * *
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 ***************************************************************************/
22
23 #include "placesitem.h"
24
25 #include <KBookmark>
26 #include <KIcon>
27 #include <KLocale>
28 #include <Solid/Block>
29
30 PlacesItem::PlacesItem(PlacesItem* parent) :
31 KStandardItem(parent)
32 {
33 }
34
35 PlacesItem::PlacesItem(const KBookmark& bookmark, PlacesItem* parent) :
36 KStandardItem(parent),
37 m_device(),
38 m_access(),
39 m_volume(),
40 m_disc()
41 {
42 setHidden(bookmark.metaDataItem("IsHidden") == QLatin1String("true"));
43
44 const QString udi = bookmark.metaDataItem("UDI");
45 if (udi.isEmpty()) {
46 setIcon(bookmark.icon());
47 setText(bookmark.text());
48 setUrl(bookmark.url());
49 setDataValue("address", bookmark.address());
50 setGroup(i18nc("@item", "Places"));
51 } else {
52 initializeDevice(udi);
53 }
54 }
55
56 PlacesItem::PlacesItem(const QString& udi, PlacesItem* parent) :
57 KStandardItem(parent),
58 m_device(),
59 m_access(),
60 m_volume(),
61 m_disc()
62 {
63 initializeDevice(udi);
64 }
65
66 PlacesItem::PlacesItem(const PlacesItem& item) :
67 KStandardItem(item),
68 m_device(),
69 m_access(),
70 m_volume(),
71 m_disc()
72 {
73 }
74
75 PlacesItem::~PlacesItem()
76 {
77 }
78
79 void PlacesItem::setUrl(const KUrl& url)
80 {
81 setDataValue("url", url);
82 }
83
84 KUrl PlacesItem::url() const
85 {
86 return dataValue("url").value<KUrl>();
87 }
88
89 void PlacesItem::setHidden(bool hidden)
90 {
91 setDataValue("isHidden", hidden);
92 }
93
94 bool PlacesItem::isHidden() const
95 {
96 return dataValue("isHidden").toBool();
97 }
98
99 Solid::Device PlacesItem::device() const
100 {
101 return m_device;
102 }
103
104 void PlacesItem::initializeDevice(const QString& udi)
105 {
106 m_device = Solid::Device(udi);
107 if (!m_device.isValid()) {
108 return;
109 }
110
111 m_access = m_device.as<Solid::StorageAccess>();
112 m_volume = m_device.as<Solid::StorageVolume>();
113 m_disc = m_device.as<Solid::OpticalDisc>();
114
115 setText(m_device.description());
116 setIcon(m_device.icon());
117 setIconOverlays(m_device.emblems());
118 setDataValue("udi", udi);
119 setGroup(i18nc("@item", "Devices"));
120
121 if (m_access) {
122 setUrl(m_access->filePath());
123 } else if (m_disc && (m_disc->availableContent() & Solid::OpticalDisc::Audio) != 0) {
124 const QString device = m_device.as<Solid::Block>()->device();
125 setUrl(QString("audiocd:/?device=%1").arg(device));
126 }
127 }
128