Fraxinus  16.5.0-fx-rc6
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxLogConsole.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxLogConsole.h"
34 
35 #include <QDesktopWidget>
36 #include <QApplication>
37 #include <QFileDialog>
38 #include <QAction>
39 #include <QMenu>
40 #include <QMenuBar>
41 
43 #include "cxDataLocations.h"
44 #include "cxLogFileWatcher.h"
45 
46 namespace cx
47 {
48 
50 {
51  QString optionsFile = cx::DataLocations::getPersistentWritablePath()+"/logconsole.xml";
52  mOptions = cx::XmlOptionFile(optionsFile);
53  CX_LOG_INFO() << "Options file: " << optionsFile;
55  CX_LOG_INFO() << "Log folder: " << mLog->getLoggingFolder();
56 
57  this->createMenus();
58 
59  this->updateWindowTitle();
60 
61  cx::ConsoleWidgetCollection* consoles = new cx::ConsoleWidgetCollection(NULL, "ConsoleWidgets", "Consoles", mOptions, mLog);
62  this->setCentralWidget(consoles);
63 
64  this->initializeGeometry();
65 }
66 
67 void LogConsole::initializeGeometry()
68 {
69  if (!this->restoreGeometry(this->getGeometryOption().readVariant().toByteArray()))
70  this->setDefaultGeometry();
71 }
72 
73 void LogConsole::setDefaultGeometry()
74 {
75  QDesktopWidget* desktop = dynamic_cast<QApplication*>(QApplication::instance())->desktop();
76  QRect screen = desktop->screenGeometry(desktop->primaryScreen());
77  screen.adjust(screen.width()*0.5, screen.height()*0.25, 0, 0);
78  this->setGeometry(screen);
79 }
80 
81 XmlOptionItem LogConsole::getGeometryOption()
82 {
83  return XmlOptionItem("geometry", mOptions.getElement());
84 }
85 
87 {
88  this->getGeometryOption().writeVariant(this->saveGeometry());
89 
90  mOptions.save();
91 }
92 
93 void LogConsole::createMenus()
94 {
95  //data
96  QAction* selectFolderAction = new QAction(QIcon(":/icons/open_icon_library/document-import-2.png"), tr("&Select folder"), this);
97  selectFolderAction->setShortcut(tr("Ctrl+L"));
98  selectFolderAction->setStatusTip(tr("Select folder"));
99  connect(selectFolderAction, &QAction::triggered, this, &LogConsole::onSelectFolder);
100 
101  QMenu* fileMenu = new QMenu(tr("File"), this);
102  fileMenu->addAction(selectFolderAction);
103  this->menuBar()->addMenu(fileMenu);
104 }
105 
106 void LogConsole::updateWindowTitle()
107 {
108  QString title = QString("Log Console [%1]").arg(mLog->getLoggingFolder());
109  this->setWindowTitle(title);
110 }
111 
112 void LogConsole::onSelectFolder()
113 {
114  QString folder = mLog->getLoggingFolder() + "/..";
115 
116  folder = QFileDialog::getExistingDirectory(this, "Open log folder", folder);
117  if (folder.isEmpty())
118  {
119  return;
120  }
121 
122  mLog->setLoggingFolder(folder);
123  this->updateWindowTitle();
124 }
125 
126 
127 } // namespace cx
void writeVariant(const QVariant &val)
#define CX_LOG_INFO
Definition: cxLogger.h:111
QDomElement getElement()
return the current element
static QString getPersistentWritablePath()
Path to location usable for persistent and temporary storage of config. Do not use directly...
void save()
save entire document.
Helper class for xml files used to store ssc/cx data.
static LogFileWatcherPtr create()