linux初探

首页

应用服务器

Linux技巧

中文文档

Linux初级

服务器源代码

命令详解

Linux技术应用

Linux安全应用

Linux业界新闻

UniX技术文章

Linux编程与内核

Linux数据库

Linux服务器

Linux安装指导

Linux论坛


首页>>Linux安全应用>>

热门文章

·利用135端口漏洞入侵个人电脑
·网吧频繁掉线(ARP)与解决方
·新手学堂:防火墙在网络中的
·害怕受网络攻击 英国公民干脆
·知己知彼:IEXPLORE命令行参
·保护个人隐私 隐藏在图片背后
·顶尖网络高手写的alexa作弊完
·国庆期间有45万余台计算机感
·病毒门诊:清除猖狂的Sxs.ex
·电脑用户须知 忘记分级审查密

推荐文章

Linux下配置Gnome的文件打开方式&开始菜单管理


和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的结构

[Default Applications]
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=http://www.itjj.net/tech/OS/Linux/2007-02-23/vim.desktop
text/x-csrc=http://www.itjj.net/tech/OS/Linux/2007-02-23/vim.desktop
text/x-dtd=http://www.itjj.net/tech/OS/Linux/2007-02-23/vim.desktop
text/x-java=http://www.itjj.net/tech/OS/Linux/2007-02-23/vim.desktop
text/mathml=http://www.itjj.net/tech/OS/Linux/2007-02-23/vim.desktop
text/x-python=http://www.itjj.net/tech/OS/Linux/2007-02-23/vim.desktop
text/x-sql=http://www.itjj.net/tech/OS/Linux/2007-02-23/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 打开方式默认为http://www.itjj.net/tech/OS/Linux/2007-02-23/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文件的结构

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


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



附录:Desktop项的结构

原文的URL是 

http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-0.9.4.html

Introduction

Both the KDE and GNOME desktop environments have adopted a similar format for "desktop entries", or configuration files describing how a particular program is to be launched, how it appears in menus, etc. It is to the larger community's benefit that a unified standard be agreed upon by all parties such that interoperation between the two environments, and indeed any additional environments that implement the specification, becomes simpler.

Basic format of the file

These desktop entry files should have the extension .desktop. Determining file type on basis of extension makes determining the file type very easy and quick. When no file extension is present, the desktop system should fall back to recognition via "magic detection". Desktop entries which describe how a directory is to be formatted/displayed should be simply called .directory.

The basic format of the desktop entry file requires that there be a "group" header named [Desktop Entry]. This "group" entry denotes that all {key,value} pairs following it belong in the Desktop Entry group. There may be other groups present in the file, but this is the most important group which explicitly needs to be supported. This group should also be used as the "magic key" for automatic MIME type detection. There should be nothing proceeding this group in the desktop entry file but possibly one or more comments (see below).

Group headers may not contain the characters [ and ] as those delimit the header.

Lines beginning with a # and blank lines are considered comments and will be ignored, however they should be preserved across reads and writes of the desktop entry file.

Compliant implementations MUST not remove any fields from the file, even if they don't support them. Such fields must be maintained in a list somewhere, and if the file is "rewritten", they will be included. This ensures that any desktop-specific extensions will be preserved even if another system accesses and changes the file.

Entries in the file are {key,value} pairs in the format:

Key=Value

Space before and after the equals sign should be ignored; the = sign is the actual delimiter.

The escape sequences /s, /n, /t, /r, and // are supported, meaning ASCII space, newline, tab, carriage return, and backslash, respectively.

Possible value types

The value types recognized are string, localestring, regexp, boolean (encoded as the string true/false), and numeric.

Values of type string must contain only ASCII characters excluding control characters. Values of type localestring are user displayable, and are encoded in UTF-8 unless the Legacy-Mixed Encoding is specified (see Appendix D, The Legacy-Mixed Encoding (Deprecated).)

Some keys can have multiple values; these should be separated by a semicolon. Those keys which have several values should have a semicolon as the trailing character. Semicolons in these values need to be escaped using /;.

Recognized desktop entry keys

Keys with type localestring may be postfixed by [LOCALE], where LOCALE is the locale type of the entry. LOCALE must be of the form lang_COUNTRY.ENCODING@MODIFIER, where _COUNTRY, .ENCODING, and @MODIFIER may be omitted. If a postfixed key occurs, the same key must be also present without the postfix.

