From 77a98ac21c2520d9fb4bb9c8f70967a8e36dc872 Mon Sep 17 00:00:00 2001
From: "Javier S. Pedro" <maemo@javispedro.com>
Date: Mon, 19 Sep 2011 01:51:04 +0200
Subject: adding notification provider plugins, idle screen

---
 metawatch/metawatch.cpp               |  92 ++++++++++++++++++++++++++++------
 metawatch/metawatch.h                 |   5 ++
 metawatch/metawatch.pro               |  14 +++++-
 metawatch/metawatch_16pt_11pxl.ttf    | Bin 0 -> 14576 bytes
 metawatch/metawatch_8pt_5pxl_CAPS.ttf | Bin 0 -> 12408 bytes
 metawatch/metawatch_8pt_7pxl_CAPS.ttf | Bin 0 -> 15212 bytes
 metawatch/metawatchplugin.cpp         |  14 ++++++
 metawatch/metawatchplugin.h           |   4 ++
 metawatch/uires.qrc                   |  13 ++++-
 metawatch/weather_cloudy.bmp          | Bin 0 -> 158 bytes
 metawatch/weather_rain.bmp            | Bin 0 -> 158 bytes
 metawatch/weather_snow.bmp            | Bin 0 -> 158 bytes
 metawatch/weather_sunny.bmp           | Bin 0 -> 158 bytes
 metawatch/weather_thunderstorm.bmp    | Bin 0 -> 158 bytes
 metawatch/weather_wind.bmp            | Bin 0 -> 158 bytes
 15 files changed, 124 insertions(+), 18 deletions(-)
 create mode 100644 metawatch/metawatch_16pt_11pxl.ttf
 create mode 100644 metawatch/metawatch_8pt_5pxl_CAPS.ttf
 create mode 100644 metawatch/metawatch_8pt_7pxl_CAPS.ttf
 create mode 100644 metawatch/weather_cloudy.bmp
 create mode 100644 metawatch/weather_rain.bmp
 create mode 100644 metawatch/weather_snow.bmp
 create mode 100644 metawatch/weather_sunny.bmp
 create mode 100644 metawatch/weather_thunderstorm.bmp
 create mode 100644 metawatch/weather_wind.bmp

(limited to 'metawatch')

diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp
index 08b9890..e6a28f4 100644
--- a/metawatch/metawatch.cpp
+++ b/metawatch/metawatch.cpp
@@ -85,7 +85,8 @@ MetaWatch::MetaWatch(const QBluetoothAddress& address, QObject *parent) :
 	_connectAlignedTimer(new QSystemAlignedTimer(this)),
 	_sendTimer(new QTimer(this)),
 	_currentMode(IdleMode),
