コード例 #1
0
ファイル: FormController.cs プロジェクト: hnjm/NetworkChat
        void Chat_NewFile(string FromID, string From, string FileName)
        {
            if (Settings.Default.PopupOnNewFileArrival)
            {
                notifyIcon1.ShowBalloonTip(5000, "New File From " + From, "You have a file called " + FileName + " from " + From, ToolTipIcon.Info);
                notifyIcon1.Tag = new string[] { FromID, FileName };
            }

            if (Settings.Default.SoundOnNewFileArrival)
            {
                SoundPlayer sp;
                if (Settings.Default.SoundFileLocation != "")
                {
                    if (File.Exists(Settings.Default.SoundFileLocation))
                    {
                        sp = new SoundPlayer(Settings.Default.SoundFileLocation);
                        sp.Play();
                    }
                    else
                    {
                        SystemSounds.Beep.Play();
                    }
                }
                else
                {
                    SystemSounds.Beep.Play();
                }
            }

            if (Settings.Default.SpeakOnNewFileArrival)
            {
                Speak.SpeakPhrase("You have a file called " + FileName + " from " + From);
            }
        }
コード例 #2
0
ファイル: FormController.cs プロジェクト: hnjm/NetworkChat
        private void userPulse(Lan.NetworkUser NetworkUser)
        {
            bool   found = false;
            string pres  = Enum.GetName(typeof(Lan.Presence), NetworkUser.Presence).ToLower();

            for (int i = 0; i < listViewUsers.Items.Count; i++)
            {
                //store in global
                Lan.NetworkUser nu = (Lan.NetworkUser)listViewUsers.Items[i].Tag;

                if (nu.UserUniqueId == NetworkUser.UserUniqueId)// & (nu.ComputerName == NetworkUser.ComputerName))
                {
                    //monitor status changes here
                    //***************************
                    currentUsers.RemoveAll(s => s.UserUniqueId == nu.UserUniqueId);
                    currentUsers.Add(NetworkUser);

                    IEnumerator tss = sendMessageToolStripMenuItemSendMessage.DropDownItems.GetEnumerator();

                    while (tss.MoveNext())
                    {
                        //if(tss.Current.
                        ToolStripItem t = (ToolStripItem)tss.Current;

                        Lan.NetworkUser nut = (Lan.NetworkUser)t.Tag;
                        if (nut.UserUniqueId == NetworkUser.UserUniqueId)
                        {
                            ResourceManager rm  = Resources.ResourceManager;
                            Image           img = (Image)rm.GetObject(pres);
                            t.Tag   = NetworkUser;
                            t.Image = img;
                        }
                    }


                    found = true;
                }
            }

            if (!found)
            {
                ListViewItem lvi = listViewUsers.Items.Add(NetworkUser.UserUniqueId, "", pres);
                lvi.SubItems.Add(NetworkUser.UserName);
                //lvi.SubItems.Add(pres);
                lvi.Tag = NetworkUser;

                ToolStripItem tsi = sendMessageToolStripMenuItemSendMessage.DropDownItems.Add(NetworkUser.UserName);
                tsi.Click += new EventHandler(tsiMenuSendMessage_Click);
                ResourceManager rm  = Resources.ResourceManager;
                Image           img = (Image)rm.GetObject(pres);
                tsi.Tag   = NetworkUser;
                tsi.Image = img;

                currentUsers.Add(NetworkUser);

                if (Settings.Default.SoundWhenUserComesOnline)
                {
                    if (Settings.Default.SoundFileLocation != "")
                    {
                        if (File.Exists(Settings.Default.SoundFileLocation))
                        {
                            SoundPlayer sp = new SoundPlayer(Settings.Default.SoundFileLocation);
                            sp.Play();
                            Thread.Sleep(50);
                        }
                        else
                        {
                            SystemSounds.Beep.Play();
                        }
                    }
                    else
                    {
                        SystemSounds.Beep.Play();
                    }
                }

                if (Settings.Default.PopupWhenUserComesOnline)
                {
                    notifyIcon1.Tag = null;
                    if (NetworkUser.Presence == Lan.Presence.Online)
                    {
                        notifyIcon1.ShowBalloonTip(5000, NetworkUser.UserName + " just came online", NetworkUser.UserName + " is now online on PC: " + NetworkUser.ComputerName, ToolTipIcon.Info);
                    }
                }

                if (Settings.Default.SpeakNameWhenUserComesOnline)
                {
                    Speak.SpeakPhrase(NetworkUser.UserName + " is now online");
                }
            }

            refreshUsers();
            refreshGroups();
        }
