Package com.trolltech.qt.core

Examples of com.trolltech.qt.core.QFile


              newFile = newFile+Global.attachmentNameDelimeter+r.getAttributes().getFileName();
          r.setNoteGuid(currentNote.getGuid());
         
          r.setGuid(randint);
          conn.getNoteTable().noteResourceTable.saveNoteResource(r, true);
        QFile f = new QFile(Global.getFileManager().getResDirPath(newFile));
        QByteArray bin = new QByteArray(r.getData().getBody());
        f.open(QFile.OpenModeFlag.WriteOnly);
        f.write(bin);
        f.close();
        newSegment = newSegment.replace("guid=\""+guid, "guid=\""+randint);
        currentNote.getResources().add(r);
       
        int startSrcPos = newSegment.indexOf(locTag);
        int endSrcPos = newSegment.indexOf("\"",startSrcPos+locTag.length()+1);
View Full Code Here


    fileName = f;
    errorMessage = "";
       
    lastError = 0;
    errorMessage = "";
    QFile xmlFile = new QFile(fileName);
    if (!xmlFile.open(QIODevice.OpenModeFlag.ReadOnly)) {
      lastError = 16;
      errorMessage = "Cannot open file.";
    }
     
    reader = new QXmlStreamReader(xmlFile)
    while (!reader.atEnd()) {
      reader.readNext();
      if (reader.hasError()) {
        errorMessage = reader.errorString();
        logger.log(logger.LOW, "************************* ERROR READING BACKUP " +reader.errorString());
        lastError = 16;
        return;
      }
      if (reader.name().equalsIgnoreCase("nevernote-export") && reader.isStartElement()) {
        QXmlStreamAttributes attributes = reader.attributes();
        String version = attributes.value("version");
        String type = attributes.value("exportType");
        String application = attributes.value("application");
        if (!version.equalsIgnoreCase("0.85") && !version.equalsIgnoreCase("0.86")
            && !version.equalsIgnoreCase("0.95")) {
          lastError = 1;
          errorMessage = "Unknown backup version = " +version;
          return;
        }
        if (!application.equalsIgnoreCase("NeverNote")) {
          lastError = 2;
          errorMessage = "This backup is from an unknown application = " +application;
          return;
        }
        if (!type.equalsIgnoreCase("backup") && backup) {
          lastError = 4;
          errorMessage = "This is an export file, not a backup file";
          return;
        }
        if (type.equalsIgnoreCase("export") && backup) {
          lastError = 5;
          errorMessage = "This is a backup file, not an export file";   
          return;
        }
       
      }
      if (reader.name().equalsIgnoreCase("Synchronization") && reader.isStartElement() && backup) {
        processSynchronizationNode();
        conn.getSyncTable().setLastSequenceDate(lastSequenceDate);
          conn.getSyncTable().setUpdateSequenceNumber(highUpdateSequenceNumber);
      }
      if (reader.name().equalsIgnoreCase("note") && reader.isStartElement()) {
        processNoteNode();
        if (backup)
          conn.getNoteTable().addNote(note, noteIsDirty);
        else {
          note.setUpdateSequenceNum(0);
          if (notebookGuid != null)
            note.setNotebookGuid(notebookGuid);
          for (int i=0; i<note.getResourcesSize(); i++) {
            note.getResources().get(i).setUpdateSequenceNum(0);
          }
          conn.getNoteTable().addNote(note, true);
        }
        if (metaData.containsKey(note.getGuid()))
          conn.getNoteTable().updateNoteMetadata(metaData.get(note.getGuid()));
      }
      if (reader.name().equalsIgnoreCase("notebook") && reader.isStartElement() && (backup || importNotebooks)) {
        processNotebookNode();
          String existingGuid = conn.getNotebookTable().findNotebookByName(notebook.getName());
          if (existingGuid == null) {
            conn.getNotebookTable().addNotebook(notebook, notebookIsDirty, notebookIsLocal);
          } else {
            conn.getNotebookTable().updateNotebookGuid(existingGuid, notebook.getGuid());
            conn.getNotebookTable().updateNotebook(notebook, notebookIsDirty);
          }
          conn.getNotebookTable().setIcon(notebook.getGuid(), notebookIcon, "PNG");
          conn.getNotebookTable().setReadOnly(notebook.getGuid(), notebookIsReadOnly);
      }
      if (reader.name().equalsIgnoreCase("tag") && reader.isStartElement() && (backup || importTags)) {
        processTagNode();
           String testGuid = conn.getTagTable().findTagByName(tag.getName());
          if (testGuid == null)
            conn.getTagTable().addTag(tag, tagIsDirty);
          else {
            conn.getTagTable().updateTagGuid(testGuid, tag.getGuid());
            conn.getTagTable().updateTag(tag,tagIsDirty);
          }
      }
      if (reader.name().equalsIgnoreCase("savedsearch") && reader.isStartElement() && backup) {
        processSavedSearchNode();
          conn.getSavedSearchTable().addSavedSearch(search, searchIsDirty);
      }
      if (reader.name().equalsIgnoreCase("LinkedNotebook") && reader.isStartElement() && backup) {
        processLinkedNotebookNode();
          conn.getLinkedNotebookTable().addNotebook(linkedNotebook, linkedNotebookIsDirty);
      }
      if (reader.name().equalsIgnoreCase("SharedNotebook") && reader.isStartElement() && backup) {
        processSharedNotebookNode();
          conn.getSharedNotebookTable().addNotebook(sharedNotebook, sharedNotebookIsDirty);
      }
    }
    xmlFile.close();
  }
View Full Code Here

 
  //********************************************************
  //* Import text files
  //********************************************************
  public boolean importTextFile() {
    QFile file = new QFile(fileName);
    if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly))) {
      // If we can't get to the file, it is probably locked.  We'll try again later.
      logger.log(logger.LOW, "Unable to save externally edited file - locked.  Saving for later.");
      return false;
    }
    QByteArray binData = file.readAll();
    file.close();
    if (binData.size() == 0) {
      // If we can't get to the file, it is probably locked.  We'll try again later.
      logger.log(logger.LOW, "Unable to save externally edited file - zero size.  Saving for later.");
      return false;
    }
View Full Code Here

  //********************************************************
  //* Import an image
  //********************************************************
  public boolean importAttachment() {
    QFile file = new QFile(fileName);
    if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly))) {
      // If we can't get to the file, it is probably locked.  We'll try again later.
      logger.log(logger.LOW, "Unable to save externally edited file - locked.  Saving for later.");
      return false;
    }
    QByteArray binData = file.readAll();
    file.close();
    if (binData.size() == 0) {
      // If we can't get to the file, it is probably locked.  We'll try again later.
      logger.log(logger.LOW, "Unable to save externally edited file - zero size.  Saving for later.");
      return false;
    }
View Full Code Here

  }
  //**************************************************************
  //* Check the file attachment to be sure it isn't over 25 mb
  //**************************************************************
  private boolean checkFileAttachmentSize(String url) {
    QFile resourceFile = new QFile(fileName);
    resourceFile.open(new QIODevice.OpenMode(
        QIODevice.OpenModeFlag.ReadOnly));
    long size = resourceFile.size();
    resourceFile.close();
    size = size / 1024 / 1024;
    if (size < 50 && Global.isPremium())
      return true;
    if (size < 25)
      return true;
View Full Code Here

  //********************************************************
  //* Build a new resource
  //********************************************************
  private Resource createResource(String mime, boolean attachment) {
    QFile resourceFile;
      resourceFile = new QFile(fileName);
      resourceFile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly));
      byte[] fileData = resourceFile.readAll().toByteArray();
      resourceFile.close();
      if (fileData.length == 0)
        return null;
      MessageDigest md;
      try {
        md = MessageDigest.getInstance("MD5");
View Full Code Here

TOP

Related Classes of com.trolltech.qt.core.QFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.