Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
The Agent - Form1.vb

Form1.vb

Caricato da: Totem
Scarica il programma completo

  1. Imports AgentObjects
  2. Imports AxAgentObjects
  3. Imports Microsoft.Win32
  4. Public Class frmHelper
  5. #Region "Enumeratori / Strutture"
  6.     Public Enum SenNum
  7.         Saluto_Iniziale
  8.         Saluto_Finale
  9.         Impegni_Salvati
  10.         Impegni_Cancellati
  11.     End Enum
  12. #End Region
  13. #Region "Variabili"
  14.     'Queste variabili vengono utilizzate con gli eventi:
  15.     '          RequestStart   e   RequestComplete
  16.     'Vedi note ed esempi relativi
  17.     '------------------------------------------------------------------------
  18.     'Dim MyRequest As IAgentCtlRequest
  19.     'Dim MySecondRequest As IAgentCtlRequest
  20.     'Dim MyThirdRequest As IAgentCtlRequest
  21.     'Dim AzioneCorrente As Integer
  22.     '**********************************************************
  23.  
  24.     'Agente
  25.     Public Agente As IAgentCtlCharacterEx
  26.     'Le misure dello schermo
  27.     Public Display As Rectangle = Screen.PrimaryScreen.Bounds
  28.     'Posizione dell'agente
  29.     Public Position As Point
  30.     Public Personaggio As String = "Peedy"
  31.  
  32.     'Costanti per la modifica dello stile del fumetto
  33.     Private Const BallonOn As Long = 1
  34.     Private Const SizeToText As Long = 2
  35.     Private Const AutoHide As Long = 4
  36.     Private Const AutoPace As Long = 8
  37.  
  38.     'Frasi di default
  39.     Public Shared Options As New clsOptions
  40.     'Azioni
  41.     Private Actions As New ArrayList
  42.     'Gli array sono difficili da gestire, così questa hashtable è utilizzata
  43.     'per migliorare la gestione di Options.Alarms
  44.     Public Shared Alarms As New Hashtable
  45. #End Region
  46. #Region "Procedure / Funzioni"
  47.     'Carica il personaggio
  48.     Public Sub LoadChar()
  49.         Personaggio = Options.Agent
  50.         'Carica il modello e i dati del personaggio nella lista
  51.         AxAgent1.Characters.Load(Personaggio, "C:\WINDOWS\msagent\chars\" + Personaggio + ".acs")
  52.         'Attribuisce ad 'Agente' il riferimento a tale personaggio
  53.         Agente = AxAgent1.Characters(Personaggio)
  54.  
  55.         With Agente
  56.             .LanguageID = &H410 ' ITALIANO
  57.             .Balloon.FontName = Options.Balloon_Font_Name
  58.             .Balloon.FontSize = Options.Balloon_Font_Size
  59.         End With
  60.     End Sub
  61.  
  62.     'Animazione iniziale
  63.     Public Sub StartAnim()
  64.         With Agente
  65.             .Show()
  66.             .MoveTo(Display.Width - 250, Display.Height - 250)
  67.             'Saluto iniziale
  68.             SaySentence(0)
  69.         End With
  70.     End Sub
  71.  
  72.     'Restituisce il quadrante in cui si trova l'agente, supposto lo schermo diviso in 4 parti uguali
  73.     'Serve per determinare la posizione delle finestre ausiliarie
  74.     'Inutilizzato dalla versione 1.2
  75.     Public Function Quadrante() As Byte
  76.         If Position.X > Display.Width / 2 Then
  77.             If Position.Y > Display.Height / 2 Then
  78.                 Return 4
  79.             Else
  80.                 Return 1
  81.             End If
  82.         Else
  83.             If Position.Y > Display.Height / 2 Then
  84.                 Return 3
  85.             Else
  86.                 Return 2
  87.             End If
  88.         End If
  89.     End Function
  90.  
  91.     'Pronuncia una frase di quelle impostate dall'utente, ma solo se Play = true
  92.     Public Shared Sub SaySentence(ByVal Index As Byte)
  93.         If Options.Sentences(Index).Play Then
  94.             frmHelper.Agente.Speak(Options.Sentences(Index).Text)
  95.         End If
  96.     End Sub
  97.  
  98.     'Pronunica una frase di quelle preimpostate, ma solo se Play = true
  99.     Public Shared Sub SayPredSentence(ByVal Index As Byte)
  100.         If Options.PredSentences(Index).Play Then
  101.             frmHelper.Agente.Speak(Options.PredSentences(Index).Text)
  102.         End If
  103.     End Sub
  104.  
  105.     'Restituisce una sottostringa del testo, dati gli elementi tra cui è compresa
  106.     'Serve per i dati meteo
  107.     Public Function SubStr(ByVal Str As String, ByVal Prev_String As String, ByVal Next_String As String)
  108.         Dim Start_Index As Int32
  109.         Dim End_Index As Int32
  110.         Dim Result As String
  111.  
  112.         Start_Index = Str.IndexOf(Prev_String) + Prev_String.Length
  113.         End_Index = Str.IndexOf(Next_String, Start_Index)
  114.         Result = Str.Substring(Start_Index, End_Index - Start_Index)
  115.  
  116.         Return Result
  117.     End Function
  118. #End Region
  119.     'Carica le opzioni, il personaggio ed eventualmente le sveglie
  120.     Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
  121.         'Controlla se Microsoft Agent è installato
  122.         If Not IO.Directory.Exists("C:\WINDOWS\msagent") Then
  123.             MessageBox.Show("Microsoft Agent risulta non essere installato su questo computer. Per installare il software necessario, " + _
  124.             "eseguire tutti i programmi presenti nella sottocartella 'Microsoft Agent' che verrà aperta tra breve.", "Error #0", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  125.             Shell("C:\WINDOWS\explorer.exe " + Chr(34) + Application.StartupPath + "\Microsoft Agent" + Chr(34), AppWinStyle.NormalFocus)
  126.             Application.Exit()
  127.         End If
  128.  
  129.         'Controlla se esistono le directory adeguate
  130.         If Not IO.Directory.Exists(Application.StartupPath + "\Imp") Then
  131.             IO.Directory.CreateDirectory(Application.StartupPath + "\Imp")
  132.         End If
  133.         If Not IO.Directory.Exists(Application.StartupPath + "\Macro") Then
  134.             IO.Directory.CreateDirectory(Application.StartupPath + "\Macro")
  135.         End If
  136.  
  137.         Options = Options.Load(Application.StartupPath + "\Settings.xml")
  138.         LoadChar()
  139.  
  140.         If Options.Alarms.Length = 0 Then
  141.             Exit Sub
  142.         Else
  143.             If Options.Alarms(0).Time = Nothing Then
  144.                 Exit Sub
  145.             End If
  146.         End If
  147.  
  148.         'Copia Options.Alarms in Alarms
  149.         For Each A As clsOptions.Alarm In Options.Alarms
  150.             Alarms.Add(A.Time, A)
  151.         Next
  152.  
  153.         'Attiva il timer se necessario
  154.         If Options.Alarms_Enabled Then
  155.             tmrAlarm.Start()
  156.         End If
  157.  
  158.         'Controlla Meteo se necessario
  159.         If Options.Meteo_On_startup Then
  160.             imgMeteo_Click(Me, New EventArgs)
  161.         End If
  162.  
  163.         'Da perfezionare
  164.         If Options.POP3_Enabled Then
  165.             'tmrControlMail.Start()
  166.         End If
  167.     End Sub
  168.  
  169.     'Esegue l'animazione iniziale e nasconde il form
  170.     Private Sub Form_Activate(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Shown
  171.         StartAnim()
  172.         Me.Visible = False
  173.         Me.Opacity = 0
  174.     End Sub
  175.  
  176.     'Comunica l'ora
  177.     Private Sub imgDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgDate.Click
  178.         Dim D As Date = Date.Now
  179.         Dim S As String
  180.         S = "Oggi è "
  181.         Select Case D.DayOfWeek
  182.             Case DayOfWeek.Monday : S += "Lunedì"
  183.             Case DayOfWeek.Tuesday : S += "Martedì"
  184.             Case DayOfWeek.Wednesday : S += "Mercoledì"
  185.             Case DayOfWeek.Thursday : S += "Giovedì"
  186.             Case DayOfWeek.Friday : S += "Venerdì"
  187.             Case DayOfWeek.Saturday : S += "Sabato"
  188.             Case DayOfWeek.Sunday : S += "Domenica"
  189.         End Select
  190.         S += " " & D.Day & " "
  191.         Select Case D.Month
  192.             Case 1 : S += "Gennaio"
  193.             Case 2 : S += "Febbraio"
  194.             Case 3 : S += "Marzo"
  195.             Case 4 : S += "Aprile"
  196.             Case 5 : S += "Maggio"
  197.             Case 6 : S += "Giugno"
  198.             Case 7 : S += "Luglio"
  199.             Case 8 : S += "Agosto"
  200.             Case 9 : S += "Settembre"
  201.             Case 10 : S += "Ottobre"
  202.             Case 11 : S += "Novembre"
  203.             Case 12 : S += "Dicembre"
  204.         End Select
  205.         S += " " & D.Year & " e sono le ore " & D.Hour & " e " & D.Minute & " minuti."
  206.         Agente.Stop()
  207.         Agente.Speak(S)
  208.     End Sub
  209.  
  210.     'Esce dal programma
  211.     Private Sub imgExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strExit.Click
  212.         With Agente
  213.             .Show()
  214.             .Stop()
  215.             'Saluto finale
  216.             SaySentence(1)
  217.             .Play("Wave")
  218.             tmrExit.Start()
  219.         End With
  220.     End Sub
  221.  
  222.     'Esegue l'animazione di congedo e chiude il programma, salvando prima le opzioni
  223.     Private Sub tmrExit_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrExit.Tick
  224.         ReDim Options.Alarms(Alarms.Count - 1)
  225.         Dim I As UInt16 = 0
  226.         For Each A As clsOptions.Alarm In Alarms.Values
  227.             Options.Alarms(I) = A
  228.             I += 1
  229.         Next
  230.         Options.Save(Application.StartupPath + "\Settings.xml")
  231.         icnHelper.Visible = False
  232.         Application.Exit()
  233.     End Sub
  234.  
  235.     'Visualizza gli impegni
  236.     Private Sub imgImp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgImp.Click
  237.         Dim TImp As New frmTodayImp
  238.         Dim X, Y As Int32
  239.  
  240.         Select Case Quadrante()
  241.             Case 1, 4
  242.                 X = Position.X - TImp.Width - 50
  243.                 Y = Position.Y
  244.             Case 2, 3
  245.                 X = Position.X + Agente.Width + 50
  246.                 Y = Position.Y
  247.         End Select
  248.  
  249.         TImp.Show()
  250.         'TImp.Location = New Point(X, Y)
  251.         Agente.Speak(TImp.txtImp.Text.Replace(vbCrLf, "\Pau=500\"))
  252.     End Sub
  253.  
  254.     'Muove l'agente in alto a sinistra
  255.     Private Sub strTopLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strTopLeft.Click
  256.         With Agente
  257.             .StopAll()
  258.             .MoveTo(10, 10)
  259.             Position = New Point(10, 10)
  260.         End With
  261.     End Sub
  262.  
  263.     'Muove l'agente in basso a sinistra
  264.     Private Sub strBottomLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strBottomLeft.Click
  265.         With Agente
  266.             .StopAll()
  267.             .MoveTo(10, Display.Height - 200)
  268.             Position = New Point(10, Display.Height - 200)
  269.         End With
  270.     End Sub
  271.  
  272.     'Muove l'agente in alto a destra
  273.     Private Sub strTopRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strTopRight.Click
  274.         With Agente
  275.             .StopAll()
  276.             .MoveTo(Display.Width - 200, 200)
  277.             Position = New Point(Display.Width - 200, 200)
  278.         End With
  279.     End Sub
  280.  
  281.     'Muove l'agente in basso a destra
  282.     Private Sub strBottomRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strBottomRight.Click
  283.         With Agente
  284.             .StopAll()
  285.             .MoveTo(Display.Width - 200, Display.Height - 200)
  286.             Position = New Point(Display.Width - 200, Display.Height - 200)
  287.         End With
  288.     End Sub
  289.  
  290.     'Modifica gli impegni
  291.     Private Sub imgModImp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgModImp.Click
  292.         Dim MImp As New frmModImp
  293.         Dim X, Y As Int32
  294.  
  295.         Select Case Quadrante()
  296.             Case 1, 4
  297.                 X = Position.X - MImp.Width - 50
  298.                 Y = Position.Y
  299.             Case 2, 3
  300.                 X = Position.X + Agente.Width + 50
  301.                 Y = Position.Y
  302.         End Select
  303.  
  304.         MImp.Show()
  305.         'MImp.Location = New Point(X, Y)
  306.  
  307.         With Agente
  308.             .StopAll()
  309.             .Play("Suggest")
  310.             'Suggerimento
  311.             SayPredSentence(0)
  312.         End With
  313.     End Sub
  314.  
  315.     'Legge un file
  316.     Private Sub imgReadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgReadFile.Click
  317.         If imgReadFile.Tag = "Smetti" Then
  318.             imgReadFile.Tag = "Leggi file"
  319.             Agente.StopAll()
  320.             Exit Sub
  321.         End If
  322.  
  323.         Dim O As New OpenFileDialog
  324.         O.Filter = "File di testo|*.txt"
  325.         If O.ShowDialog = Windows.Forms.DialogResult.OK Then
  326.             Dim R As New IO.StreamReader(O.FileName)
  327.             Dim S As String = R.ReadToEnd
  328.             S = S.Replace(":", ":\Pau=200\")
  329.             Dim Lines() As String = S.Split(".")
  330.             R.Close()
  331.  
  332.             With Agente
  333.                 .Play("Read")
  334.                 For Each Fr As String In Lines
  335.                     If Fr = Nothing Then
  336.                         Continue For
  337.                     End If
  338.                     .Speak(Fr)
  339.                 Next
  340.                 .Play("Announce")
  341.                 'Lettura terminata
  342.                 SayPredSentence(1)
  343.             End With
  344.             imgReadFile.Tag = "Smetti"
  345.         End If
  346.     End Sub
  347.  
  348.     'Visualizza / nasconde il menù
  349.     Private Sub icnHelper_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles icnHelper.DoubleClick
  350.         If Me.Opacity = 0 Then
  351.             Dim X, Y As Int32
  352.  
  353.             X = Position.X + (Agente.Width / 2) - Me.Width / 2
  354.             Y = Position.Y + (Agente.Height / 2) - Me.Height / 2
  355.  
  356.             Me.Opacity = 100
  357.             Me.Visible = 100
  358.             Me.Location = New Point(X, Y)
  359.  
  360.             'Introduzione
  361.             SayPredSentence(2)
  362.         Else
  363.             Me.Visible = False
  364.             Me.Opacity = 0
  365.         End If
  366.     End Sub
  367.  
  368.     'Sposta l'agente a seconda dei movimenti del mouse
  369.     Private Sub AxAgent1_MoveEvent(ByVal sender As System.Object, ByVal e As AxAgentObjects._AgentEvents_MoveEvent) Handles AxAgent1.MoveEvent
  370.         Position = New Point(e.x, e.y)
  371.         Me.Location = New Point(e.x - (Me.Width - Agente.Width) / 2, e.y - (Me.Height - Agente.Height) / 2)
  372.     End Sub
  373.  
  374.     'Visualizza le opzioni
  375.     Private Sub imgOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgOption.Click, strOptions.Click
  376.         Dim O As New frmOption
  377.         O.ShowDialog()
  378.     End Sub
  379.  
  380.     'Informazioni sul software
  381.     Private Sub strAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAbout.Click
  382.         Dim A As New frmAbout
  383.         A.ShowDialog()
  384.         'MsgBox("Prodotto: Virtual Agent Helper" + vbCrLf + "Versione: 1.0.0.0" + vbCrLf + "Sviluppatore: Totem" + vbCrLf + "Società: Piero Tofy's Community" + vbCrLf + _
  385.         '"Licenza: Questo prodotto è distribuito sotto la 'free license' senza scopo di lucro e in modo libero poiché parte del suo contenuto di terza parti è sotto la licenza GNU GPL (http://gnu.org/copyleft/lgpl.html)", MsgBoxStyle.Information)
  386.     End Sub
  387.  
  388.     'Indica un'immagine e la descrive
  389.     Private Sub img_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgReadFile.MouseHover, imgModImp.MouseHover, imgImp.MouseHover, imgDate.MouseHover, imgOption.MouseHover, imgMacros.MouseHover, imgMeteo.MouseHover, imgAlarm.MouseHover
  390.         With Agente
  391.             .GestureAt(Me.Location.X + sender.Location.X, Me.Location.Y + sender.Location.Y)
  392.             If Options.Speak_On_MouseOver Then
  393.                 .Speak(sender.Tag)
  394.             End If
  395.         End With
  396.     End Sub
  397.  
  398.     'Visualizza / nasconde il menù
  399.     Private Sub AxAgent1_DblClick(ByVal sender As System.Object, ByVal e As AxAgentObjects._AgentEvents_DblClickEvent) Handles AxAgent1.DblClick
  400.         icnHelper_DoubleClick(Me, New EventArgs)
  401.     End Sub
  402.  
  403.     'Controlla se ci sono sveglie e le notifica
  404.     Private Sub tmrAlarm_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAlarm.Tick
  405.         Dim Time As String
  406.         Dim D As Date = Date.Now
  407.         Time = D.Hour & "." & D.Minute
  408.         If Alarms.Contains(Time) Then
  409.             Dim Al As clsOptions.Alarm = Alarms(Time)
  410.  
  411.             'Se vi è già stata una notifica, non fa nulla
  412.             If Al.Played Then
  413.                 Exit Sub
  414.             End If
  415.  
  416.             'Se la descrizione ha il seguente formato Macro: <nomemacro>, esegue la macro
  417.             If Al.Desc.ToLower.StartsWith("macro: ") Then
  418.                 Dim MacroName As String = Al.Desc.Remove(0, "macro: ".Length).ToLower
  419.                 Dim Files() As String = IO.Directory.GetFiles(Application.StartupPath + "\Macro")
  420.  
  421.                 For Each File As String In Files
  422.                     If IO.Path.GetFileNameWithoutExtension(File).ToLower = MacroName Then
  423.                         Agente.Speak("Sto eseguendo la macro '" + MacroName + "'.")
  424.                         Shell(File)
  425.                         Exit For
  426.                     End If
  427.                 Next
  428.                 Exit Sub
  429.             End If
  430.  
  431.             Dim S As String = Alarms(Time).Desc
  432.             S = S.Replace(":", ":\Pau=200\")
  433.             Dim Lines() As String = S.Split(".")
  434.             With Agente
  435.                 .Play("Read")
  436.                 .Speak("Ore " & D.Hour & " e " & D.Minute)
  437.                 For Each Fr As String In Lines
  438.                     If Fr = Nothing Then
  439.                         Continue For
  440.                     End If
  441.                     .Speak(Fr)
  442.                 Next
  443.                 .Play("Announce")
  444.                 'Lettura terminata
  445.                 SayPredSentence(1)
  446.             End With
  447.         End If
  448.     End Sub
  449.  
  450.     'Visualizza il menù delle sveglie
  451.     Private Sub imgAlarm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgAlarm.Click
  452.         Dim A As New frmAlarm
  453.         A.Show()
  454.     End Sub
  455.  
  456.     'Apre il menù delle macro
  457.     Private Sub imgMacros_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgMacros.Click
  458.         Dim M As New frmMacro
  459.         M.ShowDialog()
  460.     End Sub
  461.  
  462.     'Esegue il tutorial del programma
  463.     Private Sub strTutorial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strTutorial.Click
  464.         'Agente.MoveTo(Display.Width / 2 - Agente.Width / 2, Display.Height / 2 - Agente.Height / 2)
  465.         'Agente.StopAll()
  466.         Agente.Speak("Benvenuto nel tutòrial del programma.\Pau=500\Ora ti spiegherò come utilizzare tutte le mie funzionalità.")
  467.  
  468.         Dim X, Y As Int32
  469.  
  470.         X = Position.X + (Agente.Width / 2) - Me.Width / 2
  471.         Y = Position.Y + (Agente.Height / 2) - Me.Height / 2
  472.  
  473.         Me.Opacity = 100
  474.         Me.Visible = 100
  475.         Me.Location = New Point(X, Y)
  476.  
  477.         With Agente
  478.             'Data e ora
  479.             '.MoveTo(Me.Location.X - .Width, Me.Location.Y - .Height / 2)
  480.             '.GestureAt(Me.Location.X + imgDate.Location.X, Me.Location.Y + imgDate.Location.Y)
  481.             .Speak("Data e Ora")
  482.             .Speak("Data e Ora: \Pau=200\Visualizza la data e l'ora odierni.")
  483.  
  484.             'Impegni per oggi
  485.             '.MoveTo(Me.Location.X + Me.Width / 2, Me.Location.Y - .Height)
  486.             '.GestureAt(Me.Location.X + imgImp.Location.X, Me.Location.Y + imgImp.Location.Y)
  487.             .Speak("Impegni per oggi")
  488.             .Speak("Qui vengono visualizzati tutti gli impegni che hai progettato per oggi.")
  489.  
  490.             'Modifica impegni
  491.             '.MoveTo(Me.Location.X - .Width, Me.Location.Y + .Height / 2)
  492.             '.GestureAt(Me.Location.X + imgModImp.Location.X, Me.Location.Y + imgModImp.Location.Y)
  493.             .Speak("Modifica impegni")
  494.             .Speak("Qui puoi modificare i tuoi impegni. \Pau=500\Seleziona il giorno che preferisci, scrivi quello che vuoi, quindi clicca Salva.")
  495.             .Speak("Cliccando Cancella, cancellerai l'impegno selezionato.")
  496.  
  497.             'Sveglie
  498.             '.MoveTo(Me.Location.X + (Me.Width - .Width) / 2, Me.Location.Y - .Height)
  499.             '.GestureAt(Me.Location.X + imgAlarm.Location.X, Me.Location.Y + imgAlarm.Location.Y)
  500.             .Speak("Sveglie")
  501.             .Speak("Qui puoi aggiungere quante sveglie vuoi. \Pau=500\Ogni trenta secondi controllerò se hai impostato qualche sveglia per l'ora attuale.")
  502.             .Speak("Se l'avrai fatto, ti dirò quello che hai scritto come un promemoria.")
  503.             .Speak("Puoi scrivere 'macro: <nome macro>' al posto del testo per eseguire una macro a una data ora.")
  504.  
  505.             'Leggi file
  506.             '.MoveTo(Me.Location.X - .Width, Me.Location.Y + .Height)
  507.             '.GestureAt(Me.Location.X + imgReadFile.Location.X, Me.Location.Y + imgReadFile.Location.Y)
  508.             .Speak("Leggi file")
  509.             .Speak("Cliccando qui mi potrai far leggere un file di testo con estensione TXT.")
  510.  
  511.             'Opzioni
  512.             '.MoveTo(Me.Location.X + Math.Abs(Me.Width - .Width) / 2, Me.Location.Y + Math.Abs(Me.Height - .Height) / 2)
  513.             '.GestureAt(Me.Location.X + imgOption.Location.X, Me.Location.Y + imgOption.Location.Y)
  514.             .Speak("Opzioni")
  515.             .Speak("Qui potrai modificare le frasi che dico e decidere anche di non farmi parlare.")
  516.             .Speak("Inoltre puoi modificare il carattere dei fumetti, la mia posizione iniziale e cambiare agente.")
  517.             .Speak("Clicca Salva per salvare le modifiche.")
  518.  
  519.             'Macro
  520.             '.GestureAt(Me.Location.X + imgMacros.Location.X, Me.Location.Y + imgMacros.Location.Y)
  521.             .Speak("Macro")
  522.             .Speak("Qui puoi aggiungere nuove macro. \Pau=500\Le macro sono combinazioni di azioni che puoi farmi eseguire.")
  523.             .Speak("Posso aprire file, programmi o cartelle per conto tuo in un solo click.")
  524.             .Speak("Clicca con il pulsante destro del mouse sulla casella di testo più grande per avere le opzioni.")
  525.             .Speak("Una volta risposto alle finestre di dialogo sarò io a generare il codice batch per te.")
  526.             .Speak("Clicca Salva per salvare o Cancella per cancellare la macro selezionata.")
  527.  
  528.             'Meteo
  529.             '.GestureAt(Me.Location.X + imgMeteo.Location.X, Me.Location.Y + imgMeteo.Location.Y)
  530.             .Speak("Méteo")
  531.             .Speak("Cliccando qui potrai sapere le previsioni di oggi per la tua zona.")
  532.             .Speak("Per attivare questa funzionalità è necessaria una connessione a Internet: il tempo impiegato per scaricare le informazioni varia a seconda della velocità della tua connessione.")
  533.         End With
  534.     End Sub
  535.  
  536.     'Controlla se ci sono nuove mail
  537.     'Questo rimane da perfezionare
  538.     Private Sub tmrControlMail_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles tmrControlMail.Tick
  539.         'Try
  540.         Dim Client As New Net.Sockets.TcpClient
  541.         Dim NetStr As Net.Sockets.NetworkStream
  542.         Dim Msg() As Byte
  543.         Dim Ret As String
  544.  
  545.         'Si connette
  546.         Client.Connect(Options.POP3_Server, Options.POP3_Port)
  547.         ReDim Msg(Client.ReceiveBufferSize)
  548.         NetStr = Client.GetStream
  549.  
  550.         'While Client.Available = 0
  551.         'End While
  552.  
  553.         'Riceve il messaggio di conferma
  554.         NetStr.Read(Msg, 0, Client.ReceiveBufferSize)
  555.         Ret = System.Text.ASCIIEncoding.ASCII.GetString(Msg)
  556.         If Not Ret.StartsWith("+OK") Then
  557.             Exit Sub
  558.         End If
  559.  
  560.         'Invia l'username
  561.         Msg = System.Text.ASCIIEncoding.ASCII.GetBytes("USER " + Options.POP3_User)
  562.         NetStr.Write(Msg, 0, Msg.Length)
  563.  
  564.         'While Client.Available = 0
  565.         'End While
  566.  
  567.         'Riceve conferma
  568.         NetStr.Read(Msg, 0, Client.ReceiveBufferSize)
  569.         Ret = System.Text.ASCIIEncoding.ASCII.GetString(Msg)
  570.         If Not Ret.StartsWith("+OK") Then
  571.             MessageBox.Show("Username errato! Modificare le opzioni!", "Error #6", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  572.             tmrControlMail.Stop()
  573.             Exit Sub
  574.         End If
  575.  
  576.         'Invia la password
  577.         Msg = System.Text.ASCIIEncoding.ASCII.GetBytes("PASS " + Options.POP3_Password)
  578.         NetStr.Write(Msg, 0, Msg.Length)
  579.  
  580.         'While Client.Available = 0
  581.         'End While
  582.  
  583.         'Riceve conferma
  584.         NetStr.Read(Msg, 0, Client.ReceiveBufferSize)
  585.         Ret = System.Text.ASCIIEncoding.ASCII.GetString(Msg)
  586.         If Not Ret.StartsWith("+OK") Then
  587.             MessageBox.Show("Nome utente o password errati! Modificare le opzioni!", "Error #7", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  588.             Exit Sub
  589.         End If
  590.  
  591.         'While Client.Available = 0
  592.         'End While
  593.  
  594.         'Richiede il numero di mail
  595.         Msg = System.Text.ASCIIEncoding.ASCII.GetBytes("LIST")
  596.         NetStr.Write(Msg, 0, Msg.Length)
  597.  
  598.         'While Client.Available = 0
  599.         'End While
  600.  
  601.         'Riceve conferma
  602.         NetStr.Read(Msg, 0, Client.ReceiveBufferSize)
  603.         Ret = System.Text.ASCIIEncoding.ASCII.GetString(Msg)
  604.         If Ret.StartsWith("+OK") Then
  605.             Dim FirstNumIndex As Int16 = 4
  606.             Dim LastNumIndex As Int16 = Ret.IndexOf("mes") - 1
  607.             Dim Number As String = Ret.Substring(FirstNumIndex, LastNumIndex - FirstNumIndex + 1)
  608.             Agente.Speak("Hai " + Number + " nuove mail!")
  609.         Else
  610.             MsgBox("Errore di login!")
  611.         End If
  612.         ' Catch Ex As Exception
  613.         'MsgBox(Ex.Message)
  614.         'End Try
  615.     End Sub
  616.  
  617.     'Permette di scrivere una mail per riportare eventuali bugs
  618.     Private Sub strBugReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strBugReport.Click
  619.         Dim M As New frmMail
  620.         M.ShowDialog()
  621.     End Sub
  622.  
  623.     'Questo codice permette di prelevare informazione meteo da Yahoo! Meteo
  624.     Public WithEvents WB As New WebBrowser
  625.  
  626.     'Naviga sulla pagina del meteo contraddistinta dall'indice selezionato
  627.     Private Sub imgMeteo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgMeteo.Click
  628.         WB.Navigate("http://it.weather.yahoo.com/ITXX/ITXX" + CInt(Options.Meteo).ToString.PadLeft(4, "0") + "/index_c.html")
  629.     End Sub
  630.  
  631.     'Cerca nella pagina le informzioni
  632.     Private Sub WB_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WB.DocumentCompleted
  633.         Dim Html As String = WB.DocumentText
  634.         Dim Previsione, Alba, Tramonto, Umi As String
  635.         Dim Max, Min, Vento, Condensazione, Visib As String
  636.  
  637.         Previsione = SubStr(Html, "width=52 height=52 alt=" + Chr(34), Chr(34) + ">")
  638.         Max = SubStr(Html, "Massime</small> <b>", "°")
  639.         Min = SubStr(Html, "Minime</small><b> ", "°")
  640.  
  641.         If Options.Meteo_Detailed Then
  642.             Vento = SubStr(Html, "Vento:</font></td><td><font size=-1>", "</font>")
  643.             Visib = SubStr(Html, "Visibilità:</font></td><td><font size=-1>", "</font>")
  644.             Condensazione = SubStr(Html, "Punto di condensazione:</font></td><td><font size=-1>", "°")
  645.             Alba = SubStr(Html, "Alba:</font></td><td><font size=-1>", "</font>")
  646.             Tramonto = SubStr(Html, "Tramonto</font></td><td><font size=-1>", "</font>")
  647.  
  648.             'Umidità e Visibilità generano errori nella ricerca, forse a causa dei caratteri 'à'
  649.             Dim Start_Index As Int32 = Html.IndexOf("Umidit") + "Umidità:</font></td><td><font size=-1>".Length
  650.             Dim End_Index As Int32 = Html.IndexOf("</font>", Start_Index)
  651.             Umi = Html.Substring(Start_Index, End_Index - Start_Index)
  652.  
  653.             Start_Index = Html.IndexOf("Visibilit") + "Visibilità:</font></td><td><font size=-1>".Length
  654.             End_Index = Html.IndexOf("</font>", Start_Index)
  655.             Visib = Html.Substring(Start_Index, End_Index - Start_Index)
  656.  
  657.             Umi = Umi.Replace("%", " per cento")
  658.             Vento = Vento.Replace(" ", " ")
  659.             Vento = Vento.Replace("km/h", "chilometri orari")
  660.             Vento = Vento.Replace("/", " a ")
  661.             If Vento.Contains("-") Then
  662.                 Vento = Vento.Replace("N", "Nord")
  663.                 Vento = Vento.Replace("S", "Sud")
  664.                 Vento = Vento.Replace("O", "Ovest")
  665.                 Vento = Vento.Replace("E", "Est")
  666.             End If
  667.             Vento = "verso " + Vento
  668.             Visib = Visib.Replace(" ", " ")
  669.             Visib = Visib.Replace("km", "chilometri")
  670.             Condensazione = Condensazione + " gradi"
  671.             Alba = Alba.Replace(":", " e ") + " minuti"
  672.             Tramonto = Tramonto.Replace(":", " e ") + " minuti"
  673.         End If
  674.  
  675.         With Agente
  676.             .Play("Read")
  677.             .Speak("Previsioni di oggi")
  678.             .Speak(Previsione + ", con una temperatura massima di " + Max + " gradi e una minima di " + Min + " gradi.")
  679.  
  680.             If Options.Meteo_Detailed Then
  681.                 .Speak("Informazioni aggiuntive")
  682.                 .Speak("Ora dell'alba: " + Alba + ".")
  683.                 .Speak("Ora del tramonto: " + Tramonto + ".")
  684.                 .Speak("Il punto di condensazione è di " + Condensazione + ", con un'umidità del " + Umi + ", mentre la visibilità è di " + Visib + ".")
  685.                 .Speak("Tira un vento " + Vento + ".")
  686.             End If
  687.         End With
  688.         WB.Stop()
  689.     End Sub
  690. End Class