Lect 08 N900programming [PDF]

  • 0 0 0
  • Gefällt Ihnen dieses papier und der download? Sie können Ihre eigene PDF-Datei in wenigen Minuten kostenlos online veröffentlichen! Anmelden
Datei wird geladen, bitte warten...
Zitiervorschau

Programming N900 Kari Pulli Research Fellow Nokia Research Center Palo Alto

1

Overview Maemo Installing things, connecting to laptop Scratchbox / MADDE Command line hello world On laptop, on phone Hello Qt Packaging it UI development DBus Mobility API

What is Maemo? Powered by Nokia: http:// maemo.nokia.com/

Powered by the community: http://maemo.org/

N900 Hardware

Development Tools Overview In general Maemo development environment consists of:

• Desktop machine with Linux, Mac OS X or Windows operating system • Maemo SDK Virtual Image recommended for fast kick-start •  http://maemovmware.garage.maemo.org/2nd_edition/

• Scratchbox • Cross-compilation toolkit • Maemo SDK • Rootstrap for x86 and ARMEL targets inside Scratchbox • Xephyr • Pseudo X server for device screen emulation • IDE and other optional tools

Detailed installation instructions

• http://wiki.maemo.org/Documentation/Maemo_5_Final_SDK_Installation

Make sure you have the latest SDK Go to http://maemo.org/development/

•  click "Download the Maemo SDK” •  download the GUI installer, which is just a python file

On Ubuntu, ensure scratchbox can resolve key hostnames :

sudo cp /etc/resolv.conf /scratchbox/etc/resolv.conf

Run the wizard from the command line sudo python maemo-sdk-install-wizard_5.0.py

•  If it asks you to install Qt python bindings, say yes •  If it fails, run sudo apt-get update and rerun the install wizard •  If some sites return error codes when running apt-get update, edit the file /etc/apt/sources.list and comment out the problematic site

Development Tools – Scratchbox & MADDE Cross-compilation in Linux can be difficult • Some Linuxes solve the problem by not supporting cross-compilation • Scratchbox solves it by isolating host and target environments • Supports two separate targets: X86 and ARMEL • http://www.scratchbox.org

Currently Maemo officially supports Scratchbox 1 • Development around another version, Scratchbox 2, is ongoing

A new tool called MADDE is available as a Technology Preview • Maemo Application Development and Debugging Environment • http://wiki.maemo.org/MADDE • Simple-to-use cross-compiler which works in Linux, Windows, Mac OS

Using Scratchbox Start it by typing the command scratchbox

Configure targets [sbox-FREMANTLE_ARMEL: ~]: sb-menu

Switch between targets with sb-menu or by typing: [sbox-FREMANTLE_ARMEL: ~]: sb-conf select FREMANTLE_X86

Single source concept • Single source – multiple targets

World of Environments Host environment •  Development with IDE

Cross-compilation environment •  Separate rootstrap for each target •  Tools to create packages

Execution environment •  Device installation •  Target debugging and emulation/running

Repositories Install Qt libraries into Scratchbox (for both x86 and ARMEL targets!) •  The repository details for Extras[-devel] are:

•  Web address: http://repository.maemo.org/extras[-devel] •  Distribution: fremantle •  Components: free non-free

•  This means that appropriate line is added to /etc/apt/sources.list

Maemo SDK VM scratchbox does not initialize resolv.conf right •  see http://maemovmware.garage.maemo.org/2nd_edition/ documentation.html •  use the following script to set the /etc/resolv.conf of scratchbox to obtain access to repositories

maemo@maemo-desktop:~$ /scratchbox/sbin/sbox_ctl restart

