コード例 #1
0
void NotebookProperties::okButtonPressed() {
    okPressed = true;

    if (this->lid > 0) {
        Notebook book;
        NotebookTable table;
        table.get(book, lid);
        book.name = name.text().trimmed().toStdString();
        book.__isset.name = true;
        table.update(book, true);
        close();
        return;
    }

    // We have a new notebook to add
    Notebook book;
    book.name = name.text().trimmed().toStdString();
    bool isSynchronized = syncBox.isChecked();
    QUuid uuid;
    QString g =  uuid.createUuid().toString().replace("{","").replace("}","");
    book.guid = g.toStdString();
    book.__isset.name = true;
    book.__isset.guid = true;
    NotebookTable t;
    t.add(0,book,true, !isSynchronized);
    close();
}
コード例 #2
0
void NoteTable::updateNotebook(qint32 noteLid, qint32 notebookLid, bool setAsDirty) {
    Notebook book;
    NotebookTable notebookTable;
    notebookTable.get(book, notebookLid);

    if (book.__isset.guid) {
        QSqlQuery query;
        query.prepare("Update DataStore set data=:notebookLid where lid=:lid and key=:key;");
        query.bindValue(":notebookLid", notebookLid);
        query.bindValue(":lid", noteLid);
        query.bindValue(":key", NOTE_NOTEBOOK_LID);
        query.exec();

        if (setAsDirty) {
            setDirty(noteLid, setAsDirty);
        }

        QString bookName = QString::fromStdString(book.name);
        query.prepare("Update NoteTable set notebook=:name where lid=:lid");
        query.bindValue(":name", bookName);
        query.bindValue(":lid", noteLid);
        query.exec();

        query.prepare("Update NoteTable set notebookLid=:nlid where lid=:lid");
        query.bindValue(":nlid", notebookLid);
        query.bindValue(":lid", noteLid);
        query.exec();
    }
}
コード例 #3
0
void NotebookMenuButton::setCurrentNotebook(int lid, Note note) {
    if (actions.size() == 0)
        loadData();

    if (lid <=0)
        return;

    blockSignals(true);
    currentNoteLid = lid;
    NotebookTable notebookTable;
    Notebook notebook;
    notebookTable.get(notebook, note.notebookGuid);
    if (currentAction < actions.size())
        actions[currentAction]->setChecked(false);
    this->setText(QString::fromStdString(notebook.name));
    for (int i=0; i<actions.size(); i++) {
        if (actions[i]->text().toLower().trimmed() == QString::fromStdString(notebook.name).toLower().trimmed()) {
            currentAction = i;
            actions[currentAction]->setChecked(true);
            blockSignals(false);
            return;
        }
    }
    blockSignals(false);
}
コード例 #4
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;
}
コード例 #5
0
void NotebookProperties::setLid(qint32 lid) {
    if (lid > 0) {
        this->lid = lid;
        Notebook book;
        NotebookTable table;
        table.get(book, lid);
        originalName = QString::fromStdString(book.name).trimmed();
        name.setText(originalName);
        syncBox.setEnabled(false);
        bool local = table.isLocal(lid);
        syncBox.setChecked(!local);
        return;
    }
    this->lid = 0;
    syncBox.setEnabled(true);
    this->setWindowTitle(tr("Add Notebook"));
    originalName = "";
}
コード例 #6
0
// Read in all of the data and build the menu.
void NotebookMenuButton::loadData() {
    rootMenu.clear();
    NotebookTable notebookTable;

    QList<qint32> lids;
    notebookTable.getAll(lids);

    if (notebookTable.findByName(currentNotebookName) <= 0)
        currentNotebookName = "";

    for (qint32 i=0; i<lids.size(); i++) {
        Notebook book;
        if (notebookTable.get(book, lids[i])) {

            QAction *action = new QAction(this);
            actions.append(action);
            action->setText(QString::fromStdString(book.name));
            action->setCheckable(true);
            connect(action, SIGNAL(triggered()), this, SLOT(notebookSelected()));
            QFont f = action->font();
            f.setPixelSize(10);
            action->setFont(f);
            QMenu *currentMenu = findStack(book);

            addNotebookMenuItem(currentMenu, action);

            if (currentNotebookName == "" && book.__isset.defaultNotebook &&
                    book.defaultNotebook) {
                currentNotebookName = QString::fromStdString(book.name);
                setText(currentNotebookName);
                currentAction = actions.size()-1;
            }
            if (QString::fromStdString(book.name) == currentNotebookName) {
                action->setChecked(true);
            }
        }
    }
}
コード例 #7
0
bool NoteTable::updateNoteList(qint32 lid, Note &t, bool isDirty) {

    NotebookTable notebookTable;
    qint32 notebookLid = notebookTable.getLid(t.notebookGuid);
    Notebook notebook;
    notebookTable.get(notebook, notebookLid);
    // Now let's update the user table
    QSqlQuery query;

    query.prepare("Delete from NoteTable where lid=:lid");
    query.bindValue(":lid", lid);
    query.exec();

    query.prepare(QString("Insert into NoteTable (lid, title, author, ") +
                  QString("dateCreated, dateUpdated, dateSubject, dateDeleted, source, sourceUrl, sourceApplication, ") +
                  QString("latitude, longitude, altitude, hasEncryption, hasTodo, isDirty, size, notebook, notebookLid, tags) ") +
                  QString("Values (:lid, :title, :author, ") +
                  QString(":dateCreated, :dateUpdated, :dateSubject, :dateDeleted, :source, :sourceUrl, :sourceApplication, ") +
                  QString(":latitude, :longitude, :altitude, :hasEncryption, :hasTodo, :isDirty, :size, :notebook, :notebookLid, :tags) ")) ;

    query.bindValue(":lid", lid);

    if (t.__isset.title)
        query.bindValue(":title", QString::fromStdString(t.title));
    else
        query.bindValue(":title", "");
    if (t.__isset.attributes && t.attributes.__isset.author)
        query.bindValue(":author", QString::fromStdString(t.attributes.author));
    else
        query.bindValue(":author", "");
    if (t.__isset.created)
        query.bindValue(":dateCreated", QVariant::fromValue(t.created));
    else
        query.bindValue(":dateCreated", 0);
    if (t.__isset.updated)
        query.bindValue(":dateUpdated", QVariant::fromValue(t.updated));
    else
        query.bindValue(":dateUpdated", 0);
    if (t.__isset.attributes && t.attributes.__isset.subjectDate)
        query.bindValue(":dateSubject", QVariant::fromValue(t.attributes.subjectDate));
    else
        query.bindValue(":dateSubject", 0);
    if (t.__isset.deleted)
        query.bindValue(":dateDeleted", QVariant::fromValue(t.deleted));
    else
        query.bindValue(":dateDeleted", 0);
    if (t.__isset.attributes && t.attributes.__isset.source)
        query.bindValue(":source", QString::fromStdString(t.attributes.source));
    else
        query.bindValue(":source", "");
    if (t.__isset.attributes && t.attributes.__isset.sourceURL)
        query.bindValue(":sourceUrl", QString::fromStdString(t.attributes.sourceURL));
    else
        query.bindValue(":sourceUrl", "");
    if (t.__isset.attributes && t.attributes.__isset.sourceApplication)
        query.bindValue(":sourceApplication", QString::fromStdString(t.attributes.sourceApplication));
    else
        query.bindValue(":sourceApplication", "");
    if (t.__isset.attributes && t.attributes.__isset.latitude)
        query.bindValue(":latitude", QVariant::fromValue(t.attributes.latitude));
    else
        query.bindValue(":latitude", 0);
    if (t.__isset.attributes && t.attributes.__isset.longitude)
        query.bindValue(":longitude", QVariant::fromValue(t.attributes.longitude));
    else
        query.bindValue(":longitude", 0);
    if (t.__isset.attributes && t.attributes.__isset.altitude)
        query.bindValue(":altitude", QVariant::fromValue(t.attributes.altitude));
    else
        query.bindValue(":altitude", 0);


    bool hasEncryption;
    if (t.content.find("<en-crypt") != string::npos)
        hasEncryption = true;
    else
        hasEncryption = false;
    query.bindValue(":hasEncryption", hasEncryption);
    bool hasTodo;
    if (t.content.find("<en-todo") != string::npos)
        hasTodo = true;
    else
        hasTodo = false;
    query.bindValue(":hasTodo", hasTodo);
    query.bindValue(":isDirty", isDirty);
    qlonglong size = t.content.length();
    for (unsigned int i=0; i<t.resources.size(); i++) {
        size+=t.resources[i].data.size;
    }
    query.bindValue(":size", size);

    query.bindValue(":notebook", QString::fromStdString(notebook.name));
    query.bindValue(":notebookLid", notebookLid);

    QString tagNames;
    QStringList sortedNames;
    for (unsigned int i=0; i<t.tagNames.size(); i++) {
        sortedNames.append(QString::fromStdString(t.tagNames.at(i)).toLower());
    }
    sortedNames.sort();

    TagTable tagTable;
    LinkedNotebookTable linkedTable;
    qint32 account = 0;
    notebookLid = notebookTable.getLid(t.notebookGuid);
    if (linkedTable.exists(notebookLid))
        account = notebookLid;

    for (int i=0; i<sortedNames.size(); i++) {
        if (i>0)
            tagNames = tagNames+", ";
        Tag currentTag;
        qint32 tagLid = tagTable.findByName(sortedNames[i], account);
        tagTable.get(currentTag, tagLid);
        tagNames = tagNames + QString::fromStdString(currentTag.name);
    }

    query.bindValue(":tags", tagNames);

    if (!query.exec()) {
        QLOG_ERROR() << "Error inserting into NoteTable: " << query.lastError();
        return false;
    }
    return true;
}