Exemplo n.º 1
0
 private void BtnOK_Click(object sender, RoutedEventArgs e)
 {
     foreach (var page in pages)
     {
         page.UpdateConfig();
     }
     Config.SaveConfig();
     ApplicationContext.BroadcastConfigChange();
     Close();
     Helpers.RunGC();
 }
Exemplo n.º 2
0
 private void BtnOK_Clicked(object?sender, EventArgs e)
 {
     UpdateBrowserMonitoringConfig();
     UpdateGeneralSettingsConfig();
     UpdateNetworkSettingsConfig();
     UpdatePasswordManagerConfig();
     UpdateAdvancedSettingsConfig();
     Config.SaveConfig();
     ApplicationContext.BroadcastConfigChange();
     Dispose();
     Helpers.RunGC();
 }
Exemplo n.º 3
0
        private static void Window_OkClicked(object?sender, EventArgs e)
        {
            var window = sender as ISpeedLimiterWindow;

            if (window == null)
            {
                return;
            }
            window.OkClicked -= Window_OkClicked;
            var speedLimitEnabled = window.EnableSpeedLimit;
            var defaultSpeedLimit = window.SpeedLimit;

            lock (Config.Instance)
            {
                Config.Instance.EnableSpeedLimit    = speedLimitEnabled ? defaultSpeedLimit > 0 : false;
                Config.Instance.DefaltDownloadSpeed = defaultSpeedLimit > 0 ? defaultSpeedLimit : 0;
                Config.SaveConfig();
            }
            ApplicationContext.BroadcastConfigChange();
        }
Exemplo n.º 4
0
        public static void CreateAndShowDialog(INewDownloadDialog window, Message?message = null,
                                               Action?destroyCallback = null)
        {
            window.DestroyEvent += (_, _) => destroyCallback?.Invoke();
            window.SetFolderValues(CommonUtils.GetFolderValues());
            if (Config.Instance.FolderSelectionMode == FolderSelectionMode.Auto)
            {
                window.SeletedFolderIndex = 0;
            }
            else
            {
                var index = CommonUtils.GetFolderValues().ToList().IndexOf(Config.Instance.UserSelectedDownloadFolder);
                if (index > 1)
                {
                    window.SeletedFolderIndex = index;
                }
                else
                {
                    Config.Instance.FolderSelectionMode = FolderSelectionMode.Auto;
                    window.SeletedFolderIndex           = 0;
                }
            }

            var fileName = string.Empty;

            if (message != null)
            {
                window.Url = message.Url;
                fileName   = FileHelper.SanitizeFileName(message.File ?? FileHelper.GetFileName(new Uri(message.Url)));
                window.SelectedFileName = fileName;

                var contentLength = 0L;
                var header        = message.GetResponseHeaderFirstValue("Content-Length");
                if (!string.IsNullOrEmpty(header))
                {
                    try
                    {
                        contentLength = Int64.Parse(header);
                    }
                    catch { }
                }
                window.SetFileSizeText(contentLength > 0 ? FormattingHelper.FormatSize(contentLength) : "---");
            }
            else
            {
                var url = ApplicationContext.Application.GetUrlFromClipboard();
                if (!string.IsNullOrEmpty(url))
                {
                    window.Url = url;
                    window.SelectedFileName = FileHelper.SanitizeFileName(FileHelper.GetFileName(new Uri(url)));
                }
                window.UrlChangedEvent += (sender, args) =>
                {
                    if (Helpers.IsUriValid(window.Url))
                    {
                        window.SelectedFileName = FileHelper.SanitizeFileName(FileHelper.GetFileName(new Uri(window.Url)));
                        fileName = window.SelectedFileName;
                    }
                };
            }

            window.FileBrowsedEvent += CommonUtils.OnFileBrowsed;
            window.DropdownSelectionChangedEvent += CommonUtils.OnDropdownSelectionChanged;

            window.UrlBlockedEvent += (sender, args) =>
            {
                if (Helpers.IsUriValid(window.Url))
                {
                    var url         = new Uri(window.Url);
                    var blockedHost = new List <string>();
                    blockedHost.AddRange(Config.Instance.BlockedHosts);
                    blockedHost.Add(url.Host);
                    Config.Instance.BlockedHosts = blockedHost.ToArray();
                    Config.SaveConfig();
                    ApplicationContext.BroadcastConfigChange();
                    window.DisposeWindow();
                }
            };

            window.DownloadClicked += (a, b) =>
            {
                OnDownloadClicked(window, fileName, CommonUtils.SelectedFolderFromIndex(window.SeletedFolderIndex), message, true);
            };

            window.DownloadLaterClicked += (a, b) =>
            {
                OnDownloadClicked(window, fileName, CommonUtils.SelectedFolderFromIndex(window.SeletedFolderIndex), message, false, b.QueueId);
            };

            window.QueueSchedulerClicked += (s, e) =>
            {
                ApplicationContext.Application.ShowQueueWindow(s);
            };

            window.ShowWindow();
        }