FXbool FXRemoveFiles::remove(const FXString& path){
  FXbool result;
  FXStat stat;

  send_filename(path);

  result = FXStat::statLink(path,stat);
  if (!result)
    result = FXStat::statFile(path,stat);

  if (result) {
    if(stat.isDirectory()){
      FXDir dir(path);
      FXString name;
      while(dir.next() && running){
        name=dir.name();
        if(name[0]=='.' && (name[1]=='\0' || (name[1]=='.' && name[2]=='\0'))) continue;
        if(!remove(path+PATHSEP+name) && !ignore) return FALSE;
        }
      if (ignore) {
        FXDir::remove(path);
        return TRUE;
        }
      else if (FXDir::remove(path)==FALSE){
        queryDelete(path);
        if (ignore==FALSE) return FALSE;
        }
      return TRUE;
      }
    if (ignore) {
      FXFile::remove(path);
      return TRUE;
      }
    if (!FXFile::remove(path)) {
      queryDelete(path);
      if (ignore==FALSE) return FALSE;
      }
    return TRUE;
    }
  return FALSE;
  }
示例#2
0
bool ProfileDB::removeProfile(int profileID)
{
    bool success = false;

    if (profileExists(profileID))
    {
        QSqlQuery queryDelete(QSqlDatabase::database(connectionName));
        queryDelete.prepare("DELETE FROM Profiles WHERE ProfileID = (:ProfileID)");
        queryDelete.bindValue(":ProfileID", profileID);
        success = queryDelete.exec();

        if(!success)
        {
            //qDebug() << "remove profile failed: " << queryDelete.lastError();
        }
    }
    else
    {
        //qDebug() << "remove profile failed: profile doesnt exist";
    }

    return success;
}
bool UsersGroupsManager::remove_elements() {
    /** METHOD TO REMOVE A LINK BETWEEN GROUPS AND STUDENTS **/
    //Get current selection
    QList<QListWidgetItem*> selection = ui->list_yes->selectedItems();
    bool browseStd = (ui->comboBox_browse->currentData().toInt() == BrowseStudents);

    //Error if no group selected
    if(selection.length() <= 0) {
        QMessageBox::critical(this, "Erreur", "Veuillez sélectionner un item.");
        return false;
    }

    // Prepare the query (to make only one global query)
    QString queryStr = "DELETE FROM tau_groups_users WHERE ";
    QMap<QString, qulonglong> bindValuesMap;

    /// Get selected elements in linking lists
    for(int i=0; i<selection.count(); i++) {
        QListWidgetItem* itemFromYes = selection.at(i);
        QListWidgetItem* itemFromBrowse = ui->list_browse->currentItem();

        // Identify the items according the selected method to link
        Group* group = NULL;
        Student* student = NULL;
        if(browseStd) {
            group = (Group*) itemFromYes->data(Qt::UserRole).toULongLong();
            student = (Student*) itemFromBrowse->data(Qt::UserRole).toULongLong();
        } else {
            group = (Group*) itemFromBrowse->data(Qt::UserRole).toULongLong();
            student = (Student*) itemFromYes->data(Qt::UserRole).toULongLong();
        }

        // Add the action to remove the link in the variables preparing the query
        if(i) queryStr += " OR ";
        QString varGrp = ":idGroup" + QString::number(i), varStd = ":idUser" + QString::number(i);
        queryStr += "(id_groups = "+varGrp+" AND id_users = "+varStd+")";
        bindValuesMap.insert(varGrp, (qulonglong) group->getId());
        bindValuesMap.insert(varStd, (qulonglong) student->getId());
    }

    /// Make the query
    QSqlQuery queryDelete(*m_db);
    queryDelete.prepare(queryStr);
    // Add the bind values
    QMapIterator<QString, qulonglong> i(bindValuesMap);
    while (i.hasNext()) {
        i.next();
        queryDelete.bindValue(i.key(), i.value());
    }
    queryDelete.exec();

    /// Update the linking lists
    update_listsYesNo();
    // Update the selected item in the browsing list
    QListWidgetItem* item = ui->list_browse->currentItem();
    if(item && !browseStd){
        // If the selected item is a group --> change the number of students
        Group* grp = (Group*) item->data(Qt::UserRole).toLongLong();
        item->setText(grp->getName() + " ("+QString::number(nbStudentsInGroup(grp->getId()))+")");
    }

    return true;
}