Skip to content

Commit

Permalink
create db in std user app dir
Browse files Browse the repository at this point in the history
  • Loading branch information
digikata committed Jun 17, 2013
1 parent 5d5a301 commit 9da4c0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 5 additions & 4 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QDir>
#include <QTextStream>
#include <QFileDialog>
#include <QApplication>
#include "mainwindow.h"
#include "ui_mainwindow.h"

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion searcher.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QStandardPaths>
#include <QDir>
#include <QVariant>
#include "searcher.h"

Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 9da4c0d

Please sign in to comment.