Diff
Modified: desktop/trunk/docs/authors.txt (63 => 64)
--- desktop/trunk/docs/authors.txt 2006-12-08 22:38:45 UTC (rev 63)
+++ desktop/trunk/docs/authors.txt 2006-12-10 18:09:56 UTC (rev 64)
@@ -1,2 +1,5 @@
Elizabeth Marie Smith aka Aurora Eos Rose
-<emsmith@callicore.net>
\ No newline at end of file
+<emsmith@callicore.net>
+
+Leon Pegg
+<leon.pegg@gmail.com>
\ No newline at end of file
Modified: desktop/trunk/lib/actions.class.php (63 => 64)
--- desktop/trunk/lib/actions.class.php 2006-12-08 22:38:45 UTC (rev 63)
+++ desktop/trunk/lib/actions.class.php 2006-12-10 18:09:56 UTC (rev 64)
@@ -295,6 +295,10 @@
$signal = 'activate';
}
$action->set_property('short-label', isset($def['short-label']) ? CC::i18n($def['short-label']) : NULL);
+ if (isset($def['active']))
+ {
+ $action->set_active($def['active']);
+ }
if (isset($def['callback']))
{
$action->connect($signal, $def['callback']);
Modified: desktop/trunk/lib/cc.class.php (63 => 64)
--- desktop/trunk/lib/cc.class.php 2006-12-08 22:38:45 UTC (rev 63)
+++ desktop/trunk/lib/cc.class.php 2006-12-10 18:09:56 UTC (rev 64)
@@ -54,7 +54,7 @@
/**
* @var string program to run
*/
- static protected $program;
+ static public $program;
/**
* @var string root callicore dir
@@ -90,6 +90,7 @@
define('EOL', PHP_EOL, true);
// CC root - whack off one dir
self::$dir = dirname((dirname(__FILE__))) . DS;
+ self::$program = ucfirst(strtolower($program));
// set up translation
if (extension_loaded('gettext'))
{
@@ -114,10 +115,9 @@
Gtk::rc_parse(self::$dir . 'stock_icons' . DS . 'stock.rc');
Gtk::rc_parse(self::$dir . 'cc_icons' . DS . 'callicore.rc');
- self::$program = $program;
spl_autoload_register(array(__CLASS__, 'autoload'));
- $class = 'CC_' . ucfirst(strtolower($program));
+ $class = 'CC_' . self::$program;
new $class();
return;
}
Modified: desktop/trunk/lib/config.class.php (63 => 64)
--- desktop/trunk/lib/config.class.php 2006-12-08 22:38:45 UTC (rev 63)
+++ desktop/trunk/lib/config.class.php 2006-12-10 18:09:56 UTC (rev 64)
@@ -58,7 +58,7 @@
*
* @return void
*/
- public function __construct($program = 'Callicore')
+ public function __construct()
{
if (!is_null(self::$singleton))
{
@@ -68,9 +68,9 @@
}
self::$singleton = $this;
- $this->program = $program;
+ $this->program = CC::$program;
$folders = CC_Folders::instance();
- $this->file = $folders->get_appdata() . strtolower($program) . '.config.ini';
+ $this->file = $folders->get_appdata() . strtolower($this->program) . '.config.ini';
if (file_exists($this->file))
{
$this->data = parse_ini_file($this->file);
Added: desktop/trunk/lib/main.class.php (63 => 64)
--- desktop/trunk/lib/main.class.php 2006-12-08 22:38:45 UTC (rev 63)
+++ desktop/trunk/lib/main.class.php 2006-12-10 18:09:56 UTC (rev 64)
@@ -0,0 +1,372 @@
+<?php
+/**
+ * main.class.php - default setup for a "main" window for a program
+ *
+ * general purpose window with a statusbar, menubar and single toolbar along
+ * with a main layout area
+ *
+ * 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 desktop
+ * @category lib
+ * @filesource
+ */
+
+/**
+ * CC_Main - basic window layout for main window
+ *
+ * takes care of status bar building, some generalized actions, and even registers
+ * a standard quit item while building a generic "main window" ui layout
+ */
+abstract class CC_Main extends CC_Window
+{
+ /**
+ * main vbox for window
+ * @var $vbox object instanceof GtkVBox
+ */
+ public $vbox;
+
+ /**
+ * main menu for the window
+ * @var $menu object instanceof GtkMenu
+ */
+ public $menu;
+
+ /**
+ * toolbar for the window
+ * @var $toolbar object instanceof CC_Toolbar
+ */
+ public $toolbar;
+
+ /**
+ * status bar for window
+ * @var $statusbar object instanceof GtkStatusBar
+ */
+ public $statusbar;
+
+ //-------- Items that should be overridden -------------
+
+ /**
+ * website url to open
+ * @var $website string
+ */
+ protected $website = 'http://callicore.net/desktop';
+
+ /**
+ * menu bar definition
+ * @var $menubar array
+ */
+ protected $menubar = array(
+ '_File' => array(
+ 'file:quit',
+ ),
+ '_View' => array(
+ 'toolbar:toggle',
+ 'view:fullscreen',
+ ),
+ '_Help' => array(
+ 'help:help',
+ 'help:website',
+ 'separator',
+ 'help:about',
+ ),
+ );
+
+ /**
+ * options available for toolbar
+ * @var $tooloptions array
+ */
+ protected $tooloptions = array(
+ 'file:quit',
+ 'view:fullscreen',
+ 'help:help',
+ 'help:website',
+ 'help:about'
+ );
+
+ /**
+ * default toolbar layout
+ * @var $tooldefault array
+ */
+ protected $tooldefault = array(
+ 'file:quit',
+ 'view:fullscreen',
+ 'separator',
+ 'help:help',
+ 'help:website',
+ 'help:about'
+ );
+
+ //----------------------------------------------------------------
+ // Setup
+ //----------------------------------------------------------------
+
+ /**
+ * public function __construct
+ *
+ * Create a new CharacterWindow instance and build internal gui items
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+
+ parent::__construct();
+ CC_Wm::add_window($this);
+
+ $this->register_actions();
+ $this->build_toolbar();
+ $this->build_menu();
+ $this->build_statusbar();
+
+ $vbox = $this->vbox = new GtkVBox();
+ $vbox->pack_start($this->menu, false, false);
+ $vbox->pack_start($this->toolbar, false, false);
+ $vbox->pack_end($this->statusbar, false, false);
+ $this->add($vbox);
+
+ $this->connect_simple('destroy', array('Gtk', 'main_quit'));
+ return;
+ }
+
+ /**
+ * protected function register_actions
+ *
+ * creates generic window actions
+ *
+ * @todo add additional generic actions
+ * @return void
+ */
+ protected function register_actions()
+ {
+ $actions = CC_Actions::instance();
+ $this->add_accel_group($actions->get_accel());
+
+ $actions->add_action('file',
+ array(
+ 'type' => 'action',
+ 'name' => 'quit',
+ 'label' => '_Quit',
+ 'short-label' => '_Quit',
+ 'tooltip' => 'Exit program',
+ 'accel' => '<Ctrl>q',
+ 'callback' => array($this, 'on_quit'),
+ 'image' => 'gtk-quit',
+ )
+ );
+
+ $actions->add_action('view',
+ array(
+ 'type' => 'toggle',
+ 'name' => 'fullscreen',
+ 'label' => '_Fullscreen',
+ 'short-label' => '_Fullscreen',
+ 'tooltip' => 'Change to fullscreen mode',
+ 'accel' => 'F11',
+ 'callback' => array($this, 'on_fullscreen'),
+ 'image' => 'gtk-fullscreen',
+ 'active' => $this->fullscreen,
+ )
+ );
+
+ $actions->add_actions('help', array(
+ array(
+ 'type' => 'action',
+ 'name' => 'help',
+ 'label' => '_Help',
+ 'short-label' => '_Help',
+ 'tooltip' => 'Open help',
+ 'accel' => 'F1',
+ 'callback' => array($this, 'on_help'),
+ 'image' => 'gtk-help',
+ ),
+ array(
+ 'type' => 'action',
+ 'name' => 'website',
+ 'label' => '_Website',
+ 'short-label' => '_Website',
+ 'tooltip' => 'Visit Callicore website',
+ 'callback' => array($this, 'on_website'),
+ 'image' => 'cc-browser',
+ ),
+ array(
+ 'type' => 'action',
+ 'name' => 'about',
+ 'label' => '_About',
+ 'short-label' => '_About',
+ 'tooltip' => 'About Callicore',
+ 'callback' => array($this, 'on_about'),
+ 'image' => 'gtk-about',
+ ),
+ ));
+
+ return;
+ }
+
+ //----------------------------------------------------------------
+ // UI building
+ //----------------------------------------------------------------
+
+ /**
+ * protected function build_toolbar
+ *
+ * todo - pass default and options and name to new toolbar
+ *
+ * @return void
+ */
+ protected function build_toolbar()
+ {
+ $this->toolbar = new CC_Toolbar($this->name, $this->tooldefault, $this->tooloptions);
+ return;
+ }
+
+ /**
+ * protected function build_menu
+ *
+ * build a default menubar
+ * file quit, view options
+ *
+ * @return void
+ */
+ protected function build_menu()
+ {
+ $menu = $this->menu = new GtkMenuBar();
+ $actions = CC_Actions::instance();
+
+ foreach( $this->menubar as $name => $def)
+ {
+ $item = new GtkMenuItem(CC::i18n($name));
+ $menu->add($item);
+ $submenu = new GtkMenu();
+ $item->set_submenu($submenu);
+ foreach ($def as $name)
+ {
+ if( $name == 'separator')
+ {
+ $submenu->append(new GtkSeparatorMenuItem());
+ }
+ else
+ {
+ list($group, $action) = explode(':', $name);
+ $submenu->append($actions->create_menu_item($group, $action));
+ }
+ }
+ }
+ return;
+ }
+
+ /**
+ * protected function build_statusbar
+ *
+ * exposes frame and label for easy manipulation, and sets a name
+ *
+ * @return void
+ */
+ protected function build_statusbar()
+ {
+ $this->statusbar = new GtkStatusbar();
+ if (empty($this->statusbar->name))
+ {
+ $this->statusbar->set_name($this->get_name());
+ }
+ // constructs a gtkframe with a gtklabel inside
+ $children = $this->statusbar->get_children();
+ $this->statusbar->frame = $children[0];
+ $this->statusbar->label = $children[0]->child;
+ $this->statusbar->label->set_padding(3, 0);
+ $this->statusbar->label->set_label(CC::i18n('Ready'));
+ $this->statusbar->label->set_use_markup(TRUE);
+ return;
+ }
+
+ //----------------------------------------------------------------
+ // Callbacks
+ //----------------------------------------------------------------
+
+ /**
+ * public function on_quit
+ *
+ * exits the program
+ *
+ * @return void
+ */
+ public function on_quit()
+ {
+ $dialog = new CC_Message('Are you sure you want to quit?', 'Exit...',
+ CC_Message::QUESTION, CC::$program);
+ if ($dialog->run() == Gtk::RESPONSE_YES)
+ {
+ $this->on_state_save();
+ $this->destroy();
+ }
+ else
+ {
+ $dialog->destroy();
+ }
+ return;
+ }
+
+ /**
+ * public function on_fullscreen
+ *
+ * toggles fullscreen on and off
+ *
+ * @return void
+ */
+ public function on_fullscreen()
+ {
+ $actions = CC_Actions::instance();
+ if ($this->fullscreen)
+ {
+ $this->unfullscreen();
+ $actions->get_action('view', 'fullscreen')->set_property('stock-id', 'gtk-fullscreen');
+ $actions->get_action('view', 'fullscreen')->set_property('tooltip', 'Change to fullscreen mode');
+ }
+ else
+ {
+ $this->fullscreen();
+ $actions->get_action('view', 'fullscreen')->set_property('stock-id', 'gtk-leave-fullscreen');
+ $actions->get_action('view', 'fullscreen')->set_property('tooltip', 'Return to regular mode');
+ }
+ return;
+ }
+
+ /**
+ * public function on_help
+ *
+ * displays some kind of help for the app
+ *
+ * @return void
+ */
+ abstract public function on_help();
+
+ /**
+ * public function on_website
+ *
+ * launches a website url
+ *
+ * @return void
+ */
+ public function on_website()
+ {
+ CC_Folders::instance()->open_file($this->website);
+ return;
+ }
+
+ /**
+ * public function on_about
+ *
+ * displays information about the app
+ *
+ * @return void
+ */
+ abstract public function on_about();
+}
+?>
\ 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
Modified: desktop/trunk/lib/message.class.php (63 => 64)
--- desktop/trunk/lib/message.class.php 2006-12-08 22:38:45 UTC (rev 63)
+++ desktop/trunk/lib/message.class.php 2006-12-10 18:09:56 UTC (rev 64)
@@ -67,16 +67,23 @@
* @param int $type one of self::INFO, self::WARNING, self::ERROR
* @return void
*/
- public function __construct($message, $title = 'Default Message', $type = self::INFO, $program = 'Callicore')
+ public function __construct($message, $title = 'Default Message', $type = self::INFO)
{
if ($type !== self::ERROR && $type !== self::WARNING && $type !== self::QUESTION)
{
$type = self::INFO;
}
- parent::__construct(null, 0, $type, Gtk::BUTTONS_CLOSE);
+ if($type == self::QUESTION)
+ {
+ parent::__construct(null, 0, $type, Gtk::BUTTONS_YES_NO);
+ }
+ else
+ {
+ parent::__construct(null, 0, $type, Gtk::BUTTONS_CLOSE);
+ }
$this->set_position(Gtk::WIN_POS_CENTER);
- $this->set_title(CC::i18n('%s : %s', $program, $title));
+ $this->set_title(CC::i18n('%s : %s', CC::$program, $title));
if (is_array($message))
{
$this->set_markup(CC::i18n(array_shift($message), $message));
Modified: desktop/trunk/lib/window.class.php (63 => 64)
--- desktop/trunk/lib/window.class.php 2006-12-08 22:38:45 UTC (rev 63)
+++ desktop/trunk/lib/window.class.php 2006-12-10 18:09:56 UTC (rev 64)
@@ -72,9 +72,29 @@
$this->set_name(strtolower(get_class($this)));
}
+ // size and config restoration cannot be done during show signal
+ $name = $this->name;
+ $config = CC_Config::instance();
+
+ // 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->fullscreen = isset($config->{$name . '_fullscreen'}) ? (bool) $config->{$name . '_fullscreen'} : false;
+ $this->maximized = isset($config->{$name . '_maximized'}) ? (bool) $config->{$name . '_maximized'} : false;
+ $this->minimized = isset($config->{$name . '_minimized'}) ? (bool) $config->{$name . '_minimized'} : false;
+
$this->connect('window-state-event', array($this, 'on_state_event'));
$this->connect_simple('delete-event', array($this, 'on_state_save'));
- $this->on_state_restore();
+ $this->connect_simple('show', array($this, 'on_state_restore'));
return;
}
@@ -86,13 +106,9 @@
* @param string $name title to set
* @return void
*/
- public function set_title($title, $program = null)
+ public function set_title($title)
{
- if (empty($this->program))
- {
- $this->program = $program;
- }
- parent::set_title(CC::i18n('%s :: %s', $this->program, $title));
+ parent::set_title(CC::i18n('%s :: %s', CC::$program, $title));
return;
}
@@ -109,7 +125,7 @@
*/
public function hide_all()
{
- if (class_exists('CC_WM') && CC_WM::is_window($this->get_name()) &&
+ if (class_exists('CC_Wm') && CC_Wm::is_window($this->get_name()) &&
$this->modal)
{
parent::grab_remove();
@@ -132,7 +148,7 @@
*/
public function show_all($modal = false)
{
- if (class_exists('CC_WM') && CC_WM::is_window($this->get_name()))
+ if (class_exists('CC_Wm') && CC_Wm::is_window($this->get_name()))
{
$return = parent::show_all();
parent::grab_add();
@@ -162,9 +178,9 @@
$config = CC_Config::instance();
// unmax/min/fullscreen
- $config->{$name . '_fullscreen'} = $this->fullscreen;
- $config->{$name . '_maximized'} = $this->maximized;
- $config->{$name . '_minimized'} = $this->minimized;
+ $config->{$name . '_fullscreen'} = (bool) $this->fullscreen;
+ $config->{$name . '_maximized'} = (bool) $this->maximized;
+ $config->{$name . '_minimized'} = (bool) $this->minimized;
if ($this->minimized)
{
@@ -174,20 +190,20 @@
{
$this->unmaximize();
}
- elseif ($this->fullscreen)
+ if ($this->fullscreen)
{
$this->unfullscreen();
}
// size
list($height, $width) = $this->get_size();
- $config->{$name . '_height'} = $height;
- $config->{$name . '_width'} = $width;
+ $config->{$name . '_height'} = (int) $height;
+ $config->{$name . '_width'} = (int) $width;
// position
list($x, $y) = $this->get_position();
- $config->{$name . '_x'} = $x;
- $config->{$name . '_y'} = $y;
+ $config->{$name . '_x'} = (int) $x;
+ $config->{$name . '_y'} = (int) $y;
$this->destroy();
return;
@@ -196,40 +212,21 @@
/**
* public function on_state_restore
*
- * restores a window state
+ * restores a window state - has to be done as show handler or fullscreen bails
*
* @return void
*/
public function on_state_restore()
{
- $name = $this->name;
- $config = CC_Config::instance();
-
- // 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))
+ if ($this->fullscreen)
{
- $this->move($x, $y);
- }
-
- $fullscreen = isset($config->{$name . '_fullscreen'}) ? (bool) $config->{$name . '_fullscreen'} : FALSE;
- $maximized = isset($config->{$name . '_maximized'}) ? (bool) $config->{$name . '_maximized'} : FALSE;
- $minimized = isset($config->{$name . '_minimized'}) ? (bool) $config->{$name . '_minimized'} : FALSE;
-
- if ($fullscreen)
- {
$this->fullscreen();
}
- if ($maximized)
+ elseif ($this->maximized)
{
$this->maximize();
}
- if ($minimized)
+ if ($this->minimized)
{
$this->iconify();
}
Modified: desktop/trunk/lib/wm.class.php (63 => 64)
--- desktop/trunk/lib/wm.class.php 2006-12-08 22:38:45 UTC (rev 63)
+++ desktop/trunk/lib/wm.class.php 2006-12-10 18:09:56 UTC (rev 64)
@@ -24,7 +24,7 @@
*
* contains all static methods
*/
-class CC_WM
+class CC_Wm
{
/**
* GtkWindow object array
@@ -104,7 +104,7 @@
*/
public static function get_window($name)
{
- if ($name !== '' && array_key_exists($name, self::$$windows))
+ if ($name !== '' && array_key_exists($name, self::$windows))
{
return self::$windows[$name];
}