rendered paste body<?php
$dialog = new GtkFileChooserDialog("File Save", null, Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, array(Gtk::STOCK_OK, Gtk::RESPONSE_OK), null);
$dialog->show_all();
if ($dialog->run() == Gtk::RESPONSE_OK) {
$selected_file = $dialog->get_filename();
echo "selected_file = $selected_file\n";
$progress_dialog = new ShowProgress(); // note 1
$idle_id = Gtk::idle_add($progress_dialog,'pulse');
$search = new ImageSearch();
$search->search($selected_file);
$progress_dialog->dialog->destroy(); // done. close the dialog box.
Gtk::idle_remove($idle_id);
}
$dialog->destroy();
class ShowProgress { // note 1
public $progress_bar;
public $dialog;
function ShowProgress() {
$dialog = new GtkDialog('Scanning in progress...', null, Gtk::DIALOG_MODAL); // create a new dialog
$top_area = $dialog->vbox;
$top_area->pack_start(new GtkLabel('Please hold on while processing directory...'));
$this->progress_bar = new GtkProgressBar();
$this->progress_bar->set_orientation(Gtk::PROGRESS_LEFT_TO_RIGHT);
$top_area->pack_start($this->progress_bar, 0, 0);
$dialog->set_has_separator(false);
$dialog->show_all(); // show the dialog
$this->dialog = $dialog; // keep a copy of the dialog ID
}
public function pulse(){
$this->progress_bar->pulse();
return true;
}
}
class ImageSearch{
protected $search = true;
public function search($path){
$this->search = true;
$found = array();
if (!$this->gather($path,$found)) {
return false;
}else{
return $found;
}
}
public function cancel(){
$this->search = false;
}
protected function gather($path,&$found){
$dir = new DirectoryIterator($path);
foreach ($dir as $file){
while(Gtk::events_pending()) Gtk::main_iteration();
if ($file->isFile() & !$file->isDot() & !$file->isDir() & $file->isReadable()) {
echo $file->getPath().DIRECTORY_SEPARATOR.$file->getFilename()."\n";
$data = getimagesize($file->getPath().DIRECTORY_SEPARATOR.$file->getFilename());
if ($data > 0) {
$found[] = array($file->getFilename(),$file->getPath());
}
}
if (!$file->isDot() & $file->isDir()) {
$this->gather($file->getPath().DIRECTORY_SEPARATOR.$file->getFilename(),$found);
}
if ($this->search == false) {
return false;
}
}
return true;
}
}
?>