From 9da4c0d51fcb4c947a885917e6debf137f4458df Mon Sep 17 00:00:00 2001 From: Alan C Date: Sat, 15 Jun 2013 20:40:25 -0700 Subject: [PATCH] create db in std user app dir --- mainwindow.cpp | 9 +++++---- searcher.cpp | 13 ++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 5fd417b..40c2974 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "mainwindow.h" #include "ui_mainwindow.h" @@ -12,6 +13,9 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); + QCoreApplication* app = QApplication::instance(); + app->setApplicationName("Upnote"); + search = new Searcher(this); notelist = 0; settings = 0; @@ -122,10 +126,7 @@ QString MainWindow::getNotesPath() { if( settings == 0) { - const QString orgval("Upnote"); - settings = new QSettings(QSettings::NativeFormat, - QSettings::UserScope, - orgval, QString(), this ); + settings = new QSettings(); } notespath = settings->value("notes_path", QString("./notes") ).toString(); return notespath; diff --git a/searcher.cpp b/searcher.cpp index 923dc92..247578c 100644 --- a/searcher.cpp +++ b/searcher.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include "searcher.h" @@ -13,8 +15,16 @@ Searcher::Searcher(QObject *parent) : { s_db = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE")); } + QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::DataLocation); + QDir datadir(dirs.at(0)); + if(!datadir.exists() ) + { + datadir.mkpath(dirs.at(0)); + } + QString dbpath = datadir.path() + "/upnote.db"; + s_db->setHostName("localhost"); - s_db->setDatabaseName("tmp.db"); + s_db->setDatabaseName(dbpath); s_db->open(); QSqlQuery setuptable(*s_db); @@ -40,6 +50,7 @@ void Searcher::load_entry( const QString &title, const QString &body) load.exec(); } + void Searcher::update_entry( const QString &title, const QString &body ) { static QSqlQuery update(*s_db);