Skip to content

Commit

Permalink
Basic infrastructure for nixnote-cmd utility.
Browse files Browse the repository at this point in the history
  • Loading branch information
baumgarr committed Oct 18, 2015
1 parent 01d3b24 commit 8b7e12d
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 65 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.6) on: Mon Jul 27 12:43:05 2015
# Generated by qmake (2.01a) (Qt 4.8.6) on: Sat Oct 17 09:03:51 2015
# 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
116 changes: 90 additions & 26 deletions Makefile.Debug

Large diffs are not rendered by default.

116 changes: 90 additions & 26 deletions Makefile.Release

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions NixNote2.pro
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ SOURCES += main.cpp\
gui/browserWidgets/fontnamecombobox.cpp \
gui/browserWidgets/fontsizecombobox.cpp \
utilities/pixelconverter.cpp \
utilities/noteindexer.cpp
utilities/noteindexer.cpp \
xml/batchimport.cpp



Expand Down Expand Up @@ -344,7 +345,8 @@ HEADERS += nixnote.h \
gui/browserWidgets/fontnamecombobox.h \
gui/browserWidgets/fontsizecombobox.h \
utilities/pixelconverter.h \
utilities/noteindexer.h
utilities/noteindexer.h \
xml/batchimport.h


#INCLUDEPATH += /usr/local/include/thrift \
Expand Down
23 changes: 16 additions & 7 deletions nixnote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ NixNote::NixNote(QWidget *parent) : QMainWindow(parent)
nixnoteTranslator->load(global.fileManager.getTranslateFilePath("nixnote2_" + QLocale::system().name() + ".qm"));
QApplication::instance()->installTranslator(nixnoteTranslator);


connect(&syncThread, SIGNAL(started()), this, SLOT(syncThreadStarted()));
connect(&counterThread, SIGNAL(started()), this, SLOT(counterThreadStarted()));
connect(&indexThread, SIGNAL(started()), this, SLOT(indexThreadStarted()));
Expand Down Expand Up @@ -152,10 +151,6 @@ NixNote::NixNote(QWidget *parent) : QMainWindow(parent)
connect(attributeTree, SIGNAL(updateSelectionRequested()), this, SLOT(updateSelectionCriteria()));
connect(trashTree, SIGNAL(updateSelectionRequested()), this, SLOT(updateSelectionCriteria()));
connect(searchText, SIGNAL(updateSelectionRequested()), this, SLOT(updateSelectionCriteria()));
// Setup file watcher
importManager = new FileWatcherManager(this);
connect(importManager, SIGNAL(fileImported(qint32,qint32)), this, SLOT(updateSelectionCriteria()));
importManager->setup();
connect(&global.resourceWatcher, SIGNAL(fileChanged(QString)), this, SLOT(resourceExternallyUpdated(QString)));

hammer = new Thumbnailer(global.db);
Expand Down Expand Up @@ -209,6 +204,15 @@ NixNote::NixNote(QWidget *parent) : QMainWindow(parent)
//QDesktopServices::setUrlHandler("evernote", this, "showDesktopUrl");
remoteQuery = new RemoteQuery();


// Setup file watcher
importManager = new FileWatcherManager(this);
connect(importManager, SIGNAL(fileImported(qint32,qint32)), this, SLOT(updateSelectionCriteria()));
connect(importManager, SIGNAL(fileImported()), this, SLOT(updateSelectionCriteria()));
importManager->setup();
this->updateSelectionCriteria(true); // This is only needed in case we imported something at statup.


QLOG_DEBUG() << "Exiting NixNote constructor";
}

