Canonical Voices

Zoltán Balogh

The Next Generation SDK

Up until now the basic architecture of the SDK IDE and tools packaging was that we have packaged and distributed the QtCreator IDE and our Ubuntu plugins as separate distro packages which strongly depend on the Qt available in the same release.

Since 14.04 we have been jumping through hoops to provide the very same developer experience from a single development branch of the SDK projects. Just to give a quick picture on what we have available in the last few releases (note that 1.3 UITK is not yet released):

14.04 Trusty Qt 5.2.1 QtCreator 3.0.1 UI Toolkit 0.1
14.10 Utopic Qt 5.3. QtCreator 3.1.1 UI Toolkit 1.1
15.04 Vivid Qt 5.4.1 QtCreator 3.1.1 UI Toolkit 1.2
15.10 Wily Qt 5.4.2 QtCreator 3.5.0 UI Toolkit 1.3

Life could have been easier by sticking to one stable Qt and QtCreator and base our SDK on it. Obviously it was not a realistic option as the phone development needed the most recent Qt and our friend Kubuntu required a hot new engine under its hood too. So Qt was quickly moving forward and the SDK followed it. Of course it was all beneficial as new Qt releases brought us bugfixes, new features and improved performance.

But on the way we came to realize that continuously backporting the UITK and the QtCreator plugins to older releases and the LTS was simply not going to be possible. It went fine for some time, but the more API breaks the new Qt and QtCreator releases brought the more problems we had to face. Some people have asked why we don’t backport the latest Qt releases to the LTS or to the stable Ubuntu. As an idea it may sound good, but changing the Qt to 5.4.2 under an application in LTS what was built against 5.2.1 Qt would certainly break that application. So it is simply not cool to mess around with such fundamental bits of a stable and long term supported release.

The only option we had was to decouple the SDK from the archive release of Qt and build it as a standalone package without any external Qt dependencies. That way we could provide the exact same experience and tools to all developers regardless if they are playing safe on Trusty/LTS or enjoy the cutting edge on the daily developed release of Wily.

The idea manifested in a really funny project. The source tree of the project is pretty empty. Only cmake and the debian/rules take care of the job. The builder pulls the latest stable Qt, QtCreator and UITK. Builds and integrates the libdbusmenu-qt and appmenu-qt5 projects and deploys the SDK IDE. The package itself is super skinny. Opposing the old model where QtCreator has pulled most of the Qt modules as dependencies this package contains all it needs and the size of it is impressing 36MB. Cheap. Just the way I like it. Plus this package already contains the 1.3 UITK as our QtCreator plugin (Devices Tab) is using it. So in fact we are just one step from enabling desktop application development on 14.04 LTS with the same UI Toolkit as we use on the commercial phone devices. And that is a super hot idea.

The Ubuntu SDK IDE project lives here: https://launchpad.net/ubuntu-sdk-ide

If you want to check out how it is done:

$ bzr branch lp:ubuntu-sdk-ide

Since we considered such a big facelift on the SDK I thought why not to make the change much bigger. Some might remember that there was a discussion on the Ubuntu Phone mailing list about the possibility to improve the Kit creation in the IDE. Since then we have been playing with the idea and I think it is now a good time to unleash the static chroots.

The basic idea is that creating the builder chroots runtime is a super slow and fragile process. The bootstrapping of the click chroot already takes a long time and installing the SDK API packages (all the libs and dev packages with headers) into the chroot is also time consuming. So why not to create these root filesystems in advance and provide them as single installable packages.

This is exactly what we have done. The base of the API packages is the Vivid core image. It is small and contains only the absolutely necessary packages, we install the SDK libs, dev packages and development tools on the core image and configure the Overlay PPA too. So the final image is pretty much equivalent with the image on a freshly updated device out there. It means that the developer can build and test against the same API set as it is available on the devices.

These API packages are still huge. Their size is around 500MB, so on a slow connection it still takes ages to download, but still it is way faster than bootstrapping a 1.6GB chroot package by package.

This API packages contain a single tar.gz file and the post install script of the package puts the content of this tar.gz to the right place and wires it in, in the way it should be. Once the package is installed the new Kit will be automatically recognized by the IDE.

One important note on this API package! If you have an armhf 15.04 Kit (click chroot) already on your system when you install this package, then your original Kit will not be removed but simply renamed to backup-[timestamp]-[original name]. So do not worry if you have customized Kits, they are safe.

The Ubuntu SDK API project is only a packaging project with a simple script to take care of the dirty details. The project is hosted here: https://launchpad.net/ubuntu-sdk-api-15.04

And if you want to see what is in it just do

$ bzr branch lp:ubuntu-sdk-api-15.04  

The release candidate packages are available from the Tools Development PPA of the SDK team: https://launchpad.net/~ubuntu-sdk-team/+archive/ubuntu/tools-development

How to test these packages?

$ sudo add-apt-repository ppa:ubuntu-sdk-team/tools-development -y

$ sudo apt-get update

$ sudo apt-get install ubuntu-sdk-ide ubuntu-sdk-api-tools

$ sudo apt-get install ubuntu-sdk-api-15.04-armhf ubuntu-sdk-api-15.04-i386

After that look for the Ubuntu SDK IDE in the dash.

Read more
April Wang

因为黑客松活动,在炎炎夏日的8月里第一次飞到了深圳,这个潮湿闷热的城市让我“大跌眼镜”(不停冒汗,眼镜真的一直往下掉)。 活动现场是在位于福田区华强北商圈中的华强创客中心,不论是平日里还是周末,路边楼下仿佛永远都是人流涌动热闹非凡。华强北创客中心是由华强集团倾力打造,中国第一个为创业者提供一站式服务的综合型创新创业生态平台。一期建筑面积有5000㎡,位于华强广场B座7楼的空中花园,堪称是华强北闹市中的一片室外桃园。整体设计布满了类似街头艺术的graffiti式画作,置身其中就能感受到它灵感激发的能量,黑客松选这里自然是理所当然。

 

Canonical一直坚信激励创新的最佳方式就是将他们需要的技术给到创新者的手中,这次深圳黑客松除了Ubuntu手机操作系统平台之外,我们还带了Ubuntu Snappy Core, 一款安全易用的智能硬件操作系统技术。针对这个最新技术, 我们在活动TechTalk环节详细讲解了如何通过KVM来做开发的上手介绍。错过的同学可以在这里下载文档参看视频。而参加活动的同学们通过将Ubuntu手机平台和Snappy技术相结合将会获得特别IoT奖项。所以这场活动的亮点和看点更加有趣。 

22日的上午10点半,倒计时开始,黑客松正式进入hacking时段。不吃不喝不停不休的30个小时之后。

呵呵, 开玩笑了,一定是有吃有喝有玩有乐了,而且还有夜宵火锅,台式足球。

既然是场hackathon,重头戏当然还是这场hacking party产出的作品了。下面我就挑几组现场做了作品和大家分享。

QML Git-OSC是由开源中国团队开发的一款基于QML的Ubuntu手机应用,有了它程序猿攻城狮们可以直接通过Ubuntu手机端访问查看保存在自己在Git@OSC上的Repo详情和代码了。作为一款为写代码人群定制的应用,这组团队成功获得了最佳上手奖- 樱桃机械键盘。

iFace是第二组出场的demo作品,展示队员Mago用含蓄幽默的方式介绍了一款,在“这个看脸的时代”,用你的颜值当工具的应用。通过脸部验证登录,上网约聊。这么懂时代,能聊的队伍很不意外的拿走了由优麒麟赞助的能说会道奖-一款便携音箱。

这场黑客松中最吸引眼球的团队E Minor(E小调),在30个小时的黑客松内产出了两款作品:LibreOffice Impress Remote 和让我从第一天就在期待的Project MrRobot。Impress Remote作品正如其名,可以让你的Ubuntu手机即刻变成你Impress文档的remote,简单但超级实用。Project Mr Robot是一款由Ubuntu手机操控超萌Rapiro机器人的应用,通过这款应用你可以通过语音,按键和摇手机来操控它。两款作品的代码也完全开源,感兴趣的同学们可以在这里这里分别找到他们的代码。这支团队,轻松拿下我们的最佳颜值奖(Ubuntu双肩背包)和最佳极客奖(由华硕公司特别赞助的移动便携投影仪);这里也特别感谢为这组颁奖,也是我们现场评审之一的美女评审秦夏鸿女士(灵游科技的副总裁)。此外Project Robot在活动结束第二天就已经被Softpedia点名报道了。

IoT Ranger是一款专为电脑牵挂强迫症人群定制的应用。它为Ubuntu手机用户提供了一个随时监测家里电脑运行状态的应用。这款基于cordava的Ubuntu手机应用,巧妙使用运行在kvm环境下的网络服务框架,成功的将Ubuntu Snappy Core技术和Ubuntu手机应用开发相结合。绝对是这次黑客松中当之不愧的IoT特别奖项作品,自然拿下了我们精心准备的Beaglebone Black。

活动现场展示的作品还有几组我就不在这里一一介绍了, 感兴趣的同学们可以后续在Ubuntu开发者网站(cn.developer.ubuntu.com)的黑客松页面找到每组作品介绍。在短短的30个小时内,我们见证了如此之多的精彩,不禁就已经开始期待下一次了。 希望在后面的日子里,每个团队都能实现作品的成功部署,在外面的世界里成功立足。 代码写的辛苦,但是能和兴趣相投的人一起通宵畅聊应该是最过瘾的事了。在此献上活动现场制作的文化衫照片和大家分享。

最后要再次感谢这次活动的特约赞助商华硕,除了特别极客奖之外,还为大家提供了丰盛的签到奖和现场Demo奖;感谢线上线下的协办单位和论坛平台让这场黑客松成为可能(Git@OSC, SegmentFault,开源中国开源社Linux伊甸园Linux中国Linuxtoy.orgQTCN开发网, Meego南极圈深圳开放创新实验室SegmentFault腾讯开放平台优麒麟中芬设计园),感谢现场评审团队,还有让这场活动分外精彩的场地赞助华强北创客中心,为大家提供分外精彩的场地赞助,轻松愉快的氛围激发大家无限的创作灵感。

 

Read more
Michi Henning

A Fast Thumbnailer for Ubuntu

Over the past few months, James Henstridge, Xavi Garcia Mena, and I have implemented a fast and scalable thumbnailing service for Ubuntu and Ubuntu Touch. This post explains how we did it, and how we achieved our performance and reliability goals.

Introduction

On a phone as well as the desktop, applications need to display image thumbnails for various media, such as photos, songs, and videos. Creating thumbnails for such media is CPU-intensive and can be costly in bandwidth if images are retrieved over the network. In addition, different types of media require the use of different APIs that are non-trivial to learn. It makes sense to provide thumbnail creation as a platform API that hides this complexity from application developers and, to improve performance, to cache thumbnails on disk.

This article explains the requirements we had and how we implemented a thumbnailer service that is extremely fast and scalable, and robust in the face of power loss or crashes.

