Browse Source

Extended media manager dcop interface by adding functions to

mount/unmount/decrypt/undecrypt a medium by device node (for example /dev/sdc).

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
undefined
Michele Calgaro 1 month ago
parent
commit
074e836c04
Signed by: Michele Calgaro <michele.calgaro@yahoo.it> GPG Key ID: 2A75B7CA8ADED5CF

+ 16
- 1
tdeioslave/media/mediamanager/medialist.cpp View File

@@ -52,6 +52,15 @@ const Medium *MediaList::findByName(const TQString &name) const
52 52
 	return m_nameMap[name];
53 53
 }
54 54
 
55
+const Medium *MediaList::findByNode(const TQString &node) const
56
+{
57
+	kdDebug(1219) << "MediaList::findByNode(" << node << ")" << endl;
58
+
59
+	if ( !m_nodeMap.contains(node) ) return 0L;
60
+
61
+	return m_nodeMap[node];
62
+}
63
+
55 64
 const Medium *MediaList::findByClearUdi(const TQString &name)
56 65
 {
57 66
 	kdDebug(1219) << "MediaList::findByClearUdi(" << name << ")" << endl;
@@ -64,7 +73,6 @@ const Medium *MediaList::findByClearUdi(const TQString &name)
64 73
 	return 0L;
65 74
 }
66 75
 
67
-
68 76
 TQString MediaList::addMedium(Medium *medium, bool allowNotification)
69 77
 {
70 78
 	kdDebug(1219) << "MediaList::addMedium(@" << medium->id() << ")" << endl;
@@ -75,6 +83,12 @@ TQString MediaList::addMedium(Medium *medium, bool allowNotification)
75 83
 		m_nameMap[name] = medium;
76 84
 	}
77 85
 
86
+	TQString node = medium->deviceNode();
87
+	if (!m_nodeMap.contains(node))
88
+	{
89
+		m_nodeMap[node] = medium;
90
+	}
91
+
78 92
 	TQString id = medium->id();
79 93
 	if (m_idMap.contains(id))
80 94
 	{
@@ -101,6 +115,7 @@ bool MediaList::removeMedium(const TQString &id, bool allowNotification)
101 115
 	Medium *medium = m_idMap[id];
102 116
 	m_idMap.remove(id);
103 117
 	m_nameMap.remove(medium->name());
118
+	m_nodeMap.remove(medium->deviceNode());
104 119
 
105 120
 	TQString name = medium->name();
106 121
 	m_media.remove(medium);

+ 5
- 3
tdeioslave/media/mediamanager/medialist.h View File

@@ -1,5 +1,5 @@
1 1
 /* This file is part of the KDE Project
2
-   Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
2
+   Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
3 3
 
4 4
    This library is free software; you can redistribute it and/or
5 5
    modify it under the terms of the GNU Library General Public
@@ -34,6 +34,7 @@ public:
34 34
 	const TQPtrList<Medium> list() const;
35 35
 	const Medium *findById(const TQString &id) const;
36 36
 	const Medium *findByName(const TQString &name) const;
37
+	const Medium *findByNode(const TQString &node) const;
37 38
 	const Medium *findByClearUdi(const TQString &name);
38 39
 
39 40
 public:
@@ -73,8 +74,9 @@ signals:
73 74
 
74 75
 private:
75 76
 	TQPtrList<Medium> m_media;
76
-	TQMap<TQString,Medium*> m_nameMap;
77
-	TQMap<TQString,Medium*> m_idMap;
77
+	TQMap<TQString, Medium*> m_idMap;
78
+	TQMap<TQString, Medium*> m_nameMap;
79
+	TQMap<TQString, Medium*> m_nodeMap;
78 80
 };
79 81
 
80 82
 #endif

+ 48
- 0
tdeioslave/media/mediamanager/mediamanager.cpp View File

@@ -355,6 +355,54 @@ TQStringVariantMap MediaManager::undecrypt(const TQString &uid)
355 355
 #endif
356 356
 }
357 357
 
358
+TQStringVariantMap MediaManager::mountByNode(const TQString &deviceNode)
359
+{
360
+	const Medium *medium = m_mediaList.findByNode(deviceNode);
361
+	if (!medium) {
362
+		TQStringVariantMap result;
363
+		result["errStr"] = i18n("No such medium: %1").arg(deviceNode);
364
+		result["result"] = false;
365
+		return result;
366
+	}
367
+	return mount(medium->id());
368
+}
369
+
370
+TQStringVariantMap MediaManager::unmountByNode(const TQString &deviceNode)
371
+{
372
+	const Medium *medium = m_mediaList.findByNode(deviceNode);
373
+	if (!medium) {
374
+		TQStringVariantMap result;
375
+		result["errStr"] = i18n("No such medium: %1").arg(deviceNode);
376
+		result["result"] = false;
377
+		return result;
378
+	}
379
+	return unmount(medium->id());
380
+}
381
+
382
+TQStringVariantMap MediaManager::decryptByNode(const TQString &deviceNode, const TQString &password)
383
+{
384
+	const Medium *medium = m_mediaList.findByNode(deviceNode);
385
+	if (!medium) {
386
+		TQStringVariantMap result;
387
+		result["errStr"] = i18n("No such medium: %1").arg(deviceNode);
388
+		result["result"] = false;
389
+		return result;
390
+	}
391
+	return decrypt(medium->id(), password);
392
+}
393
+
394
+TQStringVariantMap MediaManager::undecryptByNode(const TQString &deviceNode)
395
+{
396
+	const Medium *medium = m_mediaList.findByNode(deviceNode);
397
+	if (!medium) {
398
+		TQStringVariantMap result;
399
+		result["errStr"] = i18n("No such medium: %1").arg(deviceNode);
400
+		result["result"] = false;
401
+		return result;
402
+	}
403
+	return undecrypt(medium->id());
404
+}
405
+
358 406
 TQString MediaManager::nameForLabel(const TQString &label)
359 407
 {
360 408
     const TQPtrList<Medium> media = m_mediaList.list();

+ 5
- 0
tdeioslave/media/mediamanager/mediamanager.h View File

@@ -52,6 +52,11 @@ k_dcop:
52 52
 	TQStringVariantMap decrypt(const TQString &uid, const TQString &password);
53 53
 	TQStringVariantMap undecrypt(const TQString &uid);
54 54
 
55
+	TQStringVariantMap mountByNode(const TQString &deviceNode);
56
+	TQStringVariantMap unmountByNode(const TQString &deviceNode);
57
+	TQStringVariantMap decryptByNode(const TQString &deviceNode, const TQString &password);
58
+	TQStringVariantMap undecryptByNode(const TQString &deviceNode);
59
+
55 60
 	TQString nameForLabel(const TQString &label);
56 61
 	ASYNC setUserLabel(const TQString &name, const TQString &label);
57 62
 

Loading…
Cancel
Save