コード例 #1
0
 void logOut()
 {
     refreshTimer.Stop();
     ReplaceNotifyIcon(mainIcon, IconUtils.CreateIconWithBackground(Properties.Resources.NotificationDisabled, Properties.Settings.Default.InboxNoneColor, SystemInformation.SmallIconSize));
     countIcon.Visible       = false;
     loginMenuItem.Visible   = true;
     refreshMenuItem.Visible = false;
     markException(Properties.Resources.NotLoggedIn);
 }
コード例 #2
0
 void notifyIcon_Click(object sender, EventArgs e)
 {
     if (hasNotifications)
     {
         // Make icon normal colored
         newNotifAcknowledged = true;
         ReplaceNotifyIcon(mainIcon, IconUtils.CreateIconWithBackground(Properties.Resources.NotificationActive, Properties.Settings.Default.InboxAvailableColor, SystemInformation.SmallIconSize));
         string text = client.CurrentCounts.TotalNotifications.ToString();
         ReplaceNotifyIcon(countIcon, IconUtils.CreateIconWithText(text, new Font("Arial", 10 - text.Length, FontStyle.Regular, GraphicsUnit.Point), Properties.Settings.Default.InboxAvailableColor, SystemInformation.SmallIconSize));
     }
 }
コード例 #3
0
        void finishSetup()
        {
            // Set up cookies
            CookieContainer cookies = CredentialStore.GetCommunityCookies();

            client.SetCookies(cookies);

            // Update right click menu
            loginMenuItem.Visible   = false;
            refreshMenuItem.Visible = true;

            // Set main icon visible
            ReplaceNotifyIcon(mainIcon, IconUtils.CreateIconWithBackground(Properties.Resources.NotificationDefault, Properties.Settings.Default.InboxNoneColor, SystemInformation.SmallIconSize));
            mainIcon.Visible = true;

            // Set up timer and fire
            refreshTimer.Start();
            updateNotifications();
        }
