From 287ff7a1d6ace859b001a0d4f5cfad1913416416 Mon Sep 17 00:00:00 2001 From: Jan Darmochwal Date: Mon, 4 Oct 2010 17:19:12 +0200 Subject: Allow sessions to be active for a given date range .xml files for Virtual Sessions may have an "active"-element this patch allows a date range to be given as a parameter for that element examples: * active from Jan 1st 1970 till Jan 1st 1971 * active till Jan 1st 1971 * active from Jan 1st 1970 onwards notes: * invalid dates are treated like empty dates (eg. "1984-01-01/1984-02-30" is equal to "1984-01-01/") * active defaults to "true" for all values except "false" and past or future date ranges * an inactive session will not be displayed by vmchooser, this does not prevent the user from manually starting the corrensponding virtual machine image --- src/vsession.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src/vsession.cpp') diff --git a/src/vsession.cpp b/src/vsession.cpp index f51fa3a..35292d2 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #if 0 #include // available since Qt 4.7 #endif @@ -83,8 +85,39 @@ ImgType VSession::imgtype() const { } bool VSession::isActive() const { - // default to true - return getAttribute("active").compare("false"); + QString value(getAttribute("active")); + + if (value.compare("false")) { + return false; + } else if (value.count("/") == 1) { + // try to interpret value as date range + // [YYYY-MM-DD]/[YYYY-MM-DD] + // eg. "1970-01-01/1971-01-01" from Jan 1st 1970 till Jan 1st 1971 + // "/1971-01-01" till Jan 1st 1971 + // "1970-01-01/" from Jan 1st 1970 + // "/" allways + // note: invalid dates are treated as empty dates + + QStringList list(value.split("/")); + QString from(list.value(0)); + QString till(list.value(1)); + QDate fromDate(QDate::fromString(from, Qt::ISODate)); + QDate tillDate(QDate::fromString(till, Qt::ISODate)); + + QDate today(QDate::currentDate()); + + if (fromDate.isValid() && fromDate > today) { + // fromDate is in the future + return false; + } + + if (tillDate.isValid() && tillDate < today) { + // tillDate is in the past + return false; + } + } + + return true; } bool VSession::isLocked() const { -- cgit v1.2.3-55-g7522