Friday, May 28, 2010

Trying out MeeGo SDK

Yesterday first release of MeeGo OS for netbook and N900 was out and with this SDK for MeeGo was also out.

I tried to install MeeGO SDK on my computer. Installation is easy and dose not required much user intreaction.

I also tried to develop helloworld application and with no effort I was able to create my first application for MeeGo device.

MeeGo use Qt as Application development framework and QtCreator is it's primary IDE.

MeeGo's site has vary good instruction for installation of SDK and getting started with development.

Here is link for SDK setup and Here is link for tutorial for getting started.

Finally here are few snaps from my SDK installation and my fist application for MeeGo device.

Tuesday, May 25, 2010

Enum value to String in Qt

Update:

it looks like that Qt framework made some changes that made staticQtMetaObject as protected.

Now to get staticQtMetaObject you need to use following code.
class StaticQtMetaObject : public QObject
{
public:
    static inline const QMetaObject& get() {return staticQtMetaObject;}
};
then use it like following
QString KeyboardOptionWidget::getKeyString( int aKeyCode )
{
    int index = StaticQtMetaObject::get().indexOfEnumerator("Key");
    QMetaEnum metaEnum = StaticQtMetaObject::get().enumerator( index);
    QString keyString = metaEnum.valueToKey( aKeyCode );
    return keyString.replace("Key_","");
    return QString();
}
--------------
Some time we might need to convert Enum value to string for various reason like logging or debugging. I also needed similar thing for one of my project.

I found one interesting code that uses Qt's meta-object system to convert Enum to String. I have created one similar function that convert key board code to string.

QString KeyboardOptionWidget::getKeyString( int aKeyCode )
{
    int index = QApplication::staticQtMetaObject.indexOfEnumerator("Key");
    QMetaEnum metaEnum = QApplication::staticQtMetaObject.enumerator( index);
 
    QString keyString = metaEnum.valueToKey( aKeyCode );
    return keyString.replace("Key_","");
} 

Hope this helps.

Tuesday, May 18, 2010

How to disable Blank display on Mameo from Qt application

I have created a game for N900 which take input from accelerometer and move game object around. In this case user don't have to touch on screen and platform was assuming that user it idle and is making display off.

To avoid display off, Maemo is providing DBUS API using which you can disable display off.

Following is Qt code to send dbus call to disable display off. You need to call this method at least once in every 60 seconds to avoid display off.

QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, 
MCE_REQUEST_PATH,MCE_REQUEST_IF, MCE_PREVENT_BLANK_REQ));

You will also need to include "mce/mode-names.h","mce/dbus-names.h" and "QtDBus" headers and add dbus support in Qt's pro file.

I hope this will help to someone facing similar problem.

Friday, May 14, 2010

View switching on iPhone SDK


While creating sample game for iPhone I required to create menu page for game. Here I am putting down code that I used to create menu for my sample game.

First create a view based application.


Then created menu view as following, with two button that will load new view.

Then add new view controller, I named new view as first view and add button on first view that will switch view to menu screen.


Now connect buttons to message that get activated when button is pressed and when button connection is ready then we can write code that will enable view switching. 

In menu view controller, I used following code to load first view. 

- (IBAction) siwthToView1:(id) sender {        

    FirstView *firstView = 
[[FirstView alloc] initWithNibName:@"FirstView" bundle:nil];

    [self.view addSubview: firstView.view];

}

addSubView message will add new view on view stack and display new view on screen.

Now, in first view I used removeFromSuperview message of UIView to go back to menu view.

removeFromSuperview will remove current view from view stack and displays the superview.


- (IBAction) back:(id) sender {

    [self.view removeFromSuperview];
}

So this was all, by using this simple code I implemented my game's menu page.



Saturday, May 8, 2010

Color match game for Maemo using Qt

I have added new game called color match to my reaction game. Idea behind game is to understand problem before you react to it.

In color match game, you will see two box on screen, on upper box there will be text which is color name and lower box will display color. You have to tell if color name displayed in upper box is matching color  displayed in lower box. This is it, if your answer is correct than you will get points. Now in this game I am also considering time which you took to answer, more you take time lower the points.

Here are fews snaps from game. And if you are interested in code, I have uploaded code on my glorious repository. I will also upload game to maemo extra-devel soon.

Wednesday, May 5, 2010

Simple download manager in Qt with puase/ resume support

Update: Here is link to my full working code sample.

Recently I needed to create simple download manager that support pause/ resume.

I was using Qt's network module (QNetworkAccessManager to be specific) to download media content, but QNetworkAccessManager class by itself does not support pause/resume feature.

But with little effort we can make it to support pause/resume. Trick it to set "Range" header while making HTTP request.

Please visit RFC 2616 for more information related to Range header.

To implement download manager, I have used example code from Qt 4.6 (http://doc.qt.nokia.com/4.6/network-downloadmanager.html) and then added code to support pause and resume.

In my code when user pause download I am saving current request and on resume I am adding Range header to saved request then starting download using that saved request.

downloadSizeAtPause = _currentRequest->_device->size();
QByteArray rangeHeaderValue = "bytes=" + QByteArray::number(downloadSizeAtPause) + "-"; 

_currentRequest->_request.setRawHeader("Range",rangeHeaderValue);

QTimer::singleShot(0,this,SLOT(startNextDownload()));

So here is simple download manager.