Example #1
0
 /// <summary>Create and initialize the zoom bar control</summary>
 public HathiInspector()
 {
     // Prevent flicker with double buffering and all painting inside WM_PAINT
     SetStyle(ControlStyles.DoubleBuffer |
          ControlStyles.AllPaintingInWmPaint |
          ControlStyles.UserPaint, true);
     // Set initial state
     _borderWidth = 5;
     _barHeight = 29;
     _barSpacing = 3;
     _file = null;
     // recalculate the bars
     Recalculate();
 }
Example #2
0
 public void m_OnNewSharedFile(InterfaceFile file)
 {
     if (OnNewSharedFile!=null) OnNewSharedFile(file);
 }
Example #3
0
 private void SharedToItem(InterfaceFile shared,ListViewItem ItemShared)
 {
     if (shared==null) return;
     if (ItemShared.SubItems[0].Text!=shared.Name) ItemShared.SubItems[0].Text=shared.Name;
     if (ItemShared.SubItems[1].Text!=SizeToString(shared.Size)) ItemShared.SubItems[1].Text=SizeToString(shared.Size);
     if (ItemShared.SubItems[2].Text!=PriorityToString(shared.UploadPriority)) ItemShared.SubItems[2].Text=PriorityToString(shared.UploadPriority);
     ItemShared.Tag=shared;
     ItemShared.ImageIndex=HathiForm.SystemIconsList.GetIconIndexOf(shared.Name);
 }
Example #4
0
 private void m_OnRemovedSharedFile(InterfaceFile shared)
 {
     try
     {
     for (int i=0; i<this.Items.Count; i++)
     {
         if (shared.strHash==((InterfaceFile)Items[i].Tag).strHash)
         {
             Items.RemoveAt(i);
         }
     }
     }
     catch {}
 }
Example #5
0
 private void m_OnNewShared(InterfaceFile shared)
 {
     ListViewItem ItemShared =new ListViewItem(new string[] {"","","",""});
     ItemShared.Tag=shared;
     SharedToItem(shared,ItemShared);
     Items.Add(ItemShared);
 }
Example #6
0
 private void m_OnDeleteFile()
 {
     if (SelectedItems.Count==0) return;
     try
     {
     int SelectedItem = SelectedItems.Count;
     InterfaceFile[] Items= new InterfaceFile[SelectedItem];
     for (int i=0; i!=SelectedItem; i++)
     {
         Items[i] = (InterfaceFile)SelectedItems[i].Tag;
     }
     for (int i=0; i!=SelectedItem; i++)
     {
         if (Items[i].Status!=9) continue;
         string message = String.Format(HathiForm.Globalization["MSG_DELETEFILE"],Items[i].Name);
         if (MessageBox.Show(message,"Hathi",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)==DialogResult.Yes)
         {
             krnGateway.DeleteFile(Items[i].strHash);
             ReloadList(true);
         }
     }
     }
     catch (Exception ex)
     {
     Debug.WriteLine(ex.ToString());
     }
 }
Example #7
0
 private void m_InvokeOnRemovedSharedFile(InterfaceFile file)
 {
     if (this.InvokeRequired)
     this.BeginInvoke(new FileEvent(m_OnRemovedSharedFile),new object[] {file});
     else
     m_OnRemovedSharedFile(file);
 }
Example #8
0
 //      public sFileInfo GetFileInfo(string strFileHash)
 //      {
 //          sFileInfo response=new sFileInfo();
 //          if (apw)
 //          {
 //              CElement Element=(CElement)CKernel.FilesList[CKernel.StringToHash(strFileHash)];
 //              if (Element==null) return response;
 //              response=Element.File.GetInfo();
 //              return response;
 //          }
 //          else return response;
 //      }
 public InterfaceFile[] GetSharedFileList()
 {
     if (apw)
     {
     InterfaceFile[] response=new InterfaceFile[CKernel.FilesList.Count];
     int i=0;
     foreach (CElement Element in CKernel.FilesList.Values)
     {
         if (!Element.File.Empty)
         {
             response[i]=new InterfaceFile();
             response[i]=FileToInterfaceFile(Element);
             i++;
         }
     }
     return response;
     }
     else return null;
 }
Example #9
0
 public virtual void SubmitOnNewFile(InterfaceFile file)
 {
     if (OnNewFile!=null) OnNewFile(file);
 }
Example #10
0
 internal void NewSharedFile(InterfaceFile file)
 {
     if (apw)
     if (file!=null) SubmitOnNewSharedFile(file);
 }
Example #11
0
 internal void RemovedSharedFile(InterfaceFile file)
 {
     if (apw)
     if (file!=null) SubmitOnRemovedSharedFile(file);
 }
Example #12
0
 internal InterfaceFile FileToInterfaceFile(CElement Element)
 {
     if (apw)
     {
     if (Element==null) return null;
     InterfaceFile response=new InterfaceFile();
     response.Name=Element.File.FileName;
     response.CompleteName=Element.File.CompleteName;
     response.Size=Element.File.FileSize;
     response.BytesDownloaded=Element.File.Transferred;
     response.RemainingBytes=Element.File.GetRemainingBytes();
     response.Status=(byte)Element.File.FileStatus;
     response.ChunksStatus=Element.File.ChunksStatus;
     response.UploadPriority=Element.File.UpPriority;
     response.DownloadPriority=Element.File.DownPriority;
     response.Gaps=Element.File.Gaps;
     response.RequestingBlocks=Element.File.RequestingBlocks;
     response.UploadChunksAvaibility=Element.Statistics.UploadAvaibility;
     if (response.ChunksStatus.Length==0)
     {
         response.ChunksStatus=new byte[CHash.GetChunksCount(Element.File.FileSize)];
         for (int i=0; i < response.ChunksStatus.Length; i++)
         {
             response.ChunksStatus[i]=(byte)Protocol.ChunkState.Empty;
         }
     }
     if (Element.SourcesList!=null)
     {
         response.nSources=(ushort)Element.SourcesList.Count();
         response.DownSpeed=Element.SourcesList.GetDownloadSpeed();
         response.ChunksAvaibility=Element.SourcesList.GetChunksAvaibility();
         response.nValidSources=Element.SourcesList.GetUsableClients();
         response.nTransferringSources=Element.SourcesList.GetDownloadingClients();
     }
     else
     {
         response.DownSpeed=0;
         response.nSources=0;
     }
     response.strHash=CKernel.HashToString(Element.File.FileHash);
     if (response.Size!=0)
         response.PercentCompleted=(decimal)(response.Size-response.RemainingBytes)/response.Size;
     else
         response.PercentCompleted=0;
     response.CategoryID=Element.File.CategoryID;
     if (Element.File.FileStatus!=Protocol.FileState.Complete)
         response.Category=CKernel.CategoriesList[Element.File.CategoryID];
     else
         response.Category="";
     return response;
     }
     else return null;
 }
Example #13
0
 private void showInfo(InterfaceFile file)
 {
     sFileDetails FileInfo = (sFileDetails)krnGateway.GetFileDetails(file.strHash);
     this.tx_fileName.Text = file.Name;
     this.tx_completeName.Text = file.CompleteName;
     switch ((byte)FileInfo.Type)
     {
         case ((byte)Constants.FileType.Avi):
             FAviDetails.ShowData((Hashtable)FileInfo.ListDetails);
             FAviDetails.Show();
             break;
         default:
             FAviDetails.Hide();
             break;
     }
 }
Example #14
0
 private void m_RefreshStatistics(InterfaceFile file)
 {
     FileStatistics fstatistics = krnGateway.GetFileStatistics(file.strHash);
     labelSessionDownloadedRes.Text = HathiListView.SizeToString((uint)fstatistics.SessionDownload);
     labelSessionUploadedRes.Text = HathiListView.SizeToString((uint)fstatistics.SessionUpload);
     labelSessionRequestsRes.Text = fstatistics.SessionRequests.ToString();
     byte rating = 0;
     string comment = "";
     krnGateway.GetFileComment(file.strHash, ref comment, ref rating);
     this.textBoxComment.Text = comment;
 }
Example #15
0
 public void m_OnRemovedSharedFile(InterfaceFile file)
 {
     if (OnRemovedSharedFile!=null) OnRemovedSharedFile(file);
 }
Example #16
0
 public virtual void SubmitOnRemovedSharedFile(InterfaceFile file)
 {
     if (OnRemovedSharedFile!=null) OnRemovedSharedFile(file);
 }