コード例 #3
0
ファイル: FormController.cs プロジェクト: hnjm/NetworkChat
        private void invokeMessage(Lan.NetworkUser User, string Message)
        {
            //ONLY do this if the user is present
            object o            = tabPage1.Tag;
            bool   showOnScreen = false;

            if (o.GetType() == typeof(NetworkChat.Lan.NetworkUser))
            {
                NetworkChat.Lan.NetworkUser nu = (NetworkChat.Lan.NetworkUser)o;
                if (nu.UserUniqueId.ToLower() == User.UserUniqueId)
                {
                    showOnScreen = true;
                }
            }
            else //group
            {
            }


            if (showOnScreen)
            {
                richTextBoxReplies.Select(richTextBoxReplies.TextLength, 0);
                //use custom colors for users...
                richTextBoxReplies.SelectedRtf = @"{\rtf1\ansi\deff0{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}" + @"\cf2[" + User.TimeStamp.ToShortTimeString() + "] " + User.UserName + @": }";
                richTextBoxReplies.Select(richTextBoxReplies.TextLength, 0);

                richTextBoxReplies.SelectedRtf = Message;
                richTextBoxReplies.ScrollToCaret(); //.Select(richTextBox1.TextLength, 0);

                if (Settings.Default.AlwaysSpeakMessages)
                {
                    RichTextBox ritb = new RichTextBox();
                    ritb.Rtf = Message;
                    Speak.SpeakPhrase(User.UserName + " says: " + ritb.Text);
                }
            }
            else if (!showOnScreen | !this.TopMost | this.WindowState == FormWindowState.Minimized)//not shown on screen just flash....
            {
                //add user to usersWithMessages;
                notifyIcon1.Tag = User;

                if (Settings.Default.PopupOnNewMessage)
                {
                    notifyIcon1.ShowBalloonTip(5000, "You have a new message", "You have a new message from " + User.UserName, ToolTipIcon.Info);
                }

                if (Settings.Default.SoundOnNewMessage)
                {
                    if (Settings.Default.SoundFileLocation != "")
                    {
                        if (File.Exists(Settings.Default.SoundFileLocation))
                        {
                            SoundPlayer sp = new SoundPlayer(Settings.Default.SoundFileLocation);
                            sp.Play();
                        }
                        else
                        {
                            SystemSounds.Beep.Play();
                        }
                    }
                    else
                    {
                        SystemSounds.Beep.Play();
                    }
                }

                if (Settings.Default.SpeakMessage | Settings.Default.AlwaysSpeakMessages)
                {
                    RichTextBox ritb = new RichTextBox();
                    ritb.Rtf = Message;
                    Speak.SpeakPhrase("You have a message from " + User.UserName + ", which says: " + ritb.Text);
                }
                else if (Settings.Default.SpeakMessageIsFrom)
                {
                    Speak.SpeakPhrase("You have a new message from " + User.UserName);
                }



                usersWithMessages.Add(User);
            }

            //get old string
            //save as user who sent


            RichTextBox rtb = new RichTextBox();
            string      old = userMessages.LoadUserMessageText(User.UserUniqueId);

            rtb.Rtf = old;
            rtb.Select(rtb.TextLength, 0);

            rtb.SelectedRtf = @"{\rtf1\ansi\deff0{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}" + @"\cf2[" + User.TimeStamp.ToShortTimeString() + "] " + User.UserName + @": " + Message + " }";
            richTextBoxReplies.ScrollToCaret();


            userMessages.SaveUserMessageText(User.UserUniqueId, rtb.Rtf);
        }