-	_paintMode(IdleMode)
+	_paintMode(IdleMode),
+	_nMails(0), _nCalls(0), _nIms(0), _nSms(0)
 {
 	QImage baseImage(screenWidth, screenHeight, QImage::Format_MonoLSB);
 	baseImage.setColor(0, QColor(Qt::white).rgb());
@@ -191,8 +192,25 @@ void MetaWatch::setDateTime(const QDateTime &dateTime)
 
 void MetaWatch::updateNotificationCount(Notification::Type type, int count)
 {
-	Q_UNUSED(type);
-	Q_UNUSED(count); // TODO
+	switch (type) {
+	case Notification::MissedCallNotification:
+		_nCalls = count;
+		break;
+	case Notification::EmailNotification:
+		_nMails = count;
+		break;
+	case Notification::ImNotification:
+		_nIms = count;
+		break;
+	case Notification::SmsNotification:
+		_nSms = count;
+		break;
+	default:
+		// Ignore
+		break;
+	}
+
+	renderIdleCounts();
 }
 
 void MetaWatch::vibrate(bool on)
@@ -202,7 +220,7 @@ void MetaWatch::vibrate(bool on)
 
 void MetaWatch::showNotification(const Notification &n)
 {
-	Q_UNUSED(n); // TODO
+	qDebug() << "It's time for a notification" << n.title();
 }
 
 MetaWatch::Mode MetaWatch::currentMode() const
@@ -248,20 +266,64 @@ void MetaWatch::clear(Mode mode, bool black)
 void MetaWatch::renderIdleScreen()
 {
 	_paintMode = IdleMode;
+
+	QFont smallFont("MetaWatch Small caps 8pt", 6);
+	QImage idle_mail(QString(":/metawatch/graphics/idle_gmail.bmp"));
+	QImage idle_call(QString(":/metawatch/graphics/idle_call.bmp"));
+	QImage idle_sms(QString(":/metawatch/graphics/idle_sms.bmp"));
 	QPainter p(this);
+
 	p.fillRect(0, 0, screenWidth, screenHeight, Qt::white);
+
 	p.setPen(QPen(Qt::black, 1.0, Qt::DashLine));
-	p.drawLine(0, systemAreaHeight + 2, screenWidth, systemAreaHeight + 2);
-	p.drawLine(0, systemAreaHeight * 2 + 3, screenWidth, systemAreaHeight * 2 + 3);
-	p.setPen(Qt::black);
-	p.drawText(1, systemAreaHeight + 16, "Space Weather!");
-	QImage idle_mail(QString(":/metawatch/idle_gmail.bmp"));
-	QImage idle_call(QString(":/metawatch/idle_call.bmp"));
-	QImage idle_sms(QString(":/metawatch/idle_sms.bmp"));
-	p.drawImage(4, systemAreaHeight * 2 + 6, idle_mail);
-	p.drawImage(32 + 4, systemAreaHeight * 2 + 6, idle_call);
-	p.drawImage(32 * 2 + 4, systemAreaHeight * 2 + 6, idle_sms);
-	p.drawText(14, 93, "Too many!");
+	p.drawLine(1, systemAreaHeight + 2, screenWidth - 2, systemAreaHeight + 2);
+	p.drawLine(1, systemAreaHeight * 2 + 3, screenWidth - 2, systemAreaHeight * 2 + 3);
+
+	p.drawImage(3, systemAreaHeight * 2 + 6, idle_mail);
+	p.drawImage(32 + 3, systemAreaHeight * 2 + 6, idle_call);
+	p.drawImage(32 * 2 + 3, systemAreaHeight * 2 + 6, idle_sms);
+
+	p.end();
+	renderIdleWeather();
+	renderIdleCounts();
+	_paintMode = _currentMode;
+}
+
+void MetaWatch::renderIdleWeather()
+{
+	_paintMode = IdleMode;
+	QFont smallFont("MetaWatch Small caps 8pt", 6);
+	QImage rain(QString(":/metawatch/graphics/weather_rain.bmp"));
+	QPainter p(this);
+
+	p.setFont(smallFont);
+	p.drawText(46, systemAreaHeight + 14, "Rain");
+	p.drawImage(screenWidth - 26, systemAreaHeight + 6, rain);
+
+	_paintMode = _currentMode;
+}
+
+void MetaWatch::renderIdleCounts()
+{
+	_paintMode = IdleMode;
+	QFont medFont("MetaWatch Large caps 8pt", 6);
+	QString s;
+	QPainter p(this);
+	QTextOption opt(Qt::AlignCenter);
+	const int y = systemAreaHeight * 2 + 25;
+	const int w = 24;
+	const int h = screenHeight - (y + 1);
+	const int mails = _nMails;
+	const int calls = _nCalls;
+	const int sms = _nSms + _nIms;
+
+	qDebug() << "unread counts" << mails << calls << sms;
+
+	p.setFont(medFont);
+	p.fillRect(QRect(0, y, screenWidth, h), Qt::white);
+	p.drawText(QRect(4, y, w, h), s.sprintf("%d", mails), opt);
+	p.drawText(QRect(32 + 4, y, w, h), s.sprintf("%d", calls), opt);
+	p.drawText(QRect(32 * 2 + 4, y, w, h), s.sprintf("%d", sms), opt);
 }
 
 quint16 MetaWatch::calcCrc(const QByteArray &data, int size)
diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h
index 68e24c3..d15054f 100644
--- a/metawatch/metawatch.h
+++ b/metawatch/metawatch.h
@@ -88,6 +88,8 @@ public:
 	void update(Mode mode, const QList<QRect>& rects = QList<QRect>());
 
 	void renderIdleScreen();
+	void renderIdleWeather();
+	void renderIdleCounts();
 
 protected:
 	mutable MetaWatchPaintEngine* _paintEngine;
@@ -120,6 +122,9 @@ protected:
 	Mode _paintMode;
 	quint8 _buttonState;
 
+	// Notifications: Unread count
+	uint _nMails, _nCalls, _nIms, _nSms;
+
 	static const quint8 bitRevTable[16];
 	static const quint16 crcTable[256];
 	quint16 calcCrc(const QByteArray& data, int size);
diff --git a/metawatch/metawatch.pro b/metawatch/metawatch.pro
index f4b86f8..9a661ba 100644
--- a/metawatch/metawatch.pro
+++ b/metawatch/metawatch.pro
@@ -32,7 +32,16 @@ RESOURCES += \
 OTHER_FILES += \
 	idle_sms.bmp \
 	idle_gmail.bmp \
-	idle_call.bmp
+	idle_call.bmp \
+    weather_wind.bmp \
+    weather_thunderstorm.bmp \
+    weather_sunny.bmp \
+    weather_snow.bmp \
+    weather_rain.bmp \
+    weather_cloudy.bmp \
+    metawatch_16pt_11pxl.ttf \
+    metawatch_8pt_7pxl_CAPS.ttf \
+    metawatch_8pt_5pxl_CAPS.ttf
 
 win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/release/ -lsowatch
 else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/debug/ -lsowatch
@@ -47,7 +56,7 @@ symbian {
     TARGET.UID3 = 0xE4DC26B0
     TARGET.CAPABILITY = 
     TARGET.EPOCALLOWDLLDATA = 1
-    addFiles.sources = metawatch.dll
+	addFiles.sources = metawatchdriver.dll
     addFiles.path = !:/sys/bin
     DEPLOYMENT += addFiles
 }
@@ -60,3 +69,4 @@ unix:!symbian {
     }
     INSTALLS += target
 }
