Exemple #1
0
void NotebookMenuButton::reloadData() {
    for (int i=actions.size()-1; i>=0; i--) {
        delete actions[i];
    }
    for (int i=stackMenus.size()-1; i>=0; i--) {
        delete stackMenus[i];
    }
    stackMenus.clear();
    actions.clear();
    loadData();

    // Restore the proper notebook selection

    Note n;
    NoteTable noteTable;
    NotebookTable notebookTable;
    noteTable.get(n, currentNoteLid, false,false);
    QString notebookGuid = QString::fromStdString(n.notebookGuid);
    QList<qint32> bookList;
    notebookTable.getAll(bookList);
    QString bookName;

    for (int i=0; i<bookList.size(); i++) {
        Notebook book;
        notebookTable.get(book, bookList[i]);
        if (notebookGuid == QString::fromStdString(book.guid)) {
            bookName = QString::fromStdString(book.name);
            i=bookList.size();
        }
    }
    setCurrentNotebook(currentNoteLid, n);
    return;
}
Exemple #2
0
//***********************************************
//* Restore all notes from the trash
//***********************************************
void NTrashTree::restoreAll() {
    NoteTable ntable;
    QList<qint32> lids;
    ntable.getAllDeleted(lids);
    for (int i=0; i<lids.size(); i++) {
        ntable.restoreNote(lids[i], true);
        delete global.cache[lids[i]];
        global.cache.remove(lids[i]);
    }

    emit(updateSelectionRequested());
}
Exemple #3
0
void UrlEditor::textModified(QString text) {
    this->blockSignals(true);

    NoteTable noteTable;
    noteTable.updateUrl(currentLid, text, true);

    if (text.trimmed() == "" && !hasFocus())
        setText(defaultText);
    else
        setText(text);
    this->blockSignals(false);

    if (text.trimmed() != initialText.trimmed() || priorText.trimmed() != text.trimmed())
        emit(textUpdated());

    priorText = text;
}
Exemple #4
0
//***********************************************
//* Permanently delete all notes
//***********************************************
void NTrashTree::expungeAll() {
    QMessageBox msgBox;
    msgBox.setWindowTitle(tr("Verify Delete"));
    msgBox.setText(tr("Are you sure you want to permanently delete these notes?"));
    msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
    msgBox.setIcon(QMessageBox::Question);
    msgBox.setDefaultButton(QMessageBox::Yes);
    int rc = msgBox.exec();
    if (rc != QMessageBox::Yes)
        return;

    NoteTable ntable;
    QList<qint32> lids;
    ntable.getAllDeleted(lids);
    for (int i=0; i<lids.size(); i++) {
        ntable.expunge(lids[i]);
        delete global.cache[lids[i]];
        global.cache.remove(lids[i]);
    }
    emit(updateSelectionRequested());
}
Exemple #5
0
void IndexRunner::index() {

    indexTimer->stop();

    QList<qint32> lids;
    NoteTable noteTable;
    ResourceTable resourceTable;

    if (keepRunning && noteTable.getIndexNeeded(lids) > 0 && !pauseIndexing) {
        QLOG_DEBUG() << "Unindexed Notes found: " << lids.size();


        for (qint32 i=0; i<lids.size() && keepRunning && !pauseIndexing; i++) {
            QSqlQuery sql;
            sql.prepare("Delete from SearchIndex where lid=:lid");
            sql.bindValue(":lid", lids.at(i));
            sql.exec();

            Note n;
            noteTable.get(n, lids.at(i), false, false);
            indexNote(lids.at(i),n);
            //hammer->setNote(lids.at(i), n);
            noteTable.setIndexNeeded(lids.at(i), false);
        }
    }

    lids.empty();
    if (keepRunning && resourceTable.getIndexNeeded(lids) > 0 && !pauseIndexing) {
        QLOG_DEBUG() << "Unindexed Resources found: " << lids.size();
        for (qint32 i=0; i<lids.size() && keepRunning && !pauseIndexing; i++) {
            Resource r;
            resourceTable.get(r, lids.at(i));
            indexRecognition(lids.at(i), r);
            resourceTable.setIndexNeeded(lids.at(i), false);
        }
    }
    indexTimer->start();

}
Exemple #6
0
void NotebookMenuButton::notebookSelected() {
    blockSignals(true);
    if (!actions[currentAction]->isChecked())
        actions[currentAction]->setChecked(true);
    else {
        actions[currentAction]->setChecked(false);
        for (int i=0; i<actions.size(); i++) {
            if (actions[i]->isChecked()) {
                currentAction = i;
                i=actions.size();
            }
        }
    }
    this->setText(actions[currentAction]->text());
    blockSignals(false);
    NoteTable noteTable;
    NotebookTable notebookTable;
    QString name = text();
    qint32 notebookLid = notebookTable.findByName(name);
    if (notebookLid > 0) {
        noteTable.updateNotebook(currentNoteLid, notebookLid, true);
        emit(notebookChanged());
    }
}
Exemple #7
0
//***********************************************************
//* This is the main entry point for an import.  It is passed
//* the file which contains the export data.  It then
//* opens up the file, checks the validity of the data, and
//* then begins to parse through all of the crap.
//***********************************************************
void ImportData::import(QString file) {
    fileName = file;
    errorMessage = "";

    lastError = 0;
    QFile xmlFile(fileName);
    if (!xmlFile.open(QIODevice::ReadOnly)) {
        lastError = 16;
        errorMessage = "Cannot open file.";
    }

    reader = new QXmlStreamReader(&xmlFile);
    QSqlQuery query;
    query.exec("begin");
    while (!reader->atEnd()) {
        reader->readNext();
        if (reader->hasError()) {
            errorMessage = reader->errorString();
            QLOG_ERROR() << "************************* ERROR READING BACKUP " << errorMessage;
            lastError = 16;
            return;
        }
        if (reader->name().toString().toLower() == "nevernote-export" && reader->isStartElement()) {
            QXmlStreamAttributes attributes = reader->attributes();
            QString version = attributes.value("version").toString();
            QString type = attributes.value("exportType").toString();
            QString application = attributes.value("application").toString();
            if (version != "0.85" && version != "0.86"
                    && version != "0.95") {
                lastError = 1;
                errorMessage = "Unknown backup version = " +version;
                return;
            }
            if (application.toLower() != "nevernote") {
                lastError = 2;
                errorMessage = "This backup is from an unknown application = " +application;
                return;
            }
            if (type.toLower() == "backup" && !backup) {
                lastError = 4;
                errorMessage = "This is an export file, not a backup file";
                return;
            }
            if (type.toLower() == "export" && backup) {
                lastError = 5;
                errorMessage = "This is a backup file, not an export file";
                return;
            }
        }
        if (reader->name().toString().toLower() == "synchronization" && reader->isStartElement() && backup) {
            processSynchronizationNode();
        }
        if (reader->name().toString().toLower() == "note" && reader->isStartElement()) {
            processNoteNode();
        }
        if (reader->name().toString().toLower() == "notebook" && reader->isStartElement() && (backup || importNotebooks)) {
            processNotebookNode();
        }
        if (reader->name().toString().toLower() == "tag" && reader->isStartElement() && (backup || importTags)) {
            processTagNode();
        }
        if (reader->name().toString().toLower() == "savedsearch" && reader->isStartElement() && backup) {
            processSavedSearchNode();
        }
        if (reader->name().toString().toLower() == "linkednotebook" && reader->isStartElement() && backup) {
            processLinkedNotebookNode();
        }
        if (reader->name().toString().toLower() == "SharedNotebook" && reader->isStartElement() && backup) {
            processSharedNotebookNode();
        }
    }
    xmlFile.close();
    query.exec("commit");

    // Now we do what is a "ahem" hack.  We need to
    // go through all of the notes & rebuild the NoteTable.  This
    // is because we may have gotten notes & tags before the notebook
    // & tag names existed.  There is probably a more efficient way
    // to do this, but since we don't really do this often this works
    // as well as any awy.

    NoteTable noteTable;
    for (qint32 i=0; i<noteList.size(); i++) {
        qint32 lid = noteTable.getLid(noteList[i]);
        if (lid > 0) {
            Note note;
            bool dirty = noteTable.isDirty(lid);
            noteTable.get(note, lid, false, false);
            noteTable.updateNoteList(lid, note, dirty);
        }
    }

}
Exemple #8
0
//***********************************************************
//* Process a <note> tag
//***********************************************************
void ImportData::processNoteNode() {
    Note note;
    QUuid uuid;
    QString newGuid = uuid.createUuid().toString().replace("{", "").replace("}", "");
    note.guid = newGuid.toStdString();
    NoteMetaData meta;
    note.__isset.guid = true;
    bool noteIsDirty = false;

    bool atEnd = false;
    while(!atEnd) {
        QString name = reader->name().toString().toLower();
        if (name == "guid" && !reader->isEndElement()) {
            note.guid = textValue().toStdString();
            note.__isset.guid = true;
            noteList.append(QString::fromStdString(note.guid));
        }
        if (name == "updatesequencenumber" && !reader->isEndElement()) {
            note.updateSequenceNum = textValue().toLong();
            note.__isset.updateSequenceNum = true;
        }
        if (name == "title" && !reader->isEndElement()) {
            note.title = textValue().toStdString();
            note.__isset.title = true;
        }
        if (name == "created" && !reader->isEndElement()) {
            note.created = longLongValue();
            note.__isset.created = true;
        }
        if (name == "updated" && !reader->isEndElement()) {
            note.updated = longLongValue();
            note.__isset.updated = true;
        }
        if (name == "deleted" && !reader->isEndElement()) {
            note.deleted = longLongValue();
            note.__isset.deleted = true;
        }
        if (name == "active" && !reader->isEndElement()) {
            note.active = booleanValue();
            note.__isset.active = true;
        }
        if (name == "notebookguid" && !reader->isEndElement()) {
            note.notebookGuid = textValue().toStdString();
            note.__isset.notebookGuid = true;
        }
        if (name == "dirty" && !reader->isEndElement()) {
            noteIsDirty = booleanValue();
        }
        if (name == "content" && !reader->isEndElement()) {
            note.content = textValue().toStdString();
            note.__isset.content = true;
        }
        if (name == "titlecolor" && !reader->isEndElement()) {
            meta.setColor(intValue());
        }
        if (name == "notetags" && (createTags || backup) && !reader->isEndElement()) {
            QStringList names, guids;
            processNoteTagList(guids, names);
            for (qint32 i=0; i<guids.size(); i++) {
                note.tagGuids.push_back(guids[i].toStdString());
                note.tagNames.push_back(names[i].toStdString());
                note.__isset.tagGuids = true;
                note.__isset.tagNames = true;
            }
        }
        if (name == "noteattributes" && !reader->isEndElement()) {
            processNoteAttributes(note.attributes);
            note.__isset.attributes = true;
        }
        if (name == "noteresource" && !reader->isEndElement()) {
            Resource newRes;
            processResource(newRes);
            note.resources.push_back(newRes);
            note.__isset.resources = true;
        }
        reader->readNext();
        QString endName = reader->name().toString().toLower();
        if (endName == "note" && reader->isEndElement())
            atEnd = true;
    }

    // Loop through the resources & make sure they all have the
    // proper guid for this note
    for (unsigned int i=0; i<note.resources.size(); i++) {
        note.resources[i].noteGuid = note.guid;
    }
    NoteTable noteTable;
    if (backup)
        noteTable.add(0,note, noteIsDirty);
    else {
        note.updateSequenceNum = 0;
        if (notebookGuid != NULL)
            note.notebookGuid = notebookGuid.toStdString();
        for (unsigned int i=0; i<note.resources.size(); i++) {
             note.resources[i].updateSequenceNum = 0;
        }
        noteTable.add(0,note, true);
        if (metaData.contains(QString(note.guid.c_str()))) {
            QLOG_ERROR() << "ERROR IN IMPORTING DATA:  Metadata not yet supported";
        }
    }
    return;
}