Package com.trolltech.qt.core

Examples of com.trolltech.qt.core.QFile


        dirtySharedNotebooks.put(dsn.get(i), "");
      }
   
    lastError = 0;
    errorMessage = "";
    QFile xmlFile = new QFile(filename);
    if (!xmlFile.open(QIODevice.OpenModeFlag.WriteOnly, QIODevice.OpenModeFlag.Truncate)) {
      lastError = 16;
      errorMessage = "Cannot open file.";
    }
     
    writer = new QXmlStreamWriter(xmlFile)
    writer.setAutoFormatting(true);
    writer.setCodec("UTF-8");
    writer.writeStartDocument();
    writer.writeDTD("<!DOCTYPE NeverNote-Export>");
    writer.writeStartElement("nevernote-export");
    writer.writeAttribute("version", "0.95");
    if (fullBackup)
      writer.writeAttribute("exportType", "backup");
    else
      writer.writeAttribute("exportType", "export");     
    writer.writeAttribute("application", "NeverNote");
    writer.writeAttribute("applicationVersion", Global.version);
    if (fullBackup) {
      writer.writeStartElement("Synchronization");
      long sequenceDate = conn.getSyncTable().getLastSequenceDate();
      int number = conn.getSyncTable().getUpdateSequenceNumber();
      createTextNode("UpdateSequenceNumber", new Long(number).toString());
      createTextNode("LastSequenceDate", new Long(sequenceDate).toString());
      writer.writeEndElement();
    }
   
    for (int i=0; i<notes.size(); i++) {
      String guid = notes.get(i).getGuid();
      logger.log(logger.EXTREME, "Getting note " +guid +" : " +notes.get(i).getTitle());
      Note note = conn.getNoteTable().getNote(guid, true, true, true, true, true);
      logger.log(logger.EXTREME, "Writing note XML");
      writeNote(note);
    }
   
    writeNotebooks();
    writeTags();
    writeSavedSearches();
    writeLinkedNotebooks();
    writeSharedNotebooks();

   
    writer.writeEndElement();
    writer.writeEndDocument();

   
   
    writer.dispose();

   
    xmlFile.close();
    xmlFile.dispose();

  }
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 FILE " +reader.errorString());
        lastError = 16;
        return;
      }
      if (reader.name().equalsIgnoreCase("note") && reader.isStartElement()) {
        processNoteNode();
        note.setUpdateSequenceNum(0);
        if (notebookGuid != null)
          note.setNotebookGuid(notebookGuid);
        for (int i=0; i<note.getResourcesSize(); i++) {
          note.getResources().get(i).setUpdateSequenceNum(0);
        }
        note.setActive(true);
        if (note.getUpdated() == 0) {
          note.setUpdated(note.getCreated());
        }
        conn.getNoteTable().addNote(note, true);
      }
    }
    xmlFile.close();
  }
View Full Code Here

        type = "."+type.substring(6);
      else
        type="";
     
      String resGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(currentNoteGuid, hash.value());
      QFile tfile = new QFile(Global.getFileManager().getResDirPath(resGuid + type));
//      if (!tfile.exists()) {
        Resource r = null;
        if (resGuid != null)
           r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid,true);
         if (r==null || r.getData() == null || r.getData().getBody().length == 0) {
           resourceError = true;
           readOnly = true;
         }
         if (r!= null && r.getData() != null && r.getData().getBody().length > 0) {
         tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
         QByteArray binData = new QByteArray(r.getData().getBody());
        tfile.write(binData);
         tfile.close();
        
         // If we have recognition text, outline it
         addImageHilight(r.getGuid(), tfile);
        
        enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());
          enmedia.setAttribute("en-tag", "en-media");
          enmedia.setNodeValue("");
          enmedia.setAttribute("guid", r.getGuid());
          enmedia.setTagName("img");
        }
//      }
      // Technically, we should do a file:// to have a proper url, but for some reason QWebPage hates
      // them and won't generate a thumbnail image properly if we use them.
//    enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());
    enmedia.setAttribute("src", tfile.fileName().toString());
    enmedia.setAttribute("en-tag", "en-media");
    enmedia.setTagName("img");
    if (r != null && r.getAttributes() != null &&
        (r.getAttributes().getSourceURL() == null || !r.getAttributes().getSourceURL().toLowerCase().startsWith("http://latex.codecogs.com/gif.latex?")))
      enmedia.setAttribute("onContextMenu", "window.jambi.imageContextMenu('" +tfile.fileName()  +"');");
    else {
      QDomElement newText = doc.createElement("a");
      enmedia.setAttribute("src", tfile.fileName().toString());
      enmedia.setAttribute("en-tag", "en-latex");
      newText.setAttribute("onMouseOver", "style.cursor='hand'");
      if (r!= null && r.getAttributes() != null && r.getAttributes().getSourceURL() != null)
        newText.setAttribute("title", r.getAttributes().getSourceURL());
      newText.setAttribute("href", "latex://"+tfile.fileName().toString());
      enmedia.parentNode().replaceChild(newText, enmedia);
      newText.appendChild(enmedia);

    }
    enmedia.setNodeValue("");
