summaryrefslogtreecommitdiffstats
path: root/src/k3bmediacache.h
blob: 600a962e0b50997cb9f116e08a56f0c205422790 (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
/* 
 *
 * $Id: sourceheader 380067 2005-01-19 13:03:46Z trueg $
 * Copyright (C) 2005 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * See the file "COPYING" for the exact licensing terms.
 */


#ifndef _K3B_MEDIA_CACHE_H_
#define _K3B_MEDIA_CACHE_H_

#include <tqobject.h>

#include <tqvaluelist.h>

#include <k3bdevice.h>
#include <k3btoc.h>
#include <k3bcdtext.h>
#include <k3bdiskinfo.h>

#include "k3bmedium.h"

namespace K3bDevice {
  class DeviceManager;
}

class TQCustomEvent;


/**
 * The Media Cache does know the status of all devices at all times
 * (except for blocked devices).
 *
 * It should be used to get information about media and device status
 * instead of the libk3bdevice methods for faster access.
 *
 * The Media Cache polls for new information every 2 seconds on all devices
 * (except for blocked ones) and emits signals in case a device status changed
 * (for example a media was inserted or removed).
 *
 * To start the media caching call buildDeviceList().
 */
class K3bMediaCache : public TQObject
{
  Q_OBJECT
  TQ_OBJECT

 public:
  K3bMediaCache( TQObject* parent = 0 );
  ~K3bMediaCache();

  /**
   * block a device so it will not be polled. This is used
   * to disable polling on devices that are currently in use
   * for burning.
   *
   * \return A unique id to be used to unblock the device or -1 if the device
   *         is already blocked.
   */
  int blockDevice( K3bDevice::Device* dev );

  /**
   * Unblock a device that has been blocked with block() before.
   *
   * \param id The id returned by the previous call to block(). This makes
   *           sure only the one who did the block may unblock the device.
   *
   * \return true if dev has been blocked with id before. false otherwise.
   */
  bool unblockDevice( K3bDevice::Device* dev, int id );

  bool isBlocked( K3bDevice::Device* dev );

  /**
   * Read cached medium information.
   */
  K3bMedium medium( K3bDevice::Device* dev );

  /**
   * Read cached disk information.
   */
  K3bDevice::DiskInfo diskInfo( K3bDevice::Device* );

  /**
   * Read cached Table of contents.
   */
  K3bDevice::Toc toc( K3bDevice::Device* );

  /**
   * Read cached CD text from an Audio CD.
   */
  K3bDevice::CdText cdText( K3bDevice::Device* );

  /**
   * Read cached supported writing speeds.
   */
  TQValueList<int> writingSpeeds( K3bDevice::Device* );

  /**
   * \see K3bMedium::shortString()
   */
  TQString mediumString( K3bDevice::Device* device, bool useContent = true );

 signals:
  /**
   * Signal emitted whenever a medium changes. That means when a new medium is inserted
   * or an old one is removed.
   *
   * This signal will also be emitted when a previously blocked device becomes unblocked.
   *
   * Be aware though that the Media Cache will silently ignore removed devices. That means
   * once should also listen to K3bDevice::DeviceManager::changed() in case a USB drive or
   * something similar is removed.
   */
  void mediumChanged( K3bDevice::Device* dev );

 public slots:
  /**
   * Build the device list and start the polling.
   * It might make sense to connect this to K3bDevice::DeviceManager::changed()
   */
  void buildDeviceList( K3bDevice::DeviceManager* );

  /**
   * Clear the device list and stop all the polling.
   * This is also done in the destructor.
   */
  void clearDeviceList();

 private:
  class PollThread;
  class DeviceEntry;
  class MediaChangeEvent;

  TQMap<K3bDevice::Device*, DeviceEntry*> m_deviceMap;

  DeviceEntry* findDeviceEntry( K3bDevice::Device* );
  void customEvent( TQCustomEvent* );
};

#endif