• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • tools
  • osm-sisyphus
logger.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2011 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include "logger.h"
12 
13 #include <QDebug>
14 #include <QVariant>
15 #include <QSqlDatabase>
16 #include <QSqlQuery>
17 #include <QSqlError>
18 
19 class LoggerPrivate
20 {
21 public:
22  QSqlDatabase m_database;
23 
24  LoggerPrivate();
25 
26  void initializeDatabase();
27 };
28 
29 LoggerPrivate::LoggerPrivate()
30 {
31  m_database = QSqlDatabase::addDatabase( "QSQLITE" );
32 }
33 
34 void LoggerPrivate::initializeDatabase()
35 {
36  QSqlQuery createJobsTable( "CREATE TABLE IF NOT EXISTS jobs (id VARCHAR(255) PRIMARY KEY, name TEXT, status TEXT, description TEXT, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP);" );
37  if ( createJobsTable.lastError().isValid() ) {
38  qDebug() << "Error when executing query" << createJobsTable.lastQuery();
39  qDebug() << "Sql reports" << createJobsTable.lastError();
40  }
41 }
42 
43 Logger::Logger(QObject *parent) :
44  QObject(parent), d(new LoggerPrivate)
45 {
46 }
47 
48 Logger::~Logger()
49 {
50  delete d;
51 }
52 
53 Logger &Logger::instance()
54 {
55  static Logger m_instance;
56  return m_instance;
57 }
58 
59 void Logger::setFilename(const QString &filename)
60 {
61  d->m_database.setDatabaseName( filename );
62  if ( !d->m_database.open() ) {
63  qDebug() << "Failed to connect to database " << filename;
64  }
65 
66  d->initializeDatabase();
67 }
68 
69 void Logger::setStatus(const QString &id, const QString &name, const QString &status, const QString &message)
70 {
71  QSqlQuery deleteJob( QString("DELETE FROM jobs WHERE id='%1';").arg(id) );
72  if ( deleteJob.lastError().isValid() ) {
73  qDebug() << "Error when executing query" << deleteJob.lastQuery();
74  qDebug() << "Sql reports" << deleteJob.lastError();
75  } else {
76  QSqlQuery createStatus;
77  createStatus.prepare("INSERT INTO jobs (id, name, status, description) VALUES (:job, :name, :status, :message);");
78  createStatus.bindValue(":job", id);
79  createStatus.bindValue(":name", name);
80  createStatus.bindValue(":status", status);
81  createStatus.bindValue(":message", message);
82  if ( !createStatus.exec() ) {
83  qDebug() << "Error when executing query" << createStatus.lastQuery();
84  qDebug() << "Sql reports" << createStatus.lastError();
85  }
86  }
87 }
88 
89 #include "logger.moc"
Logger
Definition: logger.h:18
QObject
Logger::setStatus
void setStatus(const QString &id, const QString &name, const QString &status, const QString &message)
Definition: logger.cpp:69
logger.h
Logger::instance
static Logger & instance()
Definition: logger.cpp:53
Logger::setFilename
void setFilename(const QString &filename)
Definition: logger.cpp:59
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal