コード例 #1
0
ファイル: pmenu.cpp プロジェクト: kthxbyte/KDE1-Linaro
void PMenu::renameLnkFiles(QDir base_dir)
{
  PMenuItem *item;
  for( item = list.first(); item != 0; item = list.next() )
    {
      if( item->old_name.isEmpty() )
	continue;
      if( item->entry_type == submenu )
	{
	  if( item->real_name != item->old_name )
	    if( base_dir.exists( item->old_name ) )
	      {
		base_dir.rename( item->old_name, item->real_name );
		item->old_name = item->real_name;
	      }
	  QDir sub_dir(base_dir);
	  if( !sub_dir.cd(item->old_name) )
	    continue;
	  item->sub_menu->renameLnkFiles( sub_dir );
	}
      if( item->real_name == item->old_name || item->entry_type == separator )
	continue;
      if( base_dir.exists( item->old_name ) )
	{
	  base_dir.rename( item->old_name, item->real_name );
	  item->old_name = item->real_name;
	}
    }  
}
コード例 #2
0
ファイル: FileProcess.cpp プロジェクト: yuting-zhang/EasySign
void cutExtension(long maxNum)
{
    QDir Dir;
    QString loc=QCoreApplication::applicationDirPath()+"/data/video/";
    for (int i=1;i!=maxNum;++i)
    {
        Dir.rename(loc+QString::number(i)+".avi",loc+QString::number(i));
        Dir.rename(loc+QString::number(i)+"~1.avi",loc+QString::number(i)+"~1");
    }
}
コード例 #3
0
ファイル: Global.cpp プロジェクト: Breekenz/mumble
static void migrateDataDir() {
#ifdef Q_OS_MAC
	QString olddir = QDir::homePath() + QLatin1String("/Library/Preferences/Mumble");
#if QT_VERSION >= 0x050000
	QString newdir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#else
	QString newdir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#endif
	QString linksTo = QFile::readLink(olddir);
	if (!QFile::exists(newdir) && QFile::exists(olddir) && linksTo.isEmpty()) {
		QDir d;
		d.mkpath(newdir + QLatin1String("/.."));
		if (d.rename(olddir, newdir)) {
			if (d.cd(QDir::homePath() + QLatin1String("/Library/Preferences"))) {
				if (QFile::link(d.relativeFilePath(newdir), olddir)) {
					qWarning("Migrated application data directory from '%s' to '%s'",
					         qPrintable(olddir), qPrintable(newdir));
					return;
				}
			}
		}
	} else {
		/* Data dir has already been migrated. */
		return;
	}

	qWarning("Application data migration failed.");
#endif

// Qt4 used another data directory on Unix-like systems, to ensure a seamless
// transition we must first move the users data to the new directory.
#if defined(Q_OS_UNIX) && ! defined(Q_OS_MAC)
#if QT_VERSION >= 0x050000
	QString olddir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/data/Mumble");
	QString newdir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/Mumble");

	if (!QFile::exists(newdir) && QFile::exists(olddir)) {
		QDir d;
		d.mkpath(newdir + QLatin1String("/.."));
		if (d.rename(olddir, newdir)) {
			qWarning("Migrated application data directory from '%s' to '%s'",
			         qPrintable(olddir), qPrintable(newdir));
			return;
		}
	} else {
		/* Data dir has already been migrated. */
		return;
	}

	qWarning("Application data migration failed.");
#endif
#endif
}
コード例 #4
0
ファイル: Global.cpp プロジェクト: Samangan/mumble
static void migrateDataDir() {
#ifdef Q_OS_MAC
	QString olddir = QDir::homePath() + QLatin1String("/Library/Preferences/Mumble");
	QString newdir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
	QString linksTo = QFile::readLink(olddir);
	if (!QFile::exists(newdir) && QFile::exists(olddir) && linksTo.isEmpty()) {
		QDir d;
		d.mkpath(newdir + QLatin1String("/.."));
		if (d.rename(olddir, newdir)) {
			if (d.cd(QDir::homePath() + QLatin1String("/Library/Preferences"))) {
				if (QFile::link(d.relativeFilePath(newdir), olddir)) {
					qWarning("Migrated application data directory from '%s' to '%s'",
					         qPrintable(olddir), qPrintable(newdir));
					return;
				}
			}
		}
	} else {
		/* Data dir has already been migrated. */
		return;
	}

	qWarning("Application data migration failed.");
#endif
}
コード例 #5
0
bool Leaf::undoRename()
{
    QReadLocker locker (&lock);

    if (state->isLocked() || state->isRenameSucceeded() == Tribool::indeterminate)
        return false;

    if (!state->isRenameSucceeded()) {
        setStateReadyToRename();
        return true;
    }

    QDir dir;

    if (parentComponent)
        dir.setPath(parentComponent->fullPath());

    bool isSucceeded = dir.rename(newName, fileName);

    isSucceeded ? Log::log("undo SUCCEEDED : " + dir.absolutePath() + "/" + newName + " > " + fileName)
                : Log::log("undo ---FAILED : " + dir.absolutePath() + "/" + newName + " > " + fileName);

    locker.unlock();

    isSucceeded ? setStateReadyToRename()
                : setStateUndoFailed();

    return isSucceeded;
}
コード例 #6
0
void Engine::save() throw(PersistingException*)
{
    tracer->invoked(__func__);

    if (m_dirty) {
        tracer->sdebug(__func__) << "engine is dirty --> saving it..." << endl;

        // rename current file
        QDir path = m_fileAlbum->dirPath(true);
        QString oldFileName = m_fileAlbum->fileName();

        // create new filename
        QString basename = QFileInfo(oldFileName).baseName(true);
        QString timestamp = QDateTime::currentDateTime().toString("yyyyMMdd-hhmmsszzz");
        QString newFileName = QString("%1-%2.%3").arg(basename).arg(timestamp).arg(Constants::FILE_EXTENSION);

        tracer->sdebug(__func__) << "backing up file in directory '" << path.absPath() << "': '" << oldFileName << "' --> '" << newFileName << "'..." << endl;

        if (!path.rename(oldFileName, newFileName, false)) {
            QString msg = QString("Could not move old file '%1/%2' to '%3/%4'. Not saving file. Use 'Save As'.").arg(path.absPath()).arg(oldFileName).arg(path.absPath()).arg(newFileName);
            throw new PersistingException(
                msg,
                ""
            );
        }

        // save
        XmlWriter writer = XmlWriter(*this);
        writer.store(new QFile(m_fileAlbum->absFilePath()));
    }

    m_dirty = false;
}
コード例 #7
0
ファイル: desktopwidget.cpp プロジェクト: sglass68/paperman
void Desktopwidget::renameDir ()
   {
   QString path = _dir->menuGetPath ();
   QString fullPath;
   bool ok;
   QString oldName = _dir->menuGetName ();
   QModelIndex index;

   index = _dir->menuGetModelIndex ();
   if (_model->findIndex (index) != -1)
      {
      QMessageBox::warning (0, "Maxview", "You cannot rename a root directory");
      return;
      }
   QString text = QInputDialog::getText(
            this, "Maxview", "Enter new directory name:", QLineEdit::Normal,
            oldName, &ok);
   if ( ok && !text.isEmpty() && text != oldName)
      {
      QDir dir;

      QModelIndex index = _dir->menuGetModelIndex ();
      QModelIndex parent = _model->parent (index);

//       if (!_model->setData (index, QVariant (text)))
      path.truncate (path.length () - oldName.length () - 1);
      fullPath = path + "/" + text;
      if (dir.rename (path + "/" + oldName, fullPath))
         _model->refresh (parent);
//          _dir->refreshItemRename (text);  // indicates current item has new children
      else
         QMessageBox::warning (0, "Maxview", "Could not rename directory");
      }
   }
