public void Contains()
        {
            Assert.IsTrue(Buffer.Contains(TestMessages[0]));

            var msg = new MessageBuilder();
            msg.AppendText("testfoo");
            Assert.IsFalse(Buffer.Contains(msg.ToMessage()));
        }
Beispiel #2
0
 public void AppendBrokenMail()
 {
     var msg = "mailto:/[email protected]";
     var builder = new MessageBuilder();
     builder.TimeStamp = DateTime.MinValue;
     builder.Append(new TextMessagePartModel("mailto:/"));
     builder.Append(new UrlMessagePartModel("mailto:[email protected]", "*****@*****.**"));
     TestMessage(msg, builder.ToMessage());
 }
        public void Add()
        {
            MessageBuilder msg = new MessageBuilder();
            msg.AppendText("test");

            int count = Buffer.Count;
            Buffer.Add(msg.ToMessage());
            Assert.AreEqual(count + 1, Buffer.Count);
        }
Beispiel #4
0
 public void BenchmarkWithUrl()
 {
     int howOften = 5000;
     var nonurl = @"is this up to date? --> ";
     var url = @"http://www.stack.nl/~jilles/irc/atheme-help/";
     var withUrl = nonurl + url;
     var withoutUrl = @"Generated Sat Dec 11 21:29:16 CET 2010 -- old";
     var builder = new MessageBuilder();
     for (int i = 0; i < howOften; ++i) {
         builder.AppendMessage(withUrl);
     }
 }
Beispiel #5
0
        public void AppendHtmlMessageBold()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            var textPart = builder.CreateText("Test");
            textPart.Bold = true;
            builder.Append(textPart);
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendHtmlMessage("<b>Test</b>");
            var actualMsg = builder.ToMessage();
            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #6
0
        public void ParseUrlsSimple()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendUrl("http://example.com");
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("http://example.com");
            var actualMsg = builder.ToMessage();
            MessageParser.ParseUrls(actualMsg);

            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #7
0
 public void AppendFormatNonIntegerBraceChaos()
 {
     // "{{" -> escaped brace, verbatim text
     // "{{" -> escaped brace, verbatim text
     // "virtual " -> verbatim text
     // "{" -> placeholder starts
     // "0" -> placeholder text
     // "}}" -> escaped brace, placeholder text
     // "}}" -> escaped brace, placeholder text
     // "}" -> placeholder ends
     // => invalid placeholder name "0}}"
     // (same behavior as String.Format)
     var builder = new MessageBuilder();
     builder.AppendFormat("{{{{virtual {0}}}}}", "hugs");
 }
Beispiel #8
0
        public void AppendHtmlMessageCssFgRed()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            var textPart = builder.CreateText("Test");
            textPart.ForegroundColor = new TextColor(255, 0, 0);
            builder.Append(textPart);
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendHtmlMessage("<div style=\"color: #FF0000\">Test</div>");
            var actualMsg = builder.ToMessage();
            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #9
0
        public void ParseUrlsBrackets()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("foo <");
            builder.AppendUrl("http://example.com");
            builder.AppendText("> bar");
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendMessage("foo <http://example.com> bar");
            var actualMsg = builder.ToMessage();

            Assert.AreEqual(expectedMsg, actualMsg);
        }
        public void ImplicitRemoveAt()
        {
            Buffer.MaxCapacity = 16;
            // generate 32 extra messsages to exceed the max capacity which
            // forces a RemoveAt() call of the oldest messages
            var bufferCount = Buffer.Count;
            var msgs = new List<MessageModel>(Buffer);
            for (int i = 1; i <= 32; i++) {
                var builder = new MessageBuilder();
                builder.AppendText("msg{0}", bufferCount + i);
                var msg = builder.ToMessage();
                msgs.Add(msg);
                Buffer.Add(msg);
            }

            Assert.AreEqual(Buffer.MaxCapacity, Buffer.Count);
            Assert.AreEqual(msgs[32 - (Buffer.MaxCapacity - bufferCount)].ToString(), Buffer[0].ToString());
        }
