lib/framework/rho/rhoapplication.rb in rhodes-3.5.1.12 vs lib/framework/rho/rhoapplication.rb in rhodes-5.5.0
- old
+ new
@@ -22,40 +22,59 @@
# THE SOFTWARE.
#
# http://rhomobile.com
#------------------------------------------------------------------------
-require 'rhom'
-require 'rhofsconnector'
+#require 'rhom'
+#require 'rhofsconnector'
require 'rholang/localization_simplified'
require 'rho/rhomsg'
require 'rho/rhotabbar'
require 'rho/rhotoolbar'
::System::set_locale(nil, nil)
module Rho
- class RhoApplication
+ class Application
attr_accessor :default_menu
TOOLBAR_TYPE = 0
TABBAR_TYPE = 1
NOBAR_TYPE = 2
VTABBAR_TYPE = 3
@@toolbar = [{:action => :back}, {:action => :forward}, {:action => :separator},
{:action => :home}, {:action => :refresh}, {:action => :options} ]
-
+
+ #def self.make_default_native_menu
+ # { Rho::RhoMessages.get_message('home_menu') => :home, Rho::RhoMessages.get_message('refresh_menu') => :refresh,
+ # Rho::RhoMessages.get_message('sync_menu') => :sync, Rho::RhoMessages.get_message('options_menu') => :options, Rho::RhoMessages.get_message('log_menu') => :log, :separator => nil, Rho::RhoMessages.get_message('close_menu') => :close }
+ #end
+
+ def self.make_default_native_menu
+ NativeMenubar_defaultMainMenu()
+ end
+
+ def self.NativeMenubar_defaultMainMenu
+ [ {:label=>Rho::RhoMessages.get_message('home_menu'), :action=>:home},
+ { :label =>Rho::RhoMessages.get_message('refresh_menu'), :action => :refresh },
+ { :label => Rho::RhoMessages.get_message('sync_menu'), :action => :sync},
+ { :label =>Rho::RhoMessages.get_message('options_menu'), :action => :options},
+ { :label=>Rho::RhoMessages.get_message('log_menu'), :action => :log},
+ { :label=>:separator, :action => nil},
+ { :label => Rho::RhoMessages.get_message('close_menu'), :action => :close }
+ ]
+ end
+
def initialize
#LocalizationSimplified.requre_loc(Rho::RhoFSConnector::get_app_path('app') + 'lang/lang_',true)
unless @rhom
- @rhom = Rhom::Rhom.new
+ @rhom = Rhom::Rhom.get_instance
end
unless @default_menu
- @default_menu = { Rho::RhoMessages.get_message('home_menu') => :home, Rho::RhoMessages.get_message('refresh_menu') => :refresh,
- Rho::RhoMessages.get_message('sync_menu') => :sync, Rho::RhoMessages.get_message('options_menu') => :options, Rho::RhoMessages.get_message('log_menu') => :log, :separator => nil, Rho::RhoMessages.get_message('close_menu') => :close }
+ @default_menu = Rho::Application::make_default_native_menu()
end
if @vtabs != nil
@@native_bar_data = {:type => :vtabbar, :data => @vtabs}
elsif @tabs != nil
@@ -65,11 +84,10 @@
else
@@native_bar_data = nil #{:type => :nobar}
end
#::Rho::RHO.get_instance().check_sources_migration(self)
-
@initialized = true
::Rho::RHO.get_instance().set_app(::Rho::RHO::APPNAME, self)
end
@@ -115,101 +133,52 @@
def initialized?
@initialized
end
def on_activate_app
+ Rho::Application.processApplicationEvent({'applicationEvent'=>'Activated'})
end
def on_deactivate_app
+ Rho::Application.processApplicationEvent({'applicationEvent'=>'Deactivated'})
end
def on_ui_created
- start_url = Rho::RhoConfig.start_path
- start_url = "" unless start_url
-
- security_token_not_passed = System.get_property('security_token_not_passed')
- security_token_not_passed = false if security_token_not_passed.nil?
- invalid_security_token_start_path_exist = Rho::RhoConfig.exists? 'invalid_security_token_start_path'
- invalid_security_token_start_path = Rho::RhoConfig.invalid_security_token_start_path
-
- if security_token_not_passed
- if invalid_security_token_start_path_exist
- start_url = invalid_security_token_start_path
- else
- # exit from application - old way
- puts 'security_token is not passed - application will closed'
- System.exit
- end
- end
-
- puts "on_ui_created.navigate to start url: '#{start_url}'"
- WebView.navigate(start_url)
+ Rho::Application.processApplicationEvent({'applicationEvent'=>'UICreated'})
end
def on_ui_destroyed
+ Rho::Application.processApplicationEvent({'applicationEvent'=>'UIDestroyed'})
end
def on_sync_user_changed
- Rhom::Rhom.database_full_reset(false, false)
- ::Rho::RHO.get_user_db().execute_sql("UPDATE client_info SET client_id=?", "")
+ Rho::Application.processApplicationEvent({'applicationEvent'=>'SyncUserChanged'})
end
-
+
def on_reinstall_config_update(conflicts)
- puts "on_reinstall_config_update: #{conflicts}"
+ Rho::Application.processApplicationEvent({'applicationEvent'=>'ConfigConflict','eventData'=>{ 'conflicts' => conflicts}})
end
# works for schema sources
#return true to run script creating table
def on_migrate_source(old_version, new_src)
- puts "default on_migrate_source - do nothing; old_version :#{old_version}; new_src : #{new_src}"
- #if new_src['schema']
- # db = ::Rho::RHO.get_src_db(new_src['name'])
- # db.delete_table(new_src['name'])
-
- # return false #create new table
- #end
-
- return true
+ Rho::Application.processApplicationEvent({'applicationEvent'=>'DBMigrateSource','eventData'=>{ 'old_version' => old_version, 'new_src' => new_src}})
end
-
+
def set_menu(menu=nil,back_action=nil)
@default_menu = {} if @default_menu.nil?
disp_menu = menu ? menu.dup : @default_menu.dup
- disp_menu['Back'] = back_action if back_action
+ if back_action
+ if disp_menu.is_a?(Array)
+ disp_menu << {:label => 'Back', :action => back_action }
+ else
+ disp_menu['Back'] = back_action
+ end
+
+ end
#puts "RhoApplication: Using menu - #{disp_menu.inspect}"
WebView.set_menu_items(disp_menu)
- end
-
- class << self
- def get_app_path(appname)
- Rho::RhoFSConnector::get_app_path(appname)
- end
-
- def get_base_app_path
- Rho::RhoFSConnector::get_base_app_path
- end
-
- def get_user_path
- Rho::RhoFSConnector::get_user_path
- end
-
- def get_model_path(appname, modelname)
- Rho::RhoFSConnector::get_model_path(appname, modelname)
- end
-
- def get_blob_folder()
- Rho::RhoFSConnector::get_blob_folder()
- end
-
- def get_public_folder()
- Rho::RhoFSConnector::get_public_folder()
- end
-
- def get_blob_path(relative_path)
- Rho::RhoFSConnector::get_blob_path(relative_path)
- end
-
end
@@current_controller = nil
def self.current_controller()
@@current_controller
@@ -229,11 +198,11 @@
if Rho::file_exist?( req[:modelpath]+ undercase +RHO_RB_EXT )
require req['model'] + '/' + undercase #req[:modelpath]+ undercase
is_found = true
- elsif defined?( RHODES_EMULATOR )
+ elsif Rho::System.isRhoSimulator
begin
require req['model'] + '/' + undercase #req[:modelpath]+ undercase
is_found = true
rescue Exception => exc
end
@@ -246,7 +215,12 @@
@@current_controller = (Object.const_get(req['model']+'Controller').new)
res['request-body'] = @@current_controller.send :serve, self, @rhom, req, res
end
- end # RhoApplication
+ end # Application
end # Rho
+
+module Rho
+ RhoApplication = Rho::Application
+end
+