Kwartik's Blog

March 30, 2011

Use your screensaver to display your favorite quotes !

Filed under: General — Tags: , , , , — kwartik @ 9:16 pm

Xscreensaver used to display quotes randomly Screenshot of my new screensaver

The “challenge” I faced was to configure my screensaver to display randomly my favorite quotes, and this in my Linux KDE4 based environment.Unfortunately none of the screensavers shipped with KDE4 provides this option. I was ready to develop my own screensaver when I realized that the xscreensaver project provides several screensavers designed to display text coming from the output of a custom command. Xscreensaver has the great advantage of not being distribution dependant as it is shipped on most Linux and Unix systems running the X11 Window System. The good news also was that the Mandriva distribution I use provides an xcreensaver rpm that once installed integrates the different screensavers shipped with xcreensavers directly in the KDE4 list of screensavers so there is no need to manually modify the X11 configuration.

So the remaining problem was to create a custom command to print randomly one of my favorite quotes. I first defined a simple XML format to save my quotes. Below an example of an XML file that I named quotes.xml and in which I saved two quotes to illustrate the concept:

<?xml version="1.0" encoding="UTF-8"?>


<quote id='orwell-01' category="literature" reference="George Orwell - Animal Farm - 1945">
Man is the only creature that consumes without producing. He does not give milk, he does not lay eggs, he is too weak to pull the plough, he cannot run fast enough to catch rabbits. Yet he is lord of all the animals. He sets them to work, he gives back to them the bare minimum that will prevent them from starving, and the rest he keeps for himself

<quote id='shakespeare-01' category="literature" reference="William Shakespeare - Hamlet - ~1600">
To be, or not to be, that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,
And by opposing end them? To die, to sleep,
No more; and by a sleep to say we end
The heart-ache, and the thousand natural shocks
That flesh is heir to: 'tis a consummation
Devoutly to be wished. To die, to sleep;
To sleep, perchance to dream – ay, there's the rub:
For in that sleep of death what dreams may come,
When we have shuffled off this mortal coil,
Must give us pause – there's the respect
That makes calamity of so long life.
For who would bear the whips and scorns of time,
The oppressor's wrong, the proud man's contumely,
The pangs of disprized love, the law’s delay,
The insolence of office, and the spurns
That patient merit of the unworthy takes,
When he himself might his quietus make
With a bare bodkin? Who would fardels bear,
To grunt and sweat under a weary life,
But that the dread of something after death,
The undiscovered country from whose bourn
No traveller returns, puzzles the will,
And makes us rather bear those ills we have
Than fly to others that we know not of?
Thus conscience does make cowards of us all,
And thus the native hue of resolution
Is sicklied o'er with the pale cast of thought,
And enterprises of great pith and moment,
With this regard their currents turn awry,
And lose the name of action. Soft you now,
The fair Ophelia! Nymph, in thy orisons
Be all my sins remembered.


Then I created a simple PERL script named gl that parses this XML file (it requires for this purpose the excellent XML::Twig perl module usually shipped with the perl-XML-Twig rpm), chooses randomly one quote and prints it to the standard output :


use strict;
use utf8;
use Encode qw(encode decode);
use Getopt::Long;
use XML::Twig; #PERL module usually shipped in the perl-XML-Twig rpms

#---------------- BEGINNING OF CONFIGURABLE SECTION -----------------------------#

my $xml_collection = '/home/kwartik/quotes.xml';

my $encoding='utf8';

#---------------- END OF CONFIGURABLE SECTION -----------------------------------#

    "c|collection=s" => \$xml_collection,
    "e|encoding=s"  => \$encoding,

if ( $xml_collection eq "" )
     "SYNTAX : gl [-c|--collection path_to_xml_collection] [-e|--encoding encoding]\n\n"
    ."encoding option examples : 'utf8' 'iso-8859-1'\n";
  exit 1;

(-f $xml_collection) or die ("Error: collection $xml_collection is not a file.\n");

my $nb_entries = 0;
my %hash_collection = ();

sub quote
    my( $twig, $item )= @_;
    my $id = $item->att('id');
    my $category  = $item->att('category');
    my $reference  = $item->att('reference');
    $hash_collection {$id} {'category'}  =  $category;
    $hash_collection {$id} {'reference'}  =  $reference;
    $hash_collection {$id} {'quote'}  =  $item->text;
    $nb_entries ++;

my $twig= new XML::Twig( twig_handlers => { 'quote' => \&quote }   );
$twig->parsefile( $xml_collection );

sub print_quote( $ )
	my $entry = $_[0];
    my $category = $hash_collection{$entry}{'category'};
    my $quote = $hash_collection{$entry}{'quote'};
    my $reference = $hash_collection{$entry}{'reference'};
    printf("%s (%s)\n", encode($encoding, $quote) , encode($encoding, $reference) );

my $choice = int(rand($nb_entries));
my @entry = ( sort {$a cmp $b} keys %hash_collection );
exit 0;

print "\n";

The final step is to link xscreensaver to gl. I first chose the Phosphor screensaver in the KDE4 screensaver list (accessible in “Configure your desktop/desktop/screensaver”).

Phosphor screensaver appearing in the KDE4 screensaver list once xscreensaver installedSelection of Phosphor screensaver in the KDE4 screensaver list once the xscreensaver rpm has been installed

Then I used the screensaver-demo command to configure the Phosphor screensaver.

Phosphor configuration with sxcreensaver-demoConfiguration of the phosphor screensaver with the xscreensaver-demo command

The advanced tab allows to specify the custom command that xscreensaver must call to display text.

Configuration of the phosphor screensaver with the xscreensaver-demo command (advanced tab)

In the Program field, I have set the value sleep3;/usr/local/bin/gl -e iso-8859-1 to configure Phosphor to print every 3 seconds the output of gl. The -e iso-8859-1 option is used to make sure that gl prints the content in ISO-8859-1 (otherwise accents and other diacritics are badly displayed by Phosphor). It is important to notice in this example that both my XML collection file and gl script have been saved with in UTF-8. I could have also set sleep3;clear;/usr/local/bin/gl -e iso-8859-1 to ask xscreensaver to clear the screen between each quote. I have also discovered that the fortune command (usually shipped with the fortune-mod rpm) is a tool that provides many possibilities to randomly display quotes and it was indeed proposed by default by xscreensaver.


December 7, 2009

How to set up a free and practical parental control filter with Procon Latte

Filed under: General — Tags: , — kwartik @ 11:50 pm

I was looking for a simple parental control filter solution in order to be sure that my young daughter (4 years old who of course likes to click on any link she sees !) will not accidentally find herself on one of these numerous undesirable sites. My requirements were the following :

– white list feature (I want to block all sites by default and allow explicitly a small number of sites)

– configuration protected with a master password

– filtering at application level, ideally as a Firefox module (add-on). I consider as totally sufficient this solution for my daughter, as I am sure that she is too young to think of using a different browser. She would have indeed quite some difficulties to find one on the Linux system I have configured for her !

– free solution

I queried the Firefox module catalog ( Tools / Complementary Modules / Catalog ) and it basically proposed me two parental control modules :

foxfilter, promoted as “Simple and effective! FoxFilter is a personal content filter that helps block pornographic and other inappropriate content using customizable features. All filtering features are free! Premium features require a small support fee.”,

broozi, promoted as the “first Firefox add-on which enable kids to take their first steps on Internet, so simply and in full safety”.

I was amazed by the philosophy of FoxFilter. “All filtering features free”, but the most important one which is the master password to guarantee that your kid will not be able to add a site to a white list is a Premium feature ! More over, I had the impression that a lot of the configuration is done online as if the foxfilter is insterested by your parental configuration settings ! A few minutes of testing were sufficient to add the product to my black list!

– The philosophy of broozi to radically change the user interface was not at all what I was looking for. Moreover, control parental feature simply did not work, as it was possible to click on the firefox icon in the tasks bar to leave the broozi interface and to go back to the firefox interface and my daughter is clearly able to do this ! Once installed I was encouraged to purchase Rooki, which adds a real _safe_ parental control feature to broozi.

– Finally, I googled a little bit and found ProCon Latte described as a content filter for Forefox allowing to “filter any kind of material (pornography, gambling, hacking, cracking, etc…), it can also block all traffic, making sure that only desired websites (set in the Whitelist) can be accessed, and includes a profanity filter, all *like* a parental control filter.” I tested only the “block all traffic” and white list features and I really appreciated this tool. I found the interface really intuitive to use and not at all intrusive.

I have posted below a few screenshots showing how easy it was to set a configuration compliant to my requirements. My system uses french locales but of course internationalization is well managed by ProCon.

First, a master password needs to be set, it will be required at each settings modifications as shown on the picture below :

ProCon master password prompt

Then all sites can be blocked by default by clicking on the “Block all traffic checkbox” :

ProCon : activation of the "all sites are blocked by default" rule

Finally, a white list can be easily created by clicking on the “Activate white list” check box :

ProCon: activating the white list

And that’s it ! After this straight-forward configuration step, I can safely leave my daughter in front of the screen. ProCon implements also much more elaborated filtering logic that is detailed on its web site.

I was also very impressed by the support provided by corvineum, the author of ProCon. After a ProCon minor release update (v1.7.9.7 =>, I was not able to use ProCon anymore and an error related to the french accents was displayed in a popup. I sent a email to corvineum and twelve hours latter he sent me the fix ! I am not even sure that if I had experimented a similar problem with a proprietary solution, I would have observed the same reactivity !

Blog at