Exemple #1
0
    }    // END AllowNonEncryptedConnectionsForThisTorrentToolStripMenuItem_Click

    private void mMainListViewRightClickMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e)
    {
        lock (mThreadLock)
        {
            if (mSelectedTorrentId != (TorrentHandle)Torrent.TorrentValues.INVALID_TORRENT)
            {
                bool connectionsMustbeSecure = DllInterface.DoesTorrentOnlyUsesEncryptedConnections(mSelectedTorrentId);
                mMenuItemAllowUnencryptedComs.Checked = !connectionsMustbeSecure;
            }
        }
    }
Exemple #2
0
    }    // END StopAllDownloadsToolStripMenuItem_Click

    private void AllowNonEncryptedConnectionsForThisTorrentToolStripMenuItem_Click(object sender, EventArgs e)
    {
        lock (mThreadLock)
        {
            if (mSelectedTorrentId != (TorrentHandle)Torrent.TorrentValues.INVALID_TORRENT)
            {
                bool connectionsMustbeSecure = DllInterface.DoesTorrentOnlyUsesEncryptedConnections(mSelectedTorrentId);
                DllInterface.SetTorrentOnlyUsesEncryptedConnections(mSelectedTorrentId, !connectionsMustbeSecure);
            }
        }
    }    // END AllowNonEncryptedConnectionsForThisTorrentToolStripMenuItem_Click
