[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [colord-kde] colord-kcm: Improve Calibrate button by looking at org.Colord.Sensors
From: Daniel Nicoletti <dantti12 () gmail ! com>
Date: 2012-03-31 19:02:21
Message-ID: 20120331190221.6FB7AA60BB () git ! kde ! org
[Download RAW message or body]
Git commit 7416dcd43293a252907eefb23d8e3c7e3f09e724 by Daniel Nicoletti.
Committed on 31/03/2012 at 03:27.
Pushed by dantti into branch 'master'.
Improve Calibrate button by looking at org.Colord.Sensors
Improve Devices/Profiles selection
M +52 -23 colord-kcm/ColordKCM.cpp
M +5 -2 colord-kcm/ColordKCM.h
M +8 -4 colord-kcm/ColordKCM.ui
M +136 -9 colord-kcm/Description.cpp
M +11 -0 colord-kcm/Description.h
M +2 -11 colord-kcm/DeviceModel.cpp
M +3 -1 colord-kcm/DeviceModel.h
M +0 -10 colord-kcm/ProfileModel.cpp
M +3 -1 colord-kcm/ProfileModel.h
http://commits.kde.org/colord-kde/7416dcd43293a252907eefb23d8e3c7e3f09e724
diff --git a/colord-kcm/ColordKCM.cpp b/colord-kcm/ColordKCM.cpp
index 2b8e947..a51abcf 100644
--- a/colord-kcm/ColordKCM.cpp
+++ b/colord-kcm/ColordKCM.cpp
@@ -36,6 +36,8 @@
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusServiceWatcher>
+#include <QItemSelectionModel>
#include <QTimer>
#include <QFileInfo>
#include <QStringBuilder>
@@ -92,26 +94,25 @@ ColordKCM::ColordKCM(QWidget *parent, const QVariantList &args) :
// Connect this slot prior to defining the model
// so we get a selection on the first item for free
connect(sortModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(showProfile()));
+ this, SLOT(showDescription()));
sortModel->setDynamicSortFilter(true);
sortModel->setSortRole(DeviceModel::SortRole);
sortModel->sort(0);
// Set the source model then connect to the selection model to get updates
ui->devicesTV->setModel(sortModel);
connect(ui->devicesTV->selectionModel(), \
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
- this, SLOT(showProfile()));
-
- m_model = new DeviceModel(this);
- connect(m_model, SIGNAL(changed()), this, SLOT(showProfile()));
- sortModel->setSourceModel(m_model);
+ this, SLOT(showDescription()));
+ m_deviceModel = new DeviceModel(this);
+ connect(m_deviceModel, SIGNAL(changed()), this, SLOT(updateSelection()));
+ sortModel->setSourceModel(m_deviceModel);
// Profiles view setup
- ProfileModel *model = new ProfileModel(this);
- connect(m_model, SIGNAL(changed()), this, SLOT(showProfile()));
+ m_profileModel = new ProfileModel(this);
+ connect(m_profileModel, SIGNAL(changed()), this, SLOT(updateSelection()));
// Filter Proxy for the menu
m_profilesFilter = new QSortFilterProxyModel(this);
- m_profilesFilter->setSourceModel(model);
+ m_profilesFilter->setSourceModel(m_profileModel);
m_profilesFilter->setFilterRole(ProfileModel::ColorspaceRole);
m_profilesFilter->setSortRole(ProfileModel::SortRole);
m_profilesFilter->setDynamicSortFilter(true);
@@ -119,15 +120,29 @@ ColordKCM::ColordKCM(QWidget *parent, const QVariantList &args) \
:
// Sort Proxy for the View
QSortFilterProxyModel *profileSortModel = new QSortFilterProxyModel(this);
- profileSortModel->setSourceModel(model);
+ profileSortModel->setSourceModel(m_profileModel);
profileSortModel->setDynamicSortFilter(true);
profileSortModel->setSortRole(ProfileModel::SortRole);
profileSortModel->sort(0);
ui->profilesTV->setModel(profileSortModel);
connect(ui->profilesTV->selectionModel(), \
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
- this, SLOT(showProfile()));
+ this, SLOT(showDescription()));
connect(profileSortModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(showProfile()));
+ this, SLOT(showDescription()));
+
+
+ // Make sure we know is colord is running
+ QDBusServiceWatcher *watcher;
+ watcher = new QDBusServiceWatcher("org.freedesktop.ColorManager",
+ QDBusConnection::systemBus(),
+ QDBusServiceWatcher::WatchForOwnerChange,
+ this);
+ connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
+ m_deviceModel, SLOT(serviceOwnerChanged(QString,QString,QString)));
+ connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
+ m_profileModel, SLOT(serviceOwnerChanged(QString,QString,QString)));
+ connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
+ ui->profile, SLOT(serviceOwnerChanged(QString,QString,QString)));
// Creates a ColorD interface, it must be created with new
// otherwise the object will be deleted when this block ends
@@ -154,7 +169,7 @@ ColordKCM::ColordKCM(QWidget *parent, const QVariantList &args) :
connect(signalMapper, SIGNAL(mapped(int)),
ui->tabWidget, SLOT(setCurrentIndex(int)));
connect(signalMapper, SIGNAL(mapped(int)),
- this, SLOT(showProfile()));
+ this, SLOT(showDescription()));
// make sure the screen is split on the half
QList<int> sizes;
@@ -176,16 +191,17 @@ void ColordKCM::load()
// This is highly needed otherwise the size get wrong on System Settings
ui->stackedWidget->setCurrentWidget(ui->profile_page);
}
+ ui->devicesTV->setFocus();
// align the tabbar to the list view
int offset = ui->profile->innerHeight() - ui->devicesTV->viewport()->height();
ui->offsetSpacer->changeSize(30, offset, QSizePolicy::Fixed, \
QSizePolicy::Fixed);
// Make sure we have something selected
- showProfile();
+ showDescription();
}
-void ColordKCM::showProfile()
+void ColordKCM::showDescription()
{
QModelIndex index = currentIndex();
if (!index.isValid()) {
@@ -253,6 +269,24 @@ void ColordKCM::addProfileAction(QAction *action)
addProvileToDevice(profileObject, deviceObject);
}
+void ColordKCM::updateSelection()
+{
+ QAbstractItemView *view;
+ if (sender() == m_deviceModel) {
+ view = ui->devicesTV;
+ } else {
+ view = ui->profilesTV;
+ }
+
+ QItemSelection selection;
+ selection = view->selectionModel()->selection();
+ // Make sure we have an index selected
+ if (selection.indexes().isEmpty()) {
+ view->selectionModel()->select(view->model()->index(0, 0),
+ QItemSelectionModel::SelectCurrent);
+ }
+}
+
void ColordKCM::removeProfile()
{
QModelIndex index = currentIndex();
@@ -428,17 +462,12 @@ QModelIndex ColordKCM::currentIndex() const
}
QItemSelection selection;
- // we need to map the selection to source to get the real indexes
selection = view->selectionModel()->selection();
- // select the first printer if there are profiles
- if (selection.indexes().isEmpty()) {
- view->selectionModel()->select(view->model()->index(0, 0),
- QItemSelectionModel::Select);
- return ret;
+ // select the first index if the selection is not empty
+ if (!selection.indexes().isEmpty()) {
+ ret = selection.indexes().first();
}
- ret = selection.indexes().first();
-
return ret;
}
diff --git a/colord-kcm/ColordKCM.h b/colord-kcm/ColordKCM.h
index a6a5d80..99de1d8 100644
--- a/colord-kcm/ColordKCM.h
+++ b/colord-kcm/ColordKCM.h
@@ -35,6 +35,7 @@ namespace Ui {
class ColordKCM;
}
class DeviceModel;
+class ProfileModel;
class ProfileDescription;
class ColordKCM : public KCModule
{
@@ -48,9 +49,10 @@ public slots:
void load();
private slots:
- void showProfile();
+ void showDescription();
void addProfileFile();
void addProfileAction(QAction *action);
+ void updateSelection();
void removeProfile();
void fillMenu();
void on_tabWidget_currentChanged(int index);
@@ -62,7 +64,8 @@ private:
QString profilesPath() const;
Ui::ColordKCM *ui;
- DeviceModel *m_model;
+ DeviceModel *m_deviceModel;
+ ProfileModel *m_profileModel;
QStackedLayout *m_stackedLayout;
ProfileDescription *m_profileDesc;
QWidget *m_noPrinter;
diff --git a/colord-kcm/ColordKCM.ui b/colord-kcm/ColordKCM.ui
index 6851465..81996c7 100644
--- a/colord-kcm/ColordKCM.ui
+++ b/colord-kcm/ColordKCM.ui
@@ -284,10 +284,6 @@
</widget>
</item>
</layout>
- <zorder>stackedWidget</zorder>
- <zorder>widget</zorder>
- <zorder>devicesTV</zorder>
- <zorder>splitter</zorder>
</widget>
<customwidgets>
<customwidget>
@@ -302,6 +298,14 @@
<container>1</container>
</customwidget>
</customwidgets>
+ <tabstops>
+ <tabstop>devicesTV</tabstop>
+ <tabstop>devicesTb</tabstop>
+ <tabstop>profilesTb</tabstop>
+ <tabstop>removeProfileBt</tabstop>
+ <tabstop>profilesTV</tabstop>
+ <tabstop>addProfileBt</tabstop>
+ </tabstops>
<resources/>
<connections/>
</ui>
diff --git a/colord-kcm/Description.cpp b/colord-kcm/Description.cpp
index 65dc54f..89ec0c7 100644
--- a/colord-kcm/Description.cpp
+++ b/colord-kcm/Description.cpp
@@ -58,8 +58,27 @@ Description::Description(QWidget *parent) :
m_namedColors = new ProfileNamedColors;
m_metadata = new ProfileMetaData;
- QFileInfo gcmCalibrate(QLatin1String("/usr/bin/gcm-calibrate"));
- ui->calibratePB->setEnabled(gcmCalibrate.isExecutable());
+ // Creates a ColorD interface, it must be created with new
+ // otherwise the object will be deleted when this block ends
+ QDBusInterface *interface;
+ interface = new QDBusInterface(QLatin1String("org.freedesktop.ColorManager"),
+ QLatin1String("/org/freedesktop/ColorManager"),
+ QLatin1String("org.freedesktop.ColorManager"),
+ QDBusConnection::systemBus(),
+ this);
+ // listen to colord for events
+ connect(interface, SIGNAL(SensorAdded(QDBusObjectPath)),
+ this, SLOT(sensorAdded(QDBusObjectPath)));
+ connect(interface, SIGNAL(SensorRemoved(QDBusObjectPath)),
+ this, SLOT(sensorRemoved(QDBusObjectPath)));
+
+ // Ask for profiles
+ QDBusMessage message;
+ message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.ColorManager"),
+ \
QLatin1String("/org/freedesktop/ColorManager"), + \
QLatin1String("org.freedesktop.ColorManager"), + \
QLatin1String("GetSensors")); + \
QDBusConnection::systemBus().callWithCallback(message, this, \
SLOT(gotSensors(QDBusMessage))); }
Description::~Description()
@@ -78,6 +97,7 @@ int Description::innerHeight() const
void Description::setProfile(const QDBusObjectPath &objectPath)
{
m_currentProfile = objectPath;
+ m_currentDeviceId.clear();
ui->stackedWidget->setCurrentIndex(0);
QDBusInterface profileInterface(QLatin1String("org.freedesktop.ColorManager"),
@@ -207,6 +227,7 @@ void Description::setDevice(const QDBusObjectPath &objectPath)
QString deviceTitle;
m_currentDeviceId = deviceInterface.property("DeviceId").toString();
QString kind = deviceInterface.property("Kind").toString();
+ m_currentDeviceKind = kind;
QString model = deviceInterface.property("Model").toString();
QString vendor = deviceInterface.property("Vendor").toString();
QString scope = deviceInterface.property("Scope").toString();
@@ -266,16 +287,17 @@ void Description::setDevice(const QDBusObjectPath &objectPath)
\
QLatin1String("org.freedesktop.ColorManager.Profile"), QDBusConnection::systemBus(),
this);
- if (!profileInterface.isValid()) {
- return;
- }
-
- profileTitle = profileInterface.property("Title").toString();
- if (profileTitle.isEmpty()) {
- profileTitle = profileInterface.property("ProfileId").toString();
+ if (profileInterface.isValid()) {
+ profileTitle = profileInterface.property("Title").toString();
+ if (profileTitle.isEmpty()) {
+ profileTitle = profileInterface.property("ProfileId").toString();
+ }
}
}
ui->defaultProfileName->setText(profileTitle);
+
+ // Verify if the Calibrate button should be enbled or disabled
+ ui->calibratePB->setEnabled(calibrateEnabled(m_currentDeviceKind));
}
void Description::on_installSystemWideBt_clicked()
@@ -299,6 +321,50 @@ void Description::on_calibratePB_clicked()
KToolInvocation::kdeinitExec(QLatin1String("gcm-calibrate"), args);
}
+void Description::gotSensors(const QDBusMessage &message)
+{
+ if (message.type() == QDBusMessage::ReplyMessage && message.arguments().size() \
== 1) { + QDBusArgument argument = \
message.arguments().first().value<QDBusArgument>(); + ObjectPathList paths = \
qdbus_cast<ObjectPathList>(argument); + foreach (const QDBusObjectPath &path, \
paths) { + // Add the sensors but don't update the Calibrate button
+ sensorAdded(path, false);
+ }
+ // Update the calibrate button later
+ ui->calibratePB->setEnabled(calibrateEnabled(m_currentDeviceKind));
+ } else {
+ kWarning() << "Unexpected message" << message;
+ }
+}
+
+void Description::sensorAdded(const QDBusObjectPath &sensorPath, bool \
updateCalibrateButton) +{
+ if (!m_sensors.contains(sensorPath)) {
+ m_sensors.append(sensorPath);
+ }
+
+ if (updateCalibrateButton) {
+ ui->calibratePB->setEnabled(calibrateEnabled(m_currentDeviceKind));
+ }
+}
+
+void Description::sensorRemoved(const QDBusObjectPath &sensorPath, bool \
updateCalibrateButton) +{
+ m_sensors.removeOne(sensorPath);
+ if (updateCalibrateButton) {
+ ui->calibratePB->setEnabled(calibrateEnabled(m_currentDeviceKind));
+ }
+}
+
+void Description::serviceOwnerChanged(const QString &serviceName, const QString \
&oldOwner, const QString &newOwner) +{
+ Q_UNUSED(serviceName)
+ if (newOwner.isEmpty() || oldOwner != newOwner) {
+ // colord has quit or restarted
+ m_sensors.clear();
+ }
+}
+
void Description::insertTab(int index, QWidget *widget, const QString &label)
{
int pos = ui->tabWidget->indexOf(widget);
@@ -315,4 +381,65 @@ void Description::removeTab(QWidget *widget)
}
}
+bool Description::calibrateEnabled(const QString &kind)
+{
+ QString toolTip;
+ bool ret = false;
+ toolTip = i18n("Create a color profile for the selected device");
+
+ if (m_currentDeviceId.isEmpty()) {
+ // No device was selected
+ return false;
+ }
+
+ QFileInfo gcmCalibrate(QLatin1String("/usr/bin/gcm-calibrate"));
+ if (!gcmCalibrate.isExecutable()) {
+ // We don't have a calibration tool yet
+ toolTip = i18n("You need Gnome Color Management installed in order to \
calibrate devices"); + } else if (kind == QLatin1String("display")) {
+ if (m_sensors.isEmpty()) {
+ toolTip = i18n("The measuring instrument is not detected. Please check \
it is turned on and correctly connected."); + } else {
+ ret = true;
+ }
+ } else if (kind == QLatin1String("camera") ||
+ kind == QLatin1String("scanner") ||
+ kind == QLatin1String("webcam")) {
+ ret = true;
+ } else if (kind == QLatin1String("printer")) {
+ // Check if we have any sensor
+ if (m_sensors.isEmpty()) {
+ toolTip = i18n("The measuring instrument is not detected. Please check \
it is turned on and correctly connected."); + } else {
+ // Search for a suitable sensor
+ foreach (const QDBusObjectPath &sensorPath, m_sensors) {
+ QDBusInterface \
sensorInterface(QLatin1String("org.freedesktop.ColorManager"), + \
sensorPath.path(), + \
QLatin1String("org.freedesktop.ColorManager.Sensor"), + \
QDBusConnection::systemBus(), + this);
+ if (!sensorInterface.isValid()) {
+ continue;
+ }
+
+ QStringList capabilities = \
sensorInterface.property("Capabilities").toStringList(); + if \
(capabilities.contains(QLatin1String("printer"))) { + ret = true;
+ break;
+ }
+ }
+
+ // If we do not found a suitable sensor place a proper tool tip
+ if (!ret) {
+ toolTip = i18n("The measuring instrument does not support printer \
profiling."); + }
+ }
+ } else {
+ toolTip = i18n("The device type is not currently supported.");
+ }
+
+ ui->calibratePB->setToolTip(toolTip);
+ return ret;
+}
+
#include "Description.moc"
diff --git a/colord-kcm/Description.h b/colord-kcm/Description.h
index 2678221..ddeeddc 100644
--- a/colord-kcm/Description.h
+++ b/colord-kcm/Description.h
@@ -22,6 +22,7 @@
#include <QWidget>
#include <QDBusObjectPath>
+#include <QDBusMessage>
namespace Ui {
class Description;
@@ -39,19 +40,29 @@ public:
void setProfile(const QDBusObjectPath &objectPath);
void setDevice(const QDBusObjectPath &objectPath);
+public slots:
+ void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, \
const QString &newOwner); +
private slots:
void on_installSystemWideBt_clicked();
void on_calibratePB_clicked();
+ void gotSensors(const QDBusMessage &message);
+ void sensorAdded(const QDBusObjectPath &sensorPath, bool updateCalibrateButton = \
true); + void sensorRemoved(const QDBusObjectPath &sensorPath, bool \
updateCalibrateButton = true); +
private:
void insertTab(int index, QWidget *widget, const QString &label);
void removeTab(QWidget *widget);
+ bool calibrateEnabled(const QString &kind);
Ui::Description *ui;
QDBusObjectPath m_currentProfile;
QString m_currentDeviceId;
+ QString m_currentDeviceKind;
ProfileNamedColors *m_namedColors;
ProfileMetaData *m_metadata;
+ QList<QDBusObjectPath> m_sensors;
};
#endif // DESCRIPTION_H
diff --git a/colord-kcm/DeviceModel.cpp b/colord-kcm/DeviceModel.cpp
index 1d5c542..8bf8c0a 100644
--- a/colord-kcm/DeviceModel.cpp
+++ b/colord-kcm/DeviceModel.cpp
@@ -28,7 +28,6 @@
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusReply>
-#include <QtDBus/QDBusServiceWatcher>
#include <QStringBuilder>
#include <KDebug>
@@ -57,15 +56,6 @@ DeviceModel::DeviceModel(QObject *parent) :
connect(interface, SIGNAL(DeviceChanged(QDBusObjectPath)),
this, SLOT(deviceChanged(QDBusObjectPath)));
- // Make sure we know is colord is running
- QDBusServiceWatcher *watcher;
- watcher = new QDBusServiceWatcher("org.freedesktop.ColorManager",
- QDBusConnection::systemBus(),
- QDBusServiceWatcher::WatchForOwnerChange,
- this);
- connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
- this, SLOT(serviceOwnerChanged(QString,QString,QString)));
-
// Ask for devices
QDBusMessage message;
message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.ColorManager"),
@@ -192,7 +182,8 @@ void DeviceModel::deviceAdded(const QDBusObjectPath &objectPath, \
bool emitChange if (kind == QLatin1String("display")) {
kind = QLatin1String("display-device");
} else if (kind == QLatin1String("camera") ||
- kind == QLatin1String("scanner")) {
+ kind == QLatin1String("scanner") ||
+ kind == QLatin1String("webcam")) {
kind = "input-device";
} else if (kind == QLatin1String("printer")) {
kind = "output-device";
diff --git a/colord-kcm/DeviceModel.h b/colord-kcm/DeviceModel.h
index b19239d..bc6b7d4 100644
--- a/colord-kcm/DeviceModel.h
+++ b/colord-kcm/DeviceModel.h
@@ -47,6 +47,9 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role = \
Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = \
Qt::EditRole);
+public slots:
+ void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, \
const QString &newOwner); +
signals:
void changed();
@@ -55,7 +58,6 @@ private slots:
void deviceChanged(const QDBusObjectPath &objectPath);
void deviceAdded(const QDBusObjectPath &objectPath, bool emitChanged = true);
void deviceRemoved(const QDBusObjectPath &objectPath);
- void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, \
const QString &newOwner);
private:
QStandardItem* createProfileItem(const QDBusObjectPath &objectPath,
diff --git a/colord-kcm/ProfileModel.cpp b/colord-kcm/ProfileModel.cpp
index 34a4abf..243b7f1 100644
--- a/colord-kcm/ProfileModel.cpp
+++ b/colord-kcm/ProfileModel.cpp
@@ -26,7 +26,6 @@
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusReply>
#include <QtDBus/QDBusArgument>
-#include <QtDBus/QDBusServiceWatcher>
#include <QStringBuilder>
#include <QFileInfo>
@@ -59,15 +58,6 @@ ProfileModel::ProfileModel(QObject *parent) :
connect(interface, SIGNAL(ProfileChanged(QDBusObjectPath)),
this, SLOT(profileChanged(QDBusObjectPath)));
- // Make sure we know is colord is running
- QDBusServiceWatcher *watcher;
- watcher = new QDBusServiceWatcher("org.freedesktop.ColorManager",
- QDBusConnection::systemBus(),
- QDBusServiceWatcher::WatchForOwnerChange,
- this);
- connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
- this, SLOT(serviceOwnerChanged(QString,QString,QString)));
-
// Ask for profiles
QDBusMessage message;
message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.ColorManager"),
diff --git a/colord-kcm/ProfileModel.h b/colord-kcm/ProfileModel.h
index 8f6d01e..c360730 100644
--- a/colord-kcm/ProfileModel.h
+++ b/colord-kcm/ProfileModel.h
@@ -49,6 +49,9 @@ public:
static QChar getSortChar(const QString &kind);
static QString getProfileDataSource(const QDBusObjectPath &objectPath);
+public slots:
+ void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, \
const QString &newOwner); +
signals:
void changed();
@@ -57,7 +60,6 @@ private slots:
void profileChanged(const QDBusObjectPath &objectPath);
void profileAdded(const QDBusObjectPath &objectPath, bool emitChanged = true);
void profileRemoved(const QDBusObjectPath &objectPath);
- void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, \
const QString &newOwner);
private:
int findItem(const QDBusObjectPath &objectPath);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic