1 // Copyright (C) 2007-2021 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
23 // File : HelpBrowser_Application.cpp
24 // Author : Maxim GLIBIN, OpenCASCADE S.A.S. (maxim.glibin@opencascade.com)
26 #include "HelpBrowser_Application.h"
29 #include <QFileSystemWatcher>
30 #include <QTextStream>
36 HelpBrowser_Application::HelpBrowser_Application(const QString& appId, int& argc, char** argv)
37 : QtSingleApplication(appId, argc, argv)
39 watcher = new QFileSystemWatcher();
43 \brief Returns the file system watcher for monitoring files for modifications.
45 QFileSystemWatcher* HelpBrowser_Application::fileSysWatcher() const
51 \brief Removes the specified paths from the file system watcher and corresponding
52 files if \a isDeleteFile flag is set. By default, this flag is \c true.
54 void HelpBrowser_Application::clearWatcher(bool isDeleteFile)
56 QStringList aFiles = watcher->files();
57 foreach ( QString aFilePath, aFiles )
59 removeWatchPath( aFilePath );
61 QFile::remove( aFilePath );
66 Adds the path to the file system watcher if the file exists.
68 void HelpBrowser_Application::addWatchPath(const QString& thePath)
70 if ( thePath.isEmpty() )
72 qWarning("HelpBrowser_Application::addWatchPath: path is empty.");
75 watcher->addPath( thePath );
79 Removes the path to the file system watcher.
81 void HelpBrowser_Application::removeWatchPath(const QString& thePath)
83 if (thePath.isEmpty())
85 qWarning("HelpBrowser_Application::removeWatchPath: path is empty.");
88 watcher->removePath( thePath );
92 Updates the statement of watcher. If file becomes empty it is removed and
93 calls quit() function for application.
95 void HelpBrowser_Application::updateWatchStatement(const QString& thePath)
97 if ( thePath.isEmpty() )
99 qWarning("HelpBrowser_Application::updateWatchStatement: path is empty.");
103 if ( !QFile::exists( thePath ) )
104 removeWatchPath( thePath );
106 // Get list of paths to files that are being watched
107 bool isClose = false;
108 if ( watcher->files().contains( thePath ) )
110 QFile aFile( thePath );
111 if ( aFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
113 QTextStream anInSteam( &aFile );
114 if ( anInSteam.readAll().isEmpty() )
122 QFile::remove( thePath );