2010/05/21

Qt - phonon

VideoPlayback in Qt via Phonon

1. create a new Qt project with module Phonon
















...
2. Add some codes in mainwindow.h & mainwindow.cpp


--- mainwindow.h ---

class MainWindow : public QMainWindow {
      :
private:
    Ui::MainWindow *ui;
    QString m_mediaFile;
    Phonon::VideoPlayer *player;
};
--- mainwindow.cpp ---

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    player = new Phonon::VideoPlayer(Phonon::VideoCategory, this);
    /// TODO: shall be a smart way to resize the playback area
    player->move(0,63);
    player->resize(width(), height()-63);
}

void MainWindow::on_action_Open_triggered()
{
    QStringList filters;
    filters << "Image files (*.mpg *.avi)"
            << "Any files (*)";

    QFileDialog dialog(this);
    dialog.setNameFilters(filters);

    if (dialog.exec())
    {
        QStringList fileNames;
        fileNames   = dialog.selectedFiles();
        m_mediaFile = fileNames.at(0);

        setWindowTitle(m_mediaFile);
        /// Load media file.
        player->load(Phonon::MediaSource(m_mediaFile));
        player->play();
    }
}

...

The simple program can play video, mp3 and jpeg.

[] video : rmvb, mpg, vob ...
[] image : jpg ...
[] music : mp3 ...

2010/05/20

Hello World mips version with eclipse.

Project -> Properties 

[ C/C++ Build ] -> [ Environment ] -> [ Select... ]



Select PATH.


Edit the PATH
Append your toolchain binary path in value field.


[ C/C++ Build ] -> [ Settings ] 

modify [ Command ] fields in GCC C++ Compiler/C Compiler/C++ Linker/Assembler respectively.
ex:  g++  -> mipsel-linux-g++



Project -> Build Project



























The mips version Hello World is built !!!
















Don't forget to export the c++ lib before execute the HelloMips binary :)


2010/05/19

CMake - my first experience (1)

REFERENCE:
http://andescore.blogspot.com/2009/08/cmake-andes-toolchains3.html

To run mySrv and myCli on mipsel platform. Add below lines in src/CMakeLists.txt and lib/CMakeLists.txt.

SET(CMAKE_C_COMPILER mipsel-linux-gcc)
SET(CMAKE_CXX_COMPILER mipsel-linux-g++)
SET(AS mipsel-linux-as)
SET(AR mipsel-linux-ar)
SET(LD mipsel-linux-ld)
SET(NM mipsel-linux-nm)
SET(OBJCOPY mipsel-linux-objcopy)
SET(OBJDUMP mipsel-linux-objdump)
SET(READELF mipsel-linux-readelf)


$ cat src/CMakeLists.txt 
SET(CMAKE_C_COMPILER mipsel-linux-gcc)
SET(CMAKE_CXX_COMPILER mipsel-linux-g++)
SET(AS mipsel-linux-as)
SET(AR mipsel-linux-ar)
SET(LD mipsel-linux-ld)
SET(NM mipsel-linux-nm)
SET(OBJCOPY mipsel-linux-objcopy)
SET(OBJDUMP mipsel-linux-objdump)
SET(READELF mipsel-linux-readelf)

INCLUDE_DIRECTORIES(${MYSOCKET_SOURCE_DIR}/lib)
LINK_DIRECTORIES(${MYSOCKET_BINARY_DIR}/lib)
ADD_EXECUTABLE(mySrv tcpSrvDemo.c)
ADD_EXECUTABLE(myCli tcpCliDemo.c)
TARGET_LINK_LIBRARIES(mySrv myTcpSocket)
TARGET_LINK_LIBRARIES(myCli myTcpSocket)

$ cat lib/CMakeLists.txt 
SET(CMAKE_C_COMPILER mipsel-linux-gcc)
SET(CMAKE_CXX_COMPILER mipsel-linux-g++)
SET(AS mipsel-linux-as)
SET(AR mipsel-linux-ar)
SET(LD mipsel-linux-ld)
SET(NM mipsel-linux-nm)
SET(OBJCOPY mipsel-linux-objcopy)
SET(OBJDUMP mipsel-linux-objdump)
SET(READELF mipsel-linux-readelf)

FIND_LIBRARY(PTHREAD pthread)
ADD_LIBRARY(myLL myLL.c)
ADD_LIBRARY(myTcpSocket myTcpSocket.c)
TARGET_LINK_LIBRARIES(myTcpSocket myLL ${PTHREAD}) 

