Ejemplo n.º 1
0
        private void BtnUp_Clicked(object?sender, EventArgs e)
        {
            var indices = GtkHelper.GetSelectedIndices(lvFiles);

            if (indices.Length > 0 && indices[0] > 0)
            {
                var ent = GtkHelper.GetValueAt <InProgressDownloadItem>(lvFiles, indices[0] - 1, 3);
                if (ent == null)
                {
                    return;
                }
                var index = indices[indices.Length - 1];
                GtkHelper.RemoveAt(filesListStore, indices[0] - 1);
                filesListStore.InsertWithValues(index, ent.Name,
                                                FormattingHelper.FormatSize(ent.Size), ent.Status.ToString(), ent);
            }
            //var indices = GtkHelper.getse lvFiles.GetSelectedIndices();
            //if (indices.Length > 0 && indices[0] > 0)
            //{
            //    var item = this.downloads[indices[0] - 1];
            //    var index = indices[indices.Length - 1];
            //    this.downloads.Remove(item);
            //    this.downloads.Insert(index, item);
            //    //var index1 = indices[0] - 1;
            //    //var index2 = indices[0] + lvFiles.SelectedItems.Count - 1;
            //    //var value = this.downloads[index1];
            //    //this.downloads.RemoveAt(index1);
            //    //this.downloads.Insert(index2, value);
            //}
        }
Ejemplo n.º 2
0
        private void UpdateProgressOnUI(string id, int progress, double speed, long eta)
        {
            var downloadEntry = ApplicationContext.MainWindow.FindInProgressItem(id);

            if (downloadEntry != null)
            {
                downloadEntry.Progress      = progress;
                downloadEntry.DownloadSpeed = FormattingHelper.FormatSize(speed) + "/s";
                downloadEntry.ETA           = FormattingHelper.ToHMS(eta);
            }
        }
Ejemplo n.º 3
0
 public void ShowPropertiesDialog(DownloadItemBase ent, ShortState?state)
 {
     using var propWin    = PropertiesDialog.CreateFromGladeFile(GetMainWindow(), GetWindowGroup());
     propWin.FileName     = ent.Name;
     propWin.Folder       = ent.TargetDir ?? FileHelper.GetDownloadFolderByFileName(ent.Name);
     propWin.Address      = ent.PrimaryUrl;
     propWin.FileSize     = FormattingHelper.FormatSize(ent.Size);
     propWin.DateAdded    = ent.DateAdded.ToLongDateString() + " " + ent.DateAdded.ToLongTimeString();
     propWin.DownloadType = ent.DownloadType;
     propWin.Referer      = ent.RefererUrl;
     propWin.Cookies      = state?.Cookies ?? state?.Cookies1 ?? new Dictionary <string, string>();
     propWin.Headers      = state?.Headers ?? state?.Headers1 ?? new Dictionary <string, List <string> >();
     propWin.Run();
     propWin.Destroy();
     propWin.Dispose();
 }
Ejemplo n.º 4
0
        private void BtnDown_Clicked(object?sender, EventArgs e)
        {
            var indices = GtkHelper.GetSelectedIndices(lvFiles);

            if (indices.Length > 0 && indices[indices.Length - 1] < this.filesListStore.IterNChildren() - 1)
            {
                var index = indices[indices.Length - 1] + 1;
                var ent   = GtkHelper.GetValueAt <InProgressDownloadItem>(lvFiles, index, 3);
                if (ent == null)
                {
                    return;
                }
                GtkHelper.RemoveAt(filesListStore, index);
                filesListStore.InsertWithValues(indices[0], ent.Name,
                                                FormattingHelper.FormatSize(ent.Size), ent.Status.ToString(), ent);
            }
        }
Ejemplo n.º 5
0
        public void ShowPropertiesDialog(DownloadItemBase ent, ShortState?state)
        {
            var propertiesWindow = new DownloadPropertiesWindow
            {
                FileName     = ent.Name,
                Folder       = ent.TargetDir ?? FileHelper.GetDownloadFolderByFileName(ent.Name),
                Address      = ent.PrimaryUrl,
                FileSize     = FormattingHelper.FormatSize(ent.Size),
                DateAdded    = ent.DateAdded.ToLongDateString() + " " + ent.DateAdded.ToLongTimeString(),
                DownloadType = ent.DownloadType,
                Referer      = ent.RefererUrl,
                Cookies      = state?.Cookies ?? state?.Cookies1 ?? new Dictionary <string, string>(),
                Headers      = state?.Headers ?? state?.Headers1 ?? new Dictionary <string, List <string> >(),
                Owner        = GetMainWindow()
            };

            propertiesWindow.ShowDialog(GetMainWindow());
        }
