Пример #1
0
/**
 * Renames a note
 */
bool Note::renameNoteFile(QString newName) {
    // cleanup not allowed characters characters
    newName = cleanupFileName(newName);

    // add the old file suffix to the name
    QString newFileName = newName + "." + fileNameSuffix();

    // check if name has really changed
    if (name == newName) {
        return false;
    }

    // check if name already exists
    Note existingNote = Note::fetchByName(newName);
    if (existingNote.isFetched() && (existingNote.getId() != id)) {
        return false;
    }

    // get the note file to rename it
    QFile file(getFullNoteFilePathForFile(fileName));

    // store the new note file name
    fileName = newFileName;
    name = newName;
    store();

    // rename the note file name
    return file.rename(getFullNoteFilePathForFile(newFileName));
}
Пример #2
0
/**
 * @brief Copies a note to an other path
 *
 * @param destinationPath
 * @return bool
 */
bool Note::copy(QString destinationPath) {
    QDir d;
    if (this->fileExists() && (d.exists(destinationPath))) {
        QFile file(getFullNoteFilePathForFile(this->fileName));
        QString destinationFileName =
                destinationPath + QDir::separator() + this->fileName;

        if (d.exists(destinationFileName)) {
            qDebug() << destinationFileName << "already exists!";

            // find a new filename for the note
            QDateTime currentDateTime = QDateTime::currentDateTime();
            destinationFileName =
                    destinationPath + QDir::separator() + this->name + " " +
                    currentDateTime.toString(Qt::ISODate).replace(":", "_") +
                    "." + defaultNoteFileExtension();

            qDebug() << "New file name:" << destinationFileName;
        }

        return file.copy(destinationFileName);
    }

    return false;
}
Пример #3
0
//
// remove the file of the note
//
bool Note::removeNoteFile() {
    if (this->fileExists()) {
        QFile file(getFullNoteFilePathForFile(this->fileName));
        qDebug() << __func__ << " - 'this->fileName': " << this->fileName;
        qDebug() << __func__ << " - 'file': " << file.fileName();
        return file.remove();
    }

    return false;
}
Пример #4
0
bool Note::storeNoteTextFileToDisk() {
    // checks if filename has to be changed (and change it if needed)
    this->handleNoteTextFileName();

    QFile file(getFullNoteFilePathForFile(this->fileName));
    bool fileExists = this->fileExists();

    qDebug() << "storing note file: " << this->fileName;

    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
        qCritical() << file.errorString();
        return false;
    }

    // if we find a decrypted text to encrypt, then we attempt encrypt it
    if (!decryptedNoteText.isEmpty()) {
        noteText = decryptedNoteText;
        encryptNoteText();
        decryptedNoteText = "";
    }

    // transform all types of newline to \n
    // (maybe the ownCloud-sync works better then)
    QString text = this->noteText;
    text.replace(QRegExp("(\\r\\n)|(\\n\\r)|\\r|\\n"), "\n");

//    diff_match_patch *diff = new diff_match_patch();
//    QList<Diff> diffList = diff->diff_main( this->noteText, text );

//    QString html = diff->diff_prettyHtml( diffList );
//    diff->diff_cleanupSemantic( diffList );
//    qDebug() << __func__ << " - 'diffList': " << diffList[0].toString();
//    qDebug() << __func__ << " - 'html': " << html;

    QTextStream out(&file);
    out.setCodec("UTF-8");
    out << text;
    file.flush();
    file.close();

    this->hasDirtyData = false;
    this->fileLastModified = QDateTime::currentDateTime();

    if (!fileExists) {
        this->fileCreated = this->fileLastModified;
    }

    return this->store();
}
Пример #5
0
bool Note::updateNoteTextFromDisk() {
    QFile file(getFullNoteFilePathForFile(this->fileName));

    if (!file.open(QIODevice::ReadOnly)) {
        qDebug() << file.errorString();
        return false;
    }

    QTextStream in(&file);
    in.setCodec("UTF-8");
    this->noteText = in.readAll();
    file.close();

    // strangely it sometimes gets null
    if (this->noteText.isNull()) this->noteText = "";

    return true;
}
Пример #6
0
//
// checks if file of note exists in the filesystem
//
bool Note::fileExists() {
    QFile file(getFullNoteFilePathForFile(this->fileName));
    return file.exists();
}
Пример #7
0
/**
 * Returns the full path of the note file
 */
QString Note::fullNoteFilePath() {
    return getFullNoteFilePathForFile(this->fileName);
}
Пример #8
0
/**
 * Returns the full url for a note file
 */
QUrl Note::fullNoteFileUrl() {
    return QUrl("file://" + getFullNoteFilePathForFile(this->fileName));
}
Пример #9
0
/**
 * Returns the full path of the note file
 */
QString Note::fullNoteFilePath() {
    return getFullNoteFilePathForFile(relativeNoteFilePath());
}