コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: svenwal/Paw
 void growl_ServerMessage(GrowlServer sender, GrowlServer.LogMessageType type, string message)
 {
     if (Properties.Settings.Default.ShowServerMessages)
     {
         SnarlConnector.ShowMessageEx("Growl server messages", sender.ServerName, message, 10, pawIconPath, registeredApps["Paw"].windowHandle, Snarl.WindowsMessage.WM_USER + 24, "");
     }
 }
コード例 #2
0
        public Window1()
        {
            client = new WlanClient();
            InitializeComponent();

            this.snarlComWindow            = new NativeWindowApplication.SnarlMsgWnd();
            SnarlMsgWndHandle              = snarlComWindow.Handle;
            executablePath                 = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\";
            iconPath                       = executablePath + wirelessFull;
            this.snarlComWindow.pathToIcon = iconPath;
            SnarlConnector.RegisterConfig(SnarlMsgWndHandle, "WiFiSnarler", Snarl.WindowsMessage.WM_USER + 55, iconPath);
            SnarlConnector.RegisterAlert("WiFiSnarler", "WiFi connected");
            SnarlConnector.RegisterAlert("WiFiSnarler", "WiFi connected signal strength");
            SnarlConnector.RegisterAlert("WiFiSnarler", "WiFi disconnected");


            //WlanClient client = new WlanClient();

            foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
            {
                //Add the event to track when the wireless connection changes
                wlanIface.WlanConnectionNotification += new WlanClient.WlanInterface.WlanConnectionNotificationEventHandler(wlanIface_WlanConnectionNotification);
                wlanIface.WlanNotification           += new WlanClient.WlanInterface.WlanNotificationEventHandler(wlanIface_eventHandler);
            }



            // initializeAvailableWiFis();

//            NetworkChange.NetworkAddressChanged += new System.Net.NetworkInformation.NetworkAddressChangedEventHandler(NetworkIPChanged);
            //WlanClient test = new WlanClient();
        }
コード例 #3
0
 private void registerWithSnarl()
 {
     SnarlConnector.RegisterConfig(this.Handle, this.application.Name, Snarl.WindowsMessage.WM_USER + 55, pathToIcon);
     foreach (AlertClass alertClass in alertClasses)
     {
         SnarlConnector.RegisterAlert(this.application.Name, alertClass.notificationType.Name);
     }
 }
コード例 #4
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == this.SNARL_GLOBAL_MESSAGE)
            {
                if ((int)m.WParam == Snarl.SnarlConnector.SNARL_LAUNCHED)
                {
                    // Snarl has been (re)started
                    SnarlConnector.GetSnarlWindow(true);
                    registerWithSnarl();
                }
            }

            base.WndProc(ref m);
        }
コード例 #5
0
        void OnClose(object sender, System.ComponentModel.CancelEventArgs args)
        {
            m_notifyIcon.Dispose();
            m_notifyIcon = null;
            SnarlConnector.RevokeConfig(hwnd);
            if (hwnd != IntPtr.Zero)
            {
                snarlComWindow.DestroyHandle();
            }

            backgroundWorker.Abort();

            Properties.Settings.Default.Username = this.userName.Text;
            Properties.Settings.Default.Save();
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: svenwal/Paw
        private Response notificationReceived(Notification notification, CallbackInfo callbackInfo, RequestInfo requestInfo)
        {
            Response returnCode = new Response();

            if (!registeredApps.ContainsKey(notification.ApplicationName.ToUpper()))
            {
                returnCode = new Response(ErrorCode.UNKNOWN_APPLICATION, "Application not registered");
                SnarlConnector.ShowMessageEx("Error messages", "Growl notification from unregistered app", "The application " + notification.ApplicationName + " tried to send a notification without being registered", 10, pawIconPath, registeredApps["Paw"].windowHandle, Snarl.WindowsMessage.WM_USER + 24, "");
            }
            else
            {
                bool   deleteIcon = false;
                string iconPath   = "";
                iconPath = IconFetcher.getPathToIcon(notification);
                if (iconPath == "")
                {
                    GrowlApplication thisApp = registeredApps[notification.ApplicationName.ToUpper()];
                    if (notification.Name != null)
                    {
                        if (thisApp.alertClassIcons.ContainsKey(notification.Name))
                        {
                            iconPath = thisApp.alertClassIcons[notification.Name];
                        }
                    }
                    if (iconPath == "")
                    {
                        iconPath = registeredApps[notification.ApplicationName.ToUpper()].pathToIcon;
                    }
                }
                else
                {
                    deleteIcon = true;
                }
                SnarlConnector.ShowMessageEx(notification.Name, notification.Title, notification.Text, 10, iconPath, registeredApps[notification.ApplicationName.ToUpper()].windowHandle, Snarl.WindowsMessage.WM_USER + 24, "");
                if (deleteIcon)
                {
                    try
                    {
                        System.IO.File.Delete(iconPath);
                    }
                    catch
                    { }
                }
            }
            return(returnCode);
        }
コード例 #7
0
ファイル: SnarlMsgWnd.cs プロジェクト: svenwal/WiFiSnarler
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == this.SNARL_GLOBAL_MESSAGE)
            {
                if ((int)m.WParam == Snarl.SnarlConnector.SNARL_LAUNCHED)
                {
                    // Snarl has been (re)started during already running
                    // so let's register (again)
                    Snarl.SnarlConnector.GetSnarlWindow(true);

                    SnarlConnector.RegisterConfig(this.Handle, "WiFiSnarler", Snarl.WindowsMessage.WM_USER + 55, pathToIcon);

                    SnarlConnector.RegisterAlert("WiFiSnarler", "WiFi connected");
                    SnarlConnector.RegisterAlert("WiFiSnarler", "WiFi disconnected");
                }
            }
            base.WndProc(ref m);
        }
コード例 #8
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == this.SNARL_GLOBAL_MESSAGE)
            {
                if ((int)m.WParam == Snarl.SnarlConnector.SNARL_LAUNCHED)
                {
                    // Snarl has been (re)started during Shaim already running
                    // so let's register (again)
                    Snarl.SnarlConnector.GetSnarlWindow(true);

                    SnarlConnector.RegisterConfig(this.Handle, "digiTweet", Snarl.WindowsMessage.WM_USER + 55, pathToIcon);

                    SnarlConnector.RegisterAlert("digiTweet", "New tweet");
                    SnarlConnector.RegisterAlert("digiTweet", "New direct message");
                    SnarlConnector.RegisterAlert("digiTweet", "Search results");
                }
            }
            base.WndProc(ref m);
        }
コード例 #9
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == this.SNARL_GLOBAL_MESSAGE)
            {
                if ((int)m.WParam == Snarl.SnarlConnector.SNARL_LAUNCHED)
                {
                    Snarl.SnarlConnector.GetSnarlWindow(true);

                    SnarlConnector.RegisterConfig(this.Handle, "last.fm snarls", Snarl.WindowsMessage.WM_USER + 58, iconPath);

                    SnarlConnector.RegisterAlert("last.fm snarls", "Greeting");
                    SnarlConnector.RegisterAlert("last.fm snarls", "Now being played track");
                    SnarlConnector.RegisterAlert("last.fm snarls", "Recently played track");
                    SnarlConnector.RegisterAlert("last.fm snarls", "Connection error");
                    //SnarlConnector.RegisterAlert("last.fm snarls", "Debug messages");
                }
            }
            else if (m.Msg == idOfCurrentTrack)
            {
                if ((int)m.WParam == Snarl.SnarlConnector.SNARL_NOTIFICATION_ACK)
                {
                    if (currentUrl != "")
                    {
                        System.Diagnostics.Process.Start(currentUrl);
                    }
                }
            }
            else if (m.Msg == idOfRecentTrack)
            {
                if ((int)m.WParam == Snarl.SnarlConnector.SNARL_NOTIFICATION_ACK)
                {
                    if (recentUrl != "")
                    {
                        System.Diagnostics.Process.Start(recentUrl);
                    }
                }
            }

            base.WndProc(ref m);
        }
コード例 #10
0
        public MainWindow()
        {
            InitializeComponent();

            this.Title = "last.fm snarls " + versionString;
            if (hwnd == IntPtr.Zero)
            {
                snarlComWindow = new NativeWindowApplication.snarlMsgWnd();
                hwnd           = snarlComWindow.Handle;
            }

            if (!System.IO.File.Exists(iconPath))
            {
                iconPath = "";
            }

            this.userName.Text = Properties.Settings.Default.Username;

            SnarlConnector.RegisterConfig(hwnd, "last.fm snarls", Snarl.WindowsMessage.WM_USER + 58, iconPath);

            SnarlConnector.RegisterAlert("last.fm snarls", "Greeting");
            SnarlConnector.RegisterAlert("last.fm snarls", "Now being played track");
            SnarlConnector.RegisterAlert("last.fm snarls", "Recently played track");
            SnarlConnector.RegisterAlert("last.fm snarls", "last.fm error");
            SnarlConnector.RegisterAlert("last.fm snarls", "Connection error");
            if (DEBUG)
            {
                SnarlConnector.RegisterAlert("last.fm snarls", "Debug messages");
            }


            m_notifyIcon              = new System.Windows.Forms.NotifyIcon();
            m_notifyIcon.Text         = "last.fm snarls";
            m_notifyIcon.Icon         = new System.Drawing.Icon(iconPathApp);
            m_notifyIcon.DoubleClick += new EventHandler(m_notifyIcon_Click);

            userName.Focus();
        }
