------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2009 Vadim Godunko <vgodunko@gmail.com>                      --
--                                                                          --
-- QtAda is free software;  you can  redistribute it and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion. QtAda is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License distributed with QtAda;  see file COPYING.  If not, write --
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
-- Boston, MA 02110-1301, USA.                                              --
--                                                                          --
------------------------------------------------------------------------------
--  $Revision: 3625 $ $Date: 2009-11-18 11:33:44 +0300 (Wed, 18 Nov 2009) $
------------------------------------------------------------------------------
with Qt4.Dirs;
with Qt4.File_Infos;
with Qt4.Message_Boxes;
with Qt4.Strings;
with Qt4.Plugin_Loaders.Constructors;
with Qt_Ada.Application;
with Echo_Interfaces;

with Echo_Windows;

procedure Main is
   Window  : Echo_Windows.Echo_Window_Access;
   Loader  : Qt4.Plugin_Loaders.Q_Plugin_Loader_Access;
   Dummy   : Qt4.Message_Boxes.Standard_Button;
   Loaded  : Boolean;
   Plugin  : Qt4.Strings.Q_String;
   Dir     : constant Qt4.Dirs.Q_Dir
     := Qt4.Dirs.Create (Qt4.Strings.From_Utf_16 ("plugins"));
   Unix    : constant Qt4.File_Infos.Q_File_Info
     := Qt4.File_Infos.Create
         (Dir, Qt4.Strings.From_Utf_16 ("libEchoPlugin.so"));
   Windows : constant Qt4.File_Infos.Q_File_Info
     := Qt4.File_Infos.Create
         (Dir, Qt4.Strings.From_Utf_16 ("libEchoPlugin.dll"));
   Mac     : constant Qt4.File_Infos.Q_File_Info
     := Qt4.File_Infos.Create
         (Dir, Qt4.Strings.From_Utf_16 ("libEchoPlugin.dylib"));

begin
   Qt_Ada.Application.Initialize;

   if Unix.Exists then
      Plugin := Unix.File_Path;

   elsif Windows.Exists then
      Plugin := Windows.File_Path;

   elsif Mac.Exists then
      Plugin := Mac.File_Path;
   end if;

   Loader := Qt4.Plugin_Loaders.Constructors.Create (Plugin);

   Loaded := Loader.Load;

   Window :=
     Echo_Windows.Create
      (Echo_Interfaces.Echo_Interface_Access (Loader.Instance));
   Window.Show;

   if not Loaded then
      Dummy :=
        Qt4.Message_Boxes.Information
         (Window,
          Qt4.Strings.From_Utf_16 ("Error"),
          Qt4.Strings.From_Utf_16 ("Could not load the plugin"));
   end if;

   Qt_Ada.Application.Execute;
end Main;
