2011年3月24日星期四

[转载]Ubuntu设置"位置(Places)"菜单、"应用程序"菜单

"位置"菜单:
打开一个文件夹窗口(随便一个),在菜单拦打开"书签"-"编辑书签",然后就可以增加活删除"位置"(Places)菜单的项目了。
或者你可以编辑用户目录下的.gtk-bookmarks文件。
用命令 gedit ~/.gtk-bookmarks
"应用程序"菜单:
右键-编辑菜单

在64位系统中安装lightning

从thunderbird 的官网下的lightning 插件是不能用于x86_64 系统的.
可以通过软件源安装:
sudo apt-get install xul-ext-lightning
重启thunderbird就可以用了.

ref: https://lists.ubuntu.com/archives/ubuntu-users/2010-October/230200.html

2011年3月22日星期二

[转载]ubuntu 的文件关联

 
PS:如果你要修改文件的打开方式,请选择右键=>属性=>打开方式=>删除
和Windows一样,在Gnome的文件管理器(nautilus)里,双击一个文件的时候,
系统会自动调用相应的程序去打开这个文件。前提是能打开这个文件的软件已经安装
并且配置完毕了。

在Nautilus里通过右键菜单固然可以修改默认的打开方式,但是缺乏灵活性和可
操作性,比如,不能删除一些候选的打开方式,不能批量增加一些打开方式等等。

经过反复的摸索,终于被我发现了GNMOE的打开方式的配置方式。
这里需要涉及到以下几个目录和文件

~/.local/share/applications
/etc/gnome/defaults.list
/usr/share/applications
/usr/share/applications/mimeinfo.cache
~/.local/share/applications/mimeinfo.cache
去这几个目录看一下,就会发现很多以 desktop 为后缀的文件。
这些文件是多功能的,第一,它们是组成GNMOE的“开始”菜单的一部分,即“开始”
菜单里的一些应用程序项,在这里都能找到。你可以运行 alacarte, 这里会
列出整个菜单的结构,你可以编辑它,但是很多项你没法删除,因为没有权限,
你试着用root权限去运行 alacarte ,抱歉,你还是没有权限删除,要删除它们,
只有在/usr/share/applications下面找到对应的文件,直接删除这个文件即可。

从总体上讲
/etc/gnome/defaults.list保存了全局的打开方式
~/.local/share/applications/defaults.list保存了个人的打开方式
当两着不一致是,优先采用局部的个人设置。

~/.local/share/applications
/usr/share/applications
这两个分别是局部的desktop项和全局的desktop项

/usr/share/applications/mimeinfo.cache
~/.local/share/applications/mimeinfo.cache
这两个分别是全局的和局部的打开方式缓存

先看一下/etc/gnome/defaults.list的结构

[DefaultApplications]
application/csv=gnumeric.desktop
application/excel=ooo-calc.desktop
application/msexcel=ooo-calc.desktop
application/msword=ooo-writer.desktop
application/ogg=mplayer.desktop
application/pdf=evince.desktop
application/postscript=evince.desktop
.................
text/x-chdr=vim.desktop
text/x-csrc=vim.desktop
text/x-dtd=vim.desktop
text/x-java=vim.desktop
text/mathml=vim.desktop
text/x-python=vim.desktop
text/x-sql=vim.desktop
text/xml=firefox.desktop
video/dv=mplayer.desktop
video/mp4=mplayer.desktop
video/mpeg=mplayer.desktop
video/msvideo=mplayer.desktop
video/quicktime=mplayer.desktop
video/vnd.rn-realvideo=mplayer.desktop
video/x-anim=mplayer.desktop
video/x-avi=mplayer.desktop
video/x-flc=mplayer.desktop
......................

不难发现
是这样的一种形式
程序的类型/文件类型=打开这个文件的项[;项2]...[;项n]
候选打开方式可以有好几种
中间用;隔开,不留其余字符


要修改一个文件的打开方式,需要先确定这个文件的类型
以纯文本文件为例类型是plain打开方式默认为vim.desktop
候选的是firefox.desktop
text/plain=vim.desktop;firefox.desktop

可以直接编辑
~/.local/share/applications/defaults.list
/etc/gnome/defaults.list
编辑完之后,手工修改
/usr/share/applications/mimeinfo.cache
~/.local/share/applications/mimeinfo.cache
这两个cache文件。
这样就立即生效了

下面看一下desktop文件的结构

[DesktopEntry]
Encoding=UTF-8//字符编码
Name=vim  //现实的名字
MimeType=text/plain;//类型
Exec=vim%f//运行的程序%f表示一个参数
Type=Application //类型
Terminal=true//是否使用终端
NoDisplay=true//是否显示在gnome菜单里