Beispiel #11
0
        public void AppendHtmlMessageCssFgRedBgBlue()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            var textPart = builder.CreateText("Test");
            textPart.ForegroundColor = new TextColor(255, 0, 0);
            textPart.BackgroundColor = new TextColor(0, 0, 255);
            builder.Append(textPart);
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendHtmlMessage(
                "<div style=\"" +
                    "color: #FF0000; " +
                    "background: #0000FF url('smiley.gif') no-repeat fixed center" +
                "\">Test</div>");
            var actualMsg = builder.ToMessage();
            Assert.AreEqual(expectedMsg, actualMsg);
        }
        public void ImplicitFlush()
        {
            // generate 32 extra messsages to exceed the buffer size which
            // forces a flush of the buffer to db4o
            var bufferCount = Buffer.Count;
            var msgs = new List<MessageModel>(Buffer);
            for (int i = 1; i <= 32; i++) {
                var builder = new MessageBuilder();
                builder.AppendText("msg{0}", bufferCount + i);
                var msg = builder.ToMessage();
                msgs.Add(msg);
                Buffer.Add(msg);
            }

            int j = 0;
            foreach (var msg in Buffer) {
                Assert.AreEqual(msgs[j++].ToString(), msg.ToString());
            }
            Assert.AreEqual(msgs.Count, j);
        }
Beispiel #13
0
 private void CommandUnknown(CommandModel cmd)
 {
     var msg = new MessageBuilder().
         AppendEventPrefix().
         AppendText(_("Unknown Command: {0}"), cmd.Command).
         ToMessage();
     cmd.FrontendManager.AddMessageToChat(cmd.Chat, msg);
 }
Beispiel #14
0
        void CommandHelp(CommandModel cmd)
        {
            var chatView = f_MainWindow.ChatViewManager.GetChat(cmd.Chat);
            var builder = new MessageBuilder();
            // TRANSLATOR: this line is used as a label / category for a
            // list of commands below
            builder.AppendHeader(_("Frontend Commands"));
            chatView.AddMessage(builder.ToMessage());

            string[] help = {
                "help",
                "window number",
                "exit",
            };

            foreach (string line in help) {
                builder = new MessageBuilder();
                builder.AppendEventPrefix();
                builder.AppendText(line);
                chatView.AddMessage(builder.ToMessage());
            }
        }
Beispiel #15
0
 private bool Command(CommandModel cmd)
 {
     bool handled = false;
     if (cmd.IsCommand) {
         switch (cmd.Command.ToLower()) {
             case "help":
                 CommandHelp(cmd);
                 break;
             case "window":
                 CommandWindow(cmd);
                 handled = true;
                 break;
             case "exit":
                 Frontend.Quit();
                 handled = true;
                 break;
             case "gc":
     #if LOG4NET
                 _Logger.Debug("GC.Collect()");
     #endif
                 var msg = new MessageBuilder().
                     AppendEventPrefix().
                     AppendText("GCing...").
                     ToMessage();
                 cmd.FrontendManager.AddMessageToChat(cmd.Chat, msg);
                 GC.Collect();
                 handled = true;
                 break;
         }
     }
     return handled;
 }
Beispiel #16
0
        public void CopyConstructor()
        {
            var builder = new MessageBuilder();
            builder.AppendEventPrefix();
            builder.AppendUrl("http://example.com");
            builder.AppendText("foobar");
            var msg = builder.ToMessage();
            var copiedMsg = new MessageModel(msg);

            Assert.AreNotSame(msg, copiedMsg);
            Assert.IsNotNull(copiedMsg.MessageParts);
            Assert.AreNotSame(msg.MessageParts, copiedMsg.MessageParts);
            Assert.AreEqual(msg, copiedMsg);
        }
Beispiel #17
0
        void FormatUpload(MessageBuilder bld, PersonModel person, ChatModel chat, Message message)
        {
            // Figure out what the user uploaded, we need to issue another call for this
            var upload = Client.Get<UploadWrapper>(String.Format("/room/{0}/messages/{1}/upload.json", chat.ID, message.Id)).Upload;

            bld.AppendEventPrefix();
            bld.AppendIdendityName(person).AppendSpace();
            bld.AppendText(_("has uploaded '{0}' ({1} B) {2}"), upload.Name, upload.Byte_Size, upload.Full_Url);
        }