Expand Down Expand Up @@ -1801,7 +1805,7 @@ void NixNote::newNote() {
Note n;
NotebookTable notebookTable(global.db);
n.content = newNoteBody;
n.title = "Untitled note";
n.title = tr("Untitled note");
QString uuid = QUuid::createUuid();
uuid = uuid.mid(1);
uuid.chop(1);
Expand Down Expand Up @@ -2296,14 +2300,19 @@ void NixNote::heartbeatTimerTriggered() {

QByteArray data = QByteArray::fromRawData(buffer, global.sharedMemory->size());
//QLOG_ERROR() << "Shared memory data: " << data;
if (data.startsWith("SYNCHRONIZE")) {
QLOG_DEBUG() << "Sync requested by shared memory segment.";
this->synchronize();
return;
}
if (data.startsWith("IMMEDIATE_SHUTDOWN")) {
QLOG_ERROR() << "Immediate shutdown requested by shared memory segment.";
this->closeNixNote();
return;
}
if (data.startsWith("SHOW_WINDOW")) {
this->raise();
this->show();
this->showMaximized();
return;
}
if (data.startsWith("QUERY:")) {
Expand Down
13 changes: 13 additions & 0 deletions settings/filemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ void FileManager::setup(QString homeDirPath, QString programDirPath, int id) {
createDirOrCheckWriteable(dbaDir);
dbaDirPath = slashTerminatePath(dbaDir.path());

dbiDir.setPath(dbDirPath+"dbi");
createDirOrCheckWriteable(dbiDir);
dbiDirPath = slashTerminatePath(dbiDir.path());

thumbnailDir.setPath(dbDirPath+"tdba");
createDirOrCheckWriteable(thumbnailDir);
thumbnailDirPath = slashTerminatePath(thumbnailDir.path());
Expand Down Expand Up @@ -271,6 +275,15 @@ QString FileManager::getDbaDirPath(QString relativePath) {
QString FileManager::getDbaDirPathSpecialChar(QString relativePath) {
return dbaDirPath + toPlatformPathSeparator(relativePath).replace("#", "%23");
}
QString FileManager::getDbiDirPath() {
return dbiDirPath;
}
QString FileManager::getDbiDirPath(QString relativePath) {
return dbiDirPath + toPlatformPathSeparator(relativePath);
}
QString FileManager::getDbiDirPathSpecialChar(QString relativePath) {
return dbiDirPath + toPlatformPathSeparator(relativePath).replace("#", "%23");
}
QString FileManager::getThumbnailDirPath() {
return thumbnailDirPath;
}
Expand Down
6 changes: 6 additions & 0 deletions settings/filemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class FileManager : public QObject
QString dbaDirPath;
QDir dbaDir;

QString dbiDirPath;
QDir dbiDir;

QString thumbnailDirPath;
QDir thumbnailDir;

Expand Down Expand Up @@ -107,6 +110,9 @@ class FileManager : public QObject
QString getDbaDirPath();
QString getDbaDirPath(QString relativePath);
QString getDbaDirPathSpecialChar(QString relativePath);
QString getDbiDirPath();
QString getDbiDirPath(QString relativePath);
QString getDbiDirPathSpecialChar(QString relativePath);
QString getThumbnailDirPath();
QString getThumbnailDirPath(QString relativePath);
QString getThumbnailDirPathSpecialChar(QString relativePath);
Expand Down
21 changes: 18 additions & 3 deletions watcher/filewatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "sql/resourcetable.h"
#include "utilities/mimereference.h"
#include "sql/filewatchertable.h"
#include "xml/batchimport.h"

#include <QDirIterator>

Expand Down Expand Up @@ -57,17 +58,31 @@ void FileWatcher::saveDirectory(QString dir){
}

void FileWatcher::saveFile(QString file) {
Note newNote;
NoteTable ntable(global.db);
QFileInfo fileInfo(file);

// If we have a dbi import file
QLOG_DEBUG() << fileInfo.dir().absolutePath() + QDir::separator();
QLOG_DEBUG() << global.fileManager.getDbiDirPath();
if ((fileInfo.dir().absolutePath() + QDir::separator()) == global.fileManager.getDbiDirPath()) {
BatchImport importer;
importer.import(file);
emit(nnexImported());
QFile f(file);
f.remove();
return;
}


// If we have a user-import file
QFile f(file);
f.open(QIODevice::ReadOnly);
QByteArray data = f.readAll();
f.close();
if (f.size() == 0)
return;

QLOG_DEBUG() << data;
Note newNote;
NoteTable ntable(global.db);
ConfigStore cs(global.db);
qint32 lid = cs.incrementLidCounter();

Expand Down
1 change: 1 addition & 0 deletions watcher/filewatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class FileWatcher : public QFileSystemWatcher

signals:
void fileImported(qint32 noteLid, qint32 ressourceLid);
void nnexImported();

public slots:
void saveFile(QString file);
Expand Down
9 changes: 9 additions & 0 deletions watcher/filewatchermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@ void FileWatcherManager::signalImported(qint32 noteLid, qint32 resourceLid) {
}


void FileWatcherManager::signalImported() {
emit fileImported();
}

void FileWatcherManager::setup() {
this->reset();

// Setup the dbi file for batch creation of notes
FileWatcher *dbi = new FileWatcher(global.fileManager.getDbiDirPath(), FileWatcher::ImportDelete, 0, false, 0);
connect(dbi, SIGNAL(nnexImported()), this, SLOT(signalImported()));
importDelete.append(dbi);

QList<qint32> lids;
FileWatcherTable ft(global.db);
ft.getAll(lids);
Expand Down
2 changes: 2 additions & 0 deletions watcher/filewatchermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class FileWatcherManager : public QObject

signals:
void fileImported(qint32 noteLid, qint32 resourceLid);
void fileImported();

public slots:
void signalImported(qint32 noteLid, qint32 resourceLid);
void signalImported();

};

Expand Down
Loading

0 comments on commit 8b7e12d

Please sign in to comment.