Archive | Anything_Computer RSS feed for this section

Android coding samples will arrive shortly

23 Dec

I’m currently involed in a project that develops software running on android mobile platforms. The project is currently on going and I’d like to share experience with all the people that are interested in.

The coding examples will cover basic knowledge as well as third party sdks. As I am a new developer on android. These samples/tutorials won’t be very hard to master, and they are actually very useful in the whole developing process. It mainly covers: platform settings, basic usage of views, cutomize views, response to the user interaction, connection with facebook in the first stage of the articles. So watch on this blog if you feel interested in.

Advertisements

Macbuntu makes your linux mac-alike

19 Nov

What I like mac the most is the FONT, though Windows has a default well-enough, yet compared to MacOSX, is still looks not that good.

There’s a little bug in this transformation back, mainly focused on the textbox control, yet since it is well-enough, we should expect the next version.

Oh, btw, I am using Linux Mint 10. It suits pretty well.

Simple ways to get your computer connected to SSH and VPN servers in GNOME.

26 Sep

Since i’ve been studying in CSE@UNSW. Almost all the jobs are connected with SSH servers and VPN servers(OpenVPN as an example here). If you are using Linux and the Gnome Environment, it is pretty easy for you to get all things fixed in simply a few steps. And this article is meant to guide you how to do it.

Note that the system involved in this tutorial is Ubuntu 10.10 beta, yet I believed that you won’t find many differences when configuring under other distributions of Linux.

1. Get your computer connected to the SSH server.

Go to Places -> Connect to Server


select type: SSH, type in the server address, port(usually 22), and your username and hit connect. (You may leave the folder to be blank, or if you want to enter a specific folder like /, you can input in the corresponding text-box.)
You can also right click on the panel, select Add to panel, and then select “Connect to Server” applet, and hit Connect.


After a prompt in which you enter your password, you can see a mounted folder on your desktop.  All done.

2. Get your computer connected to the VPN server using OpenVPN

First you need to install the openvpn application via using the following command typed in terminal: (or you can search OpenVPN in synaptic package manager)

sudo apt-get install openvpn

Second, you need to install a small applet using the following command:

sudo apt-get install network-manager-openvpn

After all these things done, you can  click on the network applet on your panel, and scroll down to the VPN menu, then click “Config VPN”. Now you shall see a “Network Connection” dialog. If you have already configured an wireless.conf file, you can simply hit “Import” from the dialog, and import the previous configuration. After all these things done. Click the applet icon again, scroll down to VPN menu, and hit the name of VPN. Since now, everything is done.

Yet, you may face a little problem in Ubuntu 10.10 beta. When i try to do this , i was informed that the VPN server could not be connected because invalid key secrets. If you are sure that the wireless.conf file are legal and you can start the openvpn service using command line, you may try the following:

Open a terminal and type: sudo gedit

Now you see a gnone text editor running under root privileges, open the file located at /etc/dbus-1/system.d

and add the following four lines into the file right between the two policy tags:

<policy user="at_console">
<allow own="org.freedesktop.NetworkManager.vpnc"/>
<allow send_destination="org.freedesktop.NetworkManager.vpnc"/>
</policy>
Now your file shall look like this:
<!DOCTYPE busconfig PUBLIC
“-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN”
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="org.freedesktop.NetworkManager.openvpn"/>
<allow send_destination="org.freedesktop.NetworkManager.openvpn"/>
</policy>
<policy user="at_console">
<allow own="org.freedesktop.NetworkManager.vpnc"/>
<allow send_destination="org.freedesktop.NetworkManager.vpnc"/>
</policy>
<policy context="default">
<deny own="org.freedesktop.NetworkManager.openvpn"/>
<deny send_destination="org.freedesktop.NetworkManager.openvpn"/>
</policy>
</busconfig>
restart the computer, and connect it again, everything shall be just fine!

How to add desktop shortcut in KDE.

25 Aug

If you find this article helpful please follow the blog: https://rongsheng007.wordpress.com, and recommend it to your friends. Thx.

[NOTE:] This article is talking about how to add a shortcut of a batch file or shell script. If you want to add a shortcut of a file, simply right-click and “Add to desktop”.

I’ve been confusing about how to create a shortcut for a long time, yet finally figure out a way. Beside this, I go deep to the shortcut file, and work out an another complicated way~ Let’s see how to do.

1. My application need to run in a root privilege.  (skip this if your application don’t need to)

In KDE, you need to add kdesu before the command which you wish to run. (in GNOME use gksu instead)

2. What’s Now?

