Krita Source Code Documentation
Loading...
Searching...
No Matches
KisColord Class Reference

#include <KisColord.h>

+ Inheritance diagram for KisColord:

Signals

void changed ()
 
void changed (const QString &device)
 

Public Member Functions

const QString deviceName (const QString &id) const
 
QByteArray deviceProfile (const QString &id, int profile)
 
QStringList devices (const QString &type) const
 
 KisColord (QObject *parent=0)
 
 ~KisColord () override
 

Private Slots

void deviceAdded (const QDBusObjectPath &objectPath, bool emitChanged=true)
 
void deviceChanged (const QDBusObjectPath &objectPath)
 
void deviceRemoved (const QDBusObjectPath &objectPath)
 
void gotDevices (QDBusPendingCallWatcher *call)
 
void serviceOwnerChanged (const QString &serviceName, const QString &oldOwner, const QString &newOwner)
 

Private Member Functions

void addProfilesToDevice (Device *dev, QList< QDBusObjectPath > profiles) const
 

Private Attributes

CdInterface * m_cdInterface
 
QMap< QDBusObjectPath, Device * > m_devices
 

Detailed Description

Definition at line 34 of file KisColord.h.

Constructor & Destructor Documentation

◆ KisColord()

KisColord::KisColord ( QObject * parent = 0)

Definition at line 44 of file KisColord.cpp.

45 : QObject(parent)
46{
47 //dbgKrita << "Creating KisColorD";
48
49 m_cdInterface = new CdInterface(QLatin1String("org.freedesktop.ColorManager"),
50 QLatin1String("/org/freedesktop/ColorManager"),
51 QDBusConnection::systemBus(),
52 this);
53
54 // listen to colord for device events
55 connect(m_cdInterface, SIGNAL(DeviceAdded(QDBusObjectPath)),
56 this, SLOT(deviceAdded(QDBusObjectPath)));
57 connect(m_cdInterface, SIGNAL(DeviceRemoved(QDBusObjectPath)),
58 this, SLOT(deviceRemoved(QDBusObjectPath)));
59 connect(m_cdInterface, SIGNAL(DeviceChanged(QDBusObjectPath)),
60 this, SLOT(deviceChanged(QDBusObjectPath)));
61
62 // Ask for devices
63 QDBusPendingReply<QList<QDBusObjectPath> > async = m_cdInterface->GetDevices();
64 QDBusPendingCallWatcher *displayWatcher = new QDBusPendingCallWatcher(async, this);
65 connect(displayWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
66 this, SLOT(gotDevices(QDBusPendingCallWatcher*)));
67
68
69 // Make sure we know is colord is running
70 QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.freedesktop.ColorManager",
71 QDBusConnection::systemBus(),
72 QDBusServiceWatcher::WatchForOwnerChange,
73 this);
74
75 connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
76 this, SLOT(serviceOwnerChanged(QString,QString,QString)));
77}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void gotDevices(QDBusPendingCallWatcher *call)
CdInterface * m_cdInterface
Definition KisColord.h:65
void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner)
void deviceChanged(const QDBusObjectPath &objectPath)
void deviceRemoved(const QDBusObjectPath &objectPath)
void deviceAdded(const QDBusObjectPath &objectPath, bool emitChanged=true)

References connect(), deviceAdded(), deviceChanged(), deviceRemoved(), gotDevices(), m_cdInterface, and serviceOwnerChanged().

◆ ~KisColord()

KisColord::~KisColord ( )
override

Definition at line 79 of file KisColord.cpp.

80{
81 qDeleteAll(m_devices);
82 m_devices.clear();
83}
QMap< QDBusObjectPath, Device * > m_devices
Definition KisColord.h:63

References m_devices.

Member Function Documentation

◆ addProfilesToDevice()

void KisColord::addProfilesToDevice ( Device * dev,
QList< QDBusObjectPath > profiles ) const
private

Definition at line 250 of file KisColord.cpp.

