Qt/Kde coding style and SVN tree

Posted in Qt | No Comments »

Hi all,

today I will post  a script based on Qt/Kde coding style using astyle command in a woking svn tree to fix coding style.

This script works like the scrip from the last post but now to work in a SVN tree.

It will check the coding style just in the modified and added files to the svn commit.

#!/bin/bash

astyle --indent=spaces=4 --brackets=linux \
      --indent-labels --pad=oper --unpad=paren \
      --one-line=keep-statements --convert-tabs \
      --indent-preprocessor \
      $(svn status | awk '(/^M/ || /^A/) &&
            (/\.h\>/ || /\.c\>/ || /\.cpp\>/){print $2}')

You can get the source code from here.

References:

http://ragner.org/programming-languages/qt/174

http://techbase.kde.org/Policies/Kdelibs_Coding_Style

Qt/Kde coding style and Git tree

Posted in Qt | 1 Comment »

Hi all,

today I will post  a script to check and fix Qt/Kde coding style using astyle command in a woking git tree.

#!/bin/bash

astyle --indent=spaces=4 --brackets=linux
      --indent-labels --pad=oper --unpad=paren
      --one-line=keep-statements --convert-tabs
      --indent-preprocessor
      $(git-status | awk -F : '(/modified:/ ||
	/new file:/) && (/.h>/ || /.c>/ ||
	/.cpp>/) {print $2}')

Download the source code here.

So you just need run the script in a working git tree to check and fix Qt coding style.

It will check and fix Qt coding style in all files modified in the git tree.

To force the coding style fix before each commit you can put the script as git’s hook script, putting it in the .git/hooks/pre-commit file of your project.

To enable the pre-commit hook script just run:

$ chmod +x .git/hooks/pre-commit

References:

http://astyle.sourceforge.net/

http://techbase.kde.org/Policies/Kdelibs_Coding_Style

http://git-scm.com/

A Simple Qt State Machine

Posted in Qt | No Comments »

Hi,

today I will post the source code for the following satechart for a simple Qt state machine.

simple-state-machine.jpg

You can get the source code here.

    QPushButton button("Ok");

    /* The state machine. */
    QStateMachine machine;

    /* Three states to the state machine. */
    QState s1;
    QState s2;
    QState s3;

    /* For each state it sets the button's text property. */
    s1.setPropertyOnEntry(&button, "text", "In state S[1]");
    s2.setPropertyOnEntry(&button, "text", "In state S[2]");
    s3.setPropertyOnEntry(&button, "text", "In state S[3]");

    /* Adds the transitions to each state */
    s1.addTransition(&button, SIGNAL(clicked()), &s2);
    s2.addTransition(&button, SIGNAL(clicked()), &s3);
    s3.addTransition(&button, SIGNAL(clicked()), &s1);

    /* Adds the three states s1, s2 and s3 to the state machine. */
    machine.addState(&s1);
    machine.addState(&s2);
    machine.addState(&s3);

    /* Sets the state s1 as initial state. */
    machine.setInitialState(&s1);

    /* Starts the state machine. */
    machine.start();

    button.show();

When any of the states is entered, the button’s text will be changed accordingly.

Reference:

http://doc.trolltech.com/solutions/4/qtanimationframework/statemachine-api.html

Hellow world using QStateMachine from Qt state machine framework

Posted in Qt | 1 Comment »

Hi,

continuing the posts about Qt, today I will write how to implement a Qt application using QStateMachine from the new Qt animation framework.

The code below demonstrate the core functionality of the State Machine API.

= main.cpp =

/* Includes */
#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QtCore/QStateMachine>
#include <QtCore/QFinalState>
#include <QtCore/QState>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QPushButton button("Exit");

    /* State machine that will finish when a button is clicked. */
    QStateMachine machine;

    /* The initial state. */
    QState *s1 = new QState();

    /* The final state. */
    QFinalState *s2 = new QFinalState();

    /* Instructs state s1 to set the property "text" of the button to the given
       text "Click me" when the state is entered. */
    s1->setPropertyOnEntry(&button, "text", "Click me");

    /* Instructs state s1 to execute a transition to state s2 when the button
       will be clicked. */
    s1->addTransition(&button, SIGNAL(clicked()), s2);

    /* Adds the states s1 and s2 to the state machine. */
    machine.addState(s1);
    machine.addState(s2);

    /* Connects the signal finished() from the state machine to the quit() slot
       from the QApplication. So the application is going to quit when the state
       machine will be finished. */
    QObject::connect(&machine, SIGNAL(finished()), QApplication::instance(),
        SLOT(quit()));

    /* Sets the state machine's initial state; this state is entered when the
       state machine is started. */
    machine.setInitialState(s1);

    /* Starts the sate machine. */
    machine.start();

    button.show();
    return app.exec();
}

=

state01.png

The code above implements a state machine with two states s1 as initial state and s2 as final state.

When the state machine is started it starts into state s1 that sets the button’s text property to “Click me”.

The transition from s1 to s2 is controlled by the single QPushButton. When the button is clicked the machine executes a transition from state s1 to state s2.

When the state machine enter into the state s2, the final state, it emits the finished() signal that is connected to the quit() slot from QApplication, so it calls the quit() function and the application is finished.

References:

http://www.qtsoftware.com/products/appdev/add-on-products/catalog/4/Utilities/qtanimationframework/

http://doc.trolltech.com/solutions/4/qtanimationframework/statemachine-api.html

http://ragner.org/programming-languages/qt/142

Qt hello world and qmake

Posted in Qt | 1 Comment »

Hi all,

I am studying Qt and I want to do some posts about.

So I will start with a simple hello world and talking how to compile its source code.

= main.cpp =

#include <QtGui/QApplication>
#include <QtGui/QLabel>

int main(int argc, char *argv[])
{

    /* All Qt application need implements a QApplication */
    QApplication app(argc, argv); 

    /* Here QLabel is the main window! */
    QLabel label("Hello, world!");

    /* Shows the QLabel */
    label.show();

    /* Enters the main event loop and waits until exit() is called. */
    return app.exec();
}

=

Now you need to create the .pro file with the project’s configurations and dependencies.

To create the .pro file you can just run:

$  qmake -project

The command above will create a .pro file with the same name of the directory where is the source code.

To create the Makefile run:

$ qmake

So to complie the source code run:

$ make

You will see a binary file with the same name of the .pro file.

References:

http://doc.trolltech.com/4.5/classes.html

http://doc.trolltech.com/4.5/widgets-tutorial.html

http://doc.trolltech.com/4.5/qmake-manual.html

Command to rename jpeg/jpg files by date/time

Posted in Multimedia | No Comments »

Hi all,

sometimes I like to rename my photos by date/time

so I use the command jhead to do the work, just running:

$ jhead -n%Y%m%d-%H%M%S *.jpg

This command renames all files with the jpg extension with its time/date stamp in the format YYYYMMDD-HHMMSS.jpg

Reference:

http://www.linux.com/articles/56588

How to maintenance debian/changelog file in a source package

Posted in Debian, Linux | No Comments »

Hi all,

After some time finally I will write a new post here.

Today a will write how to maintenance debian/changelog file in a source package.

= Configuring environment variables =

First you need export some environment variables.

EDITOR="vim"

DEBFULLNAME=”Ragner Magalhaes”

DEBEMAIL=”foo@ragner.org”

export DEBEMAIL DEBFULLNAME EDITOR

You can put these lines above in your .bashrc file

= To create a new debian/changelog file =

In the project’s directory just run

$ dch --create

To create a new debian/changelog file.

= To increment the Debian release number =

To increment the package release number run the follow command

$ dch -i -U -D "unstable"

So it will open the debian/changelog file to you  write some comments.

Thanks to Anderson Lizardo[http://lizardo.wordpress.com/] and Alvinho.

Upgrading the BIOS (Firmware) of your EeePC

Posted in EeePC, Hack | No Comments »

I updated the BIOS of my EeePC 900 using the following howto

http://wiki.debian.org/DebianEeePC/HowTo/UpgradeBIOS

and it is working ok.

I just run the following steps:

  1. Download the BIOS image from http://support.asus.com/download/download.aspx or from http://update.eeepc.asus.com/bios/. Make sure you select the right model.
  2. Prepare an USB drive formatted with FAT16 filesystem. Note that a SD card won’t work, unless you insert it in an USB card reader. To format it using FAT16, use mkdosfs -F 16 (tip from twb). If you get an error, you may need to run *fdisk on the USB drive and shrink the partition you’re using (16 MB partition seems to work). Yes, it really does have to be FAT16.
  3. Open the downloaded file. It should contain a file named like 900-ASUS-0906.ROM. The 900 part corresponds to the EeePC model. Copy that file in the root directory of the USB key, and rename it to 900.ROM. Again, 900 corresponds to the model. If your model is 901, then the download file should contain version.ROM and it should be renamed to 901.ROM when copied on the USB key.
  4. Reboot and press Alt+F2 during the boot. The BIOS updating program will start searching for USB drives, then for a suitably named ROM file. Follow the instructions on the screen.

So good work now!

Reference:

http://wiki.debian.org/DebianEeePC/HowTo/UpgradeBIOS

How to get UUID of Hard Disks

Posted in Debian, Hack, Linux | No Comments »

The Universally Unique Identifier can be used to identify a device independent form its mount point or device name.

There are several ways to get the UUID.

The first one uses the /dev/ directory. While you are on is you might want to check other by-* directories,

$ ls -l /dev/disk/by-uuid

lrwxrwxrwx 1 root root 10 11. Okt 18:02 53cdad3b-4b01-4a6c-a099-be1cdf1acf6d -> ../../sda2

Another way to get the uuid by usage of the tool blkid as super user:

# blkid /dev/sda1

/dev/sda1: LABEL=“/” UUID=“ee7cf0a0-1922-401b-a1ae-6ec9261484c0″ SEC_TYPE=“ext2″ TYPE=“ext3″

English Dictionary Extension for Firefox

Posted in Firefox | No Comments »

It is just a tip to use [http://www.merriam-webster.com] as English dictionary extension for your Firefox.

Steps to install here[http://www.merriam-webster.com/downloads/firefox/right_click_search.htm]

Reference:

http://www.merriam-webster.com/downloads/firefox/right_click_search.htm