All pastes #940661 Raw Edit

Unnamed

public php v1 · immutable
·published 2008-03-13 04:05 UTC
rendered paste body
<?php	require_once('inc/GtkIO.php');	class PKQST_Handle	{		private $isConnected = false;		function connect()		{			if (GtkIO::connect("serv.pkqst.net",7566))			{				$this->isConnected = true;				return true;			}			else			{				$this->isConnected = false;				return false;			}		}		function loginTry($e = null,$user = null,$pass = null)		{			if (!$this->isConnected && !$this->connect()) { return false; }		}	}	class PKQST_Login	{		private $working = false;		protected $username;		protected $password;		function create()		{			$this->window	=  new GtkWindow();			$this->window	-> set_title('PoKéQuesT - Login');			$this->window	-> set_position(Gtk::WIN_POS_CENTER);			$this->window	-> set_property('allow_grow',false);			$this->window	-> set_property('allow_shrink',false);		//	$this->window	-> set_icon($this->window->render_icon(Gtk::STOCK_HOME,Gtk::ICON_SIZE_DIALOG));			$this->window	-> add($this->makeLoginForm());			$this->window	-> connect('destroy',array($this,'close'));			$this->window	-> show_all();			gtk		:: main();		}		function makeLoginForm()		{			$table = new GtkTable(3,3);			// Username				$user 	=  new GtkLabel("Username:");				$table	-> attach($user,0,1,0,1,Gtk::FILL);				$this	-> userForm = new GtkEntry();				$user	-> set_mnemonic_widget($this->userForm);				$table	-> attach($this->userForm,1,3,0,1,Gtk::FILL);			// Password				$pass 	=  new GtkLabel("Password:");				$table	-> attach($pass,0,1,1,2,Gtk::FILL);				$this	-> passForm = new GtkEntry();				$this	-> passForm-> set_visibility(false);				$pass	-> set_mnemonic_widget($this->passForm);				$table	-> attach($this->passForm,1,3,1,2,Gtk::FILL);			// Login				$login	=  new GtkButton("Login");				$table	-> attach($login,0,1,2,3,Gtk::FILL);				$login	-> connect('clicked',array($this,"login"));			// OpenID				$openid	=  new GtkButton("OpenID");				$table	-> attach($openid,1,2,2,3,Gtk::FILL);				$openid	-> connect('clicked',array($this,"openid"));			// Register				$reg	=  new GtkButton("Register");				$table	-> attach($reg,2,3,2,3,Gtk::FILL);				$reg	-> connect('clicked',array($this,"register"));						return $table;		}		function login()		{			$this->username	=  $this->userForm->get_text();			$this->password =  $this->passForm->get_text();			echo $this->username." ".$this->password."\r\n";			if ($this->username == "" || $this->password == "")			{				$txt = "";				if ($this->username == "") { $txt .= "You have not filled out a username.\r\n"; }				if ($this->password == "") { $txt .= "You have not filled out a password."; }				$this->errorMsg(null,$this->window,$txt);			}			else			{				$this	-> window->iconify();				//$d = new GtkMessageDialog($this->window,Gtk::DIALOG_MODAL,Gtk::MESSAGE_INFO,Gtk::BUTTONS_OK,"Connecting...");				$this	-> progressWindow = new GtkWindow();				$this	-> progressWindow-> set_title('Logging In...');				$this	-> progressWindow-> set_size_request(300,100);				$this	-> progressWindow-> set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);				$this	-> progressWindow-> set_position(Gtk::WIN_POS_CENTER_ALWAYS);				$vbox 	=  new GtkVBox();				$label 	=  new GtkLabel("Logging You In...");				$vbox	-> pack_start($label);				$adj	=  new GtkAdjustment(0,0,100,1,0);				$this	-> progressBar = new GtkProgressBar($adj);				$vbox	-> pack_start($this->progressBar,false);				$btn	=  new GtkButton("Cancel");				$btn	-> connect('clicked',array($this,"close"));				$vbox	-> pack_start($btn,false);				$this	-> progressWindow->add($vbox);				$this	-> progressWindow->connect('destroy',array($this,'close'));				$this	-> progressWindow->set_modal(true);				$this	-> progressWindow->show_all();				gtk::main_iteration_do(false);				$this->attemptLogin();			}		}		function attemptLogin($e = null)		{			$this->progressPulse();						if (!$this->connection->loginTry(null,$this->username,$this->password))			{				gtk::timeout_remove($this->pulseTimer);				$this->errorMsg(null,$this->progressWindow,"Could Not Connect");				$this->close();			}			return false;		}		function progressPulse($e = null)		{			$this->progressBar->pulse();return true;		}		function errorMsg($e = null,$modal,$error)		{			$d = new GtkMessageDialog($modal,Gtk::DIALOG_MODAL,Gtk::MESSAGE_ERROR,Gtk::BUTTONS_OK,$error);			$d-> set_title('Error');			$d-> set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);			$d-> set_markup("The Following Errors Occured:\r\n<span foreground='red'>$error</span>");			$d-> run();			$d-> destroy();			return true;		}		function close($e = null)		{			gtk::main_quit();			die();		}	}	$conn = new PKQST_Handle();	$lrwin = new PKQST_Login();	$lrwin->connection = $conn;	$lrwin->create();?>GtkIO:<?phpclass GtkIO {  protected $gio_ids;  protected $fd;  protected $hostname;  protected $port;  protected $errno;    # fsocketopen error status  protected $errstr;  function __construct() {    $this->gio_ids = array();  }  function connect($hostname, $port) {    $this->hostname = $hostname;    $this->port = $port;    $this->fd = fsockopen($hostname, $port,       $this->errno, $this->errstr);    if(!$this->fd)      trigger_error("GtkIO::connect : connexion error : "        . "{$this->errstr} ({$this->errno})");    else {      $this->io_setup();    }    return $this->fd;  }  function io_setup() {    $this->gio_ids[Gtk::IO_IN]   =       Gtk::io_add_watch($this->fd, Gtk::IO_IN,         array($this, 'io_in'));    $this->gio_ids[Gtk::IO_OUT]  =       Gtk::io_add_watch($this->fd, Gtk::IO_OUT,           array($this, 'io_out'));    $this->gio_ids[Gtk::IO_HUP]  =       Gtk::io_add_watch($this->fd, Gtk::IO_HUP,           array($this, 'io_hup'));    $this->gio_ids[Gtk::IO_PRI]  =       Gtk::io_add_watch($this->fd, Gtk::IO_PRI,           array($this, 'io_pri'));    $this->gio_ids[Gtk::IO_ERR]  =       Gtk::io_add_watch($this->fd, Gtk::IO_ERR,           array($this, 'io_err'));    $this->gio_ids[Gtk::IO_NVAL] =       Gtk::io_add_watch($this->fd, Gtk::IO_NVAL,          array($this, 'ion_val'));  }    function write($data) {    return fwrite($this->fd, $data, strlen($data));  }    # very incomplete : need to handle errors ...  function read($size = 2048) {    return fread($this->fd, $size);  }    function eof() {    return feof($this->fd);  }    function io_in($gio_channel, $conditions) {    echo "GtkIO::io_in()\n";  }  function io_out($gio_channel, $conditions) {    echo "GtkIO::io_out()\n";  }  function io_hup($gio_channel, $conditions) {    echo "GtkIO::io_hup()\n";  }  function io_pri($gio_channel, $conditions) {    echo "GtkIO::io_pri()\n";  }  function io_err($gio_channel, $conditions) {    echo "GtkIO::io_err()\n";  }}?>