251{
252
253 Q_FOREACH (const QDBusObjectPath &profileObjectPath, profiles) {
254
255 CdProfileInterface profile(QLatin1String("org.freedesktop.ColorManager"),
256 profileObjectPath.path(),
257 QDBusConnection::systemBus());
258 if (!profile.isValid()) {
259 return;
260 }
261
262
263 Profile *p = new Profile;
264
265 p->kind = profile.kind();
266 p->filename = profile.filename();
267 p->title = profile.title();
268 p->created = profile.created();
269 p->colorspace = profile.colorspace();
270
271 dev->profiles << p;
272 }
273}
const Params2D p
QList< Profile * > profiles
Definition KisColord.cpp:40
QString kind
Definition KisColord.cpp:20

References Profile::kind, p, and Device::profiles.

◆ changed [1/2]

void KisColord::changed ( )
signal

◆ changed [2/2]

void KisColord::changed ( const QString & device)
signal

◆ deviceAdded

void KisColord::deviceAdded ( const QDBusObjectPath & objectPath,
bool emitChanged = true )
privateslot

Definition at line 203 of file KisColord.cpp.

204{
205 if (m_devices.contains(objectPath)) {
206 //dbgKrita << "Device is already on the list" << objectPath.path();
207 return;
208 }
209
210 CdDeviceInterface device(QLatin1String("org.freedesktop.ColorManager"),
211 objectPath.path(),
212 QDBusConnection::systemBus());
213 if (!device.isValid()) {
214 dbgKrita << "Got an invalid device" << objectPath.path();
215 return;
216 }
217
218 Device *dev = new Device;
219
220 dev->id = device.deviceId();
221 dev->kind = device.kind();
222 dev->model = device.model();
223 dev->vendor = device.vendor();
224 dev->colorspace = device.colorspace();
225
226 m_devices[objectPath] = dev;
227
228 QList<QDBusObjectPath> profiles = device.profiles();
229 addProfilesToDevice(dev, profiles);
230
231// dbgKrita << "deviceAdded" << dev->id
232// << dev->kind
233// << dev->model
234// << dev->vendor
235// << "with" << profiles.size() << "profiles";
236
237 if (emitChanged) {
238 Q_EMIT changed();
239 }
240}
void changed()
void addProfilesToDevice(Device *dev, QList< QDBusObjectPath > profiles) const
#define dbgKrita
Definition kis_debug.h:45
QString vendor
Definition KisColord.cpp:37
QString model
Definition KisColord.cpp:36
QString id
Definition KisColord.cpp:34
QString kind
Definition KisColord.cpp:35
QString colorspace
Definition KisColord.cpp:38

References addProfilesToDevice(), changed(), Device::colorspace, dbgKrita, Device::id, Device::kind, m_devices, Device::model, and Device::vendor.

◆ deviceChanged

void KisColord::deviceChanged ( const QDBusObjectPath & objectPath)
privateslot

Definition at line 175 of file KisColord.cpp.

176{
177 CdDeviceInterface device(QLatin1String("org.freedesktop.ColorManager"),
178 objectPath.path(),
179 QDBusConnection::systemBus());
180 if (!device.isValid()) {
181 return;
182 }
183
184 if (!m_devices.contains(objectPath)) {
185 //dbgKrita << "deviceChanged for an unknown device" << objectPath.path();
186 deviceAdded(objectPath, false);
187 return;
188 }
189
190 QList<QDBusObjectPath> profiles = device.profiles();
191
192 Device *dev = m_devices[objectPath];
193 qDeleteAll(dev->profiles);
194 dev->profiles.clear();
195
196 addProfilesToDevice(dev, profiles);
197
198 //dbgKrita << "deviceChanged" << dev->id << "with" << profiles.size() << "profiles";
199
200 Q_EMIT changed(dev->id);
201}

References addProfilesToDevice(), changed(), deviceAdded(), Device::id, m_devices, and Device::profiles.

◆ deviceName()

const QString KisColord::deviceName ( const QString & id) const