Right click the Application Launcher.(Left-bottom, blue button), and select Menu Editor, now you can see a KDE Menu Editor dialog. Click the New Item on the toolbar, type the name and click OK. On the right side of the Menu Editor, type the command into it or use the small button on the right to locate the application. After these all, click Save on the toolbar. Then you can drag the item into the category you want, and then click Save.

3. How can I put it into desktop?

Right click the item in the Application Lanucher, then click Add to Desktop. We are done!

3. My shortcut points to a shell script or batch file that doesn’t have an icon, can I add one?

Yes, to do so move the cursor to the icon and wait until a vertical bar shows, click on the icon that looks like a screwdriver. Now you can see a Icon Setting Dialog. Click the screwdriver icon on the General tab. You can see a KEditFileType dialog. Now click the icon itself, a Select Icon dialog will show up, choose the icon you want and click OK, everything is done.

4. Can I change the icon directly from the menu?

Yes. But it is not that easy to find for the first time…Click the “CLICK HERE” part showed in the following picture…

5. What is a shortcut?

A .desktop file actually. When you use Dolphin file manager and you type applications:/ in the address bar, you can see all the applications listed in the manager. When you right click on the blank place, and select Create New -> Link to Application, you find it the same with what you were doing. But still, what it is? If you right click a shortcut and choose Open with -> Kate, you will find it is a readable ascii text file, just like this:

It is actually true that we can simply write a file like this and save it. As long as the extension of the file is not engaged by other program(say if you save it to a.txt, it will be open by kate, you save it to a.jpg, it will be open by gview). Here we save it to a.desktop(you can save it to a.hello, a.bye as well). We see a exclamation mark on the icon, when you click it, the system will pop-up a dialog and says “This will start a program”, click yes. WOW, you now create a shortcut by your own. Isn’t it amazing?

Anyway, you cannot write files or add link to applicaiton in application:/, even if you are the root. Okay, this is the end of the tutorial, Thx.

Make Qt applications work with Firebird database.

23 Aug

NB:If you see this post and you like it, please follow https://rongsheng007.wordpress.com. Thx.

In the last post, we have already figure out how to connect to the firebird database in Linux/UNIX environment. In this post, I will use application built in Qt framework to connect the firebird database and do simply task.

To allowing Qt applications connect to the firebird database, we need some tools, here I introduce the IBPP project. IBPP stands for InterBase Plus Plus. IBPP is a client interface written by a group of people which provide connectivity with Interbase database system. Firebird, as is described in previous post, derived from Interbase system. Thus it is natural that IBPP interface support firebird too.

To begin, download the  IBPP source code package from: http://sourceforge.net/projects/ibpp/files/, and unpack to your desired folder. Note that this post is based on the IBPP version 2.5.3.1, all the following configurations are based on this version. You will find two folders in the destination folder where you unpacked the file into. One is “core” and the other is “tests“. (We assume that you already has a Qt project, if not, build one.) Copy all the files from the core folder to your project files location, and put them into a new core folder if you want to. Now open the project with Qt Creator, and add these files into the project.  

[Note that, if you need to install g++ to compile the project. Qt Creator doesn’t seem to provide interfaces to allow user to switch the compiler, be aware of this. OR I haven’t found it yet??]

The first job is to add one line to every IBPP file. (or maybe you have a better idea? I don’t know coz i do this job pure manually…)

What you need to add is:

#include<string.h>    OR   #include<string>

This is very tricky isn’t it? I believed that the dev-group owns their special tool to do the job before compiling…

Okay, after the job is done, we need to configure the project environment. We are using Linux operating system, but you can configure the Qt creator in a similar way in UNIX or more specific: Mac.(See the file in tests folder, it  offers details)

Open the project file(.pro) in the Projects explorer, and add the following in your project file.

QMAKE_CXXOUTPUT = -o
QMAKE_CXXFLAGS += -DIBPP_LINUX
QMAKE_CXXFLAGS += -W -Wall -fPIC
QMAKE_CXXFLAGS += -g -DDEBUG

LIBS +=-lfbclient -lcrypt -lm -ldl -lpthread # dependancies for shared library

Now, your project file should look like this:  

Well, I believed that ALL things are set, what we need to do is to test if it really works. Open a file in your project and try the following way to connect to the database.

First of all, you need to include a header to your project file:

#include “core/ibpp.h”  (if you do not )

then we need to connect to the database using IBPP functions, as follows:

IBPP::Database ibpp = IBPP::DatabaseFactory(“”,”sys.fdb”,”SYSDBA”,”rongsheng”);
ibpp->Connect();

Besides simply do this two lines, add a try-catch block to check if the connection is successfully built. The exception class in IBPP is the IBPP::Exception, and the method for printing error msg out is e.ErrorMessage(), just as follows:

