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";
$search = new ImageSearch();
$search->search($selected_file);
}
$dialog->destroy();
class ImageSearch{
protected $search = true;
protected $dialog;
protected $progress;
public function __construct(){
$this->build_dialog();
}
public function search($path){
$this->dialog->show_all();
$timeout_id = Gtk::timeout_add(500,array($this,'pulse'));
$this->search = true;
$found = array();
if (!$this->gather($path,$found)) {
$this->dialog->hide_all();
Gtk::idle_remove($timeout_id);
return false;
}else{
$this->dialog->hide_all();
Gtk::idle_remove($timeout_id);
return $found;
}
}
public function pulse(){
$this->progress->pulse();
return true;
}
public function cancel(){
$this->search = false;
}
protected function build_dialog(){
$dialog = new GtkDialog('Scanning in progress...', null, Gtk::DIALOG_MODAL);
$top_area = $dialog->vbox;
$top_area->pack_start(new GtkLabel('Please hold on while processing directory...'));
$this->progress = new GtkProgressBar();
$this->progress->set_orientation(Gtk::PROGRESS_LEFT_TO_RIGHT);
$top_area->pack_start($this->progress, 0, 0);
$cancel = new gtkbutton('cancel');
$top_area->pack_start($cancel, false, false);
$cancel->connect_simple('clicked',array($this,'cancel'));
$dialog->set_has_separator(false);
$this->dialog = $dialog;
}
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;
}
}
?>