コード例 #11
0
        static void monitorUser()
        {
            int lastConnectionErrorId = 0;


            //MD5Hash key = new MD5Hash("1ca43b465fcb2306f51f4df7c010067c", true, Encoding.ASCII);
            //MD5Hash secret = new MD5Hash("8c225ea33ff798e680368c2cd45a5f1e", true, Encoding.ASCII);
            //AuthData myAuth = new AuthData(key, secret);
            //Settings20.AuthData = myAuth;

            // LastFmClient client = LastFmClient.Create(myAuth);
            //  client.LastFmUser.Username = "******";
            //  client.LastFmUser.EncryptAndSetPassword("xxxx");

            Track lastPlaying        = new Track();
            Track lastRecent         = new Track();;
            bool  directlyAfterStart = true;

            while (true)
            {
                try
                {
                    Response lastFmData = HttpCommunications.SendGetRequest("http://ws.audioscrobbler.com/2.0/", new
                    {
                        method  = "user.getrecenttracks",
                        user    = userNameString,
                        api_key = "1ca43b465fcb2306f51f4df7c010067c",
                        limit   = 2
                    }, false);

                    if (!lastFmData.Success)
                    {
                        lastConnectionErrorId = SnarlConnector.ShowMessageEx("last.fm error", "last.fm API error", lastFmData.ErrorText, 20, iconPath, hwnd, Snarl.WindowsMessage.WM_USER + 13, "");
                    }
                    else
                    {
                        Track nowPlaying = lastFmData.NowPlaying;
                        Track lastTrack  = lastFmData.LastPlayed;


                        if (nowPlaying != null && lastPlaying.Name != nowPlaying.Name)
                        {
                            string artworkPath = nowPlaying.getBestAlbumArt();
                            if (artworkPath == "")
                            {
                                artworkPath = iconPath;
                            }
                            SnarlConnector.ShowMessageEx("Now being played track", nowPlaying.Artist, nowPlaying.Name + "\n\n" + nowPlaying.Album, 10, artworkPath, hwnd, Snarl.WindowsMessage.WM_USER + 11, "");
                            snarlComWindow.currentUrl = nowPlaying.Link;
                            lastPlaying = nowPlaying;
                        }
                        if (lastTrack != null && lastRecent.Name != lastTrack.Name)
                        {
                            if (!directlyAfterStart)
                            {
                                string artworkPath = lastTrack.getBestAlbumArt();
                                if (artworkPath == "")
                                {
                                    artworkPath = iconPath;
                                }
                                SnarlConnector.ShowMessageEx("Recently played track", lastTrack.Artist, lastTrack.Name + "\n\n" + lastTrack.Album, 10, artworkPath, hwnd, Snarl.WindowsMessage.WM_USER + 12, "");
                                snarlComWindow.recentUrl = lastTrack.Link;
                            }


                            lastRecent = lastTrack;
                        }

                        directlyAfterStart = false;
                    }
                    Thread.Sleep(1000);
                }


                catch (Exception exp)
                {
                    if (lastConnectionErrorId == 0 && exp.Message != "Thread was being aborted.")
                    {
                        lastConnectionErrorId = SnarlConnector.ShowMessageEx("Connection error", "Connection to last.fm failed", "Connection to last.fm can't be established. Maybe the site is down or your internet connection is not available.\n\n" + exp.Message, 20, iconPath, hwnd, Snarl.WindowsMessage.WM_USER + 13, "");
                        if (DEBUG)
                        {
                            SnarlConnector.ShowMessageEx("Debug message", "Error message", exp.Message, 0, iconPath, hwnd, Snarl.WindowsMessage.WM_USER + 77, "");
                            SnarlConnector.ShowMessageEx("Debug message", "Error source", exp.Source, 0, iconPath, hwnd, Snarl.WindowsMessage.WM_USER + 77, "");
                            SnarlConnector.ShowMessageEx("Debug message", "Stack trace", exp.StackTrace.Substring(0, 500), 0, iconPath, hwnd, Snarl.WindowsMessage.WM_USER + 77, "");
                        }
                    }
                }
            }
        }
コード例 #12
0
ファイル: MainWindow.xaml.cs プロジェクト: svenwal/Paw
 void growl_FailedToStart(object sender, EventArgs e)
 {
     SnarlConnector.ShowMessageEx("Error messages", "Growl server failed to start", "Tried to start the Growl server but it failed", 10, pawIconPath, registeredApps["Paw"].windowHandle, Snarl.WindowsMessage.WM_USER + 24, "");
 }
