tag:blogger.com,1999:blog-23955466798160478752024-03-21T22:52:15.520+02:00Cristi BoianCristi Boianhttp://www.blogger.com/profile/16582720752877244818noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-2395546679816047875.post-91387632048582766102013-03-17T23:49:00.000+02:002013-03-23T22:57:56.426+02:00Battery Icon 2.1<h2>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0lVF0AmO8zoxSCiSJxSKVYIJ-BpStvXPJcPzm546AQwYysrwEib7eZk9bOfj-xa6Ka5AIxdtVQa9rROFFH2vCquvUGcpjUI_eu5N46kcC5qhUVT31xCzSte-nIb7D2KqGgOD80tOEhq4/s1600/battery-icon+(1).png" imageanchor="1" style="clear: left; display: inline !important; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0lVF0AmO8zoxSCiSJxSKVYIJ-BpStvXPJcPzm546AQwYysrwEib7eZk9bOfj-xa6Ka5AIxdtVQa9rROFFH2vCquvUGcpjUI_eu5N46kcC5qhUVT31xCzSte-nIb7D2KqGgOD80tOEhq4/s1600/battery-icon+(1).png" /></a></h2>
<div>
A new version of <a href="http://www.cristiboian.com/p/apps.html">Battery Icon</a> is now available from Nokia Store. It features a new icon was designed by <a href="http://www.pixelweed.com/">Sandor F. Szabo</a>, an easier to read indicator on the stand-by screen, and a few bug fixes.<br />
<br /></div>
<div>
Battery Icon until version 2.1 has been downloaded almost 300 000 times probably making it one of the most popular apps for MeeGo. </div>
<div>
The source code is now available under GPLv2 from <a href="https://github.com/cristiboian/battery-icon"><span id="goog_1242356492"></span>github<span id="goog_1242356493"></span></a>.</div>
<div>
<br />
To download it directly from Nokia Store tap <a href="http://store.ovi.com/content/272241"><span id="goog_1758974851"></span>here<span id="goog_1758974852"></span></a>.<br />
<br /></div>
<div>
<br /></div>
Cristi Boianhttp://www.blogger.com/profile/16582720752877244818noreply@blogger.com3tag:blogger.com,1999:blog-2395546679816047875.post-12580388220951590972012-05-04T11:27:00.000+03:002012-05-04T11:27:53.557+03:00Setting Alarms in Harmattan (Nokia N9)I have decided to kick start my blogging with a topic not very well covered by the 'official' Meego Harmattan documentation: setting alarms.<br />
<br />
The sources of this post are timed documentation only available online <a href="http://meego.gitorious.org/meego-middleware/timed/trees/master/src/doc" target="_blank">here</a> and the timed's <a href="http://paste.org/39430" target="_blank">simple-client source code</a>. You will have to look at those to do anything more complex than the topics I cover.<br />
<br />
<h3>
Headers and Compilation</h3>
<br />
You are going to need these headers:<br />
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
#include <timed/interface></div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
#include <timed/event></div>
<br />
And to add timed to CONFIG in the project file:<br />
<div style="background-color: #f3f3f3;">
<span style="font-family: "Courier New",Courier,monospace;">CONFIG += timed</span></div>
<br />
If you are building in Scratchbox (aka Platform SDK) also add libtimed-dev to the Build-Depends in debian/control file.<br />
<br />
<h3>
Simple Event with Alarm</h3>
<br />
This is pretty easy so first the code: <br />
<br />
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
Maemo::Timed::Event event;</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
event.setAttribute("APPLICATION", "alarmtest"); </div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
event.setAttribute("TITLE", "Get up now!"); </div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
event.setAttribute("PLUGIN", "libclockalarm"); </div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
event.setBootFlag();</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
event.setAlarmFlag();</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
event.setReminderFlag();</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
// set the alarm in 10s from now</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
event.setTicker(QDateTime::currentDateTime().toTime_t() + 10);</div>
<br />
<br />
And some brief explanations:<br />
<ul>
<li>APPLICATION attribute is mandatory and the string has the same rules as C identifiers (alphanumeric and underscore characters only, first character not a number). If you fail these rules no error is reported but the returned cookie is zero and no event is added.</li>
<li>TITLE attribute is the title of the alarm (in this case) and will be shown on screen.</li>
<li>PLUGIN attribute is the plugin used when the event is triggered. You can write your own plugin but here we are using the one for alarms.</li>
<li>setBootFlag() - will ring even if device is off i.e. boots the device if needed.</li>
<li>setAlarmFlag() - tells the system it's an alarm not only a scheduled task.</li>
<li>setReminderFlag() - needed to show the default alarm dialog.</li>
<li>setTicker() - sets the alarm time in seconds (there are a lot of other 'more human' ways to set this).</li>
</ul>
<br />
Now you just need to add the event to timed's queue. Here is some sample code with error checking:<br />
<br />
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
// timed interface setup<br />
Maemo::Timed::Interface timedIface;<br />
if(!timedIface.isValid()) {<br />
qDebug() << "Invalid timed interface:" << timedIface.lastError();<br />
return 1;</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
}</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
</div>
<div style="background-color: #f3f3f3;">
<span style="font-family: "Courier New",Courier,monospace;">// add the event</span><br />
<span style="font-family: "Courier New",Courier,monospace;">QDBusReply<uint> reply = timedIface.add_event_sync(event);</span><br />
<span style="font-family: "Courier New",Courier,monospace;">if(!reply.isValid()) {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> qDebug() << "Adding event failed:" << reply.error().message();</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> return 1;</span><span style="font-family: "Courier New",Courier,monospace;"> </span></div>
<div style="background-color: #f3f3f3;">
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">qDebug() << "Added event with cookie:" << reply.value();</span></div>
<br />
Note that you get back a 'cookie' which is in fact the event identifier. This can be later used to search, cancel or change the event.<br />
<br />
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
<span style="background-color: white;"></span></div>
<h3>
Event with Command Execution</h3>
<br />
To do anything more than setting the alarm we need an Action object. Here we are running a command when the user presses the alarm Stop button:<br />
<br />
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
Maemo::Timed::Event::Action &act = event.addAction();</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
act.setSendCookieFlag();</div>
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
act.runCommand("echo Event cookie <COOKIE> $(date) >> /tmp/test");</div>
<span style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;"><span style="background-color: #f3f3f3;">act.whenSysButton(2); // 1 - snooze, 2 - stop </span></span><br />
<br />
setSendCookieFlag() will cause timed to replace 'COOKIE' or '<COOKIE>' in the command string with the event cookie value.<br />
<br />
If you need to run a graphical application there are two other issues to consider. First you need some environment variables set: DISPLAY=:0 and DBUS_SESSION_BUS_ADDRESS (source it from /tmp/session/bus_address.user). Second you need to make sure the application is run as user: set the UID and GID tokens to user/users in aegis manifest file for your application path. Probably the best solution here is to use a wrapper script to start the application.<br />
<br />
Also note that timed is a crond replacement so you can schedule tasks to run in the background without user interaction. Recurrences can be done with the Maemo::Timed::Event::Recurrence class.<br />
<br />
<h3>
</h3>
<h3>
Cancel and Replace Events</h3>
<br />
There are 2 very simple API calls for canceling and replacing events based on their cookies:<br />
<br />
<div style="background-color: #f3f3f3; font-family: "Courier New",Courier,monospace;">
bool cancel_sync(uint cookie);<br />
uint replace_event_sync(Maemo::Timed::Event newEvent, uint cookie);</div>
<br />
<h3>
</h3>Cristi Boianhttp://www.blogger.com/profile/16582720752877244818noreply@blogger.com5