Requirements

We had a number of requirements we wanted to meet in our implementation.

  • Robustness
    In the event of a crash, the implementation must guarantee the integrity of on-disk data structures. This is particularly important on a phone, where we cannot expect the user to perform manual recovery (such as cleaning up damaged files). Because batteries can run out at any time, integrity must be guaranteed even in the face of power loss.
  • Scalability
    It is common for people to store many thousands of songs and photos on a device, so the cache must scale to at least tens of thousands of records. Thumbnails can range in size from a few kilobytes to well over a megabyte (for “thumbnails” at full-screen resolution), so the cache must deal efficiently with large records.
  • Re-usability
    Persistent and reliable on-disk storage of arbitrary records (ranging in size from a few bytes to potentially megabytes) is a common application requirement, so we did not want to create a cache implementation that is specific to thumbnails. Instead, the disk cache is provided as a stand-alone C++ API that can be used for any number of other purposes, such as a browser or HTTP cache, or to build an object file cache similar to ccache.
  • High performance
    The performance of the thumbnailer directly affects the user experience: it is not nice for the customer to look at “please wait a while” icons in, say, an image gallery while thumbnails are being loaded one by one. We therefore had to have a high-performance implementation that delivers cached thumbnails quickly (on the order of a millisecond per thumbnail on an Arm CPU). An efficient implementation also helps to conserve battery life.
  • Location independence and extensibility
    Canonical runs an image server at dash.ubuntu.com that provides album and artist artwork for many musicians and bands. Images from this server are used to display artwork in the music player for media that contains ID3 tags, but does not embed artwork in the media file. The thumbnailer must work with embedded images as well as remote images, and it must be possible to extend it for new types of media without unduly disturbing the existing code.
  • Low bandwidth consumption
    Mobile phones typically come with data caps, so the cache has to be frugal with network bandwidth.
  • Concurrency and isolation
    The implementation has to allow concurrent access by multiple applications, as well as concurrent access from a single implementation. Besides needing to be thread-safe, this means that a request for a thumbnail that is slow (such as downloading an image over the network) must not delay other requests.
  • Fault tolerance
    Mobile devices lose network access without warning, and users can add corrupt media files to their device. The implementation must be resilient to partial failures, such as incomplete network replies, dropped connections, and bad image data. Moreover, the recovery strategy for such failures must conserve battery and avoid repeated futile attempts to create thumbnails from media that cannot be retrieved or contains malformed data.
  • Security
    The implementation must ensure that applications cannot see (or, worse, overwrite) each other’s thumbnails or coerce the thumbnailer into delivering images from files that an application is not allowed to read.
  • Asynchronous API
    The customers of the thumbnailer are applications that are written in QML or Qt, which cannot block in the UI thread. The thumbnailer therefore must provide a non-blocking API. Moreover, the application developer should be able to get the best possible performance without having to use threads. Instead, concurrency must be internal to the implementation (which is able to put threads to use intelligently where they make sense), instead of the application throwing threads at the problem in the hope that it might make things faster when, in fact, it might just add overhead.
  • Monitoring
    The effectiveness of a cache cannot be assessed without statistics to show hit and miss rates, evictions, and other basic performance data, so it must provide a way to extract this information.
  • Error reporting
    When something goes wrong with a system service, typically the only way to learn about the problem is to look at log messages. In case of a failure, the implementation must leave enough footprints behind to allow someone to diagnose a failure after the fact with some chance of success.
  • Backward compatibility
    This project was a rewrite of an earlier implementation. Rather than delivering a “big bang” piece of software and potentially upsetting existing clients, we incrementally changed the implementation such that existing applications continued to work. (The only pre-existing interface was a QML interface that required no change.)

System architecture

Here is a high-level overview of the main system components.

A Fast Thumbnailer for UbuntuExternal API

To the outside world, the thumbnailer provides two APIs.

One API is a QML plugin that registers itself as an image provider for QQuickAsyncImageProvider. This allows the caller to to pass a URI that encodes a query for a local or remote thumbnail at a particular size; if the URI matches the registered provider, QML transfers control to the entry points in our plugin.

The second API is a Qt API that provides three methods:

QSharedPointer<Request> getThumbnail(QString const& filePath,
                                     QSize const& requestedSize);
QSharedPointer<Request> getAlbumArt(QString const& artist,
                                    QString const& album,
                                    QSize const& requestedSize);
QSharedPointer<Request> getArtistArt(QString const& artist,
                                     QString const& album,
                                     QSize const& requestedSize);

The getThumbnail() method extracts thumbnails from local media files, whereas getAlbumArt() and getArtistArt() retrieve artwork from the remote image server. The returned Request object provides a finished signal, and methods to test for success or failure of the request and to extract a thumbnail as a QImage. The request also provides a waitForFinished() method, so the API can be used synchronously.

Thumbnails are delivered to the caller in the size they are requested, subject to a (configurable) 1920-pixel limit. As an escape hatch, requests with width and height of zero deliver artwork at its original size, even if it exceeds the 1920-pixel limit. The scaling algorithm preserves the original aspect ratio and never scales up from the original, so the returned thumbnails may be smaller than their requested size.

DBus service

The thumbnailer is implemented as a DBus service with two interfaces. The first interface provides the server-side implementation of the three methods of the external API; the second interface is an administrative interface that can deliver statistics, clear the internal disk caches, and shut down the service. A simple tool, thumbnailer-admin, allows both interfaces to be called from the command line.

To conserve resources, the service is started on demand by DBus and shuts down after 30 seconds of idle time.

Image extraction

Image extraction uses an abstract base class. This interface is independent of media location and type. The actual image extraction is performed by derived implementations that download images from the remote server, extract them from local image files, or extract them from local streaming media files. This keeps knowledge of image location and encoding out of the main caching and error handling logic, and allows us to support new media types (whether local or remote) by simply adding extra derived implementations.

Image extraction is asynchronous, with currently three implementations:

  • Image downloader
    To retrieve artwork from the remote image server, the service talks to an abstract base class with asynchronous download_album() and download_artist() methods. This allows multiple downloads to run concurrently and makes it easy to add new local or remote image providers without disturbing the code for existing ones. A class derived from that abstract base implements a REST API with QNetworkAccessManager to retrieve images from dash.ubuntu.com.
  • Photo extractor
    The photo extractor is responsible for delivering images from local image files, such as JPEG or PNG files. It simply delegates that work to the image converter and scaler.
  • Audio and video thumbnail extractor
    To extract thumbnails from audio and video files, we use GStreamer. Due to reliability problems with some codecs that can hang or crash, we delegate the task to a separate vs-thumb executable. This shields the service from failures and also allows us to run several GStreamer pipelines concurrently without a crash of one pipeline affecting the others.

Image converter and scaler

We use a simple Image class with a synchronous interface to convert and scale different image formats to JPEG. The implementation uses Gdk-Pixbuf, which can handle many different input formats and is very efficient.

For JPEG source images, the code checks for the presence of EXIF data using libexif and, if it contains a thumbnail that is at least as large as the requested size, scales the thumbnail from the EXIF data. (For images taken with the camera on a Nexus 4, the original image size is 3264×1836, with an embedded EXIF thumbnail of 512×288. Scaling from the EXIF thumbnail is around one hundred times faster than scaling from the full-size image.)

Disk cache

The thumbnailer service optimizes performance and conserves bandwidth and battery by adopting a layered caching strategy.

Two-level caching with failure lookup

Internally, the service uses three separate on-disk caches:

  • Full-size cache
    This cache stores images that are expensive to retrieve (images that are remote or are embedded in audio and video files) at original resolution (scaled down to a 1920-pixel bounding box if the original image is larger). The default size of this cache is 50 MB, which is sufficient to hold around 400 images at 1920×1080 resolution. Images are stored in JPEG format (at a 90% quality setting).
  • Thumbnail cache
    This cache stores thumbnails at the size that was requested by the caller, such as 512×288. The default size of this cache is 100 MB, which is sufficient to store around 11,000 thumbnails at 512×288, or around 25,000 thumbnails at 256×144.
  • Failure cache
    The failure cache stores the keys for images that could not be extracted because of a failure. For remote images, this means that the server returned an authoritative answer “no such image exists”, or that we encountered an unexpected (non-authoritative) failure, such as the server not responding or a DNS lookup timing out. For local images, it means either that the image data could not be processed because it is damaged, or that an audio file does not contain embedded artwork.

The full-size cache exists because it is likely that an application will request thumbnails at different sizes for the same image. For example, when scrolling through a list of songs that shows a small thumbnail of the album cover beside each song, the user is likely to select one of the songs to play, at which point the media player will display the same cover in a larger size. By keeping full-size images in a separate (smallish) cache, we avoid performing an expensive extraction or download a second time. Instead, we create additional thumbnails by scaling them from the full-size cache (which uses an LRU eviction policy).

The thumbnail cache stores thumbnails that were previously retrieved, also using LRU eviction. Thumbnails are stored as JPEG at the default quality setting of 75%, at the actual size that was requested by the caller. Storing JPEG images (rather than, say, PNG) saves space and increases cache effectiveness. (The minimal quality loss from compression is irrelevant for thumbnails). Because we store thumbnails at the size they are actually needed, we may have several thumbnails for the same image in the cache (each thumbnail at a different size). But applications typically ask for thumbnails in only a small number of sizes, and ask for different sizes for the same image only rarely. So, the slight increase in disk space is minor and amply repaid by applications not having to scale thumbnails after they receive them from the cache, which saves battery and achieves better performance overall.

Finally, the failure cache is used to stop futile attempts to repeatedly extract a thumbnail when we know that the attempt will fail. It uses LRU eviction with an expiry time for each entry.

Cache lookup algorithm

When asked for a thumbnail at a particular size, the lookup and thumbnail generation proceed as follows:

  1. Check if a thumbnail exists in the requested size in the thumbnail cache. If so, return it.
  2. Check if a full-size image for the thumbnail exists in the full-size cache. If so, scale the new thumbnail from the full-size image, add the thumbnail to the thumbnail cache, and return it.
  3. Check if there is an entry for the thumbnail in the failure cache. If so, return an error.
  4. Attempt to download or extract the original image for the thumbnail. If the attempt fails, add an entry to the failure cache and return an error.
  5. If the original image was delivered by the remote server or was extracted locally from streaming media, add it to the full-size cache.
  6. Scale the thumbnail to the desired size, add it to the thumbnail cache, and return it.

Note that these steps represent only the logical flow of control for a particular thumbnail. The implementation executes these steps concurrently for different thumbnails.

Designing for performance

Apart from fast on-disk caches (see below), the thumbnailer must make efficient use of I/O bandwidth and threads. This not only means making things fast, but also to not unnecessarily waste resources such as threads, memory, network connections, or file descriptors. Provided that enough requests are made to keep the service busy, we do not want it to ever wait for a download or image extraction to complete while there is something else that could be done in the mean time, and we want it to keep all CPU cores busy. In addition, requests that are slow (because they require a download or a CPU-intensive image extraction) must not block requests that are queued up behind them if those requests would result in cache hits that could be returned immediately.

