Skip to content

Commit

Permalink
Added favorites selection criteria.
Browse files Browse the repository at this point in the history
  • Loading branch information
baumgarr committed Apr 16, 2014
1 parent 042202a commit 1d0fa91
Show file tree
Hide file tree
Showing 57 changed files with 2,075 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: nixnote2
# Generated by qmake (2.01a) (Qt 4.8.4) on: Sun Apr 13 09:42:30 2014
# Generated by qmake (2.01a) (Qt 4.8.4) on: Mon Apr 14 12:09:47 2014
# Project: NixNote2.pro
# Template: app
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile NixNote2.pro
Expand Down
146 changes: 140 additions & 6 deletions Makefile.Debug

Large diffs are not rendered by default.

146 changes: 140 additions & 6 deletions Makefile.Release

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions NixNote2.pro
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ SOURCES += main.cpp\
qevercloud/generated/constants.cpp \
qevercloud/generated/services.cpp \
qevercloud/generated/types.cpp \
gui/traymenu.cpp
gui/traymenu.cpp \
gui/favoritesview.cpp \
gui/favoritesviewdelegate.cpp \
gui/favoritesviewitem.cpp \
sql/favoritestable.cpp \
sql/favoritesrecord.cpp



Expand Down Expand Up @@ -348,7 +353,12 @@ HEADERS += nixnote.h \
qevercoud/generated/types_impl.h \
qevercloud/include/QEverCloud.h \
qevercloud/include/QEverCloudOAuth.h \
gui/traymenu.h
gui/traymenu.h \
gui/favoritesview.h \
gui/favoritesviewdelegate.h \
gui/favoritesviewitem.h \
sql/favoritestable.h \
sql/favoritesrecord.h


#INCLUDEPATH += /usr/local/include/thrift \
Expand Down
1 change: 1 addition & 0 deletions NixNote2.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
<file alias="collapsed.png">images/collapsed.png</file>
<file alias="htmlentities.png">images/htmlentities.png</file>
<file alias="screenCapture.png">images/screenCapture.png</file>
<file alias="favorites.png">images/favorites.png</file>
</qresource>
</RCC>
29 changes: 29 additions & 0 deletions filters/filtercriteria.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ FilterCriteria::FilterCriteria(QObject *parent) :
content = -1;
contentIsSet = false;

favoriteIsSet = false;
favoriteLid = -1;
resetFavorite = false;