Beispiel #18
0
 public virtual void RenderPersonIdentityName(Gtk.TreeViewColumn column,
                                              Gtk.CellRenderer cellr,
                                              Gtk.TreeModel model, Gtk.TreeIter iter)
 {
     PersonModel person = (PersonModel) model.GetValue(iter, 0);
     var renderer = (Gtk.CellRendererText) cellr;
     if (NickColors) {
         // TODO: do we need to optimize this? it's called very often...
         Gdk.Color bgColor = _PersonTreeView.Style.Base(Gtk.StateType.Normal);
         var builder = new MessageBuilder();
         builder.Settings.NickColors = true;
         builder.AppendNick(person);
         renderer.Markup = PangoTools.ToMarkup(builder.ToMessage(),
                                               bgColor);
     } else {
         renderer.Text = person.IdentityName;
     }
 }
Beispiel #19
0
        public virtual void Populate()
        {
            Trace.Call();

            Name = SyncedName;

            // sync messages
            // cleanup, be sure the output is empty
            _OutputMessageTextView.Clear();

            if (!Frontend.IsLocalEngine && Frontend.UseLowBandwidthMode) {
                var msg = new MessageBuilder();
                msg.AppendEventPrefix();
                msg.AppendMessage(_("Low Bandwidth Mode is active: no messages synced."));
                AddMessage(msg.ToMessage());
            } else {
                if (SyncedMessages != null) {
                    // TODO: push messages in batches and give back control to
                    // GTK+ in between for blocking the GUI thread less
                    foreach (MessageModel msg in SyncedMessages) {
                        AddMessage(msg);
                    }
                }
            }

            // as we don't track which messages were already seen it would
            // show all chats with message activity after the frontend connect
            if (!HasHighlight) {
                HasActivity = false;
                HasEvent = false;
            }

            // let the user know at which position new messages start
            _OutputMessageTextView.UpdateMarkerline();

            // reset tab icon to normal
            TabImage.Pixbuf = DefaultTabImage.Pixbuf;
            OnStatusChanged(EventArgs.Empty);

            SyncedMessages = null;
            _IsSynced = true;
        }
        public void SetUp()
        {
            Buffer = CreateBuffer();
            TestMessages = new List<MessageModel>();

            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("msg1");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg2");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendErrorText("msg3");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg4");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg5");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg6");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg7");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg8");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg9");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg10");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg11");
            TestMessages.Add(builder.ToMessage());

            foreach (var msg in TestMessages) {
                Buffer.Add(msg);
            }

            builder = new MessageBuilder();
            builder.AppendIdendityName(
                new ContactModel("meeebey", "meebey", "netid", "netprot")
            );
            builder.AppendSpace();
            builder.AppendText("solange eine message aber keine url hat ist der vorteil nur gering (wenn ueberhaupt)");
            SimpleMessage = builder.ToMessage();
        }
        public void IndexOf()
        {
            Assert.AreEqual(1, Buffer.IndexOf(TestMessages[1]));

            var builder = new MessageBuilder();
            builder.AppendText("non-existent");
            var msg = builder.ToMessage();
            Assert.AreEqual(-1, Buffer.IndexOf(msg));
        }
Beispiel #22
0
        public void InitMessageBuffer(MessageBufferPersistencyType persistency)
        {
            Trace.Call(persistency);

            if (MessageBuffer != null) {
                return;
            }

            switch (persistency) {
                case MessageBufferPersistencyType.Volatile:
                    MessageBuffer = new ListMessageBuffer();
                    break;
                case MessageBufferPersistencyType.Persistent:
                    try {
                        var start = DateTime.UtcNow;
                        MessageBuffer = new Db4oMessageBuffer(
                            ProtocolManager.Session.Username,
                            ProtocolManager.Protocol,
                            ProtocolManager.NetworkID,
                            ID
                        );
                        var stop = DateTime.UtcNow;
            #if LOG4NET
                        _Logger.DebugFormat(
                            "InitMessageBuffer(): initializing " +
                            "Db4oMessageBuffer({0}, {1}, {2}, {3}) " +
                            "took: {4:0.00} ms",
                            ProtocolManager.Session.Username,
                            ProtocolManager.Protocol,
                            ProtocolManager.NetworkID,
                            ID,
                            (stop - start).TotalMilliseconds
                        );
            #endif
                    } catch (Exception ex) {
            #if LOG4NET
                        _Logger.Error(
                            "InitMessageBuffer(): Db4oMessageBuffer() threw " +
                            "exception, falling back to memory backend!", ex
                        );
            #endif
                        MessageBuffer = new ListMessageBuffer();

                        var builder = new MessageBuilder();
                        builder.AppendEventPrefix();
                        builder.AppendErrorText(
                            _("Failed to open chat history for writing. " +
                              "Your chat history will not be preserved. " +
                              "Reason: {0}"),
                            ex.Message
                        );
                        MessageBuffer.Add(builder.ToMessage());
                    }
                    break;
            }
        }