コード例 #8
0
void FileSystemWidget::renameFolder()
{
    QFileInfo info = contextFileInfo();
    if (!info.isDir()) {
        return;
    }

    QString folderName = QInputDialog::getText(m_liteApp->mainWindow(),
                                               tr("Rename Folder"),tr("Folder Name"),
                                               QLineEdit::Normal,info.fileName());
    if (!folderName.isEmpty() && folderName != info.fileName()) {
        QDir dir = contextDir();
        dir.cdUp();
#ifdef Q_OS_WIN
        QString _old = info.filePath();
        QString _new = dir.path()+"/"+folderName;
        if (!MoveFileW(_old.toStdWString().c_str(),_new.toStdWString().c_str())) {
            QMessageBox::information(m_liteApp->mainWindow(),tr("Rename Folder"),
                                     tr("Failed to rename the folder!"));
        }
#else
        if (!dir.rename(info.fileName(),folderName)) {
            QMessageBox::information(m_liteApp->mainWindow(),tr("Rename Folder"),
                                     tr("Failed to rename the folder!"));
        }
#endif
    }
}
コード例 #9
0
void ConfigSettingsWidget::on_cmdSetName_clicked()
{
     auto pConnection = ((MainListView*)FrmMain::instance()->mainWidget()->widget(MainView))->model.GetConnection(id);

     auto configDir = Utils::userApplicationDataDirectory() + "/config";

        //
	QDir dir;
    dir.rename(configDir + QLatin1String ("/") + pConnection->GetName(), configDir + QLatin1String ("/") + ui.txtName->text());

	QFile file;
    file.rename(configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + pConnection->GetName() + (".ovpn"), configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + ui.txtName->text() + (".ovpn"));

    QString sql (QString("UPDATE vpn SET \"vpn-name\" = '%1' WHERE \"vpn-id\" = %2")
                .arg(Crypt::encodePlaintext(Database::instance()->makeCleanValue(ui.txtName->text())))
                 .arg(id));

    Database::instance()->execute(sql);

    QString sql2 (QString("UPDATE vpn SET \"vpn-config\" = '%1' WHERE \"vpn-id\" = %2")
		.arg(Crypt::encodePlaintext(Database::instance()->makeCleanValue(configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + ui.txtName->text() + (".ovpn"))))
		.arg(id));

    Database::instance()->execute(sql2);

    pConnection->SetName(ui.txtName->text());
    pConnection->SetConfigPath(configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + ui.txtName->text() + (".ovpn"));
}
コード例 #10
0
bool FileManager::mooveFileToGeneratedFolder(QString in_qsFileToBeMoved)
{
    QString qdDestination = m_qsPath + "/" + m_qsGeneratedFolder;
    qDebug() << qdDestination;
    QFileInfo file(in_qsFileToBeMoved);
    QDir myDir = QDir::root();
    myDir.rename(in_qsFileToBeMoved, qdDestination + "/" + file.baseName() + "." + file.completeSuffix());
    return true;
}
コード例 #11
0
ファイル: new_document_wizard.cpp プロジェクト: c3d/tao-3D
static void Rename(QDir &dir, QString oldName, QString newName, QString ext)
// ----------------------------------------------------------------------------
//   Rename the file with the given extension
// ---------------------------------------------------------------------------
{
    newName += ext;
    oldName += ext;
    dir.remove(newName);
    dir.rename(oldName, newName);
}
コード例 #12
0
void Widget::on_pushButtoncopy_clicked()
{
    QSqlQuery query;
    QString selectedfromdb = "SELECT absdirectory,symlinkdirectory FROM test";
    QString selectedasbd;
    QString symlinkdir;
    query.exec(selectedfromdb);
    QString move2;
    QDir movedir;
    FILE *pFile; //文件指针
    Mp3Info song;
    QByteArray ba;
    while(query.next() != 0)
    {
        selectedasbd = query.value(0).toString();
        symlinkdir = query.value(1).toString();
        //qDebug() << selectedasbd << "\n";
        //QString move1 = selectedasbd;
        move2 = ui->lineEdityuanmulu->text();
        qDebug() << move2;

        ba = selectedasbd.toAscii();//将所得文件名转换为字符//yfx0527
        const char *dirnow = ba.data();
        //printf("%s\n",dirnow);
        pFile = fopen(dirnow, "r");
        fseek(pFile, -128, SEEK_END);
        fread(&song, 1, sizeof (Mp3Info), pFile); //读取MP3文件ID3V标签
        //printf("%s\n",song.album);
        QString title = QString::fromLocal8Bit(song.title,30);
        QString artist = QString::fromLocal8Bit(song.artist,30);
        QString album = QString::fromLocal8Bit(song.album,30);
        QString year = QString::fromLocal8Bit(song.year,4);
        QString comment = QString::fromLocal8Bit(song.comment,28);

        //QString artist2 = artist.trimmed();

        QString dirmubiao = ui->lineEditmubiaomulu->text();
        int dirlong = dirmubiao.length();
        symlinkdir = symlinkdir.remove(0,dirlong + 4);
        qDebug() << symlinkdir;
        QString move3 = move2 + "/" + artist;
        qDebug() << move3;
        bool mkdir = movedir.mkdir(move3);
        QString move4 = move2 + symlinkdir;
        qDebug() << move4;
        bool rename = movedir.rename(selectedasbd , move4);
        //qDebug() << selectedasbd;
        qDebug() << mkdir << rename;
        fclose(pFile);

    }
}
コード例 #13
0
bool NimCompilerCleanStep::removeCacheDirectory()
{
    auto bc = qobject_cast<NimBuildConfiguration*>(buildConfiguration());
    QTC_ASSERT(bc, return false);
    if (!bc->cacheDirectory().exists())
        return true;
    QDir dir = QDir::fromNativeSeparators(bc->cacheDirectory().toString());
    const QString dirName = dir.dirName();
    if (!dir.cdUp())
        return false;
    const QString newName = QStringLiteral("%1.bkp.%2").arg(dirName, QString::number(QDateTime::currentMSecsSinceEpoch()));
    return dir.rename(dirName, newName);
}
コード例 #14
0
/**
 * @brief moves all movies in given path to seperate directories
 * @param path place to organize
 */
