[Pkg-running-devel] [openambit] 37/131: * Added udev listener (to detect device connecting) * Added temporary icons
Christian Perrier
bubulle at moszumanska.debian.org
Thu Jul 17 20:19:09 UTC 2014
This is an automated email from the git hooks/post-receive script.
bubulle pushed a commit to branch master
in repository openambit.
commit 2947b62bcfb7eac3b7ce85f08623e8a924ca496d
Author: Emil Ljungdahl <emil at kratern.se>
Date: Sat Jan 11 13:57:55 2014 +0100
* Added udev listener (to detect device connecting)
* Added temporary icons
---
src/openambit/devicemanager.cpp | 7 +++-
src/openambit/devicemanager.h | 8 ++++-
src/openambit/icons/icon_connected.png | Bin 0 -> 907 bytes
src/openambit/icons/icon_disconnected.png | Bin 0 -> 934 bytes
src/openambit/icons/icon_sync.png | Bin 0 -> 1708 bytes
src/openambit/mainwindow.cpp | 13 ++++++++
src/openambit/mainwindow.h | 3 ++
src/openambit/mainwindow.ui | 8 ++++-
src/openambit/openambit.pro | 13 ++++++--
src/openambit/resources.qrc | 7 ++++
src/openambit/udevlistener.cpp | 51 ++++++++++++++++++++++++++++++
src/openambit/udevlistener.h | 29 +++++++++++++++++
12 files changed, 133 insertions(+), 6 deletions(-)
diff --git a/src/openambit/devicemanager.cpp b/src/openambit/devicemanager.cpp
index a9428a7..c45f5da 100644
--- a/src/openambit/devicemanager.cpp
+++ b/src/openambit/devicemanager.cpp
@@ -25,13 +25,14 @@
#include <libambit.h>
DeviceManager::DeviceManager(QObject *parent) :
- QObject(parent)
+ QObject(parent), deviceObject(NULL), udevListener(NULL)
{
movesCount = MovesCount::instance();
}
DeviceManager::~DeviceManager()
{
+ delete udevListener;
chargeTimer.stop();
}
@@ -40,6 +41,10 @@ void DeviceManager::start()
connect(&chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimerHit()));
chargeTimer.setInterval(10000);
chargeTimer.start();
+
+ // Connect udev listener, fire a chargeTimerHit (implicit device detect), if hit
+ udevListener = new UdevListener();
+ connect(udevListener, SIGNAL(deviceEvent()), this, SLOT(chargeTimerHit()));
}
void DeviceManager::detect()
diff --git a/src/openambit/devicemanager.h b/src/openambit/devicemanager.h
index 7f8a683..5b12301 100644
--- a/src/openambit/devicemanager.h
+++ b/src/openambit/devicemanager.h
@@ -27,13 +27,17 @@
#include <QMutex>
#include <QTimer>
#include <QMetaType>
+#include <QSocketNotifier>
#include "settings.h"
#include "logstore.h"
#include "movescount.h"
#include "movescountxml.h"
+#include "udevlistener.h"
#include <libambit.h>
+#include <libudev.h>
+
class DeviceManager : public QObject
{
Q_OBJECT
@@ -59,7 +63,9 @@ private:
static void log_push_cb(void *ref, ambit_log_entry_t *log_entry);
static void log_progress_cb(void *ref, uint16_t log_count, uint16_t log_current, uint8_t progress_percent);
- ambit_object_t *deviceObject = NULL;
+ ambit_object_t *deviceObject;
+ UdevListener *udevListener;
+
ambit_device_info_t currentDeviceInfo;
ambit_personal_settings_t currentPersonalSettings;
diff --git a/src/openambit/icons/icon_connected.png b/src/openambit/icons/icon_connected.png
new file mode 100644
index 0000000..6d9b68e
Binary files /dev/null and b/src/openambit/icons/icon_connected.png differ
diff --git a/src/openambit/icons/icon_disconnected.png b/src/openambit/icons/icon_disconnected.png
new file mode 100644
index 0000000..83869cb
Binary files /dev/null and b/src/openambit/icons/icon_disconnected.png differ
diff --git a/src/openambit/icons/icon_sync.png b/src/openambit/icons/icon_sync.png
new file mode 100644
index 0000000..187f792
Binary files /dev/null and b/src/openambit/icons/icon_sync.png differ
diff --git a/src/openambit/mainwindow.cpp b/src/openambit/mainwindow.cpp
index eec67a1..a341ef4 100644
--- a/src/openambit/mainwindow.cpp
+++ b/src/openambit/mainwindow.cpp
@@ -53,6 +53,10 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
+ // System tray icon
+ trayIcon = new QSystemTrayIcon(QIcon(":/icon_disconnected"));
+ trayIcon->show();
+
// Setup device manager
deviceManager = new DeviceManager();
deviceManager->moveToThread(&deviceWorkerThread);
@@ -123,6 +127,9 @@ void MainWindow::syncNowClicked()
settings.beginGroup("movescountSettings");
syncMovescount = settings.value("movescountEnable", true).toBool();
settings.endGroup();
+
+ trayIcon->setIcon(QIcon(":/icon_syncing"));
+
emit MainWindow::syncNow(ui->checkBoxResyncAll->isChecked(), syncTime, syncOrbit, syncMovescount);
}
@@ -168,6 +175,8 @@ void MainWindow::deviceDetected(ambit_device_info_t deviceInfo, bool supported)
settings.endGroup();
}
}
+
+ trayIcon->setIcon(QIcon(":/icon_connected"));
}
void MainWindow::deviceRemoved(void)
@@ -185,6 +194,8 @@ void MainWindow::deviceRemoved(void)
ui->checkBoxResyncAll->setHidden(true);
ui->buttonSyncNow->setHidden(true);
ui->syncProgressBar->setHidden(true);
+
+ trayIcon->setIcon(QIcon(":/icon_disconnected"));
}
void MainWindow::deviceCharge(quint8 percent)
@@ -214,6 +225,8 @@ void MainWindow::syncFinished(bool success)
ui->buttonSyncNow->setEnabled(true);
ui->syncProgressBar->setHidden(true);
+ trayIcon->setIcon(QIcon(":/icon_connected"));
+
updateLogList();
}
diff --git a/src/openambit/mainwindow.h b/src/openambit/mainwindow.h
index 301fdbf..3984c1e 100644
--- a/src/openambit/mainwindow.h
+++ b/src/openambit/mainwindow.h
@@ -30,6 +30,7 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
+#include <QSystemTrayIcon>
namespace Ui {
class MainWindow;
@@ -74,6 +75,8 @@ private:
void movesCountSetup();
Ui::MainWindow *ui;
+ QSystemTrayIcon *trayIcon;
+
Settings settings;
SettingsDialog *settingsDialog;
DeviceManager *deviceManager;
diff --git a/src/openambit/mainwindow.ui b/src/openambit/mainwindow.ui
index 8b76f79..72c3be5 100644
--- a/src/openambit/mainwindow.ui
+++ b/src/openambit/mainwindow.ui
@@ -13,6 +13,10 @@
<property name="windowTitle">
<string>openambit</string>
</property>
+ <property name="windowIcon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/icon_disconnected</normaloff>:/icon_disconnected</iconset>
+ </property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@@ -389,7 +393,9 @@
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
- <resources/>
+ <resources>
+ <include location="resources.qrc"/>
+ </resources>
<connections>
<connection>
<sender>actionE_xit</sender>
diff --git a/src/openambit/openambit.pro b/src/openambit/openambit.pro
index a039ae2..00cda6d 100644
--- a/src/openambit/openambit.pro
+++ b/src/openambit/openambit.pro
@@ -21,7 +21,8 @@ SOURCES += main.cpp\
logentry.cpp \
movescountxml.cpp \
movescountjson.cpp \
- movescount.cpp
+ movescount.cpp \
+ udevlistener.cpp
HEADERS += mainwindow.h \
devicemanager.h \
@@ -31,7 +32,8 @@ HEADERS += mainwindow.h \
logentry.h \
movescountxml.h \
movescountjson.h \
- movescount.h
+ movescount.h \
+ udevlistener.h
FORMS += mainwindow.ui \
settingsdialog.ui
@@ -39,4 +41,9 @@ FORMS += mainwindow.ui \
INCLUDEPATH += ../libambit
QMAKE_LIBDIR += ../libambit-build
-LIBS += -lambit -lqjson -lz
+LIBS += -lambit -lqjson -ludev -lz
+
+OTHER_FILES +=
+
+RESOURCES += \
+ resources.qrc
diff --git a/src/openambit/resources.qrc b/src/openambit/resources.qrc
new file mode 100644
index 0000000..3df1b93
--- /dev/null
+++ b/src/openambit/resources.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file alias="icon_syncing">icons/icon_sync.png</file>
+ <file alias="icon_connected">icons/icon_connected.png</file>
+ <file alias="icon_disconnected">icons/icon_disconnected.png</file>
+ </qresource>
+</RCC>
diff --git a/src/openambit/udevlistener.cpp b/src/openambit/udevlistener.cpp
new file mode 100644
index 0000000..b2a3381
--- /dev/null
+++ b/src/openambit/udevlistener.cpp
@@ -0,0 +1,51 @@
+#include "udevlistener.h"
+
+#define SUUNTO_USB_VENDOR_ID "1493"
+
+UdevListener::UdevListener(QObject *parent) :
+ QObject(parent)
+{
+ udev = udev_new();
+
+ if (!udev) {
+ return;
+ }
+
+ /* Set up a monitor to monitor hid devices */
+ mon = udev_monitor_new_from_netlink(udev, "udev");
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "hid", NULL);
+ udev_monitor_enable_receiving(mon);
+
+ fd = udev_monitor_get_fd(mon);
+
+ socketNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
+ connect(socketNotifier, SIGNAL(activated(int)), this, SLOT(fdActivated(int)));
+}
+
+UdevListener::~UdevListener()
+{
+ delete socketNotifier;
+
+ udev_monitor_unref(mon);
+ udev_unref(udev);
+}
+
+void UdevListener::fdActivated(int fd)
+{
+ struct udev_device *device;
+ const char *vendorId;
+
+ if (fd == this->fd) {
+ device = udev_monitor_receive_device(mon);
+
+ if (device != NULL) {
+ // Check vendor ID, if it matches Suunto, we issue a new device scan
+ vendorId = udev_device_get_sysattr_value(device, "idVendor");
+ if (vendorId != NULL && strcmp(vendorId, SUUNTO_USB_VENDOR_ID) == 0) {
+ emit deviceEvent();
+ }
+
+ udev_device_unref(device);
+ }
+ }
+}
diff --git a/src/openambit/udevlistener.h b/src/openambit/udevlistener.h
new file mode 100644
index 0000000..7b747e3
--- /dev/null
+++ b/src/openambit/udevlistener.h
@@ -0,0 +1,29 @@
+#ifndef UDEVLISTENER_H
+#define UDEVLISTENER_H
+
+#include <QObject>
+#include <QSocketNotifier>
+
+#include <libudev.h>
+
+class UdevListener : public QObject
+{
+ Q_OBJECT
+public:
+ explicit UdevListener(QObject *parent = 0);
+ ~UdevListener();
+
+signals:
+ void deviceEvent();
+
+private slots:
+ void fdActivated(int fd);
+
+private:
+ struct udev *udev;
+ struct udev_monitor *mon;
+ int fd;
+ QSocketNotifier *socketNotifier;
+};
+
+#endif // UDEVLISTENER_H
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-running/openambit.git
More information about the Pkg-running-devel
mailing list