To achieve a high degree of concurrency without blocking on long-running operations while holding precious resources, the thumbnailer uses a three-phase lookup algorithm:

  1. In phase 1, we look at the caches to determine if we have a hit or an authoritative miss. Phase 1 is very fast. (It takes around a millisecond to return a thumbnail from the cache on a Nexus 4.) However, cache lookup can briefly stall on disk I/O or require a lot of CPU to extract and scale an image. To get good performance, phase 1 requests are passed to a thread pool with as many threads as there are CPU cores. This allows the maximum number of lookups to proceed concurrently.
  2. Phase 2 is initiated if phase 1 determines that a thumbnail requires download or extraction, either of which can take on the order of seconds. (In case of extraction from local media, the task is CPU intensive; in case of download, most of the time is spent waiting for the reply from the server.) This phase is scheduled asynchronously from an event loop. This minimizes task switching and allows large numbers of requests to be queued while only using a few bytes for each request that is waiting in the queue.
  3. Phase 3 is really a repeat of phase 1: if phase 2 produces a thumbnail, it adds it to the cache; if phase 2 does not produce a thumbnail, it creates an entry in the failure cache. By simply repeating phase 1, the lookup then results in either a thumbnail or an error.

If phase 2 determines that a download or extraction is required, that work is performed concurrently: the service schedules several downloads and extractions in parallel. By default, it will run up to two concurrent downloads, and as many concurrent GStreamer pipelines as there are CPUs. This ensures that we use all of the available CPU cores. Moreover, download and extraction run concurrently with lookups for phase 1 and 3. This means that, even if a cache lookup briefly stalls on I/O, there is a good chance that another thread can make use of the CPU.

Because slow operations do not block lookup, this also ensures that a slow request does not stall requests for thumbnails that are already in the cache. In other words, it does not matter how many slow requests are in progress: requests that can be completed quickly are indeed completed quickly, regardless of what is going on elsewhere.

Overall, this strategy works very well. For example, with sufficient workload, the service achieves around 750% CPU utilization on an 8-core desktop machine, while still delivering cache hits almost instantaneously. (On a Nexus 4, cache hits take a little over 1 ms while concurrent extractions or downloads are in progress.)

A re-usable persistent cache for C++

The three internal caches are implemented by a small and flexible C++ API. This API is available as a separate reusable PersistentStringCache component (see persistent-cache-cpp) that provides a persistent store of arbitrary key–value pairs. Keys and values can be binary, and entries can be large. (Megabyte-sized values do not present a problem.)

The implementation uses leveldb, which provides a very fast NoSQL database that scales to multi-gigabyte sizes and provides integrity guarantees. In particular, if the calling process crashes, all inserts that completed at the API level will be intact after a restart. (In case of a power failure or kernel crash, a few buffered inserts can be lost, but the integrity of the database is still guaranteed.)

To use a cache, the caller instantiates it with a path name, a maximum size, and an eviction policy. The eviction policy can be set to either strict LRU (least-recently-used) or LRU with an expiry time. Once a cache reaches its maximum size, expired entries (if any) are evicted first and, if that does not free enough space for a new entry, entries are discarded in least-recently-used order until enough room is available to insert a new record. (In all other respects, expired entries behave like entries that were never added.)

A simple get/put API allows records to be retrieved and added, for example:

auto c = core::PersistentStringCache::open(
    “my_cache”, 100 * 1024 * 1024, core::CacheDiscardPolicy::lru_only);
// Look for an entry and add it if there is a cache miss.
string key = "Bjarne";
auto value = c->get(key);
if (value) {
    cout << key << ″: ″ << *value << endl;
} else {
    value = "C++ inventor";  // Provide a value for the key. 
    c->put(key, *value);     // Insert it.
}

Running this program prints nothing on the first run, and “Bjarne: C++ inventor” on all subsequent runs.

The API also allows application-specific metadata to be added to records, provides detailed statistics, supports dynamic resizing of caches, and offers a simple adapter template that makes it easy to store complex user-defined types without the need to clutter the code with explicit serialization and deserialization calls. (In a pinch, if iteration is not needed, the cache can be used as a persistent map by setting an impossibly large cache size, in which case no records are ever evicted.)

Performance

Our benchmarks indicate good performance. (Figures are for an Intel Ivy Bridge i7-3770k 3.5 GHz machine with a 256 GB SSD.) Our test uses 60-byte string keys. Values are binary blobs filled with random data (so they are not compressible), 20 kB in size with a standard deviation of 7,000, so the majority of values are 13–27 kB in size. The cache size is 100 MB, so it contains around 5,000 records.

Filling the cache with 100 MB of records takes around 2.8 seconds. Thereafter, the benchmark does a random lookup with an 80% hit probability. In case of a cache miss, it inserts a new random record, evicting old records in LRU order to make room for the new one. For 100,000 iterations, the cache returns around 4,800 “thumbnails” per second, with an aggregate read/write throughput of around 93 MB/sec. At 90% hit rate, we see twice the performance at around 7,100 records/sec. (Writes are expensive once the cache is full due to the need to evict entries, which requires updating the main cache table as well as an index.)

Repeating the test with a 1 GB cache produces identical timings so (within limits) performance remains constant for large databases.

Overall, performance is restricted largely by the bandwidth to disk. With a 7,200 rpm disk, we measured around one third of the performance with an SSD.

Recovering from errors

The overall design of the thumbnailer delivers good performance when things work. However, our implementation has to deal with the unexpected, such as network requests that do not return responses, GStreamer pipelines that crash, request overload, and so on. What follows is a partial list of steps we took to ensure that things behave sensibly, particularly on a battery-powered device.

Retry strategy

The failure cache provides an effective way to stop the service from endlessly trying to create thumbnails that, in an earlier attempt, returned an error.

For remote images, we know that, if the server has (authoritatively) told us that it has no artwork for a particular artist or album, it is unlikely that artwork will appear any time soon. However, the server may be updated with more artwork periodically. To deal with this, we add an expiry time of one week to the entries in the failure cache. That way, we do not try to retrieve the same image again until at least one week has passed (and only if we receive a request for a thumbnail for that image again later).

As opposed to authoritative answers from the image server (“I do not have artwork for this artist.”), we can also encounter transient failures. For example, the server may currently be down, or there may be some other network-related issue. In this case, we remember the time of the failure and do not try to contact the remote server again for two hours. This conserves bandwidth and battery power.

The device may also disconnected from the network, in which case any attempt to retrieve a remote image is doomed. Our implementation returns failure immediately on a cache miss for a remote image if no network is present or the device is in flight mode. (We do not add an entry to the failure cache in this case).

For local files, we know that, if an attempt to get a thumbnail for a particular file has failed, future attempts will fail as well. This means that the only way for the problem to get fixed is by modifying or replacing the actual media file. To deal with this, we add the inode number, modification time, and inode modification time to the key for local images. If a user replaces, say, a music file with a new one that contains artwork, we automatically pick up the new version of the file because its key has changed; the old version will eventually fall out of the cache.

Download and extraction failures

We monitor downloads and extractions for timely completion. (Timeouts for downloads and extractions can be configured separately.) If the server does not respond within 10 seconds, we abandon the attempt and treat it it as a transient network error. Similarly, the vs-thumb processes that extract images from audio and video files can hang. We monitor these processes and kill them if they do not produce a result within 10 seconds.

Database corruption

Assuming an error-free implementation of leveldb, database corruption is impossible. However, in practice, an errant command could scribble over the database files. If leveldb detects that the database is corrupted, the recovery strategy is simple: we delete the on-disk cache and start again from scratch. Because the cache contents are ephemeral anyway, this is fine (other than slower operation until the working set of thumbnails makes it into the cache again).

Dealing with backlog

The asynchronous API provided by the service allows an application to submit an unlimited number of requests. Lots of requests happen if, for example, the user has inserted a flash card with thousands of photos into the device and then requests a gallery view for the collection. If the service’s client-side API blindly forwards requests via DBus, this causes a problem because DBus terminates the connection once there are more than around 400 outstanding requests.

To deal with this, we limit the number of outstanding requests to 200 and send another request via DBus only when an earlier request completes. Additional requests are queued in memory. Because this happens on the client side, the number of outstanding requests is limited only by the amount of memory that is available to the client.

A related problem arises if a client submits many requests for a thumbnail for the same image. This happens when, for example, the user looks at a list of tracks: tracks that belong to the same album have the same artwork. If artwork needs to be retrieved from the remote server, naively forwarding cache misses for each thumbnail to the server would end up re-downloading the same image several times.

We deal with this by maintaining an in-memory map of all remote download requests that are currently in progress. If phase 1 reports a cache miss, before initiating a download, we add the key for the remote image to the map and remove it again once the download completes. If more requests for the same image encounter a cache miss while the download for the original request is still in progress, the key for the in-progress download is still in the map, and we hold additional requests for the same image until the download completes. We then schedule the held requests as usual and create their thumbnails from the image that was cached by the first request.

Security

The thumbnailer runs with normal user privileges. We use AppArmor’s aa_query_label() function to verify that the calling client has read access to a file it wants a thumbnail for. This prevents one application from accessing thumbnails produced by a different application, unless both applications can read the original file. In addition, we place the entire service under an AppArmor profile to ensure that it can write only to its own cache directory.

Conclusion

Overall, we are very pleased with the overall design and performance of the thumbnailer. Each component has a clearly defined role with a clean interface, which made it easy for us to experiment and to refine the design as we went along. The design is extensible, so we can support additional media types or remote data sources without disturbing the existing code.

We used threads sparingly and only where we saw worthwhile concurrency opportunities. Using asynchronous interfaces for long-running operations kept resource usage to a minimum and allowed us to take advantage of I/O interleaving. In turn, this extracts the best possible performance from the hardware.

The thumbnailer now runs on Ubuntu Touch and is used by the gallery, camera, and music apps, as well as for all scopes that display media thumbnails.

This article has been originally published on Michi Henning's blog.

Read more
Tim Peeters

Adaptive page layouts made easy

Convergent applications

We want to make it easy for app developers to write an app that can run on different form factors without changes in the code. This implies that an app should support screens of various sizes, and the layout of the app should be optimal for each screen size. For example, a messaging app running on a desktop PC in a big window could show a list of conversations in a narrow column on the left, and the selected conversation in a wider column on the right side. The same application on a phone would show only the list of conversations, or the selected conversation with a back-button to return to the list. It would also be useful if the app automatically switches between the 1-column and 2-column layouts when the user resizes the window, or attaches a large screen to the phone.