$ cd build
$ cmake ..
$ make
[ 25%] Built target myLL
[ 50%] Built target myTcpSocket
[ 75%] Building C object src/CMakeFiles/myCli.dir/tcpCliDemo.c.o
Linking C executable myCli
[ 75%] Built target myCli
[100%] Building C object src/CMakeFiles/mySrv.dir/tcpSrvDemo.c.o
Linking C executable mySrv
[100%] Built target mySrv

$ file src/my*
src/myCli: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked (uses shared libs), not stripped
src/mySrv: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked (uses shared libs), not stripped























mySrc is running on mips platform with Linux kernel 2.6.12.
[packet] [inform] [close] are receiving status.
[status] is the server status report.

The last UI programming work - Virtual Keyboard for RTK1073/1283

This may be my last UI programming works on Realtek 1073/1283. Because default virtual keyboard developed by Realtek is not good to us. Therefore, the boss decided to develop one for ourselves. It is a virtual keyboard for user to input his own PPPoE account and password.

Major functions as below:
0. Key moved by direction buttons, and selected by [OK] button on RC.
1. Two input text fields (ACCOUNT/PASSWORD). Switched by [Next Focus]
2. Upper/Lower case switched by [Caps]
3. Erase by [Delete]
4. Move cursor by [<--] or [-->]
5. Clear current input field by [Clear]
6. Cancel input by [Cancel]
7. Save inputs by [Save]
8. Support multi-language. (EN/SC/TC)

2010/05/18

CMake - my first experience

Reference:
0.  Jserv's 貓也會的 CMake http://blog.linux.org.tw/~jserv/archives/001987.html   and http://jserv.sayya.org/cmake/cmake-overview.pdf
1. Drake's 把玩 CMake 的第一步 http://drakeguan.org/my_first_trial_of_cmake

This is my first time with CMake. Before it starts, I have to install cmake in my Ubuntu.
$ sudo apt-get install cmake
Then prepare some files and directories per Drake's suggestions.

*note:
myLL.c - a linked list library in 2009-07
myTcpSocket.c - a multi-thread tcp socket library in 2009-08


$ tree
.
├── build
├── CMakeLists.txt
├── lib
│   ├── CMakeLists.txt
│   ├── myLL.c
│   ├── myLL.h
│   ├── myTcpSocket.c
│   └── myTcpSocket.h
└── src
      ├── CMakeLists.txt
      ├── tcpCliDemo.c
      └── tcpSrvDemo.c

3 directories, 10 files


$ cat CMakeLists.txt 
cmake_minimum_required(VERSION 2.8)

PROJECT(MYSOCKET)
ADD_SUBDIRECTORY(lib)
ADD_SUBDIRECTORY(src)

$ cat src/CMakeLists.txt 
INCLUDE_DIRECTORIES(${MYSOCKET_SOURCE_DIR}/lib)
LINK_DIRECTORIES(${MYSOCKET_BINARY_DIR}/lib)
ADD_EXECUTABLE(mySrv tcpSrvDemo.c)
ADD_EXECUTABLE(myCli tcpCliDemo.c)
TARGET_LINK_LIBRARIES(mySrv myTcpSocket)
TARGET_LINK_LIBRARIES(myCli myTcpSocket)

$ cat lib/CMakeLists.txt
FIND_LIBRARY(PTHREAD pthread)
ADD_LIBRARY(myLL myLL.c)
ADD_LIBRARY(myTcpSocket myTcpSocket.c)
TARGET_LINK_LIBRARIES(myTcpSocket myLL ${PTHREAD})

$ cd build
$ cmake ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yenping/workspace/test333/build

$ ls -al
總計 44
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:20 .
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:15 ..
-rw-r--r-- 1 yenping yenping 10833 2010-05-18 17:20 CMakeCache.txt
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:20 CMakeFiles
-rw-r--r-- 1 yenping yenping  1890 2010-05-18 17:20 cmake_install.cmake
drwxr-xr-x 3 yenping yenping  4096 2010-05-18 17:20 lib
-rw-r--r-- 1 yenping yenping  5292 2010-05-18 17:20 Makefile
drwxr-xr-x 3 yenping yenping  4096 2010-05-18 17:20 src

$ make
Scanning dependencies of target myLL
[ 25%] Building C object lib/CMakeFiles/myLL.dir/myLL.c.o
Linking C static library libmyLL.a
[ 25%] Built target myLL
Scanning dependencies of target myTcpSocket
[ 50%] Building C object lib/CMakeFiles/myTcpSocket.dir/myTcpSocket.c.o
Linking C static library libmyTcpSocket.a
[ 50%] Built target myTcpSocket
Scanning dependencies of target myCli
[ 75%] Building C object src/CMakeFiles/myCli.dir/tcpCliDemo.c.o
Linking C executable myCli
[ 75%] Built target myCli
Scanning dependencies of target mySrv
[100%] Building C object src/CMakeFiles/mySrv.dir/tcpSrvDemo.c.o
Linking C executable mySrv
[100%] Built target mySrv

$ ls -al lib/ src/
lib/:
總計 48
drwxr-xr-x 3 yenping yenping  4096 2010-05-18 17:22 .
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:20 ..
drwxr-xr-x 4 yenping yenping  4096 2010-05-18 17:20 CMakeFiles
-rw-r--r-- 1 yenping yenping  1159 2010-05-18 17:20 cmake_install.cmake
-rw-r--r-- 1 yenping yenping  4638 2010-05-18 17:22 libmyLL.a
-rw-r--r-- 1 yenping yenping 12496 2010-05-18 17:22 libmyTcpSocket.a
-rw-r--r-- 1 yenping yenping  6711 2010-05-18 17:20 Makefile

src/:
總計 80
drwxr-xr-x 3 yenping yenping  4096 2010-05-18 17:22 .
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:20 ..
drwxr-xr-x 4 yenping yenping  4096 2010-05-18 17:20 CMakeFiles
-rw-r--r-- 1 yenping yenping  1159 2010-05-18 17:20 cmake_install.cmake
-rw-r--r-- 1 yenping yenping  6731 2010-05-18 17:20 Makefile
-rwxr-xr-x 1 yenping yenping 27179 2010-05-18 17:22 myCli
-rwxr-xr-x 1 yenping yenping 27360 2010-05-18 17:22 mySrv

$ tree
.
├── build
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   │   ├── CMakeCCompiler.cmake
│   │   ├── cmake.check_cache
│   │   ├── CMakeCXXCompiler.cmake
│   │   ├── CMakeDetermineCompilerABI_C.bin
│   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   ├── CMakeDirectoryInformation.cmake
│   │   ├── CMakeOutput.log
│   │   ├── CMakeSystem.cmake
│   │   ├── CMakeTmp
│   │   │   └── CMakeFiles
│   │   │       └── cmTryCompileExec.dir
│   │   ├── CompilerIdC
│   │   │   ├── a.out
│   │   │   └── CMakeCCompilerId.c
│   │   ├── CompilerIdCXX
│   │   │   ├── a.out
│   │   │   └── CMakeCXXCompilerId.cpp
│   │   ├── Makefile2
│   │   ├── Makefile.cmake
│   │   ├── progress.marks
│   │   └── TargetDirectories.txt
│   ├── cmake_install.cmake
│   ├── lib
│   │   ├── CMakeFiles
│   │   │   ├── CMakeDirectoryInformation.cmake
│   │   │   ├── myLL.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── C.includecache
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── cmake_clean_target.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   ├── depend.internal
│   │   │   │   ├── depend.make
│   │   │   │   ├── flags.make
│   │   │   │   ├── link.txt
│   │   │   │   ├── myLL.c.o
│   │   │   │   └── progress.make
│   │   │   ├── myTcpSocket.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── C.includecache
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── cmake_clean_target.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   ├── depend.internal
│   │   │   │   ├── depend.make
│   │   │   │   ├── flags.make
│   │   │   │   ├── link.txt
│   │   │   │   ├── myTcpSocket.c.o
│   │   │   │   └── progress.make
│   │   │   └── progress.marks
│   │   ├── cmake_install.cmake
│   │   ├── libmyLL.a
│   │   ├── libmyTcpSocket.a
│   │   └── Makefile
│   ├── Makefile
│   └── src
│       ├── CMakeFiles
│       │   ├── CMakeDirectoryInformation.cmake
│       │   ├── myCli.dir
│       │   │   ├── build.make
│       │   │   ├── C.includecache
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   ├── depend.internal
│       │   │   ├── depend.make
│       │   │   ├── flags.make
│       │   │   ├── link.txt
│       │   │   ├── progress.make
│       │   │   └── tcpCliDemo.c.o
│       │   ├── mySrv.dir
│       │   │   ├── build.make
│       │   │   ├── C.includecache
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   ├── depend.internal
│       │   │   ├── depend.make
│       │   │   ├── flags.make
│       │   │   ├── link.txt
│       │   │   ├── progress.make
│       │   │   └── tcpSrvDemo.c.o
│       │   └── progress.marks
│       ├── cmake_install.cmake
│       ├── Makefile
│       ├── myCli
│       └── mySrv
├── CMakeLists.txt
├── lib
│   ├── CMakeLists.txt
│   ├── myLL.c
│   ├── myLL.h
│   ├── myTcpSocket.c
│   └── myTcpSocket.h
└── src
    ├── CMakeLists.txt
    ├── tcpCliDemo.c
    └── tcpSrvDemo.c

