Revision
41
Author
emsmith
Date
2006-12-01 08:47:06 -0800 (Fri, 01 Dec 2006)

Log Message

Started the CC_ prefix, window and config are moved from writer, main is basics from old writer base class

Added Paths

Diff

Copied: desktop/trunk/lib/config.class.php (from rev 40, desktop/trunk/programs/writer/lib/config.class.php) (40 => 41)


--- desktop/trunk/programs/writer/lib/config.class.php	2006-11-30 20:05:37 UTC (rev 40)
+++ desktop/trunk/lib/config.class.php	2006-12-01 16:47:06 UTC (rev 41)
@@ -0,0 +1,209 @@
+<?php
+/**
+ * config.class.php - Callicore configuration and preferences
+ *
+ * user configuration for each individual program is stored in $appdata/program.config.ini
+ *
+ * This is released under the GPL, see license.txt for details
+ *
+ * @author       Elizabeth Smith <emsmith@callicore.net>
+ * @copyright    Elizabeth Smith (c)2006
+ * @link         http://callicore.net/writer
+ * @license      http://www.opensource.org/licenses/gpl-license.php GPL
+ * @version      $Id$
+ * @since        Php 5.2.0
+ * @package      callicore
+ * @subpackage   writer
+ * @category     lib
+ * @filesource
+ */
+
+/**
+ * CC_Config - reads in an ini file to get configuration settings
+ *
+ * Writes out to file when a configuration option is changed
+ * right now the whole file is rewritten - that may change in the future
+ */
+class CC_Config
+{
+
+	/**
+	 * singleton instance for this class
+	 * @var $singleton instanceof config
+	 */
+	static protected $singleton;
+
+	/**
+	 * multi-dim array of current configuration information
+	 * @var $data array
+	 */
+	protected $data;
+
+	/**
+	 * location of config file
+	 * @var $file string
+	 */
+	protected $file;
+
+	/**
+	 * name of program we're writing for
+	 * @var $program string
+	 */
+	protected $program;
+
+	/**
+	 * public function __construct
+	 *
+	 * Will load in a current config file and optionally create a new one
+	 *
+	 * @return void
+	 */
+	public function __construct($program = 'Callicore')
+	{
+		if(!is_null(self::$singleton))
+		{
+			throw new Exception(CC_Main::i18n(
+			'%1$s is a singleton class - use %1$s::instance() to retrieve the current object',
+			'CC_Config'));
+		}
+		self::$singleton = $this;
+
+		$this->program = $program;
+		$folders = CC_Folders::instance();
+		$this->file = $folders->getAppdata() . strtolower($program) . 'config.ini';
+		if(file_exists($file))
+		{
+			$this->data = parse_ini_file($this->file);
+		}
+		else
+		{
+			$this->data = array();
+			$this->writeFile();
+		}
+		unset($folders, $program, $this);
+		return;
+	}
+
+	/**
+	 * public function __get
+	 *
+	 * gets item from data store
+	 *
+	 * @param string $name
+	 * @return mixed
+	 */
+	protected function __get($name)
+	{
+		if(isset($this->data[$name]))
+		{
+			return $this->data[$name];
+		}
+		return;
+	}
+
+	/**
+	 * public function __isset
+	 *
+	 * checks if item is set in data store
+	 *
+	 * @param string $name
+	 * @return mixed
+	 */
+	protected function __isset($name)
+	{
+		return isset($this->data[$name]);
+	}
+
+	/**
+	 * public function __set
+	 *
+	 * sets an item in the data store and writes out the file
+	 *
+	 * @param string $name
+	 * @param mixed $value
+	 * @return void
+	 */
+	protected function __set($name, $value)
+	{
+		$this->data[$name] = $value;
+		$this->writeFile();
+		unset($name, $value);
+		return;
+	}
+
+	/**
+	 * public function __unset
+	 *
+	 * removes item from the data store and writes out the file
+	 *
+	 * @param string $name
+	 * @return void
+	 */
+	protected function __unset($name)
+	{
+		unset($this->data[$name]);
+		$this->writeFile();
+		unset($name);
+		return;
+	}
+
+	protected function writeFile()
+	{
+		$string = ';Preferences and Configuration for Callicore ' . $this->program
+			. EOL . '; Saved ' . date('Y-m-d H:i:s') . EOL . EOL;
+		foreach($this->data as $key => $value)
+		{
+			if(is_array($value))
+			{
+				$key = preg_replace('/[' . preg_quote('{}|&~![()"') . ']/', '', $key) . '[]';
+				foreach($value as $subvalue)
+				{
+					$string .= $key . ' = "' . str_replace('"', '', $subvalue) . '"' . EOL;
+				}
+			}
+			elseif(is_bool($value))
+			{
+				$string .= preg_replace('/[' . preg_quote('{}|&~![()"') . ']/', '', $key)
+					. ' = ' . (($value == TRUE) ? 'TRUE' : 'FALSE') . EOL;
+			}
+			else
+			{
+				$string .= preg_replace('/[' . preg_quote('{}|&~![()"') . ']/', '', $key)
+					. ' = "' . str_replace('"', '', $value) . '"' . EOL;
+			}
+		}
+		file_put_contents($this->file, $string);
+		unset($string, $subvalue, $key, $value);
+		return;
+	}
+
+	/**
+	 * static public function instance
+	 *
+	 * this is how items can access the config
+	 *
+	 * @return object instanceof CC_Config
+	 */
+	static public function instance()
+	{
+		if(is_null(self::$singleton))
+		{
+			self::$singleton = new CC_Config();
+		}
+		return self::$singleton;
+	}
+
+	/**
+	 * public function __clone()
+	 *
+	 * disable cloning of a singleton
+	 *
+	 * @return void
+	 */
+	public function __clone()
+	{
+		throw new Exception(CC_Main::i18n('Cannot clone singleton object %s', 'CC_Config'));
+		return;
+	}
+}
+?>
\ No newline at end of file

