Showing posts with label gnome. Show all posts
Showing posts with label gnome. Show all posts

Saturday, February 7, 2009

Display Reminders In Gnome Panel

 It was a long standing requirement of mine to create a reminder software or something which can keep me reminding of things as I always keep forgetting things. So I made a reminder that displays my reminders on the Gnome Panel.
It looks something like this:

So how do we do it?

1st of all we need to display the program we need in the Add to Panel.

For that we add to the bonobo server list. We do this by adding the following code in the folder  /usr/lib/bonobo/servers/. Let us name the file as GNOME_PerlApplet.server
The content of this file should be :
<oaf_info>
  <oaf_server iid="OAFIID:PerlSampleApplet_Factory" type="exe" location="/home/rsrijith/perl/panel-applet">
    <oaf_attribute name="repo_ids" type="stringv">
      <item value="IDL:Bonobo/GenericFactory:1.0"/>
      <item value="IDL:Bonobo/Unknown:1.0"/>
    </oaf_attribute>
    <oaf_attribute name="name" type="string" value="Panel Reminder"/>
    <oaf_attribute name="description" type="string" value="Perl Program working in Panel"/>
  </oaf_server>

  <oaf_server iid="OAFIID:PerlSampleApplet" type="factory" location="OAFIID:PerlSampleApplet_Factory">
    <oaf_attribute name="repo_ids" type="stringv">
      <item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/>
      <item value="IDL:Bonobo/Control:1.0"/>
      <item value="IDL:Bonobo/Unknown:1.0"/>
    </oaf_attribute>
    <oaf_attribute name="name" type="string" value="Panel Reminder"/>
    <oaf_attribute name="description" type="string" value="Perl Program working in Panel:R Srijith"/>
    <oaf_attribute name="panel:category" type="string" value="Amusements"/>
    <oaf_attribute name="panel:icon" type="string" value="bug-buddy.png"/>
  </oaf_server>
</oaf_info>
So this specifies the location of the perl file to run on adding this applet. So here it is /home/rsrijith/perl/panel-applet . This file should print the reminders to be printed on the panel.
The program need the Following packages:

