Commit abcc4761 authored by Julien Wintz's avatar Julien Wintz
Browse files

Updating log view to handle existing log files.

parent b34822f6
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:16:32 2012 (+0100)
* Version: $Id$
* Last-Updated: Fri Mar 2 19:09:13 2012 (+0100)
* Last-Updated: Mon Mar 5 13:02:15 2012 (+0100)
* By: Julien Wintz
* Update #: 61
* Update #: 73
*/
/* Commentary:
......@@ -22,12 +22,6 @@
#include <QtGui>
// /////////////////////////////////////////////////////////////////
// Helper function
// /////////////////////////////////////////////////////////////////
QString dtkLogPath(QCoreApplication *application);
// /////////////////////////////////////////////////////////////////
// Dummy thread
// /////////////////////////////////////////////////////////////////
......@@ -62,8 +56,11 @@ int main(int argc, char **argv)
{
QApplication application(argc, argv);
application.setApplicationName("dtkLogView");
application.setOrganizationName("inria");
application.setOrganizationDomain("fr");
dtkLogger::instance().setLevel(dtkLog::Trace);
dtkLogger::instance().attachFile(dtkLogPath(&application));
dtkLogView *view = new dtkLogView;
view->setWindowTitle("dtk Log View");
......@@ -83,17 +80,3 @@ int main(int argc, char **argv)
return status;
}
// /////////////////////////////////////////////////////////////////
// Helper function
// /////////////////////////////////////////////////////////////////
QString dtkLogPath(QCoreApplication *application)
{
QString path = QDir(application->applicationDirPath()).filePath(QString("%1.log").arg(application->applicationName()));
if (path.contains(QString("%1.app/Contents/MacOS/").arg(application->applicationName())))
path.remove(QString("%1.app/Contents/MacOS/").arg(application->applicationName()));
return path;
}
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:23:18 2012 (+0100)
* Version: $Id$
* Last-Updated: Fri Mar 2 18:53:06 2012 (+0100)
* Last-Updated: Mon Mar 5 13:02:50 2012 (+0100)
* By: Julien Wintz
* Update #: 227
* Update #: 228
*/
/* Commentary:
......@@ -74,12 +74,6 @@ QDebug operator<<(QDebug dbg, const Pixel &pixel)
Q_DECLARE_METATYPE(Pixel);
// /////////////////////////////////////////////////////////////////
// Helper function
// /////////////////////////////////////////////////////////////////
QString dtkLogPath(QCoreApplication *application);
// /////////////////////////////////////////////////////////////////
// main
// /////////////////////////////////////////////////////////////////
......@@ -162,12 +156,3 @@ int main(int argc, char **argv)
return status;
}
// /////////////////////////////////////////////////////////////////
// Helper function
// /////////////////////////////////////////////////////////////////
QString dtkLogPath(QCoreApplication *application)
{
return QDir(application->applicationDirPath()).filePath(QString("%1.log").arg(application->applicationName()));
}
......@@ -4,9 +4,9 @@
## Copyright (C) 2008-2011 - Julien Wintz, Inria.
## Created: Thu Mar 1 14:34:49 2012 (+0100)
## Version: $Id$
## Last-Updated: Mon Mar 5 11:07:46 2012 (+0100)
## Last-Updated: Mon Mar 5 12:56:54 2012 (+0100)
## By: Julien Wintz
## Update #: 25
## Update #: 26
######################################################################
##
### Commentary:
......@@ -37,6 +37,7 @@ set(${PROJECT_NAME}_HEADERS_MOC
dtkLogView_p.h)
set(${PROJECT_NAME}_SOURCES
dtkLog.cpp
dtkLogger.cpp
dtkLogEngine.cpp
dtkLogDestination.cpp
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 14:40:12 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 17:22:40 2012 (+0100)
* Last-Updated: Mon Mar 5 12:58:55 2012 (+0100)
* By: Julien Wintz
* Update #: 31
* Update #: 39
*/
/* Commentary:
......@@ -18,3 +18,11 @@
*/
#include "dtkLog.h"
#include <QtCore>
#include <QtGui>
QString dtkLogPath(QCoreApplication *application)
{
return QDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation)).filePath(QString("%1.log").arg(application->applicationName()));
}
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 14:37:36 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 21:20:39 2012 (+0100)
* Last-Updated: Mon Mar 5 12:56:25 2012 (+0100)
* By: Julien Wintz
* Update #: 126
* Update #: 133
*/
/* Commentary: See credits at EOF.
......@@ -93,6 +93,12 @@ namespace dtkLog
#define dtkFatal() \
dtkLogEngine(dtkLog::Fatal).stream()
// /////////////////////////////////////////////////////////////////
// Helper functions
// /////////////////////////////////////////////////////////////////
QString dtkLogPath(QCoreApplication *application);
// /////////////////////////////////////////////////////////////////
#endif
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:15:19 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 5 12:28:40 2012 (+0100)
* Last-Updated: Mon Mar 5 13:09:37 2012 (+0100)
* By: Julien Wintz
* Update #: 59
* Update #: 66
*/
/* Commentary:
......@@ -55,7 +55,19 @@ public:
dtkLogDestinationFile::dtkLogDestinationFile(const QString& path) : d(new dtkLogDestinationFilePrivate)
{
d->file.setFileName(path);
d->file.open(QFile::WriteOnly | QFile::Text | QIODevice::Append);
QFileInfo info(path);
QDir dir(info.absoluteDir());
if(!dir.exists()) {
QString name = dir.dirName();
dir.cdUp();
dir.mkdir(name);
}
if(!d->file.open(QFile::WriteOnly | QFile::Text | QIODevice::Append))
qDebug() << "Unable to open" << path << "for writing";
d->stream.setDevice(&(d->file));
}
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:13:52 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 5 12:32:17 2012 (+0100)
* Last-Updated: Mon Mar 5 14:12:28 2012 (+0100)
* By: Julien Wintz
* Update #: 107
* Update #: 183
*/
/* Commentary:
......@@ -17,6 +17,7 @@
*
*/
#include "dtkLog.h"
#include "dtkLogModel.h"
#include "dtkLogView.h"
#include "dtkLogView_p.h"
......@@ -31,16 +32,15 @@ dtkLogViewTree::dtkLogViewTree(QWidget *parent) : QTreeWidget(parent)
this->setFrameShape(QFrame::HLine);
this->setHeaderHidden(true);
QTreeWidgetItem *runtime_log = new QTreeWidgetItem(QStringList() << "Runtime log");
QTreeWidgetItem *file_log = new QTreeWidgetItem(QStringList() << "File log");
QTreeWidgetItem *dummy_a_log = new QTreeWidgetItem(QStringList() << "a.log");
QTreeWidgetItem *dummy_b_log = new QTreeWidgetItem(QStringList() << "b.log");
this->runtime = new QTreeWidgetItem(QStringList() << "Runtime log");
file_log->addChild(dummy_a_log);
file_log->addChild(dummy_b_log);
this->file = new QTreeWidgetItem(QStringList() << "File log");
this->file->addChild(new QTreeWidgetItem(QStringList() << dtkLogPath(qApp)));
this->addTopLevelItem(runtime_log);
this->addTopLevelItem(file_log);
this->addTopLevelItem(this->runtime);
this->addTopLevelItem(this->file);
connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(onItemClicked(QTreeWidgetItem *, int)));
}
dtkLogViewTree::~dtkLogViewTree(void)
......@@ -48,6 +48,16 @@ dtkLogViewTree::~dtkLogViewTree(void)
}
void dtkLogViewTree::onItemClicked(QTreeWidgetItem *item, int)
{
if (item == this->runtime)
emit runtimeClicked();
else if (item == this->file)
;
else
emit fileClicked(item->text(0));
}
// /////////////////////////////////////////////////////////////////
// dtkLogViewList
// /////////////////////////////////////////////////////////////////
......@@ -63,7 +73,7 @@ dtkLogViewList::dtkLogViewList(QWidget *parent) : QListView(parent)
dtkLogViewList::~dtkLogViewList(void)
{
qDeleteAll(this->models);
}
void dtkLogViewList::setRuntime(void)
......@@ -73,6 +83,31 @@ void dtkLogViewList::setRuntime(void)
this->setModel(this->model);
}
void dtkLogViewList::setFile(const QString& path)
{
if (this->models.contains(path))
this->models.remove(path);
QFile file(path);
if(!file.open(QFile::ReadOnly))
qDebug() << "Unable to read file" << path;
QString contents = file.readAll();
file.close();
QStringListModel *model = new QStringListModel(contents.split("\n"));
this->setModel(model);
this->models.insert(path, model);
// QFileSystemWatcher *watcher = new QFileSystemWatcher(QStringList() << path, this);
// connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(setFile(const QString&)));
}
// /////////////////////////////////////////////////////////////////
// dtkLogView
// /////////////////////////////////////////////////////////////////
......@@ -89,6 +124,9 @@ dtkLogView::dtkLogView(QWidget *parent) : QWidget(parent), d(new dtkLogViewPriva
layout->setSpacing(0);
layout->addWidget(d->tree);
layout->addWidget(d->list);
connect(d->tree, SIGNAL(runtimeClicked()), d->list, SLOT(setRuntime()));
connect(d->tree, SIGNAL(fileClicked(const QString&)), d->list, SLOT(setFile(const QString&)));
}
dtkLogView::~dtkLogView(void)
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:30:16 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 5 11:10:55 2012 (+0100)
* Last-Updated: Mon Mar 5 13:14:13 2012 (+0100)
* By: Julien Wintz
* Update #: 39
* Update #: 50
*/
/* Commentary:
......@@ -37,6 +37,17 @@ class dtkLogViewTree : public QTreeWidget
public:
dtkLogViewTree(QWidget *parent = 0);
~dtkLogViewTree(void);
signals:
void runtimeClicked(void);
void fileClicked(const QString& path);
protected slots:
void onItemClicked(QTreeWidgetItem *, int);
private:
QTreeWidgetItem *runtime;
QTreeWidgetItem *file;
};
// /////////////////////////////////////////////////////////////////
......@@ -51,11 +62,15 @@ public:
dtkLogViewList(QWidget *parent = 0);
~dtkLogViewList(void);
public:
public slots:
void setRuntime(void);
void setFile(const QString& path);
private:
dtkLogModel *model;
private:
QHash<QString, QStringListModel *> models;
};
// /////////////////////////////////////////////////////////////////
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 17:19:52 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 5 11:13:23 2012 (+0100)
* Last-Updated: Mon Mar 5 13:04:19 2012 (+0100)
* By: Julien Wintz
* Update #: 87
* Update #: 91
*/
/* Commentary:
......@@ -50,6 +50,9 @@ void dtkLogger::detachConsole(void)
void dtkLogger::attachFile(const QString& path)
{
if(d->files.contains(path))
return;
d->files[path] = dtkLogDestinationPointer(new dtkLogDestinationFile(path));
d->destinations << d->files[path];
......@@ -67,6 +70,9 @@ void dtkLogger::detachFile(const QString& path)
void dtkLogger::attachModel(dtkLogModel *model)
{
if(d->models.contains(model))
return;
d->models[model] = dtkLogDestinationPointer(new dtkLogDestinationModel(model));
d->destinations << d->models[model];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment