fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svtools / source / misc / filechangedchecker.cxx
blobea35296baa9cafabff730439d715490d65534407
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 mIdle(),
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 Idle
24 mIdle.SetIdleHdl(LINK(this, FileChangedChecker, TimerHandler));
26 //start the timer
27 resetTimer();
30 void FileChangedChecker::resetTimer()
32 //Start the Idle if its not active
33 if(!mIdle.IsActive())
34 mIdle.Start();
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
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_TYPED(FileChangedChecker, TimerHandler, Idle *, void)
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 Idle in any case
89 resetTimer();
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */