Archive:KDE System Administration/Configuration Files (zh TW): Difference between revisions

From KDE TechBase
No edit summary
No edit summary
Line 1: Line 1:
{{Template:I18n/Language Navigation Bar|KDE System Administration/Configuration Files}}
{{Template:I18n/Language Navigation Bar_(zh_TW)|KDE System Administration/Configuration Files}}
== 檔案格式 ==
== 檔案格式 ==
KDE 在它所有的配置檔都使用基於純文字的檔案格式。這種檔案包含由多項關鍵字與值(key-value)相配組合成的組(group)。所有的 KDE 配置檔使用 UTF-8 編碼,而不用 ASCII。
KDE 在它所有的配置檔都使用基於純文字的檔案格式。這種檔案包含由多項關鍵字與值(key-value)相配組合成的組(group)。所有的 KDE 配置檔使用 UTF-8 編碼,而不用 ASCII。
Line 64: Line 64:
== Shell 擴展 ==
== Shell 擴展 ==


So called ''Shell Expansion'' can be used to provide more dynamic default
之所以稱作''Shell 擴展'',是因為這種技術能夠用於提供更多動態的預設值。透過 shell 擴展,你能夠從環境變數或 shell 指令輸出的值來構建配置檔中關鍵字的值。
values. With shell expansion the value of a configuration key can be
constructed from the value of an environment variable or from the output of
a shell command.


To enable shell expansion for a configuration entry, the key must be followed
要想把 Shell 擴展使用在配置項目,關鍵字後必須緊跟 <tt>[$e]</tt>。一般情況下,擴展部分在第一次使用後,會寫入使用者配置檔。為了避免這種情況發生,我們推薦使用 <tt>[$ie]</tt> 來鎖定相應的配置項目。
by <tt>[$e]</tt>. Normally the expanded form is written into the users
configuration file after first use. To prevent that, it is recommend to lock
the configuration entry down by using <tt>[$ie]</tt>.


==== 範例:動態項目 ====
==== 範例:動態項目 ====
In the following example the value for the "<tt>Host</tt>" entry
在接下來的例子,「<tt>Host</tt>」項目的值由 ''hostname'' 程式的輸出決定。這個設定同樣可以被鎖定,以確保該值始終是動態決定的。
is determined by the output of the ''hostname'' program. This setting is
also locked down to ensure that the value is always determined dynamically.


The value for the "<tt>Email</tt>" entry is determined by filling in
<tt>Email</tt>」項目是由 $USER $HOST 這兩個環境變數的值來決定的。當 ''joe'' 登錄到 ''joes_host'' 時,這將會使得該值等於「<tt>joe@joes_host</tt>」。這個設定是未被鎖定的。
the values of the $USER and $HOST environment variables. When ''joe''
is logged in on ''joes_host'' this will result in a value equal to
"<tt>joe@joes_host</tt>". The setting is not locked down.


<code ini>
<code ini>
Line 92: Line 81:
== 本地化 ==
== 本地化 ==


All configuration entries can be indexed with a language code. In this case,
所有的配置項目都能按照語言碼來加以標記。在這種情況下,桌面使用者選用的語言一般會查詢相應的關鍵字值。如果預設語言(美式英語)已被選用,或者沒有與所選語言相符合的標記,沒有加標記的關鍵字項目將被使用。
the language that the user has selected for use on the desktop is used to
 
look up the key value. If the default language (American English) has been
==== 範例:把 UTF-8 用在關鍵字 ====
selected or if there is no index that corresponds to the selected language,
在接下來的例子中,「<tt>Caption</tt>」項目的值依賴於所用的語言。如果使用者選用了法語(語言碼為<tt>fr</tt>),項目的值就將是「<tt>Ma Légende</tt>」,在其餘的情況下將使用「<tt>My Caption</tt>」值。
the key entry without index is used.


==== 範例:UTF8 In Keys ====
In the following example the value of the "<tt>Caption</tt>" entry
depends on the language. If the user has selected french as language (language
code <tt>fr</tt>) the value of the entry will be "<tt>Ma Légende</tt>".
In all other cases the value "<tt>My Caption</tt>" will be used.
<code ini>
<code ini>
[Preview Image]
[Preview Image]
Line 111: Line 94:
== 鎖定 ==
== 鎖定 ==


To prevent users from overriding default settings, you can lock
為了避免使用者複寫預設設定,你可以對全系統配置檔的設定進行鎖定。無論是每個組,還是每個檔,設定都能夠單獨地鎖定。一個單獨的項目能夠透過在關鍵字後加入 <tt>[$i]</tt> 來加以鎖定。一組中的項目也同樣能夠透過在組的名字後面放置 <tt>[$i]</tt> 來加以鎖定。想要鎖定整個項目檔,在這個檔案的開頭加入 <tt>[$i]</tt> 成獨立的一行。
these settings down in the system-wide config files. Settings can be locked down individually, per group,
 