Beispiel #23
0
        public void AddMessage(MessageModel msg, bool addLinebreak, bool showTimestamps)
        {
            #if MSG_DEBUG
            Trace.Call(msg, addLinebreak);
            #endif

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

            var buffer = Buffer;
            var iter = buffer.EndIter;
            var startMark = new Gtk.TextMark(null, true);
            buffer.AddMark(startMark, iter);

            var senderPrefixWidth = GetSenderPrefixWidth(msg);
            Gtk.TextTag indentTag = null;
            if (senderPrefixWidth != 0) {
                // TODO: re-use text tags that have the same indent width
                indentTag = new Gtk.TextTag(null) {
                    Indent = -senderPrefixWidth
                };
                _MessageTextTagTable.Add(indentTag);
            }

            if (showTimestamps) {
                var msgTimeStamp = msg.TimeStamp.ToLocalTime();
                if (_LastMessage != null) {
                    var lastMsgTimeStamp = _LastMessage.TimeStamp.ToLocalTime();
                    var span = msgTimeStamp.Date - lastMsgTimeStamp.Date;
                    if (span.Days > 0) {
                        var dayLine = new MessageBuilder().
                            AppendEventPrefix();
                        if (span.Days > 1) {
                            dayLine.AppendText(_("Day changed from {0} to {1}"),
                                               lastMsgTimeStamp.ToShortDateString(),
                                               msgTimeStamp.ToShortDateString());
                        } else {
                            dayLine.AppendText(_("Day changed to {0}"),
                                               msgTimeStamp.ToLongDateString());
                        }
                        dayLine.AppendText("\n");
                        var dayLineMsg = dayLine.ToMessage().ToString();
                        Buffer.InsertWithTags(ref iter, dayLineMsg, EventTag);
                    }
                }

                string timestamp = null;
                try {
                    string format = (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];
                    if (!String.IsNullOrEmpty(format)) {
                        timestamp = msgTimeStamp.ToString(format);
                    }
                } catch (FormatException e) {
                    timestamp = "Timestamp Format ERROR: " + e.Message;
                }

                if (timestamp != null) {
                    InsertTimeStamp(buffer, ref iter, timestamp, msg);

                    // apply timestamp width to indent tag
                    if (indentTag != null) {
                        indentTag.Indent -= GetPangoWidth(timestamp);
                    }
                }
            }

            var msgStartMark = new Gtk.TextMark(null, true);
            buffer.AddMark(msgStartMark, iter);

            bool hasHighlight = false;
            foreach (MessagePartModel msgPart in msg.MessageParts) {
                // supposed to be used only in a ChatView
                if (msgPart.IsHighlight) {
                    hasHighlight = true;
                }

                // TODO: implement all types
                if (msgPart is UrlMessagePartModel) {
                    InsertToBuffer(buffer, ref iter, (UrlMessagePartModel) msgPart);
                } else if (msgPart is TextMessagePartModel) {
                    InsertToBuffer(buffer, ref iter, (TextMessagePartModel) msgPart);
                } else if (msgPart is ImageMessagePartModel) {
                    InsertToBuffer(buffer, ref iter, (ImageMessagePartModel) msgPart);
                }
            }
            var startIter = buffer.GetIterAtMark(startMark);
            if (msg.MessageType == MessageType.Event) {
                buffer.ApplyTag(EventTag, startIter, iter);
            }
            if (indentTag != null) {
                buffer.ApplyTag(indentTag, startIter, iter);
            }
            var nick = msg.GetNick();
            if (nick != null) {
                // TODO: re-use the same person tag for the same nick
                var personTag = new PersonTag(nick, nick);
                personTag.TextEvent += OnPersonTagTextEvent;
                _MessageTextTagTable.Add(personTag);

                var msgStartIter = buffer.GetIterAtMark(msgStartMark);
                var nickEndIter = msgStartIter;
                nickEndIter.ForwardChars(nick.Length + 2);
                buffer.ApplyTag(PersonTag, msgStartIter, nickEndIter);
                buffer.ApplyTag(personTag, msgStartIter, nickEndIter);
            }
            buffer.DeleteMark(startMark);
            buffer.DeleteMark(msgStartMark);
            if (addLinebreak) {
                buffer.Insert(ref iter, "\n");
            }

            CheckBufferSize();

            if (IsGtk2_17) {
                // HACK: force a redraw of the widget, as for some reason
                // GTK+ 2.17.6 is not redrawing some lines we add here, especially
                // for local messages. See:
                // http://projects.qnetp.net/issues/show/185
                QueueDraw();
            }
            if (Frontend.IsWindows && _LastMessage == null) {
                // HACK: workaround rendering issue on Windows where the
                // first inserted text is not showing up until the next insert
                QueueDraw();
            }

            if (MessageAdded != null) {
                MessageAdded(this, new MessageTextViewMessageAddedEventArgs(msg));
            }

            if (hasHighlight) {
                if (MessageHighlighted != null) {
                    MessageHighlighted(this, new MessageTextViewMessageHighlightedEventArgs(msg));
                }
            }

            _LastMessage = msg;
        }