Perl packages:

    • ExtUtils::Depends
    • ExtUtils::PkgConfig
    • Gnome2::GConf
    • Gnome2::PanelApplet
    You install this using
    sudo perl -MCPAN -e 'install <package-name>'

    Linux Package:
      • libpanelappletmm-2.6-1c2
      • libpanelappletmm-2.6-dev
      You install this using
      sudo apt-get install <package-name>

        Thus the perl file content is :
        #!/usr/bin/perl -w

        use warnings;
        use utf8;
        use Gnome2::PanelApplet;
        Gnome2::Program->init ('A Stupid Applet Written in Perl', '0.01', 'libgnomeui',
                               sm_connect => FALSE);

        Gnome2::PanelApplet::Factory->main ('OAFIID:PerlSampleApplet_Factory',
                                            'Gnome2::PanelApplet',
                                            \&fill);


        sub fill {
          my ($applet, $iid, $data) = @_;

          if ($iid ne 'OAFIID:PerlSampleApplet') {
            return FALSE;
          }
         
          my $menu_xml = <<EOX;
        <popup name="button3">
          <menuitem name="Properties Item"
                    verb="Birthdays"
                    _label="Birthdays"
                pixtype="stock"
                pixname="gtk-properties"/>
          <menuitem name="DesktopSwitcher Item"
                verb="DesktopSwitcher"
                _label="Wallpaper Switcher"
                pixtype="stock"
                pixname="gtk-stock"/>
            <menuitem name="Walldelete Item"
                verb="Walldelete"
                _label="Wallpaper Delete"
                pixtype="stock"
                pixname="gtk-stock"/>              
          <menuitem name="About Item"
                verb="About"
                _label="About"
                pixtype="stock"
                pixname="gnome-stock-about"/>
        </popup>
        EOX

          my $cb_mapping = {
            Birthdays => [\&properties_callback, 'default!'],
            DesktopSwitcher => \&deskswitcher_callback,
            Walldelete => \&walldelete_callback,
            About => \&about_callback,
          };

          $applet->setup_menu($menu_xml, $cb_mapping, 'default?');
          our $i=0;our @line;

          our $label = Gtk2::Label->new;
          $label->set_justify("left");
            $label->set_line_wrap(TRUE);
            $label->modify_font(Gtk2::Pango::FontDescription->from_string("Monospace 10"));
            $label->modify_fg("normal", Gtk2::Gdk::Color->parse("Black"));
          $applet->add ($label);
          $applet->show_all;
         
         Glib::Timeout->add (5000, \&update_value);
         #Glib::Timeout->add (500, \&update_list);
         sub update_list{
         open FILE,"/home/rsrijith/panel_remind";
          @line=<FILE>;
          close FILE;
         }
         sub update_value
         {
         
          my @string=split(':',$line[0]);
          $label->modify_fg("normal", Gtk2::Gdk::Color->parse($string[0]));
          $label->set_markup("\n".$string[1]);
          update_list();
         }
        }

        sub deskswitcher_callback
        {
         system('/home/rsrijith/shell/deskback 2>>/home/rsrijith/logs/desktopbackground');
        }

        sub walldelete_callback
        {
         system('/home/rsrijith/shell/deletewall 2>>/home/rsrijith/logs/desktopbackground');
        }

        sub properties_callback {
            my $b="";
                open BDAY,"/home/rsrijith/shell/birthdays1";
            while(<BDAY>)
            { $b.=$_."\n";
            }
          my $dialog = Gtk2::MessageDialog->new (undef, [],
                                                 'info', 'ok',
                                                 $b);
          $dialog->run;
          $dialog->destroy;
        }


        sub about_callback {
          my $about = Gnome2::About->new ('Panel Reminder', '0.1',
                                          'Perl Program working in Panel',
                                          '© 2009 R.Srijith',
                                          'R.Srijith <rsrijith007@gmail.com');
          $about->show;
        }

        This program prints the contents of /home/rsrijith/panel_remind
        An Example of the content of that file should be as

        Blue:Happy Birthday to Mahima
        So that's it!! And Happy Birthday Mahima.


        Comment me if you have any doubts or if it's not working.

        Sunday, November 16, 2008

        Automatic Desktop Wallpaper Changer

        I have a lot of wallpaper that I wanted to switch automatically. After a lot of search i found that there a command way to control all the gnome settings. So I the command I used is "gconftool-2".
        So code is like:
        #!/bin/bash
        folder="/home/rsrijith/Pics" #folder where the pics lie in
        find $folder -iregex ".*.jp.?g" >$folder/temp_back #list all images in the folder
        no=$(cat $folder/temp_back|wc -l)
        rand=$(echo `expr $RANDOM % $no`)
        while ( grep -q $rand $folder/.last50 )
        do
        rand=$(echo `expr $RANDOM % $no`)
        done
        echo $rand >> $folder/.last50
        tail -50 $folder/.last50 >$folder/temp
        cat $folder/temp >$folder/.last50
        rm $folder/temp
        file=$(sed -n $rand'p' $folder/temp_back)
        ON_USER=rsrijith #your username here

        export DBUS_SESSION=$(grep -v "^#" /home/$ON_USER/.dbus/session-bus/`cat /var/lib/dbus/machine-id`-0)

        sudo -u $ON_USER $DBUS_SESSION /usr/bin/gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$file" && echo "Worked On:"$(date) >>/home/$ON_USER/logs/desktopbackground
        echo "Set Wallpaper as:"$file >>/home/$ON_USER/logs/desktopbackground
        rm $folder/temp_back

        I have used the DBUS_SESSION variable to make it compatible with Ubuntu 8.10. The Dbus session is a bit bit different from earlier versions. The change is that it does'nt accept the change until the gnome is restarted. It's due to the new session that is made each time you update that value.

        So the folder variable should the folder where the wallpapers should lie. You can put pictures in folders inside that folder. All of it will be taken. But I have specified to take only jpg and jpeg only.Now a random image is picked from that using the environment variable $RANDOM. Next we update the gnome settings using gconftool-2 if that image was'nt used in the last 50 changes.

        Thus this file picks an image and puts it as wallpaper. So the next part is making this change automatically. For this we use cron (linux scheduler).
        Use the command below to enter the crontab
        sudo crontab -e
        Enter the crontab entry as
        */15 * * * * /home/rsrijith/shell/deskback 2>>/home/rsrijith/logs/deskbackground
        Check the entry using
        sudo crontab -l
        That's all!!!
        Anyone tried? Worked? Comment me !!!