知道这些
就可以很方便的定制“开始”菜单 和 文件的打开方式了

2011年3月20日星期日

ubuntu 桌面几个问题的解决方法

1.  底部的面板不能显示打开的程序, 即无论打开多少程序, 底部面板始终是空的, 但是Alt+Tab 却能切换程序.
     解决方法: 貌似是gnome-panel的错误, 重新载入面板就可以了.
                       具体可以猛击这里.
2. 在安装完touchpad-indicator后, 有一次切换鼠标和触摸板时, 鼠标好像卡住了, 一直显示"拖拽"状态, 鼠标能移动, 就是不能点击, 左右键都不行.
     解决方法: 这个是nautilus的问题. 要是还能运行terminal的话, 直接运行:
                        kill `pgrep nautilus`

2011年3月8日星期二

在Ubuntu上安装coin3d

  coin3d是 open invertor 的一种开发包, 有SIM 公司开发. 这是一个开放源码的OIV开发包,使用协议采用的是GPL协议,在linux和windows下都能用. 
    官方源里已经有coin3d的库了, libcoin40 对应的是2.x 版本的, libcoin60 对应的是3.x 版本的.我这里用3.x的版本
apt-get install libcoin60 libcoin60-dev libcoin60-runtime
 然后是编译SoXt:
     先搞定一些依赖:
sudo ln /usr/lib.so.1 /usr/lib.so
sudo apt-get install libmotif-dev libmotif3
     从官方下载SoXt源码包, 解压之后:
./configure
make
make install

NOTE: 安装好, 编译coin3d程序的时候要加上 -lSoXt 不然会找不到 SoXt库.

NOTE: 在使用纹理贴图时,会出现Coin warning in SbImage::readFile(): The simage library is not available, can not import any images from disk.
这是因为libsimage没有装。
sudo apt-get install libsimage-dev

2011年3月2日星期三

ubuntu 中 empathy 的people nearby 不能登录的解决办法

最近发现, 当ubuntu 开机久了以后, 经过多次待机, empathy 的people nearby就连不上, 一连直接显示 "People nearby account Network error"

google了一下, 发现这个协议是由telepathy-sault 实现的,
我就把telepathy-sault  kill掉了,
再连接, 就可以了



ref:
http://askubuntu.com/questions/10451/what-protocol-does-empathys-people-nearby-use-and-what-other-chat-programs-us

2011年3月1日星期二

定制bash提示符

废话少说,先上我的配置,把下面的加在~/.bashrc 里就可以了:

PS1="\[\e[1;30m\]\u:\[\e[36m\]\w\[\e[32m\]\$\[\e[0m\]" 
PS2="\[\e[1;32m\]>\[\e[0m\]"
以下是一些说明:
PS1和PS2:
Bash有两级提示符。第一级提示符是经常见到的Bash在等待命令输入时的情况。第一级提示符的默认值是$符号。如果用户不喜欢这个符号,或者愿意自己定义提示符,只需修改PS1变量的值。例如将其改为:
PS1=”Enter a command:”
第二级提示符是当Bash为执行某条命令需要用户输入更多信息时显示的。第二级提示符默认为>。如果需要自己定义该提示符,只需改变PS2变量的值。例如将其改为:
PS2=”More information:”

bash可识别的专用序列:
用反斜杆"\"可以显示bash一些专用的列表, 下面是bash可识别的全部专用序列的完整列表(您可以在 bash man page 的 "PROMPTING" 部分找到这个列表):
序列 说明

