コード例 #1
0
ファイル: gdata.cpp プロジェクト: nsauzede/tartini
/**
  @param s The sound file to be closed (This pointer will become invalid after returning)
  //@param ask If true (default), the user will be asked to save the file if it's been modified.
  @return 0 if the file was closed, 1 if canclled, -1 if error
*/
int GData::closeFile(SoundFile *s, int theSavingMode/*, bool ask*/)
{
  if(s == NULL) return -1;
  QString newFilename;
  QString oldFilename(s->filename);
//#ifdef WINDOWS
//  oldFilename.replace(QChar('/'), QChar('\\'));
//#endif
  oldFilename = QDir::convertSeparators(oldFilename);

  if(gdata->audioThread.playSoundFile() == s || gdata->audioThread.recSoundFile() == s) {
    gdata->stop();
  }

  if(s->saved()) { //file is already saved
    removeFileFromList(s);
    delete s;
    return 0;
  }

  if(theSavingMode == ALWAYS_ASK) {
    QString filename = QString(getFilenamePart(oldFilename.latin1()));
    int option = QMessageBox::question(NULL, QString("Save changes to file '") + filename + "' ?",
      QString("Save changes to the file '") + filename + QString("' ?\n"),
      "&Yes", "&No", "&Cancel", 0, 2);

    switch(option) {
    case 0: //Yes
      newFilename = saveFileAsk(oldFilename);
      if(newFilename.isNull()) return 1;
      removeFileFromList(s);
      delete s;
      //printf("move file %s to %s\n", oldFilename.latin1(), newFilename.latin1()); fflush(stdout);
      break;
    case 1: //No
      removeFileFromList(s);
      delete s;
      //printf("remove file %s\n", oldFilename.latin1()); fflush(stdout);
      break;
    default: //Cancelled
      return 1;
    }
  } else if(theSavingMode == NEVER_SAVE) {
    removeFileFromList(s);
    delete s;
  } else if(theSavingMode == ALWAYS_SAVE) {
    removeFileFromList(s);
    delete s;
  }
  return 0;
  /*
  if(ret == -1) {
    QMessageBox::warning(mainWindow, "Error", QString("Error removing file '") + QString(oldFilename) + QString("'"), QMessageBox::Ok, Qt::NoButton);
  }
  return ret;*/
}
コード例 #2
0
void SludgeProjectManager::on_remove_file_clicked()
{
	GList * selectedRows;
	GtkTreeIter iter;
	GtkTreePath *path;
	GtkTreeModel *model;
	gchar *indexStr;
	int index;

	if (! askAQuestion("Remove files?", "Do you want to remove the selected files from the project? (They will not be deleted from the disk.)")) {
		return;
	}

	selectedRows = gtk_tree_selection_get_selected_rows(filesSelection, &model);

	for (int j = g_list_length(selectedRows) - 1; j >= 0; j--)
	{
		path = gtk_tree_model_sort_convert_path_to_child_path(
					GTK_TREE_MODEL_SORT(model),
					(GtkTreePath *)g_list_nth(selectedRows, j)->data);

		indexStr = gtk_tree_path_to_string(path);
		index = atoi(indexStr);
        g_free(indexStr);

		removeFileFromList(index, fileList, &fileListNum);
		setFileChanged();

		gtk_tree_model_get_iter(GTK_TREE_MODEL(filesListStore), &iter, path);
		gtk_list_store_remove(filesListStore, &iter);
    }
	g_list_foreach(selectedRows, (GFunc) gtk_tree_path_free, NULL);
	g_list_free(selectedRows);
}