Example #1
0
 public UrlMessagePartModel(TextMessagePartModel model)
     : base(model)
 {
     if (model is UrlMessagePartModel) {
         _Url = (model as UrlMessagePartModel)._Url;
     }
 }
Example #2
0
        private void TextMessageReceived(object sender, TextMessageEventArgs e)
        {
            Trace.Call(sender, e);

            string user    = e.Sender.Name;
            string status  = e.Sender.Status.ToString();
            string message = e.Message.Text;

            ChatModel chat = Session.GetChat(user, ChatType.Person, this);

            if (chat == null)
            {
                PersonModel person = new PersonModel(user, user, NetworkID, Protocol, this);
                Session.AddChat(chat);
            }

            MessageModel         msg = new MessageModel();
            TextMessagePartModel msgPart;

            msgPart      = new TextMessagePartModel();
            msgPart.Text = String.Format("{0} (Status: {1}) says:\n{2}", user, status, message);
            msg.MessageParts.Add(msgPart);

            Session.AddMessageToChat(chat, msg);
        }
Example #3
0
        private void _Say(ChatModel chat, string message)
        {
            if (!chat.IsEnabled)
            {
                return;
            }

            MessageModel         msg = new MessageModel();
            TextMessagePartModel msgPart;

            _OscarSession.Messages.SendMessage(chat.ID, message);

            msgPart      = new TextMessagePartModel();
            msgPart.Text = "<";
            msg.MessageParts.Add(msgPart);

            msgPart                 = new TextMessagePartModel();
            msgPart.Text            = _OscarSession.ScreenName;
            msgPart.ForegroundColor = new TextColor(0x0000FF);
            msg.MessageParts.Add(msgPart);

            msgPart      = new TextMessagePartModel();
            msgPart.Text = "> ";
            msg.MessageParts.Add(msgPart);

            msgPart      = new TextMessagePartModel();
            msgPart.Text = message;
            msg.MessageParts.Add(msgPart);

            Session.AddMessageToChat(chat, msg);
        }
Example #4
0
        public void CommandHelp(CommandModel cd)
        {
            MessageModel         fmsg = new MessageModel();
            TextMessagePartModel fmsgti;

            fmsgti = new TextMessagePartModel();
            // TRANSLATOR: this line is used as a label / category for a
            // list of commands below. {0} would be AIM or ICQ for example.
            fmsgti.Text = "[" + String.Format(_("{0} Commands"), NetworkID) + "]";
            fmsgti.Bold = true;
            fmsg.MessageParts.Add(fmsgti);

            this.Session.AddMessageToChat(cd.Chat, fmsg);

            string[] help =
            {
                "help",
                "connect aim/icq username password",
            };

            foreach (string line in help)
            {
                cd.FrontendManager.AddTextToChat(cd.Chat, "-!- " + line);
            }
        }
Example #5
0
        public bool AttributesEquals(TextMessagePartModel textPart)
        {
            if ((object)textPart == null)
            {
                return(false);
            }

            if (f_ForegroundColor != textPart.ForegroundColor)
            {
                return(false);
            }
            if (f_BackgroundColor != textPart.BackgroundColor)
            {
                return(false);
            }
            if (f_Underline != textPart.Underline)
            {
                return(false);
            }
            if (f_Bold != textPart.Bold)
            {
                return(false);
            }
            if (f_Italic != textPart.Italic)
            {
                return(false);
            }

            return(base.Equals(textPart));
        }
Example #6
0
        //private void _OnMessageReceived(OscarSession sess, UserInfo userInfo, string message, Encoding encoding, MessageFlags msgFlags)
        private void _OnMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            ChatModel chat = GetChat(e.Message.ScreenName, ChatType.Person);

            if (chat == null)
            {
                PersonModel person = new PersonModel(e.Message.ScreenName,
                                                     e.Message.ScreenName,
                                                     NetworkID,
                                                     Protocol,
                                                     this);
                chat = new PersonChatModel(person,
                                           e.Message.ScreenName,
                                           e.Message.ScreenName,
                                           this);
                Session.AddChat(chat);
                Session.SyncChat(chat);
            }

            MessageModel         msg = new MessageModel();
            TextMessagePartModel textMsg;

            textMsg             = new TextMessagePartModel();
            textMsg.Text        = String.Format("<{0}> ", e.Message.ScreenName);
            textMsg.IsHighlight = true;
            msg.MessageParts.Add(textMsg);

            textMsg      = new TextMessagePartModel();
            textMsg.Text = e.Message.Message;
            msg.MessageParts.Add(textMsg);

            Session.AddMessageToChat(chat, msg);
        }
Example #7
0
        public virtual void MarkAsHighlight()
        {
            // colorize the whole message
            foreach (MessagePartModel msgPart in Message.MessageParts)
            {
                if (!(msgPart is TextMessagePartModel))
                {
                    continue;
                }

                TextMessagePartModel textMsg = (TextMessagePartModel)msgPart;
                if (textMsg.ForegroundColor != null &&
                    textMsg.ForegroundColor != TextColor.None)
                {
                    // HACK: don't overwrite colors as that would replace
                    // nick-colors for example
                    continue;
                }
                // HACK: we have to mark all parts as highlight else
                // ClearHighlights() has no chance to properly undo all
                // highlights
                textMsg.IsHighlight     = true;
                textMsg.ForegroundColor = Settings.HighlightColor;
            }
        }
Example #8
0
        private void _Say(CommandModel command, string text)
        {
            if (!command.Chat.IsEnabled)
            {
                return;
            }

//            string target = command.Chat.ID;
//
//            _JabberClient.Message(target, text);

            MessageModel         msg = new MessageModel();
            TextMessagePartModel msgPart;

            msgPart      = new TextMessagePartModel();
            msgPart.Text = "<";
            msg.MessageParts.Add(msgPart);

            msgPart      = new TextMessagePartModel();
            msgPart.Text = _UsersAddress;
            //msgPart.ForegroundColor = IrcTextColor.Blue;
            msgPart.ForegroundColor = new TextColor(0x0000FF);
            msg.MessageParts.Add(msgPart);

            msgPart      = new TextMessagePartModel();
            msgPart.Text = "> ";
            msg.MessageParts.Add(msgPart);

            msgPart      = new TextMessagePartModel();
            msgPart.Text = text;
            msg.MessageParts.Add(msgPart);

            Session.AddMessageToChat(command.Chat, msg);
        }
Example #9
0
        public void CommandHelp(CommandModel cd)
        {
            MessageModel         fmsg = new MessageModel();
            TextMessagePartModel fmsgti;

            fmsgti = new TextMessagePartModel();
            // TRANSLATOR: this line is used as a label / category for a
            // list of commands below
            fmsgti.Text = "[" + _("MSN Commands") + "]";
            fmsgti.Bold = true;
            fmsg.MessageParts.Add(fmsgti);

            Session.AddMessageToChat(cd.Chat, fmsg);

            string[] help =
            {
                "help",
                "connect msn username password",
            };

            foreach (string line in help)
            {
                cd.FrontendManager.AddTextToChat(cd.Chat, "-!- " + line);
            }
        }
Example #10
0
        public static void ParseUrls(MessageModel msg)
        {
            // clone MessageParts
            IList <MessagePartModel> parts = new List <MessagePartModel>(msg.MessageParts);

            foreach (MessagePartModel part in parts)
            {
                if (part is UrlMessagePartModel)
                {
                    // no need to reparse URL parts
                    continue;
                }
                if (!(part is TextMessagePartModel))
                {
                    continue;
                }

                TextMessagePartModel textPart = (TextMessagePartModel)part;
                Match urlMatch = UrlRegex.Match(textPart.Text);
                // OPT: fast regex scan
                if (!urlMatch.Success)
                {
                    // no URLs in this MessagePart, nothing to do
                    continue;
                }

                // found URL(s)
                // remove current MessagePartModel as we need to split it
                int idx = msg.MessageParts.IndexOf(part);
                msg.MessageParts.RemoveAt(idx);

                string[] textPartParts = textPart.Text.Split(new char[] { ' ' });
                for (int i = 0; i < textPartParts.Length; i++)
                {
                    string textPartPart = textPartParts[i];
                    urlMatch = UrlRegex.Match(textPartPart);
                    if (urlMatch.Success)
                    {
                        UrlMessagePartModel urlPart = new UrlMessagePartModel(textPartPart);
                        //urlPart.ForegroundColor = new TextColor();
                        msg.MessageParts.Insert(idx++, urlPart);
                        msg.MessageParts.Insert(idx++, new TextMessagePartModel(" "));
                    }
                    else
                    {
                        // FIXME: we put each text part into it's own object, instead of combining them (the smart way)
                        TextMessagePartModel notUrlPart = new TextMessagePartModel(textPartPart + " ");
                        // restore formatting / colors from the original text part
                        notUrlPart.IsHighlight     = textPart.IsHighlight;
                        notUrlPart.ForegroundColor = textPart.ForegroundColor;
                        notUrlPart.BackgroundColor = textPart.BackgroundColor;
                        notUrlPart.Bold            = textPart.Bold;
                        notUrlPart.Italic          = textPart.Italic;
                        notUrlPart.Underline       = textPart.Underline;
                        msg.MessageParts.Insert(idx++, notUrlPart);
                    }
                }
            }
        }
Example #11
0
 public UrlMessagePartModel(TextMessagePartModel model)
     : base(model)
 {
     if (model is UrlMessagePartModel)
     {
         _Url = (model as UrlMessagePartModel)._Url;
     }
 }
Example #12
0
        public virtual TextMessagePartModel CreateText(TextMessagePartModel text)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            return(new TextMessagePartModel(text));
        }
Example #13
0
        public static void ParseSmileys(MessageModel msg)
        {
            string simleyRegex;
            simleyRegex = @":-?(\(|\))";
            Regex reg = new Regex(simleyRegex);
            // clone MessageParts
            IList<MessagePartModel> parts = new List<MessagePartModel>(msg.MessageParts);
            foreach (MessagePartModel part in parts) {
                if (!(part is TextMessagePartModel)) {
                    continue;
                }

                TextMessagePartModel textPart = (TextMessagePartModel) part;
                Match simleyMatch = reg.Match(textPart.Text);
                // OPT: fast regex scan
                if (!simleyMatch.Success) {
                    // no smileys in this MessagePart, nothing to do
                    continue;
                }

                // found smiley(s)
                // remove current MessagePartModel as we need to split it
                int idx = msg.MessageParts.IndexOf(part);
                msg.MessageParts.RemoveAt(idx);

                string[] textPartParts = textPart.Text.Split(new char[] {' '});
                for (int i = 0; i < textPartParts.Length; i++) {
                    string textPartPart = textPartParts[i];
                    simleyMatch = reg.Match(textPartPart);
                    if (simleyMatch.Success) {
                        string filename = null;
                        if (textPartPart == ":-)") {
                            filename = "smile.png";
                        }
                        ImageMessagePartModel imagePart = new ImageMessagePartModel(
                            filename,
                            textPartPart
                        );
                        msg.MessageParts.Insert(idx++, imagePart);
                        msg.MessageParts.Insert(idx++, new TextMessagePartModel(" "));
                    } else {
                        // FIXME: we put each text part into it's own object, instead of combining them (the smart way)
                        TextMessagePartModel notUrlPart = new TextMessagePartModel(textPartPart + " ");
                        // restore formatting / colors from the original text part
                        notUrlPart.IsHighlight     = textPart.IsHighlight;
                        notUrlPart.ForegroundColor = textPart.ForegroundColor;
                        notUrlPart.BackgroundColor = textPart.BackgroundColor;
                        notUrlPart.Bold            = textPart.Bold;
                        notUrlPart.Italic          = textPart.Italic;
                        notUrlPart.Underline       = textPart.Underline;
                        msg.MessageParts.Insert(idx++, notUrlPart);
                    }
                }
            }
        }
Example #14
0
        public void ToMarkup()
        {
            MessageModel testmodel = new MessageModel();
            testmodel.IsCompactable = false;
            TextMessagePartModel textmodel;
            UrlMessagePartModel urlmodel;

            textmodel = new TextMessagePartModel("normal");
            testmodel.MessageParts.Add(textmodel);

            textmodel = new TextMessagePartModel("blue");
            textmodel.ForegroundColor = TextColor.Parse("0000FF");
            testmodel.MessageParts.Add(textmodel);

            textmodel = new TextMessagePartModel("bold");
            textmodel.Bold = true;
            testmodel.MessageParts.Add(textmodel);

            textmodel = new TextMessagePartModel("bold2");
            textmodel.Bold = true;
            testmodel.MessageParts.Add(textmodel);

            textmodel = new TextMessagePartModel("normal");
            testmodel.MessageParts.Add(textmodel);

            textmodel = new TextMessagePartModel("underline");
            textmodel.Underline = true;
            testmodel.MessageParts.Add(textmodel);

            textmodel = new TextMessagePartModel("combined");
            textmodel.Underline = true;
            textmodel.Bold = true;
            textmodel.Italic = true;
            textmodel.ForegroundColor = TextColor.Parse("00FF00");
            textmodel.BackgroundColor = TextColor.Parse("0000FF");
            testmodel.MessageParts.Add(textmodel);

            urlmodel = new UrlMessagePartModel("http://www.smuxi.org");
            testmodel.MessageParts.Add(urlmodel);

            textmodel = new TextMessagePartModel("normal");
            testmodel.MessageParts.Add(textmodel);

            string expected = "normal<span color='#0000FF'>blue</span>" +
                "<b>bold</b><b>bold2</b>normal<u>underline</u>" +
                "<span color='#00FF00'><u><b><i>combined</i></b></u></span>" +
                "<span color='#00008B'><u>http://www.smuxi.org</u></span>normal";
            string tested = PangoTools.ToMarkup(testmodel);

            Assert.AreEqual(expected, tested);
        }
Example #15
0
        public TextMessagePartModel(TextMessagePartModel msgPart)
        {
            if (msgPart == null)
            {
                throw new ArgumentNullException("msgPart");
            }

            f_ForegroundColor = msgPart.ForegroundColor;
            f_BackgroundColor = msgPart.BackgroundColor;
            f_Underline       = msgPart.Underline;
            f_Bold            = msgPart.Bold;
            f_Italic          = msgPart.Italic;
            f_Text            = msgPart.Text;
        }
Example #16
0
        private void _Say(ChatModel chat, string text, bool send)
        {
            if (!chat.IsEnabled)
            {
                return;
            }

            if (send)
            {
                string target = chat.ID;
                if (chat.ChatType == ChatType.Person)
                {
                    _JabberClient.Message(target, text);
                }
                else if (chat.ChatType == ChatType.Group)
                {
                    var room = _ConferenceManager.GetRoom(
                        String.Format(
                            "{0}/{1}",
                            target, _JabberClient.User
                            )
                        );
                    room.PublicMessage(text);
                    return; // don't show now. the message will be echoed back if it's sent successfully
                }
            }

            MessageModel         msg = new MessageModel();
            TextMessagePartModel msgPart;

            msgPart      = new TextMessagePartModel();
            msgPart.Text = "<";
            msg.MessageParts.Add(msgPart);

            msgPart      = new TextMessagePartModel();
            msgPart.Text = _JabberClient.User;
            //msgPart.ForegroundColor = IrcTextColor.Blue;
            msgPart.ForegroundColor = new TextColor(0x0000FF);
            msg.MessageParts.Add(msgPart);

            msgPart      = new TextMessagePartModel();
            msgPart.Text = "> ";
            msg.MessageParts.Add(msgPart);

            msgPart      = new TextMessagePartModel();
            msgPart.Text = text;
            msg.MessageParts.Add(msgPart);

            this.Session.AddMessageToChat(chat, msg);
        }
Example #17
0
        public bool Equals(TextMessagePartModel textPart)
        {
            if ((object)textPart == null)
            {
                return(false);
            }

            if (!AttributesEquals(textPart))
            {
                return(false);
            }
            if (f_Text != textPart.Text)
            {
                return(false);
            }

            return(base.Equals(textPart));
        }
Example #18
0
        protected virtual TextMessagePartModel GetColoredIdentityName(
            string idendityName, string normalized)
        {
            var name = new TextMessagePartModel(idendityName);

            if (normalized == null)
            {
                normalized = idendityName;
            }

            var crc = new Crc32();

            crc.ComputeHash(Encoding.UTF8.GetBytes(normalized));
            var hash    = crc.CrcValue;
            var upper24 = hash >> 8;

            /*
             * var lower24 = hash & 0xFFFFFFU;
             * var merged = upper24 ^ lower24;
             * var rotated = (hash >> 16) | ((hash & 0xFFFFU) << 16);
             */
            uint flippedHash       = (hash >> 16) | (hash << 16);
            var  flippedMergedHash = (flippedHash >> 8) ^ (flippedHash & 0xFFFFFFU);

            name.ForegroundColor = new TextColor(upper24);
            name.BackgroundColor = new TextColor(flippedMergedHash);

            /*
             * MD5CryptoServiceProvider csp = new MD5CryptoServiceProvider();
             * var md5hash = csp.ComputeHash(Encoding.UTF8.GetBytes(normalized));
             * var fgHash = BitConverter.ToUInt32(md5hash, 0);
             * var bgHash = BitConverter.ToUInt32(md5hash, 4);
             * name.ForegroundColor = new TextColor(fgHash >> 8);
             * name.BackgroundColor = new TextColor(bgHash >> 8);
             */

            return(name);
        }
Example #19
0
        protected virtual TextMessagePartModel GetColoredIdentityName(
            string idendityName, string normalized)
        {
            var name = new TextMessagePartModel(idendityName);

            if (normalized == null)
            {
                normalized = idendityName;
            }

            var crc = new Crc32();

            crc.ComputeHash(Encoding.UTF8.GetBytes(normalized));
            var  hash              = crc.CrcValue;
            var  upper24           = hash >> 8;
            uint flippedHash       = (hash >> 16) | (hash << 16);
            var  flippedMergedHash = (flippedHash >> 8) ^ (flippedHash & 0xFFFFFFU);

            name.ForegroundColor = new TextColor(upper24);
            name.BackgroundColor = new TextColor(flippedMergedHash);

            return(name);
        }
Example #20
0
        private void _Say(ChatModel chat, string message)
        {
            if (!chat.IsEnabled) {
                return;
            }

            MessageModel msg = new MessageModel();
            TextMessagePartModel msgPart;

            _OscarSession.Messages.SendMessage(chat.ID, message);

            msgPart = new TextMessagePartModel();
            msgPart.Text = "<";
            msg.MessageParts.Add(msgPart);

            msgPart = new TextMessagePartModel();
            msgPart.Text = _OscarSession.ScreenName;
            msgPart.ForegroundColor = new TextColor(0x0000FF);
            msg.MessageParts.Add(msgPart);

            msgPart = new TextMessagePartModel();
            msgPart.Text = "> ";
            msg.MessageParts.Add(msgPart);

            msgPart = new TextMessagePartModel();
            msgPart.Text = message;
            msg.MessageParts.Add(msgPart);

            Session.AddMessageToChat(chat, msg);
        }
Example #21
0
        public void CommandHelp(CommandModel cd)
        {
            MessageModel fmsg = new MessageModel();
            TextMessagePartModel fmsgti;

            fmsgti = new TextMessagePartModel();
            fmsgti.Text = _("[OscarProtocolManager Commands]");
            fmsgti.Bold = true;
            fmsg.MessageParts.Add(fmsgti);

            this.Session.AddMessageToChat(cd.FrontendManager.CurrentChat, fmsg);

            string[] help = {
            "help",
            "connect aim/icq username password",
            };

            foreach (string line in help) {
                cd.FrontendManager.AddTextToCurrentChat("-!- " + line);
            }
        }
Example #22
0
        private void _Say(CommandModel command, string text)
        {
            if (!command.Chat.IsEnabled) {
                return;
            }

            //            string target = command.Chat.ID;
            //
            //            _JabberClient.Message(target, text);

            MessageModel msg = new MessageModel();
            TextMessagePartModel msgPart;

            msgPart = new TextMessagePartModel();
            msgPart.Text = "<";
            msg.MessageParts.Add(msgPart);

            msgPart = new TextMessagePartModel();
            msgPart.Text = _UsersAddress;
            //msgPart.ForegroundColor = IrcTextColor.Blue;
            msgPart.ForegroundColor = new TextColor(0x0000FF);
            msg.MessageParts.Add(msgPart);

            msgPart = new TextMessagePartModel();
            msgPart.Text = "> ";
            msg.MessageParts.Add(msgPart);

            msgPart = new TextMessagePartModel();
            msgPart.Text = text;
            msg.MessageParts.Add(msgPart);

                Session.AddMessageToChat(command.Chat, msg);
        }
Example #23
0
        public void CommandHelp(CommandModel cd)
        {
            MessageModel fmsg = new MessageModel();
            TextMessagePartModel fmsgti;

            fmsgti = new TextMessagePartModel();
            // TRANSLATOR: this line is used as a label / category for a
            // list of commands below
            fmsgti.Text = "[" + _("MSN Commands") + "]";
            fmsgti.Bold = true;
            fmsg.MessageParts.Add(fmsgti);

            Session.AddMessageToChat(cd.Chat, fmsg);

            string[] help = {
            "help",
            "connect msn username password",
            };

            foreach (string line in help) {
                cd.FrontendManager.AddTextToChat(cd.Chat, "-!- " + line);
            }
        }
Example #24
0
        public static void ParseUrls(MessageModel msg)
        {
            string urlRegex;
            //urlRegex = "((([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?)");
            // It was constructed according to the BNF grammar given in RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt).

            /*
            urlRegex = @"^(?<s1>(?<s0>[^:/\?#]+):)?(?<a1>" +
                                  @"//(?<a0>[^/\?#]*))?(?<p0>[^\?#]*)" +
                                  @"(?<q1>\?(?<q0>[^#]*))?" +
                                  @"(?<f1>#(?<f0>.*))?");
            */

            urlRegex = @"(^| )(((https?|ftp):\/\/)|www\.)(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|net|org|info|biz|gov|name|edu|[a-zA-Z][a-zA-Z]))(:[0-9]+)?((\/|\?)[^ ""]*[^ ,;\.:"">)])?";
            Regex reg = new Regex(urlRegex, RegexOptions.IgnoreCase);
            // clone MessageParts
            IList<MessagePartModel> parts = new List<MessagePartModel>(msg.MessageParts);
            foreach (MessagePartModel part in parts) {
                if (part is UrlMessagePartModel) {
                    // no need to reparse URL parts
                    continue;
                }
                if (!(part is TextMessagePartModel)) {
                    continue;
                }

                TextMessagePartModel textPart = (TextMessagePartModel) part;
                Match urlMatch = reg.Match(textPart.Text);
                // OPT: fast regex scan
                if (!urlMatch.Success) {
                    // no URLs in this MessagePart, nothing to do
                    continue;
                }

                // found URL(s)
                // remove current MessagePartModel as we need to split it
                int idx = msg.MessageParts.IndexOf(part);
                msg.MessageParts.RemoveAt(idx);

                string[] textPartParts = textPart.Text.Split(new char[] {' '});
                for (int i = 0; i < textPartParts.Length; i++) {
                    string textPartPart = textPartParts[i];
                    urlMatch = reg.Match(textPartPart);
                    if (urlMatch.Success) {
                        UrlMessagePartModel urlPart = new UrlMessagePartModel(textPartPart);
                        //urlPart.ForegroundColor = new TextColor();
                        msg.MessageParts.Insert(idx++, urlPart);
                        msg.MessageParts.Insert(idx++, new TextMessagePartModel(" "));
                    } else {
                        // FIXME: we put each text part into it's own object, instead of combining them (the smart way)
                        TextMessagePartModel notUrlPart = new TextMessagePartModel(textPartPart + " ");
                        // restore formatting / colors from the original text part
                        notUrlPart.IsHighlight     = textPart.IsHighlight;
                        notUrlPart.ForegroundColor = textPart.ForegroundColor;
                        notUrlPart.BackgroundColor = textPart.BackgroundColor;
                        notUrlPart.Bold            = textPart.Bold;
                        notUrlPart.Italic          = textPart.Italic;
                        notUrlPart.Underline       = textPart.Underline;
                        msg.MessageParts.Insert(idx++, notUrlPart);
                    }
                }
            }
        }
Example #25
0
        private void _Say(ChatModel chat, string text)
        {
            if (!chat.IsEnabled) {
                return;
            }

            string target = chat.ID;
            if (chat.ChatType == ChatType.Person) {
                _JabberClient.Message(target, text);
            } else if (chat.ChatType == ChatType.Group) {
                _ConferenceManager.GetRoom(target+"/"+_JabberClient.User).PublicMessage(text);
                return; // don't show now. the message will be echoed back if it's sent successfully
            }

            MessageModel msg = new MessageModel();
            TextMessagePartModel msgPart;

            msgPart = new TextMessagePartModel();
            msgPart.Text = "<";
            msg.MessageParts.Add(msgPart);

            msgPart = new TextMessagePartModel();
            msgPart.Text = _JabberClient.User;
            //msgPart.ForegroundColor = IrcTextColor.Blue;
            msgPart.ForegroundColor = new TextColor(0x0000FF);
            msg.MessageParts.Add(msgPart);

            msgPart = new TextMessagePartModel();
            msgPart.Text = "> ";
            msg.MessageParts.Add(msgPart);

            msgPart = new TextMessagePartModel();
            msgPart.Text = text;
            msg.MessageParts.Add(msgPart);

            this.Session.AddMessageToChat(chat, msg);
        }
Example #26
0
        void ParseStyle(XmlNode style, TextMessagePartModel submodel)
        {
            if (style == null)
            {
                return;
            }
            var properties = style.InnerText.Split(';');

            foreach (string property in properties)
            {
                var colonpos = property.IndexOf(':');
                if (colonpos == -1)
                {
                    continue;
                }
                string name  = property.Substring(0, colonpos).Trim();
                string value = property.Substring(colonpos + 1).Trim();
                switch (name)
                {
                case "background":
                    value = value.Split(' ')[0];
                    submodel.BackgroundColor = TextColor.Parse(value);
                    break;

                case "background-color":
                    submodel.BackgroundColor = TextColor.Parse(value);
                    break;

                case "color":
                    submodel.ForegroundColor = TextColor.Parse(value);
                    break;

                case "font-style":
                    if (value == "normal")
                    {
                        submodel.Italic = false;
                    }
                    else if (value == "inherit")
                    {
                    }
                    else
                    {
                        submodel.Italic = true;
                    }
                    break;

                case "font-weight":
                    if (value == "normal")
                    {
                        submodel.Bold = false;
                    }
                    else if (value == "inherit")
                    {
                    }
                    else
                    {
                        submodel.Bold = true;
                    }
                    break;

                case "text-decoration":
                {
                    foreach (string val in value.Split(' '))
                    {
                        if (val == "underline")
                        {
                            submodel.Underline = true;
                        }
                    }
                }
                break;

                case "font-family":
                case "font-size":
                case "text-align":
                case "margin-left":
                case "margin-right":
                default:
                    // ignore formatting
                    break;
                }
            }
        }
Example #27
0
 void ParseStyle(XmlNode style, TextMessagePartModel submodel)
 {
     if (style == null) return;
     var properties = style.InnerText.Split(';');
     foreach (string property in properties) {
         var colonpos = property.IndexOf(':');
         if (colonpos == -1) continue;
         string name = property.Substring(0, colonpos).Trim();
         string value = property.Substring(colonpos+1).Trim();
         switch (name) {
             case "background":
                 value = value.Split(' ')[0];
                 submodel.BackgroundColor = TextColor.Parse(value);
                 break;
             case "background-color":
                 submodel.BackgroundColor = TextColor.Parse(value);
                 break;
             case "color":
                 submodel.ForegroundColor = TextColor.Parse(value);
                 break;
             case "font-style":
                 if (value == "normal") {
                     submodel.Italic = false;
                 } else if (value == "inherit") {
                 } else {
                     submodel.Italic = true;
                 }
                 break;
             case "font-weight":
                 if (value == "normal") {
                     submodel.Bold = false;
                 } else if (value == "inherit") {
                 } else {
                     submodel.Bold = true;
                 }
                 break;
             case "text-decoration":
             {
                 foreach (string val in value.Split(' ')) {
                     if (val == "underline") {
                         submodel.Underline = true;
                     }
                 }
             }
                 break;
             case "font-family":
             case "font-size":
             case "text-align":
             case "margin-left":
             case "margin-right":
             default:
                 // ignore formatting
                 break;
         }
     }
 }
Example #28
0
 void ParseHtml(XmlNode node, TextMessagePartModel model)
 {
     TextMessagePartModel submodel;
     string nodetype = node.Name.ToLower();
     if (model is UrlMessagePartModel) {
         submodel = new UrlMessagePartModel(model);
     } else if (nodetype == "a") {
         submodel = new UrlMessagePartModel(model);
         (submodel as UrlMessagePartModel).Url = node.Attributes.GetNamedItem("href").Value;
     } else {
         submodel = new TextMessagePartModel(model);
     }
     switch (nodetype) {
         case "b":
         case "strong":
             submodel.Bold = true;
             break;
         case "i":
         case "em":
             submodel.Italic = true;
             break;
         case "u":
             submodel.Underline = true;
             break;
         default:
             break;
     }
     if (node.Attributes != null) {
         ParseStyle(node.Attributes.GetNamedItem("style"), submodel);
     }
     if (node.HasChildNodes) {
         foreach (XmlNode child in node.ChildNodes) {
             // clone this model
             TextMessagePartModel nextmodel;
             if (submodel is UrlMessagePartModel) {
                 nextmodel = new UrlMessagePartModel(submodel);
             } else {
                 nextmodel = new TextMessagePartModel(submodel);
             }
             ParseHtml(child, nextmodel);
         }
     } else {
         // final node
         if (nodetype == "br") {
             AppendText("\n");
         } else if (nodetype == "img") {
             AppendUrl(node.Attributes.GetNamedItem("src").Value, "[image placeholder - UNIMPLEMENTED]");
         } else {
             model.Text = HttpUtility.HtmlDecode(node.Value);
             AppendText(model);
         }
     }
 }