Sample /etc/apt/sources.list deb http://repository.maemo.org/ fremantle/sdk free non-free deb-src http://repository.maemo.org/ fremantle/sdk free deb http://repository.maemo.org/ fremantle/tools free non-free deb-src http://repository.maemo.org/ fremantle/tools free # Extra goodies deb http://repository.maemo.org/extras/ fremantle free non-free deb http://repository.maemo.org/extras-devel/ fremantle free non-free deb-src http://repository.maemo.org/extras/ fremantle free deb-src http://repository.maemo.org/extras-devel/ fremantle free # the key ring (4bc3…) should be replaced for the one you get when you # update the SDK deb http://repository.maemo.org/ fremantle/4bc37c7c77ebe90177c050b805a8dc79 nokia-binaries

X Server •  X server allows applications to create windows to which they can draw on the screen •  Applications are X server clients •  X server also provides key press and pointer events to applications •  Maemo applications require a pseudo X server to be installed •  It acts as an X client to a real X server

•  Xephyr X server is typically used with Maemo SDK

X Server Initialization If Xephyr is not yet installed •  you should install it (outside Scratchbox): apt-get install xserver-xephyr

Outside Scratchbox, say Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac &

In Scratchbox, direct the display to window 2 by typing export DISPLAY=:2

Hildon Application Framework Start Launch the application framework •  [sbox-FREMANTLE_X86: ~]: af-sb-init.sh start

•  Hint! If you cannot launch application framework, the process may be running already, use af-sb-init.sh stop

Run standalone shell (themes, fonts will work) •  [sbox-FREMANTLE_X86: ~]: run-standalone.sh ./myqtapp

Testing scratchbox: cmd-line helloworld In scratchbox, use nano editor: nano helloworld.c #include int main(int argc, char** argv) { printf(“Hello world!\n”); return 0; } [sbox-FREMANTLE_X86: ~] > gcc -Wall -g helloworld.c -o helloworld [sbox-FREMANTLE_X86: ~] > ./helloworld Hello world!

To try on emulator, install xterm and bash, apt-get install osso-xterm apt-get install bash

copy exec to, e.g., ~/MyDocs, try from xterm

Note: Xterm emulator may need CTRL+RETURN or ENTER to get return…

Working with MADDE With MADDE

•  you can create package structure with “mad pscreate” •  compile the code with “mad qmake” and “mad make” •  create a debian package by “mad dpkg-buildpackage”

You need to install mad-developer to the device

•  it allows you to connect MADDE to device, send, run and install files and packages remotely, and connect your N900 into internet through USB cable •  MADDE and mad-developer are integrated with QtCreator see http://wiki.maemo.org/MADDE/QtCreator_integration_for_windows

With “mad remote”, you can send executable files to device, run and stop them, send package files, and install them remotely

•  you need to setup runtime which specifies the device with mad-admin •  existing runtimes are listed with “mad list” command •  see http://wiki.maemo.org/MADDE/Device_runtime for more information

Flashing the phone Find out which software build you have on the phone •  Settings->General->About product

You can flash your own phone for the latest software

•  flashing tools and instructions: http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/ Development_Environment/Maemo_Flasher-3.5 •  •  •  •  • 

turn off the tablet press and hold down key 'u’, connect USB cable when USB icon appears on screen right upper corner you can release 'u' on the computer, run sudo flasher-3.5 -F -f –R wait for flashing to finish, disconnect and boot

•  the latest public image http://tablets-dev.nokia.com/nokia_N900.php

Application Manager Open App. manager •  click "Application Manager" at the top, select "Application Catalogs” •  add new repository: •  Catalog name: extras-devel •  Web address: http://repository.maemo.org/extras-devel •  Distribution: fremantle •  Components: free non-free

Update (may take a while)

X Terminal & SSH Get SSH

•  go to “Download->All”, install openssh server and client, and rootsh •  choose a root password

The phone already has X Terminal

•  start by clicking its icon or hit the hot key “CTRL + SHFT + X” •  type root to become root (superuser) •  set normal user password with passwd user •  find IP address with /sbin/ifconfig (changes based on connection) •  start ssh with /etc/init.d/ssh start (only once, even with reboot)

If you want to do lots of command line work, ssh into phone from laptop

•  ssh [email protected] (or whatever your IP address is)

