Esempio n. 1
0
bool TupCommandExecutor::removeScene(TupSceneResponse *response)
{
    #ifdef K_DEBUG
           T_FUNCINFO;
    #endif    

    int position = response->sceneIndex();
    int scenesTotal = m_project->scenesTotal();

    TupScene *toRemove = m_project->scene(position);

    if (toRemove) {
        QDomDocument document;
        document.appendChild(toRemove->toXml(document));
        
        response->setState(document.toString());
        response->setArg(toRemove->sceneName());
        
        if (m_project->removeScene(position)) {

            if (position+1 < scenesTotal) {
                for (int i = position + 1; i < scenesTotal; i++)
                     m_project->moveScene(i, i-1);
            }

            emit responsed(response);

            return true;
        } 
    } else {
        #ifdef K_DEBUG
               tError() << "TupCommandExecutor::removeScene() - Scene doesn't exist (" << position << ")";
        #endif
    }
    
    return false;
}
Esempio n. 2
0
bool TupFileManager::save(const QString &fileName, TupProject *project)
{
    #ifdef K_DEBUG
        QString msg = "TupFileManager::save() - Saving file -> " + fileName;
            #ifdef Q_OS_WIN32
                qWarning() << msg;
            #else
                tWarning() << msg;
        #endif
    #endif

	/* 
    int indexPath = fileName.lastIndexOf(QDir::separator());
    int indexFile = fileName.length() - indexPath;
    QString name = fileName.right(indexFile - 1);
    int indexDot = name.lastIndexOf(".");
    name = name.left(indexDot);
    */
	
	QFileInfo info(fileName);
	QString name = info.baseName();	
    QString oldDirName = CACHE_DIR + project->projectName();
    QDir projectDir(oldDirName);

    if (name.compare(project->projectName()) != 0) {
        project->setProjectName(name);
        projectDir.setPath(CACHE_DIR + name);    
        project->library()->updatePaths(CACHE_DIR + name);
        if (!projectDir.exists()) {
            if (projectDir.rename(oldDirName, projectDir.path())) {
                #ifdef K_DEBUG
                    QString msg = "TupFileManager::save() - Directory renamed to -> " + projectDir.path(); 
                    #ifdef Q_OS_WIN32
                        qWarning() << msg;
                    #else
                        tWarning() << msg;
                    #endif
                #endif
            } else {
                // SQA: Check if these lines are really needed
                if (! projectDir.mkdir(projectDir.path())) {
                    #ifdef K_DEBUG
                        QString msg = "TupFileManager::save() - Error: Can't create path -> " + projectDir.path();
                        #ifdef Q_OS_WIN32
                            qDebug() << msg;
                        #else
                            tError() << msg;
                        #endif
                    #endif
                    return false;
                } else {
                    #ifdef K_DEBUG
                        QString msg = "TupFileManager::save() - Directory was created successfully -> " + projectDir.path();
                        #ifdef Q_OS_WIN32
                            qWarning() << msg;
                        #else
                            tWarning() << msg;
                        #endif
                    #endif
                }
            }
        }
    } else {
        if (!projectDir.exists()) {
            if (! projectDir.mkdir(projectDir.path())) {
                #ifdef K_DEBUG
                    QString msg = "TupFileManager::save() - Error: Can't create path -> " + projectDir.path();
                    #ifdef Q_OS_WIN32
                        qDebug() << msg;
                    #else
                        tError() << msg;
                    #endif
                #endif
                return false;
            } else {
                #ifdef K_DEBUG
                    QString msg = "TupFileManager::save() - Directory was created successfully -> " + projectDir.path();
                    #ifdef Q_OS_WIN32
                        qWarning() << msg;
                    #else
                        tWarning() << msg;
                    #endif
                #endif
            }
        }
    }

    {
     // Save project
     QFile projectFile(projectDir.path() + QDir::separator() + "project.tpp");

     if (projectFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
         QTextStream ts(&projectFile);
         QDomDocument doc;
         project->setProjectName(name);
         doc.appendChild(project->toXml(doc));
         ts << doc.toString();
         projectFile.close();
     } else {
         #ifdef K_DEBUG
             QString msg = "TupFileManager::save() - Error: Can't create file -> " + projectDir.path() + QDir::separator() + "project.tpp";
             #ifdef Q_OS_WIN32
                 qDebug() << msg;
             #else
                 tError() << msg;
             #endif
         #endif
     }
    }

    // Save scenes
    {
     int index = 0;
     int totalScenes = project->scenes().size();
     for (int i = 0; i < totalScenes; i++) {
          TupScene *scene = project->scenes().at(i);
          QDomDocument doc;
          doc.appendChild(scene->toXml(doc));
          QString scenePath = projectDir.path() + QDir::separator() + "scene" + QString::number(index) + ".tps";
          QFile sceneFile(scenePath);

          if (sceneFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
              QTextStream st(&sceneFile);
              st << doc.toString();
              index += 1;
              sceneFile.close();
          } else {
              #ifdef K_DEBUG
                  QString msg = "TupFileManager::save() - Error: Can't create file -> " + scenePath;
                  #ifdef Q_OS_WIN32
                      qDebug() << msg;
                  #else
                      tError() << msg;
                  #endif
              #endif
          }
     }
    }

    {
     // Save library
     QFile lbr(projectDir.path() + QDir::separator() + "library.tpl");

     if (lbr.open(QIODevice::WriteOnly | QIODevice::Text)) {
         QTextStream ts(&lbr);

         QDomDocument doc;
         doc.appendChild(project->library()->toXml(doc));

         ts << doc.toString();
         lbr.close();
     } else {
         #ifdef K_DEBUG
             QString msg = "TupFileManager::save() - Error: Can't create file -> " + projectDir.path() + QDir::separator() + "library.tpl";
             #ifdef Q_OS_WIN32
                 qDebug() << msg;
             #else
                 tError() << msg;
             #endif
         #endif
     }
    }

    TupPackageHandler packageHandler;
    bool ok = packageHandler.makePackage(projectDir.path(), fileName);

    if (ok) {
        #ifdef K_DEBUG
            QString msg = "TupFileManager::save() - Project saved in -> " + fileName;
            #ifdef Q_OS_WIN32
                qWarning() << msg;
            #else
                tWarning() << msg;
            #endif
        #endif
    } else {
        #ifdef K_DEBUG
            QString msg = "TupFileManager::save() - Error: Project couldn't be saved in -> " + fileName;
            #ifdef Q_OS_WIN32
                qDebug() << msg;
            #else
                tError() << msg;
            #endif
        #endif
    }

    return ok;
}