1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*********************************************************************************
NixNote - An open-source client for the Evernote service.
Copyright (C) 2015 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 "remotequery.h"
#include "global.h"
#include "filters/filterengine.h"
extern Global global;
RemoteQuery::RemoteQuery(QObject *parent) :
QObject(parent)
{
this->initDbus();
note = NULL;
lid = -1;
}
void RemoteQuery::initDbus() {
return;
QLOG_DEBUG() << "inside InitDbus()";
if (!QDBusConnection::sessionBus().isConnected()) {
return;
}
QLOG_DEBUG() << "registerintg service()";
if (!QDBusConnection::sessionBus().registerService(DBUS_SERVICE_NAME)) {
fprintf(stderr, "%s\n",
qPrintable(QDBusConnection::sessionBus().lastError().message()));
exit(1);
}
QLOG_DEBUG() << "Registering object";
QDBusConnection::sessionBus().registerObject("/com/canonical/unity/scope/notes/NixNote/RemoteQuery", this, QDBusConnection::ExportAllSlots);
QLOG_DEBUG() << "leavining init";
}
Q_SCRIPTABLE bool RemoteQuery::setNote(qint32 lid) {
this->lid = lid;
NoteTable ntable(global.db);
if (note != NULL)
delete note;
note = new Note();
if (ntable.get(*note, lid, false,false))
return true;
delete note;
note = NULL;
return false;
}
Q_SCRIPTABLE QString RemoteQuery::getNoteTitle() {
if (note == NULL)
return "";
if (note->title.isSet())
return note->title;
return "";
}
Q_SCRIPTABLE QString RemoteQuery::query(const QString &arg) {
QList<qint32> results;
FilterCriteria filter;
filter.setSearchString(arg);
FilterEngine engine;
engine.filter(&filter, &results);
QString retVal = "";
for (int i=0; i<results.size(); i++) {
retVal = retVal+ QString::number(results[i]) + QString(" ");
}
return retVal.trimmed();
}
Q_SCRIPTABLE QString RemoteQuery::getNotePreview() {
QString filename = global.fileManager.getThumbnailDirPath("")+QString::number(lid)+".png";
QFile file(filename);
if (file.exists()) {
return filename;
}
return global.fileManager.getImageDirPath("")+QString("windowIcon0.png");
}
Q_SCRIPTABLE QString RemoteQuery::getNoteDateUpdated() {
qlonglong dt = 0;
if (note->updated.isSet())
dt = note->updated;
if (dt==0)
return "";
QDateTime timestamp;
timestamp.setTime_t(dt/1000);
if (timestamp.date() == QDate::currentDate())
return tr("Today") +" " + timestamp.time().toString(Qt::SystemLocaleShortDate);
return timestamp.toString(global.dateFormat + QString(" ") +global.timeFormat);
}
Q_SCRIPTABLE QString RemoteQuery::getNoteDateCreated() {
qlonglong dt = 0;
if (note->created.isSet())
dt = note->created;
if (dt==0)
return "";
QDateTime timestamp;
timestamp.setTime_t(dt/1000);
if (timestamp.date() == QDate::currentDate())
return tr("Today") +" " + timestamp.time().toString(Qt::SystemLocaleShortDate);
return timestamp.toString(global.dateFormat + QString(" ") +global.timeFormat);
}
Q_SCRIPTABLE QString RemoteQuery::getNoteTags() {
if (!note->tagNames.isSet())
return "";
QString taglist = "";
QList <QString> tagNames = note->tagNames;
for (int i=0; i<tagNames.size(); i++) {
if (taglist.size()>0)
taglist = taglist +", ";
taglist = taglist+tagNames[i];
}
return taglist;
}
|