This repository has been archived by the owner on Dec 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mrvoice.pl
executable file
·1243 lines (1159 loc) · 39.8 KB
/
mrvoice.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
use Tk;
use Tk::DialogBox;
use File::Basename;
use File::Copy;
use DBI;
use MPEG::MP3Info;
#########
# AUTHOR: H. Wade Minter <minter@lunenburg.org>
# TITLE: mrvoice.pl
# DESCRIPTION: A Perl/TK frontend for an MP3 database. Written for The
# Great American Comedy Company, Raleigh, NC.
# http://www.greatamericancomedy.com/
# CVS INFORMATION:
# LAST COMMIT BY AUTHOR: $Author: minter $
# LAST COMMIT DATE (GMT): $Date: 2001/10/19 15:04:42 $
# CVS REVISION NUMBER: $Revision: 1.58 $
# CHANGELOG:
# See ChangeLog file
# CREDITS:
# See Credits file
##########
#####
# CONFIGURATION VARIABLES
# It is probably best to set this in your external config file, either
# ~/.mrvoicerc (Unix) or C:\mrvoice.cfg (Windows)
#####
$db_name = ''; # In the form DBNAME:HOSTNAME:PORT
$db_username = ''; # The username used to connect
# to the database.
$db_pass = ''; # The password used to connect
# to the database.
$category = 'Any'; # The default category to search
# Initial status message
$mp3player = '/usr/bin/xmms'; # Full path to MP3 player
$filepath = ''; # Path that will be prepended onto
# the filename retrieved from the
# database, to find the actual
# MP3 on the local system.
# MUST END WITH TRAILING /
$savedir = ''; # The default directory where
# hotkey save files will live.
#####
# YOU SHOULD NOT NEED TO MODIFY ANYTHING BELOW HERE FOR NORMAL USE
#####
$savefile_count = 0; # Counter variables
$savefile_max = 4; # The maximum number of files to
# keep in the "recently used" list.
$hotkeytypes = [
['Mr. Voice Hotkey Files', '.mrv'],
['All Files', '*'],
];
$mp3types = [
['MP3 Files', '*.mp3'],
['All Files', '*'],
];
# Check to see if we're on Windows or Linux, and set the RC file accordingly.
if ("$^O" eq "MSWin32")
{
$rcfile = "C:\\mrvoice.cfg";
}
else
{
$homedir = "~";
$homedir =~ s{ ^ ~ ( [^/]* ) }
{ $1
? (getpwnam($1))[7]
: ( $ENV{HOME} || $ENV{LOGDIR}
|| (getpwuid($>))[7]
)
}ex;
$rcfile = "$homedir/.mrvoicerc";
}
#STARTCSZ
# The following variables set the locations of MP3s for static hotkey'd
# sounds
#$altt = "TaDa.mp3";
#$alty = "CalloutMusic.mp3";
#$altb = "BrownBag.mp3";
#$altg = "Groaner.mp3";
#$altv = "PriceIsRightTheme.mp3";
#ENDCSZ
#####
my $version = "1.2.1"; # Program version
$status = "Welcome to Mr. Voice version $version";
sub bind_hotkeys
{
# This will set up hotkeybindings for the window that is passed
# in as the first argument.
$window = $_[0];
$window->bind("<Key-F1>", [\&play_mp3,"F1"]);
$window->bind("<Key-F2>", [\&play_mp3,"F2"]);
$window->bind("<Key-F3>", [\&play_mp3,"F3"]);
$window->bind("<Key-F4>", [\&play_mp3,"F4"]);
$window->bind("<Key-F5>", [\&play_mp3,"F5"]);
$window->bind("<Key-F6>", [\&play_mp3,"F6"]);
$window->bind("<Key-F7>", [\&play_mp3,"F7"]);
$window->bind("<Key-F8>", [\&play_mp3,"F8"]);
$window->bind("<Key-F9>", [\&play_mp3,"F9"]);
$window->bind("<Key-F10>", [\&play_mp3,"F10"]);
$window->bind("<Key-F11>", [\&play_mp3,"F11"]);
$window->bind("<Key-F12>", [\&play_mp3,"F12"]);
$window->bind("<Key-Return>", [\&do_search]);
$window->bind("<Key-Escape>", [\&stop_mp3]);
#STARTCSZ
#$window->bind("<Alt-Key-t>", [\&play_mp3,"ALT-T"]);
#$window->bind("<Alt-Key-y>", [\&play_mp3,"ALT-Y"]);
#$window->bind("<Alt-Key-b>", [\&play_mp3,"ALT-B"]);
#$window->bind("<Alt-Key-g>", [\&play_mp3,"ALT-G"]);
#$window->bind("<Alt-Key-v>", [\&play_mp3,"ALT-V"]);
#ENDCSZ
}
sub open_file
{
$selectedfile = $_[0];
if (!$selectedfile)
{
$selectedfile = $mw->getOpenFile(-filetypes=>$hotkeytypes,
-initialdir=>$savedir,
-title=>'Open a File');
}
if ($selectedfile)
{
if (! -r $selectedfile)
{
$box = $mw->DialogBox(-title=>"File Error!", -buttons=>["OK"]);
$box->add("Label",-text=>"Could not open file $selectedfile for reading")->pack();
$box->Show;
}
else
{
backup_hotkeys();
open (HOTKEYFILE,$selectedfile);
while (<HOTKEYFILE>)
{
chomp;
($var1,$var2) = split(/::/);
$$var1=$var2;
}
close (HOTKEYFILE);
$status = "Loaded hotkey file $selectedfile successfully";
dynamic_documents($selectedfile);
}
}
else
{
$status = "File load cancelled.";
}
}
sub save_file
{
$selectedfile = $mw->getSaveFile(-title=>'Save a File',
-defaultextension=>".mrv",
-filetypes=>$hotkeytypes,
-initialdir=>"$savedir");
if ($selectedfile)
{
if ( (! -w $selectedfile) && (-e $selectedfile) )
{
$box = $mw->DialogBox(-title=>"File Error!", -buttons=>["OK"]);
$box->add("Label",-text=>"Could not open file $selectedfile for writing")->pack();
$box->Show;
}
elsif ( ! -w dirname($selectedfile) )
{
$box = $mw->DialogBox(-title=>"File Error!", -buttons=>["OK"]);
$box->add("Label",-text=>"Could not write new file to directory dirname($selectedfile)")->pack();
$box->Show;
}
else
{
$selectedfile = "$selectedfile.mrv" unless ($selectedfile =~ /.*\.mrv$/);
open (HOTKEYFILE,">$selectedfile");
print HOTKEYFILE "f1::$f1\n";
print HOTKEYFILE "f2::$f2\n";
print HOTKEYFILE "f3::$f3\n";
print HOTKEYFILE "f4::$f4\n";
print HOTKEYFILE "f5::$f5\n";
print HOTKEYFILE "f6::$f6\n";
print HOTKEYFILE "f7::$f7\n";
print HOTKEYFILE "f8::$f8\n";
print HOTKEYFILE "f9::$f9\n";
print HOTKEYFILE "f10::$f10\n";
print HOTKEYFILE "f11::$f11\n";
print HOTKEYFILE "f12::$f12\n";
close (HOTKEYFILE);
$status = "Finished saving hotkeys to $selectedfile\n";
dynamic_documents($selectedfile);
}
}
else
{
$status = "File save cancelled.";
}
}
sub dynamic_documents
{
$file = $_[0];
$savefile_count++;
push (@current, $file);
$filemenu->command(-label=>"$file",
-command => [\&open_file, $file]);
if ($#current >= $savefile_max)
{
$filemenu->menu->delete(5);
shift (@current);
}
}
sub infobox
{
$box = $mw->DialogBox(-title=>"$_[0]", -buttons=>["OK"]);
$box->add("Label",-text=>"$_[1]")->pack();
$box->Show;
}
sub backup_hotkeys
{
$old_f1 = $f1;
$old_f2 = $f2;
$old_f3 = $f3;
$old_f4 = $f4;
$old_f5 = $f5;
$old_f6 = $f6;
$old_f7 = $f7;
$old_f8 = $f8;
$old_f9 = $f9;
$old_f10 = $f10;
$old_f11 = $f11;
$old_f12 = $f12;
$hotmenu->menu->entryconfigure("Restore Hotkeys", -state=>"normal");
}
sub restore_hotkeys
{
$f1 = $old_f1;
$f2 = $old_f2;
$f3 = $old_f3;
$f4 = $old_f4;
$f5 = $old_f5;
$f6 = $old_f6;
$f7 = $old_f7;
$f8 = $old_f8;
$f9 = $old_f9;
$f10 = $old_f10;
$f11 = $old_f11;
$f12 = $old_f12;
$status = "Previous hotkeys restored.";
$hotmenu->menu->entryconfigure("Restore Hotkeys", -state=>"disabled");
}
sub add_category
{
$box = $mw->DialogBox(-title=>"Add a category", -buttons=>["Ok","Cancel"]);
$acframe1 = $box->add("Frame")->pack(-fill=>'x');
$acframe1->Label(-text=>"Category Code: ")->pack(-side=>'left');
$acframe1->Entry(-width=>6,
-textvariable=>\$addcat_code)->pack(-side=>'left');
$acframe2 = $box->add("Frame")->pack(-fill=>'x');
$acframe2->Label(-text=>"Category Description: ")->pack(-side=>'left');
$acframe2->Entry(-width=>25,
-textvariable=>\$addcat_desc)->pack(-side=>'left');
$button = $box->Show;
if ($button eq "Ok")
{
if (($addcat_code) && ($addcat_desc))
{
$addcat_desc = $dbh->quote($addcat_desc);
$addcat_code =~ tr/a-z/A-Z/;
$query = "INSERT INTO categories VALUES ('$addcat_code',$addcat_desc)";
my $sth=$dbh->prepare($query);
if (! $sth->execute)
{
$error_message = $sth->errstr();
infobox("Database Error","Database returned error: $error_message\non query $query");
}
else
{
infobox("Success","Category successfully added.\nYou will need to restart to see the change");
}
}
else
{
infobox("Error","You must enter both a category code and a description");
}
}
else
{
$status = "Cancelled adding category.";
}
$addcat_code="";
$addcat_desc="";
}
sub edit_category
{
}
sub delete_category
{
my $box = $mw->DialogBox(-title=>"Delete a category",-buttons=>["Ok","Cancel"]);
$box->add("Label",-text=>"Choose a category to delete.")->pack();
my $query="SELECT * from categories ORDER BY description";
my $sth=$dbh->prepare($query);
$sth->execute or die "can't execute the query: $DBI::errstr\n";
while (@table_row = $sth->fetchrow_array)
{
$code=$table_row[0];
$name=$table_row[1];
$box->add("Radiobutton",-text=>$name,
-value=>$code,
-variable=>\$del_cat)->pack(-anchor=>"w");
}
$sth->finish;
my $choice = $box->Show();
if ($choice ne "Cancel")
{
$query = "SELECT * FROM mrvoice WHERE category='$del_cat'";
my $sth=$dbh->prepare($query);
$sth->execute;
$rows = $sth->rows;
if ($rows > 0)
{
infobox("Error","Could not delete category $del_cat because\nthere are still entries in the database\nusing it. Delete all entries using\nthis category before deleting the category");
$status = "Category not deleted";
}
else
{
$query = "DELETE FROM categories WHERE code='$del_cat'";
my $sth=$dbh->prepare($query);
infobox ("Success","Category $del_cat has been deleted.\n\nYou will need to restart Mr. Voice after\nyou finish deleting categories.") if ($sth->execute);
$status = "Deleted category";
}
}
else
{
$status = "Category deletion cancelled";
}
$del_cat="";
}
sub add_new_song
{
$box = $mw->DialogBox(-title=>"Add New Song", -buttons=>["OK","Cancel"]);
$box->add("Label",-text=>"Enter the following information for the new song,\nand choose the file to add.")->pack();
$box->add("Label",-text=>"Items marked with a * are required.\n")->pack();
$frame1 = $box->add("Frame")->pack(-fill=>'x');
$frame1->Label(-text=>"* Song Title")->pack(-side=>'left');
$frame1->Entry(-width=>30,
-textvariable=>\$addsong_title)->pack(-side=>'right');
$frame2 = $box->add("Frame")->pack(-fill=>'x');
$frame2->Label(-text=>"Artist")->pack(-side=>'left');
$frame2->Entry(-width=>30,
-textvariable=>\$addsong_artist)->pack(-side=>'right');
$frame3 = $box->add("Frame")->pack(-fill=>'x');
$frame3->Label(-text=>"* Category")->pack(-side=>'left');
$menu=$frame3->Menubutton(-text=>"Choose Category",
-relief=>'raised',
-tearoff=>0,
-indicatoron=>1)->pack(-side=>'right');
$query="SELECT * from categories ORDER BY description";
my $sth=$dbh->prepare($query);
$sth->execute or die "can't execute the query: $DBI::errstr\n";
while (@table_row = $sth->fetchrow_array)
{
$code=$table_row[0];
$name=$table_row[1];
$menu->radiobutton(-label=>$name,
-value=>$code,
-variable=>\$addsong_cat);
}
$sth->finish;
$frame4 = $box->add("Frame")->pack(-fill=>'x');
$frame4->Label(-text=>"Category Extra Info")->pack(-side=>'left');
$frame4->Entry(-width=>30,
-textvariable=>\$addsong_info)->pack(-side=>'right');
$frame5 = $box->add("Frame")->pack(-fill=>'x');
$frame5->Label(-text=>"* File to add")->pack(-side=>'left');
$frame6 = $box->add("Frame")->pack(-fill=>'x');
$frame6->Button(-text=>"Select File",
-command=>sub {
$addsong_filename = $mw->getOpenFile(-title=>'Select File',
-initialdir=>$homedir,
-filetypes=>$mp3types);
})->pack(-side=>'right');
$frame5->Entry(-width=>30,
-textvariable=>\$addsong_filename)->pack(-side=>'right');
$result = $box->Show();
if ($result eq "OK")
{
if (! $addsong_cat)
{
infobox("Error","Could not add new song\n\nYou must choose a category");
}
elsif (! -r $addsong_filename)
{
infobox ("File Error","Could not open input file $addsong_filename\nfor reading. Check file permissions");
}
elsif (! $addsong_title)
{
infobox ("File Error","You must provide the title for the song.");
}
elsif (! -w $filepath)
{
infobox ("File Error","Could not write file to directory $filepath\nPlease check the permissions");
}
else
{
if ($addsong_artist)
{
$newfilename = "$addsong_artist-$addsong_title";
}
else
{
$newfilename = $addsong_title;
}
$newfilename =~ s/[^a-zA-Z0-9\-]//g;
if ( -e "$filepath$newfilename.mp3")
{
$i=0;
while (1 == 1)
{
if (! -e "$filepath$newfilename-$i.mp3")
{
$newfilename = "$newfilename-$i";
last;
}
$i++;
}
}
$newfilename = "$newfilename.mp3";
$addsong_title = $dbh->quote($addsong_title);
$addsong_artist = $dbh->quote($addsong_artist);
$addsong_info = $dbh->quote($addsong_info);
$query = "INSERT INTO mrvoice VALUES (NULL,$addsong_title,$addsong_artist,'$addsong_cat',$addsong_info,'$newfilename',NULL)";
copy ($addsong_filename,"$filepath$newfilename");
if ($dbh->do($query))
{
infobox ("File Added Successfully","Successfully added new song into database");
$status = "File added successfully";
}
else
{
infobox ("Error","Could not add song into database");
$status = "File add exited on database error";
}
}
}
else
{
$status = "Cancelled song add";
}
$addsong_title="";
$addsong_artist="";
$addsong_info="";
$addsong_cat="";
$addsong_filename="";
}
sub edit_preferences
{
my $box = $mw->DialogBox(-title=>"Edit Preferences",
-buttons=>["Ok","Cancel"],
-default_button=>"Ok");
$box->add("Label",-text=>"You may use this form to modify the operating\npreferences for the Mr. Voice software.\n")->pack();
my $frame1 = $box->add("Frame")->pack(-fill=>'x');
$frame1->Label(-text=>"Database Name")->pack(-side=>'left');
$frame1->Entry(-width=>30,
-textvariable=>\$db_name)->pack(-side=>'right');
my $frame2 = $box->add("Frame")->pack(-fill=>'x');
$frame2->Label(-text=>"Database User Name")->pack(-side=>'left');
$frame2->Entry(-width=>30,
-textvariable=>\$db_username)->pack(-side=>'right');
my $frame3 = $box->add("Frame")->pack(-fill=>'x');
$frame3->Label(-text=>"Database Password")->pack(-side=>'left');
$frame3->Entry(-width=>30,
-textvariable=>\$db_pass)->pack(-side=>'right');
my $frame4 = $box->add("Frame")->pack(-fill=>'x');
$frame4->Label(-text=>"MP3 Directory")->pack(-side=>'left');
$frame4->Entry(-width=>30,
-textvariable=>\$filepath)->pack(-side=>'right');
my $frame5 = $box->add("Frame")->pack(-fill=>'x');
$frame5->Label(-text=>"Hotkey Directory")->pack(-side=>'left');
$frame5->Entry(-width=>30,
-textvariable=>\$savedir)->pack(-side=>'right');
my $frame6 = $box->add("Frame")->pack(-fill=>'x');
$frame6->Label(-text=>"MP3 Player")->pack(-side=>'left');
$frame6->Button(-text=>"Choose",
-command=>sub {
$mp3player = $mw->getOpenFile(-title=>'Select File');
})->pack(-side=>'right');
$frame6->Entry(-width=>30,
-textvariable=>\$mp3player)->pack(-side=>'right');
my $result = $box->Show();
if ($result eq "Ok")
{
if ( (! $db_name) || (! $db_username) || (! $db_pass) || (! $filepath) || (! $savedir) || (! $mp3player) )
{
infobox("Warning","All fields must be filled in\n");
edit_preferences();
}
if (! open(RCFILE,">$rcfile"))
{
infobox("Warning","Could not open $rcfile for writing.\nYour preferences will not be saved\n");
}
else
{
print RCFILE "db_name::$db_name\n";
print RCFILE "db_username::$db_username\n";
print RCFILE "db_pass::$db_pass\n";
print RCFILE "filepath::$filepath\n";
print RCFILE "savedir::$savedir\n";
print RCFILE "mp3player::$mp3player\n";
close(RCFILE);
}
}
read_rcfile();
}
sub edit_song
{
my $id = get_song_id();
$query = "SELECT title,artist,category,info from mrvoice where id=$id";
($edit_title,$edit_artist,$edit_category,$edit_info) = $dbh->selectrow_array($query);
$box = $mw->DialogBox(-title=>"Edit Song", -buttons=>["Edit","Cancel"],
-default_button=>"Cancel");
$box->add("Label",-text=>"You may use this form to modify information about\na song that is already in the database\n")->pack();
$frame1 = $box->add("Frame")->pack(-fill=>'x');
$frame1->Label(-text=>"Song Title")->pack(-side=>'left');
$frame1->Entry(-width=>30,
-textvariable=>\$edit_title)->pack(-side=>'right');
$frame2 = $box->add("Frame")->pack(-fill=>'x');
$frame2->Label(-text=>"Artist")->pack(-side=>'left');
$frame2->Entry(-width=>30,
-textvariable=>\$edit_artist)->pack(-side=>'right');
$frame3 = $box->add("Frame")->pack(-fill=>'x');
$frame3->Label(-text=>"Category")->pack(-side=>'left');
$menu=$frame3->Menubutton(-text=>"Choose Category",
-relief=>'raised',
-tearoff=>0,
-indicatoron=>1)->pack(-side=>'right');
$query="SELECT * from categories ORDER BY description";
my $sth=$dbh->prepare($query);
$sth->execute or die "can't execute the query: $DBI::errstr\n";
while (@table_row = $sth->fetchrow_array)
{
$code=$table_row[0];
$name=$table_row[1];
$menu->radiobutton(-label=>$name,
-value=>$code,
-variable=>\$edit_category);
}
$sth->finish;
$frame4 = $box->add("Frame")->pack(-fill=>'x');
$frame4->Label(-text=>"Extra Info")->pack(-side=>'left');
$frame4->Entry(-width=>30,
-textvariable=>\$edit_info)->pack(-side=>'right');
$result = $box->Show();
if ($result eq "Edit")
{
$edit_artist = $dbh->quote($edit_artist);
$edit_title = $dbh->quote($edit_title);
$edit_info = $dbh->quote($edit_info);
$query = "UPDATE mrvoice SET artist=$edit_artist, title=$edit_title, info=$edit_info, category='$edit_category' WHERE id=$id";
if ($dbh->do($query))
{
infobox ("Song Edited Successfully","The song was edited successfully.");
$status = "Edited song successfully";
}
else
{
infobox ("Error","There was an error editing the song.\nNo changes made.");
$status = "Error editing song - no changes made";
}
}
else
{
$status = "Cancelled song edit.";
}
$edit_title="";
$edit_artist="";
$edit_category="";
$edit_info="";
}
sub delete_song
{
my $id = get_song_id();
if ($id)
{
$box = $mw->DialogBox(-title=>"Confirm Deletion",
-default_button=>"Cancel",
-buttons=>["Delete","Cancel"]);
$box->add("Label",-text=>"About to delete song id $id from the database\nBe sure this is what you want to do!")->pack();
$box->add("Checkbutton",-text=>"Delete file on disk",
-variable=>\$delete_file_cb)->pack();
$result = $box->Show();
if ($result eq "Delete")
{
if ($delete_file_cb == 1)
{
$filequery = "SELECT filename FROM mrvoice WHERE id=$id";
($filename) = $dbh->selectrow_array($filequery);
}
$query = "DELETE FROM mrvoice WHERE id=$id";
my $sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
if ($delete_file_cb == 1)
{
infobox("File Deletion Error","Could not delete file $filepath$filename from the disk\n\nEntry was removed from the database") unless ( unlink("$filepath$filename") );
}
infobox("Song Deleted","Deleted song with ID $id");
$status = "Deleted song id $id";
}
else
{
$status = "Cancelled deletion";
}
}
else
{
$status = "No song selected for deletion";
}
$delete_file_cb = 0;
}
sub show_about
{
infobox("About Mr. Voice","Mr. Voice Version $version\n\nBy H. Wade Minter <minter\@lunenburg.org>\n\n(c)2001, Released under the GNU General Public License");
}
#STARTCSZ
#sub show_predefined_hotkeys
#{
# $box = $mw->DialogBox(-title=>"Predefined Hotkeys", -buttons=>["Close"]);
# $box->add("Label",-text=>"The following hotkeys are always available\nand
#may not be changed")->pack();
# $box->add("Label",-text=>"<Escape> - Stop the currently playing MP3")->pack();
# $box->add("Label",-text=>"<Enter> - Perform the currently entered search")->pack();
# $box->add("Label",-text=>"<ALT-t> - The \"Ta-Da\" MIDI")->pack();
# $box->add("Label",-text=>"<ALT-y> - The \"You're Out\" MIDI")->pack();
# $box->add("Label",-text=>"<ALT-b> - The Brown Bag MIDI")->pack();
# $box->add("Label",-text=>"<ALT-v> - The Price Is Right theme (Volunteer photos)")->pack();
# $box->Show;
#}
#ENDCSZ
sub clear_hotkeys
{
backup_hotkeys();
$f1="";
$f2="";
$f3="";
$f4="";
$f5="";
$f6="";
$f7="";
$f8="";
$f9="";
$f10="";
$f11="";
$f12="";
$status = "All hotkeys cleared";
}
sub clear_selected
{
$f1="" if ($f1_cb);
$f2="" if ($f2_cb);
$f3="" if ($f3_cb);
$f4="" if ($f4_cb);
$f5="" if ($f5_cb);
$f6="" if ($f6_cb);
$f7="" if ($f7_cb);
$f8="" if ($f8_cb);
$f9="" if ($f9_cb);
$f10="" if ($f10_cb);
$f11="" if ($f11_cb);
$f12="" if ($f12_cb);
$f1_cb=0;
$f2_cb=0;
$f3_cb=0;
$f4_cb=0;
$f5_cb=0;
$f6_cb=0;
$f7_cb=0;
$f8_cb=0;
$f9_cb=0;
$f10_cb=0;
$f11_cb=0;
$f12_cb=0;
$status="Selected hotkeys cleared";
}
sub list_hotkeys
{
$hotkeysbox=$mw->Toplevel();
bind_hotkeys($hotkeysbox);
$hotkeysbox->title("Hotkeys");
$hotkeysbox->Label(-text=>"Currently defined hotkeys:")->pack;
$hotkeysbox->Checkbutton(-text=>"F1:",
-variable=>\$f1_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f1)->pack();
$hotkeysbox->Checkbutton(-text=>"F2:",
-variable=>\$f2_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f2)->pack();
$hotkeysbox->Checkbutton(-text=>"F3:",
-variable=>\$f3_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f3)->pack();
$hotkeysbox->Checkbutton(-text=>"F4:",
-variable=>\$f4_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f4)->pack();
$hotkeysbox->Checkbutton(-text=>"F5:",
-variable=>\$f5_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f5)->pack();
$hotkeysbox->Checkbutton(-text=>"F6:",
-variable=>\$f6_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f6)->pack();
$hotkeysbox->Checkbutton(-text=>"F7:",
-variable=>\$f7_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f7)->pack();
$hotkeysbox->Checkbutton(-text=>"F8:",
-variable=>\$f8_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f8)->pack();
$hotkeysbox->Checkbutton(-text=>"F9:",
-variable=>\$f9_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f9)->pack();
$hotkeysbox->Checkbutton(-text=>"F10:",
-variable=>\$f10_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f10)->pack();
$hotkeysbox->Checkbutton(-text=>"F11:",
-variable=>\$f11_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f11)->pack();
$hotkeysbox->Checkbutton(-text=>"F12:",
-variable=>\$f12_cb)->pack();
$hotkeysbox->Label(-textvariable=>\$f12)->pack();
$hotkeysbox->Button(-text=>"Close",
-command=>sub { $hotkeysbox->destroy})->pack(-side=>'left');
$hotkeysbox->Button(-text=>"Clear Selected",
-command=>[\&clear_selected])->pack(-side=>'right');
}
sub get_song_id
{
@list = $mainbox->curselection();
my $selection = $mainbox->get($list['end']);
my ($id) = split /:/,$selection;
return ($id);
}
sub set_hotkey
{
my $id = get_song_id;
$box = $mw->DialogBox(-title=>"Bind Hotkeys", -buttons=>["Apply","Cancel"]);
$box->add("Label",-text=>"Choose the keys to bind song $id to:")->pack();
$box->add("Checkbutton",-text=>"F1",
-variable=>\$f1_cb)->pack();
$box->add("Checkbutton",-text=>"F2",
-variable=>\$f2_cb)->pack();
$box->add("Checkbutton",-text=>"F3",
-variable=>\$f3_cb)->pack();
$box->add("Checkbutton",-text=>"F4",
-variable=>\$f4_cb)->pack();
$box->add("Checkbutton",-text=>"F5",
-variable=>\$f5_cb)->pack();
$box->add("Checkbutton",-text=>"F6",
-variable=>\$f6_cb)->pack();
$box->add("Checkbutton",-text=>"F7",
-variable=>\$f7_cb)->pack();
$box->add("Checkbutton",-text=>"F8",
-variable=>\$f8_cb)->pack();
$box->add("Checkbutton",-text=>"F9",
-variable=>\$f9_cb)->pack();
$box->add("Checkbutton",-text=>"F10",
-variable=>\$f10_cb)->pack();
$box->add("Checkbutton",-text=>"F11",
-variable=>\$f11_cb)->pack();
$box->add("Checkbutton",-text=>"F12",
-variable=>\$f12_cb)->pack();
$result = $box->Show();
if ($result eq "Apply")
{
my $query = "SELECT filename FROM mrvoice WHERE id=$id";
my $sth=$dbh->prepare($query);
$sth->execute or die "can't execute the query: $DBI::errstr\n";
@result = $sth->fetchrow_array;
$sth->finish;
$filename = $result[0];
$f1=$filename if ($f1_cb);
$f2=$filename if ($f2_cb);
$f3=$filename if ($f3_cb);
$f4=$filename if ($f4_cb);
$f5=$filename if ($f5_cb);
$f6=$filename if ($f6_cb);
$f7=$filename if ($f7_cb);
$f8=$filename if ($f8_cb);
$f9=$filename if ($f9_cb);
$f10=$filename if ($f10_cb);
$f11=$filename if ($f11_cb);
$f12=$filename if ($f12_cb);
$f1_cb=0;
$f2_cb=0;
$f3_cb=0;
$f4_cb=0;
$f5_cb=0;
$f6_cb=0;
$f7_cb=0;
$f8_cb=0;
$f9_cb=0;
$f10_cb=0;
$f11_cb=0;
$f12_cb=0;
$status = "Hotkey assigned";
}
else
{
$status = "Hotkey assignment cancelled";
}
}
sub stop_mp3
{
system ("$mp3player --stop");
$status = "Playing Stopped";
}
sub play_mp3
{
# See if the request is coming from one our hotkeys first...
if ($_[1] eq "F1") { $filename = $f1; }
elsif ($_[1] eq "F2") { $filename = $f2; }
elsif ($_[1] eq "F3") { $filename = $f3; }
elsif ($_[1] eq "F4") { $filename = $f4; }
elsif ($_[1] eq "F5") { $filename = $f5; }
elsif ($_[1] eq "F6") { $filename = $f6; }
elsif ($_[1] eq "F7") { $filename = $f7; }
elsif ($_[1] eq "F8") { $filename = $f8; }
elsif ($_[1] eq "F9") { $filename = $f9; }
elsif ($_[1] eq "F10") { $filename = $f10; }
elsif ($_[1] eq "F11") { $filename = $f11; }
elsif ($_[1] eq "F12") { $filename = $f12; }
#STARTCSZ
# elsif ($_[1] eq "ALT-T") { $filename = $altt; }
# elsif ($_[1] eq "ALT-Y") { $filename = $alty; }
# elsif ($_[1] eq "ALT-B") { $filename = $altb; }
# elsif ($_[1] eq "ALT-G") { $filename = $altg; }
# elsif ($_[1] eq "ALT-V") { $filename = $altv; }
#ENDCSZ
else
{
# If not, find the selected song.
#@list = $mainbox->curselection();
my $id = get_song_id;
if ($id)
{
$query = "SELECT filename from mrvoice WHERE id=$id";
my $sth=$dbh->prepare($query);
$sth->execute or die "can't execute the query: $DBI::errstr\n";
@result = $sth->fetchrow_array;
$sth->finish;
$filename = $result[0];
}
}
if ($filename)
{
$status = "Playing file $filename";
system ("$mp3player $filepath$filename");
}
}
sub do_search
{
$status="Starting search";
$mainbox->delete(0,'end');
$query = "SELECT mrvoice.id,categories.description,mrvoice.info,mrvoice.artist,mrvoice.title,mrvoice.filename from mrvoice,categories where mrvoice.category=categories.code ";
$query = $query . "AND category='$category' " if ($category ne "Any");
if ($anyfield)
{
$query = $query . "AND ( info LIKE '%$anyfield%' OR title LIKE '%$anyfield%' OR artist LIKE '%$anyfield%') ";
}
else
{
$query = $query . "AND info LIKE '%$cattext%' " if ($cattext);
$query = $query . "AND title LIKE '%$title%' " if ($title);
$query = $query . "AND artist LIKE '%$artist%' " if ($artist);
}
$query = $query . "ORDER BY category,info,title";
my $sth=$dbh->prepare($query);
$sth->execute or die "can't execute the query: $DBI::errstr\n";
while (@table_row = $sth->fetchrow_array)
{
if (-e "$filepath$table_row[5]")
{
$string="$table_row[0]:($table_row[1]";
$string = $string . " - $table_row[2]" if ($table_row[2]);
$string = $string . ") - \"$table_row[4]\"";
$string = $string. " by $table_row[3]" if ($table_row[3]);
my $info = get_mp3info("$filepath$table_row[5]");
$minute = $info->{MM};
$minute = "0$minute" if ($minute < 10);
$second = $info->{SS};
$second = "0$second" if ($second < 10);
$string = $string . " [$minute:$second]";
$mainbox->insert('end',$string);
}
}
$numrows = $sth->rows;
$sth->finish;
$cattext="";
$title="";
$artist="";
$anyfield="";
$category="Any";
if ($numrows == 1)
{
$status="Displaying $numrows search result";
}
else
{
$status="Displaying $numrows search results";
}
}
sub do_exit
{
$dbh->disconnect;
close (XMMS);
exit;
}
sub rightclick_menu
{
my $rightmenu = $mw->Menu(-menuitems=>[
["command" => "Edit this song",
-command => \&edit_song],
["command" => "Delete this song",
-command => \&delete_song]
],
-tearoff=>0);
my $w=shift;
my $ev=$w->XEvent;
my $index=$w->nearest($ev->y);
$w->selectionClear(0,'end');
$w->selectionSet($index);
$rightmenu->Popup(-popover=>'cursor',
-popanchor=>'nw');
}
sub read_rcfile
{
if (-r $rcfile)
{
open (RCFILE,$rcfile);
while (<RCFILE>)
{
chomp;
($var1,$var2) = split(/::/);
$$var1=$var2;
}
close (RCFILE);
}