Resources/js/d/dascyllus.js
author Mahlon E. Smith <mahlon@martini.nu>
Mon, 23 Sep 2013 09:10:55 -0700
changeset 1 b3419d05eabb
parent 0 80c32ef237c6
permissions -rw-r--r--
Checkpoint. * Got fonts working cross platform by only using SVG. This will change with the new webkit engine when Tide 1.4 is released. * Use the Tide API accessors for cross-window data. * Make the ThingFish server object an observable, so models and their URI bases can be changed easily. * Add options for saving window state and position. * Contextual menu updates/tests for later.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     1
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     2
/*######################################################################
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     3
### D A S C Y L L U S   N A M E S P A C E
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     4
######################################################################*/
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     5
var D = {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     6
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     7
	// Versions
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     8
	platform:     Ti.getPlatform(),
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     9
	name:         Ti.API.Application.getName(),
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    10
	version:      Ti.API.Application.getVersion(),
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    11
	ti_version:   Ti.getVersion(),
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    12
	architecture: Ti.Platform.getArchitecture(),
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    13
	copyright:    Ti.App.getCopyright(),
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    14
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    15
	// Declared windows, for easy referencing
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    16
	window: {},
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    17
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    18
	// Very first run of Dasycllus?
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    19
	firstrun: false,
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    20
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    21
	// Persistent storage DB handle.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    22
	db: null,
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    23
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    24
	// The primary main tray menu.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    25
	menu: null,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    26
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    27
	// The current TF server we're connected to.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    28
	//
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    29
	//     uri: http://localhost:8080/
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    30
	//     version: Thingfish 0.5.0 (build ...)
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    31
	//
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    32
	tf: new can.Observe({
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    33
		uri: null,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    34
		version: null
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    35
	}),
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    36
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    37
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    38
	// Actions to perform at startup.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    39
	//
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    40
	init: function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    41
		var D = this;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    42
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    43
		D.initDB();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    44
		D.window.main = Ti.UI.getMainWindow();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    45
		D.initMenu();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    46
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    47
		// Thingfish server object event handlers.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    48
		//
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    49
		D.tf.bind( 'uri', D.initTF );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    50
		var server_uri = D.getPref( 'server_uri' );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    51
		if ( server_uri ) D.tf.attr( 'uri', server_uri );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    52
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    53
		// Main window event handlers.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    54
		//
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    55
		D.window.main.addEventListener( 'moved', function() { D.saveWindowState(); });
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    56
		D.window.main.addEventListener( 'resized', function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    57
			D.delay( function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    58
				D.saveWindowState();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    59
			},
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    60
			500, true );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    61
		});
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    62
		$( document ).contextmenu( function() { D.window.main.setContextMenu( D.menu ); });
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    63
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    64
		// Each Tide window is an environment unto itself.  There is a global
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    65
		// key/val namespace, though.  Make the 'D' namespace accessible to other windows here.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    66
		Ti.API.set( 'D', D );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    67
	},
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    68
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    69
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    70
	// Determine if we should be running in developer mode.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    71
	// This requires that the user has previously enabled it in preferences,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    72
	// and the --debug command line option was passed.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    73
	//
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    74
	devmode: function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    75
		return Ti.App.getArguments()[0] == "--debug" && this.getBoolPref( 'devmode' );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    76
	},
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    77
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    78
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    79
	// Event handler for changing the Thingfish server URI.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    80
	// Sanity check and instantiate appropriate Model(s).
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    81
	//
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    82
	initTF: function( event, uri, old_uri ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    83
		var serverOk = function( data, status, xhr ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    84
			var info = xhr.getResponseHeader( 'x-thingfish' );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    85
			if ( ! info ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    86
				D.tf.attr( 'version', null );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    87
				D.notify( 'Unable to connect.', 'Not a Thingfish server?' );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    88
				return;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    89
			}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    90
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    91
			D.tf.attr( 'version', data.version )
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    92
			D.notify( 'Connected.', info );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    93
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    94
			// FIXME: models?
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    95
		};
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    96
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    97
		try {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    98
			$.ajax({
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
    99
				url:      uri + '/serverinfo',
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   100
				async:    false,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   101
				success:  serverOk,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   102
				error:    function( xhr, status, err ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   103
					D.tf.attr( 'version', null );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   104
					D.notify( 'Unable to connect.', err ? err : 'Network error.' );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   105
				},
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   106
				dataType: 'json'
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   107
			});
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   108
		}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   109
		catch( err ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   110
			console.log( err );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   111
		};
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   112
	},
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   113
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   114
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   115
	// Open a handle to the local database, initializing it
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   116
	// if necessary and performing rudamentary upwards migrations.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   117
	//
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   118
	initDB: function() {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   119
		this.db = Ti.Database.openFile(
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   120
			Ti.Filesystem.getFile(
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   121
				Ti.Filesystem.getApplicationDataDirectory(), 'dascyllus.db'
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   122
			)
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   123
		);
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   124
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   125
		var rv = this.db.execute( 'PRAGMA user_version' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   126
		var schema_version = parseInt( rv.fieldByName('user_version') );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   127
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   128
		var schemas_dir = Ti.Filesystem.getFile(
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   129
				Ti.Filesystem.getApplicationDirectory(), 'sql' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   130
		var current_version = schemas_dir.getDirectoryListing().length;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   131
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   132
		if ( schema_version == 0 ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   133
			this.notify( 'Welcome!', 'Dascyllus defaults installed.' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   134
			this.firstrun = true;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   135
		}
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   136
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   137
		if ( schema_version != current_version ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   138
			console.log( 'Dascyllus DB at version ' + schema_version +
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   139
					', needs to be upgraded to ' + current_version + '.' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   140
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   141
			while ( schema_version != current_version ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   142
				var update_version = schema_version + 1;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   143
				console.log( '  updating to version ' + update_version );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   144
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   145
				var line;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   146
				var schema_file = Ti.Filesystem.getFileStream(
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   147
						Ti.Filesystem.getApplicationDirectory(), 'sql', update_version + '.sql' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   148
				schema_file.open();
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   149
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   150
				this.db.execute( 'BEGIN' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   151
				while ( line = schema_file.readLine() ) this.db.execute( line.toString() );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   152
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   153
				this.db.execute( 'PRAGMA user_version = ' + update_version  );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   154
				this.db.execute( 'COMMIT' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   155
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   156
				schema_version = update_version;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   157
				schema_file.close();
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   158
			}
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   159
		}
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   160
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   161
		return this.db;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   162
	},
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   163
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   164
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   165
	// Return a preference's current value, or null if nonexistent.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   166
	//
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   167
	getPref: function( pref ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   168
		var row = this.db.execute( "SELECT val FROM prefs WHERE key=?", pref );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   169
		if ( ! row.isValidRow() ) return null;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   170
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   171
		var value = row.fieldByName( 'val' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   172
		row.close();
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   173
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   174
		return value;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   175
	},
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   176
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   177
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   178
	// Return a preference's current value as a boolean.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   179
	//
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   180
	getBoolPref: function( pref ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   181
		return this.getPref( pref ) == '1'
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   182
	},
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   183
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   184
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   185
	// Insert or update a preference value.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   186
	//
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   187
	setPref: function( pref, value ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   188
		this.db.execute( 'BEGIN' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   189
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   190
		// Row already exists, remove it first.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   191
		if ( this.getPref( pref ) != null )
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   192
			this.db.execute( 'DELETE FROM prefs WHERE key=?', pref );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   193
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   194
		this.db.execute( 'INSERT INTO prefs VALUES ( ?, ? )', pref, value );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   195
		this.db.execute( 'COMMIT' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   196
	},
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   197
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   198
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   199
	// Set a bool preference value.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   200
	//
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   201
	setBoolPref: function( pref, value ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   202
		this.setPref( pref, (value ? '1' : '0') );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   203
	},
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   204
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   205
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   206
	// Generic delayed callback that returns the timer handle.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   207
	//
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   208
	delay: (function() {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   209
		var timer = null;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   210
		return function( callback, ms, clear_previous ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   211
			if ( clear_previous) clearTimeout( timer );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   212
			timer = setTimeout( callback, ms );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   213
			return timer;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   214
		};
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   215
	})(),
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   216
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   217
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   218
	// Create and show a new notification.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   219
	//
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   220
	notify: function( title, message, callback ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   221
		if ( ! callback ) callback = function(){};
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   222
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   223
		var notification = Ti.Notification.createNotification({
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   224
			'title' : title,
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   225
			'message' : message,
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   226
			'timeout' : 10,
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   227
			'callback' : callback,
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   228
		});
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   229
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   230
		notification.show();
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   231
		return notification;
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   232
	},
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   233
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   234
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   235
	// Record the main window position and state.
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   236
	//
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   237
	saveWindowState: function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   238
		var w      = this.window.main;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   239
		var x      = w.getX();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   240
		var y      = w.getY();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   241
		var width  = w.getWidth();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   242
		var height = w.getHeight();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   243
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   244
		var hiddenMenu     = this.menu.getItemAt( 2 ).getSubmenu().getItemAt( 0 );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   245
		var fullScreenMenu = this.menu.getItemAt( 2 ).getSubmenu().getItemAt( 1 );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   246
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   247
		var pos = this.getPref( 'window_pos' );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   248
		pos = Ti.JSON.parse( pos );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   249
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   250
		// first time
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   251
		//
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   252
		if ( ! pos ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   253
			pos =  {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   254
				x: x,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   255
				y: y,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   256
				width: width,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   257
				height: height,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   258
				fullscreen: false,
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   259
				hidden: false
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   260
			};
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   261
		}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   262
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   263
		if ( w.isVisible() ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   264
			pos.hidden = false;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   265
			fullScreenMenu.enable();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   266
		}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   267
		else {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   268
			pos.hidden = true;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   269
			fullScreenMenu.disable();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   270
		}
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   271
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   272
		if ( w.isFullScreen() ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   273
			pos.fullscreen = true;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   274
			hiddenMenu.disable();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   275
		}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   276
		else {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   277
			pos.fullscreen = false;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   278
			hiddenMenu.enable();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   279
		}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   280
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   281
		if ( ! pos.fullscreen ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   282
			pos.x      = x;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   283
			pos.y      = y;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   284
			pos.width  = width;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   285
			pos.height = height;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   286
		}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   287
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   288
		this.setPref( 'window_pos', Ti.JSON.stringify(pos) );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   289
	},
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   290
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   291
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   292
	// Set the main window according to previously saved values.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   293
	//
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   294
	setWindowState: function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   295
		var w   = this.window.main;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   296
		var pos = this.getPref( 'window_pos' );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   297
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   298
		var hiddenMenu     = this.menu.getItemAt( 2 ).getSubmenu().getItemAt( 0 );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   299
		var fullScreenMenu = this.menu.getItemAt( 2 ).getSubmenu().getItemAt( 1 );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   300
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   301
		pos = Ti.JSON.parse( pos );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   302
		if ( ! pos ) return;
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   303
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   304
		if ( pos.fullscreen ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   305
			w.setFullscreen( true );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   306
			hiddenMenu.disable();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   307
		}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   308
		else {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   309
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   310
			console.log( "Moving to x:" + pos.x + ", y:" + pos.y );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   311
			console.log( "Sizing to w:" + pos.width + ", h:" + pos.height );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   312
			w.moveTo(  pos.x, pos.y );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   313
			w.setSize( pos.width, pos.height );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   314
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   315
			hiddenMenu.enable();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   316
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   317
			if ( pos.hidden ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   318
				w.hide();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   319
				fullScreenMenu.disable();
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   320
			}
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   321
			else {
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   322
				w.show();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   323
				fullScreenMenu.enable();
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   324
			}
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   325
		}
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   326
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   327
		this.saveWindowState();
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   328
	},
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   329
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   330
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   331
	// Build the main menu.
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   332
	//
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   333
	initMenu: function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   334
		this.menu = Ti.UI.createMenu();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   335
		var tray  = Ti.UI.addTray( 'app://img/tray_icon.png' );
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   336
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   337
		// windows
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   338
		// ---------------------------------------------------------------
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   339
		this.menu.addItem( 'About', function() {
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   340
			if ( D.window.about && D.window.about.isVisible() ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   341
				D.window.about.focus();
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   342
			}
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   343
			else {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   344
				D.window.about = D.window.main.createWindow( 'app://window/about.html' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   345
				D.window.about.setTopMost( true );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   346
				D.window.about.open();
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   347
			}
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   348
		});
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   349
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   350
		this.menu.addItem( 'Preferences', function() {
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   351
			if ( D.window.prefs && D.window.prefs.isVisible() ) {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   352
				D.window.prefs.focus();
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   353
			}
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   354
			else {
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   355
				D.window.prefs = D.window.main.createWindow( 'app://window/prefs.html' );
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   356
				D.window.prefs.open();
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   357
			}
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   358
		});
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   359
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   360
		// view menu
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   361
		// ---------------------------------------------------------------
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   362
		var viewMenu = Ti.UI.createMenuItem( 'View' );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   363
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   364
		viewMenu.addItem( 'Toggle Hidden', function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   365
			if ( D.window.main.isVisible() ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   366
				D.window.main.hide();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   367
			}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   368
			else {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   369
				D.window.main.show();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   370
			}
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   371
			D.saveWindowState();
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   372
		});
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   373
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   374
		viewMenu.addItem( 'Toggle Full Screen', function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   375
			D.window.main.setFullscreen( ! D.window.main.isFullscreen() );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   376
			D.saveWindowState();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   377
		});
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   378
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   379
		this.menu.appendItem( viewMenu );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   380
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   381
		// other
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   382
		// --------------------------------------------------------------
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   383
		if ( this.getBoolPref('devmode') ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   384
			this.menu.addItem( 'Restart', function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   385
				Ti.App.restart();
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   386
			});
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   387
	   }
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   388
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   389
		tray.setMenu( this.menu );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   390
		Ti.UI.setDockMenu( this.menu );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   391
		// D.window.main.setContextMenu( this.menu );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   392
		// Ti.UI.setMenu( menu );
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   393
	},
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   394
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   395
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   396
	/*######################################################################
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   397
	### M O D E L S
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   398
	######################################################################*/
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   399
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   400
	// // A Thingfish asset.
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   401
	// //
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   402
	// initModel: function() {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   403
	//     D.Asset = can.Model({
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   404
	//         id     : 'oid',
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   405
	//         findAll: 'GET '    + D.tf.uri + '/',
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   406
	//         findOne: 'GET '    + D.tf.uri + '/{oid}',
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   407
	//         create : 'POST '   + D.tf.uri + '/',
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   408
	//         update : 'PUT '    + D.tf.uri + '/{oid}',
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   409
	//         destroy: 'DELETE ' + D.tf.uri + '/{oid}',
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   410
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   411
	//         // TODO: other metadata hooks?  diff model?
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   412
	//         metadata: 'GET ' + D.tf.uri + '/{oid}/metadata',
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   413
1
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   414
	//     }, {}).
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   415
	//         bind( 'created', function( ev, asset ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   416
	//             console.debug( "Created a new asset " + asset.id );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   417
	//         }).
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   418
	//         bind( 'updated', function( ev, asset ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   419
	//             console.debug( "Updated asset " + asset.id );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   420
	//         }).
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   421
	//         bind( 'destroyed', function( ev, asset ) {
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   422
	//             console.debug( "Removed asset " + asset.id );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   423
	//         }
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   424
	//     );
b3419d05eabb Checkpoint.
Mahlon E. Smith <mahlon@martini.nu>
parents: 0
diff changeset
   425
	// },
0
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   426
};
80c32ef237c6 Initial commit.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   427