Example #29
0
 public IEnumerable<MessagePartModel> ParsePatterns(TextMessagePartModel part)
 {
     return ParsePatterns(part, Settings.Patterns);
 }
Example #30
0
        public static IList<MessagePartModel> ParsePatterns(TextMessagePartModel textPart,
                                                            List<MessagePatternModel> patterns)
        {
            if (textPart == null) {
                throw new ArgumentNullException("textPart");
            }
            if (patterns == null) {
                throw new ArgumentNullException("patterns");
            }

            var msgParts = new List<MessagePartModel>();
            if (patterns.Count == 0) {
                // all patterns have been tried -> this text is PURE text
                msgParts.Add(textPart);
                return msgParts;
            }

            var remainingPatterns = new List<MessagePatternModel>(patterns);
            var pattern = remainingPatterns.First();
            remainingPatterns.Remove(pattern);

            var match = pattern.MessagePartPattern.Match(textPart.Text);
            if (!match.Success) {
                // no matches in this MessagePart, try other smartlinks
                return ParsePatterns(textPart, remainingPatterns);
            }

            int lastindex = 0;
            do {
                var groupValues = new string[match.Groups.Count];
                int i = 0;
                foreach (Group @group in match.Groups) {
                    groupValues[i++] = @group.Value;
                }

                string url;
                if (String.IsNullOrEmpty(pattern.LinkFormat)) {
                    url = match.Value;
                } else {
                    url = String.Format(pattern.LinkFormat, groupValues);
                }
                string text;
                if (String.IsNullOrEmpty(pattern.TextFormat)) {
                    text = match.Value;
                } else {
                    text = String.Format(pattern.TextFormat, groupValues);
                }

                if (lastindex != match.Index) {
                    // there were some non-matching-chars before the match
                    // copy that to a TextMessagePartModel
                    var notMatchPart = new TextMessagePartModel(textPart);
                    // only take the proper chunk of text
                    notMatchPart.Text = textPart.Text.Substring(lastindex, match.Index - lastindex);
                    // and try other patterns on this part
                    var parts = ParsePatterns(notMatchPart, remainingPatterns);
                    foreach (var part in parts) {
                        msgParts.Add(part);
                    }
                }

                MessagePartModel msgPart;
                if (pattern.MessagePartType == typeof(UrlMessagePartModel)) {
                    // no need to set URL and text if they are the same
                    text = text == url ? null : text;
                    msgPart = new UrlMessagePartModel(url, text);
                } else if (pattern.MessagePartType == typeof(ImageMessagePartModel)) {
                    msgPart = new ImageMessagePartModel(url, text);
                } else {
                    msgPart = new TextMessagePartModel(text);
                }
                msgParts.Add(msgPart);
                lastindex = match.Index + match.Length;
                match = match.NextMatch();
            } while (match.Success);

            if (lastindex != textPart.Text.Length) {
                // there were some non-url-chars before this url
                // copy TextMessagePartModel
                var notMatchPart = new TextMessagePartModel(textPart);
                // only take the proper chunk of text
                notMatchPart.Text = textPart.Text.Substring(lastindex);
                // and try other smartlinks on this part
                var parts = ParsePatterns(notMatchPart, remainingPatterns);
                foreach (var part in parts) {
                    msgParts.Add(part);
                }
            }
            return msgParts;
        }
Example #31
0
        private void _CommandHelp(CommandModel cd)
        {
            MessageModel msg = new MessageModel();
            TextMessagePartModel msgPart;

            msgPart = new TextMessagePartModel();
            msgPart.Text = _("[Frontend Commands]");
            msgPart.Bold = true;
            msg.MessageParts.Add(msgPart);

            cd.FrontendManager.AddMessageToChat(cd.Chat, msg);

            string[] help = {
            "help",
            "window (number|channelname|queryname|close",
            "clear",
            "echo data",
            "exec command",
            "detach",
            };

            foreach (string line in help) {
                cd.FrontendManager.AddTextToCurrentChat("-!- " + line);
            }
        }
Example #32
0
 public IEnumerable <MessagePartModel> ParsePatterns(TextMessagePartModel part)
 {
     return(ParsePatterns(part, Settings.Patterns));
 }
Example #33
0
 public virtual MessageBuilder AppendText(TextMessagePartModel textPart)
 {
     return(Append(textPart));
 }
Example #34
0
        private void _OnRawMessage(object sender, IrcEventArgs e)
        {
            #if LOG4NET
            //_Logger.Debug("_OnRawMessage(): received: '" + e.Data.RawMessage + "'");
            #endif
            bool handled = false;
            switch (e.Data.Type) {
                case ReceiveType.Who:
                case ReceiveType.List:
                case ReceiveType.Name:
                case ReceiveType.Login:
                case ReceiveType.Topic:
                case ReceiveType.BanList:
                case ReceiveType.ChannelMode:
                    // ignore
                    handled = true;
                    break;
            }

            if (e.Data.Message != null) {
                switch (e.Data.Type) {
                    case ReceiveType.Error:
                        _OnError(e);
                       handled = true;
                        break;
                    case ReceiveType.WhoIs:
                        _OnReceiveTypeWhois(e);
                       handled = true;
                        break;
                    case ReceiveType.WhoWas:
                        _OnReceiveTypeWhowas(e);
                        handled = true;
                        break;
                }
            }

            string chan;
            string nick;
            string msg;
            ChatModel chat;
            switch (e.Data.ReplyCode) {
                case ReplyCode.Null:
                case ReplyCode.Away: // already handled via _OnAway()
                case ReplyCode.NowAway: // already handled via _OnNowAway()
                case ReplyCode.UnAway: // already handled via _OnUnAway()
                case (ReplyCode) 329: // RPL_CREATIONTIME
                case (ReplyCode) 333: // RPL_TOPICWHOTIME: who set topic + timestamp
                    // ignore
                    break;
                case ReplyCode.Bounce: // RPL_ISUPPORT
                    // :friendly.landlord.eloxoph.com 005 meebey CHANTYPES=# PREFIX=(ohv)@%+ NETWORK=Eloxoph AWAYLEN=200 TOPICLEN=300 :are supported by this server
                    // :friendly.landlord.eloxoph.com 005 meebey CHANLIMIT=#:12 IRCD=WeIRCd NICKLEN=25 CASEMAPPING=ascii USERLEN=9 :are supported by this server
                    // :friendly.landlord.eloxoph.com 005 meebey CHANMODE=b,kl,,cimnOrst PENALTY MAXTARGETS=1 MAXBANS=50 MODES=5 LISTMODE=997 :are supported by this server
                    string line = String.Empty;
                    if (e.Data.RawMessageArray.Length >= 4) {
                        line = String.Join(
                            " ", e.Data.RawMessageArray, 3,
                            e.Data.RawMessageArray.Length - 3
                        );
                    }
                    string[] supportList = line.Split(' ');
                    foreach (string support in supportList) {
                        if (support.StartsWith("NETWORK=")) {
                            _Network = support.Split('=')[1];
            #if LOG4NET
                            _Logger.Debug("_OnRawMessage(): detected IRC network: '" + _Network + "'");
            #endif
                        }
                    }
                    break;
                case ReplyCode.ErrorNoSuchNickname:
                    nick = e.Data.RawMessageArray[3];
                    msg = "-!- " + String.Format(_("{0}: No such nick/channel"), nick);
                    chat = GetChat(nick, ChatType.Person);
                    if (chat != null) {
                        Session.AddTextToChat(chat, msg);
                    } else {
                        Session.AddTextToChat(_NetworkChat, msg);
                    }
                    break;
                case ReplyCode.ErrorChannelIsFull:
                case ReplyCode.ErrorInviteOnlyChannel:
                case ReplyCode.ErrorBadChannelKey:
                case ReplyCode.ErrorTooManyChannels:
                case ReplyCode.ErrorChannelOpPrivilegesNeeded:
                case ReplyCode.ErrorCannotSendToChannel:
                case ReplyCode.ErrorUnavailableResource:
                    chan = e.Data.RawMessageArray[3];
                    msg = "-!- " + chan + " " + e.Data.Message;
                    chat = GetChat(chan, ChatType.Group);
                    if (chat != null) {
                        Session.AddTextToChat(chat, msg);
                    } else {
                        Session.AddTextToChat(_NetworkChat, msg);
                    }
                    break;
                case ReplyCode.ErrorBannedFromChannel:
                    _OnErrorBannedFromChannel(e);
                    break;
                case ReplyCode.ErrorNicknameInUse:
                    _OnErrorNicknameInUse(e);
                    break;
                case ReplyCode.EndOfNames:
                    chan = e.Data.RawMessageArray[3];
                    GroupChatModel groupChat = (GroupChatModel)GetChat(
                       chan, ChatType.Group);
                    if (groupChat == null) {
                        break;
                    }
                    groupChat.IsSynced = true;
            #if LOG4NET
                    _Logger.Debug("_OnRawMessage(): " + chan + " synced");
            #endif
                    break;
                default:
                    if (!handled) {
                        var builder = CreateMessageBuilder();
                        builder.MessageType = MessageType.Event;

                        int replyCode = (int) e.Data.ReplyCode;
                        string numeric = String.Format("{0:000}", replyCode);
                        string constant;
                        if (Enum.IsDefined(typeof(ReplyCode), e.Data.ReplyCode)) {
                            constant = e.Data.ReplyCode.ToString();
                        } else {
                            constant = "?";
                        }

                        string parameters = String.Empty;
                        if (e.Data.RawMessageArray.Length >= 4) {
                            parameters = String.Join(
                                " ", e.Data.RawMessageArray, 3,
                                e.Data.RawMessageArray.Length - 3
                            );
                        }
                        int colonPosition = parameters.IndexOf(':');
                        if (colonPosition > 0) {
                            parameters = " " + parameters.Substring(0, colonPosition - 1);
                        } else {
                            parameters = String.Empty;
                        }

                        TextMessagePartModel msgPart;
                        msgPart = new TextMessagePartModel("[");
                        msgPart.ForegroundColor = IrcTextColor.Grey;
                        msgPart.Bold = true;
                        builder.AppendText(msgPart);

                        msgPart = new TextMessagePartModel(numeric);
                        if (replyCode >= 400 && replyCode <= 599) {
                            msgPart.ForegroundColor = new TextColor(255, 0, 0);
                        }
                        msgPart.Bold = true;
                        builder.AppendText(msgPart);

                        var response = String.Format(
                            " ({0}){1}",
                            constant,
                            parameters
                        );
                        builder.AppendText(response);

                        msgPart = new TextMessagePartModel("] ");
                        msgPart.ForegroundColor = IrcTextColor.Grey;
                        msgPart.Bold = true;
                        builder.AppendText(msgPart);

                        if (e.Data.Message != null) {
                            builder.MessageType = MessageType.Normal;
                            builder.AppendMessage(e.Data.Message);
                        }

                        Session.AddMessageToChat(_NetworkChat,
                                                 builder.ToMessage());
                    }
                    break;
            }
        }
Example #35
0
        public bool Equals(TextMessagePartModel textPart)
        {
            if ((object) textPart == null) {
                return false;
            }

            if (!AttributesEquals(textPart)) {
                return false;
            }
            if (f_Text != textPart.Text) {
                return false;
            }

            return base.Equals(textPart);
        }
Example #36
0
        private void InsertToBuffer(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, TextMessagePartModel fmsgti)
        {
            var tags = new List<Gtk.TextTag>();
            if (fmsgti.Text == null) {
                // Gtk.TextBuffer.Insert*() asserts on text == NULL
                return;
            }
            if (fmsgti.ForegroundColor != TextColor.None) {
                var bg = ColorConverter.GetTextColor(BackgroundColor);
                if (fmsgti.BackgroundColor != TextColor.None) {
                    bg = fmsgti.BackgroundColor;
                }
                TextColor color = TextColorTools.GetBestTextColor(
                    fmsgti.ForegroundColor, bg
                );
                string tagname = GetTextTagName(color, null);
                var tag = _MessageTextTagTable.Lookup(tagname);
                tags.Add(tag);
            }
            if (fmsgti.BackgroundColor != TextColor.None) {
                // TODO: get this from ChatView
                string tagname = GetTextTagName(null, fmsgti.BackgroundColor);
                var tag = _MessageTextTagTable.Lookup(tagname);
                tags.Add(tag);
            }
            if (fmsgti.Underline) {
            #if LOG4NET && MSG_DEBUG
                _Logger.Debug("AddMessage(): fmsgti.Underline is true");
            #endif
                tags.Add(UnderlineTag);
            }
            if (fmsgti.Bold) {
            #if LOG4NET && MSG_DEBUG
                _Logger.Debug("AddMessage(): fmsgti.Bold is true");
            #endif
                tags.Add(BoldTag);
            }
            if (fmsgti.Italic) {
            #if LOG4NET && MSG_DEBUG
                _Logger.Debug("AddMessage(): fmsgti.Italic is true");
            #endif
                tags.Add(ItalicTag);
            }

            if (tags.Count > 0) {
                buffer.InsertWithTags(ref iter, fmsgti.Text, tags.ToArray());
            } else {
                buffer.Insert(ref iter, fmsgti.Text);
            }
        }
Example #37
0
        public static void ParseSmileys(MessageModel msg)
        {
            // clone MessageParts
            IList <MessagePartModel> parts = new List <MessagePartModel>(msg.MessageParts);

            foreach (MessagePartModel part in parts)
            {
                if (!(part is TextMessagePartModel))
                {
                    continue;
                }

                TextMessagePartModel textPart = (TextMessagePartModel)part;
                Match simleyMatch             = SimleyRegex.Match(textPart.Text);
                // OPT: fast regex scan
                if (!simleyMatch.Success)
                {
                    // no smileys in this MessagePart, nothing to do
                    continue;
                }

                // found smiley(s)
                // remove current MessagePartModel as we need to split it
                int idx = msg.MessageParts.IndexOf(part);
                msg.MessageParts.RemoveAt(idx);

                string[] textPartParts = textPart.Text.Split(new char[] { ' ' });
                for (int i = 0; i < textPartParts.Length; i++)
                {
                    string textPartPart = textPartParts[i];
                    simleyMatch = SimleyRegex.Match(textPartPart);
                    if (simleyMatch.Success)
                    {
                        string filename = null;
                        if (textPartPart == ":-)")
                        {
                            filename = "smile.png";
                        }
                        ImageMessagePartModel imagePart = new ImageMessagePartModel(
                            filename,
                            textPartPart
                            );
                        msg.MessageParts.Insert(idx++, imagePart);
                        msg.MessageParts.Insert(idx++, new TextMessagePartModel(" "));
                    }
                    else
                    {
                        // FIXME: we put each text part into it's own object, instead of combining them (the smart way)
                        TextMessagePartModel notUrlPart = new TextMessagePartModel(textPartPart + " ");
                        // restore formatting / colors from the original text part
                        notUrlPart.IsHighlight     = textPart.IsHighlight;
                        notUrlPart.ForegroundColor = textPart.ForegroundColor;
                        notUrlPart.BackgroundColor = textPart.BackgroundColor;
                        notUrlPart.Bold            = textPart.Bold;
                        notUrlPart.Italic          = textPart.Italic;
                        notUrlPart.Underline       = textPart.Underline;
                        msg.MessageParts.Insert(idx++, notUrlPart);
                    }
                }
            }
        }
Example #38
0
        public override MessageBuilder AppendMessage(string msg)
        {
            msg = msg ?? "";

            if (msg.Length == 0)
            {
                return(this);
            }

            // strip color and formatting if configured
            if (StripColors)
            {
                msg = Regex.Replace(msg, (char)IrcControlCode.Color +
                                    "[0-9]{1,2}(,[0-9]{1,2})?", String.Empty);
            }
            if (StripFormattings)
            {
                msg = Regex.Replace(msg, String.Format("({0}|{1}|{2}|{3})",
                                                       (char)IrcControlCode.Bold,
                                                       (char)IrcControlCode.Clear,
                                                       (char)IrcControlCode.Italic,
                                                       (char)IrcControlCode.Underline), String.Empty);
            }

            // convert * / _ to mIRC control characters
            string[] messageParts = msg.Split(new char[] { ' ' });
            // better regex? \*([^ *]+)\*
            //string pattern = @"^({0})([A-Za-z0-9]+?){0}$";
            string pattern = @"^({0})([^ *]+){0}$";

            for (int i = 0; i < messageParts.Length; i++)
            {
                messageParts[i] = Regex.Replace(messageParts[i], String.Format(pattern, @"\*"), (char)IrcControlCode.Bold + "$1$2$1" + (char)IrcControlCode.Bold);
                messageParts[i] = Regex.Replace(messageParts[i], String.Format(pattern, "_"), (char)IrcControlCode.Underline + "$1$2$1" + (char)IrcControlCode.Underline);
                messageParts[i] = Regex.Replace(messageParts[i], String.Format(pattern, "/"), (char)IrcControlCode.Italic + "$1$2$1" + (char)IrcControlCode.Italic);
            }
            msg = String.Join(" ", messageParts);

            // crash: ^C^C0,7Dj Ler #Dj KanaL?na Girmek ZorunDaD?rLar UnutMay?N @>'^C0,4WwW.MaViGuL.NeT ^C4]^O ^C4]'
            // parse colors
            bool      bold      = false;
            bool      underline = false;
            bool      italic    = false;
            bool      color     = false;
            TextColor fg_color  = IrcTextColor.Normal;
            TextColor bg_color  = IrcTextColor.Normal;
            bool      controlCharFound;

            do
            {
                string submessage;
                int    controlPos = msg.IndexOfAny(IrcControlChars);
                if (controlPos > 0)
                {
                    // control char found and we have normal text infront
                    controlCharFound = true;
                    submessage       = msg.Substring(0, controlPos);
                    msg = msg.Substring(controlPos);
                }
                else if (controlPos != -1)
                {
                    // control char found
                    controlCharFound = true;

                    char           controlChar  = msg.Substring(controlPos, 1)[0];
                    IrcControlCode controlCode  = (IrcControlCode)controlChar;
                    string         controlChars = controlChar.ToString();
                    switch (controlCode)
                    {
                    case IrcControlCode.Clear:
#if LOG4NET && MSG_DEBUG
                        Logger.Debug("AppendMessage(): found clear control character");
#endif
                        bold      = false;
                        underline = false;
                        italic    = false;

                        color    = false;
                        fg_color = IrcTextColor.Normal;
                        bg_color = IrcTextColor.Normal;
                        break;

                    case IrcControlCode.Bold:
#if LOG4NET && MSG_DEBUG
                        Logger.Debug("AppendMessage(): found bold control character");
#endif
                        bold = !bold;
                        break;

                    case IrcControlCode.Underline:
#if LOG4NET && MSG_DEBUG
                        Logger.Debug("AppendMessage(): found underline control character");
#endif
                        underline = !underline;
                        break;

                    case IrcControlCode.Italic:
#if LOG4NET && MSG_DEBUG
                        Logger.Debug("AppendMessage(): found italic control character");
#endif
                        italic = !italic;
                        break;

                    case IrcControlCode.Color:
#if LOG4NET && MSG_DEBUG
                        Logger.Debug("AppendMessage(): found color control character");
#endif
                        color = !color;
                        string colorMessage = msg.Substring(controlPos);
#if LOG4NET && MSG_DEBUG
                        Logger.Debug("AppendMessage(): colorMessage: '" + colorMessage + "'");
#endif
                        Match match = Regex.Match(colorMessage, "^" + (char)IrcControlCode.Color + "(?<fg>[0-9][0-9]?)(,(?<bg>[0-9][0-9]?))?");
                        if (match.Success)
                        {
                            controlChars = match.Value;
                            int color_code;
                            if (match.Groups["fg"] != null)
                            {
#if LOG4NET && MSG_DEBUG
                                Logger.Debug("AppendMessage(): match.Groups[fg].Value: " + match.Groups["fg"].Value);
#endif
                                try {
                                    color_code = Int32.Parse(match.Groups["fg"].Value);
                                    fg_color   = IrcColorToTextColor(color_code);
                                } catch (FormatException) {
                                    fg_color = IrcTextColor.Normal;
                                }
                            }
                            if (match.Groups["bg"] != null)
                            {
#if LOG4NET && MSG_DEBUG
                                Logger.Debug("AppendMessage(): match.Groups[bg].Value: " + match.Groups["bg"].Value);
#endif
                                try {
                                    color_code = Int32.Parse(match.Groups["bg"].Value);
                                    bg_color   = IrcColorToTextColor(color_code);
                                } catch (FormatException) {
                                    bg_color = IrcTextColor.Normal;
                                }
                            }
                        }
                        else
                        {
                            controlChars = controlChar.ToString();
                            fg_color     = IrcTextColor.Normal;
                            bg_color     = IrcTextColor.Normal;
                        }
#if LOG4NET && MSG_DEBUG
                        Logger.Debug("AppendMessage(): fg_color.HexCode: " + String.Format("0x{0:X6}", fg_color.HexCode));
                        Logger.Debug("AppendMessage(): bg_color.HexCode: " + String.Format("0x{0:X6}", bg_color.HexCode));
#endif
                        break;
                    }
#if LOG4NET && MSG_DEBUG
                    Logger.Debug("AppendMessage(): controlChars.Length: " + controlChars.Length);
#endif

                    // check if there are more control chars in the rest of the message
                    int nextControlPos = msg.IndexOfAny(IrcControlChars, controlPos + controlChars.Length);
                    if (nextControlPos != -1)
                    {
                        // more control chars found
                        submessage = msg.Substring(controlChars.Length, nextControlPos - controlChars.Length);
                        msg        = msg.Substring(nextControlPos);
                    }
                    else
                    {
                        // no next control char
                        // skip the control chars
                        submessage = msg.Substring(controlChars.Length);
                        msg        = String.Empty;
                    }
                }
                else
                {
                    // no control char, nothing to do
                    controlCharFound = false;
                    submessage       = msg;
                }

                TextMessagePartModel msgPart = new TextMessagePartModel();
                msgPart.Text            = submessage;
                msgPart.Bold            = bold;
                msgPart.Underline       = underline;
                msgPart.Italic          = italic;
                msgPart.ForegroundColor = fg_color;
                msgPart.BackgroundColor = bg_color;
                AppendText(msgPart);
            } while (controlCharFound);
            return(this);
        }
