Pidgin 改名问题

碰到这个问题有一阵了,但一直没法准确地重现出来,今天终于试出来了,针对组名(Group)和带状态的伙伴(Buddy)或者联系人,以下以组作为一个例子,因为最容易。对于组来说,展开的时候只有组名,合并起来以后显示为“组名 (在线/全部)”。按以下步骤就会发生有趣的事情。

  1. 选择一个组
  2. 右键点击或者 F2(这个是新加的,也是我提交的,呵呵),进入编辑状态
  3. 按 ESC 或者切换焦点到其他程序
  4. 然后按回车或者空格,或者鼠标点击
  5. 组名就加上了括号

对于带状态的伙伴或者联系人,就会把状态也显示在编辑框里。这可不是我们所希望的。第三步完成以后,注意输入焦点(虚线框),上下左右动一动,会有一些新发现,当输入焦点在名字之上的时候,按回车或者空格,或者直接点击名字,就会进入修改状态。

然后开始研究这个问题,学习 [GTK+],看 GtkTreeViewGtkTreeViewColumnGtkCellRendererTextGtkCellRenderer 等的代码,总算弄明白了。Pidgin 是这么实现的,整个 Buddy List 的 TreeView 分两列,一列将其设置为不可见,并设置成 expander 一列。而第二列中,可以设置多个 Cell Renderer。[GTK+ 2.0 TreeView tutorial] 是一份非常好的指南,可以作为参考,当然,最好的参考还是代码。这几个 Cell Renderer 中包括 Group Expander、Contact Expander、Status Icon、名字、状态以及头像。

通常情况下,焦点一直在显示出来的第二列中,改名操作通过菜单在 gtk_blist_menu_alias_cb() 中进行处理,首先得到当前节点类型,是组的话拿到组名,并将组名设置在相应的 Tree Model 中。但是通过上述操作,焦点就在这一列内的各个 Cell Renderer 之见可以进行切换(使用左右键),对于组更明显一些。然后使用回车、空格或者单击激活名字,就直接可以对名字所对应的那个 Cell Renderer 进行编辑,而它是直接从 Tree Model 拿数据,在组合并的情况下,拿到的就是带括号的数据,相当于绕过了前面进行正确设置的步骤。

怎么解决呢?第一种办法是让用户根本进入不到第二列中的各个 Cell Renderer 中去,这个方法我还没研究出来,我觉得可能要连接到 GtkCellRenderer 的“editing-canceled”信号,然后把焦点拿过来,有空再试。还有一种方法就是可以让它编辑,在它编辑之前设置成正确的值,只要连接上   的“editing-started”信号,在里面把正确的值写进编辑框内就可以了。

另:在 [Pidgin Developer] 上开了个 [Ticket],并提交了补丁。

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • You can use BBCode tags in the text.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
   ____              _      _   _  __        __          __  __   _   _ 
/ ___| __ __ / \ | \ | | \ \ / / __ _ | \/ | | \ | |
| | _ \ \ / / / _ \ | \| | \ \ /\ / / / _` | | |\/| | | \| |
| |_| | \ V / / ___ \ | |\ | \ V V / | (_| | | | | | | |\ |
\____| \_/ /_/ \_\ |_| \_| \_/\_/ \__,_| |_| |_| |_| \_|
Enter the code depicted in ASCII art style.