(to make sure the QMessageBox works, include the “QMessageBox.h” header)

try{

…;

}

catch(IBPP::Exception& e)
{
QMessageBox QMsgBox;
QMsgBox.setText(e.ErrorMessage());
QMsgBox.setWindowTitle(“Error”);
QMsgBox.exec();
}

Now run this program, if you assign a blank database file, you could see a error messagebox showing up.

To connect to the database is far way from we can say that everything is done. We still need to see how to retrieve data from the database(we assume that you have already add the connection code):

IBPP::TAM itam = IBPP::amRead;     //set mode to read
IBPP::TIL itil = IBPP::ilConcurrency;  //support concurrency
IBPP::Transaction itran = IBPP::TransactionFactory(ibpp,IBPP::amRead,IBPP::ilConcurrency,IBPP::lrWait,IBPP::TFF(0));    //Initialise the transaction class which defines the transaction procedure.
itran->Start();       //start the transaction.
IBPP::Statement istat = IBPP::StatementFactory(ibpp,itran);   //The class which contains the SQL statement to be executed.
std::string sql = “select * from DICT”;        //our sql statement.
istat->Prepare(sql);  //write the sql statement into the class.
istat->Execute();      //EXECUTE !!!
std::string result;      //we define a string here which used to get the result that returns.
while(istat->Fetch())  //Fetch method is the core method which is used to fetch data from database
{
istat->Get(“DICT_NAME”,result);  //output to result. Be aware that I here only output the COLUMN “DICT_NAME”
}

Now, all the result are written in to ‘result’ variable, you can print it out as you wish. What I’m gonna do is to write them into a QListView control. So firstly I defined a QStringList outside the loop which used to store data:

QStringList list;

then I add:

QString qresult = QString::fromStdString(result);   //convert std::string to QString
list.append(qresult); //append the result into a QStringList

in the while() loop, of course behind the istat statement, and show them into the comtrol with:

QStringListModel* qmodel = new QStringListModel();
qmodel->setStringList(list); //bind the QStringList to the model
ui->listView->setModel(qmodel); //bind the QStringListModel to QListView.
//qmodel is a QListView which we created using Qt Design.

Now, we can really say everything is done! Phew:). Here is the snapshot of result.

Set up and Connect to the Firebird Database.

22 Aug

[NB]: please follow up the blog at : https://rongsheng007.wordpress.com if you are reading the article in facebook or other places. Thx.

Firebird database is a database based on the Borland Interbase database. Firebird provides powerful features both on it’s server edition and embedded edition. I personally use this database in desktop application development. This software becomes my first choice since it is free and softwares can access database file without building up the server.(embedded version).

BTW: Firebird database seems to support a variety of operating systems.

Here’s how we do it in Linux/UNIX.

1. choose the edition and download the package of firebird database from sourceforge (currently 2.5 RC3)

http://www.firebirdsql.org/index.php?op=files&id=fb250_rc3

2. Unpack the file to a folder (say ~/Document/)

3. Run scripts
for Ubuntu and it’s derived system: $ sudo sh ./install.sh
for other linux/unix, first switch to root user using
# su
then #sh ./install.sh

4. Configuration
go to the folder /opt/firebird/ , run
for Ubuntu $sudo passwd firebird
for other linux/unix: #su passwd firebird
then set the new UNIX password.

5. Test
Now you should be in the folder: /opt/firebird , if you are not in this folder, please switch to this folder.
run the following command as root:
./bin/isql
you should see:

Use CONNECT or CREATE DATABASE to specify a database
SQL>

now try the sql command:
connect ./examples/empbuild/employee.fdb user SYSDBA password ;

note: replace to the password you just set and do not ignore the ‘;’.

now you may see:
Database: ./examples/empbuild/employee.fdb, User: SYSDBA

try another command: show table; (don’t omit the ‘;’)

you may see:
COUNTRY                                      CUSTOMER
DEPARTMENT                           EMPLOYEE
EMPLOYEE_PROJECT        JOB
PROJECT                                       PROJ_DEPT_BUDGET
SALARY_HISTORY SALES

till now, you have successfully configured the firebird database, use “quit;” to exit the command prompt.

Running the Server:

If you want to start the sever rather than using files to open it, you need to start the fbguard session.

open a terminal and direct to folder :  “/opt/firebird/bin/”, then run the following command as root user.

./fbguard             or                ./fbguard -d   (if you want to run it in background)

now the system is started, you can run a GUI tool to examine, try “FlameRobin”. here is a screenshot of the configured firebird database.