Ejemplo n.º 6
0
        public void RefreshView()
        {
            if (GtkHelper.GetSelectedValue <DownloadQueue>(LbQueues, 1) is DownloadQueue queue)
            {
                filesListStore.Clear();
                var realQueue = QueueManager.GetQueue(queue.ID);

                if (realQueue != null)
                {
                    foreach (var id in realQueue.DownloadIds)
                    {
                        var ent = ApplicationContext.Application.GetInProgressDownloadEntry(id);
                        if (ent != null)
                        {
                            filesListStore.AppendValues(ent.Name, FormattingHelper.FormatSize(ent.Size), ent.Status.ToString(), ent);
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void LoadQueueDetails(DownloadQueue queue)
        {
            lvFiles.Selection.UnselectAll();
            filesListStore.Clear();
            foreach (var id in queue.DownloadIds)
            {
                var ent = ApplicationContext.Application.GetInProgressDownloadEntry(id);
                if (ent != null)
                {
                    filesListStore.AppendValues(ent.Name, FormattingHelper.FormatSize(ent.Size), ent.Status.ToString(), ent);
                }
            }

            if (queue.Schedule.HasValue)
            {
                this.SchedulerPanel.Schedule = queue.Schedule.Value;
            }
            else
            {
                this.SchedulerPanel.Schedule = this.defaultSchedule;
            }
            ChkEnableScheduler.Active = queue.Schedule.HasValue;
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
0
        private NewQueueDialog(Builder builder,
                               Window parent,
                               WindowGroup group,
                               Action <DownloadQueue, bool> okAction,
                               DownloadQueue?modifyingQueue) : base(builder.GetRawOwnedObject("dialog"))
        {
            builder.Autoconnect(this);

            Modal = true;
            SetPosition(WindowPosition.CenterAlways);
            TransientFor = parent;
            this.group   = group;
            this.group.AddWindow(this);
            GtkHelper.AttachSafeDispose(this);
            LoadTexts();
            Title = TextResource.GetText("LBL_QUEUE_OPT1");
            SetDefaultSize(640, 480);
            BtnCancel.Clicked += BtnCancel_Clicked;
            BtnOK.Clicked     += BtnOK_Clicked;

            this.listStore = new ListStore(
                typeof(bool), typeof(string),
                typeof(string), typeof(string),
                typeof(string), typeof(InProgressEntryWrapper));

            this.lvDownloads.Model = this.listStore;

            var fileNameColumn = new TreeViewColumn
            {
                Resizable   = true,
                Reorderable = false,
                Title       = TextResource.GetText("SORT_NAME"),
                Sizing      = TreeViewColumnSizing.Fixed,
                FixedWidth  = 200
            };

            var checkboxRenderer = new CellRendererToggle {
            };

            checkboxRenderer.Toggled += CheckboxRenderer_Toggled;
            fileNameColumn.PackStart(checkboxRenderer, false);
            fileNameColumn.SetAttributes(checkboxRenderer, "active", 0);

            var fileNameRendererText = new CellRendererText();

            fileNameColumn.PackStart(fileNameRendererText, false);
            fileNameColumn.SetAttributes(fileNameRendererText, "text", 1);
            this.lvDownloads.AppendColumn(fileNameColumn);

            var dateColumn = new TreeViewColumn
            {
                Resizable   = true,
                Reorderable = false,
                Title       = TextResource.GetText("SORT_DATE"),
                Sizing      = TreeViewColumnSizing.Fixed,
                FixedWidth  = 150
            };
            var dateRendererText = new CellRendererText();

            dateColumn.PackStart(dateRendererText, false);
            dateColumn.SetAttributes(dateRendererText, "text", 2);
            this.lvDownloads.AppendColumn(dateColumn);

            var sizeColumn = new TreeViewColumn
            {
                Resizable   = true,
                Reorderable = false,
                Title       = TextResource.GetText("SORT_SIZE"),
                Sizing      = TreeViewColumnSizing.Fixed,
                FixedWidth  = 150
            };
            var sizeRendererText = new CellRendererText();

            sizeColumn.PackStart(sizeRendererText, false);
            sizeColumn.SetAttributes(sizeRendererText, "text", 3);
            this.lvDownloads.AppendColumn(sizeColumn);

            var statusColumn = new TreeViewColumn
            {
                Resizable   = true,
                Reorderable = false,
                Title       = TextResource.GetText("SORT_STATUS"),
                Sizing      = TreeViewColumnSizing.Fixed,
                FixedWidth  = 150
            };
            var statusRendererText = new CellRendererText();

            statusColumn.PackStart(statusRendererText, false);
            statusColumn.SetAttributes(statusRendererText, "text", 4);
            this.lvDownloads.AppendColumn(statusColumn);

            this.okAction = okAction;
            if (modifyingQueue == null)
            {
                this.TxtQueueName.Text = "New queue #" + QueueManager.QueueAutoNumber;
                QueueManager.QueueAutoNumber++;
            }
            else
            {
                this.TxtQueueName.Text = modifyingQueue.Name;
                this.modifyingQueue    = modifyingQueue;
            }

            var set = new HashSet <string>();

            foreach (var queue in QueueManager.Queues)
            {
                foreach (var id in queue.DownloadIds)
                {
                    set.Add(id);
                }
            }

            foreach (var ent in ApplicationContext.Application.GetAllInProgressDownloads().Select(x => new EntryWrapper {
                Entry = x
            }))
            {
                if (!set.Contains(ent.Entry.Id))
                {
                    listStore.AppendValues(false,
                                           ent.Entry.Name,
                                           ent.Entry.DateAdded.ToShortDateString() + " " + ent.Entry.DateAdded.ToShortTimeString(),
                                           FormattingHelper.FormatSize(ent.Entry.Size),
                                           ent.Entry.Status.ToString(),
                                           ent);
                }
            }

            ChkSelectAll.Toggled += ChkSelectAll_Toggled;
        }
Ejemplo n.º 10
0
        public static void ShowVideoDownloadDialog(INewVideoDownloadDialog window,
                                                   string id, string name, long size, string?contentType)
        {
            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;
                }
            }
            //window.SeletedFolderIndex = Config.Instance.FolderSelectionMode == FolderSelectionMode.Auto ? 0 : 2;
            window.SelectedFileName = FileHelper.SanitizeFileName(name);
            window.FileSize         = FormattingHelper.FormatSize(size);

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

            if (!string.IsNullOrEmpty(contentType))
            {
                var mime = contentType !.ToLowerInvariant();
                if (mime.StartsWith("audio"))
                {
                    if (!(mime.Contains("mpeg") || mime.Contains("mp3")))
                    {
                        window.ShowMp3Checkbox = true;
                    }
                }
            }

            window.DownloadClicked += (a, b) =>
            {
                if (string.IsNullOrEmpty(window.SelectedFileName))
                {
                    window.ShowMessageBox(TextResource.GetText("MSG_NO_FILE"));
                    return;
                }
                if (ApplicationContext.VideoTracker.IsFFmpegRequiredForDownload(id) && !IsFFmpegInstalled())
                {
                    if (ApplicationContext.Application.Confirm(window, TextResource.GetText("MSG_DOWNLOAD_FFMPEG")))
                    {
                        ApplicationContext.Application.InstallLatestFFmpeg();
                    }
                    return;
                }
                var name = FileHelper.SanitizeFileName(window.SelectedFileName);
                if (window.IsMp3CheckboxChecked)
                {
                    name = AddMp3Extension(name);
                }
                ApplicationContext.VideoTracker.StartVideoDownload(id, name,
                                                                   CommonUtils.SelectedFolderFromIndex(window.SeletedFolderIndex),
                                                                   true,
                                                                   window.Authentication,
                                                                   window.Proxy ?? Config.Instance.Proxy,
                                                                   window.EnableSpeedLimit ? window.SpeedLimit : 0,
                                                                   null,
                                                                   window.IsMp3CheckboxChecked);
                window.DisposeWindow();
            };

            window.DownloadLaterClicked += (a, b) =>
            {
                if (string.IsNullOrEmpty(window.SelectedFileName))
                {
                    window.ShowMessageBox(TextResource.GetText("MSG_NO_FILE"));
                    return;
                }
                var name = FileHelper.SanitizeFileName(window.SelectedFileName);
                if (window.IsMp3CheckboxChecked)
                {
                    name = AddMp3Extension(name);
                }
                ApplicationContext.VideoTracker.StartVideoDownload(id, name,
                                                                   CommonUtils.SelectedFolderFromIndex(window.SeletedFolderIndex),
                                                                   false,
                                                                   window.Authentication,
                                                                   window.Proxy ?? Config.Instance.Proxy,
                                                                   window.EnableSpeedLimit ? window.SpeedLimit : 0,
                                                                   b.QueueId,
                                                                   window.IsMp3CheckboxChecked);
                window.DisposeWindow();
            };

            //window.CancelClicked += (a, b) =>
            //{
            //    window.DisposeWindow();
            //};

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

            window.ShowWindow();
        }