1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : HelpBrowser_Application.cpp
23 // Author : Maxim GLIBIN, OpenCASCADE S.A.S. (maxim.glibin@opencascade.com)
25 #include "HelpBrowser_Application.h"
28 #include <QFileSystemWatcher>
29 #include <QTextStream>
35 HelpBrowser_Application::HelpBrowser_Application(const QString& appId, int& argc, char** argv)
36 : QtSingleApplication(appId, argc, argv)
38 watcher = new QFileSystemWatcher();
42 \brief Returns the file system watcher for monitoring files for modifications.
44 QFileSystemWatcher* HelpBrowser_Application::fileSysWatcher() const
50 \brief Removes the specified paths from the file system watcher and corresponding
51 files if \a isDeleteFile flag is set. By default, this flag is \c true.
53 void HelpBrowser_Application::clearWatcher(bool isDeleteFile)
55 QStringList aFiles = watcher->files();
56 foreach ( QString aFilePath, aFiles )
58 removeWatchPath( aFilePath );
60 QFile::remove( aFilePath );
65 Adds the path to the file system watcher if the file exists.
67 void HelpBrowser_Application::addWatchPath(const QString& thePath)
69 if ( thePath.isEmpty() )
71 qWarning("HelpBrowser_Application::addWatchPath: path is empty.");
74 watcher->addPath( thePath );
78 Removes the path to the file system watcher.
80 void HelpBrowser_Application::removeWatchPath(const QString& thePath)
82 if (thePath.isEmpty())
84 qWarning("HelpBrowser_Application::removeWatchPath: path is empty.");
87 watcher->removePath( thePath );
91 Updates the statement of watcher. If file becomes empty it is removed and
92 calls quit() function for application.
94 void HelpBrowser_Application::updateWatchStatement(const QString& thePath)
96 if ( thePath.isEmpty() )
98 qWarning("HelpBrowser_Application::updateWatchStatement: path is empty.");
102 if ( !QFile::exists( thePath ) )
103 removeWatchPath( thePath );
105 // Get list of paths to files that are being watched
106 bool isClose = false;
107 if ( watcher->files().contains( thePath ) )
109 QFile aFile( thePath );
110 if ( aFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
112 QTextStream anInSteam( &aFile );
113 if ( anInSteam.readAll().isEmpty() )
121 QFile::remove( thePath );