Example #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            trayIcon                    = new System.Windows.Forms.NotifyIcon();
            trayIcon.Text               = App.appName;
            trayIcon.Icon               = Properties.Resources.favicon;
            trayIcon.BalloonTipClosed  += TrayIcon_BalloonTipClosed;
            trayIcon.BalloonTipClicked += TrayIcon_BalloonTipClicked;

            timer.Tick    += new EventHandler(Timer_Tick);
            timer.Interval = new TimeSpan(0, 0, 1); //1 sekunda
            timer.Start();

            settings = settings.Load();
            settings.Save();

            Lang.SetLanguage(settings.Language);

            LinksStorage links = new LinksStorage();

            links = links.Load();

            foreach (Link link in links.List)
            {
                DownloadClient item = new DownloadClient(link.Url, link.Directory, link.TotalBytes, link.FileName);
                item.OnDownloadInit         += Client_OnDownloadInit;
                item.OnDownloadCompleted    += Client_OnDownloadCompleted;
                item.OnDownloadError        += Client_OnDownloadError;
                item.OnDownloadStateChanged += Client_OnDownloadStateChanged;
                item.SpeedLimit              = link.SpeedLimit;
                item.Refresh();
                item.LoadIcon();
                listView.Items.Add(item);
            }
        }
Example #2
0
        private void Client_OnDownloadCompleted(DownloadClient item)
        {
            item.LoadIcon();

            CheckQueue();

            if (settings.ShowNotification)
            {
                trayIcon.Visible = true;
                trayIcon.ShowBalloonTip(10, Lang.Translate("lang_download_completed"), item.FileName, System.Windows.Forms.ToolTipIcon.Info);
            }
            if (settings.PlaySound)
            {
                System.Media.SystemSounds.Asterisk.Play();
            }
        }
Example #3
0
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            AddWindow addWindow = new AddWindow();

            addWindow.Owner = this;
            if (addWindow.ShowDialog() == true)
            {
                string dir = addWindow.pathTextBox.Text;
                foreach (string url in addWindow.UrlList)
                {
                    DownloadClient item = new DownloadClient(url, dir);
                    item.SpeedLimit              = settings.SpeedLimit;
                    item.OnDownloadInit         += Client_OnDownloadInit;
                    item.OnDownloadCompleted    += Client_OnDownloadCompleted;
                    item.OnDownloadError        += Client_OnDownloadError;
                    item.OnDownloadStateChanged += Client_OnDownloadStateChanged;

                    if (DownloadClient.ActiveCount < settings.MaxDownloads)
                    {
                        item.Start();
                    }
                    else
                    {
                        item.Queue();
                    }
                    item.Refresh();
                    item.LoadIcon();
                    listView.Items.Add(item);
                }

                //přidáno zpoždění protože z nějakého důvodu ScrollIntoView nefunguje hned po přidání položky
                Task.Delay(20).ContinueWith(t =>
                { //počká 20ms bez blokování současného vlákna
                    Dispatcher.Invoke(() =>
                    {
                        //po 20ms se kód spustí zpět na vlákně rozhraní
                        listView.Focus();
                        listView.SelectedIndex = listView.Items.Count - 1;
                        listView.ScrollIntoView(listView.SelectedItem);
                    });
                });
            }
        }
Example #4
0
 private void Client_OnDownloadInit(DownloadClient item)
 {
     item.LoadIcon();
 }