コード例 #4
0
        void updateUi(NotificationCounts counts)
        {
            try
            {
                if (oldCounts == null)
                {
                    countsDiff = new NotificationCounts();
                }
                else
                {
                    // Experimental anti-flapping: don't set counts to zero unless we have updatesUntilSetCountsToZero
                    // of confirmed polls with zero notifications
                    if (Properties.Settings.Default.EnableAntiFlapping)
                    {
                        if (counts.TotalNotifications > 0)
                        {
                            updatesSinceLastNonZeroNotificationsCount = 0;
                        }
                        else
                        {
                            ++updatesSinceLastNonZeroNotificationsCount;
                            if (updatesSinceLastNonZeroNotificationsCount < updatesUntilSetCountsToZero)
                            {
                                return;
                            }
                        }
                    }

                    var prev = oldCounts;
                    countsDiff = new NotificationCounts
                    {
                        Comments           = counts.Comments - prev.Comments,
                        Items              = counts.Items - prev.Items,
                        Invites            = counts.Invites - prev.Invites,
                        Gifts              = counts.Gifts - prev.Gifts,
                        OfflineMessages    = counts.OfflineMessages - prev.OfflineMessages,
                        TradeOffers        = counts.TradeOffers - prev.TradeOffers,
                        AsyncGames         = counts.AsyncGames - prev.AsyncGames,
                        ModeratorMessages  = counts.ModeratorMessages - prev.ModeratorMessages,
                        HelpRequestReplies = counts.HelpRequestReplies - prev.HelpRequestReplies,
                        AccountAlerts      = counts.AccountAlerts - prev.AccountAlerts,
                        TotalNotifications = counts.TotalNotifications - prev.TotalNotifications,
                    };
                }

                updatePopupCounts(counts);
                mainIcon.Text  = Application.ProductName;
                countIcon.Text = string.Format(counts.TotalNotifications == 1 ? Properties.Resources.UnreadNotificationsSingular : Properties.Resources.UnreadNotificationsPlural, counts.TotalNotifications);

                if (counts.TotalNotifications == 0)
                {
                    hasNotifications  = false;
                    countIcon.Visible = false;
                    ReplaceNotifyIcon(mainIcon, IconUtils.CreateIconWithBackground(Properties.Resources.NotificationDefault, Properties.Settings.Default.InboxNoneColor, SystemInformation.SmallIconSize));
                    mainIcon.Visible = true;
                }
                else
                {
                    hasNotifications = true;
                    Color newColor;
                    if (oldCounts == null)
                    {
                        newNotifAcknowledged = true;
                        newColor             = Properties.Settings.Default.InboxAvailableColor;
                    }
                    else
                    {
                        if (counts.TotalNotifications > oldCounts.TotalNotifications)
                        {
                            newNotifAcknowledged = false;
                            newColor             = Properties.Settings.Default.InboxNewColor;
                        }
                        else if (counts.TotalNotifications == oldCounts.TotalNotifications)
                        {
                            newColor = newNotifAcknowledged ? Properties.Settings.Default.InboxAvailableColor : Properties.Settings.Default.InboxNewColor;
                        }
                        else
                        {
                            newNotifAcknowledged = true;
                            newColor             = Properties.Settings.Default.InboxAvailableColor;
                        }
                    }

                    ReplaceNotifyIcon(mainIcon, IconUtils.CreateIconWithBackground(Properties.Resources.NotificationActive, newColor, SystemInformation.SmallIconSize));

                    // 7 point for 3 digits
                    // 8 point for 2 digits
                    // 9 point for 1 digit
                    string text = counts.TotalNotifications.ToString();
                    ReplaceNotifyIcon(countIcon, IconUtils.CreateIconWithText(text, new Font("Arial", 10 - text.Length, FontStyle.Regular, GraphicsUnit.Point),
                                                                              Properties.Settings.Default.NotificationCountColor, newColor, SystemInformation.SmallIconSize));

                    if (!countIcon.Visible)
                    {
                        // Hide main icon first, then show in this order so the count is on the left
                        mainIcon.Visible  = false;
                        countIcon.Visible = true;
                    }
                    mainIcon.Visible = !Properties.Settings.Default.SingleIcon;

                    if (Properties.Settings.Default.EnableBalloons && !muted)
                    {
                        List <string> notifications = new List <string>();
                        if (countsDiff.Comments > 0)
                        {
                            notifications.Add(countsDiff.Comments == 1 ? Properties.Resources.CommentsSingular : string.Format(Properties.Resources.CommentsPlural, countsDiff.Comments));
                        }
                        if (countsDiff.Items > 0)
                        {
                            notifications.Add(countsDiff.Items == 1 ? Properties.Resources.ItemsSingular : string.Format(Properties.Resources.ItemsPlural, countsDiff.Items));
                        }
                        if (countsDiff.Invites > 0)
                        {
                            notifications.Add(countsDiff.Invites == 1 ? Properties.Resources.InvitesSingular : string.Format(Properties.Resources.InvitesPlural, countsDiff.Invites));
                        }
                        if (countsDiff.Gifts > 0)
                        {
                            notifications.Add(countsDiff.Gifts == 1 ? Properties.Resources.GiftsSingular : string.Format(Properties.Resources.GiftsPlural, countsDiff.Gifts));
                        }
                        if (countsDiff.OfflineMessages > 0)
                        {
                            notifications.Add(countsDiff.OfflineMessages == 1 ? Properties.Resources.OfflineMessagesSingular : string.Format(Properties.Resources.OfflineMessagesPlural, countsDiff.OfflineMessages));
                        }
                        if (countsDiff.TradeOffers > 0)
                        {
                            notifications.Add(countsDiff.TradeOffers == 1 ? Properties.Resources.TradeOffersSingular : string.Format(Properties.Resources.TradeOffersPlural, countsDiff.TradeOffers));
                        }
                        if (countsDiff.AsyncGames > 0)
                        {
                            notifications.Add(countsDiff.AsyncGames == 1 ? Properties.Resources.AsyncGamesSingular : string.Format(Properties.Resources.AsyncGamesPlural, countsDiff.AsyncGames));
                        }
                        if (countsDiff.ModeratorMessages > 0)
                        {
                            notifications.Add(countsDiff.ModeratorMessages == 1 ? Properties.Resources.ModeratorMessagesSingular : string.Format(Properties.Resources.ModeratorMessagesPlural, countsDiff.ModeratorMessages));
                        }
                        if (countsDiff.HelpRequestReplies > 0)
                        {
                            notifications.Add(countsDiff.HelpRequestReplies == 1 ? Properties.Resources.HelpRequestRepliesSingular : string.Format(Properties.Resources.HelpRequestRepliesPlural, countsDiff.HelpRequestReplies));
                        }
                        if (countsDiff.AccountAlerts > 0)
                        {
                            notifications.Add(countsDiff.AccountAlerts == 1 ? Properties.Resources.AccountAlertsSingular : string.Format(Properties.Resources.AccountAlertsPlural, countsDiff.AccountAlerts));
                        }

                        if (notifications.Count > 0)
                        {
                            countIcon.BalloonTipIcon  = ToolTipIcon.Info;
                            countIcon.BalloonTipTitle = countIcon.Text;

                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(Properties.Resources.NewNotifsSince);
                            sb.AppendLine();
                            foreach (string notif in notifications)
                            {
                                sb.AppendLine(notif);
                            }
                            countIcon.BalloonTipText = sb.ToString();
                            countIcon.ShowBalloonTip(10000); // Per MSDN, timeout doesn't make a difference (since Vista)
                        }
                    }
                }

                oldCounts = counts;
            }
            catch (Exception ex)
            {
                markException(Properties.Resources.Exception + ex.Message);
            }
        }