Showing posts with label panel. Show all posts
Showing posts with label panel. Show all posts

Tuesday, March 17, 2009

Birthday Reminder For Gnome Panel

This program checks the file /home/rsrijith/shell/birthday_reminder.txt to find the upcoming birthdays in 20 days and writes into the file /home/rsrijith/shell/birthdays.
There is a file called /home/rsrijith/shell/birthdays1, the difference between it and birthdays file is that birthdays contains only first name of the person and birthdays1 contains the whole name.
So that's it. Now the code....
#!/bin/bash
echo "Birthday Finder ">>/home/rsrijith/logs/bday
date>>/home/rsrijith/logs/bday
tillm=$(date --date="+20 day" +"%b")
nowm=$(date +"%b")
tilld=$(date --date="+20 day" +"%2d")
nowd=$(date +"%d")
nowd=$((10#$nowd))
year=$(date +"%Y")
FileName='/home/rsrijith/shell/birthday_reminder.txt'
if [ -e /home/rsrijith/shell/birthdays ]
then
rm /home/rsrijith/shell/birthdays
fi
touch /home/rsrijith/shell/birthdays
if [ -e /home/rsrijith/shell/birthdays1 ]
then
rm /home/rsrijith/shell/birthdays1
fi
touch /home/rsrijith/shell/birthdays1
while read LINE
do
m=$(echo $LINE|cut -f2 -d',')
d=$(echo $LINE|cut -f3 -d',')
name=$(echo $LINE|cut -f1 -d',')
yob=$(echo $LINE|cut -f4 -d',')
if [ $m == $nowm ]
then
d="${d#0}";
if [ $nowd -le $d ]
then
name1=$name;
name=` echo $name|sed 's/\([^ ]*\).*/\1/;s/\([^.]*\).*/\1/'`
dif=$(($d-$nowd))
yrdif=$(($year-$yob))
if [ $dif -le 1 ]
then
if [ $dif -eq 0 ]
then
echo "Happy Birthday to "$name>>/home/rsrijith/shell/birthdays
echo "Happy Birthday to "$name1>>/home/rsrijith/shell/birthdays1
else
echo "$dif day to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
echo "$dif day to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
fi
else
echo "$dif days to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
echo "$dif days to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
fi

fi
else
if [ $m == $tillm ]
then
if [ $tilld -gt $d ]
then
name1=$name
name=` echo $name|sed 's/\([^ ]*\).*/\1/'`
lastdate=$(date -d "-$(date +%d) days +1 month"|cut -f 3 -d " ")
echo "$d $lastdate $nowd"

dif=$(($d+$lastdate-$nowd))
yrdif=$(($year-$yob))
echo "$dif days to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
echo "$dif days to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
fi
fi
fi
done < $FileName
if [ ! -s /home/rsrijith/shell/birthdays ]
then
echo "Nothing to Remind" > /home/rsrijith/shell/birthdays
fi
cat /home/rsrijith/shell/birthdays1|sort -n >/home/rsrijith/temp && mv /home/rsrijith/temp /home/rsrijith/shell/birthdays1
cat /home/rsrijith/shell/birthdays|sort -n >/home/rsrijith/temp && mv /home/rsrijith/temp /home/rsrijith/shell/birthdays

This code is part of the Perl Panel Code. The related codes to this are:

Reminder for Gnome Panel

This is the program that lets us to enter the text and time at which it should be reminded me. The command has the following options
  • -d: date eg:  17/3/2009
  • -t : time [ It's should be entered as 24hr clock] eg:   20:00:00
  • -r : reminder text [ It should be entered in between a double quotes ] eg: "This is a test"
  • -p :priority [ I hav'nt implemented it yet . Kept it for future implementation.] eg : 1
  • -b :Remind me before [ By using it we can change the default remind before time of 5mins ie it is used to remind from a specific mins before the time we have scheduled to remind. It is specified in mins] eg: 5
#!/usr/bin/perl
use Time::Local;
my @date;
my @time;
my $d=0,$t=0,$r=0,$p=0,$b=0;
my @deftime=localtime();
$deftime[5]+=1900;
$deftime[4]++;
my $dv="$deftime[3]/$deftime[4]/$deftime[5]",$tv="$deftime[2]:$deftime[1]:$deftime[0]",$rv="",$pv=1,$bv=0;
foreach $argnum (0 .. $#ARGV)
{
if($ARGV[$argnum] eq "-d")
{
$d=1;
$dv=$ARGV[$argnum+1];
}
elsif($ARGV[$argnum] eq "-t")
{
$t=1;
$tv=$ARGV[$argnum+1];
}
elsif($ARGV[$argnum] eq "-r")
{
$r=1;
$rv=$ARGV[$argnum+1];
print "Remind Text:$rv\n";
}
elsif($ARGV[$argnum] eq "-p")
{
$p=1;
$pv=$ARGV[$argnum+1];
print "Priority:$pv\n";
}
elsif($ARGV[$argnum] eq "-b")
{
$b=1;
$bv=$ARGV[$argnum+1];
print "Remind Before:$bv\n";
}
}
@date=split('/',$dv);
print "Date:$dv\n";
@time={0,0,0};
@time=split(':',$tv);
print "Time:$tv";
$date[1]--;
my $time=timelocal($time[2],$time[1],$time[0],$date[0],$date[1],$date[2],);
my $nowtime=timelocal(localtime());
my $difftime=$time-$nowtime;
print "\nTime Of Alarm:".$time."\nTime Now:".$nowtime."\nDifference in Seconds:".$difftime."\n";

open (FH,">>/home/rsrijith/perl/reminder");
print FH "$time:$pv:$bv:$rv\n";
close FH;
This code is part of the Perl Panel Code. The related codes to this are:

Backend For Panel Reminder

I had already posted about creating a Display Reminders In Gnome Panel. This post is an addition to that script. This is a backend script that writes what to print into the panel_remind file. I use this script to print Birthday Reminder and Things to remember of which I will be posting shortly.
So the Code is simple Perl script.
#!/usr/bin/perl
our $printl;our $i=0;our $r=0;
$| = 1;
while(TRUE)
{
open (RB,"/home/rsrijith/perl/reminder");
my @line=<RB>;
close RB;
if($line[0])
{
while($line[$i])
{
open (WR,">/home/rsrijith/panel_remind");
my @s=split(":",$line[$i]);
my $nowtime=timelocal(localtime());
my $a=$s[2]+300;
if(($s[0]-$nowtime<=$a)&&($s[0]-$nowtime>=0))
{
my $t= to_int((($s[0]-$nowtime)/60));
while($t>0)
{
open (WR,">/home/rsrijith/panel_remind");
print WR "Red:In $t Mins - $s[3]";
close WR;
$r=1;
$t--;
sleep(60);
if( $t == 0)
{ `notify-send "$s[3]" -u critical -t 60000`}
}
}
open (WB,">/home/rsrijith/perl/reminder");
my $nowtime=timelocal(localtime());
if($s[0]-$nowtime>0)
{
print WB "$line[$i]";
close WB;
}
$i++;

}
if($r eq 0)
{
bday();
}
$i=0;
}
else
{
print "Birthday";
bday();
}
}


sub bday
{
open (RB,"/home/rsrijith/shell/birthdays");
my @line=<RB>;
close RB;

if((!$line[0])&&($r==0))
{
print "nothing to remind";
$printl="Black:Nothing to Remind \n:(";
open (WR,">/home/rsrijith/panel_remind");
print WR $printl;
close WR;
sleep(100);
}
while($line[$i])
{
$_=$line[$i];
if(m/Happy/)
{
$printl="Blue:$line[$i]";
}
else
{
$printl="Black:$line[$i]";
}
open (WR,">/home/rsrijith/panel_remind");
print WR $printl;
close WR;
$i++;
sleep(5);
}
$i=0;
return;
}
This script reads from files
  • /home/rsrijith/shell/birthdays: The file contains birthdays of my friends that I need to be reminded of. The method to print the upcoming birthdays into this file is posted at <will be posted soon>.
  • /home/rsrijith/perl/reminder:The file contains reminders that I need to  be reminded. I used another script to write into that file which is posted at <will be posted soon >.
This program needs libnotify  package. The package name is libnotify1 in my computer. It may vary with linux you are in.



So the ordinary panel reminder can be made of some use using this script.
So try it out and tell me how it went.

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.