= 0 ? ".dll" : ".so"); dl($extension); $window = &new GtkWindow(); $window->set_title("The Ultimate MP3 Radio"); $window->set_usize(400, 375); $window->set_position(GTK_WIN_POS_CENTER); $window->set_policy(false, false, false); $window->set_border_width(10); $frame = &new GtkFrame(" Come on guys! Let's do the ECE dance..."); $window->add($frame); // set a callback function for the destroy signal $window->connect("destroy", "killwin"); function killwin() { echo "Window destroyed!\n "; gtk::main_quit(); } // IMPORTANT: directory playlist is stored at!! <-- used by many scripts/functions $dir = ".\playlist\\"; global $dir; // CREATE MAIN BOX $box1 = &new GtkVBox(); $box1->set_border_width(8); $frame->add($box1); // ############################################################################ // ## GENERATE MP3 PLAYLIST ################################################### // ############################################################################ function genPl() { global $dir; $fold = opendir($dir); while (($file = readdir($fold))) if ((stristr($file, ".mp3"))) { $temp = &new GtkListItem($file); $temp->set_data('name', $file); $plEntries[] = $temp; } global $totSongs; // define as global to be used by refreshPl() $totSongs = count($plEntries); return $plEntries; } global $scrolled_window; $scrolled_window = &new GtkScrolledWindow(); $scrolled_window->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); global $playlist; $playlist = &new GtkList(); $playlist->set_selection_mode(GTK_SELECTION_BROWSE); $plEntries = genPl(); $playlist->append_items($plEntries); $scrolled_window->set_usize(400,250); $scrolled_window->add_with_viewport($playlist); $box1->pack_start($scrolled_window); // ############################################################################ // ## BUTTON PANES ############################################################ // ############################################################################ // CREATE 2 BOTTOM PANES FOR 2 ROWS OF BUTTONS // // [ Upload New MP3 ] [Remove Song from Playlist] // [ Start Broadcast ] [ Close Program ] // // ############################################################################ // BOTTOM BUTTON PANE 1 $bpButtons1 = &new GtkHButtonBox(); $bpButtons1->set_layout(GTK_BUTTONBOX_SPREAD); $box1->add($bpButtons1); // BOTTOM BUTTON PANE 2 $bpButtons2 = &new GtkHButtonBox(); $bpButtons2->set_layout(GTK_BUTTONBOX_SPREAD); $box1->add($bpButtons2); // ############################################ // ## Button1: UPLOAD MP3 STUFF ############### // ############################################ // BUTTON: "Upload MP3s" $button = &new GtkButton('Upload New MP3 File'); $button->connect('clicked', 'fileUpload'); $bpButtons1->add($button); // MP3 Upload Window function fileUpload() { $fs = &new GtkFileSelection('File Selection Example'); $fs->complete("*.mp3"); $ok_button = $fs->ok_button; $ok_button->connect_object('clicked', 'uploadMP3', $fs); $cancel_button = $fs->cancel_button; $cancel_button->connect('clicked', 'canceldialog'); $cancel_button->connect_object('clicked', array($fs, 'destroy')); $fs->show(); } // "Upload" MP3 function uploadMP3($fs) { $mp3 = $fs->get_filename(); $getName = explode("\\", $mp3); $nameIs = $getName[count($getName)-1]; global $dir; copy($mp3, $dir.$nameIs); refreshPl(); $fs->destroy(); } // ############################################ // ## Button2: REMOVE SONG STUFF ############## // ############################################ // BUTTON: "Remove Song" $button = &new GtkButton('Remove Song from Playlist'); $button->connect_object('clicked', 'removeSong', $playlist, $plEntries); $bpButtons1->add($button); // FUNCTION: remove mp3 from playlist function removeSong($list, $plEntries) { $mp3item = $list->selection[0]; $mp3 = $mp3item->get_data('name'); global $dir; unlink($dir.$mp3); refreshPl(); } // ############################################ // ## Button3: START BROADCAST STUFF ########## // ############################################ // BUTTON: "Start Broadcast" $button = &new GtkButton('Start MP3 Broadcast (FM)'); $button->connect_object('clicked', 'runSerialOut', $window); $bpButtons2->add($button); // FUNCTION: run serialOut.exe -- terminal window that sends MP3 data to COM1 function runSerialOut($window) { $window->hide_all(); exec("serialOut"); } // ############################################ // ## Button4: CLOSE PROGRAM STUFF ############ // ############################################ // BUTTON: "Close Program" $button = &new GtkButton('Close Program'); $button->connect('clicked', 'destroy'); $bpButtons2->add($button); // FUNCTION: destroy (close) window function destroy() { Gtk::main_quit(); } // ############################################################################################ // ## OTHER FUNCTIONS STUFF ################################################################### // ############################################################################################ // FUNCTION: refresh playlist function refreshPl() { global $playlist; global $totSongs; $playlist->clear_items(0, $totSongs); $plEntries = genPl(); $playlist->append_items($plEntries); $playlist->show_all(); // <-- annoying tedious step!! } // FINAL INITIALIZIATION $window->show_all(); gtk::main(); ?>