Beispiel #24
0
 bool TypingDotsCallback()
 {
     if (IsDisposed) {
         return false;
     }
     if (IsComposing) {
         NumberOfTypingDots++;
         if (NumberOfTypingDots == 4) {
             NumberOfTypingDots = 0;
         }
     } else {
         NumberOfTypingDots--;
         if (NumberOfTypingDots <= 0) {
             // done
             TypingDots = null;
             UpdateChatState();
             ChatStateTimeoutRunning = false;
             return false;
         }
     }
     var builder = new MessageBuilder();
     builder.AppendText(new string('.', NumberOfTypingDots));
     TypingDots = builder.ToMessage();
     UpdateChatState();
     GLib.Timeout.Add(300, TypingDotsCallback);
     return false;
 }
Beispiel #25
0
        public void AppendFormatNegativePlaceholder()
        {
            var builder = new MessageBuilder();

            builder.AppendFormat("Hello, {-1}!", "world");
        }
Beispiel #26
0
        public void SetUp()
        {
            Buffer       = CreateBuffer();
            TestMessages = new List <MessageModel>();

            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("msg1");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg2");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendErrorText("msg3");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg4");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg5");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg6");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg7");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg8");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg9");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg10");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg11");
            TestMessages.Add(builder.ToMessage());

            foreach (var msg in TestMessages)
            {
                Buffer.Add(msg);
            }

            builder = new MessageBuilder();
            builder.AppendIdendityName(
                new ContactModel("meeebey", "meebey", "netid", "netprot")
                );
            builder.AppendSpace();
            builder.AppendText("solange eine message aber keine url hat ist der vorteil nur gering (wenn ueberhaupt)");
            SimpleMessage = builder.ToMessage();
        }
Beispiel #27
0
        public void AppendFormatPlaceholderOverflow()
        {
            var builder = new MessageBuilder();

            builder.AppendFormat("Hello, {1}!", "world");
        }
Beispiel #28
0
 void FormatEvent(MessageBuilder bld, PersonModel person, string action)
 {
     bld.AppendEventPrefix();
     bld.AppendIdendityName(person).AppendSpace();
     bld.AppendText(action);
 }
Beispiel #29
0
        void CommandGenerateMessages(CommandModel cmd)
        {
            var chat = ChatViewManager.CurrentChatView;
            _CommandManager.CommandGenerateMessages(cmd, chat);

            var builder = new MessageBuilder();
            builder.AppendText(
                "ChatView.AddMessage(): MessageTextTagTable.Size: {0}",
                chat.OutputMessageTextView.MessageTextTagTable.Size
            );
            chat.AddMessage(builder.ToMessage());
        }