コード例 #13
0
        public void FetchNotifications()
        {
            string rawData = "";

            if (Properties.Settings.Default.UrlOrUnc.ToLower().StartsWith("http"))
            {
                rawData = GetHttpContent(Properties.Settings.Default.UrlOrUnc);
            }
            else
            {
                if (File.Exists(Properties.Settings.Default.UrlOrUnc))
                {
                    rawData = File.ReadAllText(Properties.Settings.Default.UrlOrUnc);
                }
                else
                {
                    if (ShowDebug)
                    {
                        Notifier.EZNotify("Debug", "File not found", Properties.Settings.Default.UrlOrUnc, 10, Properties.Settings.Default.AppIcon);
                    }
                    UpdateTimer.Start();
                    return;
                }
            }
            if (rawData == "")
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "Empty Response", Properties.Settings.Default.UrlOrUnc, 10, Properties.Settings.Default.AppIcon);
                }
                UpdateTimer.Start();
                return;
            }
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.LoadXml(rawData);
            }
            catch (Exception exp)
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "XML general parsing error", exp.Message, 10, Properties.Settings.Default.AppIcon);
                }
                UpdateTimer.Start();
                return;
            }

            if (xmlDoc.DocumentElement.Name != "alerts")
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "Invalid XML", "XML open tag is not \"alerts\"", 10, Properties.Settings.Default.AppIcon);
                }
                UpdateTimer.Start();
                return;
            }

            try
            {
                bool alreadyShown = false;
                foreach (XmlNode alert in xmlDoc.GetElementsByTagName("alert"))
                {
                    alreadyShown = false;
                    IncomingRequest currentAlert = new IncomingRequest();
                    foreach (XmlNode childNode in alert.ChildNodes)
                    {
                        if (alreadyShown)
                        {
                            break;
                        }
                        switch (childNode.Name.ToLower())
                        {
                        case "id":
                            currentAlert.Id = Convert.ToInt64(childNode.InnerText);
                            if (currentAlert.Id > Properties.Settings.Default.LastIdShown)
                            {
                                if (Requests.Where(r => r.Id == currentAlert.Id).Count() > 0)
                                {
                                    alreadyShown = true;
                                    continue;
                                }
                            }
                            else
                            {
                                alreadyShown = true;
                                continue;
                            }

                            break;

                        case "title":
                            currentAlert.Title = childNode.InnerText;
                            break;

                        case "text":
                            currentAlert.Text = childNode.InnerText;
                            break;

                        case "icon":
                            currentAlert.Icon = childNode.InnerText;
                            break;

                        case "displaytime":
                            currentAlert.DisplayTime = Convert.ToInt32(childNode.InnerXml);
                            break;

                        case "app":
                            currentAlert.AppName = childNode.InnerText;
                            break;

                        case "class":
                            currentAlert.ClassName = childNode.InnerText;
                            break;

                        case "leftclickurl":
                            currentAlert.LeftClickUrl = childNode.InnerText;
                            break;

                        case "middleclickurl":
                            currentAlert.MiddleClickUrl = childNode.InnerText;
                            break;

                        case "rightclickurl":
                            currentAlert.RightClickUrl = childNode.InnerText;
                            break;

                        default:
                            break;
                        }
                    }
                    if (!alreadyShown && SnarlConnector.GetSnarlWindow() != IntPtr.Zero)
                    {
                        if (currentAlert.Icon == null)
                        {
                            currentAlert.Icon = Properties.Settings.Default.DefaultNotificationIcon;
                        }
                        if (currentAlert.DisplayTime == null)
                        {
                            currentAlert.DisplayTime = Properties.Settings.Default.DefaultDisplayTime;
                        }
                        if (currentAlert.ClassName == null)
                        {
                            currentAlert.ClassName = Properties.Settings.Default.DefaultNotificationClass;
                        }

                        currentAlert.SnarlNotificationId = Notifier.EZNotify(currentAlert.ClassName, currentAlert.Title, currentAlert.Text, 10, currentAlert.Icon);

                        if (currentAlert.SnarlNotificationId != 0)
                        {
                            currentAlert.AlreadyShown = true;
                            if (Properties.Settings.Default.LastIdShown < currentAlert.Id)
                            {
                                Properties.Settings.Default.LastIdShown = currentAlert.Id;
                                Properties.Settings.Default.Save();
                            }
                            Requests.Add(currentAlert);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "XML Parsing error", exp.Message, 10, Properties.Settings.Default.AppIcon);
                }
            }
            UpdateTimer.Start();
        }