1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/config.h>
12 #include <svtools/filechangedchecker.hxx>
14 FileChangedChecker::FileChangedChecker(const OUString
& rFilename
, const ::boost::function0
<void>& rCallback
) :
20 // Get the curren last file modified Status
21 getCurrentModTime(mLastModTime
);
23 // associate the callback function for the Idle
24 mIdle
.SetIdleHdl(LINK(this, FileChangedChecker
, TimerHandler
));
30 void FileChangedChecker::resetTimer()
32 //Start the Idle if its not active
36 // Set lowest Priority
37 mIdle
.SetPriority(SchedulerPriority::LOWEST
);
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
48 osl::FileStatus
aStatus( osl_FileStatus_Mask_ModifyTime
);
49 if( osl::FileBase::E_None
!= aItem
.getFileStatus(aStatus
) )
52 o_rValue
= aStatus
.getModifyTime();
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
70 mLastModTime
= newTime
;
78 IMPL_LINK_NOARG_TYPED(FileChangedChecker
, TimerHandler
, Idle
*, void)
80 // If the file has changed, then update the graphic in the doc
81 OSL_TRACE("Timeout Called");
84 OSL_TRACE("File modified");
88 // Reset the Idle in any case
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */