// pick the first notebook in the list.
String notebook = null;
listManager.getNotebookIndex().get(0).getGuid();
List<QTreeWidgetItem> selectedNotebook = notebookTree.selectedItems();
if (selectedNotebook.size() > 0 && !selectedNotebook.get(0).text(0).equalsIgnoreCase("All Notebooks") && !selectedNotebook.get(0).text(2).equalsIgnoreCase("STACK")) {
QTreeWidgetItem currentSelectedNotebook = selectedNotebook.get(0);
notebook = currentSelectedNotebook.text(2);
} else {
boolean found = false;
List<Notebook> goodNotebooks = new ArrayList<Notebook>();
for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
boolean match = false;
for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid())) {
match = true;
j = listManager.getArchiveNotebookIndex().size();
}
}
if (!match)
//goodNotebooks.add(listManager.getNotebookIndex().get(i).deepCopy());
goodNotebooks.add((Notebook)Global.deepCopy(listManager.getNotebookIndex().get(i)));
}
// Now we have a list of good notebooks, so we can look for the default
found = false;
for (int i=0; i<goodNotebooks.size(); i++) {
if (goodNotebooks.get(i).isDefaultNotebook()) {
notebook = goodNotebooks.get(i).getGuid();
found = true;
i = goodNotebooks.size();
}
}
if (goodNotebooks.size() > 0 && !found)
notebook = goodNotebooks.get(0).getGuid();
if (notebook==null)
notebook = listManager.getNotebookIndex().get(0).getGuid();
}
Note newNote = new Note();
newNote.setUpdateSequenceNum(0);
newNote.setGuid(randint);
newNote.setNotebookGuid(notebook);
newNote.setTitle("Untitled Note");
newNote.setContent(noteString.toString());
newNote.setDeleted(0);
newNote.setCreated(System.currentTimeMillis());
newNote.setUpdated(System.currentTimeMillis());
newNote.setActive(true);
NoteAttributes na = new NoteAttributes();
na.setLatitude(0.0);
na.setLongitude(0.0);
na.setAltitude(0.0);
newNote.setAttributes(new NoteAttributes());
newNote.setTagGuids(new ArrayList<String>());
newNote.setTagNames(new ArrayList<String>());
// If new notes are to be created based upon the selected tags, then we need to assign the tags
if (Global.newNoteWithSelectedTags()) {
List<QTreeWidgetItem> selections = tagTree.selectedItems();
QTreeWidgetItem currentSelection;
for (int i=0; i<selections.size(); i++) {
currentSelection = selections.get(i);
newNote.getTagGuids().add(currentSelection.text(2));
newNote.getTagNames().add(currentSelection.text(0));
}
}
conn.getNoteTable().addNote(newNote, true);
NoteMetadata metadata = new NoteMetadata();