View Full Code Here

     
      // We have pictures, so append them to the page.  This really isn't proper since
      // we leave the en-media tag in place, but since we can't edit the page it doesn't
      // hurt anything.
      for (int i=0; i<data.size(); i++) {
          QFile f = new QFile(Global.getFileManager().getResDirPath(resGuid + new Integer(i).toString()+".png"));
        f.open(OpenModeFlag.WriteOnly);
        f.write(data.get(i));
        f.close();
        QDomElement newImage = doc.createElement("img");
        newImage.setAttribute("src", QUrl.fromLocalFile(f.fileName()).toString());
        enmedia.appendChild(newImage);
      }
      return true;
    }
      return false;
View Full Code Here

              res.getAttributes().getFileName() != null &&
              !res.getAttributes().getFileName().trim().equals(""))
            fileName = res.getGuid()+Global.attachmentNameDelimeter+res.getAttributes().getFileName();
          else
            fileName = res.getGuid()+".pdf";
          QFile file = new QFile(fileManager.getResDirPath(fileName));
              QFile.OpenMode mode = new QFile.OpenMode();
              mode.set(QFile.OpenModeFlag.WriteOnly);
              file.open(mode);
              QDataStream out = new QDataStream(file);
              Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(res.getGuid(), true);
          QByteArray binData = new QByteArray(resBinary.getData().getBody());
          resBinary = null;
              out.writeBytes(binData.toByteArray());
              file.close();
              PDFPreview pdfPreview = new PDFPreview();
          goodPreview = pdfPreview.setupPreview(file.fileName(), appl,0);
          if (goodPreview) {
            QDomElement span = doc.createElement("span");
            QDomElement table = doc.createElement("table");
            span.setAttribute("pdfNavigationTable", "true");
            QDomElement tr = doc.createElement("tr");
            QDomElement td = doc.createElement("td");
            QDomElement left = doc.createElement("img");
            left.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
            left.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
            left.setAttribute("onMouseOver", "style.cursor='hand'");
            QDomElement right = doc.createElement("img");
            right.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
            left.setAttribute("onMouseDown", "window.jambi.previousPage('" +file.fileName() +"')");
            // NFC TODO: should these be file:// URLs?
            left.setAttribute("src", Global.getFileManager().getImageDirPath("small_left.png"));
            right.setAttribute("src", Global.getFileManager().getImageDirPath("small_right.png"));
            right.setAttribute("onMouseOver", "style.cursor='hand'");
           
View Full Code Here

          }
          finally {
              iStream.close();
              fOut.close();
          }
          QFile tempFile = new QFile(temp.getAbsoluteFile().toString());
          tempFile.open(OpenModeFlag.ReadOnly);
          QByteArray data = tempFile.readAll();
          tempFile.close();
          tempFile.remove();
          return data;
    }
View Full Code Here

  private void loadStyleSheet() {
    String styleSheetName = "default.qss";
    if (Global.getStyle().equalsIgnoreCase("cleanlooks"))
        styleSheetName = "default-cleanlooks.qss";
    String fileName = Global.getFileManager().getQssDirPathUser("default.qss");
    QFile file = new QFile(fileName);
   
    // If a user default.qss doesn't exist, we use the one shipped with NeverNote
    if (!file.exists()) {
      fileName = Global.getFileManager().getQssDirPath(styleSheetName);
      file = new QFile(fileName);
    }
    file.open(OpenModeFlag.ReadOnly);
    String styleSheet = file.readAll().toString();
    file.close();
    setStyleSheet(styleSheet);
  }
View Full Code Here

    QDialog dialog = new QDialog(this);
    QHBoxLayout layout = new QHBoxLayout();
    QTextEdit textBox = new QTextEdit();
    layout.addWidget(textBox);
    textBox.setReadOnly(true);
    QFile file = new QFile(Global.getFileManager().getProgramDirPath("release.txt"));
    if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly,
                QIODevice.OpenModeFlag.Text)))
      return;
    textBox.setText(file.readAll().toString());
    file.close();
    dialog.setWindowTitle(tr("Release Notes"));
    dialog.setLayout(layout);
    dialog.show();
    logger.log(logger.HIGH, "Leaving NeverNote.releaseNotes");
  }
View Full Code Here

  }
  // View a thumbnail of the note
  public void thumbnailView() {
   
    String thumbnailName = Global.getFileManager().getResDirPath("thumbnail-" + currentNoteGuid + ".png");
    QFile thumbnail = new QFile(thumbnailName);
    if (!thumbnail.exists()) {
     
      QImage img = new QImage();
      img.loadFromData(conn.getNoteTable().getThumbnail(currentNoteGuid));
      thumbnailViewer.setThumbnail(img);
    } else
View Full Code Here

    pos = name.lastIndexOf(Global.attachmentNameDelimeter);
    if (pos > -1) {
      guid = name.substring(0, pos);
    }
   
    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.  Saving for later.");
          externalFiles.add(fileName);
          return;
    }
    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.  Saving for later.");
          externalFiles.add(fileName);
          return;
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.