Logo Search packages:      
Sourcecode: canorus version File versions  Download package

CADocument * CAMainWin::openDocument ( const QString &  fileName  ) 

Opens a document with the given absolute file name. The previous document will be lost.

Returns a pointer to the opened document or null if opening the document has failed.

Definition at line 2736 of file mainwin.cpp.

References CAImport::importDocument(), CAImport::importedDocument(), CAImport::readableStatus(), CADocument::setFileName(), CAFile::setStreamFromFile(), and CAFile::status().

Referenced by on_uiImportDocument_triggered(), and CAAutoRecovery::openRecovery().

                                                           {
      stopPlayback();

      CAImport *open = 0;
      if ( fileName.endsWith(".xml") ) {
            open = new CACanorusMLImport();
            uiSaveDialog->selectFilter( CAFileFormats::CANORUSML_FILTER );
      } else if ( fileName.endsWith(".can") ) {
            open = new CACanImport();
            uiSaveDialog->selectFilter( CAFileFormats::CAN_FILTER );
      } else
            return 0; // FIXME Failing quietly, add error message

      open->setStreamFromFile( fileName );
      open->importDocument();
      open->wait();

      if( open->importedDocument() ) {
            CADocument *doc = open->importedDocument();
            delete open;

            doc->setFileName(fileName);
            return openDocument( doc );
      } else {
            QMessageBox::critical(
                  this, tr("Canorus"),
                  tr("Error while opening the file!\nError %1: ").arg(open->status()) + open->readableStatus()
            );
            delete open;
            return 0;
      }
}


Generated by  Doxygen 1.6.0   Back to index