1package AmphetaDesk::AmphetaDesk::OS::MacOS;
2###############################################################################
3# This package handles all the GUI routines for the Mac operating system.     #
4# It requires various modules to be compiled into the runtime wrapper script  #
5# - these modules are assumed to be there. If not, oopsy, we got problems.    #
6#                                                                             #
7# LIST OF ROUTINES BELOW:                                                     #
8#   gui_init - start the gui and display the window.                          #
9#   gui_listen - listen for window events for our gui.                        #
10#   gui_note - send a note to our gui window.                                 #
11#   open_url - open a url in the system's default browser.                    #
12#   _things - various routines that control the gui and should be private.    #
13###############################################################################
14
15use strict;
16use AmphetaDesk::AmphetaDesk::Settings;
17use AmphetaDesk::AmphetaDesk::Utilities;
18use Mac::Events;
19require Exporter;
20use vars qw( @ISA @EXPORT );
21@ISA = qw( Exporter );
22@EXPORT = qw( gui_init gui_listen gui_note open_url );
23
24###############################################################################
25# gui_init - start the gui and display the window.                            #
26###############################################################################
27# USAGE:                                                                      #
28#   gui_init;                                                                 #
29#                                                                             #
30# NOTES:                                                                      #
31#   This routine loads specific libraries specific to the OS and attempts to  #
32#   do everything necessary to start up a GUI window and start listening for  #
33#   events. Further down in this file, you should see supplementary GUI       #
34#   routines (starting with _) that are part of the GUI happenings this       #
35#   routine inits.                                                            #
36#                                                                             #
37# RETURNS:                                                                    #
38#   1; this routine always returns happily.                                   #
39###############################################################################
40
41sub gui_init {
42
43   return 1;
44
45}
46
47###############################################################################
48# gui_listen - listen for window events for our gui.                          #
49###############################################################################
50# USAGE:                                                                      #
51#   gui_listen;                                                               #
52#                                                                             #
53# NOTES:                                                                      #
54#   This routine checks the event queue and sees if there is anything that    #
55#   needs to be done. It's called from the main loop of our program.          #
56#                                                                             #
57# RETURNS:                                                                    #
58#   1; this routine always returns happily.                                   #
59###############################################################################
60
61sub gui_listen {
62
63    my $start = time; WaitNextEvent until time > ($start + 1); return 1;
64
65}
66
67###############################################################################
68# gui_note - send a note to our gui window.                                   #
69###############################################################################
70# USAGE:                                                                      #
71#   gui_note("This is a gui window line. Yup.");                              #
72#                                                                             #
73# NOTES:                                                                      #
74#   Much like note(), only we send our message to our os specific gui window. #
75#                                                                             #
76# RETURNS:                                                                    #
77#   1; this routine always returns happily.                                   #
78###############################################################################
79
80sub gui_note {
81
82   # eventually, this will do something a bit more meaningful.
83   my ($message) = @_; print STDOUT $message . "\n"; return 1;
84
85}
86
87###############################################################################
88# open_url - open a url in the system's default browser.                      #
89###############################################################################
90# USAGE:                                                                      #
91#    open_url( );                                                             #
92#                                                                             #
93# OS SPECIFIC NOTES:                                                          #
94#    This routine loads the Mac::InternetConfig module to find the default    #
95#    browser as defined in the Internet control panel. It will then load the  #
96#    URL within the program specified.                                        #
97#                                                                             #
98# RETURNS:                                                                    #
99#    1; we instruct the user to open their browser if we can't.               #
100###############################################################################
101
102sub open_url {
103
104   # construct our url.
105   my $url = "http://127.0.0.1:" . get_setting("urls_port") . "/index.html";
106
107   # we spit out our suggestion just to catch all instances.
108   note("If your browser doesn't load, go to <$url>.", 1);
109
110   # open url based on the default browser entry.
111   use Mac::InternetConfig qw(:DEFAULT $ICInstance);
112   ICGeneralFindConfigFile($ICInstance);
113   ICLaunchURL($ICInstance, 0, $url);
114
115   return 1;
116
117}
118
119###############################################################################
120# _things - various routines that control the gui and should be private.      #
121###############################################################################
122# USAGE:                                                                      #
123#    These are internally called by the GUI and shouldn't be publically       #
124#    used. So stop poking around here. Sheesh. Flippin' nosy people. Sigh.    #
125###############################################################################
126
1271;
128