summaryrefslogtreecommitdiffstats
path: root/tdeioslave/media/mediamanager/tdehardwarebackend.h
blob: 9b5407d8fac6e90e2569b6611c9eb217507e469d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* This file is part of the TDE Project
   Copyright (c) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

/**
* This is a media:/ backend for the builtin TDE hardware library
*
* @author Timothy Pearson <kb9vqf@pearsoncomputing.net>
* @short media:/ backend for the TDE hardware library
*/

#ifndef _TDEBACKEND_H_
#define _TDEBACKEND_H_

#include "backendbase.h"

#include <tqobject.h>
#include <tqstringlist.h>
#include <tqstring.h>

#include <config.h>

#include <tdehardwaredevices.h>

namespace TDEIO {
	class Job;
}

class Dialog;

class TDEBackend : public TQObject, public BackendBase
{
Q_OBJECT

public:
	/**
	* Constructor
	*/
	TDEBackend(MediaList &list, TQObject* parent);

	/**
	* Destructor
	*/
	~TDEBackend();

	/**
	* List all devices and append them to the media device list (called only once, at startup).
	*
	* @return true if succeded, false otherwise
	*/
	bool ListDevices();

	TQStringList mountoptions(const TQString &id);

	bool setMountoptions(const TQString &id, const TQStringList &options);

	TQString mount(const TQString &id);
	TQString mount(const Medium *medium);
	TQString unmount(const TQString &id);
// 	TQString decrypt(const TQString &id, const TQString &password);
// 	TQString undecrypt(const TQString &id);

private:
	/**
	* Append a device in the media list. This function will check if the device
	* is worth listing.
	*
	*  @param sdevice             A pointer to a TDEStorageDevice object
	*  @param allowNotification   Indicates if this event will be notified to the user
	*/
	void AddDevice(TDEStorageDevice * sdevice, bool allowNotification=true);

	/**
	* Remove a device from the device list
	*
	*  @param sdevice             A pointer to a TDEStorageDevice object
	*/
	void RemoveDevice(TDEStorageDevice * sdevice);

	/**
	* A device has changed, update it
	*
	*  @param sdevice             A pointer to a TDEStorageDevice object
	*/
	void ModifyDevice(TDEStorageDevice * sdevice);

private slots:
	void AddDeviceHandler(TDEGenericDevice* device);
	void RemoveDeviceHandler(TDEGenericDevice* device);
	void ModifyDeviceHandler(TDEGenericDevice* device);

	void slotPasswordReady();
	void slotPasswordCancel();

signals:
	void signalDecryptionPasswordError(TQString);

/* Set media properties */
private:
	/**
	* Reset properties for the given medium
	*
	*  @param sdevice             A pointer to a TDEStorageDevice objec
	*  @param allowNotification   Indicates if this event will be notified to the user
	*  @param overrideIgnoreList  If true, override event ignore requests for the current device node
	*/
	void ResetProperties(TDEStorageDevice * sdevice, bool allowNotification=false, bool overrideIgnoreList=false);

	/**
	* Find the medium that is concerned with device udi
	*/
// 	const char* findMediumUdiFromUdi(const char* udi);

	void setVolumeProperties(Medium* medium);
	bool setFloppyProperties(Medium* medium);
	void setFloppyMountState( Medium* medium );
// 	bool setFstabProperties(Medium* medium);
	void setCameraProperties(Medium* medium);
	TQString generateName(const TQString &devNode);
	static TQString isInFstab(const Medium *medium);
	static TQString listUsingProcesses(const Medium *medium);
	static TQString killUsingProcesses(const Medium *medium);

	TQString driveUDIFromDeviceUID(TQString uuid);

	// Decryption
	Dialog* m_decryptDialog;
	TQString m_decryptionPassword;
	bool m_decryptPasswordValid;

/* TDE structures */
private:
	/**
	* Object for the kded module
	*/
	TQObject* m_parent;

	/**
	* Data structure for fstab mount/unmount jobs
	*/
	struct mount_job_data {
		// [in] Medium, which is being mounted/unmounted by the job
		const Medium* medium;
		// [in,out] Should be set to true when the job completes
		bool completed;
		// [out] TDEIO::Error if an error occured during operation. Otherwise, 0
		int error;
		// [out] Error message to be displayed to the user
		TQString errorMessage;
	};

	TQMap<TDEIO::Job *, struct mount_job_data*> mount_jobs;

	TQStringList m_ignoreDeviceChangeEvents;
};

#endif /* _TDEBACKEND_H_ */