Definition at line 96 of file KisColord.cpp.

97{
98 QString res;
99 Q_FOREACH (Device *dev, m_devices.values()) {
100 if (dev->id == id) {
101 res = dev->model + ", " + dev->vendor;
102 }
103 }
104 return res;
105}

References Device::id, m_devices, Device::model, and Device::vendor.

◆ deviceProfile()

QByteArray KisColord::deviceProfile ( const QString & id,
int profile )

Definition at line 107 of file KisColord.cpp.

108{
109 QByteArray ba;
110 Device *dev = 0;
111 Profile *profile = 0;
112 Q_FOREACH (Device *d, m_devices.values()) {
113 if (d->id == id) {
114 dev = d;
115 break;
116 }
117 }
118
119 if (dev) {
120 if (dev->profiles.size() > 0) {
121 if (dev->profiles.size() < p) {
122 profile = dev->profiles[p];
123 }
124 else {
125 profile = dev->profiles[0];
126 }
127 }
128
129 if (profile) {
130 //dbgKrita << "profile filename" << profile->filename;
131 QFile f(profile->filename);
132 if (f.open(QFile::ReadOnly)) {
133 ba = f.readAll();
134 }
135 else {
136 dbgKrita << "Could not load profile" << profile->title << profile->filename;
137 }
138 }
139 }
140
141 return ba;
142}
QString filename
Definition KisColord.cpp:21
QString title
Definition KisColord.cpp:22

References dbgKrita, Profile::filename, m_devices, p, Device::profiles, and Profile::title.

◆ deviceRemoved

void KisColord::deviceRemoved ( const QDBusObjectPath & objectPath)
privateslot

Definition at line 242 of file KisColord.cpp.

243{
244 if (m_devices.contains(objectPath)) {
245 delete m_devices.take(objectPath);
246 }
247 Q_EMIT changed();
248}

References changed(), and m_devices.

◆ devices()

QStringList KisColord::devices ( const QString & type) const

Definition at line 85 of file KisColord.cpp.

86{
87 QStringList res;
88 Q_FOREACH (Device *dev, m_devices.values()) {
89 if (type == dev->kind) {
90 res << dev->id;
91 }
92 }
93 return res;
94}

References Device::id, Device::kind, and m_devices.

◆ gotDevices

void KisColord::gotDevices ( QDBusPendingCallWatcher * call)
privateslot

Definition at line 157 of file KisColord.cpp.

158{
159 //dbgKrita << "Got devices!!!";
160
161 QDBusPendingReply<QList<QDBusObjectPath> > reply = *call;
162 if (reply.isError()) {
163 dbgKrita << "Unexpected message" << reply.error().message();
164 } else {
165 QList<QDBusObjectPath> devices = reply.argumentAt<0>();
166 Q_FOREACH (const QDBusObjectPath &device, devices) {
167 deviceAdded(device, false);
168 }
169 Q_EMIT changed();
170 }
171 //dbgKrita << "gotDevices" << m_devices.count();
172 call->deleteLater();
173}
QStringList devices(const QString &type) const
Definition KisColord.cpp:85

References changed(), dbgKrita, deviceAdded(), and devices().

◆ serviceOwnerChanged

void KisColord::serviceOwnerChanged ( const QString & serviceName,
const QString & oldOwner,
const QString & newOwner )
privateslot

Definition at line 146 of file KisColord.cpp.

147{
148 Q_UNUSED(serviceName);
149 if (newOwner.isEmpty() || oldOwner != newOwner) {
150 // colord has quit or restarted
151 qDeleteAll(m_devices);
152 m_devices.clear();
153 }
154 Q_EMIT changed();
155}

References changed(), and m_devices.

Member Data Documentation

◆ m_cdInterface

CdInterface* KisColord::m_cdInterface
private

Definition at line 65 of file KisColord.h.

◆ m_devices

QMap<QDBusObjectPath, Device*> KisColord::m_devices
private

Definition at line 63 of file KisColord.h.


The documentation for this class was generated from the following files: