dofile(MACXT_Path.."/Programs/Imessenger/Imessenger.lua")
REGISTRY:Read("Imessenger","Login")
MACXT_Programmes:NewAppli_MACXT()
Afficher_Wallpaper_MACXT_TRUE = true
while true do
   Adhoc_statut = Adhoc.getState()
   MACXT_Graphic:Afficher_Wallpaper()
   MACXT_Kernel:Kernel()
   MACXT_Objets_Barre[1] = {Caption = "Imessenger",Fonction = "Options_Imessenger"}
   MACXT_Objets_Barre[2] = {Caption = "Fichier",Fonction = "Options_Fichier"}
   MACXT_Objets_Barre[3] = {Caption = "Reseau",Fonction = "Options_Reseau"}
   MACXT_Objets_Barre[4] = {Caption = "Fenetre",Fonction = "Options_Fenetre"}
   MACXT_Repertoire:Actualise_Systeme_Barre()
   if Fonction_Barre == "Options_Fichier" then
      MACXT_Objets_Barre_Fonction[1] = {Caption = "Modifier Pseudo",Action = "ModifPseudo"}
      MACXT_Repertoire:Actualise_Fonction()
   end
   if Fonction_Barre == "Options_Imessenger" then
      MACXT_Objets_Barre_Fonction[1] = {Caption = "A propos de Imessenger",Action = "Propos_Imessenger"}
      MACXT_Objets_Barre_Fonction[2] = {Caption = "Preferences",Action = "Preferences_Imessenger"}
      MACXT_Objets_Barre_Fonction[3] = {Caption = "Quitter Imessenger",Action = "Quitter_Imessenger"}
      MACXT_Repertoire:Actualise_Fonction()
   end
   if Fonction_Barre == "Options_Reseau" then
      MACXT_Objets_Barre_Fonction[1] = {Caption = "Activer Adhoc",Action = "ActiveAdhoc"}
      MACXT_Objets_Barre_Fonction[2] = {Caption = "Stopper Adhoc",Action = "StopAdhoc"}
      MACXT_Objets_Barre_Fonction[3] = {Caption = "Se Connecter",Action = "ConnectImessenger"}
      MACXT_Objets_Barre_Fonction[4] = {Caption = "Se deconnecter",Action = "deconnectImessenger"}
      MACXT_Repertoire:Actualise_Fonction()
   end
   if Fonction_Barre == "Options_Fenetre" then
      MACXT_Objets_Barre_Fonction[1] = {Caption = "Ouvri fenetre",Action = "Open_Window"}
      MACXT_Objets_Barre_Fonction[2] = {Caption = "Fermer fenetre",Action = "Close_Window"}
      MACXT_Repertoire:Actualise_Fonction()
   end
   if LancerImessenger == 1 then
      Imessenger:OpenConversation()
   end
   if ActiverImessenger == 1 then
      Imessenger:AppliImessengerAppRun()
   end
   if Action_Barre == "deconnectImessenger" then
      LancerImessenger = 0
      Afficher_Personnal_Window = 0
      MACXT_Repertoire:Anti_Bug()
   end
   if Action_Barre == "ModifPseudo" then
      LastLoginImessenger = LoginImessenger
      LoginImessenger = System.startOSK(LoginImessenger,"")
      if string.len(LoginImessenger) > 0 then
         REGISTRY:Write_On_File("Imessenger","Login","LoginImessenger = "..'"'..LoginImessenger..'"')
       else
         LoginImessenger = LastLoginImessenger
      end
      Imessage = LastLoginImessenger.." a change son pseudo en "..LoginImessenger
      MACXT_Repertoire:Anti_Bug()
   end
   if Action_Barre == "ConnectImessenger" then
      Window_Hauteur = 100
      Window_Longueur = 245
      MACXT_Graphic:Init_New_Personnal_Window()
      ActiverImessenger = 1
      MACXT_Repertoire:Anti_Bug()
   end
   if Action_Barre == "StopAdhoc" then
      if LancerImessenger ~= 1 then
         Adhoc.term()
      end
      MACXT_Repertoire:Anti_Bug()
   end
   if Action_Barre == "ActiveAdhoc" then
      Adhoc.init()
      Adhoc.connect() 
      MACXT_Repertoire:Anti_Bug()
   end
   if Action_Barre == "Propos_Imessenger" then
      MACXT_Repertoire:Reinitialiser_Window()
      Window_Hauteur = 120
      Window_Longueur = 270
      MACXT_Title = "A propos de Imessenger"
      MACXT_Graphic:Init_New_Personnal_Window()
      MACXT_Graphic:New_Textes()
      MACXT_Texte_Window[1] = {Caption = "Imessenger est une application"}
      MACXT_Texte_Window[2] = {Caption = "Qui vous permet de dialoguer"}
      MACXT_Texte_Window[3] = {Caption = "instantanement avec vos amis"}
      MACXT_Texte_Window[4] = {Caption = "bien qu'ils soient proches"}
      MACXT_Texte_Window[5] = {Caption = "de vous en meme temps :p"}
      MACXT_Repertoire:Actualise_Texte_Window()
      MACXT_Repertoire:Anti_Bug()
   end
   if Action_Barre == "Close_Window" then
      LancerImessenger = 0
      ActiverImessenger = 0
      Afficher_Personnal_Window = 0
      MACXT_Repertoire:Anti_Bug()
   end
   if Action_Barre == "Quitter_Imessenger" then
      LancerImessenger = 0
      ActiverImessenger = 0
      Afficher_Personnal_Window = 0
      Adhoc.term()
      MACXT_Repertoire:Repertoire_Menu()
      break
   end
screen.waitVblankStart()
screen:flip()
end