Added: desktop/trunk/lib/folders.class.php (40 => 41)


--- desktop/trunk/lib/folders.class.php	2006-11-30 20:05:37 UTC (rev 40)
+++ desktop/trunk/lib/folders.class.php	2006-12-01 16:47:06 UTC (rev 41)
@@ -0,0 +1,436 @@
+<?php
+/**
+ * folders.class.php - handles looking up special folders 
+ *
+ * singleton instance that looks up the location of preferences, appdata, documents,
+ * home, and temp directories, also handles OS specific file opening
+ *
+ * This is released under the GPL, see license.txt for details
+ *
+ * @author       Elizabeth Smith <emsmith@callicore.net>
+ * @copyright    Elizabeth Smith (c)2006
+ * @link         http://callicore.net/writer
+ * @license      http://www.opensource.org/licenses/gpl-license.php GPL
+ * @version      $Id$
+ * @since        Php 5.2.0
+ * @package      callicore
+ * @subpackage   writer
+ * @category     lib
+ * @filesource
+ */
+
+/**
+ * CC_Folders - detects "special folders" locations per OS
+ *
+ * all locations are cached for now
+ */
+class CC_Folders
+{
+	/**
+	 * @const LINUX OS
+	 */
+	const LINUX = 1;
+
+	/**
+	 * @const UNIX OS
+	 */
+	const UNIX = 2;
+
+	/**
+	 * @const WIN32 OS
+	 */
+	const WIN32 = 3;
+
+	/**
+	 * @const WINNT OS
+	 */
+	const WINNT = 4;
+
+	/**
+	 * @const MAC OS
+	 */
+	const MAC = 5;
+
+	/**
+	 * @const GNOME Desktop
+	 */
+	const GNOME = 6;
+
+	/**
+	 * @const KDE Desktop
+	 */
+	const KDE = 7;
+
+	/**
+	 * @const OTHER (unknown) Desktop
+	 */
+	const OTHER = 8;
+
+	/**
+	 * singleton instance for this class
+	 * @var $singleton instanceof Characters
+	 */
+	static protected $singleton;
+
+	/**
+	 * one of the OS constants
+	 * @var $os int
+	 */
+	protected $os;
+
+	/**
+	 * one of the desktop constants
+	 * @var $desktop int
+	 */
+	protected $desktop;
+
+	/**
+	 * location of temporary directory
+	 * @var $temp string
+	 */
+	protected $temp;
+
+	/**
+	 * "home" location on *nix and profile directory on windows
+	 * @var $profile string
+	 */
+	protected $profile;
+
+	/**
+	 * location of My Documents (Documents folder on most *nix varieties)
+	 * @var $documents string
+	 */
+	protected $documents;
+
+	/**
+	 * application data location (with callicore subdir tacked on)
+	 * @var $appdata string
+	 */
+	protected $appdata;
+
+	/**
+	 * public function __construct
+	 *
+	 * Uses PHP_OS to get a "general" OS name and tries to figure out the
+	 * current desktop system
+	 *
+	 * @return void
+	 */
+	public function __construct()
+	{
+		if(!is_null(self::$singleton))
+		{
+			throw new Exception(CC_Main::i18n(
+			'%1$s is a singleton class - use %1$s::instance() to retrieve the current object',
+			'CC_Folders'));
+		}
+		self::$singleton = $this;
+
+		if(stristr(PHP_OS, 'winnt'))
+		{
+			$this->os = self::WINNT;
+		}
+		elseif(stristr(PHP_OS, 'win32'))
+		{
+			$this->os = self::WIN32;
+		}
+		elseif(stristr(PHP_OS, 'darwin') || stristr(PHP_OS, 'mac'))
+		{
+			$this->os = self::MAC;
+		}
+		elseif(stristr(PHP_OS, 'linux'))
+		{
+			$this->os = self::LINUX;
+		}
+		elseif(stristr(PHP_OS, 'freebsd') || stristr(PHP_OS, 'aix') || stristr(PHP_OS, 'unix'))
+		{
+			$this->os = self::UNIX;
+		}
+		else
+		{
+			$this->os = self::UNKNOWN;
+		}
+		if((isset($_ENV['KDE_FULL_SESSION']) && $_ENV['KDE_FULL_SESSION'] == 'true') ||
+			(isset($_ENV['KDE_MULTIHEAD']) && $_ENV['KDE_MULTIHEAD'] == 'true'))
+		{
+			$this->desktop = self::KDE;
+		}
+		elseif(isset($_ENV['GNOME_DESKTOP_SESSION_ID']) || isset($_ENV['GNOME_KEYRING_SOCKET']))
+		{
+			$this->desktop = self::GNOME;
+		}
+		else
+		{
+			$this->desktop = self::UNKNOWN;
+		}
+		return;
+	}
+
+	/**
+	 * public function getOS
+	 *
+	 * returns os constant
+	 *
+	 * @return int
+	 */
+	public function getOS()
+	{
+		return $this->os;
+	}
+
+	/**
+	 * public function getAppdata
+	 *
+	 * finds appdata dependent on env variables and OS, adds callicore specific
+	 * dir if needed
+	 *
+	 * @return void
+	 */
+	public function getAppdata()
+	{
+		if(is_null($this->appdata))
+		{
+			// check environment variables for appdata
+			if(isset($_ENV['APPDATA']))
+			{
+				$this->appdata = $_ENV['APPDATA'] . DS . 'Callicore' . DS;
+			}
+			// if win doesn't have appdata, we force the issue in the user profile
+			elseif($this->os == self::WIN32 || $this->os == self::WINNT)
+			{
+				$path = $this->getProfile() . 'Application Data' . DS;
+				if(!file_exists($path))
+				{
+					mkdir($path);
+				}
+				$this->appdata = $path . 'Callicore' . DS;
+				unset($path);
+			}
+			// darwin puts things in $HOME/Library/Application Support/Callicore/
+			elseif($this->os == self::MAC)
+			{
+				$this->appdata = $this->getProfile() . 'Library/Application Support/Callicore' . DS;
+			}
+			// most *nix want ~/.callicore
+			else
+			{
+				$this->appdata = $this->getProfile() . '.callicore' . DS;
+			}
+			if(!file_exists($this->appdata))
+			{
+				mkdir($this->appdata);
+			}
+		}
+		return $this->appdata;
+	}
+
+	/**
+	 * public function getProfile
+	 *
+	 * finds windows user profile and *nix users "home" location
+	 *
+	 * @return void
+	 */
+	public function getProfile()
+	{
+		if(is_null($this->profile))
+		{
+			if($this->os == self::WINNT || $this->os == self::WIN32)
+			{
+				$env = $_ENV + $_SERVER;
+				if(isset($env['USERPROFILE']))
+				{
+					$this->profile = $env['USERPROFILE'] . DS;
+				}
+				elseif(isset($env['HOMEPATH']) && isset($env['HOMEDRIVE']))
+				{
+					$this->profile = $env['HOMEPATH'] . $env['HOMEDRIVE'] . DS;
+				}
+				elseif(isset($env['USERNAME']) && file_exists('C:\Documents and Settings\\' . $env['USERNAME']))
+				{
+					$this->profile = 'C:\Documents and Settings\\' . $env['USERNAME'] . DS;
+				}
+				else
+				{
+					$this->profile = DIR;
+				}
+				unset($env);
+			}
+			else
+			{
+				if(isset($_ENV['HOME']))
+				{
+					$this->profile = $_ENV['HOME'] . DS;
+				}
+				elseif($this->os == self::MAC && isset($_ENV['USER']) &&
+					file_exists('/Users/' . $_ENV['USER']))
+				{
+					$this->profile = '/Users/' . $_ENV['USER'] . DS;
+				}
+				elseif(sset($_ENV['USER']) &&
+					file_exists('/home/' . $_ENV['USER']))
+				{
+					$this->profile = '/home/' . $_ENV['USER'] . DS;
+				}
+				else
+				{
+					$this->profile = DIR;
+				}
+			}
+		}
+		return $this->profile;
+	}
+
+	/**
+	 * public function documents
+	 *
+	 * finds documents folder dependent on env variables and OS
+	 *
+	 * @return void
+	 */
+	public function getDocuments()
+	{
+		// we always use wscript and com on windows because we want "my documents"
+		if(is_null($this->documents))
+		{
+			if($this->os == self::WINNT || $this->os == self::WIN32)
+			{
+				$shell = new COM('WScript.Shell');
+				$this->documents = $shell->SpecialFolders('MyDocuments');
+				unset($shell);
+			}
+			else
+			{
+				$home = $this->getProfile();
+				if(file_exists($home . 'Documents'))
+				{
+					$this->documents = $home . 'Documents' . DS;
+				}
+				else
+				{
+					$this->documents = $home;
+				}
+				unset($home);
+			}
+		}
+		return $this->documents;
+	}
+
+	/**
+	 * public function getTemp
+	 *
+	 * finds temp directory using best guesses per OS
+	 *
+	 * @return string
+	 */
+	public function getTemp()
+	{
+		if(is_null($this->temp))
+		{
+			$env = $_SERVER + $_ENV;
+			if(isset($env['TEMP']) && file_exists($env['TEMP']) && is_dir($env['TEMP']))
+			{
+				$this->temp = $env['TEMP'];
+			}
+			if(isset($env['TMP']) && file_exists($env['TMP']) && is_dir($env['TMP']))
+			{
+				$this->temp = $env['TMP'];
+			}
+			elseif(file_exists('/tmp/') && is_dir('/tmp/'))
+			{
+				$this->temp = '/tmp/';
+			}
+			else
+			{
+				$this->temp = $this->getProfile();
+			}
+			unset($env);
+		}
+		return $this->temp;
+	}
+
+	/**
+	 * public function launchFile
+	 *
+	 * creates command string and pipes it to exec to open a file with an external
+	 * app dependent on OS and desktop Windows uses com to avoid the extra dos window
+	 *
+	 * @param string $file file to open
+	 * @return bool
+	 */
+	public function launchFile($file)
+	{
+		if($this->os == self::LINUX || $this->os == self::UNIX)
+		{
+			// try to use desktop launch standard
+			if(isset($_ENV['DESKTOP_LAUNCH']))
+			{
+				$file = $_ENV['DESKTOP_LAUNCH'] . '"' . $file . '"';
+			}
+			elseif($this->desktop == self::KDE)
+			{
+				$file = 'kfmclient exec "' . $file . '"';
+			}
+			elseif($this->desktop == self::GNOME)
+			{
+				$file = 'gnome-open "' . $file . '"';
+			}
+			return exec($file);
+		}
+		elseif($this->os == self::WINNT)
+		{
+			$shell = new COM('WScript.Shell');
+			$return = $shell->Run('cmd /c start "" "' . $file . '"', 0, FALSE);
+			unset($shell, $file);
+			return (bool) $return;
+		}
+		elseif($this->os == self::WIN32)
+		{
+			$shell = new COM('WScript.Shell');
+			$return = $shell->Run('command /c start "" "' . $file . '"', 0, FALSE);
+			unset($shell, $file);
+			return (bool) $return;
+		}
+		elseif($this->os == self::MAC)
+		{
+			$file = 'open "' . $file . '"';
+			return exec($file);
+		}
+		else
+		{
+			return FALSE;
+		}
+		return;
+	}
+
+	/**
+	 * static public function instance
+	 *
+	 * this is how items can access the main window instance
+	 *
+	 * @return object instanceof CC_Writer
+	 */
+	static public function instance()
+	{
+		if(is_null(self::$singleton))
+		{
+			self::$singleton = new CC_Folders();
+		}
+		return self::$singleton;
+	}
+
+	/**
+	 * public function __clone()
+	 *
+	 * disable cloning of a singleton
+	 *
+	 * @return void
+	 */
+	public function __clone()
+	{
+		throw new Exception(CC_Main::i18n('Cannot clone singleton object %s', 'CC_Folders'));
+		return;
+	}
+
+}
+?>
\ No newline at end of file
Property changes on: desktop/trunk/lib/folders.class.php
___________________________________________________________________
Name: tsvn:logminsize
   + 15
Name: svn:keywords
   + Id
Name: svn:eol-style
   + LF

Added: desktop/trunk/lib/main.class.php (40 => 41)


--- desktop/trunk/lib/main.class.php	2006-11-30 20:05:37 UTC (rev 40)
+++ desktop/trunk/lib/main.class.php	2006-12-01 16:47:06 UTC (rev 41)
@@ -0,0 +1,227 @@
+<?php
+/**
+ * main.class.php - callicore's base class
+ *
+ * handles a few base functions - run decides which program to run and
+ * starts it, i18n is used for translation, requirements checked and
+ * autoloading is set up
+ *
+ * This is released under the GPL, see license.txt for details
+ *
+ * @author       Elizabeth Smith <emsmith@callicore.net>
+ * @copyright    Elizabeth Smith (c)2006
+ * @link         http://callicore.net/writer
+ * @license      http://www.opensource.org/licenses/gpl-license.php GPL
+ * @version      $Id$
+ * @since        Php 5.2.0
+ * @package      callicore
+ * @subpackage   writer
+ * @category     lib
+ * @filesource
+ */
+
+/**
+ * CC_Main - checks settings and manages common properties
+ *
+ * Basically a wrapper for important callicore functions
+ */
+class CC_Main
+{
+	/**
+	 * @const VERSION app version number
+	 */
+	const VERSION = '1.0.0-alpha';
+
+	/**
+	 * Icon sizes - these SHOULD be constants - but
+	 * you can't set class constants after the class is defined
+	 * so they're static vars instead - annoying
+	 *
+	 * sizes are 16, 18, 20, 14, 32, 48, 64 and 128 px square
+	 *
+	 * @var GtkEnum
+	 */
+	static public $MENU = Gtk::ICON_SIZE_MENU;
+	static public $SMALL_TOOLBAR = Gtk::ICON_SIZE_SMALL_TOOLBAR;
+	static public $BUTTON = Gtk::ICON_SIZE_BUTTON;
+	static public $LARGE_TOOLBAR = Gtk::ICON_SIZE_LARGE_TOOLBAR;
+	static public $DND = Gtk::ICON_SIZE_DND;
+	static public $DIALOG = Gtk::ICON_SIZE_DIALOG;
+	static public $LARGE;
+	static public $IMAGE;
+
+	/**
+	 * @var string program to run
+	 */
+	static protected $program;
+
+	/**
+	 * static public function run
+	 *
+	 * checks for requirements, figures out the right program to run, registers
+	 * base autoload, and does basic theme setup
+	 *
+	 * @param string $program 
+	 * @return void
+	 */
+	static public function run($program = NULL)
+	{
+		// set up translation
+		if(extension_loaded('gettext'))
+		{
+			// we use system locale
+			bindtextdomain('Callicore', DIR . 'locale');
+			textdomain('Callicore');
+		}
+		if(version_compare(PHP_VERSION, '5.2.0', '<'))
+		{
+			trigger_error(self::i18n('You must use php 5.2.0 or higher'), E_USER_ERROR);
+		}
+		$have = get_loaded_extensions();
+		$needed = array('standard', 'pcre', 'date', 'PDO', 'pdo_sqlite', 'php-gtk');
+		$diff = array_diff($needed, $have);
+		if(!empty($diff))
+		{
+			trigger_error(self::i18n('%s : %s', 'The following extensions must be loaded in your php.ini for Callicore to function', implode(', ', $diff)), E_USER_ERROR);
+		}
+		unset($have, $needed, $diff);
+
+		self::$LARGE = Gtk::icon_size_register('gtk-large',64, 64);
+		self::$IMAGE = Gtk::icon_size_register('gtk-image',128, 128);
+		Gtk::rc_parse(DIR . 'stock_icons' . DS . 'stock.rc');
+		Gtk::rc_parse(DIR . 'cc_icons' . DS . 'callicore.rc');
+
+		if(is_null($program))
+		{
+			if(isset($_SERVER['argv']) && isset($_SERVER['argv'][1]))
+			{
+				$program = (string) $_SERVER['argv'][1];
+			}
+		}
+		if(is_null($program))
+		{
+			trigger_error(self::i18n('You must supply a program to run'), E_USER_ERROR);
+		}
+		self::$program = $program;
+		spl_autoload_register(array(__CLASS__, 'autoload'));
+
+		$class = 'CC_' . ucfirst(strtolower($program));
+		new $class();
+
+		unset($class, $program);
+		return;
+	}
+
+	//----------------------------------------------------------------
+	//             static helper functions
+	//----------------------------------------------------------------
+
+	/**
+	 * public static function i18n
+	 *
+	 * wrapper for gettext + sprintf/vsprintf
+	 *
+	 * @param string $string string to translate
+	 * @return string translated string
+	 */
+	public static function i18n($string)
+	{
+		$args = func_get_args();
+		array_shift($args);
+		if(!empty($args) && count($args) == 1 && is_array($args[0]))
+		{
+			$args = $args[0];
+		}
+		if(function_exists('gettext'))
+		{
+			// if we have args, the first item is format only and not translated
+			if(is_array($args) && !empty($args))
+			{
+				$args = array_map('gettext', $args);
+			}
+			else
+			{
+				$string = gettext($string);
+			}
+		}
+		return vsprintf($string, $args);
+	}
+
+	/**
+	 * public static function setDefaultIcon
+	 *
+	 * uses add_builtin_icon and render_icon to make set_default_icon_name work
+	 *
+	 * @param string $icon icon name to use as default
+	 * @return void
+	 */
+	public static function setDefaultIcon($icon)
+	{
+		$theme = GtkIconTheme::get_for_screen(GdkScreen::get_default());
+		$window = new GtkWindow();
+
+		$theme->add_builtin_icon($icon, self::$MENU,
+			$window->render_icon($icon, self::$MENU));
+		$theme->add_builtin_icon($icon, self::$SMALL_TOOLBAR,
+			$window->render_icon($icon, self::$SMALL_TOOLBAR));
+		$theme->add_builtin_icon($icon, self::$BUTTON,
+			$window->render_icon($icon, self::$BUTTON));
+		$theme->add_builtin_icon($icon, self::$LARGE_TOOLBAR,
+			$window->render_icon($icon, self::$LARGE_TOOLBAR));
+		$theme->add_builtin_icon($icon, self::$DND,
+			$window->render_icon($icon, self::$DND));
+		$theme->add_builtin_icon($icon, self::$DIALOG,
+			$window->render_icon($icon, self::$DIALOG));
+		$theme->add_builtin_icon($icon, self::$LARGE,
+			$window->render_icon($icon, self::$LARGE));
+		$theme->add_builtin_icon($icon, self::$IMAGE,
+			$window->render_icon($icon, self::$IMAGE));
+
+		GtkWindow::set_default_icon_name($icon);
+		unset($window, $theme, $icon);
+		return;
+	}
+
+	/**
+	 * static public function autoload
+	 *
+	 * overrides php's basic autoload - we use this because you shouldn't have
+	 * a different autoload defined right now
+	 *
+	 * @param string $class class to include
+	 * @return bool
+	 */
+	static public function autoload($class)
+	{
+		preg_match_all('/[A-Z][a-z0-9_]*/', str_replace('CC_', '', $class), $matches);
+		$array = array_map('strtolower', $matches[0]);
+		unset($matches, $class);
+		$file = array_pop($array) . '.class.php';
+		if(!empty($array))
+		{
+			$array[] = '';
+		}
+
+		$program = DIR . 'programs' . DS . self::$program . DS . 'lib' . DS . implode(DS, $array) . $file;
+		$lib = DIR . 'lib' . DS . implode(DS, $array) . $file;
+
+		if(file_exists($program))
+		{
+			include $program;
+			$return = TRUE;
+		}
+		elseif(file_exists($lib))
+		{
+			include $lib;
+			$return = TRUE;
+		}
+		else
+		{
+			$return = FALSE;
+		}
+
+		unset($lib, $file, $array, $class, $matches, $program);
+		return $return;
+	}
+}
+?>
\ No newline at end of file
Property changes on: desktop/trunk/lib/main.class.php
___________________________________________________________________
Name: tsvn:logminsize
   + 15
Name: svn:keywords
   + Id
Name: svn:eol-style
   + LF

Copied: desktop/trunk/lib/window.class.php (from rev 40, desktop/trunk/programs/writer/lib/window.class.php) (40 => 41)


--- desktop/trunk/programs/writer/lib/window.class.php	2006-11-30 20:05:37 UTC (rev 40)
+++ desktop/trunk/lib/window.class.php	2006-12-01 16:47:06 UTC (rev 41)
@@ -0,0 +1,160 @@
+<?php
+/**
+ * window.class.php - window abstract class
+ *
+ * general purpose window code, handles menubar, toolbar and statusbar
+ * setup as well as general actions and other items
+ *
+ * This is released under the GPL, see license.txt for details
+ *
+ * @author       Elizabeth Smith <emsmith@callicore.net>
+ * @copyright    Elizabeth Smith (c)2006
+ * @link         http://callicore.net/writer
+ * @license      http://www.opensource.org/licenses/gpl-license.php GPL
+ * @version      $Id$
+ * @since        Php 5.2.0
+ * @package      callicore
+ * @subpackage   writer
+ * @category     lib
+ * @filesource
+ */
+
+/**
+ * CC_Window - basic window with menu, toolbar, status bar automagically created
+ *
+ * Streamlines creation of similiar windows and callbacks - handles automatic
+ * saving and returning x and y position, as well as height and width on windows
+ */
+abstract class CC_Window extends GtkWindow
+{
+
+	/**
+	 * main vbox for window
+	 * @var $vbox object instanceof GtkVBox
+	 */
+	public $vbox;
+
+	/**
+	 * status bar for window
+	 * @var $statusbar object instanceof GtkStatusBar
+	 */
+	public $statusbar;
+
+	//----------------------------------------------------------------
+	//             Overrides
+	//----------------------------------------------------------------
+
+	/**
+	 * public function __construct
+	 *
+	 * Create a new CharacterWindow instance and build internal gui items
+	 *
+	 * @return void
+	 */
+	public function __construct()
+	{
+
+		parent::__construct();
+
+		$config = Config::instance();
+
+		$this->set_name(strtolower(get_class($this)));
+		$name = $this->name;
+
+		// default size and location
+		$width = isset($config->{$name . '_height'}) ? (int) $config->{$name . '_height'} : 800;
+		$height = isset($config->{$name . '_width'}) ? (int) $config->{$name . '_width'} : 600;
+		$this->set_default_size($width, $height);
+
+		$x = isset($config->{$name . '_x'}) ? (int) $config->{$name . '_x'} : NULL;
+		$y = isset($config->{$name . '_y'}) ? (int) $config->{$name . '_y'} : NULL;
+		if(!is_null($x) && !is_null($y))
+		{
+			$this->move($x, $y);
+		}
+
+		//$this->buildActions();
+		//$this->buildMenu();
+		//$this->buildToolbar();
+		$this->buildStatusbar();
+
+		$vbox = $this->vbox = new GtkVBox();
+		//$vbox->pack_start($this->menu, 0, 0);
+		//$vbox->pack_start($this->toolbar, 0, 0);
+		$vbox->pack_end($this->statusbar, 0, 0);
+		$this->add($vbox);
+
+		unset($config, $height, $width, $x, $y, $name, $vbox, $this);
+		return;
+	}
+
+	/**
+	 * public function set_title
+	 *
+	 * overload set_title
+	 *
+	 * @param string $name title to set
+	 * @return void
+	 */
+	public function set_title($title, $program = 'Callicore')
+	{
+		parent::set_title(CC_Main::i18n('%s :: %s', $class, $title));
+		unset($title, $class);
+		return;
+	}
+
+	//----------------------------------------------------------------
+	//             Gui Creation
+	//----------------------------------------------------------------
+
+	/**
+	 * protected function buildStatusbar
+	 *
+	 * build statusbar - gets the label inside and pads it gently (because
+	 * windows is stupid, has little effect on other systems), and sets a label
+	 * property for easy statusbar manipulation
+	 *
+	 * @return void
+	 */
+	protected function buildStatusbar()
+	{
+		$status = $this->statusbar = new GtkStatusBar();
+		$children = $status->get_children();
+		$status->label = $children[0]->child;
+		$status->label->set_padding(3, 0);
+		$status->label->set_label(CC_Main::i18n('Ready'));
+		$status->label->set_use_markup(TRUE);
+		unset($status, $children);
+		return;
+	}
+
+	//----------------------------------------------------------------
+	//             Callbacks
+	//----------------------------------------------------------------
+
+	/**
+	 * public function onDeleteEvent
+	 *
+	 * callback for delete-event, saves window size and position
+	 *
+	 * @return void
+	 */
+	public function onDeleteEvent()
+	{
+		$name = $this->name;
+		$config = CC_Config::instance();
+
+		list($height, $width) = $this->get_size();
+		$config->{$name . '_height'} = $height;
+		$config->{$name . '_width'} = $width;
+
+		list($x, $y) = $this->get_position();
+		$config->{$name . '_x'} = $x;
+		$config->{$name . '_y'} = $y;
+
+		unset($config, $height, $width, $x, $y, $name);
+		$this->destroy();
+		return;
+	}
+}
+?>
\ No newline at end of file