void pdf_renderer_control_TextSelected(string selected_text)
 {
     if (null != selected_text)
     {
         ObjWebBrowser.DoWebSearch(selected_text);
     }
 }
Ejemplo n.º 2
0
        protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("WebBrowserControl::Dispose({0}) @{1}", disposing, dispose_count);

            WPFDoEvents.SafeExec(() =>
            {
                // Prevent recursive run-away of the code via the chain:
                //
                // ***  Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserControl.Dispose(bool disposing)
                // **   Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserControl.Dispose()
                //      Utilities.dll!Utilities.GUI.DualTabbedLayoutStuff.DualTabbedLayout.WantsClose(Utilities.GUI.DualTabbedLayoutStuff.DualTabbedLayoutItem item)
                //      Utilities.dll!Utilities.GUI.DualTabbedLayoutStuff.DualTabbedLayout.CloseContent(System.Windows.FrameworkElement fe)
                //      Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.DeleteSearchers()
                //      Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.Dispose(bool disposing)
                //      Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.Dispose()
                // ***  Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserControl.Dispose(bool disposing)
                // **   Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserControl.Dispose()
                //
                // and prevent partial/broken cleanup due to chains like this one, resulting in
                // a dispose_count == 2:
                //
                // =2 * Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.Dispose(bool disposing)
                //      Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.Dispose()
                // =2 * Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserControl.Dispose(bool disposing)
                //      Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserControl.Dispose()
                // =1   Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.Dispose(bool disposing)
                //      Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.Dispose()
                // =1   Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserControl.Dispose(bool disposing)
                //      Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserControl.Dispose()
                //      Utilities.dll!Utilities.GUI.DualTabbedLayoutStuff.DualTabbedLayout.WantsClose(Utilities.GUI.DualTabbedLayoutStuff.DualTabbedLayoutItem item)
                //      Utilities.dll!Utilities.GUI.DualTabbedLayoutStuff.DualTabbedLayout.CloseContent(System.Windows.FrameworkElement fe)
                // *    Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.DeleteSearchers()
                //      Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.RebuildSearchers(System.Collections.Generic.HashSet<string> once_off_requested_web_searchers)
                //      Qiqqa.exe!Qiqqa.WebBrowsing.WebBrowserHostControl.ForceSnifferSearchers()
                //
                if (dispose_count == 0)
                {
                    // Get rid of managed resources
                    ObjWebBrowser?.Dispose();
                    ObjWebBrowser = null;

                    // Multiple WebBrowserControl instances MAY SHARE a single WebBrowserHostControl.
                    // It is passed to this class/instance as a reference anyway, so we SHOULD NOT
                    // kill/dispose it in here!
                    //
                    //web_browser_host_control.Dispose();
                    web_browser_host_control = null;
                }
            });

            WPFDoEvents.SafeExec(() =>
            {
                ObjWebBrowser            = null;
                web_browser_host_control = null;
            });

            ++dispose_count;
        }
Ejemplo n.º 3
0
 internal void Refresh()
 {
     try
     {
         ObjWebBrowser.Reload();
     }
     catch (Exception ex)
     {
         Logging.Warn(ex, "Problem refreshing web page");
     }
 }
Ejemplo n.º 4
0
        internal void Navigate(Uri uri)
        {
            try
            {
                // Clear out any pending uri
                this.navigate_once_visible_uri = null;

                ObjWebBrowser.Navigate(uri.ToString());
            }
            catch (Exception ex)
            {
                Logging.Warn(ex, "Problem navigating to website {0}", uri.ToString());
                MessageBoxes.Error("There was a problem navigating to {0}.  Please try again after checking the web address.", uri.ToString());
            }
        }
Ejemplo n.º 5
0
        public WebBrowserControl(WebBrowserHostControl web_browser_host_control)
        {
            this.web_browser_host_control = web_browser_host_control;

            InitializeComponent();

            ObjWebBrowser.CreateControl();
            ObjWebBrowser.Navigating        += ObjWebBrowser_Navigating;
            ObjWebBrowser.DocumentCompleted += ObjWebBrowser_DocumentCompleted;
            ObjWebBrowser.CreateWindow      += ObjWebBrowser_CreateWindow;

            // Seems to crash Qiqqa in Gecko v13 - perhaps the statuses are updating too quickly or in parallel?!
            // Seems to work with gecko v21...
            ObjWebBrowser.StatusTextChanged += ObjWebBrowser_StatusTextChanged;
        }
Ejemplo n.º 6
0
        internal void Navigate(Uri uri)
        {
            try
            {
                // Clear out any pending uri
                NavigateOnceVisibleUri = uri;

                ObjWebBrowser.Navigate(uri?.ToString() ?? "");
            }
            catch (Exception ex)
            {
                string uristr = uri?.ToString() ?? "(???)";
                Logging.Warn(ex, "Problem navigating to website {0}", uristr);
                MessageBoxes.Error("There was a problem navigating to {0}.  Please try again after checking the web address.", uristr);
            }
        }
        void HyperlinkBibTeXLinksMissing_Click(object sender, RoutedEventArgs e)
        {
            string message =
                ""
                + "If you are not seeing an \"Import into BibTeX\" link below each search result, it means that you have not yet enabled BibTeX support in Google Scholar.\n\n"
                + "If you want Qiqqa to attempt to take you to the Google Scholar settings screen, press YES and then press 'Save Preferences' when you have reviewed all the available preferences.\n\n"
                + "If you would prefer to do it yourself, press NO.  Go to the main Google Scholar page (http://scholar.google.com) USING THE QIQQA BUILT-IN BROWSER, and open the Google Scholar Settings.  Make sure you are on the .com version of Scholar, by looking at the web address.  If the address does not end in \".com\", then look for a link in the bottom right called \"Go to Google Scholar\" which should take you there.   Once on the .com Scholar settings page, in the 'Bibliography Manager' section, select 'Show links to import citations into BibTeX' and then press 'Save'.";

            if (MessageBoxes.AskQuestion(message))
            {
                string preferences_url = "http://scholar.google.com/scholar_setprefs?scis=yes&scisf=4";
                ObjWebBrowser.OpenUrl(preferences_url);
            }

            e.Handled = true;
        }
Ejemplo n.º 8
0
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    // Get rid of managed resources
                    ObjWebBrowser.Dispose();
                    ObjWebBrowser = null;
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error disposing Gecko");
                }
            }

            // Get rid of unmanaged resources
        }
Ejemplo n.º 9
0
 internal void Print()
 {
     ObjWebBrowser.Navigate("javascript:print()");
 }
Ejemplo n.º 10
0
 internal void GoBack()
 {
     ObjWebBrowser.GoBack();
 }