void MovieFilesOrganizer::moveToDirs(QString path)
{
    path = QDir::toNativeSeparators(path);
    QFileInfo fi(path);
    if (!fi.isDir()) {
        canceled(tr("Source %1 is no directory").arg(path));
    }

    QList<QStringList> contents;
    MovieFileSearcher *fileSearcher = new MovieFileSearcher(this);
    fileSearcher->scanDir(path, contents, false, true);
    fileSearcher->deleteLater();

    int pos = path.lastIndexOf(QDir::separator());
    QString dirName = path.right(path.length() - pos -1);
    QString fileName;
    NameFormatter *nameFormat = NameFormatter::instance(this);


    foreach (QStringList movie, contents) {
        int pos = movie.at(0).lastIndexOf(QDir::separator());
        if (!(movie.at(0).left(pos).endsWith(dirName))) {
            qDebug() << "skipping " << movie.at(0);
            continue;
        }

        fi.setFile(movie.at(0));
        fileName = fi.completeBaseName();
        QDir *dir = new QDir();

        QString newFolder;
        if (movie.length() == 1)
            newFolder = path + QDir::separator() + nameFormat->formatName(fileName);
        else if (movie.length() > 1)
            newFolder = path + QDir::separator() + nameFormat->formatName(
                        nameFormat->formatParts(fileName));
        else
            continue;

        if (!(dir->mkdir(newFolder)))
            continue;

        foreach (QString file, movie) {
            if (!dir->rename(file, newFolder +
                             QDir::separator() +
                             file.right(file.length() -
                                        file.lastIndexOf
                                        (QDir::separator()) - 1)))
                qDebug() << "Moving " << file << "to " << newFolder << " failed.";
        }
    }
コード例 #15
0
void SessionManager::renameSession( const QString & oldName, const QString & newName )
{
    if (mCurrentSession && mCurrentSession->name() == oldName) {
        saveSessionAs(newName);
        removeSession(oldName);
    } else {
        QDir dir = sessionsDir();
        if (dir.path().isEmpty())
            return;

        if (!dir.rename(oldName + ".yaml", newName + ".yaml"))
            qWarning("Could not rename session file!");
    }
}
コード例 #16
0
ファイル: notesubfolder.cpp プロジェクト: XavierCLL/QOwnNotes
/**
 * Renames the note subfolder in the file system
 */
bool NoteSubFolder::rename(QString newName) {
    QDir dir = this->dir();

    if (dir.exists() && !newName.isEmpty()) {
        QString oldPath = fullPath();
        setName(newName);
        QString newPath = fullPath();

        // rename the note subfolder
        return dir.rename(oldPath, newPath);
    }

    return false;
}
コード例 #17
0
void UpdatingWindow::startDownload()
{

    QDir dir;
    QStringList path = pathToDownload.split("/");
    path.removeLast();
    QString oldPath = path.join("/")+"_old/";

    QString resourcesPath = pathToDownload;
    if(osName() == "win")
    {
        resourcesPath = AppData::Instance()->executablePath(pathToDownload).replace(".exe", "")+ "/";
    }
    QDir old(oldPath);
    dir.mkpath(oldPath);
    if(!dir.rename(resourcesPath+"settings.json", oldPath+"settings.json"))
    {
        qDebug() << "Move failed!" << resourcesPath;
    }
    if(!dir.rename(resourcesPath+"list.json", oldPath+"list.json"))
    {
        qDebug() << "Move failed!" << resourcesPath+"list.json" << oldPath+"list.json";
    }

    connect(&manager, SIGNAL(finished(QNetworkReply*)),
                SLOT(fileDownloaded(QNetworkReply*)));
    writeToFile = new QFile(pathToDownload + fileToDownload);
    writeToFile->open(QIODevice::ReadWrite | QIODevice::Truncate);
    //writeToFile->resize(0);
    QNetworkRequest request(AppData::Instance()->settings["url"].toString() + "download_update.php?file=" + fileToDownload + "&os="+ osName());
    qDebug() << AppData::Instance()->settings["url"].toString() + "download_update.php?file=" + fileToDownload + "&os="+ osName();
   this->reply =  manager.get(request);
    connect(this->reply, SIGNAL(downloadProgress(qint64,qint64)),
                SLOT(downloadProgress(qint64,qint64)));
    connect(this->reply, SIGNAL(readyRead()),
                this, SLOT(readyRead()));
}
コード例 #18
0
ファイル: maildir.cpp プロジェクト: KDE/kdepim-runtime
    bool moveAndRename(QDir &dest, const QString &newName)
    {
        if (!dest.exists()) {
            qCDebug(LIBMAILDIR_LOG) << "Destination does not exist";
            return false;
        }
        if (dest.exists(newName) || dest.exists(subDirNameForFolderName(newName))) {
            qCDebug(LIBMAILDIR_LOG) << "New name already in use";
            return false;
        }

        if (!dest.rename(path, newName)) {
            qCDebug(LIBMAILDIR_LOG) << "Failed to rename maildir";
            return false;
        }
        const QDir subDirs(Maildir::subDirPathForFolderPath(path));
        if (subDirs.exists() && !dest.rename(subDirs.path(), subDirNameForFolderName(newName))) {
            qCDebug(LIBMAILDIR_LOG) << "Failed to rename subfolders";
            return false;
        }

        path = dest.path() + QDir::separator() + newName;
        return true;
    }
コード例 #19
0
ファイル: SqLiteStorage.cpp プロジェクト: codemedic/Charm
bool SqLiteStorage::migrateDatabaseDirectory( QDir oldDirectory, QDir newDirectory ) const
{
    if ( oldDirectory == newDirectory )
        return true;
    qDebug() << "Application::configure: migrating Charm database directory contents from"
             << oldDirectory.absolutePath() << "to" << newDirectory.absolutePath();

    oldDirectory.setFilter( QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot );
    Q_FOREACH ( const QString& entry, oldDirectory.entryList() )
        oldDirectory.rename( entry, newDirectory.path() + QDir::separator() + entry );

    QDir oldDirectoryParent( oldDirectory );
    oldDirectoryParent.cdUp();
    return oldDirectoryParent.rmpath( oldDirectory.dirName() );
}
コード例 #20
0
ファイル: kfilebrowser.cpp プロジェクト: phofman/kfile
/*=========================================================================
  slot handleRenameAction 
=========================================================================*/
void KFileBrowser::handleRenameAction (void)
  {
  QStringList names = getSelectedItems ();
  if (names.count() != 1)
    {
    error (tr("Please select exactly one file or folder to rename"));
    }
  else
    { 
    QString sourcePath = path + "/" + names[0];
    QFileInfo sourceInfo (sourcePath);
    QDir sourceDir = sourceInfo.dir();
    QString sourceFilename = sourceInfo.fileName();
    bool ok = false;
    QString newName = QInputDialog::getText (this, tr("Rename"),
    tr("Enter new name for") + " " + sourceFilename, 
      QLineEdit::Normal, "", &ok);
    if (ok && !newName.isEmpty())
      {
      QString targetPath = sourceDir.path() + "/" + newName;
      bool ok = false;
      if (sourceInfo.isDir())
        {
        QDir d (sourcePath);
        ok = sourceDir.rename (sourcePath, targetPath);
        }
      else
        {
        QFile f(sourcePath);
        ok = f.rename (targetPath);
        }
      if (ok)
        {
        emit statusUpdate (tr("Renamed") + " " + sourcePath + " " 
          + tr("to") + " " + targetPath);
        emit dirContentsChanged();
        }
      else
        {
        QString msg = (tr("Failed to rename") + " " + sourcePath + " " 
          + tr("to") + " " + targetPath);
        emit statusUpdate (msg);
        error (msg);
        }
      }
    }
  }
コード例 #21
0
bool TagTransactionManager::renameFile(const QFileInfo &from, const QFileInfo &to) const
{
   if(!QFileInfo(to.path()).isWritable() || !from.exists())
       return false;

   if(!to.exists() ||
       KMessageBox::warningContinueCancel(
           static_cast<QWidget *>(parent()),
           i18n("This file already exists.\nDo you want to replace it?"),
           i18n("File Exists"),KGuiItem(i18n("Replace"))) == KMessageBox::Continue)
   {
       kDebug() << "Renaming " << from.absoluteFilePath() << " to " << to.absoluteFilePath();
       QDir currentDir;
       return currentDir.rename(from.absoluteFilePath(), to.absoluteFilePath());
   }

   return false;
}
コード例 #22
0
ファイル: gopathbrowser.cpp プロジェクト: hfeeki/liteide
void GopathBrowser::renameFolder()
{
    QFileInfo info = contextFileInfo();
    if (!info.isDir()) {
        return;
    }

    QString folderName = QInputDialog::getText(m_liteApp->mainWindow(),
                                               tr("Rename Folder"),tr("Folder Name"),
                                               QLineEdit::Normal,info.fileName());
    if (!folderName.isEmpty() && folderName != info.fileName()) {
        QDir dir = contextDir();
        dir.cdUp();
        if (!dir.rename(info.fileName(),folderName)) {
            QMessageBox::information(m_liteApp->mainWindow(),tr("Rename Folder"),
                                     tr("Failed to rename the folder!"));
        }
    }
}
コード例 #23
0
ファイル: Updater.cpp プロジェクト: keke222/Multifacile
void Updater::ToDoProcess()
{
    QStringList commandList(ToDo.split("\n", QString::SkipEmptyParts));


    if(!commandList.isEmpty())
    {
        for(int i = 0; i < commandList.size(); ++i)
        {
            QStringList argList(commandList.at(i).split(" ", QString::SkipEmptyParts));

            QDir dir;

            if(argList.at(0) == "mkdir")
                for(int mkDirIndex = 1; mkDirIndex < argList.size(); mkDirIndex++)
                {
                    QFileInfo dirInfo(argList.at(mkDirIndex));
                    dir.mkdir(QDir::toNativeSeparators(dirInfo.absoluteFilePath().simplified()));
                }
            else if(argList.at(0) == "rmdir")
                for(int rmDirIndex = 1; rmDirIndex < argList.size(); rmDirIndex++)
                {
                    QDir dirToRemove(argList.at(rmDirIndex).simplified());
                    QFileInfoList infoList(dirToRemove.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot));
                    for(int j = 0; j < infoList.size(); j++)
                        QFile::remove(argList.at(rmDirIndex).simplified()+"/"+infoList.at(j).fileName());
                    dir.rmdir(argList.at(rmDirIndex).simplified());
                }
            else if(argList.at(0) == "del")
                for(int delFileIndex = 1; delFileIndex < argList.size(); delFileIndex++)
                    QFile::remove(argList.at(delFileIndex).simplified());
            else if(argList.at(0) == "renameFile")
            {
                if(QFile::exists(argList.at(2).simplified()))
                    QFile::remove(argList.at(2).simplified());
                QFile::rename(argList.at(1).simplified(), argList.at(2).simplified());
            }
            else if(argList.at(0) == "renameDir")
                dir.rename(argList.at(1).simplified(), argList.at(2).simplified());
        }
    }
    finish();
}
コード例 #24
0
void TexturesSubFolder::rename() {
    std::string name;
    auto dia = new EnterTextDialog(name,this);
    dia->setLabel("Please enter the new name");
    dia->setModal(true);
    int returnCode = dia->exec();
    delete dia;

    if(returnCode == 255) {
        int index = dir_.substr(0, dir_.size()-1).find_last_of('/');
        std::string newPath = dir_.substr(0, index);

        QDir dir;
        dir.rename(dir_.c_str(), (newPath+"/"+name).c_str());
        heading_->setText(name.c_str());
        name_ = name;
        dir_ = newPath+"/"+name+"/";
    }
}
コード例 #25
0
ファイル: notesubfolder.cpp プロジェクト: pbek/QOwnNotes
/**
 * Renames the note subfolder in the file system
 */
bool NoteSubFolder::rename(QString newName) {
    QDir dir = this->dir();

    if (dir.exists() && !newName.isEmpty()) {
        QString oldPath = fullPath();
        QString oldRelativePath = relativePath();
        setName(newName);
        QString newPath = fullPath();
        QString newRelativePath = relativePath();

        // rename the note sub folder paths of note tag links
        // (needs to be done before the folder rename because folder renaming
        // will cause a reload which would trigger the removal of the tag links)
        Tag::renameNoteSubFolderPathsOfLinks(oldRelativePath, newRelativePath);

        // rename the note subfolder
        return dir.rename(oldPath, newPath);
    }

    return false;
}
コード例 #26
0
ファイル: wpsrun.cpp プロジェクト: maxselym/Magistral
bool WPSRun::MoveWrfOut(QString s_dir, QString& report)
{
    QDir currentDir = QDir(work_folder);
    QStringList files;
    QStringList filters;
    filters << "wrfout*";
    files = currentDir.entryList(filters,QDir::Files | QDir::NoSymLinks);
    QDir outDir = QDir(s_dir);
    if(!outDir.exists())
    {
        if(!outDir.mkdir(s_dir))
        {
            report = "Can not create directory ";
            report+=s_dir;
            return false;
        }
    }
    if(files.count() == 0)
    {
        report = "No wrfout* files in directory";
        return false;
    }
    for(int i=0;i<files.count();i++)
    {
        if(!currentDir.rename(work_folder+files[i],s_dir + files[i]))
        {
            report = "Can not move file ";
            report+=files[i];
            return false;
        }
        report.append(files[i]);
        report+="\n";
    }
    report += "moved to ";
    report += s_dir;
    return true;

}
コード例 #27
0
void QTodoRecoveryDialog::recover()
{
    QFileInfo file_info;
    QDir dir;

    QListViewItem* item = list->firstChild();
    for(; item; item = item->nextSibling())
    {
        if(item->text(2).isEmpty())
        {   //we can't recover from a backup file, so we at least (try to) restore the todo-list-name :(
            file_info.setFile(item->text(0));
            dynamic_cast<QTodoRecoveryListViewItem*>(item)->list_view_item->listWidget()->getHeader()->setName(file_info.fileName());
            dynamic_cast<QTodoRecoveryListViewItem*>(item)->list_view_item->update();
            dynamic_cast<QTodoRecoveryListViewItem*>(item)->list_view_item->listWidget()->setModified();
            dynamic_cast<QTodoRecoveryListViewItem*>(item)->list_view_item->save();
        }
        else
        {
            dir.rename(item->text(0)+'~',item->text(0),true);
            dynamic_cast<QTodoRecoveryListViewItem*>(item)->list_view_item->load();
        }
    }
}
コード例 #28
0
ファイル: preview.cpp プロジェクト: caivega/tao-3D
void PreviewThread::savePreview()
// ----------------------------------------------------------------------------
//   Save a preview of the image, and wait until awoken again
// ----------------------------------------------------------------------------
{
    // Acquire input parameters
    mutex.lock();
    QImage toSave = image;
    QString filePath = path;
    uint width = maxWidth;
    uint height = maxHeight;
    image = QImage();
    mutex.unlock();

    // Check if there is anything interesting to save
    if (!toSave.isNull() && filePath != "")
    {
        // Arm singles shot time for next save
        nextSave.start(timeInterval);

        // Rescale image to maximum dimensions
        if ((uint) toSave.width() > maxWidth)
            toSave = toSave.scaledToWidth(width);
        if ((uint) toSave.height() > maxHeight)
            toSave = toSave.scaledToHeight(height);
        
        // Save image in a temporary file
        QFileInfo fileInfo (filePath);
        QFileInfo tmpInfo(fileInfo.dir(), "tmp-" + fileInfo.fileName());
        toSave.save(tmpInfo.filePath());

        // Rename file to target (automic or near-atomic operation)
        QDir dir = fileInfo.dir();
        dir.remove(fileInfo.fileName());
        dir.rename(tmpInfo.fileName(), fileInfo.fileName());
    }
}
コード例 #29
0
bool PackageUtils::prepareWidget()
{
    QString widgetInstallPath(m_packageRootPath + m_installationPath);
    while (widgetInstallPath.endsWith(QDir::separator()))
        widgetInstallPath.chop(1);

    QDir dir;
    if (!dir.mkpath(widgetInstallPath.left(widgetInstallPath.lastIndexOf(QDir::separator()))))
        return false;

#if defined(Q_OS_MAEMO5)
    // dpkg on M5 doesn't support long path name, thus unzip the .wgt in postinst script
    m_installedSize += QFileInfo(m_widget->widgetBundlePath()).size();
    if (!dir.mkpath(widgetInstallPath)
        || !QFile::copy(m_widget->widgetBundlePath(), widgetInstallPath + QDir::separator() + QFileInfo(m_widget->widgetBundlePath()).fileName()))
        return false;
#else
    // move the unzipped widget to the temp folder
    m_installedSize += Zzip::uncompressedSize(m_widget->widgetBundlePath());
    if (!dir.rename(m_sourcePath, widgetInstallPath + QDir::separator()))
        return false;

    QDir baseRootDir(m_packageRootPath);
    baseRootDir.mkpath("etc/secure/s/" + m_packageName);
    baseRootDir.mkpath(m_properties->resourcePath());
#endif

#ifdef Q_OS_MAEMO6
    // keep the original .wgt for backup
    m_installedSize += QFileInfo(m_widget->widgetBundlePath()).size();
    QString wgtFilePath(m_packageRootPath + BACKUP_SCRIPTS_DIR + "/install/");
    if (!dir.mkpath(wgtFilePath) || !QFile::copy(m_widget->widgetBundlePath(), wgtFilePath + m_appId + ".wgt"))
        return false;
#endif

    return true;
}
コード例 #30
0
bool Leaf::rename()
{
    QReadLocker locker(&lock);

    if (!state->allowRename())
        return false;

    QDir dir;

    if (parentComponent)
        dir.setPath(parentComponent->fullPath());

    bool isSucceeded = dir.rename(fileName, newName);

    isSucceeded ? Log::log("rename SUCCEEDED : " + dir.absolutePath() + "/" + fileName + " > " + newName)
                : Log::log("rename ---FAILED : " + dir.absolutePath() + "/" + fileName + " > " + newName);

    locker.unlock();

    isSucceeded ? setStateRenameSucceeded()
                : setStateRenameFailed(dir);

    return isSucceeded;
}