How to set GObject and subclass types property in gst-launch cmdline

Example 0

gst-launch-0.10 playbin2 uri=file:///home/heiher/movies/a.rmvb \
video-sink="fakesink"

Example 1

gst-launch-0.10 playbin2 uri=file:///home/heiher/movies/a.rmvb \
video-sink="ffmpegcolorspace ! xvimagesink"

Over!

使用 GtkBuilder 构造自定义构件

之前博客里有一个非常类似的记录 使用 Builder 构造自定义构件,是在学习 Vala 语言时记录的。说的是如何使用 GtkBuilder 构造出自定义构件,仅仅只给出了一个示例代码。

最近在写 GTK+ 程序时被代码写 UI 的方式搞的很累,尽管那个 UI 并不复杂。在程序中有使用自定义的构件(是 GtkWidget 的子类),这里再重新整理一下关于 GtkBuilder 构造自定义构件的日志,并给出一个 C 语言版本的示例。

GTK+ 从 2.12 开始实现了 GtkBuildable 接口类与 GtkBuilder 类用于处理从 XML 格式的 UI 描述数据中构造出对象的实例,提高 GTK+ UI 程序的开发效率。只要实现了 GtkBuildable 接口类的 Widget 类,都可以在 XML 格式的 UI 描述数据中引用,并使用 GtkBuilder 进行实例化。

目前 GTK+ 库中基本上所有的 Widget 类都实现了 GtkBuildable 接口类,也就意味着可以使用 GtkBuilder 进行实例化。然而有的时间情况并不总是那么好,我们的项目需要自定义新的 Widget 类型完成特定的功能,幸运的是这些自定义的 Widget 类型只要实现了 GtkBuildable 接口类也是一样可以被 GtkBuilder 实例化的。

示例代码

示例中 src/hev-window.h 和 src/hev-window.c 是基于 GtkWindow 简单派生出来的 HevWindow 类。ui/main.xml 使用 HevWindow 类构造了一个 Window,在 src/hev-main.c 中创建了一个 GtkBuilder 实例 builder 来装载 ui/main.xml 并通过 name (对应描述文件中的 id)来获取构造出来的 HevWindow 类型的实例,再调用 gtk_widget_show 方法显示出来。

PS:编译参数中需要使用 gmodule-export-2.0,这样才能导出自定义类型与信号处理函数,需要描述文件中指定的信号回调将不能正常调用。具体见示例中的 Makefile

Over!

X Window 禁用显示器的节能模式

在没有安装桌面环境的电源管理程序(如 gnome-power-manager)的情况下,可以通过 X Window 的 DPMS 控制选项来开启、关闭显示器的节能模式。禁用 DPMS 功能是无法禁用节能模式的。

查看当前 DPMS 状态

...
 
DPMS (Energy Star):
  Standby: 600    Suspend: 600    Off: 600
  DPMS is Enabled
  Monitor is On

禁用节能模式
编辑文件 /etx/X11/xorg.conf

...
 
Section "ServerFlags"
    Option "BlankTime" "0"
    Option "StandbyTime" "0"
    Option "SuspendTime" "0"
    Option "OffTime" "0"
EndSection
 
...

Over!

KVM 网络配置:VDE 方式

KVM 不知道从什么时候不能直接通过参数 -net nic 访问网络了,今天研究了一下可以通过 VDE 方式访问网络,配置相对之前有点复杂了。

======== Host OS 配置 ========
VDE 服务配置
配置文件 /etc/conf.d/vde 需要修改的行

VDE_CONFIG="vde-config"
 
VDE_CONNECTION="vde-connection"

复制配置文件模板 /etc/vde/vde-config.sample, /etc/vde/vde-connection.sample

sudo cp /etc/vde/vde-config.sample /etc/vde/vde-config
sudo cp /etc/vde/vde-connection.sample /etc/vde/vde-connection

配置文件 /etc/vde/vde-config 需要修改的行

VDE_SOCK_GROUP="kvm"
 
VDE_TAP="tap0"

启动 VDE 服务

sudo /etc/rc.d/vde start

配置网络接口 tap0 地址

sudo ifconfig tap0 192.168.100.1 netmask 255.255.255.0 up

配置 NAT

sudo iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j MASQUERADE
sudo iptables-save > /tmp/iptables
sudo cp /tmp/iptables /etc/iptables/iptables.rules
sudo touch /etc/iptables/ip6tables.rules

配置文件/etc/conf.d/iptables 中需要修改的行

IPTABLES_FORWARD=1

启动 NAT 服务

sudo /etc/rc.d/iptables start

启动 KVM

kvm -net nic -net vde,sock=/var/run/vde/sample.sock -hda ...

======== Guest OS 配置 ========
网络连接信息

Address: 192.168.100.2
Netmask: 255.255.255.0
Gateway: 192.168.100.1
DNS: 8.8.8.8

Over!

使用 Firefox 多实例模式调试插件

最近需要调试在 Firefox 里调试 Mozilla NPAPI 的插件程序,但是 Firefox 还需要登录着 GMail 和 OA 等应用。为了不冲突,可以创建一个新的 Firefox Profile 并启动新的实例进行调试。

创建新的 Profile

firefox -no-remote -ProfileManager


上面创建了一个新的 Profile: PluginTest

以新实例启动 Firefox

firefox -no-remote -P PluginTest