Example #39
0
        protected virtual TextMessagePartModel GetColoredIdentityName(
            string idendityName, string normalized)
        {
            var name =  new TextMessagePartModel(idendityName);
            if (normalized == null) {
                normalized = idendityName;
            }

            var crc = new Crc32();
            crc.ComputeHash(Encoding.UTF8.GetBytes(normalized));
            var hash = crc.CrcValue;
            var upper24 = hash >> 8;
            /*
            var lower24 = hash & 0xFFFFFFU;
            var merged = upper24 ^ lower24;
            var rotated = (hash >> 16) | ((hash & 0xFFFFU) << 16);
            */
            uint flippedHash = (hash >> 16) | (hash << 16);
            var flippedMergedHash = (flippedHash >> 8) ^ (flippedHash & 0xFFFFFFU);
            name.ForegroundColor = new TextColor(upper24);
            name.BackgroundColor = new TextColor(flippedMergedHash);

            /*
            MD5CryptoServiceProvider csp = new MD5CryptoServiceProvider();
            var md5hash = csp.ComputeHash(Encoding.UTF8.GetBytes(normalized));
            var fgHash = BitConverter.ToUInt32(md5hash, 0);
            var bgHash = BitConverter.ToUInt32(md5hash, 4);
            name.ForegroundColor = new TextColor(fgHash >> 8);
            name.BackgroundColor = new TextColor(bgHash >> 8);
            */

            return name;
        }
Example #40
0
        public TextMessagePartModel(TextMessagePartModel msgPart)
        {
            if (msgPart == null) {
                throw new ArgumentNullException("msgPart");
            }

            f_ForegroundColor = msgPart.ForegroundColor;
            f_BackgroundColor = msgPart.BackgroundColor;
            f_Underline = msgPart.Underline;
            f_Bold = msgPart.Bold;
            f_Italic = msgPart.Italic;
            f_Text = msgPart.Text;
        }
Example #41
0
        private void TextMessageReceived(object sender, TextMessageEventArgs e)
        {
            Trace.Call(sender, e);

            string user = e.Sender.Name;
            string status = e.Sender.Status.ToString();
            string message = e.Message.Text;

            ChatModel chat = Session.GetChat(user, ChatType.Person, this);
            if (chat == null) {
               PersonModel person = new PersonModel(user, user, NetworkID, Protocol, this);
                   Session.AddChat(chat);
            }

            MessageModel msg = new MessageModel();
            TextMessagePartModel msgPart;

            msgPart = new TextMessagePartModel();
            msgPart.Text = String.Format("{0} (Status: {1}) says:\n{2}", user, status, message);
            msg.MessageParts.Add(msgPart);

            Session.AddMessageToChat(chat, msg);
        }
Example #42
0
        public static IList <MessagePartModel> ParsePatterns(TextMessagePartModel textPart,
                                                             List <MessagePatternModel> patterns)
        {
            if (textPart == null)
            {
                throw new ArgumentNullException("textPart");
            }
            if (patterns == null)
            {
                throw new ArgumentNullException("patterns");
            }

            var msgParts = new List <MessagePartModel>();

            if (patterns.Count == 0)
            {
                // all patterns have been tried -> this text is PURE text
                msgParts.Add(textPart);
                return(msgParts);
            }

            var remainingPatterns = new List <MessagePatternModel>(patterns);
            var pattern           = remainingPatterns.First();

            remainingPatterns.Remove(pattern);

            var match = pattern.MessagePartPattern.Match(textPart.Text);

            if (!match.Success)
            {
                // no matches in this MessagePart, try other smartlinks
                return(ParsePatterns(textPart, remainingPatterns));
            }

            int lastindex = 0;

            do
            {
                var startDelimiterLength = 0;
                var regexDelimiterForStartOfPatternValue = match.Groups[MessageBuilderSettings.StartDelimiterGroupName];
                if (regexDelimiterForStartOfPatternValue != null)
                {
                    startDelimiterLength = regexDelimiterForStartOfPatternValue.Value.Length;
                }
                var endDelimiterLength = 0;
                var regexDelimiterForEndOfPatternValue = match.Groups[MessageBuilderSettings.EndDelimiterGroupName];
                if (regexDelimiterForEndOfPatternValue != null)
                {
                    endDelimiterLength = regexDelimiterForEndOfPatternValue.Value.Length;
                }

                var groupValues = match.Groups.Cast <Group>()

                                  // don't get the delimiter because it only determines
                                  // the start or end of pattern, which is not part of the pattern
                                  .Where(g => g != regexDelimiterForStartOfPatternValue &&
                                         g != regexDelimiterForEndOfPatternValue)

                                  .Select(g => g.Value).ToArray();

                string url;
                if (String.IsNullOrEmpty(pattern.LinkFormat))
                {
                    url = match.Value;
                    url = url.Substring(0 + startDelimiterLength, url.Length - (startDelimiterLength - endDelimiterLength));
                }
                else
                {
                    url = String.Format(pattern.LinkFormat, groupValues);
                }
                string text;
                if (String.IsNullOrEmpty(pattern.TextFormat))
                {
                    text = match.Value;
                }
                else
                {
                    text = String.Format(pattern.TextFormat, groupValues);
                }
                text = text.Substring(0 + startDelimiterLength, text.Length - (startDelimiterLength + endDelimiterLength));

                if (lastindex != match.Index)
                {
                    // there were some non-matching-chars before the match
                    // copy that to a TextMessagePartModel
                    var notMatchPart = new TextMessagePartModel(textPart);
                    // only take the proper chunk of text
                    notMatchPart.Text = textPart.Text.Substring(lastindex, match.Index + startDelimiterLength - lastindex);
                    // and try other patterns on this part
                    var parts = ParsePatterns(notMatchPart, remainingPatterns);
                    foreach (var part in parts)
                    {
                        msgParts.Add(part);
                    }
                }

                MessagePartModel msgPart;
                if (pattern.MessagePartType == typeof(UrlMessagePartModel))
                {
                    // no need to set URL and text if they are the same
                    text    = text == url ? null : text;
                    msgPart = new UrlMessagePartModel(url, text);
                }
                else if (pattern.MessagePartType == typeof(ImageMessagePartModel))
                {
                    msgPart = new ImageMessagePartModel(url, text);
                }
                else
                {
                    msgPart = new TextMessagePartModel(text);
                }
                msgParts.Add(msgPart);
                lastindex = match.Index + match.Length - endDelimiterLength;
                match     = match.NextMatch();
            } while (match.Success);

            if (lastindex != textPart.Text.Length)
            {
                // there were some non-matching-chars after the last match
                // copy TextMessagePartModel
                var notMatchPart = new TextMessagePartModel(textPart);
                // only take the proper chunk of text
                notMatchPart.Text = textPart.Text.Substring(lastindex);
                // and try other smartlinks on this part
                var parts = ParsePatterns(notMatchPart, remainingPatterns);
                foreach (var part in parts)
                {
                    msgParts.Add(part);
                }
            }
            return(msgParts);
        }