+
diff --git a/metawatch/metawatch_16pt_11pxl.ttf b/metawatch/metawatch_16pt_11pxl.ttf
new file mode 100644
index 0000000..9aeb8b3
Binary files /dev/null and b/metawatch/metawatch_16pt_11pxl.ttf differ
diff --git a/metawatch/metawatch_8pt_5pxl_CAPS.ttf b/metawatch/metawatch_8pt_5pxl_CAPS.ttf
new file mode 100644
index 0000000..a6b8f30
Binary files /dev/null and b/metawatch/metawatch_8pt_5pxl_CAPS.ttf differ
diff --git a/metawatch/metawatch_8pt_7pxl_CAPS.ttf b/metawatch/metawatch_8pt_7pxl_CAPS.ttf
new file mode 100644
index 0000000..72eda9e
Binary files /dev/null and b/metawatch/metawatch_8pt_7pxl_CAPS.ttf differ
diff --git a/metawatch/metawatchplugin.cpp b/metawatch/metawatchplugin.cpp
index e56d6db..751cff9 100644
--- a/metawatch/metawatchplugin.cpp
+++ b/metawatch/metawatchplugin.cpp
@@ -1,3 +1,4 @@
+#include <QtGui/QFontDatabase>
 #include <QtConnectivity/QBluetoothAddress>
 #include "metawatch.h"
 #include "metawatchsimulator.h"
@@ -6,6 +7,19 @@
 using namespace sowatch;
 QTM_USE_NAMESPACE
 
