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.
24
const QString Medium::SEPARATOR = "---";
26
Medium::Medium(const QString &id, const QString &name)
28
m_properties+= id; /* ID */
29
m_properties+= name; /* NAME */
30
m_properties+= name; /* LABEL */
31
m_properties+= QString::null; /* USER_LABEL */
33
m_properties+= "false"; /* MOUNTABLE */
34
m_properties+= QString::null; /* DEVICE_NODE */
35
m_properties+= QString::null; /* MOUNT_POINT */
36
m_properties+= QString::null; /* FS_TYPE */
37
m_properties+= "false"; /* MOUNTED */
38
m_properties+= QString::null; /* BASE_URL */
39
m_properties+= QString::null; /* MIME_TYPE */
40
m_properties+= QString::null; /* ICON_NAME */
49
m_properties+= QString::null; /* ID */
50
m_properties+= QString::null; /* NAME */
51
m_properties+= QString::null; /* LABEL */
52
m_properties+= QString::null; /* USER_LABEL */
54
m_properties+= QString::null; /* MOUNTABLE */
55
m_properties+= QString::null; /* DEVICE_NODE */
56
m_properties+= QString::null; /* MOUNT_POINT */
57
m_properties+= QString::null; /* FS_TYPE */
58
m_properties+= QString::null; /* MOUNTED */
59
m_properties+= QString::null; /* BASE_URL */
60
m_properties+= QString::null; /* MIME_TYPE */
61
m_properties+= QString::null; /* ICON_NAME */
66
const Medium Medium::create(const QStringList &properties)
70
if ( properties.size() >= PROPERTIES_COUNT )
72
m.m_properties[ID] = properties[ID];
73
m.m_properties[NAME] = properties[NAME];
74
m.m_properties[LABEL] = properties[LABEL];
75
m.m_properties[USER_LABEL] = properties[USER_LABEL];
77
m.m_properties[MOUNTABLE] = properties[MOUNTABLE];
78
m.m_properties[DEVICE_NODE] = properties[DEVICE_NODE];
79
m.m_properties[MOUNT_POINT] = properties[MOUNT_POINT];
80
m.m_properties[FS_TYPE] = properties[FS_TYPE];
81
m.m_properties[MOUNTED] = properties[MOUNTED];
82
m.m_properties[BASE_URL] = properties[BASE_URL];
83
m.m_properties[MIME_TYPE] = properties[MIME_TYPE];
84
m.m_properties[ICON_NAME] = properties[ICON_NAME];
90
Medium::List Medium::createList(const QStringList &properties)
94
if ( properties.size() % (PROPERTIES_COUNT+1) == 0)
96
int media_count = properties.size()/(PROPERTIES_COUNT+1);
98
QStringList props = properties;
100
for(int i=0; i<media_count; i++)
102
const Medium m = create(props);
105
QStringList::iterator first = props.begin();
106
QStringList::iterator last = props.find(SEPARATOR);
108
props.erase(first, last);
116
void Medium::setName(const QString &name)
118
m_properties[NAME] = name;
121
void Medium::setLabel(const QString &label)
123
m_properties[LABEL] = label;
126
void Medium::setUserLabel(const QString &label)
128
KConfig cfg("mediamanagerrc");
129
cfg.setGroup("UserLabels");
131
QString entry_name = m_properties[ID];
133
if ( label.isNull() )
135
cfg.deleteEntry(entry_name);
139
cfg.writeEntry(entry_name, label);
142
m_properties[USER_LABEL] = label;
145
void Medium::loadUserLabel()
147
KConfig cfg("mediamanagerrc");
148
cfg.setGroup("UserLabels");
150
QString entry_name = m_properties[ID];
152
if ( cfg.hasKey(entry_name) )
154
m_properties[USER_LABEL] = cfg.readEntry(entry_name);
158
m_properties[USER_LABEL] = QString::null;
163
bool Medium::mountableState(bool mounted)
165
if ( m_properties[DEVICE_NODE].isEmpty()
166
|| ( mounted && m_properties[MOUNT_POINT].isEmpty() ) )
171
m_properties[MOUNTABLE] = "true";
172
m_properties[MOUNTED] = ( mounted ? "true" : "false" );
177
void Medium::mountableState(const QString &deviceNode,
178
const QString &mountPoint,
179
const QString &fsType, bool mounted)
181
m_properties[MOUNTABLE] = "true";
182
m_properties[DEVICE_NODE] = deviceNode;
183
m_properties[MOUNT_POINT] = mountPoint;
184
m_properties[FS_TYPE] = fsType;
185
m_properties[MOUNTED] = ( mounted ? "true" : "false" );
188
void Medium::unmountableState(const QString &baseURL)
190
m_properties[MOUNTABLE] = "false";
191
m_properties[BASE_URL] = baseURL;
194
void Medium::setMimeType(const QString &mimeType)
196
m_properties[MIME_TYPE] = mimeType;
199
void Medium::setIconName(const QString &iconName)
201
m_properties[ICON_NAME] = iconName;
204
bool Medium::needMounting() const
206
return isMountable() && !isMounted();
209
KURL Medium::prettyBaseURL() const
211
if ( !baseURL().isEmpty() )
214
return KURL( mountPoint() );
217
QString Medium::prettyLabel() const
219
if ( !userLabel().isEmpty() )