// Open a selected note. This is not done via the context menu. void NTableView::openSelectedLids(bool newWindow) { QList<qint32> lids; getSelectedLids(lids); if (lids.size() == 0) return; // First, find out if we're already viewing history. If we are we // chop off the end of the history & start a new one if (global.filterPosition+1 < global.filterCriteria.size()) { while (global.filterPosition+1 < global.filterCriteria.size()) delete global.filterCriteria.takeAt(global.filterCriteria.size()-1); } FilterCriteria *newFilter = new FilterCriteria(); global.filterCriteria.at(global.filterPosition)->duplicate(*newFilter); newFilter->setSelectedNotes(lids); if (lids.size() > 0) newFilter->setLid(lids.at(0)); global.filterCriteria.push_back(newFilter); global.filterPosition++; if (lids.size() > 0) { emit openNote(newWindow); } }
//************************************************************* // This function is called when a user selects something // within this tree. It also emits a signal that will // be picked up by the main nixnote program. //************************************************************* void FavoritesView::buildSelection() { QLOG_TRACE() << "Inside FavoritesView::buildSelection()"; QList<QTreeWidgetItem*> selectedItems = this->selectedItems(); // First, find out if we're already viewing history. If we are we // chop off the end of the history & start a new one if (global.filterPosition+1 < global.filterCriteria.size()) { while (global.filterPosition+1 < global.filterCriteria.size()) global.filterCriteria.removeLast(); } filterPosition++; FilterCriteria *newFilter = new FilterCriteria(); global.filterCriteria.push_back(newFilter); global.filterPosition++; if (selectedItems.size() > 0) { qint32 lid = selectedItems[0]->data(NAME_POSITION, Qt::UserRole).toInt(); if (lid>0) newFilter->setFavorite(lid); } newFilter->resetAttribute = true; newFilter->resetDeletedOnly = true; newFilter->resetNotebook =true; newFilter->resetTags = true; newFilter->resetSavedSearch = true; newFilter->resetSearchString = true; newFilter->resetSelectedNotes = true; emit updateSelectionRequested(); QLOG_TRACE() << "Leaving FavoritesView::buildSelection()"; }
/* If we have search criteria, then we highlight the text matching those results in the note. */ void NoteFormatter::setHighlight() { FilterCriteria *criteria = global.filterCriteria[global.filterPosition]; if (criteria->isSearchStringSet()) enableHighlight = true; else enableHighlight = false; }
//************************************************************* // This function is called from the main NixNote class. // it will reset the items which are selected based upon // what the user did somewhere else (outside this widget). //************************************************************* void LineEdit::updateSelection() { blockSignals(true); FilterCriteria *criteria = global.filterCriteria[global.filterPosition]; // if (criteria->resetSearchString) { // this->blockSignals(true); // this->setText(defaultText); // setStyleSheet(inactiveColor); // this->blockSignals(false); // } if (global.filterPosition != filterPosition) { if (criteria->resetSearchString) { setText(defaultText); setStyleSheet(inactiveColor); } if (criteria->isSearchStringSet()) { setText(criteria->getSearchString()); setStyleSheet(activeColor); } } filterPosition = global.filterPosition; blockSignals(false); }
// A tag was selected so a new FilterCriteria is created and the // filtered table will display the results. void NTagView::buildSelection() { QLOG_TRACE() << "Inside NTagView::buildSelection()"; QList<QTreeWidgetItem*> selectedItems = this->selectedItems(); if (selectedItems.size() > 0 && selectedItems[0]->data(0,Qt::UserRole) == "root") return; // First, find out if we're already viewing history. If we are we // chop off the end of the history & start a new one if (global.filterPosition+1 < global.filterCriteria.size()) { while (global.filterPosition+1 < global.filterCriteria.size()) global.filterCriteria.removeLast(); } filterPosition++; FilterCriteria *newFilter = new FilterCriteria(); global.filterCriteria.push_back(newFilter); global.filterPosition++; if (selectedItems.size() > 0) { newFilter->setTags(selectedItems); } newFilter->resetAttribute = true; newFilter->resetDeletedOnly = true; newFilter->resetSavedSearch = true; newFilter->resetFavorite = true; newFilter->resetTags = true; emit updateSelectionRequested(); QLOG_TRACE() << "Leaving NTagView::buildSelection()"; }
// The note list changed, so we need to reselect any valid notes. void NTableView::refreshSelection() { this->blockSignals(true); FilterCriteria *criteria = global.filterCriteria[global.filterPosition]; QList<qint32> historyList; criteria->getSelectedNotes(historyList); QLOG_TRACE() << "Highlighting selected rows after refresh"; // Check the highlighted LIDs from the history selection. for (int i=0; i<historyList.size(); i++) { if (proxy->lidMap->contains(historyList[i])) { int rowLocation = proxy->lidMap->value(historyList[i]); if (rowLocation > 0) { QModelIndex modelIndex = model()->index(rowLocation,NOTE_TABLE_LID_POSITION); QModelIndex proxyIndex = proxy->mapFromSource(modelIndex); rowLocation = proxyIndex.row(); selectRow(rowLocation); } } } QLOG_TRACE() << "Highlighting complete"; // Make sure at least one thing is selected QLOG_TRACE() << "Selecting one item if nothing else is selected"; QModelIndexList l = selectedIndexes(); if (l.size() == 0) { qint32 rowLid = selectAnyNoteFromList(); criteria->setLid(rowLid); } QLOG_TRACE() << "refleshSelection() complete"; this->blockSignals(false); }
//************************************************************* // This function is called when a user selects something // within this tree. It also emits a signal that will // be picked up by the main nixnote program. //************************************************************* void NTrashTree::buildSelection() { QLOG_TRACE() << "Inside NTrashTree::buildSelection()"; // First, find out if we're already viewing history. If we are we // chop off the end of the history & start a new one if (global.filterPosition+1 < global.filterCriteria.size()) { while (global.filterPosition+1 < global.filterCriteria.size()) global.filterCriteria.removeLast(); } filterPosition++; FilterCriteria *newFilter = new FilterCriteria(); global.filterCriteria.push_back(newFilter); global.filterPosition++; if (root->isSelected()) newFilter->setDeletedOnly(true); else newFilter->setDeletedOnly(false); newFilter->resetSavedSearch = true; newFilter->resetDeletedOnly = true; newFilter->resetAttribute = true; newFilter->resetFavorite = true; newFilter->resetNotebook =true; newFilter->resetTags = true; newFilter->resetSearchString = true; emit updateSelectionRequested(); QLOG_TRACE() << "Leaving NTrashTree::buildSelection()"; }
void FilterCriteria::duplicate(FilterCriteria &newFilter) { if (attributeIsSet) newFilter.setAttribute(*attribute); if (contentIsSet) newFilter.setContent(content); if (deletedOnlyIsSet) newFilter.setDeletedOnly(deletedOnly); if (selectedNotesIsSet) newFilter.setSelectedNotes(selectedNotes); if (tagsIsSet) newFilter.setTags(tags); if (savedSearch) newFilter.setSavedSearch(*savedSearch); if (searchStringIsSet) newFilter.setSearchString(searchString); if (attributeIsSet) newFilter.setAttribute(*attribute); newFilter.resetNotebook = resetNotebook; newFilter.resetTags = resetTags; newFilter.resetSavedSearch = resetSavedSearch; newFilter.resetAttribute = resetAttribute; newFilter.resetDeletedOnly = resetDeletedOnly; newFilter.resetContent = resetContent; newFilter.resetSearchString = resetSearchString; }
// Delete the selected notes void NTableView::deleteSelectedNotes() { QList<qint32> lids; this->getSelectedLids(lids); if (lids.size() == 0) return; QString typeDelete; QString msg; FilterCriteria *f = global.filterCriteria[global.filterPosition]; bool expunged = false; typeDelete = tr("Delete "); if (f->isDeletedOnlySet() && f->getDeletedOnly()) { typeDelete = tr("Permanently delete "); expunged = true; } if (lids.size() == 1) msg = typeDelete + tr("selected note?"); else msg = typeDelete +QString::number(lids.size()) + " notes?"; QMessageBox msgBox; msgBox.setWindowTitle(tr("Verify Delete")); msgBox.setText(msg); 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(global.db); QSqlQuery sql(*global.db); QSqlQuery transaction(*global.db); //transaction.exec("begin"); sql.prepare("Delete from filter where lid=:lid"); for (int i=0; i<lids.size(); i++) { ntable.deleteNote(lids[i], true); if (expunged) ntable.expunge(lids[i]); sql.bindValue(":lid", lids[i]); sql.exec(); delete global.cache[lids[i]]; global.cache.remove(lids[i]); } //transaction.exec("commit"); emit(notesDeleted(lids, expunged)); }
//************************************************************* // This function is called when a user selects something // within this tree. It also emits a signal that will // be picked up by the main nixnote program. //************************************************************* void NAttributeTree::buildSelection() { QLOG_TRACE() << "Inside NNotebookView::buildSelection()"; QList<QTreeWidgetItem*> selectedItems = this->selectedItems(); if (selectedItems.size() > 0 && selectedItems[0]->data(0,Qt::UserRole) == "root") { blockSignals(true); root->setSelected(false); blockSignals(false); return; } for (int i=0; i<selectedItems.size(); i++) { QTreeWidgetItem *item = selectedItems[i]; if (item->data(0, Qt::UserRole) == 0 || item->data(0,Qt::UserRole) == "root") { item->setSelected(false); } } selectedItems = this->selectedItems(); if (selectedItems.size() == 0) return; // First, find out if we're already viewing history. If we are we // chop off the end of the history & start a new one if (global.filterPosition+1 < global.filterCriteria.size()) { while (global.filterPosition+1 < global.filterCriteria.size()) global.filterCriteria.removeLast(); } filterPosition++; FilterCriteria *newFilter = new FilterCriteria(); global.filterCriteria.push_back(newFilter); global.filterPosition++; if (selectedItems.size() > 0) { newFilter->setAttribute(*(selectedItems[0])); } newFilter->resetSavedSearch = true; newFilter->resetDeletedOnly = true; newFilter->resetNotebook =true; newFilter->resetTags = true; newFilter->resetAttribute = true; newFilter->resetFavorite = true; newFilter->resetSearchString = true; emit updateSelectionRequested(); QLOG_TRACE() << "Leaving NNotebookView::buildSelection()"; }
//************************************************************* // This function is called when a user selects something // within this tree. It also emits a signal that will // be picked up by the main nixnote program. //************************************************************* void FavoritesView::buildSelection() { QLOG_TRACE() << "Inside FavoritesView::buildSelection()"; QList<QTreeWidgetItem*> selectedItems = this->selectedItems(); // First, find out if we're already viewing history. If we are we // chop off the end of the history & start a new one if (global.filterPosition+1 < global.filterCriteria.size()) { while (global.filterPosition+1 < global.filterCriteria.size()) global.filterCriteria.removeLast(); } filterPosition++; FilterCriteria *newFilter = new FilterCriteria(); global.filterCriteria.push_back(newFilter); global.filterPosition++; if (selectedItems.size() > 0) { qint32 lid = selectedItems[0]->data(NAME_POSITION, Qt::UserRole).toInt(); if (lid>0) { newFilter->setFavorite(lid); FavoritesViewItem *item = (FavoritesViewItem*)selectedItems[0]; if (item->record.type == FavoritesRecord::Note) { newFilter->setLid(item->record.target.toInt()); } if (item->record.type == FavoritesRecord::Search) { SavedSearch search; SearchTable table(global.db); QLOG_DEBUG() << item->record.target.toInt(); table.get(search, item->record.target.toInt()); if (search.query.isSet()) newFilter->setSearchString(search.query); } } } newFilter->resetAttribute = true; newFilter->resetDeletedOnly = true; newFilter->resetNotebook =true; newFilter->resetTags = true; newFilter->resetSavedSearch = true; newFilter->resetSearchString = true; newFilter->resetSelectedNotes = true; emit updateSelectionRequested(); QLOG_TRACE() << "Leaving FavoritesView::buildSelection()"; }
//************************************************************* // This function is called when a user selects something // within this tree. It also emits a signal that will // be picked up by the main nixnote program. //************************************************************* void LineEdit::buildSelection() { QLOG_TRACE() << "Inside LineEdit::buildSelection()"; savedText = text().trimmed(); // First, find out if we're already viewing history. If we are we // chop off the end of the history & start a new one if (global.filterPosition+1 < global.filterCriteria.size()) { while (global.filterPosition+1 < global.filterCriteria.size()) global.filterCriteria.removeLast(); } filterPosition++; FilterCriteria *newFilter = new FilterCriteria(); global.filterCriteria.push_back(newFilter); FilterCriteria *oldFilter = global.filterCriteria[global.filterPosition]; global.filterPosition++; newFilter->setSearchString(text()); newFilter->resetNotebook = true; newFilter->resetTags = true; newFilter->resetAttribute = true; newFilter->resetFavorite = true; newFilter->resetDeletedOnly = true; newFilter->resetSavedSearch = true; QList<qint32> oldLids; oldFilter->getSelectedNotes(oldLids); newFilter->setSelectedNotes(oldLids); newFilter->setLid(oldFilter->getLid()); emit updateSelectionRequested(); QLOG_TRACE() << "Leaving LineEdit::buildSelection()"; }
//************************************************************* // This function is called when a user selects something // within this tree. It also emits a signal that will // be picked up by the main nixnote program. //************************************************************* void NNotebookView::buildSelection() { QLOG_TRACE() << "Inside NNotebookView::buildSelection()"; QList<QTreeWidgetItem*> selectedItems = this->selectedItems(); if (selectedItems.size() > 0 && selectedItems[0]->data(0,Qt::UserRole).toString().startsWith("root"), Qt::CaseInsensitive) return; // First, find out if we're already viewing history. If we are we // chop off the end of the history & start a new one if (global.filterPosition+1 < global.filterCriteria.size()) { while (global.filterPosition+1 < global.filterCriteria.size()) global.filterCriteria.removeLast(); } int currentCount = global.filterCriteria.size(); FilterCriteria *newFilter = new FilterCriteria(); if (currentCount > 0) { FilterCriteria *currentFilter = global.filterCriteria[currentCount-1]; if (currentFilter->isLidSet()) { newFilter->setLid(currentFilter->getLid()); } if (currentFilter->isSelectedNotesSet()) { QList<qint32> lids; currentFilter->getSelectedNotes(lids); newFilter->setSelectedNotes(lids); } } global.filterCriteria.push_back(newFilter); filterPosition++; global.filterPosition++; if (selectedItems.size() > 0) { newFilter->setNotebook(*(selectedItems[0])); } qint32 notebookLid = 0; if (selectedItems.size() > 0) notebookLid = selectedItems[0]->data(NAME_POSITION, Qt::UserRole).toInt(); newFilter->resetAttribute = true; newFilter->resetDeletedOnly = true; newFilter->resetFavorite = true; newFilter->resetNotebook = true; newFilter->resetSavedSearch = true; newFilter->resetTags = true; newFilter->resetSearchString = true; emit updateSelectionRequested(); emit notebookSelectionChanged(notebookLid); QLOG_TRACE() << "Leaving NNotebookView::buildSelection()"; }
//************************************************************* // This function is called from the main NixNote class. // it will reset the items which are selected based upon // what the user did somewhere else (outside this widget). //************************************************************* void NTrashTree::updateSelection() { blockSignals(true); FilterCriteria *criteria = global.filterCriteria[global.filterPosition]; if (global.filterPosition != filterPosition) { QList<QTreeWidgetItem*> selectedItems = this->selectedItems(); for (int i=0; i<selectedItems.size() && criteria->resetDeletedOnly; i++) { selectedItems[i]->setSelected(false); } if (criteria->isDeletedOnlySet() && criteria->getDeletedOnly()) { root->setSelected(true); } } filterPosition = global.filterPosition; blockSignals(false); }
//************************************************************* // This function is called from the main NixNote class. // it will reset the items which are selected based upon // what the user did somewhere else (outside this widget). //************************************************************* void FavoritesView::updateSelection() { blockSignals(true); FilterCriteria *criteria = global.filterCriteria[global.filterPosition]; if (global.filterPosition != filterPosition) { QList<QTreeWidgetItem*> selectedItems = this->selectedItems(); for (int i=0; i<selectedItems.size(); i++) { selectedItems[i]->setSelected(false); } } if (criteria->isFavoriteSet()) { dataStore[criteria->getFavorite()]->setSelected(true); } filterPosition = global.filterPosition; blockSignals(false); }
void NTagView::updateSelection() { blockSignals(true); FilterCriteria *criteria = global.filterCriteria[global.filterPosition]; if (global.filterPosition != filterPosition) { QList<QTreeWidgetItem*> selectedItems = this->selectedItems(); for (int i=0; i<selectedItems.size() && criteria->resetTags; i++) { selectedItems[i]->setSelected(false); } for (int i=0; i<criteria->getTags().size() && criteria->isTagsSet(); i++) { criteria->getTags()[i]->setSelected(true); } } root->setSelected(false); filterPosition = global.filterPosition; blockSignals(false); }
//****************************************** //* Global settings used by the program //****************************************** Global::Global() { dbLock = new QReadWriteLock(QReadWriteLock::Recursive); listView = ListViewWide; FilterCriteria *criteria = new FilterCriteria(); filterCriteria.push_back(criteria); filterPosition = 0; criteria->resetNotebook = true; criteria->resetTags = true; criteria->resetSavedSearch = true; criteria->resetAttribute = true; criteria->resetFavorite = true; criteria->resetDeletedOnly = true; criteria->setDeletedOnly(false); criteria->resetLid = true; criteria->resetSearchString = true; username = ""; password = ""; javaFound = false; }
//************************************************************* // This function is called from the main NixNote class. // it will reset the items which are selected based upon // what the user did somewhere else (outside this widget). //************************************************************* void NNotebookView::updateSelection() { blockSignals(true); FilterCriteria *criteria = global.filterCriteria[global.filterPosition]; if (global.filterPosition != filterPosition) { QList<QTreeWidgetItem*> selectedItems = this->selectedItems(); for (int i=0; i<selectedItems.size() && criteria->resetNotebook; i++) { selectedItems[i]->setSelected(false); } if (criteria->isNotebookSet()) { criteria->getNotebook()->setSelected(true); } } filterPosition = global.filterPosition; if (selectedItems().size() == 0) root->setSelected(false); blockSignals(false); }
// A user asked to open new notes via the context menu. void NTableView::openNoteContextMenuTriggered() { QList<qint32> lids; getSelectedLids(lids); if (lids.size() == 0) return; // First, find out if we're already viewing history. If we are we // chop off the end of the history & start a new one if (global.filterPosition+1 < global.filterCriteria.size()) { while (global.filterPosition+1 < global.filterCriteria.size()) delete global.filterCriteria.takeAt(global.filterCriteria.size()-1); } for (int i=0; i<lids.size(); i++) { FilterCriteria *newFilter = new FilterCriteria(); global.filterCriteria.at(global.filterPosition)->duplicate(*newFilter); newFilter->setSelectedNotes(lids); newFilter->setLid(lids.at(i)); global.filterCriteria.push_back(newFilter); global.filterPosition++; emit openNote(true); } }
void FilterCriteria::duplicate(FilterCriteria &newFilter) { if (attributeIsSet) newFilter.setAttribute(*attribute); if (contentIsSet) newFilter.setLid(content); for (int i=0; i<selectedNotes.size(); i++) { newFilter.selectedNotes.append(selectedNotes[i]); } if (deletedOnlyIsSet) newFilter.setDeletedOnly(deletedOnly); if (selectedNotesIsSet) newFilter.setSelectedNotes(selectedNotes); if (tagsIsSet) newFilter.setTags(tags); if (savedSearch) newFilter.setSavedSearch(*savedSearch); if (searchStringIsSet) newFilter.setSearchString(searchString); if (attributeIsSet) newFilter.setAttribute(*attribute); newFilter.resetNotebook = resetNotebook; newFilter.resetTags = resetTags; newFilter.resetSavedSearch = resetSavedSearch; newFilter.resetAttribute = resetAttribute; newFilter.resetDeletedOnly = resetDeletedOnly; newFilter.resetLid = resetLid; newFilter.resetSearchString = resetSearchString; }
// Do the alter. If the notebook is not found we create it. // If a tag is not found for an add, we add it. If a tag is // not found for a deleteTag, we just ignore it. int AlterNote::alterNote() { // If a query is specified, we find the matching notes. if (query != "") { FilterCriteria *filter = new FilterCriteria(); global.filterCriteria.append(filter); global.filterPosition = 0; FilterEngine engine; filter->setSearchString(query); QList<qint32> lids; engine.filter(filter, &lids); this->lids.append(lids); } NotebookTable bookTable(global.db); TagTable tagTable(global.db); NoteTable noteTable(global.db); // Loop through each note requested. for (int i=0; i<lids.size(); i++) { qint32 lid = lids[i]; // Do the notebook request if (notebook != "") { qint32 notebookLid = bookTable.findByName(notebook); if (notebookLid<0) { Notebook book; book.name = notebook; NUuid uuid; book.guid = uuid.create(); notebookLid = bookTable.add(0,book,true,true); } if (noteTable.getNotebookLid(lid) != notebookLid) noteTable.updateNotebook(lid, notebookLid, true); } // Add the tags for (int j=0; j<addTagNames.size(); j++) { qint32 tagLid = tagTable.findByName(addTagNames[j],0); if (tagLid <= 0) { Tag t; t.name = addTagNames[j]; NUuid uuid; t.guid = uuid.create(); tagLid = tagTable.add(0,t,true,0); } if (!noteTable.hasTag(lid,tagLid)) noteTable.addTag(lid, tagLid, true); } // Remove any tags specified for (int j=0; j<delTagNames.size(); j++) { qint32 tagLid = tagTable.findByName(delTagNames[j],0); if (tagLid > 0 && noteTable.hasTag(lid,tagLid)) { noteTable.removeTag(lid, tagLid, true); } } if (reminderCompleted) { noteTable.setReminderCompleted(lid, true); } if (clearReminder) { noteTable.removeReminder(lid); } } return 0; }