]> vaikene.ee Git - evaf/commitdiff
Added a small utility that converts date/time values
authorEnar Vaikene <enar.vaikene@logica.com>
Wed, 18 Jul 2012 16:53:17 +0000 (18:53 +0200)
committerEnar Vaikene <enar.vaikene@logica.com>
Wed, 18 Jul 2012 16:53:17 +0000 (18:53 +0200)
to and from 4+2 bytes CUC format. Epoch can be freely
entered and has two preset values: standard UNIX time
and Galileo epoch.

src/apps/CMakeLists.txt
src/apps/ScosTime/CMakeLists.txt [new file with mode: 0644]
src/apps/ScosTime/gui.cpp [new file with mode: 0644]
src/apps/ScosTime/gui.h [new file with mode: 0644]
src/apps/ScosTime/lib.h [new file with mode: 0644]
src/apps/ScosTime/version.h [new file with mode: 0644]
src/apps/ScosTime/version.rc [new file with mode: 0644]

index 3aa82ad26cbbc63de67bc7df7a6da4546df52c07..1bd0076508fa262792a500bf53e8b03bb541c55b 100644 (file)
@@ -2,3 +2,4 @@ set(eVaf_INCLUDE ${eVaf_INCLUDE} ${CMAKE_SOURCE_DIR}/src/apps/FileFinder)
 
 add_subdirectory(PswGen)
 add_subdirectory(FileFinder)
+add_subdirectory(ScosTime)
diff --git a/src/apps/ScosTime/CMakeLists.txt b/src/apps/ScosTime/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c56fb72
--- /dev/null
@@ -0,0 +1,41 @@
+# Name of the target
+set(TARGET ScosTime)
+
+# Qt modules
+include(${QT_USE_FILE})
+
+# Include files
+include_directories(${eVaf_INCLUDE})
+
+# Required eVaf libraries
+set(eVaf_LIBRARIES CommonLib PluginsLib GuiLib)
+
+# Source files
+set(SRCS
+    gui.cpp
+)
+
+# Header files for the meta-object compiler
+set(MOC_HDRS
+    gui.h
+)
+
+# Resources
+#set(RCCS
+#    gui.qrc
+#)
+
+# Version info resource file for Windows builds
+if(WIN32 AND NOT MINGW)
+    set(SRCS ${SRCS} version.rc)
+endif(WIN32 AND NOT MINGW)
+
+qt4_add_resources(RCC_SRCS ${RCCS})
+
+qt4_wrap_cpp(MOC_SRCS ${MOC_HDRS})
+
+add_library(${TARGET} SHARED ${SRCS} ${MOC_SRCS} ${RCC_SRCS})
+
+target_link_libraries(${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES})
+
+install(TARGETS ${TARGET} DESTINATION bin)
diff --git a/src/apps/ScosTime/gui.cpp b/src/apps/ScosTime/gui.cpp
new file mode 100644 (file)
index 0000000..1ea9ba1
--- /dev/null
@@ -0,0 +1,206 @@
+/**
+ * @file ScosTime/gui.cpp
+ * @brief GUI for the ScosTime application
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2012 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#include "gui.h"
+#include "version.h"
+
+#include <Common/Globals>
+#include <Common/iLogger>
+#include <Common/iRegistry>
+#include <SdiWindow/iSdiWindow>
+#include <Gui/Panel>
+
+#include <QtGui>
+
+
+VER_EXPORT_VERSION_INFO()
+Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, eVaf::ScosTime::Module)
+
+
+//-------------------------------------------------------------------
+
+using namespace eVaf;
+using namespace eVaf::ScosTime;
+
+Module::Module()
+    : Plugins::iPlugin()
+    , mReady(false)
+{
+    setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
+
+    EVAF_INFO("%s created", qPrintable(objectName()));
+}
+
+Module::~Module()
+{
+    EVAF_INFO("%s destroyed", qPrintable(objectName()));
+}
+
+bool Module::init(QString const & args)
+{
+    Q_UNUSED(args);
+
+    // Get the main window interface and fill it with the widgets
+    SdiWindow::iSdiWindow * win = evafQueryInterface<SdiWindow::iSdiWindow>("iSdiWindow");
+    EVAF_TEST_X(win, "No iSdiWindow interface");
+
+    Gui::Panel * panel = new Gui::Panel;
+    win->addPanel("PswGen", panel);
+
+    QVBoxLayout * v = new QVBoxLayout;
+    panel->setLayout(v);
+
+    QGridLayout * g = new QGridLayout;
+    v->addLayout(g);
+    g->setColumnStretch(1, 2);
+
+    QLabel * l = new QLabel(tr("&Epoch:", VER_MODULE_NAME_STR));
+    l->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+    g->addWidget(l, 0, 0);
+
+    wEpoch = new QComboBox;
+    l->setBuddy(wEpoch);
+    wEpoch->setEditable(true);
+    wEpoch->addItems(QStringList() << "1970-01-01T00:00:00.000" << "1999-08-22T00:00:00.000");
+    g->addWidget(wEpoch, 0, 1);
+    panel->setFocusProxy(wEpoch);
+
+    l = new QLabel(tr("&Date/time:", VER_MODULE_NAME_STR));
+    l->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+    g->addWidget(l, 1, 0);
+
+    wDateTime = new QLineEdit;
+    l->setBuddy(wDateTime);
+    QRegExp rxDateTime("^\\d{4}\\.\\d{3}\\.\\d{2}\\.\\d{2}\\.\\d{2}(\\.\\d{3})?$");
+    wDateTime->setValidator(new QRegExpValidator(rxDateTime, wDateTime));
+    g->addWidget(wDateTime, 1, 1);
+
+    QPushButton * btn = new QPushButton(tr("Convert", VER_MODULE_NAME_STR));
+    g->addWidget(btn, 1, 2);
+    connect(btn, SIGNAL(clicked()), this, SLOT(dateTimeClicked()));
+
+    l = new QLabel(tr("&HEX:", VER_MODULE_NAME_STR));
+    l->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+    g->addWidget(l, 2, 0);
+
+    wHex = new QLineEdit;
+    l->setBuddy(wHex);
+    wHex->setMaxLength(12);
+    wHex->setInputMask(">HHHHHHHHhhhh");
+    g->addWidget(wHex, 2, 1);
+
+    btn = new QPushButton(tr("Convert", VER_MODULE_NAME_STR));
+    g->addWidget(btn, 2, 2);
+    connect(btn, SIGNAL(clicked()), this, SLOT(hexClicked()));
+
+    v->addStretch();
+
+    QHBoxLayout * h = new QHBoxLayout;
+    h->addStretch();
+    v->addLayout(h);
+
+    QAction * a = new QAction(panel);
+    a->setShortcut(Qt::Key_Escape);
+    connect(a, SIGNAL(triggered()), qApp, SLOT(quit()));
+    panel->addAction(a);
+
+    mReady = true;
+
+    EVAF_INFO("%s initialized", qPrintable(objectName()));
+
+    return true;
+}
+
+void Module::done()
+{
+    mReady = false;
+
+    EVAF_INFO("%s finalized", qPrintable(objectName()));
+}
+
+QDateTime Module::strToDateTime(QString const & s) const
+{
+    QStringList tok = s.split(QChar('.'));
+    if (tok.size() < 5)
+        return QDateTime();
+
+    bool ok = false;
+    int year = tok.at(0).toInt(&ok);
+    if (!ok)
+        return QDateTime();
+    int days = tok.at(1).toInt(&ok);
+    if (!ok)
+        return QDateTime();
+    int hours = tok.at(2).toInt(&ok);
+    if (!ok)
+        return QDateTime();
+    int minutes = tok.at(3).toInt(&ok);
+    if (!ok)
+        return QDateTime();
+    int secs = tok.at(4).toInt(&ok);
+    if (!ok)
+        return QDateTime();
+    int msecs = 0;
+    if (tok.size() > 5) {
+        msecs = tok.at(5).toInt(&ok);
+        if (!ok)
+            return QDateTime();
+    }
+
+    QDate dt(year, 1, 1);
+    dt = dt.addDays(days - 1);
+
+    return QDateTime(dt, QTime(hours, minutes, secs, msecs), Qt::UTC);
+}
+
+void Module::dateTimeClicked()
+{
+    QDateTime epoch = QDateTime::fromString(wEpoch->currentText(), Qt::ISODate);
+    epoch.setTimeSpec(Qt::UTC);
+    QDateTime tm = strToDateTime(wDateTime->text());
+    qint64 msecs = epoch.msecsTo(tm);
+    quint32 coarse = quint32(msecs / 1000);
+    quint32 fine = quint32(rint(1000.0 * double(msecs % 1000) * 58.0 / 885.0));
+    wHex->setText(QString("%1%2").arg(coarse, 8, 16, QChar('0')).arg(fine, 4, 16, QChar('0')));
+}
+
+void Module::hexClicked()
+{
+    bool ok = false;
+    int coarse = wHex->text().left(8).toLong(&ok, 16);
+    if (!ok)
+        return;
+    int fine = 0;
+    if (wHex->text().size() > 8)
+        fine = wHex->text().mid(8, 4).toLong(&ok, 16);
+    if (!ok)
+        return;
+
+    QDateTime epoch = QDateTime::fromString(wEpoch->currentText(), Qt::ISODate);
+    epoch.setTimeSpec(Qt::UTC);
+    QDateTime tm = epoch.addSecs(coarse);
+    tm = tm.addMSecs(rint((double(fine) / 58.0 * 885.0) / 1000.0));
+    wDateTime->setText(QString("%1.%2.%3.%4.%5.%6")
+                       .arg(tm.date().year(), 4, 10, QChar('0'))
+                       .arg(tm.date().dayOfYear(), 3, 10, QChar('0'))
+                       .arg(tm.time().hour(), 2, 10, QChar('0'))
+                       .arg(tm.time().minute(), 2, 10, QChar('0'))
+                       .arg(tm.time().second(), 2, 10, QChar('0'))
+                       .arg(tm.time().msec(), 3, 10, QChar('0')));
+}
diff --git a/src/apps/ScosTime/gui.h b/src/apps/ScosTime/gui.h
new file mode 100644 (file)
index 0000000..fe6b5e3
--- /dev/null
@@ -0,0 +1,84 @@
+/**
+ * @file ScosTime/gui.h
+ * @brief GUI for the ScosTime application
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2012 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#ifndef __SCOSTIME_GUI_H
+#  define __SCOSTIME_GUI_H
+
+#include <Plugins/iPlugin>
+
+#include <QObject>
+#include <QString>
+#include <QDateTime>
+
+class QLineEdit;
+class QComboBox;
+
+namespace eVaf {
+namespace ScosTime {
+
+/**
+ * Graphical User Interface for the ScosTime application.
+ *
+ * This module adds a GUI window to the ScosTime application using the SdiWindow module.
+ */
+class Module : public Plugins::iPlugin
+{
+    Q_OBJECT
+    Q_INTERFACES(eVaf::Plugins::iPlugin)
+
+public:
+
+    Module();
+
+    virtual ~Module();
+
+    virtual bool init(const QString & args);
+
+    virtual void done();
+
+    virtual bool isReady() const { return mReady; }
+
+
+private slots:
+
+    void dateTimeClicked();
+
+    void hexClicked();
+
+
+private: // Methods
+
+    QDateTime strToDateTime(QString const & s) const;
+
+private: // Members
+
+    /// Flag indicating that the module is ready
+    bool mReady;
+
+    /// Widgets on the screen
+    QComboBox * wEpoch;
+    QLineEdit * wDateTime;
+    QLineEdit * wHex;
+
+};
+
+} // namespace eVaf::ScosTime
+} // namespace eVaf
+
+#endif // gui.h
diff --git a/src/apps/ScosTime/lib.h b/src/apps/ScosTime/lib.h
new file mode 100644 (file)
index 0000000..e062e08
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * @file ScosTime/lib.h
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2012 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#ifndef __SCOSTIME_LIB_H
+#  define __SCOSTIME_LIB_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(SCOSTIME_LIBRARY)
+#  define SCOSTIME_EXPORT Q_DECL_EXPORT
+#else
+#  define SCOSTIME_EXPORT Q_DECL_IMPORT
+#endif
+
+#endif // lib.h
diff --git a/src/apps/ScosTime/version.h b/src/apps/ScosTime/version.h
new file mode 100644 (file)
index 0000000..d3a0b51
--- /dev/null
@@ -0,0 +1,60 @@
+/**
+ * @file ScosTime/version.h
+ * @brief Version information for eVaf modules
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2012 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#ifndef __SCOSTIME_VERSION_H
+#  define __SCOSTIME_VERSION_H
+
+#include <version_rc.h>
+
+/**
+ * Module/library version number in the form major,minor,release,build
+ */
+#define VER_FILE_VERSION                0,1,1,1
+
+/**
+ * Module/library version number in the string format (shall end with \0)
+ */
+#define VER_FILE_VERSION_STR            "0.1.1.1\0"
+
+/**
+ * Module/library name (shall end with \0)
+ */
+#define VER_MODULE_NAME_STR             "ScosTime\0"
+
+/**
+ * Module type (see version_rc.h for all the types)
+ */
+#define VER_MODULE_TYPE                 MT_GENERIC
+
+/**
+ * Module type in the string format (see version_rc for all the types)
+ */
+#define VER_MODULE_TYPE_STR             MT_GENERIC
+
+/**
+ * Original file name for windows (shall end with \0)
+ */
+#define VER_ORIGINAL_FILE_NAME_STR      "ScosTime.dll\0"
+
+/**
+ * Description of the module/library (shall end with \0)
+ */
+#define VER_FILE_DESCRIPTION_STR         "Small tool to encode and decode date/time values.\0"
+
+#endif // version.h
diff --git a/src/apps/ScosTime/version.rc b/src/apps/ScosTime/version.rc
new file mode 100644 (file)
index 0000000..2c0f57b
--- /dev/null
@@ -0,0 +1,54 @@
+/**
+ * @file ScosTime/version.rc
+ * @brief Windows resource file with module/library version information.
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2012 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#include "version.h"
+#include <version_rc.h>
+#include <winver.h>
+
+
+VS_VERSION_INFO VERSIONINFO
+        FILEVERSION VER_FILE_VERSION
+        PRODUCTVERSION VER_PRODUCT_VERSION
+        FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+        FILEFLAGS VS_FF_DEBUG
+#else
+        FILEFLAGS 0x0L
+#endif
+        FILEOS VOS__WINDOWS32
+        FILETYPE VFT_DLL
+        FILESUBTYPE 0x0L
+        BEGIN
+                BLOCK "StringFileInfo"
+                BEGIN
+                        BLOCK "040904B0"
+                        BEGIN
+                                VALUE "CompanyName", VER_COMPANY_NAME_STR
+                                VALUE "FileDescription", VER_FILE_DESCRIPTION_STR
+                                VALUE "FileVersion", VER_FILE_VERSION_STR
+                                VALUE "LegalCopyright", VER_LEGAL_COPYRIGHT_STR
+                                VALUE "OriginalFilename", VER_ORIGINAL_FILE_NAME_STR
+                                VALUE "ProductName", VER_PRODUCT_NAME_STR
+                                VALUE "ProductVersion", VER_PRODUCT_VERSION_STR
+                                VALUE "Build Date", VER_PRODUCT_DATE_STR
+                                VALUE "Module Name", VER_MODULE_NAME_STR
+                                VALUE "Module Type", VER_MODULE_TYPE_STR
+                        END
+                END
+        END