Create a new note
| 1988 | // Create a new note |
| 1989 | //***************************** |
| 1990 | void NixNote::newNote() { |
| 1991 | if (noteButton->property("currentNoteButton").toInt() != NewTextNote) { |
| 1992 | noteButton->setText(newNoteButton->text()); |
| 1993 | noteButton->setIcon(newNoteButton->icon()); |
| 1994 | noteButton->setProperty("currentNoteButton", NewTextNote); |
| 1995 | } |
| 1996 | QString newNoteBody = QString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")+ |
| 1997 | QString("<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">")+ |
| 1998 | QString("<en-note style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;\"><br/></en-note>"); |
| 1999 | |
| 2000 | Note n; |
| 2001 | NotebookTable notebookTable(global.db); |
| 2002 | n.content = newNoteBody; |
| 2003 | n.title = tr("Untitled note"); |
| 2004 | QString uuid = QUuid::createUuid().toString(); |
| 2005 | uuid = uuid.mid(1); |
| 2006 | uuid.chop(1); |
| 2007 | n.guid = uuid; |
| 2008 | n.active = true; |
| 2009 | //QDateTime now; |
| 2010 | n.created = QDateTime::currentMSecsSinceEpoch(); |
| 2011 | n.updated = n.created; |
| 2012 | n.updateSequenceNum = 0; |
| 2013 | if (notebookTreeView->selectedItems().size() > 0) { |
| 2014 | NNotebookViewItem *item = (NNotebookViewItem*)notebookTreeView->selectedItems().at(0); |
| 2015 | qint32 lid = item->lid; |
| 2016 | |
| 2017 | // If we have a stack, we find the first notebook (in alphabetical order) for the new note. |
| 2018 | if (lid == 0) { |
| 2019 | QString stackName = notebookTreeView->selectedItems().at(0)->data(0, Qt::DisplayRole).toString(); |
| 2020 | QList<qint32> notebooks; |
| 2021 | notebookTable.getStack(notebooks, stackName); |
| 2022 | QString priorName; |
| 2023 | Notebook book; |
| 2024 | if (notebooks.size() > 0) { |
| 2025 | for (int i=0; i<notebooks.size(); i++) { |
| 2026 | qint32 priorLid = notebooks[i]; |
| 2027 | notebookTable.get(book, priorLid); |
| 2028 | QString currentName = ""; |
| 2029 | if (book.name.isSet()) |
| 2030 | currentName = book.name; |
| 2031 | if (currentName.toUpper() < priorName.toUpper() || priorName == "") { |
| 2032 | lid = notebooks[i]; |
| 2033 | } |
| 2034 | priorLid = notebooks[i]; |
| 2035 | priorName = currentName; |
| 2036 | } |
| 2037 | } |
| 2038 | } |
| 2039 | QString notebookGuid; |
| 2040 | notebookTable.getGuid(notebookGuid, lid); |
| 2041 | n.notebookGuid = notebookGuid; |
| 2042 | } else { |
| 2043 | QList<QTreeWidgetItem *>items = favoritesTreeView->selectedItems(); |
| 2044 | QString notebookGuid = notebookTable.getDefaultNotebookGuid(); |
| 2045 | for (int i=0; i<items.size(); i++) { |
| 2046 | FavoritesViewItem *item = (FavoritesViewItem*)items[i]; |
| 2047 | if (item->record.type == FavoritesRecord::LocalNotebook || |
no test coverage detected