Esempio n. 1
0
        public void SetEndData(AsyncTranslateState state)
        {
            bool nothingFound = true;

            foreach (Result r in state.Results)
            {
                if (!r.ResultNotFound)
                {
                    nothingFound = false;
                    break;
                }
            }
            string htmlString;

            if (nothingFound && TranslateOptions.Instance.ResultWindowOptions.HideWithoutResult)
            {
                htmlString = "<span><br/>" + LangPack.TranslateString("Nothing found") + "<br/></span>";

                Wait();
                HtmlHelper.AddTranslationCell(wBrowser, isClean, htmlString);
            }

            isClean = false;

            //force set of proper size - some time don't show bottom lines
            Size sz = wBrowser.Size;

            sz.Height++;
            wBrowser.Size = sz;
            RealRecalcSizes();
            sz.Height--;
            wBrowser.Size = sz;
            RealRecalcSizes();
        }
Esempio n. 2
0
        public void ShowSource()
        {
            Wait();
            string clean   = wBrowser.DocumentText;
            int    bodyidx = clean.IndexOf("<body>");

            if (bodyidx < 0)
            {
                bodyidx = clean.IndexOf("<BODY>");
            }

            if (bodyidx < 0)
            {
                MessageBox.Show(FindForm(),
                                LangPack.TranslateString("Nothing found"),
                                Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            clean = clean.Substring(0, bodyidx);
            HtmlSourceViewForm form = new HtmlSourceViewForm();

            form.Source = clean + WebBrowserHelper.GetDocument(wBrowser).Body.OuterHtml + "\r\n</html>";
            form.Text   = wBrowser.Url.ToString();
            form.Show();
        }
Esempio n. 3
0
        void LoadSubjects()
        {
            lbSubjects.BeginUpdate();
            loadingSubjects = true;
            lbSubjects.Items.Clear();
            string val;

            val = "+ " + LangPack.TranslateString("Toggle all");
            lbSubjects.Items.Add(new SubjectContainer("Toggle all", val));

            foreach (string s in supportedSubjects)
            {
                val = LangPack.TranslateString(s);
                if (s == "Common")
                {
                    val = "+" + val;
                }
                lbSubjects.Items.Add(new SubjectContainer(s, val), subjects.Contains(s));
            }
            lbSubjects.EndUpdate();
            lbSubjects.SetItemChecked(0, lbSubjects.CheckedItems.Count == supportedSubjects.Count);
            loadingSubjects      = false;
            serviceItemsSettings = null;             //reset
            LoadServices(false);
        }
 public HotkeyData(Keys keys, MouseButtons mouseButtons, bool custom)
 {
     this.keys         = keys;
     this.mouseButtons = mouseButtons;
     this.name         = HotkeysOptionsControl.GetHotkeyName(keys, mouseButtons, custom);
     this.caption      = LangPack.TranslateString(name);
 }
Esempio n. 5
0
        static void DownloadVersionsCompleted(Object sender, DownloadStringCompletedEventArgs e)
        {
            WebClient client = sender as WebClient;

            if (state == UpdateState.Cancel)
            {
                Cancelled();
                return;
            }

            if (e.Cancelled || e.Error != null)
            {
                string url = Constants.VersionsTxtUrls[versionUrlToCheck];
                if (TryToRerunVersionsCheck(client))
                {
                    return;
                }

                if (e.Error != null)
                {
                    SetErrorState(string.Format(CultureInfo.InvariantCulture, LangPack.TranslateString("Error on downloading {0}"), url) + "\r\n" + e.Error.Message);
                }
                else
                {
                    SetErrorState(LangPack.TranslateString("Canceled"));
                }
                return;
            }


            //versions.txt received, next step
            ParseVersions(client, e.Result);
        }
Esempio n. 6
0
        public static GuessResult Guess(string phrase, NetworkSetting networkSetting, EventHandler <GuessCompletedEventArgs> guessCompletedHandler)
        {
            AsyncGuessState state = null;
            bool            done  = false;
            EventHandler <GuessCompletedEventArgs> myHandler = delegate(object sender, GuessCompletedEventArgs e)
            {
                try
                {
                    FreeCL.Forms.Application.EndGuiLockingTask();
                    if (guessCompletedHandler != null)
                    {
                        guessCompletedHandler.Invoke(state, e);
                    }
                }
                finally
                {
                    done = true;
                }
            };

            FreeCL.Forms.Application.StartGuiLockingTask(LangPack.TranslateString("Language detection"));
            state = GuessAsync(phrase, networkSetting, myHandler);

            while (!done)
            {
                System.Windows.Forms.Application.DoEvents();
                Thread.Sleep(50);
            }
            return(state.Result);
        }
        void CbSubjectSelectedIndexChanged(object sender, EventArgs e)
        {
            if (ignoreLanguageChange)
            {
                return;
            }

            if (lvProfiles.SelectedItems.Count != 1)
            {
                return;
            }

            ListViewItem         lvi = lvProfiles.SelectedItems[0];
            UserTranslateProfile pf  = lvi.Tag as UserTranslateProfile;

            if (pf == null)
            {
                return;
            }

            SubjectContainer sc = cbSubject.SelectedItem as SubjectContainer;

            pf.Subject = sc.Subject;

            lvi.SubItems[2].Text = LangPack.TranslateString(sc.Subject);
        }
        void BChangeNameClick(object sender, EventArgs e)
        {
            ListViewItem         lvi = lvProfiles.SelectedItems[0];
            UserTranslateProfile pf  = lvi.Tag as UserTranslateProfile;

            string             oldName  = pf.Name;
            SetProfileNameForm nameForm = new SetProfileNameForm(pf as UserTranslateProfile, profiles);

            DialogResult dr = nameForm.ShowDialog(FindForm());

            nameForm.Dispose();
            if (dr == DialogResult.Cancel)
            {
                pf.Name = oldName;
                return;
            }
            else
            {
                profilesHistory.RenameProfile(oldName, pf.Name);
            }


            lvi.Text          = pf.Name;
            lProfileName.Text = pf.Name;

            lvi.SubItems[1].Text = (LangPack.TranslateLanguage(pf.TranslationDirection.From) +
                                    " -> " +
                                    LangPack.TranslateLanguage(pf.TranslationDirection.To)
                                    );
            lvi.SubItems[2].Text = LangPack.TranslateString(pf.Subject);


            LvProfilesSelectedIndexChanged(lvProfiles, new EventArgs());
        }
Esempio n. 9
0
        void OnLanguageChanged()
        {
            ignoreServicesLoading = true;
            try
            {
                if (languages != null)
                {
                    LoadLanguages();
                    LoadSubjects();
                    LoadHistory();
                }
                tpLangs.Text                = LangPack.TranslateString("Languages");
                tpSubject.Text              = LangPack.TranslateString("Subjects");
                tpServices.Text             = LangPack.TranslateString("Services");
                lEnabled.Text               = LangPack.TranslateString("Enabled");
                lDisabled.Text              = LangPack.TranslateString("Error");
                lDisabledByUser.Text        = LangPack.TranslateString("Disabled");
                miMoveServiceUp.Text        = LangPack.TranslateString("Move service up");
                miMoveServiceUp.ToolTipText = miMoveServiceUp.Text;
                ttMain.SetToolTip(sbServiceUp, miMoveServiceUp.Text);

                miMoveServiceDown.Text        = LangPack.TranslateString("Move service down");
                miMoveServiceDown.ToolTipText = miMoveServiceDown.Text;
                ttMain.SetToolTip(sbServiceDown, miMoveServiceDown.Text);
                //TODO:ttMain.SetToolTip(sbEnableService, LangPack.TranslateString(""));


                LvServicesResize(this, new EventArgs());
            }
            finally
            {
                ignoreServicesLoading = false;
                LoadServices(false);
            }
        }
        void InitUserProfileControls()
        {
            cbFrom.Items.Clear();
            cbTo.Items.Clear();

            for (int i = 0; i < (int)Language.Last; i++)
            {
                LanguageDataContainer ld = new LanguageDataContainer((Language)i, LangPack.TranslateLanguage((Language)i));
                cbFrom.Items.Add(ld);
                cbTo.Items.Add(ld);
            }

            cbSubject.Items.Clear();
            foreach (string subject in Manager.Subjects)
            {
                SubjectContainer sc = new SubjectContainer(subject, LangPack.TranslateString(subject));
                cbSubject.Items.Add(sc);
            }

            SubjectContainer sc1 = new SubjectContainer(SubjectConstants.Any, LangPack.TranslateString(SubjectConstants.Any));

            cbSubject.Items.Add(sc1);

            changed = false;
            LvProfilesSelectedIndexChanged(lvProfiles, new EventArgs());
        }
Esempio n. 11
0
 static void Cancelled()
 {
     message           = LangPack.TranslateString("Canceled");
     state             = UpdateState.None;
     versionUrlToCheck = 0;
     TranslateOptions.Instance.UpdateOptions.NextCheck       = new DateTime(DateTime.Now.Ticks + DateTimeUtils.Days(1).Ticks);       //next day
     TranslateOptions.Instance.UpdateOptions.LastCheckResult = message;
     TranslateOptions.Instance.UpdateOptions.LastCheck       = DateTime.Now;
 }
        void OnLanguageChanged()
        {
            aMoveProfileUp.Hint   = TranslateString("Move profile up");
            aMoveProfileDown.Hint = TranslateString("Move profile down");
            chName.Text           = TranslateString("Name");
            chDirection.Text      = TranslateString("Translation direction");
            chSubject.Text        = TranslateString("Subject");
            lName.Text            = TranslateString("Name");
            cbIncludeMonolingualDictionaryInTranslation.Text = TranslateString("Include monolingual dictionaries in translation");
            aAddProfile.Hint      = TranslateString("Add new user profile");
            aRemoveProfile.Hint   = TranslateString("Remove user profile");
            tpDefaultOptions.Text = TranslateString("Options");
            tpOptions.Text        = TranslateString("Options");
            tpServices.Text       = TranslateString("Services");
            bChangeName.Text      = TranslateString("Set profile properties");
            lLangPair.Text        = TranslateString("Translation direction");
            lSubject.Text         = TranslateString("Subject");

            aEditServices.Hint    = TranslateString("Edit services");
            aRemoveService.Hint   = TranslateString("Remove service");
            aMoveServiceUp.Hint   = TranslateString("Move service up");
            aMoveServiceDown.Hint = TranslateString("Move service down");


            tpLanguageSelector.Text = TranslateString("View");
            cbShowServices.Text     = TranslateString("Show services list");
            cbShowLanguages.Text    = TranslateString("Show languages list");
            cbShowSubjects.Text     = TranslateString("Show subjects list");

            bLanguageFilter.Text = TranslateString("Filter of languages");

            foreach (ListViewItem lvi in lvProfiles.Items)
            {
                if (lvi.Tag == defaultProfile)
                {
                    lvi.Text = TranslateString(TranslateOptions.Instance.DefaultProfile.Name);
                }
                else
                {
                    UserTranslateProfile pf = lvi.Tag as UserTranslateProfile;
                    if (pf != null)
                    {
                        lvi.SubItems[1].Text = (LangPack.TranslateLanguage(pf.TranslationDirection.From) +
                                                " -> " +
                                                LangPack.TranslateLanguage(pf.TranslationDirection.To)
                                                );
                        lvi.SubItems[2].Text = LangPack.TranslateString(pf.Subject);
                    }
                }
            }


            chDirection.Width = -2;
            chSubject.Width   = -2;

            InitUserProfileControls();
        }
Esempio n. 13
0
 void OnLanguageChanged()
 {
     lName.Text    = LangPack.TranslateString("Name") + " :";
     lSize.Text    = LangPack.TranslateString("Size") + " :";
     cbSystem.Text = LangPack.TranslateString("Default font");
     toolTip.SetToolTip(cbSystem,
                        LangPack.TranslateString("Name") + " :" + defaultFont.Name + ", " +
                        LangPack.TranslateString("Size") + " :" + defaultFont.Size.ToString()
                        );
 }
Esempio n. 14
0
        void OnLanguageChanged()
        {
            bOk.Text       = TranslateString("OK");
            bCancel.Text   = LangPack.TranslateString("Cancel");
            lName.Text     = LangPack.TranslateString("Profile name");
            lLangPair.Text = TranslateString("Translation direction");
            lSubject.Text  = TranslateString("Subject");

            Text = LangPack.TranslateString("Set profile properties");
        }
Esempio n. 15
0
        void AboutFormVisibleChanged(object sender, EventArgs e)
        {
            lStats.Text = string.Format(
                TranslateString("{0} phrases translated by {1} calls to translate services"),
                TranslateOptions.Instance.StatOptions.Calls,
                TranslateOptions.Instance.StatOptions.ServiceCalls
                );

            Text            = LangPack.TranslateString("About") + " " + lAppTitle.Text;
            bDonate.Text    = LangPack.TranslateString("Donate ...");
            bDonate.Visible = !(FreeCL.RTL.LangPack.CurrentLanguage == "Russian" || FreeCL.RTL.LangPack.CurrentLanguage == "Ukrainian");
        }
Esempio n. 16
0
        void LvServicesEnabledSelectedIndexChanged(object sender, EventArgs e)
        {
            LockUpdate(true);
            try
            {
                if (skipselectingservices)
                {
                    return;
                }
                ListView lv = sender as ListView;
                if (lv.SelectedItems.Count == 0)
                {
                    return;
                }

                ListViewItem             lvi = lv.SelectedItems[0];
                ServiceSettingsContainer sc  = lvi.Tag as ServiceSettingsContainer;
                serviceStatus.ShowLanguage = selection.From == Language.Any || selection.To == Language.Any;
                serviceStatus.Status       = sc;

                if (sc.DisabledByUser)
                {
                    sbEnableService.Text = LangPack.TranslateString("Enable");
                }
                else
                {
                    sbEnableService.Text = LangPack.TranslateString("Disable");
                }
                miEnableService.Text = sbEnableService.Text;
                //ttMain.SetToolTip(sbEnableService, sbEnableService.Text);

                if ((lvServicesEnabled == lv || lv == lvServicesDisabled) &&
                    lv.Items.Count > 1 &&
                    (selection.From != Language.Any && selection.To != Language.Any))
                {
                    sbServiceUp.Enabled   = lv.SelectedIndices[0] != 0;
                    sbServiceDown.Enabled = lv.SelectedIndices[0] != lv.Items.Count - 1;
                }
                else
                {
                    sbServiceUp.Enabled   = false;
                    sbServiceDown.Enabled = false;
                }

                miMoveServiceDown.Enabled = sbServiceDown.Enabled;
                miMoveServiceUp.Enabled   = sbServiceUp.Enabled;
            }
            finally
            {
                LockUpdate(false);
            }
        }
Esempio n. 17
0
 void OnLanguageChanged()
 {
     Text = TranslateString("Usage information collecting");
     bYes.Text = TranslateString("Yes");
     bNo.Text = LangPack.TranslateString("Cancel");
     lTop.Text = TranslateString("Do you want to allow collecting of basic information about application usage ?");
     gbWill.Text = TranslateString("Tool will");
     gbWillNot.Text = TranslateString("Tool will not");
     lWill.Text = TranslateString("Collect anonymous information about tool usage : tool running time, tool version, OS version.");
     lWillNot.Text = TranslateString("Collect your name, address, or any other personally identifiable information. The information collected is anonymous.");
     llAlreadyCollected.Text = TranslateString("You can check already collected data here");
     lDisable.Text = TranslateString("You can disable data collecting at any time in \"Options\" dialog");
 }
        void OnLanguageChanged()
        {
            Text       = TranslateString("Filter of languages");
            lInfo.Text = TranslateString("Choose languages you want to translate from and to. Disabled languages will be removed from \"Languages\" tab of default profile");

            gbFrom.Text = TranslateString("Source languages");
            gbTo.Text   = TranslateString("Target languages");


            bCancel.Text = LangPack.TranslateString("Cancel");
            bOk.Text     = TranslateString("OK");

            LoadLanguages();
        }
Esempio n. 19
0
        static void DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (state == UpdateState.Cancel)
            {
                Cancelled();
                return;
            }

            if (e.Cancelled || e.Error != null)
            {
                if (e.Error != null)
                {
                    SetErrorState(string.Format(CultureInfo.InvariantCulture, LangPack.TranslateString("Error on downloading {0}"), urlToDownload) + "\r\n" + e.Error.Message);
                }
                else
                {
                    SetErrorState(LangPack.TranslateString("Canceled"));
                }
                return;
            }

            string pathToAppData = FreeCL.Forms.Application.DataFolder + Path.DirectorySeparatorChar + "Update";

            if (!Directory.Exists(pathToAppData))
            {
                Directory.CreateDirectory(pathToAppData);
            }
            updateFileName = pathToAppData + Path.DirectorySeparatorChar + fileName;
            if (File.Exists(updateFileName))
            {
                try
                {
                    File.Delete(updateFileName);
                }
                catch
                {
                    SetErrorState(string.Format(CultureInfo.InvariantCulture, LangPack.TranslateString("File {0} already exists"), updateFileName));
                    return;
                }
            }

            FileStream fs = new FileStream(updateFileName, FileMode.Create, FileAccess.Write, FileShare.None);

            fs.Write(e.Result, 0, e.Result.Length);
            fs.Dispose();
            NativeMethods.MarkFileToDeleteOnReboot(updateFileName);
            state = UpdateState.UpdateDownloaded;
        }
Esempio n. 20
0
            void GenerateData()
            {
                name = "";
                if (!string.IsNullOrEmpty(serviceItemData.ServiceItem.Description))
                {
                    name = LangPack.TranslateString(serviceItemData.ServiceItem.Description) + " - ";
                }
                name += LangPack.TranslateString(serviceItemData.ServiceItem.Service.FullName);

                type         = ServiceSettingsContainer.GetServiceItemType(serviceItemData.ServiceItem);
                languagePair = LangPack.TranslateLanguage(serviceItemData.LanguagePair.From) +
                               "->" +
                               LangPack.TranslateLanguage(serviceItemData.LanguagePair.To);

                subject = LangPack.TranslateString(serviceItemData.Subject);
            }
        public static string GetServiceItemType(ServiceItem serviceItem)
        {
            string result;

            if (serviceItem is Translator)
            {
                result = LangPack.TranslateString("Translator");
            }
            else if (serviceItem is AntonymsDictionary)
            {
                result = LangPack.TranslateString("Dictionary of antonyms");
            }
            else if (serviceItem is SynonymsDictionary)
            {
                result = LangPack.TranslateString("Dictionary of synonyms");
            }
            else if (serviceItem is PhraseologicalDictionary)
            {
                result = LangPack.TranslateString("Phraseological dictionary");
            }
            else if (serviceItem is Encyclopedia)
            {
                result = LangPack.TranslateString("Encyclopedia");
            }
            else if (serviceItem is MonolingualSearchEngine || serviceItem is BilingualSearchEngine)
            {
                result = LangPack.TranslateString("Search Engine");
            }
            else if (serviceItem is MonolingualDictionary)
            {
                result = LangPack.TranslateString("Monolingual dictionary");
            }
            else if (serviceItem is BilingualPhrasesDictionary)
            {
                result = LangPack.TranslateString("Bilingual phrases dictionary");
            }
            else if (serviceItem is BilingualSentensesDictionary)
            {
                result = LangPack.TranslateString("Bilingual sentenses dictionary");
            }
            else
            {
                result = LangPack.TranslateString("Bilingual dictionary");
            }
            return(result);
        }
Esempio n. 22
0
        string GetNewProfileName()
        {
            string nameBase = "";

            if (profile.TranslationDirection.From != Language.Any)
            {
                nameBase += StringParser.SafeResizeString(LangPack.TranslateLanguage(profile.TranslationDirection.From), 3);
            }
            else
            {
                nameBase += LangPack.TranslateLanguage(profile.TranslationDirection.From);
            }

            nameBase += "->";

            if (profile.TranslationDirection.To != Language.Any)
            {
                nameBase += StringParser.SafeResizeString(LangPack.TranslateLanguage(profile.TranslationDirection.To), 3);
            }
            else
            {
                nameBase += LangPack.TranslateLanguage(profile.TranslationDirection.To);
            }

            if (profile.Subject != SubjectConstants.Any && profile.Subject != SubjectConstants.Common)
            {
                nameBase += "->" + StringParser.SafeResizeString(LangPack.TranslateString(profile.Subject), 3);
            }

            if (!IsProfileNameExists(nameBase, profile.Name))
            {
                return(nameBase);
            }

            string result;

            for (int i = 1; i < 1000; i++)
            {
                result = nameBase + " " + i.ToString();
                if (!IsProfileNameExists(result, profile.Name))
                {
                    return(result);
                }
            }
            return("");
        }
        static void GenerateListByUrlHtml(WebBrowser wBrowser)
        {
            string nodeName = "list_by_url";

            string InnerHtml = GenerateTopNode(nodeName, LangPack.TranslateString("Grouped by Service's Url") + " - " + Manager.Services.Count.ToString(), 0, true);

            HtmlHelper.AddTranslationCell(wBrowser, null, true, InnerHtml, null);

            HtmlHelper.CreateTable(wBrowser, nodeName, nodeName + "_table");

            SortedDictionary <string, List <ServiceItem> > list = new SortedDictionary <string, List <ServiceItem> >();

            foreach (Service service in Manager.Services)
            {
                List <ServiceItem> inner_list = new List <ServiceItem>();
                list.Add(service.Url.AbsoluteUri, inner_list);
                foreach (Translator translator in service.Translators)
                {
                    inner_list.Add(translator);
                }
                foreach (BilingualDictionary dictionary in service.BilingualDictionaries)
                {
                    inner_list.Add(dictionary);
                }
                foreach (MonolingualDictionary dictionary in service.MonolingualDictionaries)
                {
                    inner_list.Add(dictionary);
                }
            }

            bool is_first = true;

            foreach (KeyValuePair <string, List <ServiceItem> > kvp in list)
            {
                foreach (ServiceItem si in kvp.Value)
                {
                    GenerateServiceItemSell(wBrowser, si, nodeName + "_table_body", is_first, true);
                    if (is_first)
                    {
                        is_first = false;
                    }
                }
            }
        }
Esempio n. 24
0
        public void SetStatistics(long translateTicks)
        {
            if (!TranslateOptions.Instance.ResultWindowOptions.ShowQueryStatistics)
            {
                return;
            }

            string htmlString = string.Format(CultureInfo.InvariantCulture,
                                              LangPack.TranslateString("Full time : {0} s"),
                                              new DateTime(translateTicks).ToString("ss.fffffff", CultureInfo.InvariantCulture));;

            htmlString = "<span style=\"" + HtmlHelper.InfoTextStyle + "\">" + htmlString + "</span>";

            Wait();
            HtmlHelper.AddTranslationCell(wBrowser, isClean, htmlString);

            isClean = false;
            RecalcSizes();
        }
Esempio n. 25
0
 public bool Apply()
 {
     if (proxyMode == ProxyMode.System)
     {
         networkSetting.Proxy             = WebRequest.DefaultWebProxy;
         networkSetting.Proxy.Credentials = CredentialCache.DefaultCredentials;
     }
     else if (proxyMode == ProxyMode.None)
     {
         networkSetting.Proxy = null;
     }
     else
     {
         try
         {
             WebProxy proxyObject = new WebProxy("http://" + proxyHost + ":" + proxyPort.ToString(CultureInfo.InvariantCulture) + "/", true);
             proxyObject.Credentials = CredentialCache.DefaultCredentials;
             if (proxyAuthentication)
             {
                 if (!proxyNtlmAuthentication)
                 {
                     proxyObject.Credentials = new NetworkCredential(proxyUser, ProxyDecryptedPassword);
                 }
                 else
                 {
                     proxyObject.Credentials = new NetworkCredential(proxyUser, ProxyDecryptedPassword, proxyNtlmDomain);
                 }
             }
             networkSetting.Proxy = proxyObject;
         }
         catch (System.UriFormatException)
         {
             proxyMode = ProxyMode.System;
             string errmessage = LangPack.TranslateString("Format of HTTP-Proxy ({0}) is wrong. Proxy settings will be reset to default.");
             errmessage = string.Format(errmessage, proxyHost);
             MessageBox.Show(errmessage, Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
             return(false);
         }
     }
     return(true);
 }
        void AAddProfileExecute(object sender, EventArgs e)
        {
            UserTranslateProfile pf = new UserTranslateProfile();

            SetProfileNameForm nameForm = new SetProfileNameForm(pf, profiles);
            DialogResult       dr       = nameForm.ShowDialog(FindForm());

            nameForm.Dispose();
            if (dr == DialogResult.Cancel)
            {
                return;
            }

            profiles.Add(pf);

            ListViewItem lvi = new ListViewItem();

            lvi.Text = pf.Name;
            lvi.Tag  = pf;

            lvi.SubItems.Add(LangPack.TranslateLanguage(pf.TranslationDirection.From) +
                             " -> " +
                             LangPack.TranslateLanguage(pf.TranslationDirection.To)
                             );
            lvi.SubItems.Add(LangPack.TranslateString(pf.Subject));

            lvProfiles.Items.Add(lvi);
            lvProfiles.Focus();

            foreach (ListViewItem lv in lvProfiles.SelectedItems)
            {
                lv.Selected = false;
                lv.Focused  = false;
            }

            lvi.Selected = true;
            lvi.Focused  = true;

            AEditServicesExecute(this, new EventArgs());
        }
 public void Check(string phrase)
 {
     try
     {
         string err;
         if (setting.ServiceItem.CheckPhrase(phrase, out err))
         {
             error   = "";
             enabled = true;
         }
         else
         {
             error   = LangPack.TranslateString(err);
             enabled = false;
         }
     }
     catch (Exception e)
     {
         error   = LangPack.TranslateString(e.Message);
         enabled = false;
     }
 }
Esempio n. 28
0
        private static void Main(string[] args)
        {
            //if(MonoHelper.IsUnix)
            //	Environment.SetEnvironmentVariable ("MONO_BROWSER_ENGINE", "webkit");

            if (CommandLineHelper.IsCommandSwitchSet("gen_list"))
            {
                try
                {
                    WebUI.ResultsWebServer.UnhandledException += OnUnhandledExceptionEvent;
                    WebUI.ResultsWebServer.Start();

                    ServicesListHtmlGenerator.Generate();
                }
                catch (Exception e)
                {
                    Application.OnThreadException(e);
                }
                return;
            }

            try
            {
                Application.ExceptionsLog += GlobalEventsLogException;
                ResultsCache.UseCache      = true;
                GuessResultsCache.UseCache = true;

                UpdatesManager.Init();
                Application.ShowSplashForm(null);

                Application.OptionsForm = new OptionsForm();
                Application.BaseOptions = new TranslateOptions();
                Application.AboutForm   = new AboutForm();

                OptionsControlsManager.RegisterOptionControl(typeof(StartupOptionsControl), "General", 0, "Startup", 1);
                OptionsControlsManager.RegisterOptionControl(typeof(TrayOptionsControl), "General", 0, "Tray", 2);
                OptionsControlsManager.RegisterOptionControl(typeof(ResultWindowOptionControl), "General", 0, "Result view", 3);
                OptionsControlsManager.RegisterOptionControl(typeof(GuesserOptionsControl), "General", 0, "Language detection", 4);

                if (!MonoHelper.IsUnix)                //monobug - don't work with DataSource
                {
                    OptionsControlsManager.RegisterOptionControl(typeof(KeyboardLayoutControl), "General", 0, "Keyboard layouts", 5);
                }


                OptionsControlsManager.RegisterOptionControl(typeof(UpdatesOptionsControl), "General", 0, "Updates", 6);
                OptionsControlsManager.RegisterOptionControl(typeof(HotkeysOptionsControl), "General", 0, "Hotkeys", 7);

                OptionsControlsManager.RegisterOptionControl(typeof(InputFontOptionsControl), "Fonts", 1, "Input text", 0);
                OptionsControlsManager.RegisterOptionControl(typeof(ResultViewFontOptionsControl), "Fonts", 1, "Result view", 1);
                OptionsControlsManager.RegisterOptionControl(typeof(ToolbarsFontOptionsControl), "Fonts", 1, "Toolbars", 2);

                OptionsControlsManager.RegisterOptionControl(typeof(GeneralNetworkOptionsControl), "Network", 2, "Common", 0);

                OptionsControlsManager.RegisterOptionControl(typeof(CustomProfilesControl), "Profiles", 3, "List", 4);
                OptionsControlsManager.RegisterOptionControl(typeof(AnalyticsOptionsControl), "Usage information collecting", 4, "Usage information collecting", 4);

                Application.Initialize();

                if (TranslateOptions.Instance.SingleInstance && ProcessHelper.IsOtherInstanceAlreadyStarted())
                {
                    ProcessHelper.ActivateOtherInstance(ApplicationInfo.ProductName);
                    return;
                }

                UpdatesManager.CheckNewVersion();

                WebUI.ResultsWebServer.UnhandledException += OnUnhandledExceptionEvent;
                try
                {
                    WebUI.ResultsWebServer.Start();
                }
                catch (System.Reflection.TargetInvocationException e)
                {
                    if (e.InnerException != null && e.InnerException.GetType() == typeof(System.Security.VerificationException))
                    {
                        MessageBox.Show(LangPack.TranslateString("Running from network share not supported.\nTool can work only when started from local drive under appropriate user's rights."),
                                        Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        throw;
                    }
                }

                AnalyticsMonitor.Start();
                Application.Run(new TranslateMainForm());
                WebUI.ResultsWebServer.Stop();
            }
            catch (Exception e)
            {
                Application.OnThreadException(e);
            }
        }
        void LoadStatus()
        {
            //Console.WriteLine("LoadStatus : " + status.Setting.ServiceItem.Service.FullName);

            Clear();
            while (!isClean)
            {
                Application.DoEvents();
            }
            Wait();

            string name = "";

            if (!string.IsNullOrEmpty(status.Setting.ServiceItem.Description))
            {
                name += LangPack.TranslateString(status.Setting.ServiceItem.Description) + " - ";
            }

            name += LangPack.TranslateString(status.Setting.ServiceItem.Service.FullName);

            string htmlString = string.Format(CultureInfo.InvariantCulture,
                                              HtmlHelper.ServiceNameFormat,
                                              status.Setting.ServiceItem.Service.Url,
                                              HttpUtility.HtmlEncode(name));

            htmlString += "<br><b>" + LangPack.TranslateString("Type") + "</b> : " + status.Type;

            if (!shortView)
            {
                if (status.Setting.Subject != SubjectConstants.Common)
                {
                    htmlString += "<br>" + "<b>" + LangPack.TranslateString("Subject") + "</b> : " + LangPack.TranslateString(status.Setting.Subject);
                }
            }
            else
            {
                htmlString += ", " + "<b>" + LangPack.TranslateString("Subject") + "</b> : " + LangPack.TranslateString(status.Setting.Subject);
            }

            if (showLanguage)
            {
                if (!shortView)
                {
                    htmlString += "<br>" + LangPack.TranslateLanguage(status.Setting.LanguagePair.From) +
                                  "->" +
                                  LangPack.TranslateLanguage(status.Setting.LanguagePair.To);
                }
                else
                {
                    htmlString += "<br><b>" + LangPack.TranslateString("Translation direction") +
                                  "</b> : " +
                                  LangPack.TranslateLanguage(status.Setting.LanguagePair.From) +
                                  "->" +
                                  LangPack.TranslateLanguage(status.Setting.LanguagePair.To);
                }
            }

            if (!shortView)
            {
                if (status.DisabledByUser)
                {
                    htmlString += "<br>" + LangPack.TranslateString("<b>Status</b> : Disabled");
                    htmlString += string.Format("<br><button id=\"btn\" type=\"button\"  align=\"top\" style=\"{0}\">{1}</button>",
                                                HtmlHelper.ButtonTextStyle, LangPack.TranslateString("Enable"));
                }
                else if (status.Enabled)
                {
                    htmlString += "<br>" + LangPack.TranslateString("<b>Status</b> : Enabled");
                    htmlString += string.Format("<br><button id=\"btn\" type=\"button\" align=\"top\" style=\"{0}\">{1}</button>",
                                                HtmlHelper.ButtonTextStyle, LangPack.TranslateString("Disable"));
                }
                else
                {
                    htmlString += "<br>" + LangPack.TranslateString("<b>Status</b> : Error");
                    htmlString += " - " + string.Format("<span style=\"" + HtmlHelper.ErrorTextStyle + "\">{0}</span>", status.Error);
                    htmlString += string.Format("<br><button id=\"btn\" type=\"button\" align=\"top\" style=\"{0}\">{1}</button>",
                                                HtmlHelper.ButtonTextStyle, LangPack.TranslateString("Disable"));
                }
            }

            if (status.Setting.ServiceItem.CharsLimit != -1)
            {
                htmlString += "<br>" + "<b>";
                htmlString += string.Format(LangPack.TranslateString("Limit {0} : {1} characters"),
                                            "</b>", status.Setting.ServiceItem.CharsLimit);
            }

            if (status.Setting.ServiceItem.LinesLimit != -1)
            {
                htmlString += "<br>" + "<b>";
                htmlString += string.Format(LangPack.TranslateString("Limit {0} : {1} lines"),
                                            "</b>", status.Setting.ServiceItem.LinesLimit);
            }

            if (status.Setting.ServiceItem.WordsLimit != -1)
            {
                htmlString += "<br>" + "<b>";
                htmlString += string.Format(LangPack.TranslateString("Limit {0} : {1} words"),
                                            "</b>", status.Setting.ServiceItem.WordsLimit);
            }

            if (status.IsAsteriskMaskSupported || status.IsQuestionMaskSupported)
            {
                htmlString += "<br>" + "<b>" + LangPack.TranslateString("Masks") + "</b> : ";
                if (status.IsAsteriskMaskSupported)
                {
                    htmlString += "'*'";
                }

                if (status.IsAsteriskMaskSupported && status.IsQuestionMaskSupported)
                {
                    htmlString += ",";
                }

                if (status.IsQuestionMaskSupported)
                {
                    htmlString += "'?'";
                }
            }



            //tableCell.InnerHtml = htmlString;
            Wait();
            HtmlHelper.AddTranslationCell(wbStatus, isClean, htmlString, status.Setting.ServiceItem);

            HtmlElement button = WebBrowserHelper.GetDocument(wbStatus).GetElementById("btn");

            if (button != null)
            {
                button.Click += OnButtonClick;
            }


            isClean = false;
            RealRecalcSizes();
        }
        static void GenerateListByLangHtml(WebBrowser wBrowser)
        {
            //count langs without gb\us english
            int pairsCount = 0;

            foreach (LanguagePair lp in Manager.LanguagePairServiceItems.Keys)
            {
                if (lp.From != Language.English_GB && lp.From != Language.English_US &&
                    lp.To != Language.English_GB && lp.To != Language.English_US)
                {
                    pairsCount++;
                }
            }

            string nodeName  = "list_by_lang";
            string InnerHtml = GenerateTopNode(nodeName, LangPack.TranslateString("Grouped by Language") + GetLangsPairsCount(pairsCount), 0, true);

            HtmlHelper.AddTranslationCell(wBrowser, null, true, InnerHtml, null);
            HtmlHelper.CreateTable(wBrowser, nodeName, nodeName + "_table");

            SortedDictionary <string, SortedDictionary <string, List <ServiceItem> > > langs = new SortedDictionary <string, SortedDictionary <string, List <ServiceItem> > >();

            foreach (KeyValuePair <LanguagePair, ServiceItemsCollection> kvpData in Manager.LanguagePairServiceItems)
            {
                if (kvpData.Key.From == Language.English_GB || kvpData.Key.From == Language.English_US ||
                    kvpData.Key.To == Language.English_GB || kvpData.Key.To == Language.English_US)
                {
                    continue;
                }

                string fromlang = LangPack.TranslateLanguage(kvpData.Key.From);
                string tolang   = LangPack.TranslateLanguage(kvpData.Key.To);
                SortedDictionary <string, List <ServiceItem> > inner_list;
                if (!langs.TryGetValue(fromlang, out inner_list))
                {
                    inner_list = new SortedDictionary <string, List <ServiceItem> >();
                    langs.Add(fromlang, inner_list);
                }
                List <ServiceItem> items;
                if (!inner_list.TryGetValue(tolang, out items))
                {
                    items = new List <ServiceItem>();
                    inner_list.Add(tolang, items);
                }

                foreach (ServiceItem si in kvpData.Value)
                {
                    if (!(si is MonolingualSearchEngine || si is BilingualSearchEngine))
                    {
                        items.Add(si);
                    }
                }
            }


            foreach (KeyValuePair <string, SortedDictionary <string, List <ServiceItem> > > kvp in langs)
            {
                string htmlString = "";

                string childnodeName = "by_lang_" + kvp.Key;
                childnodeName = childnodeName.Replace("'", "_");
                htmlString   += GenerateTopNode(childnodeName, "-" + kvp.Key + " ->" + GetLangsPairsCount(kvp.Value.Count));
                HtmlHelper.AddTranslationCell(wBrowser, nodeName + "_table_body", true, htmlString, null);

                HtmlHelper.CreateTable(wBrowser, childnodeName, childnodeName + "_table");
                string topchildnodeName = childnodeName + "_table_body";
                foreach (KeyValuePair <string, List <ServiceItem> > kvpToLangs in kvp.Value)
                {
                    if (kvpToLangs.Value.Count == 0)
                    {
                        continue;
                    }
                    htmlString = "";


                    childnodeName = "by_lang_" + kvp.Key + "_" + kvpToLangs.Key;
                    childnodeName = childnodeName.Replace("'", "_");
                    htmlString   += GenerateTopNode(childnodeName, kvp.Key + "->" + kvpToLangs.Key + " -" + GetServicesCount(kvpToLangs.Value.Count), 1);
                    HtmlHelper.AddTranslationCell(wBrowser, topchildnodeName, true, htmlString, null);

                    HtmlHelper.CreateTable(wBrowser, childnodeName, childnodeName + "_table");

                    SortedDictionary <string, List <ServiceItem> > sortedServices = new SortedDictionary <string, List <ServiceItem> >();
                    foreach (ServiceItem si in kvpToLangs.Value)
                    {
                        List <ServiceItem> inner_list;
                        if (!sortedServices.TryGetValue(si.Service.Url.AbsoluteUri, out inner_list))
                        {
                            inner_list = new List <ServiceItem>();
                            sortedServices.Add(si.Service.Url.AbsoluteUri, inner_list);
                        }
                        inner_list.Add(si);
                    }

                    bool is_first = true;
                    foreach (KeyValuePair <string, List <ServiceItem> > kvpServices in sortedServices)
                    {
                        foreach (ServiceItem si in kvpServices.Value)
                        {
                            GenerateServiceItemSell(wBrowser, si, childnodeName + "_table_body", is_first, false);
                            if (is_first)
                            {
                                is_first = false;
                            }
                        }
                    }
                }
            }
        }