Example #17
0
 private void CalculateFilterSummary(InterfaceFile[] files)
 {
     ResetFiterSummary();
     string category;
     int i=0;
     bool isCategoryFiltered;
     InterfaceFile file;
     while (i<files.Length)
     {
     file=files[i];
     i++;
     if (file==null) continue;
     category="";
     switch (file.Status)
     {
     case 0:
     case 8:
     case 9:
         category="Started";
         break;
     case 1:
     case 2:
         category="Stopped";
         break;
     }
     CFilterSummary filterSummary;
     isCategoryFiltered=false;
     if (CurrentCategoryFilter=="LBL_VIDEO")
         isCategoryFiltered=(!CUtils.IsVideo(file.Name));
     else if (CurrentCategoryFilter=="LBL_AUDIO")
         isCategoryFiltered=(!CUtils.IsAudio(file.Name));
     else if (CurrentCategoryFilter=="LBL_FILE")
         isCategoryFiltered=(!CUtils.IsFile(file.Name));
     else isCategoryFiltered=((CurrentCategoryFilter.Length!=0)&&(CurrentCategoryFilter!=file.Category));
     if (!isCategoryFiltered)
     {
         if (category.Length>0)
         {
             filterSummary=((CFilterSummary)FilterSummary[category]);
             filterSummary.TotalSize+=file.Size/1024/1024;
             filterSummary.Items++;
         }
         filterSummary=((CFilterSummary)FilterSummary["All"]);
         filterSummary.TotalSize+=file.Size/1024/1024;
         filterSummary.Items++;
     }
     }
     if (OnSummaryFilterChanged!=null) OnSummaryFilterChanged(this,null);
 }
Example #18
0
 /// <summary>
 /// Paint a InterfaceFile chunk to any graphics
 /// </summary>
 /// <param name="file"></param>
 /// <param name="g"></param>
 /// <param name="rec"></param>
 /// <param name="PercentBar"></param>
 public static void DrawBar(InterfaceFile file, Graphics g, Rectangle rec, bool PercentBar, bool PercentNumber)
 {
     Rectangle barRect;
     Color end;
     LinearGradientBrush chunkBrush;
     // fill background with white
     //SolidBrush white = new SolidBrush(Color.White);
     //g.FillRectangle(white, rec);
     barRect = new Rectangle(rec.Left, rec.Top, rec.Width, rec.Height);
     //SolidBrush b = new SolidBrush(Color.Red);
     Color b=Color.Red;
     int xpos = barRect.Left;//this.HeaderLeft[column];
     //if (xpos==0) xpos = barRect.Left;
     int ChunkLength;
     for (int i = 0; i < file.ChunksStatus.Length; i++)
     {
     //ChunkLength=(int)Decimal.Round((decimal)(this.HeaderRight[column]-xpos)/(decimal)(file.ChunksStatus.Length-i),0);
     ChunkLength = (int)Decimal.Round((decimal)(barRect.Right-xpos)/(decimal)(file.ChunksStatus.Length-i),0);
     switch (file.ChunksStatus[i])
     {
     case 3: //if completed : green else black
         if (file.Status==9)
             b=System.Drawing.Color.Green;//Color.FromArgb(82, 246, 91);
         else
             b=Color.Black;
         break;
     case 0:
         b=Color.Red;
         break;
     case 1:
         b=Color.Gray;
         break;
     case 2:
         b=Color.LightGray;
         break;
     default:
         b=Color.Red;
         break;
     }
     if ((file.ChunksStatus[i]==0)&&(file.ChunksAvaibility!=null)&&(file.ChunksAvaibility[i]>0))
     {
         int col=file.ChunksAvaibility[i]*4;
         if (col>200) col=200;
         col=Math.Abs(200-col);
         b=Color.FromArgb(255,col,col,255);
     }
     try
     {
         if (ChunkLength<=0) continue;
         // calculate the new end color based on start color
         end = ControlPaint.Dark(b, 0.3F);
         // generate the linear brush
         chunkBrush = new LinearGradientBrush(new Rectangle(xpos, barRect.Top, ChunkLength, barRect.Height), b, end, 90);
         g.FillRectangle(chunkBrush, xpos, barRect.Top, ChunkLength, barRect.Height);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
     }
     xpos += ChunkLength;
     }
     decimal percent = file.PercentCompleted;
     if (PercentBar)
     {
     int CompleteChunkLength = (int)(percent*(rec.Right-rec.Left));
     Pen myProgressBarPen = new Pen(Color.FromArgb(82, 246, 91),2);
     g.DrawLine(myProgressBarPen,rec.Left,rec.Top+1,rec.Left+CompleteChunkLength,rec.Top+1);
     }
     if (PercentNumber)
     {
     g.DrawString(((byte)(percent*100)).ToString()+ " %",new System.Drawing.Font("Microsoft Sans Serif",7.25F,GraphicsUnit.Point),new SolidBrush(Color.White),barRect);
     }
 }