void TFileAttachmentWidget::addContactCard(const Contact& contact)
{
  bool sortEnabled = FreezeAttachmentTable();

  QString displayName = contact.get_display_name().c_str() + QString(".vcf");
  //replace illegal characters in the file
  displayName.replace("<", "(");
  displayName.replace(">", ")");
  QFileInfo fileInfo(displayName);
  //delete object in the TFileAttachmentItem destructor
  QByteArray* vCardData = new QByteArray();
  ContactvCard::convert(contact/*in*/, vCardData/*out*/);

  AttachmentIndex.push_back(fileInfo);

  TScaledSize scaledSize = ScaleAttachmentSize(vCardData->size());

  /// Allocate objects representing table items - name item automatically will register in the list.
  TFileAttachmentItem* fileNameItem = new TFileAttachmentItem(fileInfo, this, vCardData);
  TFileAttachmentItem* fileSizeItem = new TFileAttachmentItem(fileNameItem, scaledSize);
  AddAttachmentItems(fileNameItem, fileSizeItem);

  UnFreezeAttachmentTable(sortEnabled);

  UpdateColumnHeaders();
  emit attachmentListChanged();
}
void TFileAttachmentWidget::onDelTriggered()
  {
  TSelection selection;
  RetrieveSelection(&selection);

  bool sortEnabled = FreezeAttachmentTable();

  int row_no = 0;

  for(AAttachmentItem* item : selection)
    {
    item->Unregister();
    int rowNo = item->row();
    ui->attachmentTable->removeRow(rowNo);
    row_no = rowNo;
    }

  if(row_no < ui->attachmentTable->rowCount())
    ui->attachmentTable->selectRow(row_no);
  else
    ui->attachmentTable->selectRow(row_no-1);

  UnFreezeAttachmentTable(sortEnabled);

  UpdateColumnHeaders();

  ui->attachmentTable->setFocus();
  
  emit attachmentListChanged();
  }
void TFileAttachmentWidget::addFiles(const QStringList& files)
  {
  if (files.isEmpty())
    return;

  bool sortEnabled = FreezeAttachmentTable();

  for(QStringList::const_iterator fileNameIt = files.constBegin();
      fileNameIt != files.constEnd(); ++fileNameIt)
    {
    const QString& fileName = *fileNameIt;

    ///probably it will be wrong strip unicode chars: .toLocal8Bit().constData());
    QFileInfo fileInfo(fileName);
    if(fileInfo.exists() == false)
      continue;

    /** Ignore redundant files (it was originally implemented this way) but others mail clients
        allow this.
    */
    TFileInfoList::const_iterator foundPos = std::find(AttachmentIndex.begin(),
      AttachmentIndex.end(), fileInfo);
    if(foundPos != AttachmentIndex.end())
      continue;
    
    AttachmentIndex.push_back(fileInfo);

    unsigned long long size = fileInfo.size();
    TScaledSize scaledSize = ScaleAttachmentSize(size);

    /// Allocate objects representing table items - name item automatically will register in the list.
    TFileAttachmentItem* fileNameItem = new TFileAttachmentItem(fileInfo, this);
    TFileAttachmentItem* fileSizeItem = new TFileAttachmentItem(fileNameItem, scaledSize);
    AddAttachmentItems(fileNameItem, fileSizeItem);
    }
  
  UnFreezeAttachmentTable(sortEnabled);
  
  UpdateColumnHeaders();

  emit attachmentListChanged();
  }
void TFileAttachmentWidget::onDelTriggered()
  {
  TSelection selection;
  RetrieveSelection(&selection);

  bool sortEnabled = FreezeAttachmentTable();

  for(AAttachmentItem* item : selection)
    {
    item->Unregister();
    int rowNo = item->row();
    ui->attachmentTable->removeRow(rowNo);
    }

  UnFreezeAttachmentTable(sortEnabled);

  UpdateColumnHeaders();
  
  emit attachmentListChanged();
  }
void TFileAttachmentWidget::LoadAttachedFiles(const TAttachmentContainer& attachedFiles)
  {
  bool sortEnabled = FreezeAttachmentTable();

  for(const TPhysicalAttachment& a : attachedFiles)
    {
    size_t size = a.body.size();
    uchar  *imageData = (uchar*)a.body.data ();
    TImage image;
    image.loadFromData(imageData, size);

    TScaledSize scaledSize = ScaleAttachmentSize(size);

    /// Allocate objects representing table items - name item automatically will register in the list.
    TVirtualAttachmentItem* fileNameItem = new TVirtualAttachmentItem(a, this);
    TVirtualAttachmentItem* fileSizeItem = new TVirtualAttachmentItem(fileNameItem, scaledSize);
    fileNameItem->setToolTip( image.toHtml() );
    AddAttachmentItems(fileNameItem, fileSizeItem);
    }

  UnFreezeAttachmentTable(sortEnabled);
  
  UpdateColumnHeaders();
  }