Example #43
0
        public override MessageBuilder AppendMessage(string msg)
        {
            msg = msg ?? "";

            if (msg.Length == 0) {
                return this;
            }

            // strip color and formatting if configured
            if (StripColors) {
                msg = Regex.Replace(msg, (char)IrcControlCode.Color +
                            "[0-9]{1,2}(,[0-9]{1,2})?", String.Empty);
            }
            if (StripFormattings) {
                msg = Regex.Replace(msg, String.Format("({0}|{1}|{2}|{3})",
                                                    (char)IrcControlCode.Bold,
                                                    (char)IrcControlCode.Clear,
                                                    (char)IrcControlCode.Italic,
                                                    (char)IrcControlCode.Underline), String.Empty);
            }

            // convert * / _ to mIRC control characters
            string[] messageParts = msg.Split(new char[] {' '});
            // better regex? \*([^ *]+)\*
            //string pattern = @"^({0})([A-Za-z0-9]+?){0}$";
            string pattern = @"^({0})([^ *]+){0}$";
            for (int i = 0; i < messageParts.Length; i++) {
                messageParts[i] = Regex.Replace(messageParts[i], String.Format(pattern, @"\*"), (char)IrcControlCode.Bold      + "$1$2$1" + (char)IrcControlCode.Bold);
                messageParts[i] = Regex.Replace(messageParts[i], String.Format(pattern,  "_"),  (char)IrcControlCode.Underline + "$1$2$1" + (char)IrcControlCode.Underline);
                messageParts[i] = Regex.Replace(messageParts[i], String.Format(pattern,  "/"),  (char)IrcControlCode.Italic    + "$1$2$1" + (char)IrcControlCode.Italic);
            }
            msg = String.Join(" ", messageParts);

            // crash: ^C^C0,7Dj Ler #Dj KanaL?na Girmek ZorunDaD?rLar UnutMay?N @>'^C0,4WwW.MaViGuL.NeT ^C4]^O ^C4]'
            // parse colors
            bool bold = false;
            bool underline = false;
            bool italic = false;
            bool color = false;
            TextColor fg_color = IrcTextColor.Normal;
            TextColor bg_color = IrcTextColor.Normal;
            bool controlCharFound;
            do {
                string submessage;
                int controlPos = msg.IndexOfAny(IrcControlChars);
                if (controlPos > 0) {
                    // control char found and we have normal text infront
                    controlCharFound = true;
                    submessage = msg.Substring(0, controlPos);
                    msg = msg.Substring(controlPos);
                } else if (controlPos != -1) {
                    // control char found
                    controlCharFound = true;

                    char controlChar = msg.Substring(controlPos, 1)[0];
                    IrcControlCode controlCode = (IrcControlCode)controlChar;
                    string controlChars = controlChar.ToString();
                    switch (controlCode) {
                        case IrcControlCode.Clear:
            #if LOG4NET && MSG_DEBUG
                            Logger.Debug("AppendMessage(): found clear control character");
            #endif
                            bold = false;
                            underline = false;
                            italic = false;

                            color = false;
                            fg_color = IrcTextColor.Normal;
                            bg_color = IrcTextColor.Normal;
                            break;
                        case IrcControlCode.Bold:
            #if LOG4NET && MSG_DEBUG
                            Logger.Debug("AppendMessage(): found bold control character");
            #endif
                            bold = !bold;
                            break;
                        case IrcControlCode.Underline:
            #if LOG4NET && MSG_DEBUG
                            Logger.Debug("AppendMessage(): found underline control character");
            #endif
                            underline = !underline;
                            break;
                        case IrcControlCode.Italic:
            #if LOG4NET && MSG_DEBUG
                            Logger.Debug("AppendMessage(): found italic control character");
            #endif
                            italic = !italic;
                            break;
                        case IrcControlCode.Color:
            #if LOG4NET && MSG_DEBUG
                            Logger.Debug("AppendMessage(): found color control character");
            #endif
                            color = !color;
                            string colorMessage = msg.Substring(controlPos);
            #if LOG4NET && MSG_DEBUG
                            Logger.Debug("AppendMessage(): colorMessage: '" + colorMessage + "'");
            #endif
                            Match match = Regex.Match(colorMessage, (char)IrcControlCode.Color + "(?<fg>[0-9][0-9]?)(,(?<bg>[0-9][0-9]?))?");
                            if (match.Success) {
                                controlChars = match.Value;
                                int color_code;
                                if (match.Groups["fg"] != null) {
            #if LOG4NET && MSG_DEBUG
                                    Logger.Debug("AppendMessage(): match.Groups[fg].Value: " + match.Groups["fg"].Value);
            #endif
                                    try {
                                        color_code = Int32.Parse(match.Groups["fg"].Value);
                                        fg_color = IrcColorToTextColor(color_code);
                                    } catch (FormatException) {
                                        fg_color = IrcTextColor.Normal;
                                    }
                                }
                                if (match.Groups["bg"] != null) {
            #if LOG4NET && MSG_DEBUG
                                    Logger.Debug("AppendMessage(): match.Groups[bg].Value: " + match.Groups["bg"].Value);
            #endif
                                    try {
                                        color_code = Int32.Parse(match.Groups["bg"].Value);
                                        bg_color = IrcColorToTextColor(color_code);
                                    } catch (FormatException) {
                                        bg_color = IrcTextColor.Normal;
                                    }
                                }
                            } else {
                                controlChars = controlChar.ToString();
                                fg_color = IrcTextColor.Normal;
                                bg_color = IrcTextColor.Normal;
                            }
            #if LOG4NET && MSG_DEBUG
                            Logger.Debug("AppendMessage(): fg_color.HexCode: " + String.Format("0x{0:X6}", fg_color.HexCode));
                            Logger.Debug("AppendMessage(): bg_color.HexCode: " + String.Format("0x{0:X6}", bg_color.HexCode));
            #endif
                            break;
                    }
            #if LOG4NET && MSG_DEBUG
                    Logger.Debug("AppendMessage(): controlChars.Length: " + controlChars.Length);
            #endif

                    // check if there are more control chars in the rest of the message
                    int nextControlPos = msg.IndexOfAny(IrcControlChars, controlPos + controlChars.Length);
                    if (nextControlPos != -1) {
                        // more control chars found
                        submessage = msg.Substring(controlChars.Length, nextControlPos - controlChars.Length);
                        msg = msg.Substring(nextControlPos);
                    } else {
                        // no next control char
                        // skip the control chars
                        submessage = msg.Substring(controlChars.Length);
                        msg = String.Empty;
                    }
                } else {
                    // no control char, nothing to do
                    controlCharFound = false;
                    submessage = msg;
                }

                TextMessagePartModel msgPart = new TextMessagePartModel();
                msgPart.Text = submessage;
                msgPart.Bold = bold;
                msgPart.Underline = underline;
                msgPart.Italic = italic;
                msgPart.ForegroundColor = fg_color;
                msgPart.BackgroundColor = bg_color;
                AppendText(msgPart);
            } while (controlCharFound);
            return this;
        }
Example #44
0
        private void _CommandHelp(CommandModel cd)
        {
            MessageModel msg = new MessageModel();
            TextMessagePartModel msgPart;

            msgPart = new TextMessagePartModel();
            // TRANSLATOR: this line is used as a label / category for a
            // list of commands below
            msgPart.Text = "[" + _("Frontend Commands") + "]";
            msgPart.Bold = true;
            msg.MessageParts.Add(msgPart);

            cd.FrontendManager.AddMessageToChat(cd.Chat, msg);

            string[] help = {
            "help",
            "window (number|channelname|queryname|close)",
            "clear",
            "echo data",
            "exec command",
            "detach",
            };

            foreach (string line in help) {
                cd.FrontendManager.AddTextToChat(
                    cd.Chat,
                    String.Format("-!- {0}", line)
                );
            }
        }
Example #45
0
        //private void _OnMessageReceived(OscarSession sess, UserInfo userInfo, string message, Encoding encoding, MessageFlags msgFlags)
        private void _OnMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            ChatModel chat = GetChat(e.Message.ScreenName, ChatType.Person);
            if (chat == null) {
                PersonModel person = new PersonModel(e.Message.ScreenName,
                                                     e.Message.ScreenName,
                                                     NetworkID,
                                                     Protocol,
                                                     this);
                chat = new PersonChatModel(person,
                                           e.Message.ScreenName,
                                           e.Message.ScreenName,
                                           this);
                Session.AddChat(chat);
                Session.SyncChat(chat);
            }

            MessageModel msg = new MessageModel();
            TextMessagePartModel textMsg;

            textMsg = new TextMessagePartModel();
            textMsg.Text = String.Format("<{0}> ", e.Message.ScreenName);
            textMsg.IsHighlight = true;
            msg.MessageParts.Add(textMsg);

            textMsg = new TextMessagePartModel();
            textMsg.Text = e.Message.Message;
            msg.MessageParts.Add(textMsg);

            Session.AddMessageToChat(chat, msg);
        }
Example #46
0
 public virtual MessageBuilder AppendText(TextMessagePartModel textPart)
 {
     return Append(textPart);
 }
