Esempio n. 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));
}
Esempio n. 2
0
StackFrameItem::StackFrameItem(QString level, QString address, QString function, QString line, QString file, QString fullName, StackFramesTreeWidget *pStackFramesTreeWidget)
  : QTreeWidgetItem(pStackFramesTreeWidget)
{
  mpStackFramesTreeWidget = pStackFramesTreeWidget;
  mLevel = level;
  mAddress = address;
  mLine = line;
  mFile = cleanupFileName(file);
  mFullName = cleanupFileName(fullName);
  mFunction = cleanupFunction(function);
  setText(0, mFunction);
  setToolTip(0, mFunction);
  setText(1, mLine);
  setToolTip(1, mLine);
  setText(2, getFileName());
  setToolTip(2, getFileName());
  filterStackFrame();
}
Esempio n. 3
0
/**
 * Checks if the filename has to be changed
 * Generates a new name and filename and removes the old file
 * (the new file is not stored to a note text file!)
 */
void Note::handleNoteTextFileName() {
    // split the text into a string list
    QStringList noteTextLines = this->noteText.split(
            QRegExp("(\\r\\n)|(\\n\\r)|\\r|\\n"));

    // do nothing if there is no text
    if (noteTextLines.count() == 0) return;

    QString name = noteTextLines[0];
    // do nothing if the first line is empty
    if (name == "") return;

    // remove a leading "# " for markdown headlines
    name.remove(QRegularExpression("^#\\s"));

    // cleanup additional characters
    name = cleanupFileName(name);

    // check if name has changed
    if (name != this->name) {
        qDebug() << __func__ << " - 'name' was changed: " << name;
        QString fileName = name + "." + defaultNoteFileExtension();

        // check if note with this filename already exists
        Note note = Note::fetchByFileName(fileName);
        if (note.id > 0) {
            // find new filename for the note (not very safe yet)
            QDateTime currentDateTime = QDateTime::currentDateTime();
            name += " " + currentDateTime
                    .toString(Qt::ISODate).replace(":", "_");
        }

        // remove old note file
        // TODO(pbek): note doesn't seem to be removed very often
        this->removeNoteFile();

        // update the first line of the note text
        // TODO(pbek): UI has to be updated too then!
        noteTextLines[0] = name;
        this->noteText = noteTextLines.join("\n");

        // store new name and filename
        this->name = name;
        this->fileName = name + "." + defaultNoteFileExtension();
        this->store();
    }

    qDebug() << __func__ << " - 'name': " << name;
    qDebug() << __func__ << " - 'this->id': " << this->id;
}