Beispiel #30
0
        public void AddMessage(MessageModel msg, bool addLinebreak, bool showTimestamps)
        {
            #if MSG_DEBUG
            Trace.Call(msg, addLinebreak);
            #endif

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

            var buffer = Buffer;
            var iter = buffer.EndIter;
            var startMark = new Gtk.TextMark(null, true);
            buffer.AddMark(startMark, iter);

            var senderPrefixWidth = GetSenderPrefixWidth(msg);
            Gtk.TextTag indentTag = null;
            if (senderPrefixWidth != 0) {
                // TODO: re-use text tags that have the same indent width
                indentTag = new Gtk.TextTag(null) {
                    Indent = -senderPrefixWidth
                };
                _MessageTextTagTable.Add(indentTag);
            }

            if (showTimestamps) {
                var msgTimeStamp = msg.TimeStamp.ToLocalTime();
                if (_LastMessage != null) {
                    var lastMsgTimeStamp = _LastMessage.TimeStamp.ToLocalTime();
                    var span = msgTimeStamp.Date - lastMsgTimeStamp.Date;
                    if (span.Days > 0) {
                        var dayLine = new MessageBuilder().
                            AppendEventPrefix();
                        if (span.Days > 1) {
                            dayLine.AppendText(_("Day changed from {0} to {1}"),
                                               lastMsgTimeStamp.ToShortDateString(),
                                               msgTimeStamp.ToShortDateString());
                        } else {
                            dayLine.AppendText(_("Day changed to {0}"),
                                               msgTimeStamp.ToLongDateString());
                        }
                        dayLine.AppendText("\n");
                        var dayLineMsg = dayLine.ToMessage().ToString();
                        Buffer.InsertWithTags(ref iter, dayLineMsg, EventTag);
                    }
                }

                string timestamp = null;
                try {
                    string format = (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];
                    if (!String.IsNullOrEmpty(format)) {
                        timestamp = msgTimeStamp.ToString(format);
                    }
                } catch (FormatException e) {
                    timestamp = "Timestamp Format ERROR: " + e.Message;
                }

                if (timestamp != null) {
                    timestamp = String.Format("{0} ", timestamp);
                    buffer.Insert(ref iter, timestamp);

                    // apply timestamp width to indent tag
                    if (indentTag != null) {
                        indentTag.Indent -= GetPangoWidth(timestamp);
                    }
                }
            }

            var msgStartMark = new Gtk.TextMark(null, true);
            buffer.AddMark(msgStartMark, iter);

            bool hasHighlight = false;
            foreach (MessagePartModel msgPart in msg.MessageParts) {
                // supposed to be used only in a ChatView
                if (msgPart.IsHighlight) {
                    hasHighlight = true;
                }

                // TODO: implement all types
                if (msgPart is UrlMessagePartModel) {
                    var urlPart = (UrlMessagePartModel) msgPart;
                    var linkText = urlPart.Text ?? urlPart.Url;

                    var url = urlPart.Url;
                    Uri uri;
                    try {
                        uri = new Uri(url);
                    } catch (UriFormatException ex) {
            #if LOG4NET
                        _Logger.Error("AddMessage(): Invalid URL: " + url, ex);
            #endif
                        buffer.Insert(ref iter, linkText);
                        continue;
                    }

                    var tags = new List<Gtk.TextTag>();
                    // link URI tag
                    var linkTag = new LinkTag(uri);
                    linkTag.TextEvent += OnLinkTagTextEvent;
                    _MessageTextTagTable.Add(linkTag);
                    tags.Add(linkTag);

                    // link style tag
                    tags.Add(LinkTag);

                    buffer.InsertWithTags(ref iter, linkText, tags.ToArray());
                } else if (msgPart is TextMessagePartModel) {
                    var tags = new List<Gtk.TextTag>();
                    TextMessagePartModel fmsgti = (TextMessagePartModel) msgPart;
                    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);
                    }
                }
            }
            var startIter = buffer.GetIterAtMark(startMark);
            if (msg.MessageType == MessageType.Event) {
                buffer.ApplyTag(EventTag, startIter, iter);
            }
            if (indentTag != null) {
                buffer.ApplyTag(indentTag, startIter, iter);
            }
            var nick = msg.GetNick();
            if (nick != null) {
                // TODO: re-use the same person tag for the same nick
                var personTag = new PersonTag(nick, nick);
                personTag.TextEvent += OnPersonTagTextEvent;
                _MessageTextTagTable.Add(personTag);

                var msgStartIter = buffer.GetIterAtMark(msgStartMark);
                var nickEndIter = msgStartIter;
                nickEndIter.ForwardChars(nick.Length + 2);
                buffer.ApplyTag(PersonTag, msgStartIter, nickEndIter);
                buffer.ApplyTag(personTag, msgStartIter, nickEndIter);
            }
            buffer.DeleteMark(startMark);
            buffer.DeleteMark(msgStartMark);
            if (addLinebreak) {
                buffer.Insert(ref iter, "\n");
            }

            CheckBufferSize();

            if (IsGtk2_17) {
                // HACK: force a redraw of the widget, as for some reason
                // GTK+ 2.17.6 is not redrawing some lines we add here, especially
                // for local messages. See:
                // http://projects.qnetp.net/issues/show/185
                QueueDraw();
            }
            if (Frontend.IsWindows && _LastMessage == null) {
                // HACK: workaround rendering issue on Windows where the
                // first inserted text is not showing up until the next insert
                QueueDraw();
            }

            if (MessageAdded != null) {
                MessageAdded(this, new MessageTextViewMessageAddedEventArgs(msg));
            }

            if (hasHighlight) {
                if (MessageHighlighted != null) {
                    MessageHighlighted(this, new MessageTextViewMessageHighlightedEventArgs(msg));
                }
            }

            _LastMessage = msg;
        }
 void FormatEvent(MessageBuilder bld, PersonModel person, string action)
 {
     bld.AppendEventPrefix();
     bld.AppendIdendityName(person).AppendSpace();
     bld.AppendText(action);
 }
