|
Lines 41-52
Link Here
|
| 41 |
#include <kprocess.h> |
41 |
#include <kprocess.h> |
| 42 |
|
42 |
|
| 43 |
#define MOUNT_SUFFIX ( \ |
43 |
#define MOUNT_SUFFIX ( \ |
| 44 |
(medium->isMounted() ? TQString("_mounted") : TQString("_unmounted")) + \ |
44 |
(medium->isMounted() ? TQString("_mounted") : TQString("_unmounted")) \ |
| 45 |
(medium->isEncrypted() ? (halClearVolume ? "_decrypted" : "_encrypted") : "" ) \ |
|
|
| 46 |
) |
45 |
) |
| 47 |
#define MOUNT_ICON_SUFFIX ( \ |
46 |
#define MOUNT_ICON_SUFFIX ( \ |
| 48 |
(medium->isMounted() ? TQString("_mount") : TQString("_unmount")) + \ |
47 |
(medium->isMounted() ? TQString("_mount") : TQString("_unmount")) \ |
| 49 |
(medium->isEncrypted() ? (halClearVolume ? "_decrypt" : "_encrypt") : "" ) \ |
|
|
| 50 |
) |
48 |
) |
| 51 |
|
49 |
|
| 52 |
/* Static instance of this class, for static HAL callbacks */ |
50 |
/* Static instance of this class, for static HAL callbacks */ |
|
Lines 57-66
Link Here
|
| 57 |
{ |
55 |
{ |
| 58 |
char* _ppt_string; |
56 |
char* _ppt_string; |
| 59 |
TQString _ppt_QString; |
57 |
TQString _ppt_QString; |
| 60 |
_ppt_string = libhal_device_get_property_string(ctx, udi, key, NULL); |
58 |
_ppt_string = hal_device_get_property_string(ctx, udi, key); |
| 61 |
if ( _ppt_string ) |
59 |
if ( _ppt_string ) |
| 62 |
_ppt_QString = _ppt_string; |
60 |
_ppt_QString = _ppt_string; |
| 63 |
libhal_free_string(_ppt_string); |
61 |
hal_free_string(_ppt_string); |
| 64 |
return _ppt_QString; |
62 |
return _ppt_QString; |
| 65 |
} |
63 |
} |
| 66 |
|
64 |
|
|
Lines 92-98
Link Here
|
| 92 |
|
90 |
|
| 93 |
/* Remove all the registered media first */ |
91 |
/* Remove all the registered media first */ |
| 94 |
int numDevices; |
92 |
int numDevices; |
| 95 |
char** halDeviceList = libhal_get_all_devices( m_halContext, &numDevices, NULL ); |
93 |
char** halDeviceList = hal_get_all_devices( m_halContext, &numDevices ); |
| 96 |
|
94 |
|
| 97 |
if ( halDeviceList ) |
95 |
if ( halDeviceList ) |
| 98 |
{ |
96 |
{ |
|
Lines 102-171
Link Here
|
| 102 |
} |
100 |
} |
| 103 |
} |
101 |
} |
| 104 |
|
102 |
|
| 105 |
libhal_free_string_array( halDeviceList ); |
103 |
hal_free_string_array( halDeviceList ); |
| 106 |
|
104 |
|
| 107 |
DBusError error; |
105 |
hal_shutdown(m_halContext); |
| 108 |
dbus_error_init(&error); |
|
|
| 109 |
libhal_ctx_shutdown(m_halContext, &error); |
| 110 |
libhal_ctx_free(m_halContext); |
| 111 |
} |
106 |
} |
| 112 |
|
107 |
|
| 113 |
if (m_halStoragePolicy) |
108 |
if (m_halStoragePolicy) |
| 114 |
libhal_storage_policy_free(m_halStoragePolicy); |
109 |
hal_storage_policy_free(m_halStoragePolicy); |
| 115 |
} |
110 |
} |
| 116 |
|
111 |
|
| 117 |
/* Connect to the HAL */ |
112 |
/* Connect to the HAL */ |
| 118 |
bool HALBackend::InitHal() |
113 |
bool HALBackend::InitHal() |
| 119 |
{ |
114 |
{ |
| 120 |
kdDebug(1219) << "Context new" << endl; |
115 |
kdDebug(1219) << "Context new" << endl; |
| 121 |
m_halContext = libhal_ctx_new(); |
116 |
|
|
|
117 |
/* libhal initialization */ |
| 118 |
m_halFunctions.main_loop_integration = HALBackend::hal_main_loop_integration; |
| 119 |
m_halFunctions.device_added = HALBackend::hal_device_added; |
| 120 |
m_halFunctions.device_removed = HALBackend::hal_device_removed; |
| 121 |
m_halFunctions.device_new_capability = NULL; |
| 122 |
m_halFunctions.device_lost_capability = NULL; |
| 123 |
m_halFunctions.device_property_modified = HALBackend::hal_device_property_modified; |
| 124 |
m_halFunctions.device_condition = HALBackend::hal_device_condition; |
| 125 |
|
| 126 |
m_halContext = hal_initialize(&m_halFunctions, false); |
| 122 |
if (!m_halContext) |
127 |
if (!m_halContext) |
| 123 |
{ |
128 |
{ |
| 124 |
kdDebug(1219) << "Failed to initialize HAL!" << endl; |
129 |
kdDebug(1219) << "Failed to initialize HAL!" << endl; |
| 125 |
return false; |
130 |
return false; |
| 126 |
} |
131 |
} |
| 127 |
|
132 |
|
| 128 |
// Main loop integration |
|
|
| 129 |
kdDebug(1219) << "Main loop integration" << endl; |
| 130 |
DBusError error; |
| 131 |
dbus_error_init(&error); |
| 132 |
dbus_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); |
| 133 |
|
| 134 |
if (!dbus_connection || dbus_error_is_set(&error)) { |
| 135 |
dbus_error_free(&error); |
| 136 |
libhal_ctx_free(m_halContext); |
| 137 |
m_halContext = NULL; |
| 138 |
return false; |
| 139 |
} |
| 140 |
|
| 141 |
dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE); |
| 142 |
|
| 143 |
MainLoopIntegration(dbus_connection); |
| 144 |
libhal_ctx_set_dbus_connection(m_halContext, dbus_connection); |
| 145 |
|
| 146 |
// HAL callback functions |
| 147 |
kdDebug(1219) << "Callback functions" << endl; |
| 148 |
libhal_ctx_set_device_added(m_halContext, HALBackend::hal_device_added); |
| 149 |
libhal_ctx_set_device_removed(m_halContext, HALBackend::hal_device_removed); |
| 150 |
libhal_ctx_set_device_new_capability (m_halContext, NULL); |
| 151 |
libhal_ctx_set_device_lost_capability (m_halContext, NULL); |
| 152 |
libhal_ctx_set_device_property_modified (m_halContext, HALBackend::hal_device_property_modified); |
| 153 |
libhal_ctx_set_device_condition(m_halContext, HALBackend::hal_device_condition); |
| 154 |
|
| 155 |
kdDebug(1219) << "Context Init" << endl; |
| 156 |
if (!libhal_ctx_init(m_halContext, &error)) |
| 157 |
{ |
| 158 |
if (dbus_error_is_set(&error)) |
| 159 |
dbus_error_free(&error); |
| 160 |
libhal_ctx_free(m_halContext); |
| 161 |
m_halContext = NULL; |
| 162 |
kdDebug(1219) << "Failed to init HAL context!" << endl; |
| 163 |
return false; |
| 164 |
} |
| 165 |
|
| 166 |
/** @todo customize watch policy */ |
133 |
/** @todo customize watch policy */ |
| 167 |
kdDebug(1219) << "Watch properties" << endl; |
134 |
kdDebug(1219) << "Watch properties" << endl; |
| 168 |
if (!libhal_device_property_watch_all(m_halContext, &error)) |
135 |
if (hal_device_property_watch_all(m_halContext)) |
| 169 |
{ |
136 |
{ |
| 170 |
kdDebug(1219) << "Failed to watch HAL properties!" << endl; |
137 |
kdDebug(1219) << "Failed to watch HAL properties!" << endl; |
| 171 |
return false; |
138 |
return false; |
|
Lines 173-179
Link Here
|
| 173 |
|
140 |
|
| 174 |
/* libhal-storage initialization */ |
141 |
/* libhal-storage initialization */ |
| 175 |
kdDebug(1219) << "Storage Policy" << endl; |
142 |
kdDebug(1219) << "Storage Policy" << endl; |
| 176 |
m_halStoragePolicy = libhal_storage_policy_new(); |
143 |
m_halStoragePolicy = hal_storage_policy_new(); |
| 177 |
/** @todo define libhal-storage icon policy */ |
144 |
/** @todo define libhal-storage icon policy */ |
| 178 |
|
145 |
|
| 179 |
/* List devices at startup */ |
146 |
/* List devices at startup */ |
|
Lines 186-201
Link Here
|
| 186 |
kdDebug(1219) << "ListDevices" << endl; |
153 |
kdDebug(1219) << "ListDevices" << endl; |
| 187 |
|
154 |
|
| 188 |
int numDevices; |
155 |
int numDevices; |
| 189 |
char** halDeviceList = libhal_get_all_devices(m_halContext, &numDevices, NULL); |
156 |
char** halDeviceList = hal_get_all_devices(m_halContext, &numDevices); |
| 190 |
|
157 |
|
| 191 |
if (!halDeviceList) |
158 |
if (!halDeviceList) |
| 192 |
return false; |
159 |
return false; |
| 193 |
|
160 |
|
| 194 |
kdDebug(1219) << "HALBackend::ListDevices : " << numDevices << " devices found" << endl; |
161 |
kdDebug(1219) << "HALBackend::ListDevices : " << numDevices << " devices found" << endl; |
| 195 |
for (int i = 0; i < numDevices; i++) |
162 |
for (int i = 0; i < numDevices; i++) { |
|
|
163 |
kdDebug(1219) << "HALBackend::ListDevices : adding device " << i << endl; |
| 196 |
AddDevice(halDeviceList[i], false); |
164 |
AddDevice(halDeviceList[i], false); |
|
|
165 |
kdDebug(1219) << "HALBackend::ListDevices : end adding device " << i << endl; |
| 166 |
} |
| 197 |
|
167 |
|
| 198 |
libhal_free_string_array( halDeviceList ); |
168 |
hal_free_string_array( halDeviceList ); |
| 199 |
|
169 |
|
| 200 |
return true; |
170 |
return true; |
| 201 |
} |
171 |
} |
|
Lines 206-268
Link Here
|
| 206 |
{ |
176 |
{ |
| 207 |
/* We don't deal with devices that do not expose their capabilities. |
177 |
/* We don't deal with devices that do not expose their capabilities. |
| 208 |
If we don't check this, we will get a lot of warning messages from libhal */ |
178 |
If we don't check this, we will get a lot of warning messages from libhal */ |
| 209 |
if (!libhal_device_property_exists(m_halContext, udi, "info.capabilities", NULL)) |
179 |
if (!hal_device_property_exists(m_halContext, udi, "info.capabilities")) { |
|
|
180 |
kdDebug(1219) << "HALBackend::AddDevice : Device does not expose capability. Skipping." << endl; |
| 210 |
return; |
181 |
return; |
|
|
182 |
} |
| 211 |
|
183 |
|
| 212 |
/* If the device is already listed, do not process. |
184 |
/* If the device is already listed, do not process. |
| 213 |
This should not happen, but who knows... */ |
185 |
This should not happen, but who knows... */ |
| 214 |
/** @todo : refresh properties instead ? */ |
186 |
/** @todo : refresh properties instead ? */ |
| 215 |
if (m_mediaList.findById(udi)) |
187 |
if (m_mediaList.findById(udi)) { |
|
|
188 |
kdDebug(1219) << "HALBackend::AddDevice : Device is already listed. Skipping." << endl; |
| 216 |
return; |
189 |
return; |
|
|
190 |
} |
| 217 |
|
191 |
|
| 218 |
if (libhal_device_get_property_bool(m_halContext, "/org/freedesktop/Hal/devices/computer", "storage.disable_volume_handling", NULL)) |
192 |
if (hal_device_get_property_bool(m_halContext, "/org/freedesktop/Hal/devices/computer", "storage.disable_volume_handling")) |
| 219 |
allowNotification=false; |
193 |
allowNotification=false; |
| 220 |
|
194 |
|
| 221 |
/* Add volume block devices */ |
195 |
/* Add volume block devices */ |
| 222 |
if (libhal_device_query_capability(m_halContext, udi, "volume", NULL)) |
196 |
if (hal_device_query_capability(m_halContext, udi, "volume")) |
| 223 |
{ |
197 |
{ |
|
|
198 |
kdDebug(1219) << "HALBackend::AddDevice : Device is a volume." << endl; |
| 224 |
/* We only list volumes that... |
199 |
/* We only list volumes that... |
| 225 |
* - are encrypted with LUKS or |
|
|
| 226 |
* - have a filesystem or |
200 |
* - have a filesystem or |
| 227 |
* - have an audio track |
201 |
* - have an audio track |
| 228 |
*/ |
202 |
*/ |
| 229 |
if ( ( libhal_device_get_property_QString(m_halContext, udi, "volume.fsusage") != "crypto" || |
203 |
if ( (libhal_device_get_property_QString(m_halContext, udi, "volume.fsusage") != "filesystem") && |
| 230 |
libhal_device_get_property_QString(m_halContext, udi, "volume.fstype") != "crypto_LUKS" |
204 |
(!hal_device_get_property_bool(m_halContext, udi, "volume.disc.has_audio")) && |
| 231 |
) && |
205 |
(!hal_device_get_property_bool(m_halContext, udi, "volume.disc.is_blank")) ) { |
| 232 |
libhal_device_get_property_QString(m_halContext, udi, "volume.fsusage") != "filesystem" && |
206 |
kdDebug(1219) << "HALBackend::AddDevice : no filesystem, no audio track on device. Skipping." << endl; |
| 233 |
!libhal_device_get_property_bool(m_halContext, udi, "volume.disc.has_audio", NULL) && |
|
|
| 234 |
!libhal_device_get_property_bool(m_halContext, udi, "volume.disc.is_blank", NULL) ) |
| 235 |
return; |
207 |
return; |
|
|
208 |
} |
| 236 |
|
209 |
|
| 237 |
/* Query drive udi */ |
210 |
/* Query drive udi */ |
| 238 |
TQString driveUdi = libhal_device_get_property_QString(m_halContext, udi, "block.storage_device"); |
211 |
TQString driveUdi = libhal_device_get_property_QString(m_halContext, udi, "block.storage_device"); |
| 239 |
if ( driveUdi.isNull() ) // no storage - no fun |
212 |
if ( driveUdi.isNull() ) { // no storage - no fun |
|
|
213 |
kdDebug(1219) << "HALBackend::AddDevice : UDI is null. Skipping." << endl; |
| 240 |
return; |
214 |
return; |
|
|
215 |
} |
| 241 |
|
216 |
|
| 242 |
// if the device is locked do not act upon it |
217 |
// if the device is locked do not act upon it |
| 243 |
if (libhal_device_get_property_bool(m_halContext, driveUdi.ascii(), "info.locked", NULL)) |
218 |
if (hal_device_get_property_bool(m_halContext, driveUdi.ascii(), "info.locked")) |
| 244 |
allowNotification=false; |
219 |
allowNotification=false; |
| 245 |
|
220 |
|
| 246 |
// if the device is locked do not act upon it |
221 |
// if the device is locked do not act upon it |
| 247 |
if (libhal_device_get_property_bool(m_halContext, driveUdi.ascii(), "storage.partition_table_changed", NULL)) |
222 |
if (hal_device_get_property_bool(m_halContext, driveUdi.ascii(), "storage.partition_table_changed")) |
| 248 |
allowNotification=false; |
223 |
allowNotification=false; |
| 249 |
|
224 |
|
| 250 |
/** @todo check exclusion list **/ |
225 |
/** @todo check exclusion list **/ |
| 251 |
|
226 |
|
| 252 |
/* Special handling for clear crypto volumes */ |
|
|
| 253 |
LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, udi); |
| 254 |
if (!halVolume) |
| 255 |
return; |
| 256 |
const char* backingVolumeUdi = libhal_volume_crypto_get_backing_volume_udi(halVolume); |
| 257 |
if ( backingVolumeUdi != NULL ) |
| 258 |
{ |
| 259 |
/* The crypto drive was unlocked and may now be mounted... */ |
| 260 |
kdDebug(1219) << "HALBackend::AddDevice : ClearVolume appeared for " << backingVolumeUdi << endl; |
| 261 |
ResetProperties(backingVolumeUdi, allowNotification); |
| 262 |
libhal_volume_free(halVolume); |
| 263 |
return; |
| 264 |
} |
| 265 |
libhal_volume_free(halVolume); |
| 266 |
|
227 |
|
| 267 |
/* Create medium */ |
228 |
/* Create medium */ |
| 268 |
Medium* medium = new Medium(udi, ""); |
229 |
Medium* medium = new Medium(udi, ""); |
|
Lines 272-289
Link Here
|
| 272 |
{ |
233 |
{ |
| 273 |
// if it's not mountable by user and not by HAL, don't show it at all |
234 |
// if it's not mountable by user and not by HAL, don't show it at all |
| 274 |
if ( ( libhal_device_get_property_QString(m_halContext, udi, "volume.fsusage") == "filesystem" && |
235 |
if ( ( libhal_device_get_property_QString(m_halContext, udi, "volume.fsusage") == "filesystem" && |
| 275 |
!libhal_device_get_property_bool(m_halContext, udi, "volume.is_mounted", NULL ) ) && |
236 |
!hal_device_get_property_bool(m_halContext, udi, "volume.is_mounted") ) && |
| 276 |
( libhal_device_get_property_bool(m_halContext, udi, "volume.ignore", NULL ) ) ) |
237 |
( hal_device_get_property_bool(m_halContext, udi, "volume.ignore") ) ) |
| 277 |
{ |
238 |
{ |
|
|
239 |
kdDebug(1219) << "HALBackend::AddDevice : Device is not mountable. Skipping." << endl; |
| 278 |
delete medium; |
240 |
delete medium; |
| 279 |
return; |
241 |
return; |
| 280 |
} |
242 |
} |
| 281 |
} |
243 |
} |
| 282 |
|
244 |
|
| 283 |
// instert medium into list |
245 |
// insert medium into list |
| 284 |
m_mediaList.addMedium(medium, allowNotification); |
246 |
kdDebug(1219) << "HALBackend::AddDevice : Adding medium into list." << endl; |
|
|
247 |
m_mediaList.addMedium(medium, allowNotification); |
| 285 |
|
248 |
|
| 286 |
// finally check for automount |
249 |
// finally check for automount |
| 287 |
TQMap<TQString,TQString> options = MediaManagerUtils::splitOptions(mountoptions(udi)); |
250 |
TQMap<TQString,TQString> options = MediaManagerUtils::splitOptions(mountoptions(udi)); |
| 288 |
kdDebug() << "automount " << options["automount"] << endl; |
251 |
kdDebug() << "automount " << options["automount"] << endl; |
| 289 |
if (options["automount"] == "true" && allowNotification ) { |
252 |
if (options["automount"] == "true" && allowNotification ) { |
|
Lines 294-307
Link Here
|
| 294 |
|
257 |
|
| 295 |
return; |
258 |
return; |
| 296 |
} |
259 |
} |
|
|
260 |
else |
| 261 |
{ |
| 262 |
kdDebug(1219) << "HALBackend::AddDevice : Device is not a volume." << endl; |
| 263 |
} |
| 297 |
|
264 |
|
| 298 |
/* Floppy & zip drives */ |
265 |
/* Floppy & zip drives */ |
| 299 |
if (libhal_device_query_capability(m_halContext, udi, "storage", NULL)) |
266 |
if (hal_device_query_capability(m_halContext, udi, "storage")) |
| 300 |
if ((libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "floppy") || |
267 |
if ((libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "floppy") || |
| 301 |
(libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "zip") || |
268 |
(libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "zip") || |
| 302 |
(libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "jaz")) |
269 |
(libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "jaz")) |
| 303 |
{ |
270 |
{ |
| 304 |
if (! libhal_device_get_property_bool(m_halContext, udi, "storage.removable.media_available", NULL) ) |
271 |
if (! hal_device_get_property_bool(m_halContext, udi, "storage.removable.media_available") ) |
| 305 |
allowNotification = false; |
272 |
allowNotification = false; |
| 306 |
/* Create medium */ |
273 |
/* Create medium */ |
| 307 |
Medium* medium = new Medium(udi, ""); |
274 |
Medium* medium = new Medium(udi, ""); |
|
Lines 314-324
Link Here
|
| 314 |
} |
281 |
} |
| 315 |
|
282 |
|
| 316 |
/* Camera handled by gphoto2*/ |
283 |
/* Camera handled by gphoto2*/ |
| 317 |
if (libhal_device_query_capability(m_halContext, udi, "camera", NULL) && |
284 |
if (hal_device_query_capability(m_halContext, udi, "camera") && |
| 318 |
((libhal_device_get_property_QString(m_halContext, udi, "camera.access_method")=="ptp") || |
285 |
hal_device_property_exists(m_halContext, udi, "camera.libgphoto2.support") && |
| 319 |
|
286 |
hal_device_get_property_bool(m_halContext, udi, "camera.libgphoto3.support") |
| 320 |
(libhal_device_property_exists(m_halContext, udi, "camera.libgphoto2.support", NULL) && |
|
|
| 321 |
libhal_device_get_property_bool(m_halContext, udi, "camera.libgphoto2.support", NULL))) |
| 322 |
) |
287 |
) |
| 323 |
{ |
288 |
{ |
| 324 |
/* Create medium */ |
289 |
/* Create medium */ |
|
Lines 327-332
Link Here
|
| 327 |
m_mediaList.addMedium(medium, allowNotification); |
292 |
m_mediaList.addMedium(medium, allowNotification); |
| 328 |
return; |
293 |
return; |
| 329 |
} |
294 |
} |
|
|
295 |
kdDebug(1219) << "HALBackend::AddDevice : Device was intentionally not added. Skipping." << endl; |
| 330 |
} |
296 |
} |
| 331 |
|
297 |
|
| 332 |
void HALBackend::RemoveDevice(const char *udi) |
298 |
void HALBackend::RemoveDevice(const char *udi) |
|
Lines 348-354
Link Here
|
| 348 |
return; |
314 |
return; |
| 349 |
bool allowNotification = false; |
315 |
bool allowNotification = false; |
| 350 |
if (strcmp(key, "storage.removable.media_available") == 0) |
316 |
if (strcmp(key, "storage.removable.media_available") == 0) |
| 351 |
allowNotification = libhal_device_get_property_bool(m_halContext, udi, key, NULL); |
317 |
allowNotification = hal_device_get_property_bool(m_halContext, udi, key); |
| 352 |
ResetProperties(mediumUdi, allowNotification); |
318 |
ResetProperties(mediumUdi, allowNotification); |
| 353 |
} |
319 |
} |
| 354 |
|
320 |
|
|
Lines 421-439
Link Here
|
| 421 |
return medium->id().ascii(); |
387 |
return medium->id().ascii(); |
| 422 |
|
388 |
|
| 423 |
/* Hard part : this is a volume whose drive is registered */ |
389 |
/* Hard part : this is a volume whose drive is registered */ |
| 424 |
if (libhal_device_property_exists(m_halContext, udi, "info.capabilities", NULL)) |
390 |
if (hal_device_property_exists(m_halContext, udi, "info.capabilities")) |
| 425 |
if (libhal_device_query_capability(m_halContext, udi, "volume", NULL)) |
391 |
if (hal_device_query_capability(m_halContext, udi, "volume")) |
| 426 |
{ |
392 |
{ |
| 427 |
/* check if this belongs to an encrypted volume */ |
393 |
/* check if this belongs to an encrypted volume */ |
| 428 |
LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, udi); |
394 |
HalVolume* halVolume = hal_volume_from_udi(m_halContext, udi); |
| 429 |
if (!halVolume) return NULL; |
395 |
if (!halVolume) return NULL; |
| 430 |
const char* backingUdi = libhal_volume_crypto_get_backing_volume_udi(halVolume); |
396 |
hal_volume_free(halVolume); |
| 431 |
if (backingUdi != NULL) { |
|
|
| 432 |
const char* result = findMediumUdiFromUdi(backingUdi); |
| 433 |
libhal_volume_free(halVolume); |
| 434 |
return result; |
| 435 |
} |
| 436 |
libhal_volume_free(halVolume); |
| 437 |
|
397 |
|
| 438 |
/* this is a volume whose drive is registered */ |
398 |
/* this is a volume whose drive is registered */ |
| 439 |
TQString driveUdi = libhal_device_get_property_QString(m_halContext, udi, "block.storage_device"); |
399 |
TQString driveUdi = libhal_device_get_property_QString(m_halContext, udi, "block.storage_device"); |
|
Lines 462-472
Link Here
|
| 462 |
|
422 |
|
| 463 |
Medium* m = new Medium(mediumUdi, ""); |
423 |
Medium* m = new Medium(mediumUdi, ""); |
| 464 |
|
424 |
|
| 465 |
if (libhal_device_query_capability(m_halContext, mediumUdi, "volume", NULL)) |
425 |
if (hal_device_query_capability(m_halContext, mediumUdi, "volume")) |
| 466 |
setVolumeProperties(m); |
426 |
setVolumeProperties(m); |
| 467 |
if (libhal_device_query_capability(m_halContext, mediumUdi, "storage", NULL)) |
427 |
if (hal_device_query_capability(m_halContext, mediumUdi, "storage")) |
| 468 |
setFloppyProperties(m); |
428 |
setFloppyProperties(m); |
| 469 |
if (libhal_device_query_capability(m_halContext, mediumUdi, "camera", NULL)) |
429 |
if (hal_device_query_capability(m_halContext, mediumUdi, "camera")) |
| 470 |
setCameraProperties(m); |
430 |
setCameraProperties(m); |
| 471 |
|
431 |
|
| 472 |
m_mediaList.changeMediumState(*m, allowNotification); |
432 |
m_mediaList.changeMediumState(*m, allowNotification); |
|
Lines 480-563
Link Here
|
| 480 |
|
440 |
|
| 481 |
const char* udi = medium->id().ascii(); |
441 |
const char* udi = medium->id().ascii(); |
| 482 |
/* Check if the device still exists */ |
442 |
/* Check if the device still exists */ |
| 483 |
if (!libhal_device_exists(m_halContext, udi, NULL)) |
443 |
if (!hal_device_exists(m_halContext, udi)) |
| 484 |
return; |
444 |
return; |
| 485 |
|
445 |
|
| 486 |
/* Get device information from libhal-storage */ |
446 |
/* Get device information from libhal-storage */ |
| 487 |
LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, udi); |
447 |
HalVolume* halVolume = hal_volume_from_udi(m_halContext, udi); |
| 488 |
if (!halVolume) |
448 |
if (!halVolume) |
| 489 |
return; |
449 |
return; |
| 490 |
TQString driveUdi = libhal_volume_get_storage_device_udi(halVolume); |
450 |
TQString driveUdi = hal_volume_get_storage_device_udi(halVolume); |
| 491 |
LibHalDrive* halDrive = 0; |
451 |
HalDrive* halDrive = 0; |
| 492 |
if ( !driveUdi.isNull() ) |
452 |
if ( !driveUdi.isNull() ) |
| 493 |
halDrive = libhal_drive_from_udi(m_halContext, driveUdi.ascii()); |
453 |
halDrive = hal_drive_from_udi(m_halContext, driveUdi.ascii()); |
| 494 |
if (!halDrive) { |
454 |
if (!halDrive) { |
| 495 |
// at times HAL sends an UnmountForced event before the device is removed |
455 |
// at times HAL sends an UnmountForced event before the device is removed |
| 496 |
libhal_volume_free(halVolume); |
456 |
hal_volume_free(halVolume); |
| 497 |
return; |
457 |
return; |
| 498 |
} |
458 |
} |
| 499 |
|
459 |
|
| 500 |
medium->setName( |
460 |
medium->setName( |
| 501 |
generateName(libhal_volume_get_device_file(halVolume)) ); |
461 |
generateName(hal_volume_get_device_file(halVolume)) ); |
| 502 |
|
|
|
| 503 |
LibHalVolume* halClearVolume = NULL; |
| 504 |
if ( libhal_device_get_property_QString(m_halContext, udi, "volume.fsusage") == "crypto" ) |
| 505 |
{ |
| 506 |
kdDebug(1219) << "HALBackend::setVolumeProperties : crypto volume" << endl; |
| 507 |
|
462 |
|
| 508 |
medium->setEncrypted(true); |
463 |
kdDebug(1219) << "HALBackend::setVolumeProperties : normal volume" << endl; |
| 509 |
char* clearUdi = libhal_volume_crypto_get_clear_volume_udi(m_halContext, halVolume); |
464 |
medium->mountableState( |
| 510 |
TQString clearUdiString; |
465 |
hal_volume_get_device_file(halVolume), /* Device node */ |
| 511 |
if (clearUdi != NULL) { |
466 |
hal_volume_get_mount_point(halVolume), /* Mount point */ |
| 512 |
kdDebug(1219) << "HALBackend::setVolumeProperties : crypto clear volume avail - " << clearUdi << endl; |
467 |
hal_volume_get_fstype(halVolume), /* Filesystem type */ |
| 513 |
halClearVolume = libhal_volume_from_udi(m_halContext, clearUdi); |
468 |
hal_volume_is_mounted(halVolume) ); /* Mounted ? */ |
| 514 |
// ignore if halClearVolume is NULL -> just not decrypted in this case |
|
|
| 515 |
clearUdiString = clearUdi; |
| 516 |
libhal_free_string(clearUdi); |
| 517 |
} |
| 518 |
|
| 519 |
if (halClearVolume) |
| 520 |
medium->mountableState( |
| 521 |
libhal_volume_get_device_file(halVolume), /* Device node */ |
| 522 |
clearUdiString, |
| 523 |
libhal_volume_get_mount_point(halClearVolume), /* Mount point */ |
| 524 |
libhal_volume_get_fstype(halClearVolume), /* Filesystem type */ |
| 525 |
libhal_volume_is_mounted(halClearVolume) ); /* Mounted ? */ |
| 526 |
else |
| 527 |
medium->mountableState( |
| 528 |
libhal_volume_get_device_file(halVolume), /* Device node */ |
| 529 |
TQString::null, |
| 530 |
TQString::null, /* Mount point */ |
| 531 |
TQString::null, /* Filesystem type */ |
| 532 |
false ); /* Mounted ? */ |
| 533 |
} |
| 534 |
else |
| 535 |
{ |
| 536 |
kdDebug(1219) << "HALBackend::setVolumeProperties : normal volume" << endl; |
| 537 |
medium->mountableState( |
| 538 |
libhal_volume_get_device_file(halVolume), /* Device node */ |
| 539 |
libhal_volume_get_mount_point(halVolume), /* Mount point */ |
| 540 |
libhal_volume_get_fstype(halVolume), /* Filesystem type */ |
| 541 |
libhal_volume_is_mounted(halVolume) ); /* Mounted ? */ |
| 542 |
} |
| 543 |
|
469 |
|
| 544 |
|
470 |
|
| 545 |
char* name = libhal_volume_policy_compute_display_name(halDrive, halVolume, m_halStoragePolicy); |
471 |
char* name = hal_volume_policy_compute_display_name(halDrive, halVolume, m_halStoragePolicy); |
| 546 |
TQString volume_name = TQString::fromUtf8(name); |
472 |
TQString volume_name = TQString::fromUtf8(name); |
| 547 |
TQString media_name = volume_name; |
473 |
TQString media_name = volume_name; |
| 548 |
medium->setLabel(media_name); |
474 |
medium->setLabel(media_name); |
| 549 |
free(name); |
475 |
free(name); |
| 550 |
|
476 |
|
| 551 |
TQString mimeType; |
477 |
TQString mimeType; |
| 552 |
if (libhal_volume_is_disc(halVolume)) |
478 |
if (hal_volume_is_disc(halVolume)) |
| 553 |
{ |
479 |
{ |
| 554 |
mimeType = "media/cdrom" + MOUNT_SUFFIX; |
480 |
mimeType = "media/cdrom" + MOUNT_SUFFIX; |
| 555 |
|
481 |
|
| 556 |
LibHalVolumeDiscType discType = libhal_volume_get_disc_type(halVolume); |
482 |
HalVolumeDiscType discType = hal_volume_get_disc_type(halVolume); |
| 557 |
if ((discType == LIBHAL_VOLUME_DISC_TYPE_CDROM) || |
483 |
if ((discType == HAL_VOLUME_DISC_TYPE_CDROM) || |
| 558 |
(discType == LIBHAL_VOLUME_DISC_TYPE_CDR) || |
484 |
(discType == HAL_VOLUME_DISC_TYPE_CDR) || |
| 559 |
(discType == LIBHAL_VOLUME_DISC_TYPE_CDRW)) |
485 |
(discType == HAL_VOLUME_DISC_TYPE_CDRW)) |
| 560 |
if (libhal_volume_disc_is_blank(halVolume)) |
486 |
if (hal_volume_disc_is_blank(halVolume)) |
| 561 |
{ |
487 |
{ |
| 562 |
mimeType = "media/blankcd"; |
488 |
mimeType = "media/blankcd"; |
| 563 |
medium->unmountableState(""); |
489 |
medium->unmountableState(""); |
|
Lines 565-574
Link Here
|
| 565 |
else |
491 |
else |
| 566 |
mimeType = "media/cdwriter" + MOUNT_SUFFIX; |
492 |
mimeType = "media/cdwriter" + MOUNT_SUFFIX; |
| 567 |
|
493 |
|
| 568 |
if ((discType == LIBHAL_VOLUME_DISC_TYPE_DVDROM) || (discType == LIBHAL_VOLUME_DISC_TYPE_DVDRAM) || |
494 |
if ((discType == HAL_VOLUME_DISC_TYPE_DVDROM) || (discType == HAL_VOLUME_DISC_TYPE_DVDRAM) || |
| 569 |
(discType == LIBHAL_VOLUME_DISC_TYPE_DVDR) || (discType == LIBHAL_VOLUME_DISC_TYPE_DVDRW) || |
495 |
(discType == HAL_VOLUME_DISC_TYPE_DVDR) || (discType == HAL_VOLUME_DISC_TYPE_DVDRW) || |
| 570 |
(discType == LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR) || (discType == LIBHAL_VOLUME_DISC_TYPE_DVDPLUSRW) ) |
496 |
(discType == HAL_VOLUME_DISC_TYPE_DVDPLUSR) || (discType == HAL_VOLUME_DISC_TYPE_DVDPLUSRW) ) |
| 571 |
if (libhal_volume_disc_is_blank(halVolume)) |
497 |
if (hal_volume_disc_is_blank(halVolume)) |
| 572 |
{ |
498 |
{ |
| 573 |
mimeType = "media/blankdvd"; |
499 |
mimeType = "media/blankdvd"; |
| 574 |
medium->unmountableState(""); |
500 |
medium->unmountableState(""); |
|
Lines 576-591
Link Here
|
| 576 |
else |
502 |
else |
| 577 |
mimeType = "media/dvd" + MOUNT_SUFFIX; |
503 |
mimeType = "media/dvd" + MOUNT_SUFFIX; |
| 578 |
|
504 |
|
| 579 |
if (libhal_volume_disc_has_audio(halVolume) && !libhal_volume_disc_has_data(halVolume)) |
505 |
if (hal_volume_disc_has_audio(halVolume) && !hal_volume_disc_has_data(halVolume)) |
| 580 |
{ |
506 |
{ |
| 581 |
mimeType = "media/audiocd"; |
507 |
mimeType = "media/audiocd"; |
| 582 |
medium->unmountableState( "audiocd:/?device=" + TQString(libhal_volume_get_device_file(halVolume)) ); |
508 |
medium->unmountableState( "audiocd:/?device=" + TQString(hal_volume_get_device_file(halVolume)) ); |
| 583 |
} |
509 |
} |
| 584 |
|
510 |
|
| 585 |
medium->setIconName(TQString::null); |
511 |
medium->setIconName(TQString::null); |
| 586 |
|
512 |
|
| 587 |
/* check if the disc id a vcd or a video dvd */ |
513 |
/* check if the disc id a vcd or a video dvd */ |
| 588 |
DiscType type = LinuxCDPolling::identifyDiscType(libhal_volume_get_device_file(halVolume)); |
514 |
DiscType type = LinuxCDPolling::identifyDiscType(hal_volume_get_device_file(halVolume)); |
| 589 |
switch (type) |
515 |
switch (type) |
| 590 |
{ |
516 |
{ |
| 591 |
case DiscType::VCD: |
517 |
case DiscType::VCD: |
|
Lines 603-626
Link Here
|
| 603 |
{ |
529 |
{ |
| 604 |
mimeType = "media/hdd" + MOUNT_SUFFIX; |
530 |
mimeType = "media/hdd" + MOUNT_SUFFIX; |
| 605 |
medium->setIconName(TQString::null); // reset icon |
531 |
medium->setIconName(TQString::null); // reset icon |
| 606 |
if (libhal_drive_is_hotpluggable(halDrive)) |
532 |
if (hal_drive_is_hotpluggable(halDrive)) |
| 607 |
{ |
533 |
{ |
| 608 |
mimeType = "media/removable" + MOUNT_SUFFIX; |
534 |
mimeType = "media/removable" + MOUNT_SUFFIX; |
| 609 |
medium->needMounting(); |
535 |
medium->needMounting(); |
| 610 |
switch (libhal_drive_get_type(halDrive)) { |
536 |
switch (hal_drive_get_type(halDrive)) { |
| 611 |
case LIBHAL_DRIVE_TYPE_COMPACT_FLASH: |
537 |
case HAL_DRIVE_TYPE_COMPACT_FLASH: |
| 612 |
medium->setIconName("compact_flash" + MOUNT_ICON_SUFFIX); |
538 |
medium->setIconName("compact_flash" + MOUNT_ICON_SUFFIX); |
| 613 |
break; |
539 |
break; |
| 614 |
case LIBHAL_DRIVE_TYPE_MEMORY_STICK: |
540 |
case HAL_DRIVE_TYPE_MEMORY_STICK: |
| 615 |
medium->setIconName("memory_stick" + MOUNT_ICON_SUFFIX); |
541 |
medium->setIconName("memory_stick" + MOUNT_ICON_SUFFIX); |
| 616 |
break; |
542 |
break; |
| 617 |
case LIBHAL_DRIVE_TYPE_SMART_MEDIA: |
543 |
case HAL_DRIVE_TYPE_SMART_MEDIA: |
| 618 |
medium->setIconName("smart_media" + MOUNT_ICON_SUFFIX); |
544 |
medium->setIconName("smart_media" + MOUNT_ICON_SUFFIX); |
| 619 |
break; |
545 |
break; |
| 620 |
case LIBHAL_DRIVE_TYPE_SD_MMC: |
546 |
case HAL_DRIVE_TYPE_SD_MMC: |
| 621 |
medium->setIconName("sd_mmc" + MOUNT_ICON_SUFFIX); |
547 |
medium->setIconName("sd_mmc" + MOUNT_ICON_SUFFIX); |
| 622 |
break; |
548 |
break; |
| 623 |
case LIBHAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER: |
549 |
case HAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER: |
| 624 |
{ |
550 |
{ |
| 625 |
medium->setIconName("ipod" + MOUNT_ICON_SUFFIX); |
551 |
medium->setIconName("ipod" + MOUNT_ICON_SUFFIX); |
| 626 |
|
552 |
|
|
Lines 628-652
Link Here
|
| 628 |
KProtocolInfo::isKnownProtocol( TQString("ipod") ) ) |
554 |
KProtocolInfo::isKnownProtocol( TQString("ipod") ) ) |
| 629 |
{ |
555 |
{ |
| 630 |
medium->unmountableState( "ipod:/" ); |
556 |
medium->unmountableState( "ipod:/" ); |
| 631 |
medium->mountableState( libhal_volume_is_mounted(halVolume) ); |
557 |
medium->mountableState( hal_volume_is_mounted(halVolume) ); |
| 632 |
} |
558 |
} |
| 633 |
break; |
559 |
break; |
| 634 |
} |
560 |
} |
| 635 |
case LIBHAL_DRIVE_TYPE_CAMERA: |
561 |
case HAL_DRIVE_TYPE_CAMERA: |
| 636 |
{ |
562 |
{ |
| 637 |
mimeType = "media/camera" + MOUNT_SUFFIX; |
563 |
mimeType = "media/camera" + MOUNT_SUFFIX; |
| 638 |
const char *physdev = libhal_drive_get_physical_device_udi(halDrive); |
564 |
const char *physdev = hal_drive_get_physical_device_udi(halDrive); |
| 639 |
// get model from camera |
565 |
// get model from camera |
| 640 |
if (physdev && libhal_device_query_capability(m_halContext, physdev, "camera", NULL)) |
566 |
if (physdev && hal_device_query_capability(m_halContext, physdev, "camera")) |
| 641 |
{ |
567 |
{ |
| 642 |
if (libhal_device_property_exists(m_halContext, physdev, "usb_device.product", NULL)) |
568 |
if (hal_device_property_exists(m_halContext, physdev, "usb_device.product")) |
| 643 |
medium->setLabel(libhal_device_get_property_QString(m_halContext, physdev, "usb_device.product")); |
569 |
medium->setLabel(libhal_device_get_property_QString(m_halContext, physdev, "usb_device.product")); |
| 644 |
else if (libhal_device_property_exists(m_halContext, physdev, "usb.product", NULL)) |
570 |
else if (hal_device_property_exists(m_halContext, physdev, "usb.product")) |
| 645 |
medium->setLabel(libhal_device_get_property_QString(m_halContext, physdev, "usb.product")); |
571 |
medium->setLabel(libhal_device_get_property_QString(m_halContext, physdev, "usb.product")); |
| 646 |
} |
572 |
} |
| 647 |
break; |
573 |
break; |
| 648 |
} |
574 |
} |
| 649 |
case LIBHAL_DRIVE_TYPE_TAPE: |
575 |
case HAL_DRIVE_TYPE_TAPE: |
| 650 |
medium->setIconName(TQString::null); //FIXME need icon |
576 |
medium->setIconName(TQString::null); //FIXME need icon |
| 651 |
break; |
577 |
break; |
| 652 |
default: |
578 |
default: |
|
Lines 661-668
Link Here
|
| 661 |
} |
587 |
} |
| 662 |
medium->setMimeType(mimeType); |
588 |
medium->setMimeType(mimeType); |
| 663 |
|
589 |
|
| 664 |
libhal_drive_free(halDrive); |
590 |
hal_drive_free(halDrive); |
| 665 |
libhal_volume_free(halVolume); |
591 |
hal_volume_free(halVolume); |
| 666 |
} |
592 |
} |
| 667 |
|
593 |
|
| 668 |
bool HALBackend::setFstabProperties( Medium *medium ) |
594 |
bool HALBackend::setFstabProperties( Medium *medium ) |
|
Lines 713-722
Link Here
|
| 713 |
|
639 |
|
| 714 |
const char* udi = medium->id().ascii(); |
640 |
const char* udi = medium->id().ascii(); |
| 715 |
/* Check if the device still exists */ |
641 |
/* Check if the device still exists */ |
| 716 |
if (!libhal_device_exists(m_halContext, udi, NULL)) |
642 |
if (!hal_device_exists(m_halContext, udi)) |
| 717 |
return false; |
643 |
return false; |
| 718 |
|
644 |
|
| 719 |
LibHalDrive* halDrive = libhal_drive_from_udi(m_halContext, udi); |
645 |
HalDrive* halDrive = hal_drive_from_udi(m_halContext, udi); |
| 720 |
if (!halDrive) |
646 |
if (!halDrive) |
| 721 |
return false; |
647 |
return false; |
| 722 |
|
648 |
|
|
Lines 724-744
Link Here
|
| 724 |
|
650 |
|
| 725 |
if (drive_type == "zip") { |
651 |
if (drive_type == "zip") { |
| 726 |
int numVolumes; |
652 |
int numVolumes; |
| 727 |
char** volumes = libhal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes); |
653 |
char** volumes = hal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes); |
| 728 |
libhal_free_string_array(volumes); |
654 |
hal_free_string_array(volumes); |
| 729 |
kdDebug(1219) << " found " << numVolumes << " volumes" << endl; |
655 |
kdDebug(1219) << " found " << numVolumes << " volumes" << endl; |
| 730 |
if (numVolumes) |
656 |
if (numVolumes) |
| 731 |
{ |
657 |
{ |
| 732 |
libhal_drive_free(halDrive); |
658 |
hal_drive_free(halDrive); |
| 733 |
return false; |
659 |
return false; |
| 734 |
} |
660 |
} |
| 735 |
} |
661 |
} |
| 736 |
|
662 |
|
| 737 |
medium->setName( generateName(libhal_drive_get_device_file(halDrive)) ); |
663 |
medium->setName( generateName(hal_drive_get_device_file(halDrive)) ); |
| 738 |
medium->setLabel(i18n("Unknown Drive")); |
664 |
medium->setLabel(i18n("Unknown Drive")); |
| 739 |
|
665 |
|
| 740 |
// HAL hates floppies - so we have to do it twice ;( |
666 |
// HAL hates floppies - so we have to do it twice ;( |
| 741 |
medium->mountableState(libhal_drive_get_device_file(halDrive), TQString::null, TQString::null, false); |
667 |
medium->mountableState(hal_drive_get_device_file(halDrive), TQString::null, TQString::null, false); |
| 742 |
setFloppyMountState(medium); |
668 |
setFloppyMountState(medium); |
| 743 |
|
669 |
|
| 744 |
if (drive_type == "floppy") |
670 |
if (drive_type == "floppy") |
|
Lines 762-768
Link Here
|
| 762 |
|
688 |
|
| 763 |
medium->setIconName(TQString::null); |
689 |
medium->setIconName(TQString::null); |
| 764 |
|
690 |
|
| 765 |
libhal_drive_free(halDrive); |
691 |
hal_drive_free(halDrive); |
| 766 |
|
692 |
|
| 767 |
return true; |
693 |
return true; |
| 768 |
} |
694 |
} |
|
Lines 796-802
Link Here
|
| 796 |
|
722 |
|
| 797 |
const char* udi = medium->id().ascii(); |
723 |
const char* udi = medium->id().ascii(); |
| 798 |
/* Check if the device still exists */ |
724 |
/* Check if the device still exists */ |
| 799 |
if (!libhal_device_exists(m_halContext, udi, NULL)) |
725 |
if (!hal_device_exists(m_halContext, udi)) |
| 800 |
return; |
726 |
return; |
| 801 |
|
727 |
|
| 802 |
/** @todo find name */ |
728 |
/** @todo find name */ |
|
Lines 804-828
Link Here
|
| 804 |
|
730 |
|
| 805 |
TQString device = "camera:/"; |
731 |
TQString device = "camera:/"; |
| 806 |
|
732 |
|
| 807 |
char *cam = libhal_device_get_property_string(m_halContext, udi, "camera.libgphoto2.name", NULL); |
733 |
char *cam = hal_device_get_property_string(m_halContext, udi, "camera.libgphoto2.name"); |
| 808 |
DBusError error; |
734 |
DBusError error; |
| 809 |
dbus_error_init(&error); |
735 |
dbus_error_init(&error); |
| 810 |
if (cam && |
736 |
if (cam && |
| 811 |
libhal_device_property_exists(m_halContext, udi, "usb.linux.device_number", NULL) && |
737 |
hal_device_property_exists(m_halContext, udi, "usb.linux.device_number") && |
| 812 |
libhal_device_property_exists(m_halContext, udi, "usb.bus_number", NULL)) |
738 |
hal_device_property_exists(m_halContext, udi, "usb.bus_number")) |
| 813 |
device.sprintf("camera://%s@[usb:%03d,%03d]/", cam, |
739 |
device.sprintf("camera://%s@[usb:%03d,%03d]/", cam, |
| 814 |
libhal_device_get_property_int(m_halContext, udi, "usb.bus_number", &error), |
740 |
hal_device_get_property_int(m_halContext, udi, "usb.bus_number"), |
| 815 |
libhal_device_get_property_int(m_halContext, udi, "usb.linux.device_number", &error)); |
741 |
hal_device_get_property_int(m_halContext, udi, "usb.linux.device_number")); |
| 816 |
|
742 |
|
| 817 |
libhal_free_string(cam); |
743 |
hal_free_string(cam); |
| 818 |
|
744 |
|
| 819 |
/** @todo find the rest of this URL */ |
745 |
/** @todo find the rest of this URL */ |
| 820 |
medium->unmountableState(device); |
746 |
medium->unmountableState(device); |
| 821 |
medium->setMimeType("media/gphoto2camera"); |
747 |
medium->setMimeType("media/gphoto2camera"); |
| 822 |
medium->setIconName(TQString::null); |
748 |
medium->setIconName(TQString::null); |
| 823 |
if (libhal_device_property_exists(m_halContext, udi, "usb_device.product", NULL)) |
749 |
if (hal_device_property_exists(m_halContext, udi, "usb_device.product")) |
| 824 |
medium->setLabel(libhal_device_get_property_QString(m_halContext, udi, "usb_device.product")); |
750 |
medium->setLabel(libhal_device_get_property_QString(m_halContext, udi, "usb_device.product")); |
| 825 |
else if (libhal_device_property_exists(m_halContext, udi, "usb.product", NULL)) |
751 |
else if (hal_device_property_exists(m_halContext, udi, "usb.product")) |
| 826 |
medium->setLabel(libhal_device_get_property_QString(m_halContext, udi, "usb.product")); |
752 |
medium->setLabel(libhal_device_get_property_QString(m_halContext, udi, "usb.product")); |
| 827 |
else |
753 |
else |
| 828 |
medium->setLabel(i18n("Camera")); |
754 |
medium->setLabel(i18n("Camera")); |
|
Lines 837-842
Link Here
|
| 837 |
** HAL CALL-BACKS ** |
763 |
** HAL CALL-BACKS ** |
| 838 |
******************************************/ |
764 |
******************************************/ |
| 839 |
|
765 |
|
|
|
766 |
void HALBackend::hal_main_loop_integration(LibHalContext *ctx, |
| 767 |
DBusConnection *dbus_connection) |
| 768 |
{ |
| 769 |
kdDebug(1219) << "HALBackend::hal_main_loop_integration" << endl; |
| 770 |
Q_UNUSED(ctx); |
| 771 |
s_HALBackend->MainLoopIntegration(dbus_connection); |
| 772 |
} |
| 773 |
|
| 840 |
void HALBackend::hal_device_added(LibHalContext *ctx, const char *udi) |
774 |
void HALBackend::hal_device_added(LibHalContext *ctx, const char *udi) |
| 841 |
{ |
775 |
{ |
| 842 |
kdDebug(1219) << "HALBackend::hal_device_added " << udi << endl; |
776 |
kdDebug(1219) << "HALBackend::hal_device_added " << udi << endl; |
|
Lines 863-869
Link Here
|
| 863 |
|
797 |
|
| 864 |
void HALBackend::hal_device_condition(LibHalContext *ctx, const char *udi, |
798 |
void HALBackend::hal_device_condition(LibHalContext *ctx, const char *udi, |
| 865 |
const char *condition_name, |
799 |
const char *condition_name, |
| 866 |
const char* message |
800 |
DBusMessage* message |
| 867 |
) |
801 |
) |
| 868 |
{ |
802 |
{ |
| 869 |
kdDebug(1219) << "HALBackend::hal_device_condition " << udi << " -- " << condition_name << endl; |
803 |
kdDebug(1219) << "HALBackend::hal_device_condition " << udi << " -- " << condition_name << endl; |
|
Lines 875-898
Link Here
|
| 875 |
TQStringList HALBackend::getHALmountoptions(TQString udi) |
809 |
TQStringList HALBackend::getHALmountoptions(TQString udi) |
| 876 |
{ |
810 |
{ |
| 877 |
const char* _ppt_string; |
811 |
const char* _ppt_string; |
| 878 |
LibHalVolume* volume; |
812 |
HalVolume* volume; |
| 879 |
LibHalDrive* drive; |
813 |
HalDrive* drive; |
| 880 |
|
814 |
|
| 881 |
TQString _ppt_TQString; |
815 |
TQString _ppt_TQString; |
| 882 |
|
816 |
|
| 883 |
volume = libhal_volume_from_udi( m_halContext, udi.latin1() ); |
817 |
volume = hal_volume_from_udi( m_halContext, udi.latin1() ); |
| 884 |
if( volume ) |
818 |
if( volume ) |
| 885 |
drive = libhal_drive_from_udi( m_halContext, libhal_volume_get_storage_device_udi( volume ) ); |
819 |
drive = hal_drive_from_udi( m_halContext, hal_volume_get_storage_device_udi( volume ) ); |
| 886 |
else |
820 |
else |
| 887 |
drive = libhal_drive_from_udi( m_halContext, udi.latin1() ); |
821 |
drive = hal_drive_from_udi( m_halContext, udi.latin1() ); |
| 888 |
|
822 |
|
| 889 |
if( !drive ) |
823 |
if( !drive ) |
| 890 |
return TQString::null; |
824 |
return TQString::null; |
| 891 |
|
825 |
|
| 892 |
if( volume ) |
826 |
if( volume ) |
| 893 |
_ppt_string = libhal_volume_policy_get_mount_options ( drive, volume, NULL ); |
827 |
_ppt_string = hal_volume_policy_get_mount_options ( drive, volume, NULL ); |
| 894 |
else |
828 |
else |
| 895 |
_ppt_string = libhal_drive_policy_get_mount_options ( drive, NULL ); |
829 |
_ppt_string = hal_drive_policy_get_mount_options ( drive, NULL ); |
| 896 |
|
830 |
|
| 897 |
_ppt_TQString = TQString(_ppt_string ? _ppt_string : ""); |
831 |
_ppt_TQString = TQString(_ppt_string ? _ppt_string : ""); |
| 898 |
|
832 |
|
|
Lines 908-931
Link Here
|
| 908 |
return TQStringList(); // not handled by HAL - fstab entry |
842 |
return TQStringList(); // not handled by HAL - fstab entry |
| 909 |
|
843 |
|
| 910 |
TQString volume_udi = name; |
844 |
TQString volume_udi = name; |
| 911 |
if (medium->isEncrypted()) { |
|
|
| 912 |
// see if we have a clear volume |
| 913 |
LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, medium->id().latin1()); |
| 914 |
if (halVolume) { |
| 915 |
char* clearUdi = libhal_volume_crypto_get_clear_volume_udi(m_halContext, halVolume); |
| 916 |
if (clearUdi != NULL) { |
| 917 |
volume_udi = clearUdi; |
| 918 |
libhal_free_string(clearUdi); |
| 919 |
} else { |
| 920 |
// if not decrypted yet then no mountoptions |
| 921 |
return TQStringList(); |
| 922 |
} |
| 923 |
libhal_volume_free(halVolume); |
| 924 |
} else { |
| 925 |
// strange... |
| 926 |
return TQStringList(); |
| 927 |
} |
| 928 |
} |
| 929 |
|
845 |
|
| 930 |
KConfig config("mediamanagerrc"); |
846 |
KConfig config("mediamanagerrc"); |
| 931 |
|
847 |
|
|
Lines 939-955
Link Here
|
| 939 |
if (use_defaults) |
855 |
if (use_defaults) |
| 940 |
config.setGroup("DefaultOptions"); |
856 |
config.setGroup("DefaultOptions"); |
| 941 |
|
857 |
|
| 942 |
char ** array = libhal_device_get_property_strlist(m_halContext, volume_udi.latin1(), "volume.mount.valid_options", NULL); |
|
|
| 943 |
TQMap<TQString,bool> valids; |
858 |
TQMap<TQString,bool> valids; |
| 944 |
|
|
|
| 945 |
for (int index = 0; array && array[index]; ++index) { |
| 946 |
TQString t = array[index]; |
| 947 |
if (t.endsWith("=")) |
| 948 |
t = t.left(t.length() - 1); |
| 949 |
valids[t] = true; |
| 950 |
kdDebug() << "valid " << t << endl; |
| 951 |
} |
| 952 |
libhal_free_string_array(array); |
| 953 |
TQStringList result; |
859 |
TQStringList result; |
| 954 |
TQString tmp; |
860 |
TQString tmp; |
| 955 |
|
861 |
|
|
Lines 963-970
Link Here
|
| 963 |
|
869 |
|
| 964 |
bool removable = false; |
870 |
bool removable = false; |
| 965 |
if ( !drive_udi.isNull() ) |
871 |
if ( !drive_udi.isNull() ) |
| 966 |
removable = libhal_device_get_property_bool(m_halContext, drive_udi.latin1(), "storage.removable", NULL) |
872 |
removable = hal_device_get_property_bool(m_halContext, drive_udi.latin1(), "storage.removable") |
| 967 |
|| libhal_device_get_property_bool(m_halContext, drive_udi.latin1(), "storage.hotpluggable", NULL); |
873 |
|| hal_device_get_property_bool(m_halContext, drive_udi.latin1(), "storage.hotpluggable"); |
| 968 |
|
874 |
|
| 969 |
bool value; |
875 |
bool value; |
| 970 |
if (use_defaults) |
876 |
if (use_defaults) |
|
Lines 979-989
Link Here
|
| 979 |
config.setGroup(current_group); |
885 |
config.setGroup(current_group); |
| 980 |
} |
886 |
} |
| 981 |
|
887 |
|
| 982 |
if (libhal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.is_blank", NULL) |
888 |
if (hal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.is_blank") |
| 983 |
|| libhal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.is_vcd", NULL) |
889 |
|| hal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.is_vcd") |
| 984 |
|| libhal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.is_svcd", NULL) |
890 |
|| hal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.is_svcd") |
| 985 |
|| libhal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.is_videodvd", NULL) |
891 |
|| hal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.is_videodvd") |
| 986 |
|| libhal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.has_audio", NULL)) |
892 |
|| hal_device_get_property_bool(m_halContext, volume_udi.latin1(), "volume.disc.has_audio")) |
| 987 |
value = false; |
893 |
value = false; |
| 988 |
|
894 |
|
| 989 |
result << TQString("automount=%1").arg(value ? "true" : "false"); |
895 |
result << TQString("automount=%1").arg(value ? "true" : "false"); |
|
Lines 1540-1568
Link Here
|
| 1540 |
} |
1446 |
} |
| 1541 |
options[noptions] = NULL; |
1447 |
options[noptions] = NULL; |
| 1542 |
|
1448 |
|
| 1543 |
TQString qerror = i18n("Cannot mount encrypted drives!"); |
|
|
| 1544 |
|
| 1545 |
if (!medium->isEncrypted()) { |
| 1546 |
// normal volume |
| 1547 |
qerror = mount_priv(medium->id().latin1(), mount_point.utf8(), options, noptions, dbus_connection); |
| 1548 |
} else { |
| 1549 |
// see if we have a clear volume |
| 1550 |
LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, medium->id().latin1()); |
| 1551 |
if (halVolume) { |
| 1552 |
char* clearUdi = libhal_volume_crypto_get_clear_volume_udi(m_halContext, halVolume); |
| 1553 |
if (clearUdi != NULL) { |
| 1554 |
qerror = mount_priv(clearUdi, mount_point.utf8(), options, noptions, dbus_connection); |
| 1555 |
libhal_free_string(clearUdi); |
| 1556 |
} |
| 1557 |
libhal_volume_free(halVolume); |
| 1558 |
} |
| 1559 |
} |
| 1560 |
|
| 1561 |
if (!qerror.isEmpty()) { |
| 1562 |
kdError() << "mounting " << medium->id() << " returned " << qerror << endl; |
| 1563 |
return qerror; |
| 1564 |
} |
| 1565 |
|
| 1566 |
medium->setHalMounted(true); |
1449 |
medium->setHalMounted(true); |
| 1567 |
ResetProperties(medium->id().latin1()); |
1450 |
ResetProperties(medium->id().latin1()); |
| 1568 |
|
1451 |
|
|
Lines 1584-1594
Link Here
|
| 1584 |
if (!medium) |
1467 |
if (!medium) |
| 1585 |
{ // now we get fancy: if the udi is no volume, it _might_ be a device with only one |
1468 |
{ // now we get fancy: if the udi is no volume, it _might_ be a device with only one |
| 1586 |
// volume on it (think CDs) - so we're so nice to the caller to unmount that volume |
1469 |
// volume on it (think CDs) - so we're so nice to the caller to unmount that volume |
| 1587 |
LibHalDrive* halDrive = libhal_drive_from_udi(m_halContext, _udi.latin1()); |
1470 |
HalDrive* halDrive = hal_drive_from_udi(m_halContext, _udi.latin1()); |
| 1588 |
if (halDrive) |
1471 |
if (halDrive) |
| 1589 |
{ |
1472 |
{ |
| 1590 |
int numVolumes; |
1473 |
int numVolumes; |
| 1591 |
char** volumes = libhal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes); |
1474 |
char** volumes = hal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes); |
| 1592 |
if (numVolumes == 1) |
1475 |
if (numVolumes == 1) |
| 1593 |
medium = m_mediaList.findById( volumes[0] ); |
1476 |
medium = m_mediaList.findById( volumes[0] ); |
| 1594 |
} |
1477 |
} |
|
Lines 1626-1644
Link Here
|
| 1626 |
const char *options[2]; |
1509 |
const char *options[2]; |
| 1627 |
TQString udi = TQString::null; |
1510 |
TQString udi = TQString::null; |
| 1628 |
|
1511 |
|
| 1629 |
if (!medium->isEncrypted()) { |
1512 |
udi = medium->id(); |
| 1630 |
// normal volume |
1513 |
|
| 1631 |
udi = medium->id(); |
|
|
| 1632 |
} else { |
| 1633 |
// see if we have a clear volume |
| 1634 |
LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, medium->id().latin1()); |
| 1635 |
if (halVolume) { |
| 1636 |
char *clearUdi = libhal_volume_crypto_get_clear_volume_udi(m_halContext, halVolume); |
| 1637 |
udi = clearUdi; |
| 1638 |
libhal_free_string(clearUdi); |
| 1639 |
libhal_volume_free(halVolume); |
| 1640 |
} |
| 1641 |
} |
| 1642 |
if (udi.isNull()) { |
1514 |
if (udi.isNull()) { |
| 1643 |
kdDebug() << "unmount failed: no udi" << endl; |
1515 |
kdDebug() << "unmount failed: no udi" << endl; |
| 1644 |
return i18n("Internal Error"); |
1516 |
return i18n("Internal Error"); |
|
Lines 1748-1858
Link Here
|
| 1748 |
return TQString(); |
1620 |
return TQString(); |
| 1749 |
} |
1621 |
} |
| 1750 |
|
1622 |
|
| 1751 |
TQString HALBackend::decrypt(const TQString &_udi, const TQString &password) |
|
|
| 1752 |
{ |
| 1753 |
const Medium* medium = m_mediaList.findById(_udi); |
| 1754 |
if (!medium) |
| 1755 |
return i18n("No such medium: %1").arg(_udi); |
| 1756 |
|
| 1757 |
if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) |
| 1758 |
return TQString(); |
| 1759 |
|
| 1760 |
const char *udi = medium->id().latin1(); |
| 1761 |
DBusMessage *msg = NULL; |
| 1762 |
DBusMessage *reply = NULL; |
| 1763 |
DBusError error; |
| 1764 |
|
| 1765 |
kdDebug() << "Setting up " << udi << " for crypto\n" <<endl; |
| 1766 |
|
| 1767 |
msg = dbus_message_new_method_call ("org.freedesktop.Hal", udi, |
| 1768 |
"org.freedesktop.Hal.Device.Volume.Crypto", |
| 1769 |
"Setup"); |
| 1770 |
if (msg == NULL) { |
| 1771 |
kdDebug() << "decrypt failed for " << udi << ": could not create dbus message\n"; |
| 1772 |
return i18n("Internal Error"); |
| 1773 |
} |
| 1774 |
|
| 1775 |
TQCString pwdUtf8 = password.utf8(); |
| 1776 |
const char *pwd_utf8 = pwdUtf8; |
| 1777 |
if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &pwd_utf8, DBUS_TYPE_INVALID)) { |
| 1778 |
kdDebug() << "decrypt failed for " << udi << ": could not append args to dbus message\n"; |
| 1779 |
dbus_message_unref (msg); |
| 1780 |
return i18n("Internal Error"); |
| 1781 |
} |
| 1782 |
|
| 1783 |
dbus_error_init (&error); |
| 1784 |
if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, msg, -1, &error)) || |
| 1785 |
dbus_error_is_set (&error)) |
| 1786 |
{ |
| 1787 |
TQString qerror = i18n("Internal Error"); |
| 1788 |
kdDebug() << "decrypt failed for " << udi << ": " << error.name << " " << error.message << endl; |
| 1789 |
if (strcmp (error.name, "org.freedesktop.Hal.Device.Volume.Crypto.SetupPasswordError") == 0) { |
| 1790 |
qerror = i18n("Wrong password"); |
| 1791 |
} |
| 1792 |
dbus_error_free (&error); |
| 1793 |
dbus_message_unref (msg); |
| 1794 |
while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; |
| 1795 |
return qerror; |
| 1796 |
} |
| 1797 |
|
| 1798 |
dbus_message_unref (msg); |
| 1799 |
dbus_message_unref (reply); |
| 1800 |
|
| 1801 |
while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; |
| 1802 |
|
| 1803 |
return TQString(); |
| 1804 |
} |
| 1805 |
|
| 1806 |
TQString HALBackend::undecrypt(const TQString &_udi) |
| 1807 |
{ |
| 1808 |
const Medium* medium = m_mediaList.findById(_udi); |
| 1809 |
if (!medium) |
| 1810 |
return i18n("No such medium: %1").arg(_udi); |
| 1811 |
|
| 1812 |
if (!medium->isEncrypted() || medium->clearDeviceUdi().isNull()) |
| 1813 |
return TQString(); |
| 1814 |
|
| 1815 |
const char *udi = medium->id().latin1(); |
| 1816 |
DBusMessage *msg = NULL; |
| 1817 |
DBusMessage *reply = NULL; |
| 1818 |
DBusError error; |
| 1819 |
|
| 1820 |
kdDebug() << "Tear down " << udi << "\n" <<endl; |
| 1821 |
|
| 1822 |
msg = dbus_message_new_method_call ("org.freedesktop.Hal", udi, |
| 1823 |
"org.freedesktop.Hal.Device.Volume.Crypto", |
| 1824 |
"Teardown"); |
| 1825 |
if (msg == NULL) { |
| 1826 |
kdDebug() << "teardown failed for " << udi << ": could not create dbus message\n"; |
| 1827 |
return i18n("Internal Error"); |
| 1828 |
} |
| 1829 |
|
| 1830 |
if (!dbus_message_append_args (msg, DBUS_TYPE_INVALID)) { |
| 1831 |
kdDebug() << "teardown failed for " << udi << ": could not append args to dbus message\n"; |
| 1832 |
dbus_message_unref (msg); |
| 1833 |
return i18n("Internal Error"); |
| 1834 |
} |
| 1835 |
|
| 1836 |
dbus_error_init (&error); |
| 1837 |
if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, msg, -1, &error)) || |
| 1838 |
dbus_error_is_set (&error)) |
| 1839 |
{ |
| 1840 |
TQString qerror = i18n("Internal Error"); |
| 1841 |
kdDebug() << "teardown failed for " << udi << ": " << error.name << " " << error.message << endl; |
| 1842 |
dbus_error_free (&error); |
| 1843 |
dbus_message_unref (msg); |
| 1844 |
while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; |
| 1845 |
return qerror; |
| 1846 |
} |
| 1847 |
|
| 1848 |
dbus_message_unref (msg); |
| 1849 |
dbus_message_unref (reply); |
| 1850 |
|
| 1851 |
ResetProperties(udi); |
| 1852 |
|
| 1853 |
while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; |
| 1854 |
|
| 1855 |
return TQString(); |
| 1856 |
} |
| 1857 |
|
| 1858 |
#include "halbackend.moc" |
1623 |
#include "halbackend.moc" |