To accomplish this, we introduced the AdaptivePageLayout component in Ubuntu.Components 1.3. This version of  Ubuntu.Components is still under development (expect an official release announcement soon), but if you are running the latest version of the Ubuntu UI Toolkit, you can already try it out by updating your import Ubuntu.Components to version 1.3. Note that you should not mix import versions, so when you update one of your components to 1.3, they should all be updated.

AdaptivePageLayout

AdaptivePageLayout is an Item with the following properties and functions:

  • property Page primaryPage
  • function addPageToCurrentColumn(sourcePage, newPage)
  • function addPageToNextColumn(sourcePage, newPage)
  • function removePages(page)

To understand how it works, imagine that internally, the AdaptivePageLayout keeps track of an infinite number of virtual columns that may be displayed on your screen. Not all virtual columns are visible on the screen. By default, depending on the width of your AdaptivePageLayout, either one or two columns are visible. When a Page is added to a virtual column that is not visible, it will instead be shown in the right-most visible column.

The Page defined as primaryPage will initially be visible in the first (left-most) column and all the other columns are empty (see figure 1).

Figure 1: Showing only primaryPage in layouts of 100 and 50 grid-units.
Showing only primaryPage at 100 grid units. Showing primaryPage at 50 grid units.

To show another Page in the first column, call addPageToCurrentColumn() with as parameters the current page (primaryPage), and the new page. The new page will then show up in the same column with a back button in the header to close the new page and return to the previous page (see figure 2). So far, AdaptivePageLayout is no different than a PageStack.

Figure 2: Page with back button in the first column.
Page with back button in the first column at 100 grid units. Page with back button in first column at 50 grid units.

The differences with PageStack become evident when you want to keep the first page visible in the first column, while adding a new page to the next column. To do this, call addPageToNextColumn() with the same parameters as addPageToCurrentColumn() above. The new page will now show up in the following column on the screen (see figure  3).

Figure 3: Adding a page to the next column.
Added a page to the next column at 100 grid units. Added a page to the next column at 50 grid units.

However, if you resize the window so that it fits only one column, the left column will be hidden, and the page that was in the right column will now have a back button. Resizing back to get the two-column layout will again give you the first page on the left, and the new page on the right. Call removePages(page) to remove page and all pages that were added after page was added. There is one exception: primaryPage is never removed, so removePages(primaryPage) will remove all pages except primaryPage and return your AdaptivePageLayout to its initial state.

AdaptivePageLayout automatically chooses between a one and two-column layout depending on the width of the window. It also automatically shows a back button in the correct column when one is needed and synchronizes the header size between the different columns (see figure 4).

Figure 4: Adding sections to any column increases the height of the header in every column.
Added a page with sections to the right column at 100 grid units. Added a page with sections at 50 grid units.

Future extensions

The version of AdaptivePageLayout that is now in the UI toolkit is only the first version. What works now will keep working, but we will extend the API to support the following:

  • Layouts with more than two columns
  • Use different conditions for switching between layouts
  • User-resizable columns
  • Automatic and manual hiding of the header in single-column layouts
  • Custom proxy objects to support Autopilot tests for applications

Below you can read the full source code that was used to create the screenshots above. The screenhots do not cover all the possible orders in which the pages left and right can be added, so I encourage you to run the code for yourself and discover its full behavior. We are looking forward to see your first applications using the new AdaptivePageLayout component soon :). Of course if there are any questions you can leave a comment below or ping members of the SDK team (I am t1mp) in #ubuntu-app-devel on Freenode IRC.

 

import QtQuick 2.4
import Ubuntu.Components 1.3

MainView {
    width: units.gu(100)
    height: units.gu(70)

    AdaptivePageLayout {
        id: layout
        anchors.fill: parent
        primaryPage: rootPage

        Page {
            id: rootPage
            title: i18n.tr("Root page")

            Column {
                anchors {
                    top: parent.top
                    left: parent.left
                    margins: units.gu(1)
                }
                spacing: units.gu(1)

                Button {
                    text: "Add page left"
                    onClicked: layout.addPageToCurrentColumn(rootPage, leftPage)
                }
                Button {
                    text: "Add page right"
                    onClicked: layout.addPageToNextColumn(rootPage, rightPage)
                }
                Button {
                    text: "Add sections page right"
                    onClicked: layout.addPageToNextColumn(rootPage, sectionsPage)
                }
            }
        }

        Page {
            id: leftPage
            title: i18n.tr("First column")

            Rectangle {
                anchors {
                    fill: parent
                    margins: units.gu(2)
                }
                color: UbuntuColors.orange

                Button {
                    anchors.centerIn: parent
                    text: "right"
                    onTriggered: layout.addPageToNextColumn(leftPage, rightPage)
                }
            }
        }

        Page {
            id: rightPage
            title: i18n.tr("Second column")

            Rectangle {
                anchors {
                    fill: parent
                    margins: units.gu(2)
                }
                color: UbuntuColors.green

                Button {
                    anchors.centerIn: parent
                    text: "Another page!"
                    onTriggered: layout.addPageToCurrentColumn(rightPage, sectionsPage)
                }
            }
        }

        Page {
            id: sectionsPage
            title: i18n.tr("Page with sections")
            head.sections.model: [i18n.tr("one"), i18n.tr("two"), i18n.tr("three")]

            Rectangle {
                anchors {
                    fill: parent
                    margins: units.gu(2)
                }
                color: UbuntuColors.blue
            }
        }
    }
}

 

Read more
Daniel Holbach

Announcing UbuContest 2015

Have you read the news already? Canonical, the Ubucon Germany 2015 team, and the UbuContest 2015 team, are happy to announce the first UbuContest! Contestants from all over the world have until September 18, 2015 to build and publish their apps and scopes using the Ubuntu SDK and Ubuntu platform. The competion has already started, so register your competition entry today! You don’t have to create a new project, submit what you have and improve it over the next two months.

But we know it's not all about shiny new apps and scopes! A great platform also needs content, great design, testing, documentation, bug management, developer support, interesting blog posts, technology demonstrations and all of the other incredible things our community does every day. So we give you, our community members, the opportunity to nominate other community members for prizes!

We are proud to present five dedicated categories:

  1. Best Team Entry: A team of up to three developers may register up to two apps/scopes they are developing. The jury will assign points in categories including "Creativity", "Functionality", "Design", "Technical Level" and "Convergence". The top three entries with the most points win.

  2. Best Individual Entry: A lone developer may register up to two apps/scopes he or she is developing. The rest of the rules are identical to the "Best Team Entry" category.

  1. Outstanding Technical Contribution: Members of the general public may nominate candidates who, in their opinion, have done something "exceptional" on a technical level. The nominated candidate with the most jury votes wins.

  1. Outstanding Non-Technical Contribution: Members of the general public may nominate candidates who, in their opinion, have done something exceptional, but non-technical, to bring the Ubuntu platform forward. So, for example, you can nominate a friend who has reported and commented on all those phone-related bugs on Launchpad. Or nominate a member of your local community who did translations for Core Apps. Or nominate someone who has contributed documentation, written awesome blog articles, etc. The nominated candidate with the most jury votes wins.

  1. Convergence Hero: The "Best Team Entry" or "Best Individual Entry" contribution with the highest number of "Convergence" points wins. The winner in this category will probably surprise us in ways we have yet to imagine.

Our community judging panel members Laura Cowen, Carla Sella, Simos Xenitellis, Sujeevan Vijayakumaran and Michael Zanetti will select the winners in each category. Successful winners will be awarded items from a huge pile of prizes, including travel subsidies for the first-placed winners to attend Ubucon Germany 2015 in Berlin, four Ubuntu Phones sponsored by bq and Meizu, t-shirts, and bundles of items from the official Ubuntu Shop.

We wish all the contestants good luck!

Go to ubucontest.eu or ubucon.de/2015/contest for more information, including how to register and nominate folks. You can also follow us on Twitter @ubucontest, or contact us via e-mail at contest@ubucon.de.

 

Read more
April Wang

手机系统7月更新

7月份Ubuntu手机系统的更新信息列表:

常规类改善

  • 图标更新,包括应用和提示类图标
  • Shell rotation
  • 增加了更多欧洲小语种语言类键盘,包括罗马尼亚语,苏格兰盖尔语,希腊语,挪威文,乌兰克语,斯洛伐克文,冰岛文

Scopes

  • 默认聚合类新闻,照片,和今天Scope中都已经支持关键词标注

商店更新

  • 退款功能 (Ubuntu商店目前允许用户在购买应用后15分钟内取消订单)
  • 新增应用评级编辑

浏览器更新

  • 新增书签文件夹
  • 键盘便捷键功能

其他

  • 改善了来电转发的用户界面(在系统设置 > 手机)
  • 添加了WPA企业级支持到系统设置和网络中
  • 在魅族MX4手机上实现了,通过LED闪灯提示用户手机有最新提示讯息
  • 新增在拨号和短信应用中编辑联络人信息的功能
  • 支持在拨号和短信应用中使用群发信息
  • 添加了GPS位置标注到照相机中
  • SDK最新添加了让显示屏持续开启的功能(例如,在游戏开发中,开发者可以避免屏幕自动超时黑屏的情况)
  • 另外还修复了50多个小八哥

Read more
April Wang

Ubuntu设计-ol-01.jpg

 

To celebrate the Developer Edition Ubuntu phone launch in China, Canonical organized a “celebrate Ubuntu” hackathon for phone in Beijing. It is also hosted as part of the on-going China Mobile & Ubuntu Developer Innovation Contest, all projects that were coded during the hackathon can be submitted into the contest afterwards.  This 30+ hour hackathon was packed with creativity, excitement and laughter, it was exhausting but amazingly fun.

With the help of media partners (TechCrunch CN, Tech Noda), local tech partners & communities (GitCafe, MS OpenTech,  Ubuntu Kylin, Kaiyuanshe, SegmentFault, CSDN, linuxCN, OSCN, Linuxeden, QTCN, Linuxtoy.org), there are over 120 people signed up online pre-hackathon, and 70+ people turned up onsite.

IMG_3094.JPG
IMG_3095.JPG

 

Being the first ever Ubuntu phone hackathon in China, it doesn’t have any fixed topic and project requirement, as long as it will run on an ubuntu phone in the end. The entire hackathon was driven by pure innovation and creativity.

Ideas and solutions to problems that can benefit or provide entertainment for phone users is the key for this hackathon. There are 7 different awards to be given out to credit different types of ideas.

  • Avant-garde Award - for the most innovative ideas and projects

  • Geek Award - for hardcore techy geeky projects

  • Foolproof Award - for most user friendly projects

  • TalkDaTalk Award - for best project demonstration

  • Stunning Award - for best design projects

  • Entertaining Award - for most fun and entertaining projects

  • Special Content Award - for certain most needed content providing categories

And every team who stood up and provided a project demo received a final demo prize.

Final judging panels were made up by teams from Canonical and China Mobile device company. Each project are being reviewed by its creativity, usability, problem solving level, technical difficulty, design and the completion level. 30 hour straight hackathon is an intense exercise, there were 14 teams in the end proved their talent and effort through their live demo sessions. Four Meizu MX4 phone were given out for the top 4 teams, and all final teams received a Qt Core Tutorial book and numerous small gifts.

DSC_3439.JPG
DSC_3443.JPG
IMG_3091.JPG

 

A live weibo tweets & hackathon countdown wall, that was put together by @penk , provided a great live interactive platform for onsite participants and online fans and community members.

 

 
The 30+ hour hackathon was fueled with energy, determination and of course food, water, cans of redbull & sweets! :) Here is a few clips on how the energy and creativity was flowing throughout the event.
 
IMG_3783.JPG
 
Some of the teams were fresh learners, spent the first day learning and second day coding. However, some of them in the end were part of the final winners too!
 

 

Then of course, all work and no play makes Jack a dull boy. Various gaming sessions and polaroid fun took place naturally to keep things alive and exciting!

 

 

 

Now let’s take a look at some of the finalists and their amazing work after the 30 hour hackathon.

Douban FM

A great qml app with neat design and smooth user login experience, which also enables multi device sync up under your own account.  Coded by the one man(the guy on the right hand side of the picture) team @DawnDIYSoft, who is also the man behind the current youku scope in the Ubuntu store

 

Loli

A brand new programming language, which was re-implemented with an interpreter built with JavaScript and ported to Ubuntu phone. Their project can be found here on github.  As you have probably guessed by now, they are of course the winner of the Geek Award, which was presented by Caobin, Project Manager from the China Mobile Device Company.

 

Memory Dictionary
Utilizing fragmented time slots in your life, such as when you are travelling on a metro train, to memorizing new words and phrases (English language learning app). The app was already built for MacOS, iOS and Android, and is very popular on those platforms. During the hackathon, the team ported it to Ubuntu phone based on cordova.

 

Couple Like:

An html5 app that compares two person’s pictures to provide a conclusion on what type of couple the two will make. It’s light hearted, fun and packed with love, coded by a team of couple who were on the dance floor not long before the demo.  Also one of the project that runs smoothly on the phone by the end of the hackathon.

 

Dou Dizhu (poker game)

A single poker game with it's own memory management system and AI. It was implemented in qt widget, so still need some work to port it to Ubuntu phone. But through the desktop demo, it already looking addictive and entertaining.

 

Utu / uPhoto

It’s an app implemented with C++ for image/photo processing, still a WIP project, but exciting enough for us to know that soon we can beautifying our snapshots on our Ubuntu phone.  

 

uChat/(Ubuntu Chat)

A dating messaging service application dedicated for anyone who finds it difficult to make the first move or the right move when it comes to meeting someone. It involves server side and client side technology, despite their initial plan of using html5 based on webapp or cordova, the prototype in the end was built with qml by a team of university students in their second and third year.

 

A few more clips of the hackathon and of course a happy group shot.

 

 
 

Read more
April Wang

2015年7月4-5日,我们聚集北京一起经历了Ubuntu手机在中国的首场黑客松。@DawnDIY最近发布了一篇细心记录下的活动回忆录, 在这里和大家分享。 

Ubuntu Hackathon

 2015年07月08日  DawnDIY


前言

很早就知道"黑客松"(Hackathon),也关注过一些国内的 Hackathon 活动,只是一直都没有去尝试参与过。以前是没有美工前端,所以自己变成了个野生渣前端。最近很长时间都在关注 Ubuntu Touch 的进度,得知有在北京举办 Hackathon 活动,也就迅数报名了。好吧,我的第一次 Hackathon 献给 Ubuntu 了。

准备

当然这次 Ubuntu Hackathon 是为 Ubuntu Touch 开发应用。Ubuntu Touch 上的开发基本分三类。

一是 Scope,Scope 目前在中文也没有很合适的翻译,官方也没有给出中文名称我们都以 Scope 来叫它就好了。开发 Scope,官方给出了一个框架并提供了各类API,可以快速的做出一个不错的 Scope,具体可以参见这里 (友情提示: 网页底部有切换简体中文的链接)

二是 QML App,这也是真正意义上的 Native App 吧。使用 QML 语言进行开发,当然可以结合Qt使用C++对其做支持。

三是 HTML5 App,HTML5 应用,当下比较流行吧。因为今年的 HTML5 标准正式发布,和之前各种宣传,HTML5技术也多用于移动设备开发,最大的好处就是 write once, run everywhere 。

四是 Webapp,这个其实就没什么了,可以把现有的网站 url 打包成一个简单的入口 webapp。其实就是一个网站的快捷方式。

对于 Qt/QML,虽然很早也知道了解过,但从来没写过东西。那Qt是用的C++,好久没碰了。其实 QML 里面可以直接写 Javascript 也不用担心太多,真是万能的 Javascript 啊。那后来发现一些比较复杂不方便在QML里面做的事情,还有一些敏感的内容不能直接暴露在 QML 里面,那么就只能用 C++ 了,写了一段时间发现真的是生疏了。后来 Google 之发现有人说可以用 Golang,瞬间欣喜起来,自己学习过 Golang 也做过一些项目,而且也在期待 Google 将其用在 Android 开发上。然后就得知了 go-qml 这个项目后,就开始深入使用 QML 结合 Golang 来做 GUI 应用。其实 go-qml 的作者也说了,这个库属于 alpha 阶段,而且确实从 v0 到 v1 的时候有些写法和API也确实变了,读了部分源码后发现源码里面一些 Comment 也标记了一些 TODO 和 疑问。所以就当实验性开发吧,不过现在用过来并没有发现很多问题,唯一比较麻烦的就是 Golang Type 到 QML Type 的转换上面有限制。

对于 Scope,第一感觉就像是 Android 里面的 Widget。后来慢慢啃文档也就慢慢理解了,Scope 主要的作用也就是作为一种对信息的聚合、展示、搜索等功能。Scope 可以聚合子 Scope 的信息,也可以对子 Scope 进行搜索。不过目前的 Scope 在功能性方面还是不是特别多,并且 Scope 里的 previewwidget 的功能目前也比较弱,使得很多想象力被限制了。所以 Joey Chan 和 校长 也都和我说 Scope 也就那样了,做 App 吧。So... Learn by doing...

疯狂一下吧

7月4~5日,自从 Rex 那里知道有 Hackathon 以后这个日子已经期待很久了,终于来了~由于最近比较忙,4日凌晨1点才睡觉的,也没怎么准备早上7点40起来,随便把电脑、各种线往书包里面塞,另外还带了我做了特殊处理出国网络比较快的 Raspberry Pi2~

9点多到了 Microsoft 大厦,后来回想起来倒是怪怪的,抱着装着 Ubuntu 的 MacbookPro 去了 Microsoft 大厦参加 Ubuntu Hackathon~呵呵~

一进会场~哇,有美女接待,一紧张忘记拍照了,后悔啊~~~然后默默地找自己的名字,然后弱弱地说我没有团队一个人来的 :) 。找到一个比较靠前的 8 号桌坐下来了。整理好东西,坐下等待安排了。瞬间发现0点钟方向坐着刘老师、11点钟方向坐着 Rex 和 Penk 。刘老师之前见过,Rex第一次见面,不过看见他一直拿着笔记本蹲跪在地上忙,就没过去打扰了。后来上前和刘老师打了声招呼然后聊了会儿之前我和他说用 Golang 的事情。

Rex 和 Penk 上台做简要介绍,Rex 介绍说已经有国内开发者在开发 Ubuntu Touch 平台的 App 了,出现了 Joey Chan 的 AesyWeibo,然后PPT上突然出现我之前做的 Youku Scope,嘿嘿~欣喜一下。然后 Rex 说 Youku Scope 是在场的一位开发者做的,问他在哪。我开始懵了一下然后站起来,只见 Penk 在那喊了一声,“原来就是你啊”。然后继续,今天的主题就是没有主题。Let's start...

现场很多人是没有 Nexus4 或者其他可以运行 Ubuntu Touch 的手机,于是官方向每一桌提供开发机。哇,是刚才签到的妹纸来发~~只见快到我这桌了,好紧张,然后就看到她默默地走过去了,略过我这桌了,为什么?我很费解,此时 Penk 突然在我面前坐下了。好吧,妹纸走了,Penk大神来了~哈哈,都不用相互介绍我们就聊起来了,问我要做什么,我说还没想好,可能做个音乐相关的吧。Penk说要不要把Youku Scope 完善一下,也行...然后 coding...

为 Scope 添加 Account 功能之前还没看,这下顺便开一下,还请教了几次刘老师,遇到了挺多困难的。后来休息一下,想想,还是尝试做新的东西吧,这样在限时里完成才有挑战,那好,开启 QML 模式~ 之前就想在 Ubuntu Touch 做类似豆瓣FM的app,那好就定这个了~

哈哈,晚饭居然可以自助选择盖饭和麻辣烫~ 吃饱喝足继续 Hack~ 不过每次红牛都被抢光了,都是结束的时候 Rex 分了我一灌,感谢~

Coding...
Coding...
Coding...

我算是坚持的比较晚的吧~4日晚上基本没睡,电脑里面一直循环着一些 Death Metal。邻座的一组貌似还是外地来参加的学生,他们也比较努力也都好多没睡,听他们在讨论,发现年轻真好,比我在大学的时候强多了!PS:刘老师混进了同学们中,开始还在聊技术,后来还聊到大学生活,刘老师真能聊,哈哈~~

5日凌晨的时候还遇到了一个好玩的事情~调试了一个微博的接口,用到了上传图片,由于权限的问题,我只能上传整张图片,而不能给定url。这个接口调了我好久,就是为了能有一个分享音乐的功能,后来去请教 Penk,Penk 也是一夜没有睡了佩服!向 Penk 说了一下后,他理解了我的思路也确定没问题,但怎么就不行了呢~调用微博的接口总报错不给通过,好吧,吐槽一下微博的文档好多细节没写好。见 Penk 也是一夜没睡,很累的样子,感谢听我瞎扯~ 后来自己想办法吧!快速用 Python 在本地做了个服务,直接发请求到本地,看看是不是自己的问题,瞬间条理就清晰了~哈哈~ Penk 给我当了一次小黄鸭~后来在厕所碰到 Penk,兴奋的和 Penk 说了我怎么解决的~ 回来后瞬间感觉又有能量了,直到坚持到7点后吃了 Joe 提供的早餐,我就小睡了一会儿~~~

Debug 到早上8点,基本要完成的都完成了。嘿嘿~豆瓣FM for Ubuntu Touch ! 还有一个离线播放的功能还没做完,因为目前没法精确判断 WiFi 和 移动数据 的状态,不过已经有人在 Launchpad 上提交 Bug 了。PS: 其实 Ubuntu Touch 现在就像一个小孩子,我也是慢慢看着它一点点的变化,要不是平时很忙,我恨不得仔细读读所有的源码,把一些我发现的 Bug 直接 fix 掉再提交。呵呵,我早晚会仔细研究其源码的。不过我还是贡献了挺多翻译的~

闪电秀

  • 尺子
  • Couple like
  • 优图
  • 斗地主
  • 日记本
  • 记忆词典
  • 路痴助手
  • uChat
  • rocket 拼图
  • LoLi team(mb)
  • 撞脸
  • 小飞机
  • 需求交互
  • 豆瓣FM for Ubuntu touch

上面的就是小伙伴们30个小时的奋战成果!值得一提的是其中有些朋友是刚开始学习开发,尺子的作者他就提到他也是学习 C++/Qt 不久,但我觉得尺子这个作品很实用的。

Couple Like 是一对搭档完成的,嘿嘿,这个创意不错,是一款通过图像人脸识别辨别其年龄以及两个人的匹配程度的应用。最强的是演示时候用的 Demo 图片。

斗地主、日记本等那些,原来大家都是qt高手啊,都在 Ubuntu 平台上实现了很好玩的应用。希望早日在 Ubuntu Touch 见到。

值得一提的是 LoLi team 他们在用 Js 在 Ubuntu Touch 上实现了 LoLi 的解析器,LoLi 是他们自己发明的一个 Lisp 的方言,纯技术层面来说,这个很牛啊~佩服佩服~而且让我感觉到年轻真好~~要哭了

uChat 一款基于 LBS 的社交应用,是一组在校的同学做的,他们做的演示和理念都不错,我以前也想过一个类似的应用~

轮到我的 豆瓣FM for Ubuntu Touch 登场了~哈哈~可能一晚上没睡,感觉自己演讲的不好吧~随便整理了一个slide, 这个 slide 也是开源的哦,大家可以folk,里面有一些有用的资料。借用 Rex 的电脑简单的把 slide 讲了一遍,还是那句话,因为我喜欢音乐,所以我做了相关的应用,这样真的很开心。然后就是演示了,点击应用播放的刚好是 自然卷 的单曲《坐在巷口的那对男女》,大家都挺熟悉的,当我把话筒对着手机的扬声器时,大家听见音乐都鼓起掌了。谢谢大家喜欢,然后介绍了一些必要的功能(后来发现其实我好多忘记演示了),然后...然后就没有然后了... No~还有 One More Thing... 大家听到还有"One more thing"的时候有惊奇起来。为了纪念这次活动,我在 豆瓣FM for Ubuntu Touch 中制作了一个彩蛋,嘿嘿,只有特殊的方式才能进去的哦~大家看到后都哈哈大笑起来。待我把它完善好后,大家自己去发现吧 :)

后话

第一次参加 Hackathon,感觉很充实,也认识了很多朋友。最好的感受就是和一群兴趣相投的朋友做自己爱做的事情真好~最后就是回家睡个天昏地暗~

小站最近改版,好久没写博文了,突然发现码了好多字啊~不行,我得睡觉了~88

Read more
David Callé

Add a C++ backend to your QML UI

Whether you are creating a new app or porting an existing one from another ecosystem, you may need more backend power than the QML + JavaScript duo proposed in the QML app tutorial.

Let's have a peek at how to to add a C++ backend to your application, using system libraries or your own, and vastly increase its performance and potential features.

In this tutorial, you will learn how to use and invoke C++ classes from QML and integrate a 3rd party library into your project.

Read the tutorial

Read more
April Wang

Pawel Stolowski于2015年6月11日发布一篇名为“Cleaning up scopes settings”的博文,我们在这里简单翻译转发和大家分享一下。

Unity 7(在当前桌面上提供Ubuntu shell和默认UX体验)和Unity 8(支持手机且很快将支持融合桌面)在数据源可见性方面存在很大程度的差异。未来Unity 8版本将废弃过去遗产的隐私标记,会更偏向于一种更加清晰的方式,让用户自己决定将数据发送到哪里。

Unity 7中的Scope搜索并保存隐私 

在默认情况下,在Unity 7中使用常规Dash搜索时,它将首先联络Canonical的智能Scope服务器,该服务器会推荐适合搜索关键词的最好或最相关的Scope。然后,下一步是在这些Scope中筛选查询到实际结果,然后呈现出来。

但是,这种方法意味着用户事先并不一定知道自己的搜索内容有向哪些Scope提出查询,而且搜索关键词会被发送到智能Scope的服务器。虽然发送至服务器的数据是匿名的,我们了解到仍有一些用户担心数据隐私问题。正是出于这个原因,我们推出了隐私标记:一个阻止访问智能Scope服务器的Scope设置。

Unity 8中的Scope搜索

Unity 8中的Scope体系结构截然不同:整个搜索过程不会涉及到智能Scope服务器。

相反,每次的搜索查询仅被发送到目前正在使用的Scope(即当前可见的Scope)中,因此用户始终知道他们的搜索数据的都会被发送到哪里。

如果是在使用一个聚合类Scope的情况下, 其中聚合了不同数据来源的子Scope,它的设置页面内会列出所有聚合了的子Scope。用户可以选择自行设置禁用每个单独子Scope的数据源。 

Unity 8废弃了过去遗留的隐私标记

由于在Unity 8中进行内容搜索查询时,可以清晰的看到并且可以轻松禁用Scope及其子Scope的数据源,隐私标记自然就变成了多此一举多余设置。正因如此,我们决定在我们的手机系统/ Unity 8后续简介中去掉清除这一项过去遗留下的设置。

如果你在Unity 8中有使用这一标记,其实通过取消收藏设置(在手机上点掉星号设置)或禁用聚合类Scope中对应的子Scope数据源都可以达到相同的效果。你还可以卸载独立Scope。

在Unity 8中保护隐私

在shell中,你可以看到两种Scope:普通独立/品牌类Scope和聚合类Scope。品牌类/独立Scope可以访问自己独立数据源,但不能同时访问其他或此品牌之外的数据源。因此,例如名叫“我的音乐”的Scope,将仅查询你的手机上本地的音乐文档,而名为“BBC News”的Scope也只能查询到bbc.co.uk的新闻内容。如果你不希望使用“BBC News”Scope,就不调用(通过manage dash)或收藏该Scope(类似于不调用网页应用程序)。

而聚合类Scope却不同于独立/品牌类Scope,本身可以(通过关键字tagging的方式)聚合到各种子Scope数据源,而且不区分它们是在访问本地还是远程的数据。如果你对某一子Scope的内容不太放心,你就可以在聚合类Scope的设置页面中禁用它。

关于作者

Pawel Stolowski工作于Unity API团队,致力于开发并实现Unity Shell搜索功能的Scope中间件及API有关的工作。他还致力于实际Scope(例如Music、Video、Apps等等)的开发以及Ubuntu Linux相关的其他项目中。大家可以通过Twitter关注Pawel - @pstolowski

Read more
Pawel Stolowski

Cleaning up scopes settings

The scopes architecture on Unity 7, which provides the Ubuntu shell and default UX experience on current desktops, and Unity 8, which powers the phone and soon the convergent desktop, differ to a large degree when it comes to visibility of data sources. Future Unity 8 builds will be obsoleting the legacy privacy flag in favour of a clearer way for users to decide where the data is being sent to.

Scope searches and preserving privacy in Unity 7

By default, using a regular Dash search in Unity 7 will first contact Canonical's smart scopes server, which recommends the best or most promising scopes for the search term. Then, as a second step, those scopes are queried for actual results, which will finally be presented.

However, this approach means that the user doesn't necessarily know in advance which scopes are queried and that the search term will be hitting the smart scopes server. Although the data sent to server is anonymized, we understood that some users might still be concerned about data privacy. It was for that reason that privacy flag was introduced: a setting for scopes that prevents access to the smart scopes server.

Scope searches in Unity 8

The scopes architecture in Unity 8 is quite different: there is no smart scope server involved in the search lifecycle.

Instead, each query is only sent to the currently  active scope (that is, the one that is currently visible), so that the user always knows where their search data ends up.

For the case where the current scope being is aggregating multiple other scopes, its settings page will list all aggregated scopes, offering the possibility to individually disable each one if desired.

Obsoleting the privacy flag in Unity 8

With this clear visibility of what's being queried, and the possibility to easily disable sources/scopes, the privacy flag becomes redundant in Unity 8. As such, we have decided to remove this legacy setting in one of our phone/Unity 8 next snapshots.

If you have been using this flag under Unity 8, either unfavorite or disable the respective scopes from the aggregator settings to reach the same result. You can also uninstall the individual scopes.

Creating privacy in Unity 8

In the shell you can see two kind of scopes: normal scopes and aggregator scopes. Normal scopes can access either local or remote data but never both at the same time. So, if there is a scope called “My Music” then this scope will only query your phone, while a “BBC News” scope will only query bbc.co.uk. If you don’t want to use “BBC News” scope then do not invoke (via manage dash) or favor the scope (similar to not to invoke (web)apps).

Aggregator scopes in contrast can aggregate all kind of scopes whether they access local or remote data. If you’re concerned about a specific scope you can disable it via the scopes’ settings page that lists all scopes being aggregated. However, given that most scopes deal with remote data, it will be faster to just unfavorite the respective aggregator via “Manage Dash” and favorite the interesting scopes dealing with local data like “My Music” or “My Videos”. This has also the benefit of not having (almost) empty dash pages.

Read more
April Wang

上周西班牙手机厂商BQ和Canonical再次联和发布又一新款Ubuntu手机 - BQ Aquaris E5 Ubuntu版本。 这也是BQ厂商发布的第二款Ubuntu手机, 这一次带来了更大的屏幕和更加强悍的摄像头硬件, 还有增强的电池容量,让这款手机待机更久。 

2015年6月9日,英国时间, 这款最新Ubuntu手机正式开卖。 售价199.9欧元(约1399.31元人民币), 比之前的BQ Aquarius E4.5 Ubuntu版本手机贵了约30美金(约190元人民币)。 我们来看一下, 这款最新Ubuntu家族的成员到底新意何处。 

Aquaris E5的硬件配置:

这款E5 Ubuntu手机只有一个颜色 - 黑色, 内存16GB

硬件配置来说, E5其实和前一款Ubuntu E4.5区别不大, 同样使用联发科技的四核处理器,搭配1GB的RAM。 

最大的硬件提升是来自E5相机的。 E5机身前置和后置的相机都装配了BSI感应器和Largan镜片。 后置相机拍摄的照片像素可达1300万像素,而前置相机可达5百万像素。 

另外E5还带有一个MSD卡片插槽, 可以将总内存增加到32GB。 

目前这款BQ E5的Ubuntu手机仅限欧洲售卖,而且将会在6月22日开始发货。

此外Ubuntu酝酿很久的融汇Convergence口袋PC手机也在积极开发中。 让你的手机直接插上一个显示频, 键盘和鼠标就能当做PC来使用的话, 想想就很让人鸡冻\(≧▽≦)/!

Read more
Zoltán Balogh

Sprinting for convergence

Convergence is all around. Our deeply loved UI Toolkit, what was primarily targeting touch environments is converging to where users might have keyboards and pointer devices. But that is just one point. The innovative track for Ubuntu is called Snappy and at the same time the SDK is converging to the desktop. We move to the direction where frameworks and applications are packaged and distributed in a new model. It is exciting to see how the different development tracks do move in the same direction.

Last week the SDK team has spent quality time with the creative folks from the design team and with master ninjas from the QA team to put down the foundations of a converged UI Toolkit and SDK.

We had two major questions when we entered the sprint:


How UI Components will look and behave when pointer and keyboard devices become available even during runtime?

How can we enable scope and application development for literally any kind of Ubuntu device?


Our offering is not only for smartphones. The UI components are as good on a big screen desktop as on a tablet sized device or on any small device with a screen. I totally can imagine the UI Toolkit on a car’s infotainment dash or on a control panel of an intelligent house. But before the bold dreams we focus on bringing the components to the classic desktop environment.

Application convergence

When we talk about convergence we mostly mean application convergence. The “definition of done” is when one can start an application on a touchscreen phone and the application scales and adapts automatically to a bigger screen with keyboard and mouse when plugged into the device.
The driving applications are Ubuntu browser, dekko email client, music player, calendar, document viewer, messaging, address book, snap decisions/alerts and Telegram.

As an addition the toolkit will provide API to control window and page sizing, a component to easily transition from a one column pagestack to a multi-column view, supporting 2 or more columns. A detachable header component is also planned, so applications can put headers in different views, not only in a MainView. But more about these in the following.

Foundations and tools

To make a converged SDK we do need a solid and sustainable foundation. Not only the UITK depends on the Qt stack but our own IDE needs it. On the sprint we already made working prototypes of distro decoupled Qt and IDE packages. In other terms it means that we can produce the Qt, UI Toolkit and SDK Tools snappy packages pretty much any time when needed. The cool thing in keeping our eyes on snappy is that this new structure motivates us to cut the loose ends from our packages and make the SDK more portable and easier to build.

The promise is that we will have distro independent (snappable) SDK tools and UITK with Qt 5.4 for anything what is compatible with the 14.04 Ubuntu.

UI Toolkit 2.0 plans

Improving the performance and the overall quality are the keywords for UITK 2.0. We will list those components what would perform better if they were implemented in C++, starting with MainView as it is needed for the Convergence story.

We want to upstream the UITK to Qt. Living close to our upstream foundation brings great value. Refactoring the source tree to have a single Ubuntu.Components module without submodules is the natural first step towards upstreaming. It will make the UITK more compatible with other Qt modules. Early bits might land on 1.3 depending on the needs. The detailed API planning will start end of Ubuntu 15.09 and is planned to land on 16.04.

Scopes

The scopes toolkit will slowly migrate from the Unity8 space to the UI Toolkit. It means that the components used now for scope development will be available for classic application development. Also the scopes APIs are under heavy re-factoring. According to the present plans the UITK will be available to the scopes and scopes will become more active aggregators than ever. The key point with scopes is that we will put lots of effort on scopes development as they are one of the most visible differentiation from other platforms.

Scrollbars

An issue with the current version is the thumb is covering actions in the UI because it can not be positioned outside the window and if users approach an action on the right hand side the thumb is revealed. The scrolling user experience will be the same as in Unity7 with the exception that the thumb appears inside the window area. The thumb follows the mouse cursor position and hides when the mouse does not move. The design team is currently prototyping two different scrollbars, one with a thumb and one without, which visually would look the same as in Qt Creator for example, and we will evaluate which fits better to the designs and will release the most appropriate and usable one.

Tooltips

When mouse pointers are available the tooltip appears when hovering over a component. With a touch interface a long press interaction is under investigation which would invoke a tooltip on a component or action..

The tooltip appears under the mouse cursor after a timeout (1 second), positioned the same way as popovers, and disappears after a timeout (10s) or when the mouse is moved out of the component’s area.

Date and time pickers

This is one of the components which got a heavy design facelift. The components are no longer tumbler based Pickers, but composed of an editable component, which when tapped/clicked opens a popup, in which there can be a calendar component for date picking, or a picker for time picking. The main component is a text input with no text cursor, when activated with keyboard, the entire content will be selected, and can be edited at once, i.e. no positioning will be possible. The popups will be full screen dialogs on screens smaller than 40x71 GU, and popovers on bigger screens.

Dropdown Menus & popovers

We are considering to reuse QtQuick Controls Menu components, adapting those to the toolkit’s theming and actions. Keyboard shortcuts and accelerator will only be visible with mouse/keyboard attached in any drop down menu. The context menus will be single level menus in the first iteration and cascading menus might come later if needed. The individual application menus are not high priority but we will listen to the app developers and hear what they need.

Expandables, ListItems module

As now we have OptionSelector and ItemSelector what is confusing, and neither of them is configurable enough. The old Ubuntu.Components.ListItems has a pile of components which is just not flexible enough, and they are all underperforming. Expansion will be introduced to the new ListItem, and new layouts will be made which will be flexible enough to survive eventual design changes. This is not a high priority for convergence, however it will serve as a ground for phone and desktop layouts as well as the prerequisite for the application menus. We will keep trying to separate the layout from the ListItem, hopefully we will manage to do that performantly enough.

Accessing ListItem actions on desktop

At first, a mouse right click will bring up a `contextual` menu which will contain leading, trailing and default actions, as well as selection/drag modes, without any API change on ListItem. After application menu will be implemented, we will enable the context menu on the ListItem together with other components.

Panels behaviour & MultiColumnView

For the 2-column pagestack we still need to find out the best navigation model, more precisely the way we handle the headers of the pages, cascading or not. We gathered the tasks we have to complete in order to provide convergent view handling:

  • PageStack cannot be adapted to the new UX without major API changes, therefore we will introduce a component called MultiColumnView, which can transition from one column to 2 or more columns. The component will put Pages side by side, and will maintain a stack depending on where the page is pushed, above the current page or next to it. Applications using this component must specify the minimum and maximum sizes for the page

  • Title, or header handling should be detached from MainView, and there will be a Header component which then can be used in bottom edge, or a ListView’s header component

  • The bottom edge will be used on the desktop, and there will be a component called BottomEdgeHint which provides a clickable component if there’s a mouse. The bottom edge swipe known from the touch environment will simply translate a new clickable component what will appear when the mouse is hovered on it. The content of the component (for example a pagestack) depends on what the developer wants.

Focus handling

The focus handling concerns not only TAB/Shift+TAB navigation between components, but also the keyboard navigation inside composite components, such as ListView, ComboButton, text inputs, header, etc. The focus highlight is more or less agreed, however there is a little prototyping ongoing to figure out whether we can do some nice effects on it or not.

 

Read more
Daniel Holbach

Thanks to the tireless work of Oliver Grawert we now have a handy tool called node-snapper which very easily turns your node.js project into a .snap package. It will automatically take care of bundling required libraries, other related node.js projects and will make a multi-arch ("fat") package available, so it will immediately work on armhf and amd64 architectures.

Intrigued? Check out our tutorial Turning node.js projects into snap packages.

Read more
David Callé

Have you taken Vision Mobile’s developer survey? The survey is covering your development in Mobile, Desktop, Cloud, and IoT this year, there is something all devs can contribute towards and help shape the findings for this survey.

Participating is easy - take the 10-minute Developer Skill Census survey and enter a draw to win prizes such as the BQ Aquaris E4.5 Ubuntu Edition, iPhone 6, Apple Sports Watch, Oculus Rift Dev Kit, and many more. A free chapter from one of VisionMobile’s premium paid reports will also be given immediately upon completion, taking a close look at app profits & costs.

The survey closes on 5th June - enter the survey now

Thanks to everyone who has already completed the survey!

Read more
Christian Dywan

We all love QML because it allows for fast prototyping, and not only that, it's a very efficient tool for production applications. The complexity of C and C++ is hidden behind neat and simple API. Many if not most app developers these days take advantage of that without even having to know the implementation details. Most of the Ubuntu UI Toolkit is pure QML except for performance-critical elements like the new ListItem or the theming engine.

There's a notable flaw however to QML as a language when it comes to versioning. Any QML component is made known to the engine in one of two ways. Using qmldir, which essentially is a text file listing with version numbers and filenames - unfortunately there's no error handling whatsoever so qmldir files in productive use are all but flawless and mistakes including missing files won't be noticed easily, made worse by the fact that QML automagically recognizes files as class names regardless of being registered anywhere. The other way is qmlRegisterType in one of its various incarnations - seemingly with inbuilt support for minor revisions which in fact are completely unrelated to QML.

Looking further at how classes behave it's not looking much better either. There's no support for versions in functions, properties or signals. All members will show up in all versions the same QML file is registered to. Additions as well as changes affect all versions - unless you fork the implementation, which is what we do for the Ubuntu UI Toolkit these days to ensure new versions don't break existing code, with the exception of bug fixes. To make matters worse, if the implementation imports another, newer version, the public API will follow suit. Regardless of the policy of a particular project, there's no easy way of ensuring the public API is what you want it to be, it's just too failible.

Fortunately the Ubuntu UI Toolkit has employed a solution that's now become available for everyone:

 

Usage: apicheck [-v[v]] [-qml] [-json] IMPORT_URI [...IMPORT_URI]

Generate an API description file of one or multiple components.
Example: apicheck Ubuntu.Components
    apicheck --json Ubuntu.DownloadManager

The following rules apply for inclusion of public API:

 - Types not declared as internal in qmldir
 - C++ types exported from a plugin
 - Properties and functions not prefixed with __ (two underscores)
 - Members of internal base classes become part of public components

 

It's designed to serialize the public QML API in a way that is human readable as well as easy to process in a pogrammatic fashion. Let's try it out, shall we?

/usr/lib/x86_64-linux-gnu/ubuntu-ui-toolkit/apicheck Ubuntu.Components > components.api.new

This will give you something like the following in the file components.api.new:

Ubuntu.Components.PageHeadConfiguration 1.1: Object
    readonly property Action actions
property Action backAction
    property Item contents
    property color foregroundColor
    property string preset
    readonly property PageHeadSections sections
Ubuntu.Components.PageHeadConfiguration 1.3: Object
    readonly property Action actions
    property Action backAction
    property Item contents
    property color foregroundColor
    property bool locked
    property string preset
    readonly property PageHeadSections sections
    property bool visible
Ubuntu.Components.UbuntuShape.HAlignment: Enum
    AlignHCenter
    AlignLeft
    AlignRight
Ubuntu.Components.ViewItems 1.2: QtObject
    property bool dragMode
    signal dragUpdated(ListItemDrag event)
    property bool selectMode
    property QList<int> selectedIndices