resetNotebook = false;
resetTags = false;
Expand Down Expand Up @@ -228,7 +231,32 @@ void FilterCriteria::unsetSearchString() {




qint32 FilterCriteria::getFavorite() {
return favoriteLid;
}

void FilterCriteria::setFavorite(qint32 lid) {
favoriteLid = lid;
favoriteIsSet = true;
valueSet = true;
}

bool FilterCriteria::isFavoriteSet() {
return favoriteIsSet;
}

void FilterCriteria::unsetFavorite() {
favoriteIsSet = false;
}




void FilterCriteria::duplicate(FilterCriteria &newFilter) {
if (favoriteIsSet)
newFilter.setFavorite(favoriteLid);

if (attributeIsSet)
newFilter.setAttribute(*attribute);

Expand Down Expand Up @@ -260,6 +288,7 @@ void FilterCriteria::duplicate(FilterCriteria &newFilter) {
if (attributeIsSet)
newFilter.setAttribute(*attribute);

newFilter.resetFavorite = resetFavorite;
newFilter.resetNotebook = resetNotebook;
newFilter.resetTags = resetTags;
newFilter.resetSavedSearch = resetSavedSearch;
Expand Down
9 changes: 9 additions & 0 deletions filters/filtercriteria.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class FilterCriteria : public QObject
QString searchString;
bool searchStringIsSet;

qint32 favoriteLid;
bool favoriteIsSet;

bool deletedOnly;
bool deletedOnlyIsSet;

Expand Down Expand Up @@ -110,6 +113,12 @@ class FilterCriteria : public QObject
void unsetSearchString();
bool resetSearchString;

qint32 getFavorite();
void setFavorite(qint32 lid);
bool isFavoriteSet();
void unsetFavorite();
bool resetFavorite;

void duplicate(FilterCriteria &criteria);


Expand Down
58 changes: 58 additions & 0 deletions filters/filterengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "sql/notebooktable.h"
#include "sql/resourcetable.h"
#include "sql/nsqlquery.h"
#include "sql/favoritesrecord.h"
#include "sql/favoritestable.h"

#include <QtSql>

Expand All @@ -33,6 +35,8 @@ void FilterEngine::filter() {

FilterCriteria *criteria = global.filterCriteria[global.filterPosition];

QLOG_DEBUG() << "Filtering favorite";
filterFavorite(criteria);
QLOG_DEBUG() << "Filtering notebooks";
filterNotebook(criteria);
QLOG_DEBUG() << "Filtering tags";
Expand Down Expand Up @@ -364,6 +368,57 @@ void FilterEngine::filterAttributes(FilterCriteria *criteria) {



void FilterEngine::filterFavorite(FilterCriteria *criteria) {
if (!criteria->isSet() || !criteria->isFavoriteSet())
return;

FavoritesTable ftable(global.db);
FavoritesRecord rec;
if (!ftable.get(rec, criteria->getFavorite()))
return;

if (rec.type == FavoritesRecord::ConflictNotebook ||
rec.type == FavoritesRecord::LocalNotebook ||
rec.type == FavoritesRecord::LinkedNotebook ||
rec.type == FavoritesRecord::SharedNotebook ||
rec.type == FavoritesRecord::SynchronizedNotebook) {
qint32 notebookLid = rec.target.toInt();
NotebookTable ntable(global.db);
QString guid="";
if (ntable.getGuid(guid, notebookLid)) {
filterIndividualNotebook(guid);
}
return;
}

if (rec.type == FavoritesRecord::NotebookStack ||
rec.type == FavoritesRecord::LinkedStack) {
QString stackname = rec.target.toString();
filterStack(stackname);
return;
}

if (rec.type == FavoritesRecord::Tag) {
NoteTable noteTable(global.db);
TagTable tagTable(global.db);
NSqlQuery sql(*global.db);
sql.exec("create temporary table if not exists goodLids (lid integer)");
sql.exec("delete from goodLids");
QList<qint32> notes;
QString tagGuid="";
tagTable.getGuid(tagGuid, rec.target.toInt());
noteTable.getNotesWithTag(notes, tagGuid);
sql.prepare("insert into goodLids (lid) values (:note)");
for (qint32 i=0; i<notes.size(); i++) {
sql.bindValue(":note", notes[i]);
sql.exec();
}
sql.exec("delete from filter where lid not in (select lid from goodLids)" );

}

}

void FilterEngine::filterNotebook(FilterCriteria *criteria) {
if (!criteria->isSet() || !criteria->isNotebookSet())
return;
Expand All @@ -382,6 +437,9 @@ void FilterEngine::filterNotebook(FilterCriteria *criteria) {
}
}




// If they only chose one notebook, then delete everything else
void FilterEngine::filterIndividualNotebook(QString &notebook) {
NotebookTable notebookTable(global.db);
Expand Down
1 change: 1 addition & 0 deletions filters/filterengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FilterEngine : public QObject
{
Q_OBJECT
private:
void filterFavorite(FilterCriteria *criteria);
void filterNotebook(FilterCriteria *criteria);
void filterIndividualNotebook(QString &guid);
void filterStack(QString& stack);
Expand Down
1 change: 1 addition & 0 deletions global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Global::Global()
criteria->resetTags = true;
criteria->resetSavedSearch = true;
criteria->resetAttribute = true;
criteria->resetFavorite = true;
criteria->resetDeletedOnly = true;
criteria->setDeletedOnly(false);
criteria->resetLid = true;
Expand Down
20 changes: 20 additions & 0 deletions gui/externalbrowse.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*********************************************************************************
NixNote - An open-source client for the Evernote service.
Copyright (C) 2014 Randy Baumgarte
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***********************************************************************************/


#include "externalbrowse.h"
#include <QGridLayout>
#include <QLayout>
Expand Down
21 changes: 21 additions & 0 deletions gui/externalbrowse.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*********************************************************************************
NixNote - An open-source client for the Evernote service.
Copyright (C) 2014 Randy Baumgarte
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***********************************************************************************/



#ifndef EXTERNALBROWSE_H
#define EXTERNALBROWSE_H

Expand Down
Loading

0 comments on commit 1d0fa91

Please sign in to comment.