17 directories, 82 files (<--- 3 directories, 10 files)
At final, test mySrv and myCli. They seem work fine.
FINISHED.

2010/05/12

warning: array subscript has type `char'

A 'char' may be 'signed' or 'unsigned'. Most regular compilers will default to 'signed'.
So if you have an array with index 127, you increment the index and it becomes -128.
This may of course be your intention.
A 'safe' type to use for an array 

index is 'int' or 'unsigned char'.


char idx;  /// limited range
somedata[idx] = otherdata;


==> (to eliminate the warning...)


unsigned char idx;
int idx;


memo.

2010/05/10

Simple Poker ?!




A simple Black Jack game in linux. 

If you are interested in the history of poker, click below links.
Reference:



Program output as below.


~/workspace/poker$ ./myBJ 1 2
   m_magic = 37

====== Poker in Sequence (no shuffle) ===================
S(Spades), H(Hearts), D(Diamonds), C(Clubs), A(1), X(10).
SA S2 S3 S4 S5 S6 S7 S8 S9 SX SJ SQ SK 
HA H2 H3 H4 H5 H6 H7 H8 H9 HX HJ HQ HK 
DA D2 D3 D4 D5 D6 D7 D8 D9 DX DJ DQ DK 
CA C2 C3 C4 C5 C6 C7 C8 C9 CX CJ CQ CK 

===== {0.0} SPECIAL GLASSES {S.A} =====
DA HA DQ CA CX C2 S5 SX S4 DJ H5 H7 HJ 
HQ HX H2 H9 C3 H6 C8 C9 SK C7 CJ S2 S8 
C6 H4 C5 H3 DK H8 S9 S7 C4 D7 D5 S3 SA 
D8 D3 HK D4 CK S6 SJ SQ D6 CQ D2 D9 DX 
===== {0.0} SPECIAL GLASSES {S.A} =====

Dispatch initial cards for dealer and players ...
Dealer     Card [1] = C4 
Player [1] Card [1] = D7 
Dealer     Card [2] = ** 
Player [1] Card [2] = S3 

Player [1] has D7 S3 
Player [1] now [10]... one more card ? (y/n) Player [1] has D7 S3 SA 
Player [1] now [11]... one more card ? (y/n) Player [1] has D7 S3 SA D8 
Player [1] now [19]... one more card ? (y/n) 
Dealer [0] has C4 D5 
Dealer [0] now [9]... one more card ? (y/n) Dealer [0] has C4 D5 D3 
Dealer [0] now [12]... one more card ? (y/n) Dealer [0] has C4 D5 D3 HK 
*** Exceed 21 pts (22) *** YOU LOSE !

Dealer [0] got [22] pts | C4 D5 D3 HK 
Player [1] got [19] pts | D7 S3 SA D8 
Press 'q' to exit game .

Dispatch initial cards for dealer and players ...
Dealer     Card [1] = D4 
Player [1] Card [1] = CK 
Dealer     Card [2] = ** 
Player [1] Card [2] = SJ 

Player [1] has CK SJ 
Player [1] now [20]... one more card ? (y/n) 
Dealer [0] has D4 S6 
Dealer [0] now [10]... one more card ? (y/n) Dealer [0] has D4 S6 SQ 
Dealer [0] now [20]... one more card ? (y/n) 
Dealer [0] got [20] pts | D4 S6 SQ 
Player [1] got [20] pts | CK SJ 
Press 'q' to exit game .
*** G A M E - O V E R ***


2010/05/09

Install Apache/PHP/MySQL on Ubuntu 10.04

It's almost nine years since the first and also the last time I installed the Apache web server. The web services on the last server are a company calendar (schedule) and a namelist implemented by php3 and mysql.

First we have to install Apache server via
$ sudo apt-get install apache2

Open http://localhost/ or http://127.0.0.1/ in a web browser to check if the web server is successfully installed.














Then, the php shall be installed.
$ sudo apt-get install php5 libapache2-mod-php5 php5-mysql

We may try a simple test php program on /var/www/test.php
$ sudo vi /var/www/test.php

$ sudo /etc/init.d/apache2 restart
Check again !

Install mysql server. 
$ sudo apt-get install mysql-server mysql-client phpmyadmin
Setup your own password during installation.

After installation, browse http://localhost/phpmyadmin/ and provide the username as root and your password as below.























When username and password are verified, you shall get below screen.