Example #1
0
 public void InsertImage(string fileName)
 {
     var magic = new Magic(true);
     string mimeType = magic.Lookup(fileName);
     if (mimeType.StartsWith("image/")) {
         var cursor = base.TextCursor();
         cursor.InsertHtml(String.Format("<img src=\"{0}\" />", fileName));
     }
 }
Example #2
0
        public static string Mime(string filename)
        {
            string mime;
            Magic m = new Magic(true);

            mime = Marshal.PtrToStringAuto(magic_file(m._magic, filename));
            if (mime == null) {
                throw new MagicException(m.Error);
            }

            return mime;
        }
Example #3
0
        public static string Descrition(string filename)
        {
            string desc;
            Magic m = new Magic(false);

            magic_setflags(m._magic, DefaultFlags);
            desc = Marshal.PtrToStringAuto(magic_file(m._magic, filename));

            if (desc == null) {
                throw new MagicException(m.Error);
            }

            return desc;
        }
Example #4
0
        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);
            }
        }