protected override void InsertFromMimeData(Qyoto.QMimeData source) { var cursor = base.TextCursor(); if (source.HasImage()) { var image = QPixmap.FromImage((QImage)source.ImageData()); var document = base.Document(); var imageName = Guid.NewGuid().ToString(); document.AddResource((int)QTextDocument.ResourceType.ImageResource, new QUrl(imageName), image); cursor.InsertImage(imageName); } else if (source.HasUrls()) { var magic = new Magic(true); foreach (var url in source.Urls()) { if (url.Scheme() == "file") { string fileName = url.Path(); if (File.Exists(fileName)) { string mimeType = magic.Lookup(url.Path()); if (mimeType.StartsWith("image/")) { // FIXME: If image is over a certain size, send as file transfer rather // than encoded inline. cursor.InsertHtml(String.Format("<img src=\"{0}\" />", fileName)); } else { // FIXME: Generate and insert an image representing a file. Console.WriteLine("File Transfer: " + fileName); } } else { // FIXME: Support "sending" directories? cursor.InsertText(url.ToString()); } } else if (url.Scheme() == "http" || url.Scheme() == "https") { cursor.InsertHtml(String.Format("<a href=\"{0}\">{0}</a>", url.ToString())); } else { cursor.InsertText(url.ToString()); } } } else { base.InsertFromMimeData(source); } }
protected override bool CanInsertFromMimeData(Qyoto.QMimeData source) { if (source.HasImage()) { return(true); } else { return(base.CanInsertFromMimeData(source)); } }