Example phone app repository settings Nokia-N900:~# cat /etc/apt/sources.list.d/hildon-application-manager.list deb https://downloads.maemo.nokia.com/fremantle/ssu/apps/ ./ deb https://downloads.maemo.nokia.com/fremantle/ssu/mr0 ./ deb https://downloads.maemo.nokia.com/fremantle1.2/ovi/ ./ deb https://downloads.maemo.nokia.com/fremantle/apps/ ./ deb http://repository.maemo.org/extras/ fremantle-1.2 free non-free deb http://repository.maemo.org/extras-testing fremantle free non-free deb http://repository.maemo.org fremantle/tools free non-free deb http://repository.maemo.org/extras-devel fremantle free non-free

Edit from app manager, or on xterm with vi, or add lines like this: echo "deb http://repository.maemo.org fremantle/tools free non-free" \ >> /etc/apt/sources.list.d/hildon-application-manager.list

Use like this: apt-get apt-get apt-get apt-get

update upgrade dist-upgrade install gdb strace

apt-get install libqt4-maemo5*

Compile for ARM and try on the phone Select target, compile, send to phone [sbox-FREMANTLE_X86: ~] > sb-conf select FREMANTLE_ARMEL [sbox-FREMANTLE_ARMEL: ~] > gcc -Wall -g helloworld.c -o helloworld [sbox-FREMANTLE_ARMEL: ~] > scp helloworld [email protected]:/home/user [email protected]'s password: helloworld 100% 6105 6.0KB/s 00:00

On your laptop connected with ssh, or directly on the phone xterm Nokia-N900:~# cd /home/user Nokia-N900:/home/user# ls -la helloworld -rwxr-xr-x 1 root root 6105 Apr 11 16:56 helloworld Nokia-N900:/home/user# ./helloworld Hello world!

More tips and hints Folder 'Nokia N900' equals to '/home/user/MyDocs’ Files stored in 'MyDocs' are not availableon the phone when connected to the computer via USB •  (from Maemo Wiki http://wiki.maemo.org/User_FAQ)

The images taken with native camera application go into •  ~/MyDocs/DCIM folder (“Camera” folder) •  not into ~/MyDocs/.images folder!

Ctrl+Fn+P takes a screenshot •  places it into a folder MyDocs/.images/Screenshots •  For more shortcuts, see http://wiki.maemo.org/N900_shortcuts_and_gestures

Qt Development in Maemo http://wiki.maemo.org/Qt4_Hildon Installing Qt packages into scratchbox: Qt 4.5 (community port): •  Packages already available in the default SDK repository •  Install Qt binaries and development packages •  [sbox-FREMANTLE_X86: ~]: fakeroot apt-get install libqt4-dev •  Qt 4.6 Beta: •  Make sure that the repository list (/etc/apt/sources.list) contains maemo extras and extras-devel •  Call: ”fakeroot apt-get update && fakeroot apt-get install libqt4-maemo5-dev” •  Beta is installed to /opt/qt4-maemo5 (so you need to use /opt/qt4-maemo5/bin/qmake) •  To use the new Maemo 5 specific widgets, add the following line to your project file: •  Qt += dbus maemo5

HelloQt Create helloqt.cpp Type qmake –project qmake make

Run on the emulator af-sb-init.sh start run-standalone.sh ./helloqt

Try on the phone •  switch to ARMEL •  rm *.o; qmake; make •  send to phone, try it out

Building Qt Applications in Maemo Building in Qt way • qmake –project • Creates the .pro project file (if not already created) • qmake • Creates Makefile with Qt add-ons (.moc files, .rsc files etc.) • make • Builds the project • Creates Maemo application framework files (desktop file and DBus service file)

If qmake is not found or linking fails because libraries are not found, add environment variables export PATH=$PATH:/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib

Installing Qt Libraries on a Device (N900) Qt 4.5 (community port): •  N900 has the Qt 4.5 core packages pre-installed. Rest of the packages (GUI, webkit, …) are downloaded automatically when user installs packages that depend on those. •  Alternatively, binaries can be installed with the terminal application. For example: •  sudo gainroot •  apt-get update •  apt-get install libqt4-core

