Beispiel #1
0
        public void ShowMedia(GDMMultimediaRecord mediaRec, bool modal)
        {
            if (mediaRec == null)
            {
                throw new ArgumentNullException("mediaRec");
            }

            GDMFileReferenceWithTitle fileRef = mediaRec.FileReferences[0];
            MultimediaKind            mmKind  = GKUtils.GetMultimediaKind(fileRef.MultimediaFormat);

            if (mmKind == MultimediaKind.mkNone)
            {
                return;
            }

            bool externalViewer = !GlobalOptions.Instance.EmbeddedMediaPlayer &&
                                  ((mmKind == MultimediaKind.mkAudio || mmKind == MultimediaKind.mkVideo));

            if (externalViewer)
            {
                string targetFile = fContext.MediaLoad(fileRef);
                GKUtils.LoadExtFile(targetFile);
            }
            else
            {
                //var mediaViewer = AppHost.Container.Resolve<IMediaViewerWin>(this);
                MediaViewerWin mediaViewer = new MediaViewerWin(this);
                try {
                    try {
                        mediaViewer.FileRef = fileRef;
                        if (modal)
                        {
                            mediaViewer.Show();
                        }
                        else
                        {
                            mediaViewer.ShowInTaskbar = true;
                            mediaViewer.Show();
                        }
                    } finally {
                        if (modal)
                        {
                            mediaViewer.Dispose();
                        }
                    }
                } catch (Exception ex) {
                    if (mediaViewer != null)
                    {
                        mediaViewer.Dispose();
                    }
                    Logger.LogWrite("BaseWinSDI.ShowMedia(): " + ex.Message);
                }
            }
        }
Beispiel #2
0
        private void LoadList()
        {
            GEDCOMRecord record;
            var          enumerator = fBase.Context.Tree.GetEnumerator(GEDCOMRecordType.rtMultimedia);

            while (enumerator.MoveNext(out record))
            {
                GEDCOMMultimediaRecord       mediaRec = (GEDCOMMultimediaRecord)record;
                GEDCOMFileReferenceWithTitle fileRef  = mediaRec.FileReferences[0];

                MultimediaKind mmKind = GKUtils.GetMultimediaKind(fileRef.MultimediaFormat);
                if (mmKind == MultimediaKind.mkImage)
                {
                    fFileRefs.Add(fileRef);
                }
            }
        }
Beispiel #3
0
        public override void UpdateView()
        {
            fView.Title = fFileRef.Title;

            MultimediaKind mmKind = GKUtils.GetMultimediaKind(fFileRef.MultimediaFormat);

            try {
                switch (mmKind)
                {
                case MultimediaKind.mkImage:
                {
                    IImage img = fBase.Context.LoadMediaImage(fFileRef, false);
                    if (img != null)
                    {
                        fView.SetViewImage(img, fFileRef);
                    }
                    break;
                }

                case MultimediaKind.mkAudio:
                case MultimediaKind.mkVideo:
                {
                    string targetFile = fBase.Context.MediaLoad(fFileRef);
                    fView.SetViewMedia(targetFile);
                    break;
                }

                case MultimediaKind.mkText:
                {
                    Stream fs            = fBase.Context.MediaLoad(fFileRef, false);
                    bool   disposeStream = (fs != null);

                    switch (fFileRef.MultimediaFormat)
                    {
                    case GDMMultimediaFormat.mfTXT:
                        using (StreamReader strd = new StreamReader(fs)) {
                            string text = strd.ReadToEnd();
                            fView.SetViewText(text);
                        }
                        break;

                    case GDMMultimediaFormat.mfRTF:
                        using (StreamReader strd = new StreamReader(fs)) {
                            string text = strd.ReadToEnd();
                            fView.SetViewRTF(text);
                        }
                        break;

                    case GDMMultimediaFormat.mfHTM:
                        disposeStream = false;
                        fView.SetViewHTML(fs);
                        break;
                    }
                    if (disposeStream)
                    {
                        fs.Dispose();
                    }
                    break;
                }
                }
            } catch (Exception ex) {
                fView.DisposeViewControl();
                Logger.WriteError("MediaViewerController.UpdateView()", ex);
            }
        }
Beispiel #4
0
        private void SetFileRef(GEDCOMFileReferenceWithTitle value)
        {
            fFileRef = value;
            Title    = fFileRef.Title;
            Control ctl = null;

            MultimediaKind mmKind = GKUtils.GetMultimediaKind(fFileRef.MultimediaFormat);

            try {
                switch (mmKind)
                {
                case MultimediaKind.mkImage:
                {
                    IImage img = fBase.Context.LoadMediaImage(fFileRef, false);
                    if (img != null)
                    {
                        SetViewImage(((ImageHandler)img).Handle, fFileRef);
                    }
                    break;
                }

                case MultimediaKind.mkAudio:
                case MultimediaKind.mkVideo:
                {
                    string targetFile = fBase.Context.MediaLoad(fFileRef);
                    SetViewMedia(targetFile);
                    break;
                }

                case MultimediaKind.mkText:
                {
                    Stream fs = fBase.Context.MediaLoad(fFileRef, false);

                    switch (fFileRef.MultimediaFormat)
                    {
                    case GEDCOMMultimediaFormat.mfTXT:
                    {
                        TextArea txtBox = new TextArea();
                        txtBox.ReadOnly = true;

                        try {
                            // FIXME: fix encoding! and test other!!!
                            using (StreamReader strd = new StreamReader(fs, Encoding.GetEncoding(1251))) {
                                txtBox.Text = strd.ReadToEnd();
                            }
                        } catch (Exception ex) {
                            Logger.LogWrite("MediaViewerWin.SetFileRef.1(): " + ex.Message);
                        }

                        ctl = txtBox;
                        SetViewControl(ctl);
                    }
                    break;

                    case GEDCOMMultimediaFormat.mfRTF:
                    {
                        RichTextArea rtfBox = new RichTextArea();
                        rtfBox.ReadOnly = true;

                        try {
                            using (StreamReader strd = new StreamReader(fs)) {
                                rtfBox.Text = strd.ReadToEnd();
                            }
                        } catch (Exception ex) {
                            Logger.LogWrite("MediaViewerWin.SetFileRef.2(): " + ex.Message);
                        }

                        ctl = rtfBox;
                        SetViewControl(ctl);
                    }
                    break;

                    case GEDCOMMultimediaFormat.mfHTM:
                    {
                        var browser = new WebView();

                        try {
                            browser.LoadHtml(fs);

                            /*using (StreamReader strd = new StreamReader(fs)) {
                             *  browser.DocumentText = strd.ReadToEnd();
                             *  // didn't work, because didn't defines codepage from page's header (?!)
                             * }*/
                        } catch (Exception ex) {
                            Logger.LogWrite("MediaViewerWin.SetFileRef.3(): " + ex.Message);
                        }

                        ctl = browser;
                        SetViewControl(ctl);
                    }
                    break;
                    }
                    if (fs != null && !(ctl is WebView))
                    {
                        fs.Dispose();
                    }

                    break;
                }
                }
            } catch (Exception ex) {
                if (ctl != null)
                {
                    ctl.Dispose();
                }

                Logger.LogWrite("MediaViewerWin.SetFileRef(): " + ex.Message);
            }
        }
Beispiel #5
0
        public static bool IsPictureFormat(this GDMFileReferenceWithTitle fileRef)
        {
            MultimediaKind mmKind = GKUtils.GetMultimediaKind(fileRef.MultimediaFormat);

            return(mmKind == MultimediaKind.mkImage);
        }