Example #47
0
        public static IList <MessagePartModel> ParsePatterns(TextMessagePartModel textPart,
                                                             List <MessagePatternModel> patterns)
        {
            if (textPart == null)
            {
                throw new ArgumentNullException("textPart");
            }
            if (patterns == null)
            {
                throw new ArgumentNullException("patterns");
            }

            var msgParts = new List <MessagePartModel>();

            if (patterns.Count == 0)
            {
                // all patterns have been tried -> this text is PURE text
                msgParts.Add(textPart);
                return(msgParts);
            }

            var remainingPatterns = new List <MessagePatternModel>(patterns);
            var pattern           = remainingPatterns.First();

            remainingPatterns.Remove(pattern);

            var match = pattern.MessagePartPattern.Match(textPart.Text);

            if (!match.Success)
            {
                // no matches in this MessagePart, try other smartlinks
                return(ParsePatterns(textPart, remainingPatterns));
            }

            int lastindex = 0;

            do
            {
                var groupValues = new string[match.Groups.Count];
                int i           = 0;
                foreach (Group @group in match.Groups)
                {
                    groupValues[i++] = @group.Value;
                }

                string url;
                if (String.IsNullOrEmpty(pattern.LinkFormat))
                {
                    url = match.Value;
                }
                else
                {
                    url = String.Format(pattern.LinkFormat, groupValues);
                }
                string text;
                if (String.IsNullOrEmpty(pattern.TextFormat))
                {
                    text = match.Value;
                }
                else
                {
                    text = String.Format(pattern.TextFormat, groupValues);
                }

                if (lastindex != match.Index)
                {
                    // there were some non-matching-chars before the match
                    // copy that to a TextMessagePartModel
                    var notMatchPart = new TextMessagePartModel(textPart);
                    // only take the proper chunk of text
                    notMatchPart.Text = textPart.Text.Substring(lastindex, match.Index - lastindex);
                    // and try other patterns on this part
                    var parts = ParsePatterns(notMatchPart, remainingPatterns);
                    foreach (var part in parts)
                    {
                        msgParts.Add(part);
                    }
                }

                MessagePartModel msgPart;
                if (pattern.MessagePartType == typeof(UrlMessagePartModel))
                {
                    // no need to set URL and text if they are the same
                    text    = text == url ? null : text;
                    msgPart = new UrlMessagePartModel(url, text);
                }
                else if (pattern.MessagePartType == typeof(ImageMessagePartModel))
                {
                    msgPart = new ImageMessagePartModel(url, text);
                }
                else
                {
                    msgPart = new TextMessagePartModel(text);
                }
                msgParts.Add(msgPart);
                lastindex = match.Index + match.Length;
                match     = match.NextMatch();
            } while (match.Success);

            if (lastindex != textPart.Text.Length)
            {
                // there were some non-url-chars before this url
                // copy TextMessagePartModel
                var notMatchPart = new TextMessagePartModel(textPart);
                // only take the proper chunk of text
                notMatchPart.Text = textPart.Text.Substring(lastindex);
                // and try other smartlinks on this part
                var parts = ParsePatterns(notMatchPart, remainingPatterns);
                foreach (var part in parts)
                {
                    msgParts.Add(part);
                }
            }
            return(msgParts);
        }
Example #48
0
        public virtual TextMessagePartModel CreateText(TextMessagePartModel text)
        {
            if (text == null) {
                throw new ArgumentNullException("text");
            }

            return new TextMessagePartModel(text);
        }
Example #49
0
        void ProcessIdentityNameChanged(XmppPersonModel contact, TextMessagePartModel oldIdentityNameColored, string oldIdentityName)
        {
            var builder = CreateMessageBuilder();
            builder.AppendEventPrefix();
            string idstring = (oldIdentityName == contact.Jid.Bare)?"":GenerateIdString(contact);
            oldIdentityNameColored.BackgroundColor = TextColor.None;
            builder.AppendFormat("{2}{1} is now known as {0}", contact, idstring, oldIdentityNameColored);

            if (ContactChat != null) {
                PersonModel oldp = ContactChat.GetPerson(contact.ID);
                if (oldp != null) {
                    Session.UpdatePersonInGroupChat(ContactChat, oldp, contact.ToPersonModel());
                    Session.AddMessageToChat(ContactChat, new MessageModel(builder.ToMessage()));
                }
            }

            var chat = Session.GetChat(contact.ID, ChatType.Person, this) as PersonChatModel;
            if (chat != null) {
                chat.Name = contact.IdentityName;
                builder.MessageType = MessageType.ChatNameChanged;
                var msg = builder.ToMessage();
                Session.AddMessageToChat(chat, msg);

                chat.Person = contact.ToPersonModel();
                var msg2 = new MessageModel(msg);
                msg2.MessageType = MessageType.PersonChatPersonChanged;
                Session.AddMessageToChat(chat, msg2);
            }
        }
Example #50
0
        public static void ParseUrls(MessageModel msg)
        {
            // clone MessageParts
            IList<MessagePartModel> parts = new List<MessagePartModel>(msg.MessageParts);
            foreach (MessagePartModel part in parts) {
                if (part is UrlMessagePartModel) {
                    // no need to reparse URL parts
                    continue;
                }
                if (!(part is TextMessagePartModel)) {
                    continue;
                }

                TextMessagePartModel textPart = (TextMessagePartModel) part;
                Match urlMatch = UrlRegex.Match(textPart.Text);
                // OPT: fast regex scan
                if (!urlMatch.Success) {
                    // no URLs in this MessagePart, nothing to do
                    continue;
                }

                // found URL(s)
                // remove current MessagePartModel as we need to split it
                int idx = msg.MessageParts.IndexOf(part);
                msg.MessageParts.RemoveAt(idx);

                string[] textPartParts = textPart.Text.Split(new char[] {' '});
                for (int i = 0; i < textPartParts.Length; i++) {
                    string textPartPart = textPartParts[i];
                    urlMatch = UrlRegex.Match(textPartPart);
                    if (urlMatch.Success) {
                        UrlMessagePartModel urlPart = new UrlMessagePartModel(textPartPart);
                        //urlPart.ForegroundColor = new TextColor();
                        msg.MessageParts.Insert(idx++, urlPart);
                        msg.MessageParts.Insert(idx++, new TextMessagePartModel(" "));
                    } else {
                        // FIXME: we put each text part into it's own object, instead of combining them (the smart way)
                        TextMessagePartModel notUrlPart = new TextMessagePartModel(textPartPart + " ");
                        // restore formatting / colors from the original text part
                        notUrlPart.IsHighlight     = textPart.IsHighlight;
                        notUrlPart.ForegroundColor = textPart.ForegroundColor;
                        notUrlPart.BackgroundColor = textPart.BackgroundColor;
                        notUrlPart.Bold            = textPart.Bold;
                        notUrlPart.Italic          = textPart.Italic;
                        notUrlPart.Underline       = textPart.Underline;
                        msg.MessageParts.Insert(idx++, notUrlPart);
                    }
                }
            }
        }
Example #51
0
        public void CommandHelp(CommandModel cd)
        {
            MessageModel fmsg = new MessageModel();
            TextMessagePartModel fmsgti;

            fmsgti = new TextMessagePartModel();
            // TRANSLATOR: this line is used as a label / category for a
            // list of commands below. {0} would be AIM or ICQ for example.
            fmsgti.Text = "[" + String.Format(_("{0} Commands"), NetworkID) + "]";
            fmsgti.Bold = true;
            fmsg.MessageParts.Add(fmsgti);

            this.Session.AddMessageToChat(cd.Chat, fmsg);

            string[] help = {
            "help",
            "connect aim/icq username password",
            };

            foreach (string line in help) {
                cd.FrontendManager.AddTextToChat(cd.Chat, "-!- " + line);
            }
        }
Example #52
0
        public void CommandHelp(CommandModel cd)
        {
            Trace.Call(cd);

            if (cd == null) {
                throw new ArgumentNullException("cd");
            }

            MessageModel msg = new MessageModel();
            TextMessagePartModel msgPart;

            msgPart = new TextMessagePartModel();
            msgPart.Text = _("[Engine Commands]");
            msgPart.Bold = true;
            msg.MessageParts.Add(msgPart);

            cd.FrontendManager.AddMessageToChat(cd.Chat, msg);

            string[] help = {
                "help",
                "connect/server protocol [protocol-parameters]",
                "disconnect",
                "network list",
                "network close [server]",
                "network switch [server]",
                "config (save|load)",
            };

            foreach (string line in help) {
                cd.FrontendManager.AddTextToCurrentChat("-!- " + line);
            }
        }
Example #53
0
        void ParseHtml(XmlNode node, TextMessagePartModel model)
        {
            TextMessagePartModel submodel;
            string nodetype = node.Name.ToLower();

            if (model is UrlMessagePartModel)
            {
                submodel = new UrlMessagePartModel(model);
            }
            else if (nodetype == "a")
            {
                submodel = new UrlMessagePartModel(model);
                (submodel as UrlMessagePartModel).Url = node.Attributes.GetNamedItem("href").Value;
            }
            else
            {
                submodel = new TextMessagePartModel(model);
            }
            switch (nodetype)
            {
            case "b":
            case "strong":
                submodel.Bold = true;
                break;

            case "i":
            case "em":
                submodel.Italic = true;
                break;

            case "u":
                submodel.Underline = true;
                break;

            default:
                break;
            }
            if (node.Attributes != null)
            {
                ParseStyle(node.Attributes.GetNamedItem("style"), submodel);
            }
            if (node.HasChildNodes)
            {
                foreach (XmlNode child in node.ChildNodes)
                {
                    // clone this model
                    TextMessagePartModel nextmodel;
                    if (submodel is UrlMessagePartModel)
                    {
                        nextmodel = new UrlMessagePartModel(submodel);
                    }
                    else
                    {
                        nextmodel = new TextMessagePartModel(submodel);
                    }
                    ParseHtml(child, nextmodel);
                }
            }
            else
            {
                // final node
                if (nodetype == "br")
                {
                    AppendText("\n");
                }
                else if (nodetype == "img")
                {
                    AppendUrl(node.Attributes.GetNamedItem("src").Value, "[image placeholder - UNIMPLEMENTED]");
                }
                else
                {
                    model.Text = HttpUtility.HtmlDecode(node.Value);
                    AppendText(model);
                }
            }
        }
Example #54
0
        public bool AttributesEquals(TextMessagePartModel textPart)
        {
            if ((object) textPart == null) {
                return false;
            }

            if (f_ForegroundColor != textPart.ForegroundColor) {
                return false;
            }
            if (f_BackgroundColor != textPart.BackgroundColor) {
                return false;
            }
            if (f_Underline != textPart.Underline) {
                return false;
            }
            if (f_Bold != textPart.Bold) {
                return false;
            }
            if (f_Italic != textPart.Italic) {
                return false;
            }

            return base.Equals(textPart);
        }