+bool MetaWatchPlugin::fontsLoaded = false;
+
+MetaWatchPlugin::MetaWatchPlugin()
+{
+	if (!fontsLoaded) {
+		QFontDatabase::addApplicationFont(":/metawatch/fonts/metawatch_16pt_11pxl.ttf");
+		QFontDatabase::addApplicationFont(":/metawatch/fonts/metawatch_8pt_7pxl_CAPS.ttf");
+		QFontDatabase::addApplicationFont(":/metawatch/fonts/metawatch_8pt_5pxl_CAPS.ttf");
+		// "MetaWatch Large 16pt", "MetaWatch Large caps 8pt", "MetaWatch Small caps 8pt"
+		fontsLoaded = true;
+	}
+}
+
 MetaWatchPlugin::~MetaWatchPlugin()
 {
 
diff --git a/metawatch/metawatchplugin.h b/metawatch/metawatchplugin.h
index 9662ec0..57b1029 100644
--- a/metawatch/metawatchplugin.h
+++ b/metawatch/metawatchplugin.h
@@ -11,10 +11,14 @@ class MetaWatchPlugin : public QObject, public WatchPluginInterface {
 	Q_INTERFACES(sowatch::WatchPluginInterface)
 
 public:
+	MetaWatchPlugin();
 	~MetaWatchPlugin();
 
 	virtual QStringList drivers();
 	virtual Watch* getWatch(const QString& driver, QSettings& settings, QObject *parent = 0);
+
+protected:
+	static bool fontsLoaded;
 };
 
 }
diff --git a/metawatch/uires.qrc b/metawatch/uires.qrc
index 4be7fc8..24d70fb 100644
--- a/metawatch/uires.qrc
+++ b/metawatch/uires.qrc
@@ -1,7 +1,18 @@
 <RCC>
-    <qresource prefix="/metawatch">
+    <qresource prefix="/metawatch/graphics">
         <file>idle_call.bmp</file>
         <file>idle_gmail.bmp</file>
         <file>idle_sms.bmp</file>
+        <file>weather_cloudy.bmp</file>
+        <file>weather_rain.bmp</file>
+        <file>weather_snow.bmp</file>
+        <file>weather_sunny.bmp</file>
+        <file>weather_thunderstorm.bmp</file>
+        <file>weather_wind.bmp</file>
+    </qresource>
+    <qresource prefix="/metawatch/fonts">
+        <file>metawatch_8pt_5pxl_CAPS.ttf</file>
+        <file>metawatch_8pt_7pxl_CAPS.ttf</file>
+        <file>metawatch_16pt_11pxl.ttf</file>
     </qresource>
 </RCC>
diff --git a/metawatch/weather_cloudy.bmp b/metawatch/weather_cloudy.bmp
new file mode 100644
index 0000000..506c24a
Binary files /dev/null and b/metawatch/weather_cloudy.bmp differ
diff --git a/metawatch/weather_rain.bmp b/metawatch/weather_rain.bmp
new file mode 100644
index 0000000..fc12c6e
Binary files /dev/null and b/metawatch/weather_rain.bmp differ
diff --git a/metawatch/weather_snow.bmp b/metawatch/weather_snow.bmp
new file mode 100644
index 0000000..d328105
Binary files /dev/null and b/metawatch/weather_snow.bmp differ
diff --git a/metawatch/weather_sunny.bmp b/metawatch/weather_sunny.bmp
new file mode 100644
index 0000000..df9f774
Binary files /dev/null and b/metawatch/weather_sunny.bmp differ
diff --git a/metawatch/weather_thunderstorm.bmp b/metawatch/weather_thunderstorm.bmp
new file mode 100644
index 0000000..f101610
Binary files /dev/null and b/metawatch/weather_thunderstorm.bmp differ
diff --git a/metawatch/weather_wind.bmp b/metawatch/weather_wind.bmp
new file mode 100644
index 0000000..59bd81b
Binary files /dev/null and b/metawatch/weather_wind.bmp differ
-- 
cgit v1.2.3