示例#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);
            }
        }
示例#2
0
 private void Client_OnDownloadStateChanged(DownloadClient item, States oldState, States newState)
 {
     if (newState != States.Error)
     {
         item.Refresh();
         listView.Items.Refresh();
         if (oldState == States.Error)
         {
             item.ErrorMsg = null;
         }
     }
 }
示例#3
0
        private void MenuItemLimit_Click(object sender, RoutedEventArgs e) //Omezit rychlost
        {
            DownloadClient item = lastItem;

            BandwidthWindow bandwidthWindow = new BandwidthWindow();

            bandwidthWindow.textBox.Text = (item.SpeedLimit / 1024).ToString();
            bandwidthWindow.Owner        = this;
            if (bandwidthWindow.ShowDialog() == true)
            {
                item.SpeedLimit = Int64.Parse(bandwidthWindow.textBox.Text) * 1024;
                item.Refresh();
                listView.Items.Refresh();
            }
        }
示例#4
0
        private void MenuItemRename_Click(object sender, RoutedEventArgs e) //Přejmenovat
        {
            DownloadClient item = lastItem;

            if (item.FileName == "")
            {
                return;
            }

            RenameWindow renameWindow = new RenameWindow(item);

            renameWindow.Owner = this;

            if (renameWindow.ShowDialog() == true)
            {
                item.Refresh();
                listView.Items.Refresh();
            }
        }
示例#5
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);
                    });
                });
            }
        }
示例#6
0
        private void Client_OnDownloadError(DownloadClient item, string message)
        {
            item.ErrorMsg = message;
            item.Refresh();
            listView.Items.Refresh();

            CheckQueue();


            if (settings.ShowNotification)
            {
                trayIcon.Visible = true;
                trayIcon.ShowBalloonTip(10, Lang.Translate("lang_error"), message, System.Windows.Forms.ToolTipIcon.Error);
            }
            if (settings.PlaySound)
            {
                System.Media.SystemSounds.Hand.Play();
            }
        }