Пример #1
0
//static
FileOperation* FileOperation::trashFiles(FmPathList* srcFiles, bool prompt, QWidget* parent) {
  if(prompt) {
    int result = QMessageBox::warning(parent, tr("Confirm"),
                                      tr("Do you want to move the selected files to trash can?"),
                                      QMessageBox::Yes|QMessageBox::No,
                                      QMessageBox::No);
    if(result != QMessageBox::Yes)
      return NULL;
  }

  FileOperation* op = new FileOperation(FileOperation::Trash, srcFiles);
  op->run();
  return op;
}
Пример #2
0
void traverse(FileOperation& file_op, const int32_t offset, const int32_t items, std::vector<FileInfoV2>& infos)
{
  int ret = TFS_SUCCESS;
  FileInfoV2 file_info;
  for (int i = 0; i < items; i++)
  {
    ret = file_op.pread((char*)(&file_info), FILE_INFO_V2_LENGTH,
        offset + i * FILE_INFO_V2_LENGTH);
    if (FILE_INFO_V2_LENGTH == ret)
    {
      if (INVALID_FILE_ID != file_info.id_)
      {
        // dump_file_info(file_info, i);
        infos.push_back(file_info);
      }
    }
    else
    {
      printf("file %s format error\n", file_op.get_path().c_str());
      break;
    }
  }
}
Пример #3
0
void dump_all_file_infos(FileOperation& file_op, const int32_t offset, const int32_t items)
{
  int ret = TFS_SUCCESS;
  dump_file_info_header();
  FileInfoV2 file_info;
  for (int i = 0; i < items; i++)
  {
    ret = file_op.pread((char*)(&file_info), FILE_INFO_V2_LENGTH,
        offset + i * FILE_INFO_V2_LENGTH);
    if (FILE_INFO_V2_LENGTH == ret)
    {
      if (INVALID_FILE_ID != file_info.id_)
      {
        dump_file_info(file_info, i);
        while (file_info.next_ != 0)
        {
          int32_t slot = file_info.next_;
          ret = file_op.pread((char*)(&file_info), FILE_INFO_V2_LENGTH,
              offset + slot * FILE_INFO_V2_LENGTH);
          if (FILE_INFO_V2_LENGTH == ret)
          {
            dump_file_info(file_info, slot);
          }
          else
          {
            break;
          }
        }
      }
    }
    else
    {
      break;
    }
  }
}
Пример #4
0
void FilePropsDialog::accept() {

  // applications
  if(mimeType && ui->openWith->isChanged()) {
    GAppInfo* currentApp = ui->openWith->selectedApp();
    g_app_info_set_as_default_for_type(currentApp, fm_mime_type_get_type(mimeType), NULL);
  }

  // check if chown or chmod is needed
  guint32 newUid = uidFromName(ui->owner->text());
  guint32 newGid = gidFromName(ui->ownerGroup->text());
  bool needChown = (newUid != -1 && newUid != uid) || (newGid != -1 && newGid != gid);

  int newOwnerPermSel = ui->ownerPerm->currentIndex();
  int newGroupPermSel = ui->groupPerm->currentIndex();
  int newOtherPermSel = ui->otherPerm->currentIndex();
  Qt::CheckState newExecCheckState = ui->executable->checkState();
  bool needChmod = ((newOwnerPermSel != ownerPermSel) ||
                    (newGroupPermSel != groupPermSel) ||
                    (newOtherPermSel != otherPermSel) ||
                    (newExecCheckState != execCheckState));

  if(needChmod || needChown) {
    FmPathList* paths = fm_path_list_new_from_file_info_list(fileInfos_);
    FileOperation* op = new FileOperation(FileOperation::ChangeAttr, paths);
    fm_path_list_unref(paths);
    if(needChown) {
      // don't do chown if new uid/gid and the original ones are actually the same.
      if(newUid == uid)
        newUid = -1;
      if(newGid == gid)
        newGid = -1;
      op->setChown(newUid, newGid);
    }
    if(needChmod) {
      mode_t newMode = 0;
      mode_t newModeMask = 0;
      // FIXME: we need to make sure that folders with "r" permission also have "x"
      // at the same time. Otherwise, it's not able to browse the folder later.
      if(newOwnerPermSel != ownerPermSel && newOwnerPermSel != ACCESS_NO_CHANGE) {
        // owner permission changed
        newModeMask |= (S_IRUSR|S_IWUSR); // affect user bits
        if(newOwnerPermSel == ACCESS_READ_ONLY)
          newMode |= S_IRUSR;
        else if(newOwnerPermSel == ACCESS_READ_WRITE)
          newMode |= (S_IRUSR|S_IWUSR);
      }
      if(newGroupPermSel != groupPermSel && newGroupPermSel != ACCESS_NO_CHANGE) {
        qDebug("newGroupPermSel: %d", newGroupPermSel);
        // group permission changed
        newModeMask |= (S_IRGRP|S_IWGRP); // affect group bits
        if(newGroupPermSel == ACCESS_READ_ONLY)
          newMode |= S_IRGRP;
        else if(newGroupPermSel == ACCESS_READ_WRITE)
          newMode |= (S_IRGRP|S_IWGRP);
      }
      if(newOtherPermSel != otherPermSel && newOtherPermSel != ACCESS_NO_CHANGE) {
        // other permission changed
        newModeMask |= (S_IROTH|S_IWOTH); // affect other bits
        if(newOtherPermSel == ACCESS_READ_ONLY)
          newMode |= S_IROTH;
        else if(newOtherPermSel == ACCESS_READ_WRITE)
          newMode |= (S_IROTH|S_IWOTH);
      }
      if(newExecCheckState != execCheckState && newExecCheckState != Qt::PartiallyChecked) {
        // executable state changed
        newModeMask |= (S_IXUSR|S_IXGRP|S_IXOTH);
        if(newExecCheckState == Qt::Checked)
          newMode |= (S_IXUSR|S_IXGRP|S_IXOTH);
      }
      op->setChmod(newMode, newModeMask);

      if(hasDir) { // if there are some dirs in our selected files
        QMessageBox::StandardButton r = QMessageBox::question(this,
                                          tr("Apply changes"),
                                          tr("Do you want to recursively apply these changes to all files and sub-folders?"),
                                          QMessageBox::Yes|QMessageBox::No);
        if(r == QMessageBox::Yes)
          op->setRecursiveChattr(true);
      }
    }
    op->setAutoDestroy(true);
    op->run();
  }

  QDialog::accept();
}
Пример #5
0
// static
FileOperation* FileOperation::changeAttrFiles(FmPathList* srcFiles, QWidget* parent) {
  //TODO
  FileOperation* op = new FileOperation(FileOperation::ChangeAttr, srcFiles);
  op->run();
  return op;
}
Пример #6
0
//static
FileOperation* FileOperation::unTrashFiles(FmPathList* srcFiles, QWidget* parent) {
  FileOperation* op = new FileOperation(FileOperation::UnTrash, srcFiles);
  op->run();
  return op;
}
Пример #7
0
//static
FileOperation* FileOperation::symlinkFiles(FmPathList* srcFiles, FmPath* dest, QWidget* parent) {
  FileOperation* op = new FileOperation(FileOperation::Link, srcFiles);
  op->setDestination(dest);
  op->run();
  return op;
}