\a ASCII 响铃字符(也可以键入 \007)
\d "Wed Sep 06" 格式的日期
\e ASCII 转义字符(也可以键入 \033)
\h 主机名的第一部分(如 "mybox")
\H 主机的全称(如 "mybox.mydomain.com")
\j 在此 shell 中通过按 ^Z 挂起的进程数
\l 此 shell 的终端设备名(如 "ttyp4")
\n 换行符
\r 回车符
\s shell 的名称(如 "bash")
\t 24 小时制时间(如 "23:01:01")
\T 12 小时制时间(如 "11:01:01")
\@ 带有 am/pm 的 12 小时制时间
\u 用户名
\v bash 的版本(如 2.04)
\V Bash 版本(包括补丁级别) ?/td>
\w 当前工作目录(如 "/home/drobbins")
\W 当前工作目录的“基名 (basename)”(如 "drobbins")
\! 当前命令在历史缓冲区中的位置
\# 命令编号(只要您键入内容,它就会在每次提示时累加)
\$ 如果您不是超级用户 (root),则插入一个 "$";如果您是超级用户,则显示一个 "#"
\xxx 插入一个用三位数 xxx(用零代替未使用的数字,如 "\007")表示的 ASCII 字符
\\ 反斜杠
\[ 这个序列应该出现在不移动光标的字符序列(如颜色转义序列)之前。它使 bash 能够正确计算自动换行。
\] 这个序列应该出现在非打印字符序列之后。
终端的颜色控制
我们看到很多 \e[ 这样的东西,事实上这个叫做 ANSI 控制码,在 Linux 和 Windows 的命令行里面都是通用的,\e 是 Escape 键的键码,\e[ 是一切 ANSI 控制码的开头。首先来到 \e[1;30m 这个控制码,这表示设置这个符号之后的字符为黑色,而 \e[0m 则是清除所有格式.
具体的颜色及其它控制列表 可以看:http://en.wikipedia.org/wiki/ANSI_escape_code#graphics

PS: PS1 也可以改成一下形式, 在程序出错时, 能有高亮提示: 

PS1='`a=$?;if [ $a -ne 0 ]; then a="  "$a; echo -ne "\[\e[s\e[1A\e[$((COLUMNS-2))G\e[33m\e[1;41m${a:(-3)}\e[u\]\[\e[0m\e[47m\e[2m\]"; fi`\[\e[1;30m\]\u:\[\e[36m\]\w\[\e[32m\]\$\[\e[0m\]' 

具体可见 WowUbuntu


ref:
http://blogold.chinaunix.net/u/27543/showart_255624.html
http://blog.donews.com/badcoffee/archive/2005/04/08/327553.aspx
http://wowubuntu.com/bash-prompt.html?utm_campaign=twitter&utm_medium=twitter&utm_source=twitter
http://en.wikipedia.org/wiki/ANSI_escape_code#graphics

[转载]Linux Kernel -- miscdev

http://nano-chicken.blogspot.com/2009/12/linux-modules6-miscdev.html
有時候我們需要寫一些"小的驅動程式",而早期的UNIX/Linux需要註冊major/minor number,即便可能只需要1個minor number,往往卻佔住major number底下的所有minor number,於是在Linux 2.0有了miscellaneous character drivers的誕生,misc driver使用major number 10,然後使用者如果需要這樣的"小驅動程式",便可以指明minor number即可。

使用misc device必須include <linux/miscdevice.h>,裡面包含了許多的官方的minor number,您可以挑選您適合的minor number,裡面也包含了兩個API,misc_register()/misc_deregister()。
一般您只要填好struct miscdevice的內容,再使用misc_register()進行註冊,或者使用misc_deregister()進行移除即可。
struct miscdevice  {
 int minor;
 const char *name;
 const struct file_operations *fops;
 struct list_head list;
 struct device *parent;
 struct device *this_device;
 const char *devnode;
};
minor:就是您要註冊的minor number。
name:device的name。
fops:file operations。
其他的就不用理會了。

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
MODULE_LICENSE("GPL");

#define DEV_BUFSIZE 1024

static int dev_open(struct inode*, struct file*);
static int dev_release(struct inode*, struct file*);
static ssize_t dev_read(struct file*, char __user*, size_t, loff_t*);
static ssize_t dev_write(struct file*, const char __user *, size_t, loff_t*);
static void __exit exit_modules(void);

static struct file_operations dev_fops = {
    .owner = THIS_MODULE,
    .open = dev_open,
    .release = dev_release,
    .read = dev_read,
    .write = dev_write,
};

static struct miscdevice brook_miscdev = {
    .minor      = 11,
    .name       = "brook_dev",
    .fops       = &dev_fops,
};

static int
dev_open(struct inode *inode, struct file *filp)
{
    printk("%s():\n", __FUNCTION__);
    return 0;
}

static int
dev_release(struct inode *inode, struct file *filp)
{
    printk("%s():\n", __FUNCTION__);
    return 0;
}

static ssize_t
dev_read(struct file *filp, char __user *buf, size_t count, loff_t *pos)
{
    printk("%s():\n", __FUNCTION__);
    *pos = 0;
    return 0;
}

static ssize_t
dev_write(struct file *filp, const char __user *buf,
        size_t count, loff_t *pos)
{
    printk("%s():\n", __FUNCTION__);
    return count;
}

static int __init init_modules(void)
{
    int ret;

    ret = misc_register(&brook_miscdev);
    if (ret != 0) {
        printk("cannot register miscdev on minor=11 (err=%d)\n",ret);
    }

    return 0;
}

static void __exit exit_modules(void)
{
    misc_deregister(&brook_miscdev);
}

module_init(init_modules);
module_exit(exit_modules);