Over!

Bash Shortcuts For Maximum Productivity

It may or may not surprise you to know that the bash shell has a very rich array of convenient shortcuts that can make your life, working with the command line, a whole lot easier. This ability to edit the command line using shortcuts is provided by the GNU Readline library. This library is used by many other *nix application besides bash, so learning some of these shortcuts will not only allow you to zip around bash commands with absurd ease :), but can also make you more proficient in using a variety of other *nix applications that use Readline. I don’t want to get into Readline too deeply so I’ll just mention one more thing. By default Readline uses emacs key bindings, although it can be configured to use the vi editing mode, I however prefer to learn the default behavior of most applications (I find it makes my life easier not having to constantly customize stuff). If you’re familiar with emacs then many of these shortcuts will not be new to you, so these are mostly for the rest of us :).

Command Editing Shortcuts

  • Ctrl + a – go to the start of the command line
  • Ctrl + e – go to the end of the command line
  • Ctrl + k – delete from cursor to the end of the command line
  • Ctrl + u – delete from cursor to the start of the command line
  • Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
  • Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
  • Ctrl + xx – move between start of command line and current cursor position (and back again)
  • Alt + b – move backward one word (or go to start of word the cursor is currently on)
  • Alt + f – move forward one word (or go to end of word the cursor is currently on)
  • Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
  • Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
  • Alt + u – make uppercase from cursor to end of word
  • Alt + l – make lowercase from cursor to end of word
  • Alt + t – swap current word with previous
  • Ctrl + f – move forward one character
  • Ctrl + b – move backward one character
  • Ctrl + d – delete character under the cursor
  • Ctrl + h – delete character before the cursor
  • Ctrl + t – swap character under cursor with the previous one

Command Recall Shortcuts

  • Ctrl + r – search the history backwards
  • Ctrl + g – escape from history searching mode
  • Ctrl + p – previous command in history (i.e. walk back through the command history)
  • Ctrl + n – next command in history (i.e. walk forward through the command history)
  • Alt + . – use the last word of the previous command

Command Control Shortcuts

  • Ctrl + l – clear the screen
  • Ctrl + s – stops the output to the screen (for long running verbose command)
  • Ctrl + q – allow output to the screen (if previously stopped using command above)
  • Ctrl + c – terminate the command
  • Ctrl + z – suspend/stop the command

Bash Bang (!) Commands
Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.

  • !! – run last command
  • !blah – run the most recent command that starts with ‘blah’ (e.g. !ls)
  • !blah:p – print out the command that !blah would run (also adds it as the latest command in the command history)
  • !$ – the last word of the previous command (same as Alt + .)
  • !$:p – print out the word that !$ would substitute
  • !* – the previous command except for the last word (e.g. if you type ‘find some_file.txt /‘, then !* would give you ‘find some_file.txt‘)
  • !*:p – print out what !* would substitute

There is one more handy thing you can do. This involves using the ^^ ‘command’. If you type a command and run it, you can re-run the same command but substitute a piece of text for another piece of text using ^^ e.g.:

$ ls -al
total 12
drwxrwxrwx+ 3 Administrator None    0 Jul 21 23:38 .
drwxrwxrwx+ 3 Administrator None    0 Jul 21 23:34 ..
-rwxr-xr-x  1 Administrator None 1150 Jul 21 23:34 .bash_profile
-rwxr-xr-x  1 Administrator None 3116 Jul 21 23:34 .bashrc
drwxr-xr-x+ 4 Administrator None    0 Jul 21 23:39 .gem
-rwxr-xr-x  1 Administrator None 1461 Jul 21 23:34 .inputrc
$ ^-al^-lash
ls -lash
total 12K
   0 drwxrwxrwx+ 3 Administrator None    0 Jul 21 23:38 .
   0 drwxrwxrwx+ 3 Administrator None    0 Jul 21 23:34 ..
4.0K -rwxr-xr-x  1 Administrator None 1.2K Jul 21 23:34 .bash_profile
4.0K -rwxr-xr-x  1 Administrator None 3.1K Jul 21 23:34 .bashrc
   0 drwxr-xr-x+ 4 Administrator None    0 Jul 21 23:39 .gem
4.0K -rwxr-xr-x  1 Administrator None 1.5K Jul 21 23:34 .inputrc

Here, the command was the ^-al^-lash which replaced the –al with –lash in our previous ls command and re-ran the command again.

There is lots, lots more that you can do when it comes to using shortcuts with bash. But, the shortcuts above will get you 90% of the way towards maximum bash productivity. If you think that I have missed out on an essential bash shortcut that you can’t live without (I am sure I have), then please let me know and I’ll update the post. As usual, feel free to subscribe to my feed for more tips and opinions on all things software development.

Over!
{ Via }

Enable IME in password field in Firefox 4.0.1

Sometimes, you need software keyboard and uses GTK+ Input method module in password field in Firefox browser.

Why it doesn’t work?
May be security, Firefox disable input method context support in password entry widget by default.

How to make it works?
Modify file: widget/src/gtk2/nsGtkIMModule.h

// If software keyboard is needed in password field and uses GTK2 IM module
// for inputting characters, we need to enable IME in password field too.
//#ifdef MOZ_PLATFORM_MAEMO
#define NS_IME_ENABLED_ON_PASSWORD_FIELD 1
//#endif

Rebuild firefox.

Over!