Ubuntu.Components.i18n 1.0 0.1: QtObject
    property string domain
    property string language
    function bindtextdomain(string domain_name, string dir_name)
    function string tr(string text)
    function string tr(string singular, string plural, int n)
    function string dtr(string domain, string text)
    function string dtr(string domain, string singular, string plural, int n)
    function string ctr(string context, string text)
    function string dctr(string domain, string context, string text)
    function string tag(string text)
    function string tag(string context, string text)

There are, in order, a QML component, an enum, an attached property and a singleton, all read from the typesystem in the way they will be available to QML applications.

Now in addition to reviewing this file with the naked eye you also use diff:

diff -F '[.0-9]' -u components.api{,.new}

Now let's imagine we're making some changes to some of the classes and running it again will yield this result:

@@ -415,11 +415,11 @@ Ubuntu.Components.PageHeadConfiguration
 Ubuntu.Components.PageHeadConfiguration 1.3: Object
     readonly property Action actions
     property Action backAction
-    property Item contents
+    property var contents
     property color foregroundColor
     property bool locked
     property string preset
-    readonly property PageHeadSections sections
+    property PageHeadSections sections
     property bool visible
 Ubuntu.Components.PageHeadSections 1.1: QtObject
     property bool enabled
@@ -1001,7 +1001,7 @@ Ubuntu.Components.UbuntuShape.FillMode:
 Ubuntu.Components.UbuntuShape.HAlignment: Enum
     AlignHCenter
     AlignLeft
-    AlignRight
+    AlignTop
 Ubuntu.Components.UbuntuShape.VAlignment: Enum
     AlignBottom
     AlignTop
@@ -1017,7 +1017,6 @@ Ubuntu.Components.UriHandler 1.0 0.1: Qt
 Ubuntu.Components.ViewItems 1.2: QtObject
     property bool dragMode
     signal dragUpdated(ListItemDrag event)
-    property bool selectMode
     property QList<int> selectedIndices
 Ubuntu.Components.i18n 1.0 0.1: QtObject
     property string domain
@@ -1027,7 +1026,7 @@ Ubuntu.Components.i18n 1.0 0.1: QtObject
     function string tr(string singular, string plural, int n)
     function string dtr(string domain, string text)
     function string dtr(string domain, string singular, string plural, int n)
-    function string ctr(string context, string text)
+    function string ctr(string context, string text, bool newArgument)
     function string dctr(string domain, string context, string text)
     function string tag(string text)
     function string tag(string context, string text)

See what happened there? Several changes show up in the diff output, including changed arguments, removed and added members and even the removal of the readonly keyword.

In the case of the Ubuntu UI Toolkit a components.api file lives in the repository. A qmake target generates components.api.new from the local branch and prints a diff of the two files. This is run as part of make check, meaning any changes to the API become visible at the time you run unit tests, as well as CI builds for merge requests made on Launchpad. Any changes will cause make check to fail so the branch has to include an updated componets.api which shows up in Launchpad reviews and bzr command line tools.

If any of this got you excited, maybe you wanna add it to your own components and improve QA?

Read more
David Callé

Are you involved in Ubuntu phone, desktop, cloud or IoT development? Voice your opinion on what factors contribute to your choice of developing on Ubuntu by getting involved in the biggest developer survey yet.

Vision Mobile have launched their 9th edition developer economics survey today, covering developer sentiment across platforms, revenues, apps, tools, APIs, segments and regions. This ambitious survey covers everything from mobile, desktop, cloud and IoT. Key insights from the survey will be provided as a free download in late July, and a free chapter from one of VisionMobile’s premium paid reports will also be given immediately upon completion, taking a close look at app profits & costs.

Tell us your thoughts about the latest developer trends, take the 10 minute survey now - some amazing prizes are up for grabs including the BQ Aquaris E4.5 Ubuntu Edition, Apple Sports Watch, iPhone 6, Oculus Rift Dev Kit + many more gadgets!

Read more
April Wang

Mark Shuttleworth昨晚揭晓了Ubuntu 15.10 的版本代号 Wily Werewolf。Wily在英文中一般用于描述易于适应环境锐敏足智的角色人物,而Werewolf则是传说中的一种神秘物种,小说中常常以人形出现但会在满月之日变成狼性的狼人 


Ubuntu 15.10 将会在今年10月份发布,而它的代码名也是至今为止Ubuntu版本名中第二个被重复的字母 (另外一组曾被重复使用的字母为H,相关版本名分别为Hardy Heron和Hoary Hedgehog)


为了昨晚有错过直播的筒子们另外再献上 , Mark现场的几段精彩keynote,致即将到来的Pocket PC!


“We [the Linux desktop] were always five, ten years behind. Always copying the other guy. Here, for the first time, we have this vision at the same time,” he said.

“It doesn’t matter [who had the idea first]. We’re living in a world where, if we make a great experience, all the applications that run on a Windows converged experience might also run on a Ubuntu converged experience.”

“I’d like us to rise above kind of saying ‘you’re copying our ideas’. We didn’t patent those ideas. We spoke very publicly about that vision because we wanted it to be true. I think it’s exciting for everybody that [it now is].”

配图源自:http://itsfoss.com/

顺便提一下,Ubuntu手机开发培训本周六落地南京,附近的小伙伴们别忘了立即报名啊。

Read more
David Callé

Internationalizing your QML app

 

As a developer, you probably want to see your apps in many hands. One way to make it happen is to enable your application for translation.

With minimal effort, you can mark your application strings for translation, expose them to community translators and integrate these translations into your package. The translations building process is handled by the SDK itself and if you happen to use Launchpad, translators will quickly see your project and help you, but you still need to mark your user-visible strings as translatable.

Let's get started ›

Read more
Loïc Molinari

A magnifying glass in QML

To create sharp visual components, we need to make sure our renderings look good at the pixel level. This is a common task and the terms precision and pixel-perfectness have become ubiquitous in discussions among programmers and designers at Canonical. In the last years, the industry started to increase the pixel density of screens, again (remember the CRT era), resulting in a higher number of pixels within a specified space (see Retina Display for instance). A consequence is that jaggies are less visible than before because we are reaching the point where the pixels are small enough that the eye is not able to detect them. In an idealized world of high density screens that would completely remove the need of anti-aliasing algorithms to smooth edges, but the fact of the matter is that we are not there yet and we will still have to thoroughly inspect the quality of anti-aliasing algorithms for a while.

Handheld magnifying glass

At a previous job, a colleague of mine used to keep a handheld magnifying glass on his desk. I was quite amused to see him glued to his screen validating the visual quality of commits with this thing. As the graphics engine programmer, I barely remember the reason for which I never proposed the inclusion of a software magnifier, it could be because of the overloaded backlog we had to deal with at the time but I guess it actually was just out of sheer mischief. Most desktop environments include a software magnifier, but depending on its quality (efficiency and ease of use), it often makes sense to integrate a custom magnifier directly in the application being developed (it makes less sense to ship it in release builds though...). This article explains how to implement an efficient one with QML using offscreen framebuffers and shaders.

Offscreen framebuffers (exposed as FBOs in OpenGL), vertex shaders and fragment shaders are now widely available in mobile and mid-range GPUs allowing the creation of interesting real-time post-processing effects for most devices on the market. Magnification, or to be more precise zooming & panning (magnification solely being the process of rendering an image at a higher scale), is one of it. In low-level graphics programming terms, all it takes is to do a first pass that renders the scene in a FBO and a second pass that renders a texture mapped quad to the default framebuffer reading the FBO as a texture. Image zooming and panning is a basic 2D scale and translate transformation that can be efficiently implemented by tweaking the texture coordinates used to sample the FBO at the second pass. The vertex shader, executed for the 4 vertices making our quad, will easily take care of it using a single multiply-add op (transformed_coords = scale * coords + translation) and the hardware accelerated rasterizer and texture units will make the actual rendering very efficient. In order to clearly distinguish the magnified pixels, it is important to use a simple nearest neighbour filter. These low-level bits are nicely exposed to QML through the ShaderEffectSource and  ShaderEffect items. The former allows to render a given Item to a FBO and the latter provides support for quads rendered using custom vertex and fragment shaders.

Here is the QML code of the magnifier:

import QtQuick 2.4

Item {
    // Public properties.
    property Item scene: null
    property MouseArea area: null

    id: root
    visible: scene != null
    property real __scaling: 1.0
    property variant __translation: Qt.point(0.0, 0.0)

    // The FBO abstraction handling our first offscreen pass.
    ShaderEffectSource {
        id: effectSource
        anchors.fill: parent
        sourceItem: scene
        hideSource: scene != null
        visible: false
        smooth: false  // Nearest neighbour texture filtering.
    }

    // The shader abstraction handling our second pass with the
    // translation and scaling in the vertex shader and the simple
    // texturing from the FBO in the fragment shader.

    ShaderEffect {
            id: effect
            anchors.fill: parent
            property real scaling: __scaling
            property variant translation: __translation
            property variant texture: effectSource

            vertexShader: "
                uniform highp mat4 qt_Matrix;
                uniform mediump float scaling;
                uniform mediump vec2 translation;
                attribute highp vec4 qt_Vertex;
                attribute mediump vec2 qt_MultiTexCoord0;
                varying vec2 texCoord;
                void main() {
                    texCoord =

                        qt_MultiTexCoord0 * vec2(scaling)
                        + translation;
                    gl_Position = qt_Matrix * qt_Vertex;
                }"

            fragmentShader: "
                uniform sampler2D texture;
                uniform lowp float qt_Opacity;
                varying mediump vec2 texCoord;
                void main() {
                    gl_FragColor =

                        texture2D(texture, texCoord) * qt_Opacity;
                }"

    }

    // Mouse handling.
    Connections {
        target: scene != null ? area : null
        [...]
     }
}

 

And here is how to use it:

import QtQuick 2.4

Item {
    id: root

    Item {
        id: scene
        anchors.fill: parent
    }

    ZoomPan {
        id: zoomPan
        anchors.fill: parent
        scene: scene
        area: mouseArea
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        enabled: true
        hoverEnabled: true
        acceptedButtons: Qt.AllButtons
    }
}

 

Mouse handling has been snipped off the code for conciseness but it can be studied directly from the code repository. One important point to notice is that for zooming to be a pleasant experience, it has to be implemented using a logarithmic scale as opposed to a linear scale. Each scale value at a zooming level is the previous one multiplied by the desired scale factor, so a scale factor of 2 and a zooming level n give a scale value of 2n. Another point is that to scale an image up, the range of its texture coordinates must be scaled down, this explains why the actual scaling is inverted. So a scale value of 2n would give an actual scaling of 2-n. A bit counterintuitive at first…

We’re done with the theory. Let’s have a look at the final result:

 

This technique helped me in the making of several visual elements, I would be glad if other programmers find it useful too. Zooming and panning is a very common feature in image viewers, the technique could be adapted for that use case too (with potentially some tweaks to support tiling of big pictures). Maybe that would be a good addition to the Ubuntu UI toolkit, don’t hesitate to ask if you would like official support for it.

The source code is available on launchpad:

Read more