MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / newExternalNote

Method newExternalNote

nixnote.cpp:2091–2166  ·  view source on GitHub ↗

Create a new note in an external window.

Source from the content-addressed store, hash-verified

2089//* Create a new note in an external window.
2090//**********************************************
2091void NixNote::newExternalNote() {
2092 QString newNoteBody = QString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")+
2093 QString("<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">")+
2094 QString("<en-note style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;\"><br/></en-note>");
2095
2096 Note n;
2097 NotebookTable notebookTable(global.db);
2098 n.content = newNoteBody;
2099 n.title = "Untitled note";
2100 QString uuid = QUuid::createUuid().toString();
2101 uuid = uuid.mid(1);
2102 uuid.chop(1);
2103 n.guid = uuid;
2104 n.active = true;
2105 //QDateTime now;
2106 n.created = QDateTime::currentMSecsSinceEpoch();
2107 n.updated = n.created;
2108 n.updateSequenceNum = 0;
2109 if (notebookTreeView->selectedItems().size() == 0) {
2110 n.notebookGuid = notebookTable.getDefaultNotebookGuid();
2111 } else {
2112 NNotebookViewItem *item = (NNotebookViewItem*)notebookTreeView->selectedItems().at(0);
2113 qint32 lid = item->lid;
2114
2115 // If we have a stack, we find the first notebook (in alphabetical order) for the new note.
2116 if (lid == 0) {
2117 QString stackName = notebookTreeView->selectedItems().at(0)->data(0, Qt::DisplayRole).toString();
2118 QList<qint32> notebooks;
2119 notebookTable.getStack(notebooks, stackName);
2120 QString priorName;
2121 Notebook book;
2122 if (notebooks.size() > 0) {
2123 for (int i=0; i<notebooks.size(); i++) {
2124 qint32 priorLid = notebooks[i];
2125 notebookTable.get(book, priorLid);
2126 QString currentName = "";
2127 if (book.name.isSet())
2128 currentName = book.name;
2129 if (currentName.toUpper() < priorName.toUpper() || priorName == "") {
2130 lid = notebooks[i];
2131 }
2132 priorLid = notebooks[i];
2133 priorName = currentName;
2134 }
2135 }
2136 }
2137 QString notebookGuid;
2138 notebookTable.getGuid(notebookGuid, lid);
2139 n.notebookGuid = notebookGuid;
2140 }
2141 NoteTable table(global.db);
2142 qint32 lid = table.add(0,n,true);
2143 tabWindow->openNote(lid, NTabWidget::ExternalWindow);
2144 updateSelectionCriteria();
2145
2146 // Find the position in the external window array & set the focus.
2147 int pos = -1;
2148 for (int i=0; i<tabWindow->externalList->size(); i++) {

Callers 3

NixNoteMethod · 0.95
trayActivatedMethod · 0.95

Calls 11

dataMethod · 0.80
newNoteFocusToTitleMethod · 0.80
QStringClass · 0.50
toStringMethod · 0.45
getStackMethod · 0.45
getMethod · 0.45
isSetMethod · 0.45
getGuidMethod · 0.45
addMethod · 0.45
openNoteMethod · 0.45

Tested by

no test coverage detected