or per file. An individual entry can be locked down by adding <tt>[$i]</tt>
==== 範例:使用 [$i] ====
behind the key. A group of entries can be locked down by placing
在接下來的例子中,「<tt>Caption</tt>」項目已經被鎖定。所有在「<tt>Mail Settings</tt>」組中的項目同樣也已經被鎖定。
<tt>[$i]</tt> behind the group name. To lock down the entire file, start
the file with <tt>[$i]</tt> on a single line.


==== 範例:Using [$i] ====
In the following example the "<tt>Caption</tt>" entry has been locked
down. All entries in the "<tt>Mail Settings</tt>" group have been
locked down as well.
<code>
<code>
[Preview Image]
[Preview Image]
Line 131: Line 108:
</code>
</code>


If an entry has been locked down, entries that would otherwise take
如果一個項目已經被鎖定,那麼其他優先於預設設定的項目將被忽略。
precedence over the default setting will now be ignored.


Any changes that applications make to settings that have been locked
Any changes that applications make to settings that have been locked
Line 146: Line 122:


== 編輯器 ==
== 編輯器 ==
如果你不願意使用文字編輯器的話,那麼 [http://extragear.kde.org/apps/kconfigeditor/ KConfigEditor] 提供了一種編輯 KDE 配置檔的方便方法。
如果你不願意使用文字編輯器的話,那麼 [http://extragear.kde.org/apps/kconfigeditor/ KConfigEditor] 提供了一種編輯 KDE 配置檔的便利方法。


要想在命令列中進行腳本設計或修改檔案,命令列應用程式 <tt>kwriteconfig</tt> 是非常有用的。<tt>kwriteconfig</tt> 可以同時建立一個配置檔名、一個組、一個關鍵字、一個可選的類型和一個值,例如:
要想在命令列中進行腳本設計或修改檔案,命令列程式 <tt>kwriteconfig</tt> 是非常有用的。<tt>kwriteconfig</tt> 可以同時建立一個配置檔名、一個組、一個關鍵字、一個可選的類型和一個值,例如:


<code>kwriteconfig --file kickerrc \
<code>kwriteconfig --file kickerrc \

Revision as of 10:41, 20 March 2010

Template:I18n/Language Navigation Bar (zh TW)

檔案格式

KDE 在它所有的配置檔都使用基於純文字的檔案格式。這種檔案包含由多項關鍵字與值(key-value)相配組合成的組(group)。所有的 KDE 配置檔使用 UTF-8 編碼,而不用 ASCII。

每組的開始處是由放置在中括號內的組名標示。所有放置在開始標籤後的關鍵字與值項目皆屬於該組。每個組結束於下一組的開始標籤或設定檔的結尾。

在檔案最上面的第一個項,不會作為預設的組被優先處理。

範例:一份簡單的配置檔

以下的範例展示了一個包含兩個組的配置檔。第一組包含了關鍵字「LargeCursor」和「SingleClick」,第二組包含了關鍵字「Show hidden files」和「Sort by」。 [KDE] LargeCursor=false SingleClick=true

[KFileDialog Settings] Show hidden files=false Sort by=Name

在組中的每個項目都是使用「關鍵字=值」的格式。關鍵字能夠包含空格,也可在其後加上放置於中括號內的選項。

等號後面的部分是每個項目的值。所有在等號周圍和項目末端的空格都將被忽略。

如果一個值需要包含一個空格在它的開始或結尾,這種情況可以用反斜線加 s 來代替。

有許多其他這樣的反斜線替代碼,以下是完整列表:

  • \s」 能夠被當作空格使用
  • \t」 能夠被當作 tab 使用
  • \r」 表示 return 符號
  • \n」 表示換行符號(新增一行)
  • \\」 表示反斜線本身

範例:空白

下面的配置檔片段相當於與上一個範例。關鍵字與值周圍的空白將被忽略。 [KDE] LargeCursor= false SingleClick = true

[KFileDialog Settings]

  Show hidden files   = false

Sort by =Name

範例:保留空白

在接下來的例子中「Caption」項的值以兩個空格開始,同時「Description」項包含三行文字。反斜線標記的換行符號(\n)用於分割不同行。 [Preview Image] Caption=\s My Caption Description=This is\na very long\ndescription.

配置檔中的空行將被忽略,就像對待井字「#」開始的行一樣。井字用於在配置檔中加上註釋,但是需要注意當 KDE 應用程式更新配置檔時,這些註釋將不被保留。

配置

在許多 [[../KDE Filesystem Hierarchy#Location_of_the_Directory_Trees|KDE 目錄樹]]的 share/config 子目錄下可以有多個同名的配置檔。在這種情況下,所有這些配置檔中的資訊將逐條項地合併在一起。如果某個組內同一個關鍵字不止在一個地方被定義過,將使用最高優先權目錄樹下的關鍵字值。在 $KDEHOME 下的配置檔擁有最高優先權。如果某個組中的某個關鍵字在同一個檔中被定義了多次,那麼最後出現的值將被採用。

KDE 的級聯配置方案提供使用者在系統或整個組織預設設定的基礎上,對某些個別設定進行修改。KDE 不會為了符合系統的預設設定,覆寫 $KDEHOME 下的使用者配置檔項目。這樣使得預設設定的修改可以立即傳播給所有使用者。注意,不同於傳統透過 /etc/skel 來為使用者提供預設設定,修改 /etc/skel 只能套用於建立新的使用者帳戶時。

當管理員不希望預設設定被個別使用者隨意修改時,可以鎖定預設設定。

Shell 擴展

之所以稱作Shell 擴展,是因為這種技術能夠用於提供更多動態的預設值。透過 shell 擴展,你能夠從環境變數或 shell 指令輸出的值來構建配置檔中關鍵字的值。

要想把 Shell 擴展使用在配置項目,關鍵字後必須緊跟 [$e]。一般情況下,擴展部分在第一次使用後,會寫入使用者配置檔。為了避免這種情況發生,我們推薦使用 [$ie] 來鎖定相應的配置項目。

範例:動態項目

在接下來的例子,「Host」項目的值由 hostname 程式的輸出決定。這個設定同樣可以被鎖定,以確保該值始終是動態決定的。

Email」項目是由 $USER 和 $HOST 這兩個環境變數的值來決定的。當 joe 登錄到 joes_host 時,這將會使得該值等於「joe@joes_host」。這個設定是未被鎖定的。

[Mail Settings] Host[$ie]=$(hostname) Email[$e]=${USER}@${HOST}

本地化

所有的配置項目都能按照語言碼來加以標記。在這種情況下,桌面使用者選用的語言一般會查詢相應的關鍵字值。如果預設語言(美式英語)已被選用,或者沒有與所選語言相符合的標記,沒有加標記的關鍵字項目將被使用。

範例:把 UTF-8 用在關鍵字

在接下來的例子中,「Caption」項目的值依賴於所用的語言。如果使用者選用了法語(語言碼為fr),項目的值就將是「Ma Légende」,在其餘的情況下將使用「My Caption」值。

[Preview Image] Caption=My Caption Caption[fr]=Ma Légende

鎖定

為了避免使用者複寫預設設定,你可以對全系統配置檔的設定進行鎖定。無論是每個組,還是每個檔,設定都能夠單獨地鎖定。一個單獨的項目能夠透過在關鍵字後加入 [$i] 來加以鎖定。一組中的項目也同樣能夠透過在組的名字後面放置 [$i] 來加以鎖定。想要鎖定整個項目檔,在這個檔案的開頭加入 [$i] 成獨立的一行。

範例:使用 [$i]

在接下來的例子中,「Caption」項目已經被鎖定。所有在「Mail Settings」組中的項目同樣也已經被鎖定。

[Preview Image] Caption[$i]=My Caption

[Mail Settings][$i] Host[$e]=$(hostname) Email=waldo@kde.org

如果一個項目已經被鎖定,那麼其他優先於預設設定的項目將被忽略。

Any changes that applications make to settings that have been locked down will be silently dropped. Applications may respond differently to locked down settings. Some applications recognize when a setting has been locked down and will remove the elements from its user interface. Other applications will continue to offer these options in their user interface even though the option does not have any effect any more. It is also possible that it is actually still possible to change the setting in the running program. In that case the changed setting will be effective for the time the program remains running. When the program is restarted it will then return to the locked-down default settings.

編輯器

如果你不願意使用文字編輯器的話,那麼 KConfigEditor 提供了一種編輯 KDE 配置檔的便利方法。

要想在命令列中進行腳本設計或修改檔案,命令列程式 kwriteconfig 是非常有用的。kwriteconfig 可以同時建立一個配置檔名、一個組、一個關鍵字、一個可選的類型和一個值,例如:

kwriteconfig --file kickerrc \

            --group General \
            --key AutoHidePanel \
            --type bool \
            true