I manage to get my email widget working thanks to th code here so kindly uploaded Byron Todd, I have a no new mail state and a New mail state, but where in the code can I reset to a default state, so that when the email notifier has been click and the user has gone to url I cam set Object.state to default so it displays a fresh icon, Sorry for my bad english.
'Global variables here
Dim UserID, Passwd 'Placeholders for user id and password
Dim CtrlKey
Const VK_Control = &H11 ' Control key
'Called when the script is executed
Sub Object_OnScriptEnter
UserID = Object.LocalStorage("UserID") 'Retrieve saved user id information
Passwd = Object.LocalStorage("Passwd") 'Retrieve saved password information
CtrlKey = False
VerifyParams 'Check to see if user id and password have been set
Object.SetTimer 500, 300000 '300000ms equals 5 minutes - adjust to your liking
End Sub
Sub VerifyParams
If UserID = "" Or Passwd = "" Then
SetParams 'Get the user id and password
End If
CheckGmail 'The process to check and count # of gmails via the Atom feed
End Sub
Function Object_OnLButtonUp(x, y, moved)
If Moved = False Then
If CtrlKey Then 'Control-Click was detected, so configure object is called
SetParams
CtrlKey = False
Else
DesktopX.Object("DotGmailURL").ExecuteCommand 'Open the default browser to Gmail
End If
End If
End Function
Function Object_OnKeyDown(key, extended) 'Returns whether or not Control key is pressed
If key = VK_Control Then 'at time of "click"
CtrlKey = True
Else
CtrlKey = False
End If
End Function
Sub Object_OnMouseLeave
CheckGmail 'Force a check of Gmail simply by mousing over (and leaving)
End Sub
Sub SetParams 'Not much error checking at the moment, just checks for blanks
NewUserID = InputBox("Current Gmail ID = " & UserID _
& VBCrlf & VBCrlf & "Change to [Everything in front of @gmail.com]: ")
If NewUserID <> "" Then
UserID = NewUserID
Else
End If
NewPasswd = InputBox("Current Gmail Password = " & Passwd _
& VBCrlf & VBCrlf & "Change to: ")
If NewPasswd <> "" Then
Passwd = NewPasswd
Else
End If
End Sub
Sub Object_OnTimer500 'Check on a regular basis
CheckGmail
End Sub
Sub CheckGmail 'Code derivative from Woodbridge's gmail objects and similar ones found at Konfab
' MsgBox "Checking GMail " & UserID & " " & Passwd 'Debug mode
If System.InternetConnected = True Then
Set AtomInfo = CreateObject("Microsoft.XmlHttp")
AtomURL = "https://" & UserID & ":" & Passwd & "@gmail.google.com/gmail/feed/atom"
AtomInfo.Open "GET", AtomURL, False 'Make sure that we authenticate to the feed first
AtomInfo.Send "Authentication"
AtomURL = "https://gmail.google.com/gmail/feed/atom"
AtomInfo.Open "GET", AtomURL , False 'Now get the actual feed
AtomInfo.Send "Gmail Information"
GmailAtomInfo = AtomInfo.ResponseText
' MsgBox GmailAtomInfo 'Debug mode - what's coming back?
NumMail = 0
CountMail = 1
Do While CountMail <> 0
CountMail = Instr(CountMail, GmailAtomInfo, "<entry>") 'One <entry> for each available gmail
If CountMail > 1 Then
NumMail = NumMail + 1
CountMail = CountMail + 1
End If
Loop
' MsgBox "Number of Gmails = " & NumMail 'Debug mode - number of Gmails found
If NumMail >= 1 Then
Object.ToolTipText = "You have " & NumMail & " new Gmail(s)!" & vbNewLine & _
"Click to go to Gmail."
Object.State = "New Gmail"
Else
If NumMail = 0 Then
Object.ToolTipText = "No new Gmails." & vbNewLine & "Control-Click to configure."
Object.State = "No New Mail"
End If
End If
Set AtomInfo = Nothing 'All "Set" variables are pointers and must be set to nothing
'or memory leakage occurs
Else
Object.ToolTipText = "Internet Not Connected"
End If
End Sub
'Called when the script is terminated
Sub Object_OnScriptExit
Object.KillTimer 500 'Kill the timer !!!Don't leave Timers running!!!
Object.LocalStorage("UserID") = UserID 'Store UserID
Object.LocalStorage("Passwd") = Passwd 'Store Password
End Sub