config_dialog_generic($glade,$config_array); $conf->btn_ok->connect("pressed",array(&$this,"update_config")); to display it: $conf->prefs = $current_config_array; $conf->show(); function update_config() { $new_config_array = $conf->get_results(); $conf->hide(); } */ //if (substr(PHP_OS, 0, 3) == 'WIN') // require_once(APPDIR ."modules/midgard/phpglade.class"); class phpmole_config_dialog extends phpide_Dialog_Generic { var $prefs; // where stuff is stored and retrieved from var $dialogs = array(); function phpmole_config_dialog() { $this->phpide_Dialog_Generic(dirname(__FILE__)."/master_config.glade"); // load other dialogs and add them. $this->holder = $this->widget->get_widget("config_holder"); $this->notebook = &new GtkNotebook(); $this->notebook->set_tab_pos(GTK_POS_LEFT); $this->notebook->show(); $this->holder->add($this->notebook); $this->add_config_dialog(dirname(__FILE__)."/config_dialog.glade","PHPMole"); if (file_exists(APPDIR . "modules/config_dialog.glade")) $this->add_config_dialog(APPDIR . "modules/config_dialog.glade","Modules"); $dh = opendir(APPDIR . "modules"); while (($file = readdir($dh)) != NULL) { //echo "CHECKING $file"; if ($file[0] == ".") continue; if (!is_dir(APPDIR . "modules/$file")) continue; if (!file_exists(APPDIR . "modules/$file/config_dialog.glade")) continue; $this->add_config_dialog(APPDIR . "modules/$file/config_dialog.glade",$file); } $dh = opendir(APPDIR . "transports"); while (($file = readdir($dh)) != NULL) { //echo "CHECKING $file"; if ($file[0] == ".") continue; if (!is_dir(APPDIR . "transports/$file")) continue; if (!file_exists(APPDIR . "transports/$file/config_dialog.glade")) continue; $this->add_config_dialog(APPDIR . "transports/$file/config_dialog.glade",$file); } $this->connect_dialogs(); // load font and color stuff $this->dialog_font_select=$this->widget->get_widget("fontselectiondialog1"); $this->dialog_color_select=$this->widget->get_widget("colorselectiondialog1"); $this->dialog_color_select_widget=$this->dialog_color_select->colorsel; $this->btn_fontsel_ok=$this->widget->get_widget("fontsel_ok"); $this->btn_fontsel_cancel=$this->widget->get_widget("fontsel_cancel"); $this->btn_fontsel_ok->connect_object_after('clicked',array(&$this,"fontsel_ok")); $this->btn_fontsel_cancel->connect_object_after('clicked',array(&$this,"fontsel_cancel")); $this->btn_colorsel_ok=$this->widget->get_widget("colorsel_ok"); $this->btn_colorsel_cancel=$this->widget->get_widget("colorsel_cancel"); $this->btn_colorsel_ok->connect_object_after('clicked',array(&$this,"colorsel_ok")); $this->btn_colorsel_cancel->connect_object_after('clicked',array(&$this,"colorsel_cancel")); } function connect_dialogs() { global $application; foreach($application->prefs->prefs as $k => $v) { $kname = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k))); $widget = $this->find_widget($kname); if (!$widget) continue; switch (get_class($widget)) { case "GtkButton": $widget->connect_object_after('clicked', array(&$this,"select_font"), array($kname,$k)); break; case "GtkDrawingArea": $btn = $widget->parent; $btn->connect_object_after('button_press_event', array(&$this,"select_color"), array($kname, $k)); break; } } } function add_config_dialog($filename,$title) { $n = count($this->dialogs); $class = "GladeXML"; if (substr(PHP_OS, 0, 3) == 'WIN') $class = "phpglade"; $this->dialogs[$n] = &new $class($filename); $widget = $this->dialogs[$n]->get_widget("config"); $p = $widget->parent; $p->remove($widget); $label = &new GtkLabel( $title); $label->show(); $widget->show(); $this->notebook->append_page($widget,$label); } function show() { $this->load_prefs(); $this->ok_pressed_callback = array(&$this,"save_prefs"); $this->__show(); } function &find_widget($name) { for ($i=0;$i< count($this->dialogs);$i++) if ($widget = $this->dialogs[$i]->get_widget($name)) return $widget; } function load_prefs() { global $application; foreach($application->prefs->prefs as $k => $v) { $kname = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k))); $kname2 = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k." ".sprintf("%01d",$v)))); $widget = $this->find_widget($kname); if (!$widget) $widget = $this->find_widget($kname2); if (!$widget) continue; switch (get_class($widget)) { case "GtkCheckButton": $vv=0; if ($v) $vv = 1; $widget->set_active($vv); break; case "GtkSpinButton": $widget->set_value($v); break; case "GtkButton": $this->set_fontname( $kname,$v); break; case "GtkDrawingArea": $this->set_buttoncolor($kname,$v); break; case "GtkRadioButton": $widget->set_active(0); break; case "GtkText": $len = $widget->get_length(); $widget->delete_text(0,$len); $widget->insert_text($v,0); break; } } $this->prefs = $application->prefs->prefs; } function save_prefs() { global $application; $application->prefs->prefs = $this->prefs; foreach($application->prefs->prefs as $k => $v) { $kname = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k))); $kname2 = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k." ".sprintf("%01d",$v)))); $widget = $this->find_widget($kname); if (!$widget) $widget = $this->find_widget($kname2); if (!$widget) continue; switch (get_class($widget)) { case "GtkCheckButton": $application->prefs->prefs[$k] = $widget->get_active(); break; case "GtkSpinButton": $application->prefs->prefs[$k] = $widget->get_value_as_int(); break; case "GtkRadioButton": // now this is a bit more complex!!! $application->prefs->prefs[$k] = 0; // default it for ($i=0;$i<9;$i++) { $w = $this->find_widget($kname . "_".sprintf("%01d",$i)); if (!$w) break; if ($w->get_active()) $application->prefs->prefs[$k] = $i; } break; } } $application->prefs->save_user_prefs(); $application->module_manager->broadcast("configuration_changed"); } function set_buttoncolor($widgetname, $setting) { $setting = substr("000000".dechex($setting),-6); $s = substr($setting,4,2) . substr($setting,2,2) . substr($setting,0,2); $setting = "#". $s; $w = $this->find_widget($widgetname); $current_style=$w->get_style(); $new_style = $current_style->copy(); $new_style->bg[GTK_STATE_NORMAL]=new GdkColor($setting); $w->set_style($new_style); } function set_fontname($widgetname,$setting) { $b = $this->find_widget($widgetname); $w = $b->child; $fontar = explode("-",$setting); $size = $fontar[7]; if (substr(PHP_OS, 0, 3) != 'WIN') { $current_style=$w->get_style(); $new_style = $current_style->copy(); $new_style->font = gdk::font_load($setting); $w->set_style($new_style); } if ($size == "*") $size = $fontar[8]/10; $w->set_text($fontar[2] ."(".$size.")"); } function select_font($a) { $fontar = explode("-",$this->prefs[$a[1]]); //echo serialize($fontar); if ($fontar[8] == "*") { $fontar[8] = $fontar[7]*10; $fontar[7] = "*"; } $fontname = implode("-",$fontar); //echo "SET" .$fontname; $this->dialog_font_select->set_font_name($fontname); $this->dialog_font_select->show(); $this->active_font_sel = $a[1]; $this->active_font_sel_widget = $a[0]; Gtk::grab_remove($this->window); Gtk::grab_add($this->dialog_font_select); } function fontsel_ok() { $this->prefs[$this->active_font_sel] = $this->dialog_font_select->get_font_name(); //echo "GOT " .$this->prefs[$this->active_font_sel]; $this->set_fontname($this->active_font_sel_widget,$this->prefs[$this->active_font_sel]); $this->dialog_font_select->hide(); Gtk::grab_remove($this->dialog_font_select); Gtk::grab_add($this->window); } function fontsel_cancel() { $this->dialog_font_select->hide(); Gtk::grab_remove($this->dialog_font_select); Gtk::grab_add($this->window); } function select_color($e,$a){ //echo "looking up prefs ". serialize($a)."\n"; $setting = substr("000000".dechex($this->prefs[$a[1]]),-6); $b = hexdec( substr($setting,0,2)) /256; $g = hexdec( substr($setting,2,2))/256; $r = hexdec( substr($setting,4,2))/256; $this->not_active_window = TRUE; $this->dialog_color_select_widget->set_color($r,$g,$b); $this->dialog_color_select->show(); $wi = $this->dialog_color_select->window; $wi->raise(); $this->active_color_sel = $a[1]; $this->active_color_sel_widget = $a[0]; Gtk::grab_remove($this->window); Gtk::grab_add($this->dialog_color_select); } function colorsel_ok() { echo "OK Pressed"; $a = $this->dialog_color_select_widget->get_color(); //echo "GOT " . serialize($a); $b = substr("00".dechex($a[2]*255),-2) . substr("00".dechex($a[1]*255),-2) . substr("00".dechex($a[0]*255),-2); //echo "XX " . $this->active_color_sel . " storing ($b) = ". hexdec($b) . "\n"; $this->prefs[$this->active_color_sel] = hexdec($b); $this->set_buttoncolor($this->active_color_sel_widget,$this->prefs[$this->active_color_sel]); $this->dialog_color_select->hide(); Gtk::grab_remove($this->dialog_color_select); Gtk::grab_add($this->window); $this->not_active_window = FALSE; } function colorsel_cancel() { $this->dialog_color_select->hide(); Gtk::grab_remove($this->dialog_color_select); Gtk::grab_add($this->window); $this->not_active_window = FALSE; } } ?>