2024年3月4日星期一

Decimal to/from Octal by Qt QString

 quint32 oct_value = 20;

QString str_oct;


// from oct to dec

str_oct.setNum(oct_value);

quint32 dec_value = str_oct.toUInt(nullptr, 8);


// from dec to oct

str_oct.setNum(dec_value, 8);

oct_value = str_oct.toUInt();


2021年2月3日星期三

Directory Selection Menu Example for Linux (Bash Shell Script)

 #!/bin/bash

selectdir() {

# get directory list and convert it to an array

dir_list=($(ls -d $1/* | awk '{ print $1 }'))


selection=$(whiptail --title "Folder Selection" --menu "Select a folder:" 14 40 6 \

            `for index in ${!dir_list[*]}; do printf "%d %s " $index ${dir_list[$index]}; done` \

            3>&1 1>&2 2>&3)


exitstatus=$?

if [ $exitstatus -eq 0 ]; then

    echo ${dir_list[$selection]}

fi

}

path=$(selectdir $PWD)

echo "selected path = "$path


2018年4月11日星期三

iBus, iBus Pinyin and BLFS 8.2 (Systemd edition)

1. Remove "i18h.h" for iBus

We can remove the file "/etc/profile.d/i18n.h" so that the system variable "LANG" will be handled by the file "/etc/locale.conf" only. The advantage is we can use the systemd command "localectl" to configure the system locale. (The command "localectl will NOT handle the file "i18h.h" so sometimes you will find that the system locale is incorrect even you have used the command "localectl" to set your system locale setting.)

2. Setup system variables for ibus

Create the following file:

cat > /etc/profile.d/ibus.sh << EOF

export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus

EOF

3. Setup auto start for iBus

Create the following file:

cat > /etc/xdg/autostart/ibus-daemon.desktop << EOF

[Desktop Entry]
Type=Application
Encoding=UTF-8
Version=1.5.18
Name=ibus-daemon
Comment=iBus Daemon
Exec=/usr/bin/ibus-daemon --xim -d
X-GNOME-Autostart-enabled=true
X-KDE-autostart-after=panel

EOF

4. Build iBus Pinyin

4.1 Install Berkely Database

4.2 Download three files from iBus libpinyin web site (https://sourceforge.net/projects/libpinyin)

- libpinyin source code
- model file (in this example, model15 is used)
- ibus-pinyin source code

4.3 Build libpinyin

extract the source code package and run the following commands:

cp ../model15.text.tar.gz data/
sed '51,51d' -i data/Makefile.am

./autogen.sh --prefix=/usr --disable-static
make
make install

Note: The above "cp" and "sed" commands are used to remove the "wget" instruction and copy the model file to the target folder so we can build the source codes in the offline environment.

4.4 Build ibus-pinyin

extract the sourc code package and run the following commands:

./autogen.sh --prefix=/usr --sysconfdir=/etc
make
make install

5. Test iBus for pinyin

If you run the command "gtk-query-immodules-2.0" (for GTK+ 2.x) or the command "gtk-query-immodules-3.0" (for GTK+ 3.x), you will find that iBus input module will be activated if the beginning of the system locale is "zh", "ja" or "ko" only.
Therefore, we have to use the systemd command "localectl" to set the correct system locale such as "zh_CN.GB18030". You can run "locale -a" to find out the available system locale and read the Chapter 6.2 (Glibc 2.27) of LFS 8.2 for more information.

Then, you can start the iBus configure panel and add "Pinyin" method in the list.
Now, you should able to switch iBus input method and input Chinese characters in your text editor (e.g. mousepad).

Setup Notification Deamo for BLFS 8.2

If Notification daemon is not started automatically, you can run the following command (as root):

cp /usr/share/applications/notification-daemon.desktop /etc/xdg/autostart/

2018年4月7日星期六

Install Onboard for BLFS 8.2

1. Install hunspell

1.1 extract the source code package
1.2 execute:
autoreconf -vfi
./configure --prefix=/usr --sysconfdir=/etc
make
make install
ldconfig

2. Install python distutils extra

2.1 extract the source code package
2.2 execute:
python3 setup.py build
python3 setup.py install --optimize=1


3. Install Onboard

3.1 extract the source code package
3.2 execute:

python3 setup.py build
python3 setup.py install --optimize=1

glib-compile-schemas /usr/share/glib-2.0/schemas


Install X11Vnc for BLFS 8.2

X11Vnc is a VNC server for Linux

1. Install libvncserver

1.1 extract the source code package
1.2 execute:
./autogen.sh --prefix=/usr
make
make install

2. Install TCL and TK packages

3. Install x11vnc

3.1 extract the source codes package
3.2 execute:
./autogen.sh --prefix=/usr --sysconfdir=/etc
make
make install

xinput_calibrator and xorg driver

xinput_calibrator (version 0.7.5) is a X Window calibration application for touch screen device.
However, it only works with "evdev" xorg driver and cannot work with "libinput" xorg dirver.

To check which xorg driver is using for your touch screen device, we can execute the following command:

grep -e "Using input driver" /var/log/Xorg.0.log

If you find that "libinput" is using for your touch screen device, you have to create a configuration file to fix it:

cat > /usr/share/X11/xorg.conf.d/90-FixTouchDriver.conf << "EOF"

Section "InputClass"
    Identifier "You touch screen device Id"
    MatchIsTouchscreen          "on"
    MatchDevicePath              "/dev/input/event*"
    Driver                                "evdev"
EndSection

EOF

Then, xinput_calibrator should be able to get the correct values from the xorg driver.