•  Qt 4.6 Beta: •  Install libqt4-maemo5-core either from terminal application or from Application manager

Exercise 1: Build and Run Application Source for this exercise is located under the directory •  qmobilepaint_exercise

Make sure that the Qt project is visible in the Scratchbox •  copy it to /scratchbox/users/usrname/home/usrname/

Compile it for the X86 target in Scratchbox

•  using qmake and make •  if everything goes fine, the executable is in the src directory

Launch Xephyr Run the application by typing its name

•  try it out: color picker, file open, or save dialogs •  you will notice that it doesn’t look very nice yet… •  fonts, decorations, Maemo UI style in general is missing •  application needs to be managed by Maemo window manager

./qmobilepaint

29

Exercise 2: Run App within App Framework Start the application framework in X86 Scratchbox •  af-sb-init.sh start

Then launch the application •  directly •  using the ”standalone shell” script

Now the user experience is much nicer •  and according to the Maemo 5 UI style

The app is still not actually installed in the emulated device •  The application is not known by the package management system •  The application is also missing the desktop file so it is not listed among other applications

af-sb-init.sh start

./qmobilepaint

run-standalone.sh ./qmobilepaint

31

Debian Packages Maemo applications are distributed as Debian packages •  so Qt apps in Maemo as well

Two phases in creation •  create package structure – Use dh_make tool •  create the actual package – Use dpkg-buildpackage tool

Qt projects with a proper package structure and packages can be also made with MADDE •  mad pscreate -t •  mad dpkg-createpackage •  See http://wiki.maemo.org/MADDE/Qt_Example for details

Qt Application Deployment Move the application binary or Debian package to the device •  use N900 as a USB mass storage, copy the file, unmount •  or use scp

If using a Debian package, you need to also install it: •  sudo gainroot •  dpkg -i mypackage_version_armel.deb

Finally, run the application from where it was copied/installed: •  ./myFirstQtApplication

PC Connectivity info http://pc-connectivity.garage.maemo.org/ •  connection establishment •  internet sharing •  remote shell •  file sharing •  remote desktop •  file transfer

Package Creation Manually Inside Scratchbox, rename your project folder (required by dh_make) mv myqtapplication myqtapplication-1.0

Create the basic package structure into a folder dh_make --createorig --single –e [email protected] -c gpl •  a single application package created making a copy of the original source archive and using a GPL license

Edit rules, control, copyright, etc., files as needed Build the actual package dpkg-buildpackage –rfakeroot –b // Binary distribution

More details at:

•  http://wiki.maemo.org/Packaging_a_Qt_application •  http://wiki.forum.nokia.com/index.php/Qt_for_Maemo_Developers_Guide

Control File Edit the maintainer field Define build dependencies Add depends info Add some package description Add build dependency for Qt library, if Qt is used (libqt4dev or libqt4-maemo5dev) Add dependencies to proper libqt4-core, etc., packages

Source: myqtapplication Section: user/other Priority: extra Maintainer: unknown Build-Depends: debhelper (>= 5), libqt4-dev Standards-Version: 3.7.2 Package: myqtapplication Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description:

Exercise 3: Create and Install a Package Edit the fields in the incomplete ”control” file in the debian directory Look for the ”EXERCISE CONTROLFILE” tags •  What is the ”Source” of this package? •  What is the requirement for ”Section”, so that the end-users will see the application in the Application Manager? •  Should something be added to the ”Build-Depends”? •  What ”Architecture” would you use?

Switch to ARMEL target type Create the .deb package with dpkg

•  verify the dpkg output to see everything goes ok •  qmobilepaint_1.0.0_armel.deb should be created at /qmobilepaint_exercise

Check ”libqt4-core” ”libqt4-gui” and ”libqt4-svg” are installed in device •  Application Manager and apt-get are able to resolve dependencies for end users, but you as a developer are now using dpkg which cannot handle the dependencies