When reading in the desktop entry file, the value of the key is selected by matching the current POSIX locale for the LC_MESSAGES category against the LOCALE postfixes of all occurrences of the key, with the .ENCODING part stripped. The .ENCODING field is used only when the value of the Encoding key for the desktop entry file is Legacy-Mixed (see Appendix D, The Legacy-Mixed Encoding (Deprecated).)

The matching of is done as follows. If LC_MESSAGES is of the form lang_COUNTRY.ENCODING@MODIFIER, then it will match a key of the form lang_COUNTRY@MODIFIER. If such a key does not exist, it will attempt to match lang_COUNTRY followed by lang@MODIFIER. Then, a match against lang by itself will be attempted. Finally, if no matching key is found the required key without a locale specified is used. The encoding from the LC_MESSAGES value is ignored when matching.

If LC_MESSAGES does not have a MODIFIER field, then no key with a modifier will be matched. Similarly, if LC_MESSAGES does not have a COUNTRY field, then no key with a country specified will be matched. If LC_MESSAGES just has a lang field, then it will do a straight match to a key with a similar value. The following table lists possible matches of various LC_MESSAGES values in the order in which they are matched. Note that the ENCODING field isn't shown.

Table 1. Locale Matching

LC_MESSAGES valuePossible keys in order of matching
lang_COUNTRY@MODIFIERlang_COUNTRY@MODIFIER, lang_COUNTRY, lang@MODIFIER, lang, default value
lang_COUNTRYlang_COUNTRY, lang, default value
lang@MODIFIERlang@MODIFIER, lang, default value
langlang, default value

For example, if the current value of the LC_MESSAGES category is sr_YU@Latn and the desktop file includes:

 Name=Foo
Name[sr_YU]=...
Name[sr@Latn]=...
Name[sr]=...

then the value of the Name keyed by sr_YU is used.

Case is significant. The keys Name and NAME are not equivalent. The same holds for group names. Key values are case sensitive as well.

Keys are either OPTIONAL or REQUIRED. If a key is optional it may or may not be present in the file. However, if it isn't, the implementation of the standard should not blow up, it must provide some sane defaults. Additionally, keys either MUST or MAY be supported by a particular implementation.

Some keys only make sense in the context when another particular key is also present.

Some example keys: Name[C], Comment[it].

Table 2. Standard Keys

