rhythmbox插件开发笔记3:安装 makefile && schema && po

 本篇主要讲通过makefile方式来安装rhythmbox插件的相关知识。


makefile


如果makefile是什么,请自行谷歌

参考了pandasunny同学的rhythmbox-baidu-music,如有冒犯请指出

 1 SCHEMAS_DIR=$(DESTDIR)/usr/share/glib-2.0/schemas
 2 PLUGIN_DIR=$(DESTDIR)/usr/lib/rhythmbox/plugins/xiami
 3 PLUGIN_DATA_DIR=$(DESTDIR)/usr/share/rhythmbox/plugins/xiami
 4 PLUGIN_USER_DIR=$(HOME)/.local/share/rhythmbox/plugins/xiami
 5 PLUGIN_LOCALE_DIR=$(DESTDIR)/usr/share/locale
 6 
 7 clear:
 8     rm -f *.py[co] */*.py[co]
 9 install: install-po schemas
10     mkdir -p $(PLUGIN_DIR)
11     mkdir -p $(PLUGIN_DATA_DIR)
12     cp -r *.py baidu-music.plugin $(PLUGIN_DIR)
13     cp -r *.ui popup-ui.xml images $(PLUGIN_DATA_DIR)
14 install-local: install-po schemas
15     mkdir -p $(PLUGIN_USER_DIR)
16     cp -r *.py *.ui popup-ui.xml xiami.plugin images $(PLUGIN_USER_DIR)
17 uninstall:
18     rm -rf $(PLUGIN_DIR)
19     rm -rf $(PLUGIN_DATA_DIR)
20     rm -rf $(PLUGIN_USER_DIR)
21     rm -f $(SCHEMAS_DIR)/org.gnome.rhythmbox.plugins.xiami.gschema.xml
22     glib-compile-schemas $(SCHEMAS_DIR)
23     for i in ./po/*.po; do 
24         lang=`basename $$i .po`; 
25         rm -f $(PLUGIN_LOCALE_DIR)/$$lang/LC_MESSAGES/rhythmbox-xiami.mo; 
26     done
27 install-po:
28     for i in ./po/*.po; do 
29         lang=`basename $$i .po`; 
30         msgfmt -c ./po/$$lang.po -o ./po/$$lang.mo; 
31         mkdir -p $(PLUGIN_LOCALE_DIR)/$$lang/LC_MESSAGES; 
32         mv ./po/$$lang.mo $(PLUGIN_LOCALE_DIR)/$$lang/LC_MESSAGES/rhythmbox-xiami.mo; 
33     done
34     rm -f ./po/*.mo
35 schemas:
36     if [ ! -d $(SCHEMAS_DIR) ]; then 
37         mkdir -p $(SCHEMAS_DIR); 
38     fi
39     cp org.gnome.rhythmbox.plugins.xiami.gschema.xml $(SCHEMAS_DIR)
40     glib-compile-schemas $(SCHEMAS_DIR)

schema


 由于编写插件的过程中需要处理一些设定文件,所以用到了

self.setting = Gio.Settings("org.gnome.rhythmbox.plugins.xiami")

Gio.Settings 实际上是封装了GTK 3的GSettings。它将需要的设定存到后缀名为gschema.xml的schema文件中。

下面给出schema文件的例子

 1 <schemalist>
 2     <schema id="org.gnome.rhythmbox.plugins.xiami" path="/org/gnome/rhythmbox/plugins/xiami/">
 3         <key name="username" type="s">
 4             <default>''</default>
 5             <summary>Username</summary>
 6             <description>The username of xiami account.</description>
 7         </key>
 8         <key name="password" type="s">
 9             <default>''</default>
10             <summary>Password</summary>
11             <description>The password of xiami account.</description>
12         </key>
13         <key name="lyric-path" type="s">
14             <default>'~/.lyrics/'</default>
15             <summary>Lyric dir</summary>
16             <description>The dir of lyrics</description>
17         </key>
18         <child name="source" schema="org.gnome.rhythmbox.source"/>
19     </schema>
20 </schemalist>

 要想能在GSettings中能使用这个文件,还需要两步(如MakeFIle的39行和40行所示):

1将这个文件拷贝到文件夹/usr/share/glib-2.0/schemas/

2用glib-compile-schemas编译这个文件夹。

参考了下面两篇文章:

http://www.micahcarrick.com/gsettings-python-gnome-3.html

http://lazka.github.io/pgi-docs/Gio-2.0/classes/Settings.html


po

对mo,po的解释这篇文章讲的很好,就不赘述了。MakeFile的27-34行描述了对mo,po文件的具体操作。


下一篇将详细介绍通过插件自定义rhythmbox界面的具体方法。

原文地址:https://www.cnblogs.com/s0-0s/p/3874287.html