diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2011-09-26 02:36:09 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2011-09-26 02:36:09 +0200 |
commit | 0822b88738e00625efd27ccca9119885272924d2 (patch) | |
tree | f379817602cc23dd829c0aa4751b6b5edc348923 | |
parent | cf5d24b94d96b722c6d76c2225293a56a50d3c2b (diff) | |
download | sowatch-0822b88738e00625efd27ccca9119885272924d2.tar.gz sowatch-0822b88738e00625efd27ccca9119885272924d2.zip |
fixing bugs found during use ;)
-rw-r--r-- | ckitcallnotification/ckitcallprovider.cpp | 8 | ||||
-rw-r--r-- | libsowatch/declarativewatchlet.cpp | 9 | ||||
-rw-r--r-- | libsowatch/graphicswatchlet.cpp | 18 | ||||
-rw-r--r-- | libsowatch/graphicswatchlet.h | 9 | ||||
-rw-r--r-- | libsowatch/libsowatch.pro | 4 | ||||
-rw-r--r-- | libsowatch/testdeclarativewatchlet.cpp | 9 | ||||
-rw-r--r-- | libsowatch/testdeclarativewatchlet.h | 19 | ||||
-rw-r--r-- | libsowatch/watchpaintengine.cpp | 31 | ||||
-rw-r--r-- | libsowatch/watchpaintengine.h | 12 | ||||
-rw-r--r-- | libsowatch/watchserver.cpp | 12 | ||||
-rw-r--r-- | metawatch/metawatch.cpp | 100 | ||||
-rw-r--r-- | metawatch/metawatchpaintengine.cpp | 15 | ||||
-rw-r--r-- | metawatch/metawatchpaintengine.h | 3 |
13 files changed, 135 insertions, 114 deletions
diff --git a/ckitcallnotification/ckitcallprovider.cpp b/ckitcallnotification/ckitcallprovider.cpp index 90dab97..acfcca3 100644 --- a/ckitcallnotification/ckitcallprovider.cpp +++ b/ckitcallnotification/ckitcallprovider.cpp @@ -22,8 +22,8 @@ void CKitCallProvider::activeCallChanged() { QVariantMap info = _activeCall->value().toMap(); qDebug() << "active call changed" << info; - if (!info.contains("state")) { - qWarning() << "broken active call context property"; + if (!info.contains("state") || !info.value("status", false).toBool()) { + return; // Ignore until we get a map with all the required properties. } int state = info["state"].toInt(); if (state == 0) { @@ -34,13 +34,15 @@ void CKitCallProvider::activeCallChanged() } // "Incoming call" if (_notification) { + // An existing incoming call has been updated _notification->changeDisplayName(displayName); } else { + // This is a new incoming call _notification = new CKitCallNotification(displayName, this); emit incomingNotification(_notification); } } else { - // Call is either answered, dropped, missed, .. + // Call has either been answered, rejected, missed, .. if (_notification) { _notification->clear(); _notification->deleteLater(); diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp index 60538f8..ca60fb0 100644 --- a/libsowatch/declarativewatchlet.cpp +++ b/libsowatch/declarativewatchlet.cpp @@ -66,15 +66,14 @@ QDeclarativeContext* DeclarativeWatchlet::rootContext() void DeclarativeWatchlet::activate() { - Watchlet::activate(); + GraphicsWatchlet::activate(); _wrapper->activate(); - _scene->update(); } void DeclarativeWatchlet::deactivate() { - Watchlet::deactivate(); _wrapper->deactivate(); + GraphicsWatchlet::deactivate(); } void DeclarativeWatchlet::handleComponentStatus(QDeclarativeComponent::Status status) @@ -90,7 +89,7 @@ void DeclarativeWatchlet::handleComponentStatus(QDeclarativeComponent::Status st case QDeclarativeComponent::Ready: obj = _component->create(); if (_component->isError()) { - qWarning() << "QML has instantation errors:"; + qWarning() << "QML has errors found while creating:"; qWarning() << _component->errors(); return; } @@ -99,7 +98,7 @@ void DeclarativeWatchlet::handleComponentStatus(QDeclarativeComponent::Status st scene()->addItem(_item); break; case QDeclarativeComponent::Error: - qWarning() << "QML has errors:"; + qWarning() << "QML has errors found while loading:"; qWarning() << _component->errors(); break; } diff --git a/libsowatch/graphicswatchlet.cpp b/libsowatch/graphicswatchlet.cpp index 538723a..195d11b 100644 --- a/libsowatch/graphicswatchlet.cpp +++ b/libsowatch/graphicswatchlet.cpp @@ -1,4 +1,5 @@ #include <QtCore/QDebug> +#include <QtCore/QEvent> #include <QtGui/QPainter> #include "watch.h" @@ -30,18 +31,25 @@ void GraphicsWatchlet::setScene(QGraphicsScene *scene) void GraphicsWatchlet::sceneChanged(const QList<QRectF> ®ion) { - foreach(const QRectF& r, region) - { + foreach(const QRectF& r, region) { _damaged += r.toRect(); } - if (!_damaged.isEmpty() && _active && !watch()->busy()) { const QVector<QRect> rects = _damaged.rects(); QPainter p(watch()); - foreach(const QRect& r, rects) - { + + foreach(const QRect& r, rects) { _scene->render(&p, r, r, Qt::IgnoreAspectRatio); } _damaged = QRegion(); } } + +void GraphicsWatchlet::activate() +{ + Watchlet::activate(); + // We have to assume that the watch has completely forgot about everything. + QRect area(0, 0, watch()->width(), watch()->height()); + _damaged += area; + _scene->update(area); +} diff --git a/libsowatch/graphicswatchlet.h b/libsowatch/graphicswatchlet.h index 37752a9..3202631 100644 --- a/libsowatch/graphicswatchlet.h +++ b/libsowatch/graphicswatchlet.h @@ -18,13 +18,14 @@ public: QGraphicsScene* scene(); void setScene(QGraphicsScene* scene); -protected: - QGraphicsScene* _scene; - QRegion _damaged; - protected slots: void sceneChanged(const QList<QRectF>& region); +protected: + void activate(); + + QGraphicsScene* _scene; + QRegion _damaged; }; } diff --git a/libsowatch/libsowatch.pro b/libsowatch/libsowatch.pro index 44458c2..5ab1f3b 100644 --- a/libsowatch/libsowatch.pro +++ b/libsowatch/libsowatch.pro @@ -20,7 +20,6 @@ SOURCES += \ watchlet.cpp \ watch.cpp \ testwatchlet.cpp \ - testdeclarativewatchlet.cpp \ graphicswatchlet.cpp \ declarativewatchwrapper.cpp \ declarativewatchlet.cpp \ @@ -37,7 +36,6 @@ HEADERS +=\ watchlet.h \ watch.h \ testwatchlet.h \ - testdeclarativewatchlet.h \ sowatch.h \ graphicswatchlet.h \ declarativewatchwrapper.h \ @@ -93,3 +91,5 @@ unix:!symbian { + + diff --git a/libsowatch/testdeclarativewatchlet.cpp b/libsowatch/testdeclarativewatchlet.cpp deleted file mode 100644 index 432d525..0000000 --- a/libsowatch/testdeclarativewatchlet.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "testdeclarativewatchlet.h" - -using namespace sowatch; - -TestDeclarativeWatchlet::TestDeclarativeWatchlet(WatchServer* server) : - DeclarativeWatchlet(server, "com.javispedro.sowatch.testdeclarativewatchlet") -{ - setSource(QUrl("qrc:/testdeclarativewatchlet.qml")); -} diff --git a/libsowatch/testdeclarativewatchlet.h b/libsowatch/testdeclarativewatchlet.h deleted file mode 100644 index a200663..0000000 --- a/libsowatch/testdeclarativewatchlet.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef SOWATCH_TESTDECLARATIVEWATCHLET_H -#define SOWATCH_TESTDECLARATIVEWATCHLET_H - -#include "declarativewatchlet.h" - -namespace sowatch -{ - -class TestDeclarativeWatchlet : public DeclarativeWatchlet -{ - Q_OBJECT -public: - explicit TestDeclarativeWatchlet(WatchServer* server); - -}; - -} - -#endif // SOWATCH_TESTDECLARATIVEWATCHLET_H diff --git a/libsowatch/watchpaintengine.cpp b/libsowatch/watchpaintengine.cpp index 6c509cb..90ad8bf 100644 --- a/libsowatch/watchpaintengine.cpp +++ b/libsowatch/watchpaintengine.cpp @@ -1,19 +1,40 @@ #include <QtCore/QDebug> #include <math.h> -#include "watch.h" #include "watchpaintengine.h" using namespace sowatch; -WatchPaintEngine::WatchPaintEngine(Watch* watch) +WatchPaintEngine::WatchPaintEngine() : QPaintEngine(QPaintEngine::AllFeatures), - _watch(watch), _painter(), - _hasPen(false), _hasBrush(false), _clipEnabled(false) + _painter() { } +WatchPaintEngine::~WatchPaintEngine() +{ + +} + +bool WatchPaintEngine::begin(QPaintDevice *pdev) +{ + _damaged = QRegion(); + _area = QRect(0, 0, pdev->width(), pdev->height()); + _hasPen = false; + _penWidth = 0.0; + _hasBrush = false; + _clipEnabled = false; + _clipRegion = _area; + + return _painter.begin(pdev); +} + +bool WatchPaintEngine::end() +{ + return _painter.end(); +} + void WatchPaintEngine::damageMappedRect(const QRect &r) { if (_clipEnabled) { @@ -57,7 +78,7 @@ void WatchPaintEngine::updateClipRegion(const QRegion& region, Qt::ClipOperation switch(op) { case Qt::NoClip: _clipEnabled = false; - _clipRegion = QRegion(0, 0, _watch->width(), _watch->height()); + _clipRegion = _area; break; case Qt::ReplaceClip: _clipEnabled = true; diff --git a/libsowatch/watchpaintengine.h b/libsowatch/watchpaintengine.h index 74d4e09..7a97ad7 100644 --- a/libsowatch/watchpaintengine.h +++ b/libsowatch/watchpaintengine.h @@ -6,12 +6,14 @@ namespace sowatch { -class Watch; - class WatchPaintEngine : public QPaintEngine { public: - WatchPaintEngine(Watch* watch); + ~WatchPaintEngine(); + + /* You are supposed to override these two functions. */ + bool begin(QPaintDevice *pdev); + bool end(); void drawEllipse(const QRectF &r); void drawEllipse(const QRect &r); @@ -33,15 +35,17 @@ public: void updateState(const QPaintEngineState &state); protected: + WatchPaintEngine(); + void damageMappedRect(const QRect& r); void damageRect(const QRect& r); void damageRect(const QRectF& r); void damagePenStroke(const QLineF& line); void updateClipRegion(const QRegion& region, Qt::ClipOperation op); - Watch* _watch; QPainter _painter; QRegion _damaged; + QRect _area; bool _hasPen; qreal _penWidth; diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index 07e4609..c81d937 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -68,6 +68,7 @@ void WatchServer::runWatchlet(const QString& id) void WatchServer::closeWatchlet() { if (_currentWatchlet) { + qDebug() << "deactivating watchlet" << _currentWatchlet->id(); _currentWatchlet->deactivate(); _currentWatchlet = 0; if (_watch->isConnected() && _pendingNotifications.empty()) { @@ -183,13 +184,13 @@ void WatchServer::notificationReceived(Notification *notification) connect(notification, SIGNAL(changed()), SLOT(notificationChanged())); connect(notification, SIGNAL(cleared()), SLOT(notificationCleared())); - qDebug() << "notification received" << notification->title() << notification->count(); + qDebug() << "notification received" << notification->title() << "(" << notification->count() << ")"; _watch->updateNotificationCount(type, getNotificationCount(type)); QDateTime oldThreshold = QDateTime::currentDateTime().addSecs(-_oldNotificationThreshold); if (notification->dateTime() < oldThreshold) { - return; // Do not care about that old notifications... + return; // Do not care about notifications that old... } if (_pendingNotifications.isEmpty()) { @@ -211,7 +212,7 @@ void WatchServer::notificationChanged() Notification* n = static_cast<Notification*>(obj); const Notification::Type type = n->type(); - qDebug() << "notification changed" << n->title() << n->count(); + qDebug() << "notification changed" << n->title() << "(" << n->count() << ")"; _watch->updateNotificationCount(type, getNotificationCount(type)); if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) { @@ -228,11 +229,12 @@ void WatchServer::notificationCleared() const Notification::Type type = n->type(); _notifications[type].removeOne(n); - qDebug() << "notification deleted" << n->title() << n->count(); + qDebug() << "notification deleted" << n->title() << "(" << n->count() << ")"; _watch->updateNotificationCount(type, getNotificationCount(type)); - if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) {qDebug() << "removing top notification"; + if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) { + qDebug() << "removing top notification"; _pendingNotifications.removeAll(n); nextNotification(); } else { diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp index 1ad7159..e1d9780 100644 --- a/metawatch/metawatch.cpp +++ b/metawatch/metawatch.cpp @@ -238,6 +238,11 @@ void MetaWatch::displayNotification(Notification *n) QFont lf("MetaWatch Large 16pt"); QFont mf("MetaWatch Large 16pt"); QImage icon = iconForNotification(n); + + sf.setPixelSize(8); + mf.setPixelSize(14); + lf.setPixelSize(16); + const int iconW = icon.width(), iconH = icon.height(); const int margin = 4; const int x = margin; @@ -247,10 +252,6 @@ void MetaWatch::displayNotification(Notification *n) int textFlags; QString text; - sf.setPixelSize(8); - mf.setPixelSize(16); - lf.setPixelSize(18); - qDebug() << "displayNotification" << n->title() << n->body(); p.begin(this); @@ -267,7 +268,7 @@ void MetaWatch::displayNotification(Notification *n) p.drawText(dateRect, textFlags, text); p.setFont(lf); - textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere; + textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap; text = n->title(); QRect titleMaxRect(x, titleY, screenWidth - x*2, screenHeight - titleY); @@ -607,6 +608,8 @@ void MetaWatch::updateLines(Mode mode, const QImage& image, const QVector<bool>& if (lineCount == 0) return; + qDebug() << "sending" << lineCount << "rows to watch"; + for (int line = 0; line < lines.size(); line++) { if (lines[line]) { lineCount--; @@ -690,6 +693,7 @@ void MetaWatch::disableButton(Mode mode, Button button, ButtonPress press) void MetaWatch::handleStatusChange(const Message &msg) { Q_UNUSED(msg); + qDebug() << "got status change message"; } void MetaWatch::handleButtonEvent(const Message &msg) @@ -700,7 +704,7 @@ void MetaWatch::handleButtonEvent(const Message &msg) } quint8 watchBtn = msg.options & 0xF; - ButtonPress press = (ButtonPress) ((msg.options & 0x30) >> 4); + ButtonPress press = static_cast<ButtonPress>((msg.options & 0x30) >> 4); int button = -1; if (watchBtn < 8) { @@ -785,52 +789,58 @@ void MetaWatch::socketDisconnected() void MetaWatch::socketData() { - qint64 dataRead; + do { + qint64 dataRead; - if (_partialReceived.type == 0) { - /* Still not received even the packet type */ - /* Receive the full header, 4 bytes. */ - if (_socket->bytesAvailable() < 4) return; /* Wait for more. */ - char header[4]; + qDebug() << "received" << _socket->bytesAvailable() << "bytes"; - dataRead = _socket->read(header, 4); - if (dataRead < 4 || header[0] != 0x01) { - qWarning() << "TODO: Resync / Handle Garbage"; - return; - } + if (_partialReceived.type == 0) { + /* Still not received even the packet type */ + /* Receive the full header, 4 bytes. */ + if (_socket->bytesAvailable() < 4) return; /* Wait for more. */ + char header[4]; - _partialReceived.type = static_cast<MessageType>(header[2]); - _partialReceived.data.resize(header[1] - 6); - _partialReceived.options = header[3]; - } + dataRead = _socket->read(header, 4); + if (dataRead < 4 || header[0] != 0x01) { + qWarning() << "TODO: Resync to start of frame"; + return; + } - /* Got the header; now, try to get the complete packet. */ - if (_socket->bytesAvailable() < _partialReceived.data.size() + 2) { - return; /* Wait for more. */ - } - dataRead = _socket->read(_partialReceived.data.data(), _partialReceived.data.size()); - if (dataRead < _partialReceived.data.size()) { - qWarning() << "Short read"; - return; - } + _partialReceived.type = static_cast<MessageType>(header[2]); + _partialReceived.data.resize(header[1] - 6); + _partialReceived.options = header[3]; + qDebug() << "got header"; + } - char tail[2]; - dataRead = _socket->read(tail, 2); - if (dataRead < 2) { - qWarning() << "Short read"; - return; - } + /* We have the header; now, try to get the complete packet. */ + if (_socket->bytesAvailable() < _partialReceived.data.size() + 2) { + return; /* Wait for more. */ + } + dataRead = _socket->read(_partialReceived.data.data(), _partialReceived.data.size()); + if (dataRead < _partialReceived.data.size()) { + qWarning() << "Short read"; + return; + } - quint16 realCrc = calcCrc(_partialReceived); - quint16 expectedCrc = tail[1] << 8 | (tail[0] & 0xFFU); - if (realCrc == expectedCrc) { - handleMessage(_partialReceived); - } else { - qWarning() << "CRC error?"; - } + char tail[2]; + dataRead = _socket->read(tail, 2); + if (dataRead < 2) { + qWarning() << "Short read"; + return; + } - _partialReceived.data.clear(); - _partialReceived.type = NoMessage; + quint16 realCrc = calcCrc(_partialReceived); + quint16 expectedCrc = tail[1] << 8 | (tail[0] & 0xFFU); + if (realCrc == expectedCrc) { + handleMessage(_partialReceived); + } else { + qWarning() << "CRC error?"; + } + + // Prepare for the next packet + _partialReceived.data.clear(); + _partialReceived.type = NoMessage; + } while (_socket->bytesAvailable() > 0); } void MetaWatch::socketError(QBluetoothSocket::SocketError error) diff --git a/metawatch/metawatchpaintengine.cpp b/metawatch/metawatchpaintengine.cpp index 58a7b9d..1b449ab 100644 --- a/metawatch/metawatchpaintengine.cpp +++ b/metawatch/metawatchpaintengine.cpp @@ -3,24 +3,25 @@ using namespace sowatch; +const QRect MetaWatchPaintEngine::totalAreaRect(0, 0, MetaWatch::screenWidth, MetaWatch::screenHeight); + MetaWatchPaintEngine::MetaWatchPaintEngine(MetaWatch* watch) : - WatchPaintEngine(watch), _watch(watch), - _imageRect(0, 0, MetaWatch::screenWidth, MetaWatch::screenHeight) + WatchPaintEngine(), + _watch(watch) { } bool MetaWatchPaintEngine::begin(QPaintDevice *pdev) { - _damaged = QRegion(); _watch = static_cast<MetaWatch*>(pdev); _mode = _watch->paintTargetMode(); - return _painter.begin(_watch->imageFor(_mode)); + return WatchPaintEngine::begin(_watch->imageFor(_mode)); } bool MetaWatchPaintEngine::end() { - bool ret = _painter.end(); + bool ret = WatchPaintEngine::end(); if (ret) { _watch->update(_mode, _damaged.rects().toList()); } @@ -94,7 +95,7 @@ void MetaWatchPaintEngine::updateState(const QPaintEngineState &state) bool MetaWatchPaintEngine::fillsEntireImage(const QRect& rect) { - return rect == _imageRect && + return rect == totalAreaRect && (!_clipEnabled || - (_clipRegion.numRects() == 1 && _clipRegion.rects().at(0) == _imageRect)); + (_clipRegion.numRects() == 1 && _clipRegion.rects().at(0) == totalAreaRect)); } diff --git a/metawatch/metawatchpaintengine.h b/metawatch/metawatchpaintengine.h index c3b7466..98e85bb 100644 --- a/metawatch/metawatchpaintengine.h +++ b/metawatch/metawatchpaintengine.h @@ -25,9 +25,10 @@ public: protected: bool fillsEntireImage(const QRect& rect); + static const QRect totalAreaRect; + MetaWatch* _watch; MetaWatch::Mode _mode; - QRect _imageRect; bool _isBrushBlack; bool _isBrushWhite; }; |