Beispiel #32
0
        public virtual void Populate()
        {
            Trace.Call();

            Name = SyncedName;

            // sync messages
            // cleanup, be sure the output is empty
            _OutputMessageTextView.Clear();

            if (!Frontend.IsLocalEngine && Frontend.UseLowBandwidthMode) {
                var msg = new MessageBuilder();
                msg.AppendEventPrefix();
                msg.AppendMessage(_("Low Bandwidth Mode is active: no messages synced."));
                AddMessage(msg.ToMessage());
            } else {
                if (SyncedMessages != null) {
                    // TODO: push messages in batches and give back control to
                    // GTK+ in between for blocking the GUI thread less
                    foreach (MessageModel msg in SyncedMessages) {
                        AddMessage(msg);
                        if (msg.TimeStamp <= SyncedLastSeenMessage) {
                            // let the user know at which position new messages start
                            _OutputMessageTextView.UpdateMarkerline();
                        }
                    }
                }
            }

            // as we don't track which events have already been seen it would
            // show all chats with unseen events after the frontend connect
            if (!HasHighlight) {
                HasEvent = false;
                // Smuxi protocol < 0.13 does not support remembering seen
                // messages thus we mark all message as seen as we can't tell
                // which ones are new
                if (Frontend.EngineProtocolVersion < new Version(0, 13)) {
                    HasActivity = false;
                }
            }

            // reset tab icon to normal
            TabImage.Pixbuf = DefaultTabImage.Pixbuf;
            OnStatusChanged(EventArgs.Empty);

            SyncedMessages = null;
            IsSynced = true;
        }
Beispiel #33
0
        public void AppendFormatNonIntegerPlaceholder()
        {
            var builder = new MessageBuilder();

            builder.AppendFormat("Hello, {zeroth}!", "world");
        }
Beispiel #34
0
        private void _CommandHelp(CommandModel cd)
        {
            var chatView = ChatViewManager.GetChat(cd.Chat);
            var builder = new MessageBuilder();
            // TRANSLATOR: this line is used as a label / category for a
            // list of commands below
            builder.AppendHeader(_("Frontend Commands"));
            chatView.AddMessage(builder.ToMessage());

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

            foreach (string line in help) {
                builder = new MessageBuilder();
                builder.AppendEventPrefix();
                builder.AppendText(line);
                chatView.AddMessage(builder.ToMessage());
            }
        }
