diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-05-14 01:13:41 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-05-14 01:13:41 +0200 |
commit | 80c58c124caf17f670d8efc120f5ae4bfd9aa09f (patch) | |
tree | c6d036f06437e54f80afd65e1a700a018cab994b /liveview | |
parent | c3392e5d539e87f4720b3d107aaefffdc9579f4d (diff) | |
download | sowatch-80c58c124caf17f670d8efc120f5ae4bfd9aa09f.tar.gz sowatch-80c58c124caf17f670d8efc120f5ae4bfd9aa09f.zip |
added liveview watchlet menu (API break)
Diffstat (limited to 'liveview')
-rw-r--r-- | liveview/liveview.cpp | 117 | ||||
-rw-r--r-- | liveview/liveview.h | 17 | ||||
-rw-r--r-- | liveview/liveviewpaintengine.cpp | 4 |
3 files changed, 105 insertions, 33 deletions
diff --git a/liveview/liveview.cpp b/liveview/liveview.cpp index 746c04a..c36f944 100644 --- a/liveview/liveview.cpp +++ b/liveview/liveview.cpp @@ -16,6 +16,7 @@ LiveView::LiveView(ConfigKey* settings, QObject* parent) : _screenWidth(0), _screenHeight(0), _mode(RootMenuMode), _paintEngine(0), + _rootMenuFirstWatchlet(0), _sendTimer(new QTimer(this)) { _sendTimer->setInterval(DelayBetweenMessages); @@ -90,6 +91,7 @@ void LiveView::setDateTime(const QDateTime& dateTime) // the phone to be sending it. // Wonder what will happen during DST changes? // Do nothing here. + Q_UNUSED(dateTime); } void LiveView::queryDateTime() @@ -154,6 +156,7 @@ void LiveView::setWatchletsModel(WatchletsModel *model) _watchlets = model; if (_watchlets) { connect(_watchlets, SIGNAL(modelChanged()), SLOT(handleWatchletsChanged())); + handleWatchletsChanged(); } } @@ -164,13 +167,9 @@ QImage* LiveView::image() void LiveView::renderImage(int x, int y, const QImage &image) { - QBuffer buffer; - buffer.open(QIODevice::WriteOnly); - if (image.save(&buffer, "PNG")) { - displayBitmap(x, y, buffer.buffer()); - qDebug() << "render image at" << x << 'x' << y << "size" << image.size(); - } else { - qWarning() << "Failed to encode image"; + QByteArray data = encodeImage(image); + if (!data.isEmpty()) { + displayBitmap(x, y, data); } } @@ -194,10 +193,62 @@ void LiveView::desetupBluetoothWatch() _sendingMsgs.clear(); } +void LiveView::recreateWatchletsMenu() +{ + // Erase all current watchlets frm the menu + QList<RootMenuItem>::iterator it = _rootMenu.begin(); + it += _rootMenuFirstWatchlet; + _rootMenu.erase(it, _rootMenu.end()); + + if (_watchlets) { + const int num_watchlets = _watchlets->size(); + for (int i = 0; i < num_watchlets; i++) { + RootMenuItem item; + QModelIndex index = _watchlets->index(i); + item.type = MenuOther; + item.title = _watchlets->data(index, WatchletsModel::TitleRole).toString(); + item.icon = encodeImage(_watchlets->data(index, WatchletsModel::IconRole).toUrl()); + item.unread = 0; + item.watchletId = _watchlets->at(i)->id(); + _rootMenu.append(item); + } + } +} + void LiveView::refreshMenu() { if (_mode == RootMenuMode) { - setMenuSize(3); + setMenuSize(_rootMenu.size()); + } +} + +QByteArray LiveView::encodeImage(const QImage& image) const +{ + QBuffer buffer; + buffer.open(QIODevice::WriteOnly); + if (image.save(&buffer, "PNG")) { + return buffer.buffer(); + } else { + qWarning() << "Failed to encode image"; + return QByteArray(); + } +} + +QByteArray LiveView::encodeImage(const QUrl& url) const +{ + if (url.encodedPath().endsWith(".png")) { + // Just load the image + QFile f(url.toLocalFile()); + if (f.open(QIODevice::ReadOnly)) { + qDebug() << "Encoding local PNG" << url.toLocalFile(); + return f.readAll(); + } else { + qWarning() << "Could not read image:" << url.toString(); + return QByteArray(); + } + } else { + qDebug() << "Encoding local nonPNG" << url.toLocalFile(); + return encodeImage(QImage(url.toLocalFile())); } } @@ -359,13 +410,11 @@ void LiveView::handleNavigation(const Message &msg) return; } - int menu_id = msg.data[4]; - int item_id = msg.data[3]; - int event = msg.data[2]; + int menu_id = static_cast<unsigned char>(msg.data[4]); + int item_id = static_cast<unsigned char>(msg.data[3]); + int event = static_cast<unsigned char>(msg.data[2]); qDebug() << "navigation" << event << item_id << menu_id; - - switch (event) { case SelectLongPress: if (_mode == ApplicationMode) { @@ -375,8 +424,22 @@ void LiveView::handleNavigation(const Message &msg) } break; case SelectMenu: - sendResponse(NavigationResponse, ResponseOk); - emit watchletRequested("com.javispedro.sowatch.neko"); + if (item_id <= _rootMenu.size()) { + sendResponse(NavigationResponse, ResponseError); + + switch(_rootMenu[item_id].type) { + case MenuNotificationList: + Q_ASSERT(false); // TODO + break; + case MenuOther: + emit watchletRequested(_rootMenu[item_id].watchletId); + break; + } + + } else { + sendResponse(NavigationResponse, ResponseError); + } + return; } @@ -387,22 +450,13 @@ void LiveView::handleNavigation(const Message &msg) void LiveView::handleMenuItemsRequest(const Message &msg) { qDebug() << "Sending menu items"; - QFile icon_file; - - icon_file.setFileName(SOWATCH_RESOURCES_DIR "/liveview/graphics/menu_notifications.png"); - icon_file.open(QIODevice::ReadOnly); - sendMenuItem(0, MenuNotificationList, 2, tr("Notifications"), icon_file.readAll()); - icon_file.close(); - - icon_file.setFileName(SOWATCH_RESOURCES_DIR "/liveview/graphics/menu_missed_calls.png"); - icon_file.open(QIODevice::ReadOnly); - sendMenuItem(1, MenuNotificationList, 1, tr("Missed calls"), icon_file.readAll()); - icon_file.close(); - - icon_file.setFileName(SOWATCH_RESOURCES_DIR "/liveview/graphics/menu_messages.png"); - icon_file.open(QIODevice::ReadOnly); - sendMenuItem(2, MenuOther, 0, tr("Messages"), icon_file.readAll()); - icon_file.close(); + if (_mode == RootMenuMode) { + for (int i = 0; i < _rootMenu.size(); i++) { + qDebug() << "Sending one menu item"; + sendMenuItem(i, _rootMenu[i].type, _rootMenu[i].unread, + _rootMenu[i].title, _rootMenu[i].icon); + } + } } void LiveView::handleDateTimeRequest(const Message &msg) @@ -567,6 +621,7 @@ void LiveView::handleSendTimerTick() void LiveView::handleWatchletsChanged() { + recreateWatchletsMenu(); if (_connected) { refreshMenu(); } diff --git a/liveview/liveview.h b/liveview/liveview.h index bd8a3ac..4df7f10 100644 --- a/liveview/liveview.h +++ b/liveview/liveview.h @@ -120,12 +120,25 @@ protected: { } }; + struct RootMenuItem { + MenuItemType type; + QByteArray icon; + QString title; + int unread; + QString watchletId; + }; + void setupBluetoothWatch(); void desetupBluetoothWatch(); + /** Recreate the device menu (after watchlets change) */ + void recreateWatchletsMenu(); /** Update the device menu (after a power on, etc.) */ void refreshMenu(); + QByteArray encodeImage(const QImage& image) const; + QByteArray encodeImage(const QUrl& url) const; + protected: void send(const Message& msg); void sendResponse(MessageType type, ResponseType response); @@ -169,6 +182,10 @@ private: mutable LiveViewPaintEngine* _paintEngine; QImage _image; + QList<RootMenuItem> _rootMenu; + /** Keeps the index of the first watchlet. */ + int _rootMenuFirstWatchlet; + /** Message outbox queue. */ QQueue<Message> _sendingMsgs; QTimer* _sendTimer; diff --git a/liveview/liveviewpaintengine.cpp b/liveview/liveviewpaintengine.cpp index 1caa1e3..9f7ffec 100644 --- a/liveview/liveviewpaintengine.cpp +++ b/liveview/liveviewpaintengine.cpp @@ -35,7 +35,7 @@ void LiveViewPaintEngine::drawRects(const QRectF *rects, int rectCount) for (i = 0; i < rectCount; i++) { const QRectF& r = rects[i]; if (_hasBrush && fillsEntireImage(r.toRect()) && _isBrushBlack) { - _watch->clear(); + //_watch->clear(); _damaged = QRegion(); continue; } @@ -58,7 +58,7 @@ void LiveViewPaintEngine::drawRects(const QRect *rects, int rectCount) for (i = 0; i < rectCount; i++) { const QRect& r = rects[i]; if (_hasBrush && fillsEntireImage(r) && _isBrushBlack) { - _watch->clear(); + //_watch->clear(); _damaged = QRegion(); continue; } |