~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kioslave/media/libmediacommon/medium.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE Project
2
 
   Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
3
 
 
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.
7
 
 
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.
12
 
 
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.
17
 
*/
18
 
 
19
 
#include "medium.h"
20
 
 
21
 
#include <kconfig.h>
22
 
#include <klocale.h>
23
 
 
24
 
const QString Medium::SEPARATOR = "---";
25
 
 
26
 
Medium::Medium(const QString &id, const QString &name)
27
 
{
28
 
        m_properties+= id; /* ID */
29
 
        m_properties+= name; /* NAME */
30
 
        m_properties+= name; /* LABEL */
31
 
        m_properties+= QString::null; /* USER_LABEL */
32
 
 
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 */
41
 
 
42
 
        loadUserLabel();
43
 
 
44
 
        m_halmounted = false;
45
 
}
46
 
 
47
 
Medium::Medium()
48
 
{
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 */
53
 
 
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 */
62
 
        
63
 
        m_halmounted = false;
64
 
}
65
 
 
66
 
const Medium Medium::create(const QStringList &properties)
67
 
{
68
 
        Medium m;
69
 
 
70
 
        if ( properties.size() >= PROPERTIES_COUNT )
71
 
        {
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];
76
 
 
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];
85
 
        }
86
 
 
87
 
        return m;
88
 
}
89
 
 
90
 
Medium::List Medium::createList(const QStringList &properties)
91
 
{
92
 
        List l;
93
 
 
94
 
        if ( properties.size() % (PROPERTIES_COUNT+1) == 0)
95
 
        {
96
 
                int media_count = properties.size()/(PROPERTIES_COUNT+1);
97
 
 
98
 
                QStringList props = properties;
99
 
 
100
 
                for(int i=0; i<media_count; i++)
101
 
                {
102
 
                        const Medium m = create(props);
103
 
                        l.append(m);
104
 
 
105
 
                        QStringList::iterator first = props.begin();
106
 
                        QStringList::iterator last = props.find(SEPARATOR);
107
 
                        ++last;
108
 
                        props.erase(first, last);
109
 
                }
110
 
        }
111
 
 
112
 
        return l;
113
 
}
114
 
 
115
 
 
116
 
void Medium::setName(const QString &name)
117
 
{
118
 
        m_properties[NAME] = name;
119
 
}
120
 
 
121
 
void Medium::setLabel(const QString &label)
122
 
{
123
 
        m_properties[LABEL] = label;
124
 
}
125
 
 
126
 
void Medium::setUserLabel(const QString &label)
127
 
{
128
 
        KConfig cfg("mediamanagerrc");
129
 
        cfg.setGroup("UserLabels");
130
 
 
131
 
        QString entry_name = m_properties[ID];
132
 
 
133
 
        if ( label.isNull() )
134
 
        {
135
 
                cfg.deleteEntry(entry_name);
136
 
        }
137
 
        else
138
 
        {
139
 
                cfg.writeEntry(entry_name, label);
140
 
        }
141
 
 
142
 
        m_properties[USER_LABEL] = label;
143
 
}
144
 
 
145
 
void Medium::loadUserLabel()
146
 
{
147
 
        KConfig cfg("mediamanagerrc");
148
 
        cfg.setGroup("UserLabels");
149
 
 
150
 
        QString entry_name = m_properties[ID];
151
 
 
152
 
        if ( cfg.hasKey(entry_name) )
153
 
        {
154
 
                m_properties[USER_LABEL] = cfg.readEntry(entry_name);
155
 
        }
156
 
        else
157
 
        {
158
 
                m_properties[USER_LABEL] = QString::null;
159
 
        }
160
 
}
161
 
 
162
 
 
163
 
bool Medium::mountableState(bool mounted)
164
 
{
165
 
        if ( m_properties[DEVICE_NODE].isEmpty()
166
 
          || ( mounted && m_properties[MOUNT_POINT].isEmpty() ) )
167
 
        {
168
 
                return false;
169
 
        }
170
 
 
171
 
        m_properties[MOUNTABLE] = "true";
172
 
        m_properties[MOUNTED] = ( mounted ? "true" : "false" );
173
 
 
174
 
        return true;
175
 
}
176
 
 
177
 
void Medium::mountableState(const QString &deviceNode,
178
 
                            const QString &mountPoint,
179
 
                            const QString &fsType, bool mounted)
180
 
{
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" );
186
 
}
187
 
 
188
 
void Medium::unmountableState(const QString &baseURL)
189
 
{
190
 
        m_properties[MOUNTABLE] = "false";
191
 
        m_properties[BASE_URL] = baseURL;
192
 
}
193
 
 
194
 
void Medium::setMimeType(const QString &mimeType)
195
 
{
196
 
        m_properties[MIME_TYPE] = mimeType;
197
 
}
198
 
 
199
 
void Medium::setIconName(const QString &iconName)
200
 
{
201
 
        m_properties[ICON_NAME] = iconName;
202
 
}
203
 
 
204
 
bool Medium::needMounting() const
205
 
{
206
 
        return isMountable() && !isMounted();
207
 
}
208
 
 
209
 
KURL Medium::prettyBaseURL() const
210
 
{
211
 
        if ( !baseURL().isEmpty() )
212
 
            return baseURL();
213
 
 
214
 
                return KURL( mountPoint() );
215
 
}
216
 
 
217
 
QString Medium::prettyLabel() const
218
 
{
219
 
        if ( !userLabel().isEmpty() )
220
 
        {
221
 
                return userLabel();
222
 
        }
223
 
        else
224
 
        {
225
 
                return label();
226
 
        }
227
 
}
228