Exemple #3
0
    }    // END FindTorrentItemInMainListView

    public void RefreshListView()
    {
        // remove old torrents
        bool removed = false;

        do
        {
            removed = false;
            for (Int32 i = 0; i < mListView.Items.Count; i++)
            {
                TorrentHandle handle = (TorrentHandle)mListView.Items[i].Tag;

                if (torrentManager.GetTorrent(handle) == null)
                {
                    mListView.Items.Remove(mListView.Items[i]);
                    removed = true;
                    break;
                }
            }
        }while(removed == true);


        for (Int32 i = 0; i < torrentManager.TorrentCount; i++)
        {
            Torrent torrent = torrentManager.TorrentAtIndex(i);

            DllInterface.TorrentMetaData meta = torrent.MetaData;


            ListViewItem listViewItem = FindTorrentItemInMainListView(torrent.Handle);
            ListViewItem.ListViewSubItem idItem;
            ListViewItem.ListViewSubItem sizeItem;
            ListViewItem.ListViewSubItem doneItem;
            ListViewItem.ListViewSubItem statusItem;
            ListViewItem.ListViewSubItem seedsItem;
            ListViewItem.ListViewSubItem peersItem;
            ListViewItem.ListViewSubItem downSpeedItem;
            ListViewItem.ListViewSubItem upSpeedItem;
            ListViewItem.ListViewSubItem etaItem;


            bool addToControl = false;
            if (listViewItem == null)
            {
                addToControl = true;
            }

            if (addToControl)
            {
                // create the new item and pass the torrent name, all other details are sub items
                listViewItem = new System.Windows.Forms.ListViewItem(meta.mName);

                idItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(idItem);

                sizeItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(sizeItem);

                doneItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(doneItem);

                statusItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(statusItem);

                seedsItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(seedsItem);

                peersItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(peersItem);

                downSpeedItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(downSpeedItem);

                upSpeedItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(upSpeedItem);

                etaItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(etaItem);

                mListView.Items.AddRange(new System.Windows.Forms.ListViewItem[] { listViewItem });

                // custom data
                listViewItem.Tag = torrent.Handle;
            }
            else
            {
                idItem        = listViewItem.SubItems[1];
                sizeItem      = listViewItem.SubItems[2];
                doneItem      = listViewItem.SubItems[3];
                statusItem    = listViewItem.SubItems[4];
                seedsItem     = listViewItem.SubItems[5];
                peersItem     = listViewItem.SubItems[6];
                downSpeedItem = listViewItem.SubItems[7];
                upSpeedItem   = listViewItem.SubItems[8];
                etaItem       = listViewItem.SubItems[9];
            }

            // set the image depending on if the connection is encrypted or not
            if (DllInterface.DoesTorrentOnlyUsesEncryptedConnections(torrent.Handle))
            {
                // fully encrypted, padlock icon
                listViewItem.ImageIndex = 6;
            }
            else
            {
                // some connections are plain text
                listViewItem.ImageIndex = 7;
            }


            String strNewValue;

            // Name
            if (listViewItem.Text != meta.mName)
            {
                listViewItem.Text = meta.mName;
            }

            strNewValue = torrent.Handle.ToString();
            if (idItem.Text != strNewValue)
            {
                idItem.Text = strNewValue;
            }

            // size
            Int64 totalSize = meta.mTotalSize;
            strNewValue = FormatBytes(totalSize);             //String.Format("{0:0} MB", (totalSize / (1024.0f * 1024.0f)));
            if (sizeItem.Text != strNewValue)
            {
                sizeItem.Text = strNewValue;
            }


            // done
            float onePercent = (meta.mTotalPieces / 100.0f);
            float done       = meta.mPiecesDownloaded / onePercent;
            if (float.IsNaN(done))
            {
                done = 0.0f;
            }
            strNewValue = String.Format("{0:0.0}%", done);
            if (doneItem.Text != strNewValue)
            {
                doneItem.Text = strNewValue;
            }

            // status
            switch (meta.mState)
            {
            case DllInterface.TorrentMetaData.TorrentState.Stopped:
                strNewValue = String.Format("Stopped");
                break;

            case DllInterface.TorrentMetaData.TorrentState.CreateFiles:
                strNewValue = String.Format("Creating Files");
                break;

            case DllInterface.TorrentMetaData.TorrentState.PeerMode:
                strNewValue = String.Format("Downloading");
                break;

            case DllInterface.TorrentMetaData.TorrentState.SeedMode:
                strNewValue = String.Format("Seeding");
                break;

            case DllInterface.TorrentMetaData.TorrentState.Queued:
                strNewValue = String.Format("Queued");
                break;

            case DllInterface.TorrentMetaData.TorrentState.Rechecking:
                strNewValue = String.Format("Checking");
                break;
            }
            if (statusItem.Text != strNewValue)
            {
                statusItem.Text = strNewValue;
            }

            // Seeds
            UInt32 numConnectedSeeds = meta.mNumSeeds;
            //UInt32 totalSeeds = 0;
            //strNewValue = String.Format("{0} ({1})", numConnectedSeeds, totalSeeds);
            strNewValue = String.Format("{0}", numConnectedSeeds);
            if (seedsItem.Text != strNewValue)
            {
                seedsItem.Text = strNewValue;
            }

            // Peers
            UInt32 numConnectedPeers = meta.mNumPeers;
            //UInt32 totalPeers = 0;
            strNewValue = String.Format("{0}", numConnectedPeers);
            if (peersItem.Text != strNewValue)
            {
                peersItem.Text = strNewValue;
            }


            // down speed
            float speed = ((float)meta.mDownloadSpeed / 1024.0f);
            strNewValue = String.Format("{0:0.0} kB/s", speed);
            if (downSpeedItem.Text != strNewValue)
            {
                downSpeedItem.Text = strNewValue;
            }

            // up speed
            speed       = ((float)meta.mUploadSpeed / 1024.0f);
            strNewValue = String.Format("{0:0.0} kB/s", speed);
            if (upSpeedItem.Text != strNewValue)
            {
                upSpeedItem.Text = strNewValue;
            }


            // TODO : if state is done, leave the following field blank...


            // eta
            if (meta.mDownloadSpeed == 0)
            {
                char chInfinity = (char)0x221E;

                strNewValue = String.Format("{0}", chInfinity);
                if (etaItem.Text != strNewValue)
                {
                    etaItem.Text = strNewValue;
                }
            }
            else
            {
                TimeSpan t = TimeSpan.FromSeconds(meta.mEta);
                if (t.Days > 0)
                {
                    strNewValue = string.Format("{0}d {1:D2}h {2:D2}m", t.Days, t.Hours, t.Minutes);
                }
                else if (t.Hours > 0)
                {
                    strNewValue = string.Format("{0}h {1:D2}m", t.Hours, t.Minutes);
                }
                else if (t.Minutes > 0)
                {
                    strNewValue = string.Format("{0} minute", t.Minutes);
                    if (t.Minutes > 1)
                    {
                        strNewValue = strNewValue + "s";
                    }
                }
                else
                {
                    strNewValue = string.Format("{0} seconds", t.Seconds);
                }

                if (etaItem.Text != strNewValue)
                {
                    etaItem.Text = strNewValue;
                }
            }
        }
    }// END RefreshListView