Copy and install it on a device, run it from X Terminal

•  there is no desktop file so it isn’t listed among other applications

If you don’t have an N900

•  you can practice the above with the X86 target (Scratchbox)

# EXERCISE CONTROLFILE: # What is the Source for the package? Source: # EXERCISE CONTROLFILE: # What could be a proper Section? Section: Priority: extra Maintainer: unknown # EXERCISE CONTROLFILE: # What is missing from the Build-Depends of this package? Build-Depends: debhelper (>= 5) Standards-Version: 3.7.2 Package: qmobilepaint # EXERCISE CONTROLFILE: # What Architecture type would you use for this application? Architecture: Depends: ${shlibs:Depends}, ${misc:Depends}, hildon-application-manager Description: QMobilePaint Painting example. XB-Maemo-Icon-26: iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAABHNCSVQICAgI fAhkiAAAAAlwSFlzAAAILgAACC4B4ThkEQAAABl0RVh0U29mdHdhcmUAd3d3 …

# EXERCISE CONTROLFILE: # Source of this package is the qmobilepaint binary Source: qmobilepaint # EXERCISE CONTROLFILE: # Section could be for example "user/graphics". App Mgr only shows packages under "user” Section: user/graphics Priority: extra Maintainer: Kari Pulli # EXERCISE CONTROLFILE: # Build-Depends should contain libqt4-dev Build-Depends: debhelper (>= 5), libqt4-dev Standards-Version: 3.7.2 Package: qmobilepaint # EXERCISE CONTROLFILE: # Architecture = "any” -> determined automatically during package creation (X86 or ARMEL) Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, hildon-application-manager Description: QMobilePaint Painting example. XB-Maemo-Icon-26: iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAABHNCSVQICAgI fAhkiAAAAAlwSFlzAAAILgAACC4B4ThkEQAAABl0RVh0U29mdHdhcmUAd3d3 …

Observations [sbox-FREMANTLE_ARMEL: ~/exercises/qmobilepaint_exercise/QMobilePaint-1.0] > dh_make -createorig --single -e [email protected] -c lgpl Package name "QMobilePaint" is not in a valid format. Debian policy manual states: "Package names must only consist of lower case letters, digits (0-9), plus (+) or minus (-) signs, and periods (.)” [sbox-FREMANTLE_ARMEL: ~/exercises/qmobilepaint_exercise/qmobilepaint-1.0] > dh_make -createorig --single -e [email protected] -c lgpl Maintainer name : unknown … Type of Package : Single Hit to confirm: You already have a debian/ subdirectory in the source tree. dh_make will not try to overwrite anything. [sbox-FREMANTLE_ARMEL: ~/exercises/qmobilepaint_exercise/qmobilepaint-1.0] > dpkgbuildpackage -rfakeroot –b dpkg-buildpackage: source package is qmobilepaint … 39

Integration to Application Framework [app name].desktop file is required to make your Maemo application visible in the task launcher •  contains information such as application name, icon logical name, application binary file name, etc.

Copied to /usr/share/ applications/hildon

[Desktop Entry] Encoding=UTF-8 Version=1.0 Type=Application Name=My Qt Application Exec=/usr/bin/myqtapplication Icon=myqtapplicationicon StartupWMClass= X-Window-Icon=myqtapplicationicon X-HildonDesk-ShowInToolbar=true

