CustusX
15.3.3-beta
An IGT application
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
cxFileWatcherWidget.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 "
cxFileWatcherWidget.h
"
34
#include "
cxLogger.h
"
35
#include <QFileSystemWatcher>
36
#include <QFileInfo>
37
38
39
namespace
cx
40
{
41
FileWatcherWidget::FileWatcherWidget
(QWidget* parent, QString objectName, QString windowTitle) :
42
BaseWidget
(parent, objectName, windowTitle),
43
mFileSystemWatcher(new QFileSystemWatcher())
44
{
45
connect(
mFileSystemWatcher
, SIGNAL(fileChanged(
const
QString&)),
this
, SLOT(
previewFileSlot
(
const
QString&)));
46
}
47
48
FileWatcherWidget::~FileWatcherWidget
()
49
{}
50
51
bool
FileWatcherWidget::internalOpenNewFile
(
const
QString absoluteFilePath)
52
{
53
if
(
mCurrentFile
)
54
{
55
if
(
mCurrentFile
->isOpen())
56
{
57
this->
watchFile
(
false
);
58
mCurrentFile
->close();
59
}
60
}
61
62
mCurrentFile
.reset(
new
QFile(absoluteFilePath));
63
this->
watchFile
(
true
);
64
65
if
(!
mCurrentFile
->exists())
66
{
67
return
false
;
68
}
69
70
if
(!
mCurrentFile
->open(QIODevice::ReadOnly))
71
{
72
reportWarning
(
"Could not open file "
+absoluteFilePath);
73
//return false; Is this missing???
74
}
75
return
true
;
76
}
77
78
void
FileWatcherWidget::watchFile
(
bool
on)
79
{
80
if
(!
mCurrentFile
)
81
return
;
82
83
QFileInfo info(*
mCurrentFile
);
84
85
if
(on)
86
{
87
if
(!
mFileSystemWatcher
->files().contains(info.absoluteFilePath()))
88
mFileSystemWatcher
->addPath(info.absoluteFilePath());
89
}
90
else
91
{
92
mFileSystemWatcher
->removePath(info.absoluteFilePath());
93
}
94
}
95
}
/* namespace cx */
cxFileWatcherWidget.h
cx::FileWatcherWidget::internalOpenNewFile
bool internalOpenNewFile(const QString absoluteFilePath)
Definition:
cxFileWatcherWidget.cpp:51
cx::FileWatcherWidget::mFileSystemWatcher
QFileSystemWatcher * mFileSystemWatcher
Definition:
cxFileWatcherWidget.h:71
cx::FileWatcherWidget::watchFile
void watchFile(bool on)
Definition:
cxFileWatcherWidget.cpp:78
cxLogger.h
cx::FileWatcherWidget::previewFileSlot
virtual void previewFileSlot(const QString &absoluteFilePath)=0
cx::FileWatcherWidget::FileWatcherWidget
FileWatcherWidget(QWidget *parent, QString objectName, QString windowTitle)
Definition:
cxFileWatcherWidget.cpp:41
cx::FileWatcherWidget::mCurrentFile
boost::shared_ptr< QFile > mCurrentFile
Definition:
cxFileWatcherWidget.h:72
cx::reportWarning
void reportWarning(QString msg)
Definition:
cxLogger.cpp:91
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition:
cxBaseWidget.h:108
cx::FileWatcherWidget::~FileWatcherWidget
virtual ~FileWatcherWidget()
Definition:
cxFileWatcherWidget.cpp:48
CX
source
resource
widgets
cxFileWatcherWidget.cpp
Generated on Sat Mar 21 2015 18:32:37 for CustusX by
1.8.6