summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Darmochwal2010-10-04 17:19:12 +0200
committerJan Darmochwal2010-10-04 17:19:12 +0200
commit287ff7a1d6ace859b001a0d4f5cfad1913416416 (patch)
tree82f7695f4fcd842e3eb00a5b59d37a938ffa75a1
parentTreeView for sessions (replaces ListView) (diff)
downloadvmchooser-287ff7a1d6ace859b001a0d4f5cfad1913416416.tar.gz
vmchooser-287ff7a1d6ace859b001a0d4f5cfad1913416416.tar.xz
vmchooser-287ff7a1d6ace859b001a0d4f5cfad1913416416.zip
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 <active param="[YYYY-MM-DD]/[YYYY-MM-DD]"/> examples: * <active param="1970-01-01/1971-01-01"> active from Jan 1st 1970 till Jan 1st 1971 * <active param="/1971-01-01"> active till Jan 1st 1971 * <active param="1970-01-01/"> 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
-rw-r--r--src/vsession.cpp37
1 files changed, 35 insertions, 2 deletions
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 <QDir>
#include <QApplication>
#include <QProcess>
+#include <QDate>
+#include <QStringList>
#if 0
#include <QHostInfo> // 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 {