Posts tagged qt

Binary Tree Rebuilder

Imagine you have a Binary Tree, with those characteristics:

  • Nodes do not respect any order relation – In other words: it’s not a Binary Search Tree of any kind
  • Every node appears once and only once within the tree
A nice Binary Tree
A nice Binary Tree

Then, your little brother passes by your desk and, to upset you, deletes the tree from your computer memory/HD (yeah, I know, I’m pathetic at inventing hypothetical situations :-P ).

Fortunately though, you previously did a Pre-Order and an In-Order visit of your tree, and stored the result in an 2 nice array.

Can you rebuild the original tree structure out of this 2 array?

How are you going to rebuild it?

Yes, you can! (Sorry, I couldn’t resist). And it’s quite easy as well. What you have to do, is the following:

  • Take the first element of the PreOrder Array and use it as root of a new tree
  • Find the position of this New Node in the InOrder Array, scanning it from 0 to n-1 (n is the number of Nodes)
  • IF next element in the PreOrder Array is on the left of the New Node in the InOrder array: call RECURSIVELY this procedure, this time taking into account the portion of InOrder array that goes from 0 to the position of the New Node in the InOrder Array -1.
  • IF next element in the PreOrder Array is on the right of the New Node in the InOrder array: call RECURSIVELY this procedure, this time taking into account the portion of InOrder array that goes from the position of the New Node in the InOrder Array +1 to n-1.
  • Return the New Node

By the way, this doesn’t work. To fix it we should be more generic, specifying things a little bit better. Things like:

  • Every recursive calls takes into account a portion of the InOrder array; in the case of the first call it’s the entire array
  • There is going to be as much recursive calls as the number of elements in the PreOrder array

Of course, is a tree what we are talking about here: recursion is a MUST. More >

Serverless chat to reduce office distance

This idea comes out for an old university-time idea: to write a serverless chat application. Of course, I’m aware of the complications and the problems that using Broadcasting could create, so this problems would be took in consideration by design.

Office

But why now? I was thinking of a way to reduce the “office distances”: making easy to connect with a person who works in your own office. I know, it sounds a bit “creepy” to depend on an application to do that. After all you could just stand up and go to the colleague’s desk. And that’s what I’d normally do: nothing impossible.

But I can see that this is not always the case for every personality, and, sometimes, I fall in the same “shyness” (since in UK, no one believes me when I say “I’m shy”, but I actually am: I just use jokes to relax and break-the-ice). So months passes by, you never learn the name of some colleagues and so on. After all how many times you work in projects where more than 10 people are involved?

Acceptance-less

A system like this could explicitly avoid concepts like “accept a contact in your contact-list”: the contact list would be the list of all the clients connected to the network, no one excluded. I know you could probably do this kind of stuff configuring accordingly some server chat, but you need:

  • Infrastructure, set up by an IT department
  • Maintenance, provided by an IT department

Both this things are normally very rare resources to have in a classical office environment. IT is always evil ;-) . Am I not right?

Cross platform by design

I have in mind Qt as the framework to build something like that. It already covers the most of the desktop environments, and it can be set to integrate nicely. Not like Java. :-P

Features? No, for now brainstorming

Yeah, I could start to write a long list of all the features I think such software should have, but this post was more to ask the micro-crowd that reads my blog “what do you think of such an idea?”. Any idea will be took in consideration.

Features

Ok, that’s what I have in mind for now:

  • Acceptance-less contact-list (I believe that’s a core one)
  • Chat layout built into a WebView: styling through plugins of CSS(3) files
  • Drag and Drop file-transfer (no-passthrough-server: imagine the speed on a lan!)
  • Encryption: communication can be encrypted, encrypting the socket traffic one has opened with another client
  • Position: this could be like a “status” info, but allowing the person to pin him/herself on a Office map, so that can be easy to find

Please advice for more ;)

And after this chat?

Just stand up and go there: it’s not like your colleague is going to harm you or something. ;)

QDetroBro: Experimenting with Qt on S60

The best way to learn a new language or a new framework is to find an idea and implement it. So I’m doing for Qt on S60. So I decided to implement a dummy browser that has some smart/attractive/peculiar/interesting/funny bits. QDetroBro

Because I’m lazy to package and attach code, and because is always good the evolution of a project from the ground-up, I decided to post it on my GitHub account. You can find it at: http://github.com/detronizator/QDetroBro/tree/master.

It passed through 3 major phases:

  1. v0.1-beta – Ultra-dummy browser with very “boring” UI. The entire code was in only 1/2 classes (power of Qt and Signal-Slots). Commit: f49bd…
  2. v0.2-beta – A lot of interesting new bits, like Animations, Stylesheet-themed Widgets and so on. Commit: dae20…
  3. v0.2.2-beta – The current release. Commit: 240c5…

If you want to take a look at it to see what Qt on S60 can enable, please do. You can download the latest build from here.

Ah, of course there are requirements to run Qt code on S60. You find what to install on your phone here (“Demos for your S60″ section).

Snippet: fix Screen Orientation in a Qt/S60 app

I follow the Qt/S60 Mailing list, that is turning out to be a very interesting and active ML, and the Qt Labs blog, always full of very good code, written directly by the guys of Qt Software. I thought could be nice to start to post some of the stuff I’m learning.

#include <eikenv .h>
#include <eikappui .h>
#include <aknenv .h>
#include <aknappui .h>
// ...
// lock orientation
CAknAppUi* appUi = dynamic_cast<caknappui *>( CEikonEnv::Static()->AppUi() );
if ( appUi )
{
   appUi->SetOrientationL( CAknAppUi::EAppUiOrientationPortrait );
}
// ...

Today’s source is: Nokia Forum.

Nokia should Learn, not Teach

From Slashdot:

Nokia Urges Linux Developers To Be Cool With DRM


superglaze writes in to note that according to Nokia’s software chief, its plans for open source include getting developers to accept things like DRM, commercial IP rights, and SIM locks.

«[Ari] Jaaksi admitted that concepts like these “go against the open-source philosophy,” but said they were necessary components of the current mobile industry.
“Why do we need closed vehicles? We do,” he said.
“Some of these things harm the industry but they’re here [as things stand]. These are touchy, emotional issues, but this dialogue is very much needed. As an industry, we plan to use open-source technologies, but we are not yet ready to play by the rules; but this needs to work the other way round too.”»

So, Nokia wants to EAT using the knowledge and the software that the Open Source Community created… and, at the same time, change it’s culture and impose concepts that are COMPLETELY against the Open Source “philosophy” itself. Interesting…
Instead of learning of the quality of what the Open Source community is capable of doing using a development model built around “equality and quality”, they want to teach/impose? And to who? To the Trolltech employee? They are free to do so… but this does not mean that the rest of the Community will change its mind.
QT? There is KDE that has a foundation to protect it PLUS there is always the Fork option ;-) .
Think about XFree86 and X.org: nowdays they lost all the users… because of the stupid decision of changing the license.

Sorry mates, this is not the right way. And now you are not the only player any more: still the biggest… but this is changing, and the Q4-2007 + Q1-2008 says that more than anything else.

Source: Pollycoke.