add mp3 and ogg torrent url info to JamendoAlbum
[amarok.git] / src / medium.cpp
blobf6692d6bb18c09b8f68e4dc7d7756dae94dc544e
1 /* This file is part of the KDE Project
2 Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
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
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
18 #include "medium.h"
20 #include "debug.h"
22 #include <KConfig>
23 #include <KLocale>
25 const QString Medium::SEPARATOR = "---";
27 Medium::Medium(const QString &id, const QString &name)
29 m_properties+= "false"; /* AUTODETECTED */
30 m_properties+= id; /* ID */
31 m_properties+= name; /* NAME */
32 m_properties+= name; /* LABEL */
33 m_properties+= QString(); /* USER_LABEL */
35 m_properties+= "false"; /* MOUNTABLE */
36 m_properties+= QString(); /* DEVICE_NODE */
37 m_properties+= QString(); /* MOUNT_POINT */
38 m_properties+= QString(); /* FS_TYPE */
39 m_properties+= "false"; /* MOUNTED */
40 m_properties+= QString(); /* BASE_URL */
41 m_properties+= QString(); /* MIME_TYPE */
42 m_properties+= QString(); /* ICON_NAME */
44 loadUserLabel();
47 Medium::Medium(const Medium *medium)
49 m_properties += ( medium->isAutodetected() ? "true" : "false" );
50 m_properties += medium->id();
51 m_properties += medium->name();
52 m_properties += medium->label();
53 m_properties += medium->userLabel();
54 m_properties += ( medium->isMountable() ? "true" : "false" );
55 m_properties += medium->deviceNode();
56 m_properties += medium->mountPoint();
57 m_properties += medium->fsType();
58 m_properties += ( medium->isMounted() ? "true" : "false" );
59 m_properties += medium->baseURL();
60 m_properties += medium->mimeType();
61 m_properties += medium->iconName();
62 loadUserLabel();
65 Medium::Medium()
67 m_properties+= QString(); /* AUTODETECTED */
68 m_properties+= QString(); /* ID */
69 m_properties+= QString(); /* NAME */
70 m_properties+= QString(); /* LABEL */
71 m_properties+= QString(); /* USER_LABEL */
73 m_properties+= QString(); /* MOUNTABLE */
74 m_properties+= QString(); /* DEVICE_NODE */
75 m_properties+= QString(); /* MOUNT_POINT */
76 m_properties+= QString(); /* FS_TYPE */
77 m_properties+= QString(); /* MOUNTED */
78 m_properties+= QString(); /* BASE_URL */
79 m_properties+= QString(); /* MIME_TYPE */
80 m_properties+= QString(); /* ICON_NAME */
83 const Medium Medium::create(const QStringList &properties)
85 Medium m;
87 if ( properties.size() >= PROPERTIES_COUNT )
89 m.m_properties[AUTODETECTED] = properties[AUTODETECTED];
90 m.m_properties[ID] = properties[ID];
91 m.m_properties[NAME] = properties[NAME];
92 m.m_properties[LABEL] = properties[LABEL];
93 m.m_properties[USER_LABEL] = properties[USER_LABEL];
95 m.m_properties[MOUNTABLE] = properties[MOUNTABLE];
96 m.m_properties[DEVICE_NODE] = properties[DEVICE_NODE];
97 m.m_properties[MOUNT_POINT] = properties[MOUNT_POINT];
98 m.m_properties[FS_TYPE] = properties[FS_TYPE];
99 m.m_properties[MOUNTED] = properties[MOUNTED];
100 m.m_properties[BASE_URL] = properties[BASE_URL];
101 m.m_properties[MIME_TYPE] = properties[MIME_TYPE];
102 m.m_properties[ICON_NAME] = properties[ICON_NAME];
105 return m;
108 Medium::List Medium::createList(const QStringList &properties)
110 List l;
111 if ( properties.size() % (PROPERTIES_COUNT+1) == 0 )
113 int media_count = properties.size()/(PROPERTIES_COUNT+1);
115 QStringList props = properties;
117 for(int i=0; i<media_count; i++)
119 const Medium m = create(props);
120 l.append(m);
122 QStringList::iterator first = props.begin();
123 QStringList::iterator last = props.find(SEPARATOR);
124 ++last;
125 props.erase(first, last);
129 return l;
132 void Medium::setAutodetected(bool autodetected)
134 m_properties[AUTODETECTED] = autodetected ? "true" : "false";
137 void Medium::setName(const QString &name)
139 m_properties[NAME] = name;
142 void Medium::setMountPoint(const QString &mountPoint)
144 m_properties[MOUNT_POINT] = mountPoint;
147 void Medium::setId(const QString &id)
149 m_properties[ID] = id;
152 void Medium::setLabel(const QString &label)
154 m_properties[LABEL] = label;
157 void Medium::setFsType(const QString &type)
159 m_properties[FS_TYPE] = type;
162 void Medium::setUserLabel(const QString &label)
164 KConfig cfg("mediamanagerrc");
165 KConfigGroup grp(&cfg, "UserLabels");
167 QString entry_name = m_properties[ID];
169 if ( label.isNull() )
171 grp.deleteEntry(entry_name);
173 else
175 grp.writeEntry(entry_name, label);
178 m_properties[USER_LABEL] = label;
181 void Medium::loadUserLabel()
183 KConfig cfg("mediamanagerrc");
184 KConfigGroup grp(&cfg, "UserLabels");
186 QString entry_name = m_properties[ID];
188 if ( grp.hasKey(entry_name) )
190 m_properties[USER_LABEL] = grp.readEntry(entry_name, QString());
192 else
194 m_properties[USER_LABEL] = QString();
199 bool Medium::mountableState(bool mounted)
201 if ( m_properties[DEVICE_NODE].isEmpty()
202 || m_properties[MOUNT_POINT].isEmpty() )
204 return false;
207 m_properties[MOUNTABLE] = "true";
208 m_properties[MOUNTED] = ( mounted ? "true" : "false" );
210 return true;
213 void Medium::mountableState(const QString &deviceNode,
214 const QString &mountPoint,
215 const QString &fsType, bool mounted)
217 m_properties[MOUNTABLE] = "true";
218 m_properties[DEVICE_NODE] = deviceNode;
219 m_properties[MOUNT_POINT] = mountPoint;
220 m_properties[FS_TYPE] = fsType;
221 m_properties[MOUNTED] = ( mounted ? "true" : "false" );
224 void Medium::unmountableState(const QString &baseURL)
226 m_properties[MOUNTABLE] = "false";
227 m_properties[BASE_URL] = baseURL;
230 void Medium::setMimeType(const QString &mimeType)
232 m_properties[MIME_TYPE] = mimeType;
235 void Medium::setIconName(const QString &iconName)
237 m_properties[ICON_NAME] = iconName;
240 bool Medium::needMounting() const
242 return isMountable() && !isMounted();
245 KUrl Medium::prettyBaseURL() const
247 if ( isMountable() )
249 return KUrl( mountPoint() );
251 else
253 return KUrl( baseURL() );
257 QString Medium::prettyLabel() const
259 if ( !userLabel().isEmpty() )
261 return userLabel();
263 else
265 return label();