•  This is usually handled by adding ”INSTALLS” item “desktop” to the X-Osso-Type=application/x-executable Terminal=false project file (see http://doc.qt.nokia.com/4.6/ qmake-environmentreference.html%23installs)

Exercise 4: Create a Desktop File Now it is time to set a desktop file for the qmobilepaint, so that it is listed in task launcher menu Create a desktop entry with file name: ”qmobilepaint.desktop” in the src directory of the project •  Remember to really use UTF-8 encoding for the file •  Set executable path to value: /usr/bin/qmobilepaint

Take a look at the ”src.pro” file in the src directory of the project and look for the ”EXERCISE DESKTOPFILE” tags in it. They mark the places that you need to edit •  Add an item in the ”INSTALLS” list representing the desktop file •  Item identifier can be freely used, choose e.g. ”desktop”

•  Add proper path & files information for the previously specified item •  What is the correct path for the desktop file?

Build a package again and install it to a device. Now your application should be listed under the ”More…” folder of the applications menu •  Again, you can create a package for Scratchbox instead if you don’t have hardware available

Maemo 5 UI Style at a Glance

“Hildonizing” Qt Improved finger usability and screen real estate usage Lists and window panes scrollable with finger from window pane New dialog layout, no cancel button, cancel action by clicking outside of dialog

How to Handle Maemo Specific Implementation? Qt 4.6 specific parts should be separated as follows: #ifdef Q_WS_MAEMO_5 // maemo5-specific implementation added here in C++ #endif maemo5: { # maemo5-specific configuration added here in .pro file }

Qt 4.5 specific parts should be separated with •  “#ifdef Q_WS_HILDON ... #endif” blocks in c++ files •  “contains(QT_CONFIG, hildon) : { ... }“ blocks in .pro files

Some Maemo 5 Specific Widgets in Qt 4.6 QMaemo5ValueButton

•  a picker button, basically a button with an extra value

QMaemo5AbstractPickSelector

•  an abstract interface to implement Maemo 5 “pickers”, plus a picker implementations for time picking (QMaemo5TimePickSelector), etc.

QMaemo5InformationBox

•  support for Maemo 5 banners and notes

QMaemo5EditBar

•  support for Maemo 5 edit toolbar

Hierarchical menus difficult to use with fingers Just add QActions directly to QMenuBar Don’t add too many items Menu bar is property of the window manager in Maemo

MyMainWindow::MyMainWindow() { QMenuBar *menuBar = new QMenuBar(); QAction *showCat = new QAction("Show a Cat",this); menuBar->addAction(showCat); connect(showCat, SIGNAL(triggered()), this, SLOT(show_mainw2())); QAction *showDialog = new QAction("Show Dialog",this); menuBar->addAction(showDialog); connect(showDialog, SIGNAL(triggered()), this, SLOT(show_dialog())); setMenuBar(menuBar); … }

…More about Maemo 5 UI – Dialogs Make a normal dialog Put content in QScrollArea Activate finger scrollable •  QAbstractKineticScroller is enabled for QScrollArea by default in Qt 4.6 for Maemo

Put content in QVerticalBoxLayout inside the scroll area

void MyMainWindow::SetupDialog() { dialog = new QDialog(this); // dialog content placed inside scroll area QScrollArea *scrollArea = new QScrollArea(dialog); scrollArea->setWidgetResizable(true); #ifdef Q_WS_MAEMO_5 // Scrolling is activated for QAbstractItemView and QScrollArea by default in Qt 4.6 #else scrollArea->setProperty("FingerScrollable",true); // activate scrolling #endif // place content in vertical layout QWidget *scrollAreaWidgetContents = new QWidget(); QVBoxLayout *verticalLayout = new QVBoxLayout(scrollAreaWidgetContents); verticalLayout->addWidget(new QPushButton("First Button", scrollAreaWidgetContents)); verticalLayout->addWidget(new QCheckBox("Check out this", scrollAreaWidgetContents)); for(int i=0;iaddWidget(new QPushButton("Push Button", scrollAreaWidgetContents));

}

// OK button and overall horizontal layout QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); buttonBox->setOrientation(Qt::Vertical); buttonBox->setStandardButtons(QDialogButtonBox::Ok); buttonBox->setCenterButtons(false); scrollArea->setWidget(scrollAreaWidgetContents); QHBoxLayout *horizontalLayout = new QHBoxLayout(dialog); horizontalLayout->addWidget(scrollArea); horizontalLayout->addWidget(buttonBox);

Stacked Windows A stack sets a hierarchical relationship between windows •  a child window is on top of its parent window •  navigate to previous window by removing the topmost window

Users can only see and interact with the window on the top of stack until it is closed

// Implementing a stacked window changed between Qt 4.5.3 and Qt 4.6. // In Qt 4.5.3 only need a ”child” QMainWindow within the ”parent” MyMainWindow::MyMainWindow() { mainw2 = new QMainWindow(this); b2 = newQPushButton(”Show stacked window”); #ifdef Q_WS_MAEMO_5 setAttribute(Qt::WA_Maemo5StackedWindow); mainw2->setAttribute(Qt::WA_Maemo5StackedWindow); #endif connect(b2,SIGNAL(clicked()),this,SLOT(show_mainw2())); … } void MyMainWindow::show_mainw2() { mainw2->show(); }

New widget attributes Some new window flags added for special Maemo 5 features:

• Busy indicator for windows and dialogs • Support to disable window compositing in the window manager to improve drawing performance • Stacked windows as we just learned • Portrait and landscape orientation

Maemo-specific widget attributes in qnamespace.h: •  WA_Maemo5ShowProgressIndicator •  WA_Maemo5DesktopApplet •  WA_Maemo5NonComposited •  WA_Maemo5StackedWindow •  WA_Maemo5ForcePortraitOrientation •  WA_Maemo5ForceLandscapeOrientation

Input Methods Hildon input method supports several input modes •  Alpha •  Numeric •  Special •  Hexadecimal •  Telephone numbers •  Unrestricted •  Multiline •  Invisible •  Automatically capitalized •  Dictionary

How to Set the Input Mode?

int mode = HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE; QInputContext qic = someWidget->inputContext(); qic->setInputMode(mode);

Qt widgets like QTextEdit, QLineEdit... set the right input method mode automatically

Maemo Specific Storage Locations QDesktopServices::storageLocation(StandardLocation) • DesktopLocation => ~/MyDocs • DocumentsLocation => ~/MyDocs/.documents • PicturesLocation => ~/MyDocs/.images • Note: The images taken with native camera application go into ~/MyDocs/DCIM folder (which is equal to “Camera” folder), not into ~/MyDocs/.images folder! • MusicLocation => ~/MyDocs/.sounds • MoviesLocation => ~/MyDocs/.videos

Using D-Bus • D-Bus was mentioned when we talked about Maemo Software Architecture • It is an Inter-Process Communication (IPC) and Remote Procedure Calling (RPC) for Linux (including Maemo), and available via QtDBus module • See: • http://qt.nokia.com/doc/4.6/intro-to-dbus.html • http://qt.nokia.com/doc/4.6/qtdbus.html

• To use QtDbus add in your project file: CONFIG += qdbus • Remember that QtDbus is not available on all platforms

• An example of using D-Bus to request notifications is given in the next slide

Device Orientation • Qt 4.6 for Maemo provides support for changing the application orientation: void Window::toggleLandscape(bool b) { setAttribute(Qt::WA_Maemo5ForcePortraitOrientation, !b); setAttribute(Qt::WA_Maemo5ForceLandscapeOrientation, b); relayout(); }

•  Device orientation changes can be dynamically observed with D-Bus (even with Qt 4.5): MyReceiverClass * receiver = new MyReceiverClass(this); QDBusConnection systemBus = QDBusConnection::systemBus(); systemBus.connect("com.nokia.mce", "/com/nokia/mce/signal", "com.nokia.mce.signal", "sig_device_orientation_ind", receiver, SLOT(orientationChanged(QString))); // “portrait” or “landscape”

Exercise 5: Utilize D-Bus with Qt Some Maemo-specific tasks require using D-Bus interprocessing communication mechanism. Your task is to implement minimizing qtmobilepaint application with D-Bus. Look for the ”EXERCISE DBUS” tags in “widget.cpp”. Send a minimizing signal using the Qt D-Bus module •  Include the Qt D-Bus headers •  Create and send the actual signal. Here are the details you need: •  path is just ”/”, •  interface is ”com.nokia.hildon_desktop”, and •  signal is ”exit_app_view”

•  Remember that this functionality is Hildon-specific! How should you take that into account?

Look for the same tag in the ”src.pro” file. Add Qt D-Bus module to the project

•  Remember again that the D-Bus is not available in all platforms and needs to be variated

Build the application and verify the behavior with a device or Scratchbox

Exercise 6: Fix Storage Locations Qt for Maemo is evolving rapidly and the qmobilepaint exercise contains some obsolete code for opening/ saving pictures •  Your task is to update the code

Check the existing behavior of opening/saving pictures with the qmobilepaint

•  Look for the ”EXERCISE STORAGELOC” tags in ”widgets.cpp” •  How would you improve the functionality having studied this topic during the course?

After implementing your changes, recompile and verify the results. The proposed opening/saving directory should make sense.

Exercise 7: Add Maemo 5 Specific Widgets This exercise is for playing with Maemo 5 specific widgets Check the existing behavior of changing the pen size •  Look for the ”EXERCISE MAEMO5_SPECIFIC” tags in ”widgets.cpp” and in “widgets.h” •  How could you use the Maemo 5 specific widgets to show a dialog for pen size picking instead?

After implementing your changes, recompile and verify the results

Qt Mobility APIs What is the Mobility Project? •  a new suite of Qt APIs for mobile device functionality •  for cross-platform mobile application development •  avoid the need to use non-portable platform APIs •  Beta package released on Feb 15, 2010

Follow the progress at •  http://labs.trolltech.com/page/Projects/QtMobility

Bearer Management API Provides way to control which connection is used •  e.g., choose to use either 3G or WLAN in different situations •  also a smooth switch from one bearer to another is possible

Contacts API Provides way to •  Add, remove and update contacts and contact groups •  Search for contacts and contacts groups

Location API Provides easy way to access location information Modes •  one-time fetch •  periodically •  on position change

QGeoAreaMonitor provides notifications •  enter or exit a specified region

Messaging API Provides ways to •  send messages •  receive •  reply •  search messages •  filtered •  ordered

Multimedia API Provides way to •  show pictures and play music, video files, and multimedia streams •  record video or sound or take photos •  listen to the radio

Publish and Subscribe API Provides ways to •  publish items •  read item values •  navigate through items •  subscribe to change notifications

Data is stored as a tree-like data structure •  when a child of a node is changed, the node change as well •  this allows applications to be notified always when any child is changed for some node

Values are fetched with a path string •  e.g., /Device/Network/Interfaces/eth0/Name

Service Frameworks API Unified way of finding, implementing and accessing services across multiple platforms •  A service is an independent component that allows a client to perform a well-defined operation •  For example, application could provide a service interface named •  com.nokia.qt.sysinfo

•  Other applications can invoke methods of the service provider using the QServiceManager

System Information API Obtain information about the features and versions •  Versions of Operating system, firmware, WebKit, Qt •  Device information like battery level, screen size, SIM, input methods •  Display information •  Features such as GPS, bluetooth, wlan, camera, fm radio, etc.

Sensors API Provides way to access sensor data These include •  Ambient Light •  Compass •  Proximity •  Magnetometer •  Accelerometer •  Orientation •  Rotation •  Tap

Versit© API Provides way to read and write Versit© documents •  vCards •  vCalendar

Allows applications to easily map QContacts to vCards •  and vice versa

Further Information • Qt Development Frameworks:

• http://qt.nokia.com/ • http://qt.nokia.com/developer/qt-for-maemo-developers

• Forum Nokia:

• http://www.forum.nokia.com/Technology_Topics/Device_Platforms/ Maemo.xhtml • http://wiki.forum.nokia.com/index.php/ Qt_for_Maemo_Developers_Guide

• Maemo community:

• http://maemo.org/ • See ”Development” section and the wiki under ”Community” for lots of good information • http://qt4.garage.maemo.org/