Ejemplo n.º 11
0
 internal void GoForward()
 {
     ObjWebBrowser.GoForward();
 }
        public GoogleBibTexSnifferControl()
        {
            InitializeComponent();

            // Search options
            search_options                           = new SearchOptions();
            search_options_bindable                  = new AugmentedBindable <SearchOptions>(search_options);
            ObjSearchOptionsPanel.DataContext        = search_options_bindable;
            search_options_bindable.PropertyChanged += search_options_bindable_PropertyChanged;

            // Fades of buttons
            Utilities.GUI.Animation.Animations.EnableHoverFade(PDFRendererControlAreaButtonPanel);
            Utilities.GUI.Animation.Animations.EnableHoverFade(ObjBibTeXEditButtonPanel);

            this.Title = "Qiqqa BibTeX Sniffer";

            this.Closing += GoogleBibTexSnifferControl_Closing;
            this.Closed  += GoogleBibTexSnifferControl_Closed;

            this.KeyUp += GoogleBibTexSnifferControl_KeyUp;

            ButtonPrev.Icon    = Icons.GetAppIcon(Icons.Back);
            ButtonPrev.ToolTip = "Move to previous PDF.";
            ButtonPrev.Click  += ButtonPrev_Click;

            ButtonNext.Icon    = Icons.GetAppIcon(Icons.Forward);
            ButtonNext.ToolTip = "Move to next PDF.  You can press the middle key (the 5 key) as a shortcut.";
            ButtonNext.Click  += ButtonNext_Click;

            ButtonClear.Icon    = Icons.GetAppIcon(Icons.GoogleBibTexSkipForever);
            ButtonClear.ToolTip = "Clear this BibTeX.";
            ButtonClear.Click  += ButtonClear_Click;

            ButtonSkipForever.Icon    = Icons.GetAppIcon(Icons.GoogleBibTexSkip);
            ButtonSkipForever.ToolTip = "This document has no BibTeX.  Skip it!";
            ButtonSkipForever.Click  += ButtonSkipForever_Click;

            ButtonValidate.Icon    = Icons.GetAppIcon(Icons.GoogleBibTexNext);
            ButtonValidate.ToolTip = "The automatic BibTeX for this document is great.  Mark it as valid!";
            ButtonValidate.Click  += ButtonValidate_Click;

            ButtonConfig.Icon    = Icons.GetAppIcon(Icons.DocumentMisc);
            ButtonConfig.ToolTip = LocalisationManager.Get("PDF/TIP/MORE_MENUS");
            ButtonConfig.Click  += ButtonConfig_Click;

            ButtonRedo.Icon    = Icons.GetAppIcon(Icons.DesktopRefresh);
            ButtonRedo.ToolTip = "Retry detection of this PDF.";
            ButtonRedo.Click  += ButtonRedo_Click;

            ButtonWizard.Icon        = Icons.GetAppIcon(Icons.BibTeXSnifferWizard);
            ButtonWizard.ToolTip     = "Toggle the BibTeX Sniffer Wizard.\nWhen this is enabled, the sniffer will automatically browse to the first item it sees in Google Scholar.\nThis saves you time because you just have to scan that the BibTeX is correct before moving onto your next paper!";
            ButtonWizard.DataContext = ConfigurationManager.Instance.ConfigurationRecord_Bindable;

            ObjWebBrowser.GoBibTeXMode();
            ObjWebBrowser.PageLoaded += ObjWebBrowser_PageLoaded;
            ObjWebBrowser.TabChanged += ObjWebBrowser_TabChanged;

            PDFRendererControlArea.ToolTip = "This is the current PDF that has no BibTeX associated with it.  You can select text from the PDF to automatically search for that text.";
            ObjWebBrowser.ToolTip          = "Use this browser to hunt for BibTeX of PubMed XML.  As soon as you find some, it will automatically be associated with your PDFF.";
            TxtBibTeX.ToolTip = "This is the BibTeX that is currently associated with the displayed PDF.\nFeel free to edit this or replace it with a # if there is no BibTeX for this record and you do not want the Sniffer to keep prompting you for some...";

            HyperlinkBibTeXLinksMissing.Click += HyperlinkBibTeXLinksMissing_Click;

            Webcasts.FormatWebcastButton(ButtonWebcast, Webcasts.BIBTEX_SNIFFER);

            // Set dimensions
            {
                this.Width  = 800;
                this.Height = 600;

                // Be a little larger if possible
                if (SystemParameters.FullPrimaryScreenWidth > 1024)
                {
                    this.Height = 1024;
                }
                if (SystemParameters.FullPrimaryScreenHeight > 1024)
                {
                    this.Height = 1024;
                }
            }

            TxtBibTeX.TextChanged += TxtBibTeX_TextChanged;

            // Navigate to GS in a bid to not have the first .bib prompt for download
            ObjWebBrowser.ForceAdvancedMenus();
            ObjWebBrowser.ForceSnifferSearchers();
            ObjWebBrowser.DefaultWebSearcherKey = WebSearchers.SCHOLAR_KEY;
        }
        private void ReflectLatestBrowserContent()
        {
            try
            {
                // Neaten the text in the browser
                string text = ObjWebBrowser.CurrentPageText;

                if (null == text)
                {
                    return;
                }

                // Process
                text = text.Trim();

                // If this is valid BibTeX, offer it
                {
                    if (IsValidBibTex(text))
                    {
                        FeatureTrackingManager.Instance.UseFeature(Features.MetadataSniffer_ValidBibTeX);
                        UseAsBibTeX(text);

                        return;
                    }
                }

                // If this is valid PubMed XML, offer it
                {
                    string        converted_bibtex;
                    List <string> messages;
                    bool          success = PubMedXMLToBibTex.TryConvert(text, out converted_bibtex, out messages);
                    if (success)
                    {
                        FeatureTrackingManager.Instance.UseFeature(Features.MetadataSniffer_ValidPubMed);
                        UseAsBibTeX(converted_bibtex);
                        return;
                    }
                    else
                    {
                        if (0 < messages.Count)
                        {
                            foreach (string message in messages)
                            {
                                Logging.Info(message);
                            }
                        }
                    }
                }

                // Otherwise lets try parse the page cos it might be a google scholar page and if so we are going to want to try to get the first link to BibTeX
                if (ConfigurationManager.Instance.ConfigurationRecord.Metadata_UseBibTeXSnifferWizard)
                {
                    // Only do this automatically if there is not already bibtex in the record
                    if (null != pdf_document && String.IsNullOrEmpty(pdf_document.BibTex))
                    {
                        string url  = ObjWebBrowser.CurrentUri.ToString();
                        string html = ObjWebBrowser.CurrentPageHTML;
                        List <GoogleScholarScrapePaper> gssps = GoogleScholarScraper.ScrapeHtml(html, url);

                        try
                        {
                            // Try to process the first bibtex record
                            if (0 < gssps.Count)
                            {
                                GoogleScholarScrapePaper gssp = gssps[0];
                                if (!String.IsNullOrEmpty(gssp.bibtex_url))
                                {
                                    if (last_autonavigated_url != gssp.bibtex_url)
                                    {
                                        last_autonavigated_url = gssp.bibtex_url;

                                        gssp.bibtex_url = gssp.bibtex_url.Replace("&amp;", "&");
                                        ObjWebBrowser.OpenUrl(gssp.bibtex_url);
                                    }
                                }
                            }
                        }

                        catch (Exception ex)
                        {
                            Logging.Warn(ex, "Sniffer was not able to parse the results that came back from GS.");
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                Logging.Error(ex, "There was an exception while trying to parse the html back from Google Scholar");
            }
        }
 void GoogleBibTexSnifferControl_Closed(object sender, EventArgs e)
 {
     ObjWebBrowser.Dispose();
 }
        private void ReflectPDFDocument(string search_terms)
        {
            if (0 < pdf_documents_search_pool.Count)
            {
                TxtProgress.Text    = String.Format("Document {0} of {1}.", pdf_documents_search_index + 1, pdf_documents_search_pool.Count);
                ObjProgress.Value   = pdf_documents_search_index + 1;
                ObjProgress.Maximum = pdf_documents_search_pool.Count;
            }
            else
            {
                TxtProgress.Text    = "No documents";
                ObjProgress.Value   = 1;
                ObjProgress.Maximum = 1;
            }

            if (null != this.pdf_document_rendered)
            {
                // Clear down the previous renderer control
                PDFRendererControlArea.Children.Clear();

                if (null != this.pdf_renderer_control)
                {
                    this.pdf_renderer_control.Dispose();
                    this.pdf_renderer_control = null;
                }

                this.pdf_document_rendered = null;
                this.DataContext           = null;
            }

            if (null != pdf_document)
            {
                // Force inference of the title in case it has not been populated...
                PDFMetadataInferenceFromOCR.InferTitleFromOCR(pdf_document, true);

                this.pdf_document_rendered = pdf_document;
                this.DataContext           = pdf_document.Bindable;

                if (pdf_document.DocumentExists)
                {
                    ObjNoPDFAvailableMessage.Visibility = Visibility.Collapsed;
                    PDFRendererControlArea.Visibility   = Visibility.Visible;

                    // Make sure the first page is OCRed...
                    pdf_document.PDFRenderer.GetOCRText(1);

                    // Set up the new renderer control
                    this.pdf_renderer_control = new PDFRendererControl(this.pdf_document, false, PDFRendererControl.ZoomType.Zoom1Up);
                    this.pdf_renderer_control.ReconsiderOperationMode(PDFRendererControl.OperationMode.TextSentenceSelect);
                    this.pdf_renderer_control.TextSelected += pdf_renderer_control_TextSelected;
                    PDFRendererControlArea.Children.Add(pdf_renderer_control);
                }
                else
                {
                    ObjNoPDFAvailableMessage.Visibility = Visibility.Visible;
                    PDFRendererControlArea.Visibility   = Visibility.Collapsed;
                }

                // Make sure we have something to search for
                if (String.IsNullOrEmpty(search_terms))
                {
                    string title_combined = pdf_document.TitleCombined;
                    if (PDFDocument.TITLE_UNKNOWN != title_combined && pdf_document.DownloadLocation != title_combined)
                    {
                        search_terms = pdf_document.TitleCombined;
                    }
                }

                // Kick off the search
                if (!String.IsNullOrEmpty(search_terms))
                {
                    ObjWebBrowser.DoWebSearch(search_terms);
                }
            }
        }