PhoneBook plugin module bug fix
"Kevin Walsh" <[email protected]> Mon, 17 Feb 2003 19:10:56 -0000
| Newsgroups | gmane.music.equipment.slimp3.dev |
|---|---|
| Message-ID | <[email protected]> |
I just received a bug report that pointed out that the PhoneBook plugin module bombs out if there's no phonebook.txt file. Perhaps I should have tested the module a little more thoroughly before posting. :-) I also updated the comments at the top of the file to specify where the phonebook.txt file should be located. I've attached the new version. Remember that this module only works with very recent CVS versions of the SLIMP3 server. -- _/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/ _/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h _/ _/ _/ _/ _/ _/ _/ _/_/ [email protected] _/ _/ _/_/_/_/ _/ _/_/_/ _/ _/ ------------------------ Yahoo! Groups Sponsor ---------------------~--> Get 128 Bit SSL Encryption! http://us.click.yahoo.com/FpY02D/vN2EAA/xGHJAA/rIp0lB/TM ---------------------------------------------------------------------~-> To unsubscribe from this group, send an email to: [email protected] Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
PhoneBook.pm
(application/octet-stream, 3.7 KB)
# # $Id$ # # Author: Kevin Walsh <[email protected]> # # Copyright (c) 2003 Cursor Software Limited. # All rights reserved. # # Simple phone book plugin for the SLIMP3 server. Allows the SLIMP3 # clients to scroll through phone book entries saved in a text file. # # The text file format consists of multiple lines in the following # format: # # name | number # # for instance: # # Some person | (020) 8111 1111 # Another person | (020) 8222 2222 # And another | (020) 8333 3333 # # The module will sort the list for you (by name), so you don't have # to worry about that. # # The phonebook.txt file should be placed in the SLIMP3 server # user's home directory. That is the same directory as the # .slimp3.pref file, by the way. # # Scroll through the list using the up/down buttons or use the numeric # keys like a phone keypad (1=ABC, 2=DEF etc.) to jump to an entry in # the list. The 'add' (rec) key will refresh the phone book list from # the text file if required. # # ---------------------------------------------------------------------- # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA # use SliMP3::Prefs; use File::Spec::Functions qw(catdir); use strict; package Plugins::PhoneBook; use File::Spec::Functions qw(catdir); sub getDisplayName { 'Phone Book' } my $phonebook_location = catdir(SliMP3::Prefs::preferencesPath(),'phonebook.txt'); my @phone_list = (); my %display_current; my %functions = ( 'left' => sub { SliMP3::Buttons::Common::popModeRight(shift); }, 'up' => sub { my $client = shift; $display_current{$client} = SliMP3::Buttons::Common::scroll( $client, -1, $#phone_list + 1, $display_current{$client} || 0, ); SliMP3::Display::update($client); }, 'down' => sub { my $client = shift; $display_current{$client} = SliMP3::Buttons::Common::scroll( $client, 1, $#phone_list + 1, $display_current{$client} || 0, ); SliMP3::Display::update($client); }, 'numberScroll' => sub { my ($client,undef,$digit) = @_; $display_current{$client} = SliMP3::Buttons::Common::numberScroll( $client, $digit, \@phone_list, 1, sub { $phone_list[shift]->[0] }, ); SliMP3::Display::update($client); }, 'add' => sub { # # refresh the phonebook list from the text file # my $client = shift; SliMP3::Animation::showBriefly($client,'Updating...',''); read_textfile(); }, ); sub lines { my $client = shift; if (scalar(@phone_list)) { return @{$phone_list[$display_current{$client} || 0]}; } return ('Your phone book is empty',''); } sub read_textfile { @phone_list = (); open(PHONEBOOK,$phonebook_location) or return undef; while (<PHONEBOOK>) { s/^\s+//; s/[\s\r\n]+$//; next unless $_; my @cols = split('\s*\|\s*',$_); push(@phone_list,\@cols); } close PHONEBOOK; @phone_list = sort { lc($a->[0]) cmp lc($b->[0]) } @phone_list; undef; } sub setMode { my $client = shift; read_textfile(); $client->lines(\&lines); SliMP3::Display::update($client); } sub getFunctions { \%functions; } 1;