Beispiel #35
0
        public void AppendMessageWithOddUrls()
        {
            var msg     = @"zack: http://anonscm.debian.org/gitweb/?p=lintian/lintian.git;a=blob;f=checks/source-copyright.desc;h=3276a57e81b1c8c38073e667221e262df1a606c0;hb=167170d7911473a726f7e77008d8b2246a6822e8";
            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("zack: "));
            builder.Append(new UrlMessagePartModel("http://anonscm.debian.org/gitweb/?p=lintian/lintian.git;a=blob;f=checks/source-copyright.desc;h=3276a57e81b1c8c38073e667221e262df1a606c0;hb=167170d7911473a726f7e77008d8b2246a6822e8"));
            TestMessage(msg, builder.ToMessage());

            msg               = "http://sources.debian.net/src/kfreebsd-10/10.0~svn259778-1/sys/cddl/dev/dtrace/dtrace_anon.c";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://sources.debian.net/src/kfreebsd-10/10.0~svn259778-1/sys/cddl/dev/dtrace/dtrace_anon.c"));
            TestMessage(msg, builder.ToMessage());

            msg               = "http://www.stack.nl/~jilles/cgi-bin/hgwebdir.cgi/charybdis/raw-rev/9d769851c1c7";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://www.stack.nl/~jilles/cgi-bin/hgwebdir.cgi/charybdis/raw-rev/9d769851c1c7"));
            TestMessage(msg, builder.ToMessage());

            msg               = "<RAOF> meebey: Associated mono branch is master-experimental in git+ssh://git.debian.org/~/public_git/mono.git";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("<RAOF> meebey: Associated mono branch is master-experimental in "));
            builder.Append(new UrlMessagePartModel("git+ssh://git.debian.org/~/public_git/mono.git"));
            TestMessage(msg, builder.ToMessage());

            msg               = "<knocte> meebey: does this URL highlight ok with latest master?  https://groups.google.com/forum/#!topic/fsharp-opensource/KLejo_vw5R4";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("<knocte> meebey: does this URL highlight ok with latest master?  "));
            builder.Append(new UrlMessagePartModel("https://groups.google.com/forum/#!topic/fsharp-opensource/KLejo_vw5R4"));
            TestMessage(msg, builder.ToMessage());

            msg               = "<astronouth7303> found another bad URL: http://www.flickr.com/photos/34962649@N00/12000715226/in/photostream/";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("<astronouth7303> found another bad URL: "));
            builder.Append(new UrlMessagePartModel("http://www.flickr.com/photos/34962649@N00/12000715226/in/photostream/"));
            TestMessage(msg, builder.ToMessage());

            msg               = "http://en.wikipedia.org/Talk:Main_Page";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://en.wikipedia.org/Talk:Main_Page"));
            TestMessage(msg, builder.ToMessage());

            msg               = "http://en.wikipedia.org/wiki/Godunov's_scheme";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://en.wikipedia.org/wiki/Godunov's_scheme"));
            TestMessage(msg, builder.ToMessage());

            msg               = "<astronouth7303> ok, this is just trippy URL matching: http://couchdb.local/mydb/_magic";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("<astronouth7303> ok, this is just trippy URL matching: "));
            builder.Append(new UrlMessagePartModel("http://couchdb.local/mydb/_magic"));
            TestMessage(msg, builder.ToMessage());

            msg               = "https://web.archive.org/web/20050208144213/http://www.jaganelli.de/";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("https://web.archive.org/web/20050208144213/http://www.jaganelli.de/"));
            TestMessage(msg, builder.ToMessage());

            msg               = "irc://freenode/smuxi";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel(msg));
            TestMessage(msg, builder.ToMessage());

            msg               = "http://www.test.de/bilder.html?data[meta_id]=13895&data[bild_id]=7";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://www.test.de/bilder.html?data[meta_id]=13895&data[bild_id]=7"));
            TestMessage(msg, builder.ToMessage());

            msg               = "https://eu.api.soyoustart.com/console/#/order/dedicated/server/{serviceName}#GET";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel(msg));
            TestMessage(msg, builder.ToMessage());
        }
Beispiel #36
0
        private void InitDatabase()
        {
            ConfigureDatabase();
            try {
                OpenDatabase();
            } catch (Exception ex) {
            #if LOG4NET
                Logger.Error("InitDatabase(): failed to open message " +
                             "database: " + DatabaseFile, ex);
            #endif
                FixDatabase(ex);
                // WORXNOWPLX
                OpenDatabase();

                var builder = new MessageBuilder();
                builder.AppendEventPrefix();
                builder.AppendErrorText(
                    _("Your chat history is no longer available because of " +
                      "an error but will be preserved from now on.")
                );
                Add(builder.ToMessage());
            }
        }
Beispiel #37
0
        public void AppendFormatMissingOpeningBrace()
        {
            var builder = new MessageBuilder();

            builder.AppendFormat("Hello, 0}!", "world");
        }