Lars Windolf's blog

Liferea Trick #8: Change Menu Accelerators

When you are not satisfied with the menu key bindings defined by Liferea do not despair it is easy to change them!

Variant #1: Edit ~/.config/liferea/accels

This variant is 100% portable and should work for everyone. Open ~/.config/liferea/accels in your favourite editor. This file is loaded upon startup by Liferea and contains lines like these:

; (gtk_accel_path "<Actions>/AddActions/NewVFolder" "")
; (gtk_accel_path "<Actions>/GeneralActions/SearchMenu" "")
; (gtk_accel_path "<Actions>/ItemActions/ToggleItemFlag" "<Primary>t")
; (gtk_accel_path "<Actions>/GeneralActions/PrevReadItem" "<Primary><Shift>n")

Note how only the "ToggleItemFlag" and the "PrevReadItem" line have defined key bindings, while "NewVFolder" and "SearchMenu" don't.

To change a key binding first remove the semicolon at the start of the line and then adapt or clear the key binding field. Choose prefixes like "<Primary>" (for Ctrl), "<Alt>", "$lt;Shift> as needed and append the key after it.

Variant #2: Enable Editable Accelerators with your Linux Distro Settings

This variant is hard to document as different distributions have different setting dialogs. Some expose a setting to enable life editing of key bindings. Once this is enabled you can open a menu hover over a menu option and press the accelerator you want to assign. It should show up instantly.

Recent Liferea Tricks

Debugging dovecot ACL Shared Mailboxes Not Showing in Thunderbird

When you can't get ACL shared mailboxes visible with Dovecot and Thunderbird here are some debugging tipps:

  1. Thunderbird fetches the ACLs on startup (and maybe at some other interval). So for testing restart Thunderbird on each change you make.
  2. Ensure the shared mailboxes index can be written. You probably have it configured like
    plugin {
      acl_shared_dict = file:/var/lib/dovecot/db/shared-mailboxes.db

    Check if such a file was created and is populated with new entries when you add ACLs from the mail client. As long as entries do not appear here, nothing can work.

  3. Enable debugging in the dovecot log or use the "debug" flag and check the ACLs for the user who should see a shared mailbox like this:
    doveadm acl debug -u [email protected] shared/users/box
    • Watch out for missing directories
    • Watch out for permission issues
    • Watch out for strangely created paths this could hint a misconfigured namespace prefix

Python re.sub Examples

Example for re.sub() usage in Python


import re

result = re.sub(pattern, repl, string, count=0, flags=0);

Simple Examples

num = re.sub(r'abc', '', input)              # Delete pattern abc
num = re.sub(r'abc', 'def', input)           # Replace pattern abc -> def
num = re.sub(r'\s+', '\s', input)            # Eliminate duplicate whitespaces
num = re.sub(r'abc(def)ghi', '\1', input)    # Replace a string with a part of itself

Advance Usage

Replacement Function

Instead of a replacement string you can provide a function performing dynamic replacements based on the match string like this:

def my_replace(m):
    if :
       return <replacement variant 1>
    return <replacement variant 2>

result = re.sub("\w+", my_replace, input)

Count Replacements

When you want to know how many replacements did happen use re.subn() instead:

result = re.sub(pattern, replacement, input)
print ('Result: ', result[0])
print ('Replacements: ', result[1])

Missing tray icon on Ubuntu-derived distributions

If you are a MATE desktop user using a Liferea 1.10.xx package installed from the official package repositories of your Linux distribution and since the switch from 1.8.xx the trayicon went missing then the reason is very probably that you are using a package build by Ubuntu for the Unity desktop that strips the trayicon support.

You can verify wether this is the case in the "Preferences" dialog which should look like this

If the trayicon option is not visible than the package doesn't support a trayicon.

This is known to be the case for at least Mint17.

PHP preg_replace() Examples

This post gives some simple examples for using regular expressions with preg_replace() in PHP scripts.

1. Syntax of preg_replace

While full syntax is

mixed preg_replace ( mixed $pattern , mixed 
$replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )

2. Simple Replacing with preg_replace()

$result = preg_replace('/abc/', 'def', $string);   # Replace all 'abc' with 'def'
$result = preg_replace('/abc/i', 'def', $string);  # Replace with case insensitive matching
$result = preg_replace('/\s+/', '', $string);      # Strip all whitespaces

3. Advanced Usage of preg_replace()

Multiple replacements:

$result = preg_replace(
    array('/pattern1/', '/pattern2/'),
    array('replace1', 'replace2'),

Replacement Back References:

$result = preg_replace('/abc(def)hij/', '/\\1/', $string);
$result = preg_replace('/abc(def)hij/', '/$1/', $string);
$result = preg_replace('/abc(def)hij/', '/${1}/', $string);

Do only a finite number of replacements:

# Perform maximum of 5 replacements
$result = preg_replace('/abc/', 'def', $string, -1, 5);

Multi-line replacement

# Strip HTML tag
$result = preg_replace('#.*#m', '', $string);

Writing Liferea Plugins Tutorial (Part 1)

Some time ago a fellow Liferea user asked about documentation on writing Liferea plugins. I see the need and the benefit and want to start doing so with a series of blog posts that later can be compiled into a tutorial to be included on the website/sources.

Plugins with GObject Introspection

First it is important to know that Liferea 1.10+ uses GObject Introspection (GI) and libpeas to allow implementing plugins. This quote from the GNOME wiki explain how GI works:

GObject introspection is a middleware layer between C libraries (using GObject) and language bindings. The C library can be scanned at compile time and generate a metadata file, in addition to the actual native C library. Then at runtime, language bindings can read this metadata and automatically provide bindings to call into the C library.

The important point is: by Liferea using GI (as all GNOME applications and many other GTK applications do now) plugins can be written in practically any scripting language. Most users seem to favour Python and all current plugins included with the Liferea sources are in Python. Note that this tutorial will also focus on Python only.

How are plugins triggered from with Liferea?

Ok, I can write a script in Python! How will Liferea run it and when?

This is where libpeas comes in, which is a basic library to implement a plugin system. If you click the preferences dialog and switch to the "Plugins" button you see a dialog provided by the PeasGtkPluginsManager class of libpeas. Detection, activation and configuration of plugins is handled by libpeas.

Now for the "When?" question: To properly allow applications to hook plugins into different parts of the applications libpeas allow an application to define one or more so called "Activatable" interfaces.

For simplicity for Liferea I decided to only support a LifereaShellActivatable interface. This means all plugins are activated together with the LifereaShell instance (src/ui/liferea_shell.c). This class represents the main application window holding all widgets. So when your plugin gets activated all widgets exist and you can access everything like extending or modifying the GUI, changing settings, everything you can think of.

Note: in the code there are two more interfaces:

  • LifereaAuthActivatable
  • LifereaMediaPlayerActivatable

that are used to implement two important features (GNOME keyring support and a simple media player). Feel free to use those two, but be aware that they work differently and activate at other times and not just once as the LifereaShellActivatable.

Using LifereaShellActivatable

If you script in Python using LifereaShellActivatable means simply deriving a new class from it. For example:

from gi.repository import GObject, Peas, PeasGtk, Gtk, Liferea, Gdk
class ExamplePlugin (GObject.Object, Liferea.ShellActivatable):
__gtype_name__ = 'ExamplePlugin'
object = (type=GObject.Object)
shell = (type=Liferea.Shell)
def do_activate (self):
# Do something here...
def do_deactivate (self):
# Maybe do somethin here too...

The activate() and deactivate() methods are required by libpeas and provide you with the starting points to do stuff. By fetching the "Liferea.Shell" instance you gain access to the main window. Using this you can both lookup widgets or other Liferea classes like the Liferea.FeedList to perform actions against business objects of Liferea.

Providing a plugin configuration

Along with the actual plugin code libpeas requires a plugin configuration file defining the language the plugin is implemented with and metadata (name, description, website...) for this plugin. Such a file looks like this:

Name=Example Plugin
Description=Illustrates how to implement plugins in Liferea
Authors=Lars Windolf 
Copyright=Copyright © 2014 Lars Windolf

Most important is the "Loader" setting indicating the correct scripting language and the "Module" setting which together with the "Loader" setting as "python" indicates that or plugin script is to be named "". Both the "" plugin script and it's "example.plugin" config file need to be put into the Liferea plugins directory...

Where to put my plugin script?

There are two possible locations for the plugin script (and it's configuration file):

  • For user provided plugins: usually ~/.config/liferea/plugins
  • For package provided plugins: usually /usr/lib/liferea/plugins

Note that paths can be different with different XDG settings.

When writing and testing don't bother installing the plugin in the package directories. Just put it in ~/.config/liferea/plugins, fire up Liferea.

More about how to check for activation, debug problems and handling enabling/disabling in the next installment of this tutorial!

Getting rid of Bash Ctrl+R

Today was a good day, as I stumbled over this post (at hinting on the following bash key bindings:

bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'

It changes the behaviour of the up and down cursor keys to not go blindly through the history but only through items matching the current prompt. Of course at the disadvantage of having to clear the line to go through the full history. But as this can be achieved by a Ctrl-C at any time it is still preferrable to Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R Ctrl+R ....

Liferea 1.10.12 Released

This is a new maintenance release.

The Changes:

	* Fixes Github #86: Support HTTP content negotiation
	  (suggested by DanMan)
	* Fixes Github #98:  Stop calling Atom person constructs w/ URI invalid
	  (patch by Aristotle Pagaltzis)
	* Fixes Github #100: Problems with dark Adwaita theme in GTK 3.14
	  (reported by majutsushi)


You can download the release on Github:

Liferea 1.11.1 Released

There is a new maintenance release for the unstable line: Liferea 1.11.1 with the following changes:

    * Fixes Github #81: Inability to add subscriptions
      (reported by GreenLunar)
    * Fixes Javascript links not opening in new browser tabs

    * Updated Hebrew translation (Genghis Khan)
    * Fixes Github #88: Minor DE translation mistake (moraxy)


You can download the release on Github:

Liferea 1.10.11 Released

This is a new maintenance release.

The Changes:

    * Fixes Github #53: Doesn't automatically update feed name and favicon
      for new feed (reported by asl97)
    * Fixes Github #67: Missing dist files for documentation
      (patch by Mikel Olasagasti)
    * Fixes Javascript links not opening in new browser tabs

    * Updated French translation (Guillaume Bernard)
    * Updated Hebrew translation (Genghis Khan)


You can download the release on Github:

Syndicate content