fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / misc / filechangedchecker.cxx
blob39c6c0eb93508bc7d46e4bac2f8b8cee5e9a5fff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "sal/config.h"
12 #include "svtools/filechangedchecker.hxx"
14 FileChangedChecker::FileChangedChecker(const OUString& rFilename, const ::boost::function0<void>& rCallback) :
15 mTimer(),
16 mFileName(rFilename),
17 mLastModTime(),
18 mpCallback(rCallback)
20 // Get the curren last file modified Status
21 getCurrentModTime(mLastModTime);
23 // associate the callback function for the timer
24 mTimer.SetTimeoutHdl(LINK(this, FileChangedChecker, TimerHandler));
26 //start the timer
27 resetTimer();
30 void FileChangedChecker::resetTimer()
32 //Start the timer if its not active
33 if(!mTimer.IsActive())
34 mTimer.Start();
36 // Set a timeout of 3 seconds
37 mTimer.SetTimeout(3000);
40 bool FileChangedChecker::getCurrentModTime(TimeValue& o_rValue) const
42 // Need a Directory item to fetch file status
43 osl::DirectoryItem aItem;
44 osl::DirectoryItem::get(mFileName, aItem);
46 // Retrieve the status - we are only interested in last File
47 // Modified time
48 osl::FileStatus aStatus( osl_FileStatus_Mask_ModifyTime );
49 if( osl::FileBase::E_None != aItem.getFileStatus(aStatus) )
50 return false;
52 o_rValue = aStatus.getModifyTime();
53 return true;
56 bool FileChangedChecker::hasFileChanged()
58 // Get the current file Status
59 TimeValue newTime={0,0};
60 if( !getCurrentModTime(newTime) )
61 return true; // well. hard to answer correctly here ...
63 // Check if the seconds time stamp has any difference
64 // If so, then our file has changed meanwhile
65 if( newTime.Seconds != mLastModTime.Seconds ||
66 newTime.Nanosec != mLastModTime.Nanosec )
68 // Since the file has changed, set the new status as the file status and
69 // return True
70 mLastModTime = newTime ;
72 return true;
74 else
75 return false;
78 IMPL_LINK_NOARG(FileChangedChecker, TimerHandler)
80 // If the file has changed, then update the graphic in the doc
81 OSL_TRACE("Timeout Called");
82 if(hasFileChanged())
84 OSL_TRACE("File modified");
85 mpCallback();
88 // Reset the timer in any case
89 resetTimer();
90 return 0;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */