[Libreoffice-commits] .: svtools/inc svtools/source

Thorsten Behrens thorsten at kemper.freedesktop.org
Fri Dec 3 07:37:42 PST 2010


 svtools/inc/svtools/filechangedchecker.hxx |   53 +++++++++++++
 svtools/source/misc/filechangedchecker.cxx |  115 +++++++++++++++++++++++++++++
 svtools/source/misc/makefile.mk            |    1 
 3 files changed, 169 insertions(+)

New commits:
commit 3cedb3ee719afa2443507f3797f45e18db091c35
Author: Surendran Mahendran <surenspost at gmail.com>
Date:   Fri Dec 3 16:17:02 2010 +0100

    First cuts for edit with external tool method
    
    Moves FileChangedChecker to svtools, for reuse in other applications

diff --git a/svtools/inc/svtools/filechangedchecker.hxx b/svtools/inc/svtools/filechangedchecker.hxx
new file mode 100644
index 0000000..0806b70
--- /dev/null
+++ b/svtools/inc/svtools/filechangedchecker.hxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       [ Surendran Mahendran <surenspost at gmail.com>]
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+#ifndef SVTOOLS_INCLUDED_FILECHANGEDCHECKER_HXX
+#define SVTOOLS_INCLUDED_FILECHANGEDCHECKER_HXX
+
+#include <boost/function.hpp>
+#include <osl/file.hxx>
+#include <vcl/timer.hxx>
+
+/** Periodically checks if a file has been modified
+
+    Instances of this class setup a vcl timer to occasionally wake up
+    check whether file modification time has changed.
+ */
+class FileChangedChecker
+{
+private :
+    Timer                    mTimer;
+    rtl::OUString            mFileName;
+    TimeValue                mLastModTime;
+    ::boost::function0<void> mpCallback;
+
+    bool getCurrentModTime(TimeValue& o_rValue) const;
+
+public :
+    DECL_LINK(TimerHandler, Timer *);
+    void resetTimer();
+    bool hasFileChanged();
+    FileChangedChecker(const rtl::OUString& rFilename, const ::boost::function0<void>& rCallback);
+};
+
+#endif
diff --git a/svtools/source/misc/filechangedchecker.cxx b/svtools/source/misc/filechangedchecker.cxx
new file mode 100644
index 0000000..abd0f34
--- /dev/null
+++ b/svtools/source/misc/filechangedchecker.cxx
@@ -0,0 +1,115 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       [ Surendran Mahendran <surenspost at gmail.com>]
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_svtools.hxx"
+
+#include "svtools/filechangedchecker.hxx"
+#include <osl/time.h>
+#include "com/sun/star/system/XSystemShellExecute.hpp"
+#include "com/sun/star/system/SystemShellExecuteFlags.hpp"
+#include <comphelper/processfactory.hxx>
+
+using namespace ::com::sun::star;
+
+FileChangedChecker::FileChangedChecker(const rtl::OUString& rFilename, const ::boost::function0<void>& rCallback) :
+    mTimer(),
+    mFileName(rFilename),
+    mLastModTime(),
+    mpCallback(rCallback)
+{
+    // Get the curren last file modified Status
+    getCurrentModTime(mLastModTime);
+
+    // associate the callback function for the timer
+    mTimer.SetTimeoutHdl(LINK(this, FileChangedChecker, TimerHandler));
+
+    //start the timer
+    resetTimer();
+}
+
+void FileChangedChecker::resetTimer()
+{
+    //Start the timer if its not active
+    if(!mTimer.IsActive())
+        mTimer.Start();
+
+    // Set a timeout of 3 seconds
+    mTimer.SetTimeout(3000);
+}
+
+bool FileChangedChecker::getCurrentModTime(TimeValue& o_rValue) const
+{
+    // Need a Directory item to fetch file status
+    osl::DirectoryItem aItem;
+    osl::DirectoryItem::get(mFileName, aItem);
+
+    // Retrieve the status - we are only interested in last File
+    // Modified time
+    osl::FileStatus aStatus( FileStatusMask_ModifyTime );
+    if( osl::FileBase::E_None != aItem.getFileStatus(aStatus) )
+        return false;
+
+    o_rValue = aStatus.getModifyTime();
+    return true;
+}
+
+bool FileChangedChecker::hasFileChanged()
+{
+    // Get the current file Status
+    TimeValue newTime={0,0};
+    if( !getCurrentModTime(newTime) )
+        return true; // well. hard to answer correctly here ...
+
+    // Check if the seconds time stamp has any difference
+    // If so, then our file has changed meanwhile
+    if( newTime.Seconds != mLastModTime.Seconds ||
+        newTime.Seconds != mLastModTime.Seconds )
+    {
+        // Since the file has changed, set the new status as the file status and
+        // return True
+        mLastModTime = newTime ;
+
+        return true;
+    }
+    else
+        return false;
+}
+
+IMPL_LINK(FileChangedChecker, TimerHandler, Timer *, EMPTYARG)
+{
+    // If the file has changed, then update the graphic in the doc
+    OSL_TRACE("Timeout Called \n");
+    if(hasFileChanged())
+    {
+        OSL_TRACE("File modified \n");
+        mpCallback();
+    }
+
+    // Reset the timer in any case
+    resetTimer();
+    return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/source/misc/makefile.mk b/svtools/source/misc/makefile.mk
index e66bba3..fe76804 100755
--- a/svtools/source/misc/makefile.mk
+++ b/svtools/source/misc/makefile.mk
@@ -60,6 +60,7 @@ SLOFILES=\
     $(SLO)$/ehdl.obj                \
     $(SLO)$/embedhlp.obj            \
     $(SLO)$/embedtransfer.obj       \
+    $(SLO)$/filechangedchecker.obj  \
     $(SLO)$/helpagentwindow.obj     \
     $(SLO)$/imagemgr.obj            \
     $(SLO)$/imageresourceaccess.obj \


More information about the Libreoffice-commits mailing list