KeyDescriptionValue TypeREQ?MUST?Type
TypeThere are 4 types of desktop entries: Application, Link, FSDevice and Directory. stringYESYES
VersionVersion of Desktop Entry Specification (While the version field is not required to be present, it should be in all newer implementations of the Desktop Entry Specification. If the version number is not present, a "pre-standard" desktop entry file is to be assumed). numericNOYES1-4
EncodingEncoding of the whole desktop entry file (UTF-8 or Legacy-Mixed). stringYESYES1-4
NameSpecific name of the application, for example "Mozilla". localestringYESYES1-4
GenericNameGeneric name of the application, for example "Web Browser". localestringNOYES1-4
NoDisplayNoDisplay means "this application exists, but don't display it in the menus". This can be useful to e.g. associate this application with MIME types, so that it gets launched from a file manager (or other apps), without having a menu entry for it (there are tons of good reasons for this, including e.g. the netscape -remote, or kfmclient openURL kind of stuff). booleanNONO1-4
CommentTooltip for the entry, for example "View sites on the Internet", should not be redundant with Name or GenericName. localestringNOYES1-4
IconIcon to display in file manager, menus, etc. If the name is an absolute path, the given file will be used. If the name is not an absolute path, an implementation-dependent search algorithm will be used to locate the icon. Icons may be localized with the Icon[xx]= syntax. stringNOYES1-4
HiddenHidden should have been called Deleted. It means the user deleted (at his level) something that was present (at an upper level, e.g. in the system dirs). It's strictly equivalent to the .desktop file not existing at all, as far as that user is concerned. This can also be used to "uninstall" existing files (e.g. due to a renaming) - by letting make install install a file with Hidden=true in it. booleanNONO1-4
FilePatternA list of regular expressions to match against for a file manager to determine if this entry's icon should be displayed. Usually simply the name of the main executable and friends. regexp(s)NONO1
TryExecFile name of a binary on disk used to determine if the program is actually installed. If not, entry may not show in menus, etc. stringNONO1
ExecProgram to execute, possibly with arguments. stringNOYES1
PathIf entry is of type Application, the working directory to run the program in. stringNOYES1
TerminalWhether the program runs in a terminal window. booleanNOYES1
SwallowTitleIf entry is swallowed onto the panel, this should be the title of the window. localestringNONO1
SwallowExecProgram to exec if swallowed app is clicked. stringNONO1
ActionsAdditional actions possible, see MIME type discussion in the section called “Registering MIME Types”. string(s)NOYES1
MimeTypeThe MIME type(s) supported by this entry. strings(s)NONO1
SortOrderThis may specify the order in which to display files. string(s)NONO4
DevThe device to mount. stringNONO3
FSTypeThe type of file system to try to mount. stringNONO3
MountPointThe mount point of the device in question. stringNONO3
ReadOnlySpecifies whether or not the device is read only. booleanNONO3
UnmountIconIcon to display when device is not mounted. Mounted devices display icon from the Icon key. UnmountIcons may be localized with the UnmountIcon[xx]= syntax. stringNONO3
URLIf entry is Link type, the URL to access. stringNOYES2
CategoriesCategories in which the entry should be shown in a menu (for possible values see the Desktop Menu Specification). string(s)NONO1
OnlyShowIn, NotShowInA list of strings identifying the environments that should display/not display a given desktop entry. Only one of these keys, either OnlyShowIn or NotShowIn, may appear in a group (for possible values see the Desktop Menu Specification). string(s)NONO1-4
StartupNotifyIf true, it is KNOWN that the application will send a "remove" message when started with the DESKTOP_LAUNCH_ID environment variable set (see the Startup Notification Protocol Specification for more details). booleanNONO1
StartupWMClassIf true, it is KNOWN that the application will map at least one window with the given string as its WM class or WM name hint (see the Startup Notification Protocol Specification for more details). stringNONO1

Character set encoding of the file

Desktop entry files are encoded as lines of 8-bit characters separated by LF characters.

  • Key names must contain only the characters A-Za-z0-9-

  • Group names may contain all ASCII characters except for [ and ] and control characters.

  • Values of type string may contain all ASCII characters except for control characters.

  • Values of type boolean must either be the string true or false.

  • Numeric values must be a valid floating point number as recognized by the %f specifier for scanf.

Comment lines are uninterpreted and may contain any character (except for LF). However, using UTF-8 for comment lines that contain characters not in ASCII is encouraged.

The encoding for values of type localestring is determined by the Encoding field.

List of valid Exec parameter variables

Each Exec field may take a number of arguments which will be expanded by the file manager or program launcher and passed to the program if necessary.

Literal % characters must be escaped as %%, and adding new format characters is not allowed. It's a fatal error to have an Exec field with a format character not given in the spec (exception to this are the deprecated format characters which can be ignored, that is expanded to no parameters, by the implementation). Again for emphasis: nonstandard extensions are not allowed here - you must add an X-Foo-Exec field if you have nonstandard Exec lines.

The escaping of the exec parameters is done in the way the mailcap specification describes. Take a look at RFC 1524 for more information.

Recognized fields are as follows:

%fA single file name, even if multiple files are selected. The system reading the desktop entry should recognize that the program in question cannot handle multiple file arguments, and it should should probably spawn and execute multiple copies of a program for each selected file if the program is not able to handle additional file arguments. If files are not on the local file system (i.e. are on HTTP or FTP locations), the files will be copied to the local file system and %f will be expanded to point at the temporary file. Used for programs that do not understand the URL syntax.
%FA list of files. Use for apps that can open several local files at once.
%uA single URL.
%UA list of URLs.
%dDirectory containing the file that would be passed in a %f field.
%DList of directories containing the files that would be passed in to a %F field.
%nA single filename (without path).
%NA list of filenames (without paths).
%iThe Icon field of the desktop entry expanded as two parameters, first --icon and then the contents of the Icon field. Should not expand as any parameters if the Icon field is empty or missing.
%cThe translated Name field associated with the desktop entry.
%kThe location of the desktop file as either a URI (if for example gotten from the vfolder system) or a local filename or empty if no location is known.
%vThe name of the Device entry in the desktop file.

Registering MIME Types

The MimeType key is used to indicate the MIME Types that an application knows how to handle. Applications that can handle multiple MIME Types would list all of the ones it can handle in a ';' separated list, as normal. It is expected that for some applications this list could become long. An application is expected to be able to reasonably open files of these types using the command listed in the Exec keyword.

There should be no priority for MIME Types in this field, or any form of priority in the desktop file. Priority for applications is handled external to the .desktop files.

Caching MIME Types

To make parsing of all the desktop files less costly, a update-desktop-database program is provided that will generate a cache file. The concept is identical to that of the 'update-mime-database' program in that it lets applications avoid reading in (potentially) hundreds of files. It will need to be run after every desktop file is installed. One cache file is created for every directory in $XDG_DATA_DIRS/applications/, and will create a file called $XDG_DATA_DIRS/applications/mimeinfo.cache.

The format of the cache is similar to that of the desktop file, and is just a list mapping mime-types to desktop files. Here's a quick example of what it would look like:

application/x-foo=foo.desktop;bar.desktop;
application/x-bar=bar.desktop;

Each MIME Type is listed only once per cache file, and the desktop-id is expected to exist in that particular directory. That is to say, if the cache file is located at /usr/share/applications/mimeinfo.cache, bar.desktop refers to the file /usr/share/applications/bar.desktop.

Priority of MIME Types and desktop files

There is also a preference list to determine preferred application of a given MIME Type. It defines the 'default' application to handle a given MIME Type. It has the same format as the cache list.

mime/type=desktop-id.desktop;

If a mime type is listed multiple times (either in the same file, or in another file further down the search path), the latter mention wins. If a listed file doesn't exist, or is precluded through the OnlyShowIn or NotShowIn files, they should be ignored. This means that applications will have to keep a history of the preferred applications that they run into, so that if the top desktop file for a given MIME Type isn't available, the second one can be tested, etc.

It is also worth noting who this mechanism is defined for. It is primarily intended for use by distributors/sysadmins to provide a sane set of defaults for their users. Additionally, users themselves can use this mechanism to override the user defaults. We intentionally don't provide a way for application authors themselves to list themselves as the default for a given type, as we felt that that cannot work.

Extending the format

If the standard is to be amended with a new {key,value} pair which should be applicable to all supporting parties, a group discussion will take place. This is the preferred method for introducing changes. If one particular party wishes to add a field for personal use, they should prefix the key with the string X-PRODUCT, e.g. X-NewDesktop-Foo, following the precedent set by other IETF and RFC standards.

Alternatively, fields can be placed in their own group, where they may then have arbitrary key names. If this is the case, the group should follow the scheme outlined above, i.e. [X-PRODUCT GROUPNAME] or something similar. These steps will avoid namespace clashes between different yet similar environments.

A. Example Desktop Entry File

[Desktop Entry]
Version=1.0
Type=Application
Encoding=UTF-8
Name=Foo Viewer
Comment=The best viewer for Foo objects available!
TryExec=fooview
Exec=fooview %F
Icon=fooview.png
MimeType=image/x-foo
X-KDE-Library=libfooview
X-KDE-FactoryName=fooviewfactory
X-KDE-ServiceType=FooService

[Desktop Action Inverse]
Exec=fooview --inverse %f
Name=Foo Viewer (inverse image)

[Desktop Action Edit]
Exec=fooview --edit %f
Name=Foo Viewer (edit image)
Icon=fooview-edit.png

B. Currently reserved for use within KDE

During the time KDE added some extensions that are currently not prefixed by the X- prefix, but should be in future KDE releases.

  • Keys added by KDE: ServiceTypes, DocPath, Keywords, InitialPreference

  • Types added by KDE: ServiceType, Service

C. Deprecated Items

As this standard is quite old there are some deprecated items that may or may not be used by several implementations.

  • Type=MimeType is deprecated as there is a new standard for this now, see the Shared MIME-info Database specification for more information. In consequence the Keys Patterns (various file name extensions associated with the MIME type) and DefaultApp (the default application associated with this MIME type) are also deprecated.

  • Using .kdelnk instead of .desktop as the file extension is deprecated.

  • Using [KDE Desktop Entry] instead of [Desktop Entry] as header is deprecated.

  • Encoding=Legacy-Mixed, which allowed localestrings in the encoding of the specified locale, is deprecated.

  • Deprecated Exec parameters: %m (the mini-icon associated with the desktop entry, this should be expanded as two parameters, --miniicon and the content of the MiniIcon field, it can also be ignored by expanding it to no parameters).

  • Deprecated keys: MiniIcon (small icon for menus, etc), TerminalOptions (if the program runs in a terminal, any options that should be passed to the terminal emulator before actually executing the program), Protocols, Extensions, BinaryPattern, MapNotify.

  • Historically some booleans have been represented by the numeric entries 0 or 1. With this version of the standard they are now to be represented as a boolean string. However, if an implementation is reading a pre-1.0 desktop entry, it should interpret 0 and 1 as false and true, respectively.

  • Historically lists have been comma separated. This is inconsistent with other lists which are separated by a semicolon. When reading a pre-1.0 desktop entry, comma separated lists should continue to be supported.

D. The Legacy-Mixed Encoding (Deprecated)

The Legacy-Mixed encoding corresponds to the traditional encoding of desktop files in older versions of the GNOME and KDE desktop files. In this encoding, the encoding of each localestring key is determined by the locale tag for that key, if any. For keys without a locale tag, the value must contain only ASCII characters.

If the file specifies an unsupported encoding, the implementation should either ignore the file, or, if the user has requested a direct operation on the file (such as opening it for editing), display an appropriate error indication to the user.

In the absence of an Encoding line, the implementation may choose to autodetect the encoding of the file by using such factors as:

  • The location of the file on the file system

  • Whether the contents of the file are valid UTF-8

If the implementation does not perform such auto-detection, it should treat a file without an Encoding key in the same way as a file with an unsupported Encoding Key.

If the locale tag includes an .ENCODING part, then that determines the encoding for the line. Otherwise, the encoding is determined by the language, or lang_COUNTRY pair from the locale tag, according to the following table.

EncodingAliasesTags
ARMSCII-8 (*) hy
BIG5 zh_TW
CP1251 be bg
EUC-CNGB2312zh_CN
EUC-JP ja
EUC-KR ko
GEORGIAN-ACADEMY (*)  
GEORGIAN-PS (*) ka
ISO-8859-1 br ca da de en es eu fi fr gl it nl no pt sv wa
ISO-8859-2 cs hr hu pl ro sk sl sq sr
ISO-8859-3  eo
ISO-8859-5 mk sp
ISO-8859-7 el
ISO-8859-9 tr
ISO-8859-13 lt lv mi
ISO-8859-14 cy ga
ISO-8859-15 et
KOI8-R ru
KOI8-U uk
TCVN-5712 (*)TCVNvi
TIS-620 th
VISCII  
Encoding

The name given here is listed here is typically the canonical name for the encoding in the GNU C Library's iconv facility. Encodings marked with (*) are not currently supported by the GNU C Library; for this reason, implementations may choose to ignore lines in desktop files that resolve to this encoding. Desktop files with these encodings are currently rare or non-existent.

Aliases

Other names for the encoding found in existing desktop files.

Tags

Language tags for which this is the default encoding.

This table above covers all tags and encodings that are known to be currently in use. Implementors may choose to support encodings not in the above set. For tags without defaults listed in the above table, desktop file creators must specify the .ENCODING part of the locale tag.

Matching the .ENCODING part of the locale tag against a locale name or alias should be done by stripping all punctuation characters from both the tag and the name or alias, converting both name and alias to lowercase, and comparing the result. This is necessary because, for example, Big5 is frequently found instead of BIG5 and georgianacademy instead of GEORGIAN-ACADEMY. Desktop files creators should, however, use the name as it appears in the "Encoding" column above.


Linux联盟收集整理

相关文章:

·在虚拟机下体验ubuntu
·将eva启动项添加到gnome环境的菜单中
·Ubuntu分辨率的设置
·grub的用法
·linux怎么给一个普通用户reboot权限
·linux启动服务功能介绍
·Linux 的带宽管理系统
·Debian命令总结
·RoseHA(for Solaris)快速安装指引

Copyright@2005 www.linuxGoo.com All Right Reserved