summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Schmelzer2011-11-02 12:24:32 +0100
committerSebastian Schmelzer2011-11-02 12:24:32 +0100
commitb14c8f0b4453c15b3608a1da4f95d51ef17461a0 (patch)
tree9b54be369b1d297867b6367a78f3a35db32f2365
downloadlibChooser-b14c8f0b4453c15b3608a1da4f95d51ef17461a0.tar.gz
libChooser-b14c8f0b4453c15b3608a1da4f95d51ef17461a0.tar.xz
libChooser-b14c8f0b4453c15b3608a1da4f95d51ef17461a0.zip
initial import
-rw-r--r--.gitignore7
-rw-r--r--AUTHORS0
-rw-r--r--CMakeLists.txt14
-rw-r--r--COPYING340
-rw-r--r--INSTALL0
-rw-r--r--README0
-rw-r--r--src/CMakeLists.txt45
-rw-r--r--src/Defaults.h25
-rw-r--r--src/Session.h50
-rw-r--r--src/SessionTreeItem.cpp65
-rw-r--r--src/SessionTreeItem.h49
-rw-r--r--src/SessionTreeModel.cpp179
-rw-r--r--src/SessionTreeModel.h50
-rw-r--r--src/VSession.cpp356
-rw-r--r--src/VSession.h136
-rw-r--r--src/VSessionHandler.cpp190
-rw-r--r--src/VSessionHandler.h62
-rw-r--r--src/XSession.cpp150
-rw-r--r--src/XSession.h93
-rw-r--r--src/XSessionHandler.cpp47
-rw-r--r--src/XSessionHandler.h29
21 files changed, 1887 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d758817
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+/educhooser
+Makefile*
+moc_*
+debug
+release
+.project
+.cproject
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/AUTHORS
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..9de597e
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 2.6)
+project(libChooser)
+
+#
+# Qt4
+#
+find_package(Qt4 4.5.0 REQUIRED)
+if(QT4_FOUND)
+message(STATUS "Qt4 found")
+else(QT4_FOUND)
+message(FATAL_ERROR "Qt4 not found")
+endif(QT4_FOUND)
+
+add_subdirectory (src)
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..d60c31a
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/INSTALL
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..d81ebf8
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,45 @@
+include(${QT_USE_FILE})
+
+set(QT_USE_QTXML TRUE)
+set(QT_USE_QTSVG TRUE)
+
+include(${QT_USE_FILE})
+
+set(LCHOOSER_MOC_HEADERS "SessionTreeModel.h")
+set(LCHOOSER_MOC_SOURCES "SessionTreeModel.cpp")
+set(LCHOOSER_HEADERS "Session.h" "SessionTreeItem.h" "VSession.h" "VSessionHandler.h" "XSession.h" "XSessionHandler.h")
+set(LCHOOSER_SOURCES "SessionTreeItem.cpp" "VSession.cpp" "VSessionHandler.cpp" "XSession.cpp" "XSessionHandler.cpp")
+
+QT4_WRAP_CPP(LCHOOSER_MOC_SOURCES ${LCHOOSER_MOC_HEADERS})
+
+add_library (Chooser_static STATIC ${LCHOOSER_SOURCES} ${LCHOOSER_MOC_SOURCES} ${LCHOOSER_HEADERS} ${LCHOOSER_MOC_HEADERS})
+set_target_properties (Chooser_static PROPERTIES OUTPUT_NAME Chooser)
+add_library (Chooser_shared SHARED ${LCHOOSER_SOURCES} ${LCHOOSER_MOC_SOURCES} ${LCHOOSER_HEADERS} ${LCHOOSER_MOC_HEADERS})
+set_target_properties (Chooser_shared PROPERTIES OUTPUT_NAME Chooser)
+set(MY_OWN_INSTALL_PREFIX "/usr" CACHE PATH "Prefix prepended to install directories")
+set(CMAKE_INSTALL_PREFIX "${MY_OWN_INSTALL_PREFIX}" CACHE INTERNAL "Prefix prepended to install directories" FORCE)
+install(TARGETS Chooser_static Chooser_shared
+ LIBRARY DESTINATION lib COMPONENT libs
+ ARCHIVE DESTINATION lib COMPONENT libs
+)
+
+install(FILES ${LCHOOSER_MOC_HEADERS} ${LCHOOSER_HEADERS} DESTINATION include COMPONENT dev)
+
+set(CPACK_COMPONENTS_ALL libs dev)
+set(CPACK_COMPONENT_LIBS_DISPLAY_NAME "libChooser")
+set(CPACK_COMPONENT_DEV_DISPLAY_NAME "libChooser-dev")
+set(CPACK_COMPONENT_LIBS_DESCRIPTION "libChooser")
+set(CPACK_COMPONENT_DEV_DESCRIPTION "libChooser development headers")
+set(CPACK_COMPONENT_LIBS_GROUP "core")
+set(CPACK_COMPONENT_DEV_GROUP "dev")
+set(CPACK_COMPONENT_DEV_DEPENDS libs)
+
+set(CPACK_GENERATOR "DEB")
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sebastian Schmelzer <ssc@xss.nu>") #required
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "emuchooser is ...")
+set(CPACK_PACKAGE_DESCRIPTION "...")
+set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqtcore4")
+set(CPACK_DEBIAN_PACKAGE_SECTION "")
+set(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}1.1.1+lenny1")
+
+INCLUDE(CPack)
diff --git a/src/Defaults.h b/src/Defaults.h
new file mode 100644
index 0000000..d168248
--- /dev/null
+++ b/src/Defaults.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#ifndef CHOOSERDEFAULTS_H_
+#define CHOOSERDEFAULTS_H_
+
+#define LIBCHOOSER_BIN_PATH "/var/opt/openslx/bin"
+#define LIBCHOOSER_ETC_BASE_PATH "/etc/vmchooser"
+#define LIBCHOOSER_VMPATH "/var/lib/virt"
+
+#define LIBCHOOSER_X_SESSIONS_PATH "/usr/share/xsessions"
+
+#endif /* CHOOSERDEFAULTS_H_ */
diff --git a/src/Session.h b/src/Session.h
new file mode 100644
index 0000000..4b0ad69
--- /dev/null
+++ b/src/Session.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#ifndef VMCHOOSER_SESSION_H_
+#define VMCHOOSER_SESSION_H_
+
+class QString;
+
+class Session {
+ public:
+ virtual ~Session() {}
+
+ virtual bool isActive() const = 0;
+ virtual bool isLocked() const = 0;
+ virtual bool isValid() const = 0;
+ virtual int priority() const = 0;
+ virtual QString shortDescription() const = 0;
+ virtual QString description() const = 0;
+ virtual QString icon() const = 0;
+
+ virtual QString title() const = 0;
+ virtual QString screenshot() const = 0;
+ virtual QString os() const = 0;
+ virtual QString emulator() const = 0;
+ virtual QString author() const = 0;
+ virtual QString creationDate () const = 0;
+ virtual QString changeDate() const = 0;
+
+ virtual bool run() const = 0;
+ virtual int type() const = 0;
+
+ virtual bool operator<(const Session& s) const = 0;
+
+ const static int XSESSION = 0;
+ const static int VSESSION = 1;
+
+};
+#endif /*VMCHOOSER_SESSION_H_*/
diff --git a/src/SessionTreeItem.cpp b/src/SessionTreeItem.cpp
new file mode 100644
index 0000000..ed7ead7
--- /dev/null
+++ b/src/SessionTreeItem.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#include "SessionTreeItem.h"
+
+SessionTreeItem::SessionTreeItem(const Session* session,
+ SessionTreeItem *parent)
+ : parent_(parent), session_(session) {
+}
+
+SessionTreeItem::SessionTreeItem(const QString& text, SessionTreeItem *parent)
+ : parent_(parent), session_(NULL), text_(text) {
+}
+
+SessionTreeItem::~SessionTreeItem() {
+ qDeleteAll(children_);
+}
+
+void SessionTreeItem::appendChild(SessionTreeItem *item) {
+ children_.append(item);
+}
+
+SessionTreeItem *SessionTreeItem::child(int row) {
+ return children_.value(row);
+}
+
+int SessionTreeItem::childCount() const {
+ return children_.count();
+}
+
+int SessionTreeItem::columnCount() const {
+ return 1;
+}
+
+SessionTreeItem *SessionTreeItem::parent() {
+ return parent_;
+}
+
+int SessionTreeItem::row() const {
+ if (parent_) {
+ return parent_->children_.indexOf(const_cast<SessionTreeItem*>(this));
+ }
+
+ return 0;
+}
+
+const Session* SessionTreeItem::session() const {
+ return session_;
+}
+
+const QString SessionTreeItem::text() const {
+ return text_;
+}
diff --git a/src/SessionTreeItem.h b/src/SessionTreeItem.h
new file mode 100644
index 0000000..1c41195
--- /dev/null
+++ b/src/SessionTreeItem.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#ifndef SESSIONTREEITEM_H
+#define SESSIONTREEITEM_H
+
+#include <QList>
+#include <QVariant>
+
+// class ... instead of include?
+#include "Session.h"
+#include <QString>
+
+class SessionTreeItem {
+ public:
+ SessionTreeItem(const Session* session, SessionTreeItem *parent = 0);
+ SessionTreeItem(const QString& text, SessionTreeItem *parent = 0);
+ ~SessionTreeItem();
+
+ void appendChild(SessionTreeItem *child);
+
+ SessionTreeItem *child(int row);
+ int childCount() const;
+ int columnCount() const;
+ int row() const;
+ SessionTreeItem *parent();
+ const Session* session() const;
+ const QString text() const;
+
+ private:
+ QList<SessionTreeItem*> children_;
+ SessionTreeItem *parent_;
+ const Session *session_;
+ const QString text_;
+};
+
+#endif // SESSIONTREEITEM_H
diff --git a/src/SessionTreeModel.cpp b/src/SessionTreeModel.cpp
new file mode 100644
index 0000000..273d050
--- /dev/null
+++ b/src/SessionTreeModel.cpp
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#include <QFileInfo>
+#include <QIcon>
+#include <QResource>
+#include <QString>
+
+#include "SessionTreeItem.h"
+#include "SessionTreeModel.h"
+
+
+SessionTreeModel::SessionTreeModel(QObject *parent)
+ : QAbstractItemModel(parent) {
+ root_ = new SessionTreeItem("dummy");
+}
+
+SessionTreeModel::~SessionTreeModel() {
+ delete root_;
+}
+
+int SessionTreeModel::columnCount(const QModelIndex& /*parent*/) const {
+ return 1;
+}
+
+int SessionTreeModel::rowCount(const QModelIndex &parent) const {
+ SessionTreeItem* parentItem;
+ if (parent.column() > 0) {
+ return 0;
+ }
+
+ if (!parent.isValid()) {
+ parentItem = root_;
+ } else {
+ parentItem = static_cast<SessionTreeItem*>(parent.internalPointer());
+ }
+
+ return parentItem->childCount();
+}
+
+QVariant SessionTreeModel::data(const QModelIndex &index, int role) const {
+ if (!index.isValid()) {
+ return QVariant();
+ }
+
+ SessionTreeItem* item =
+ static_cast<SessionTreeItem*>(index.internalPointer());
+
+ const Session* s = item->session();
+ if (s) {
+ if (role == Qt::DisplayRole)
+ return s->shortDescription();
+ if (role == Qt::ToolTipRole)
+ return s->description();
+ if (role == Qt::DecorationRole) {
+ // TODO: use cache for icons
+ if (index.column() == 0) { // TODO: is this line needed?
+ QString icon(s->icon());
+
+ if (QFileInfo(icon).isAbsolute()) {
+ // try to load icon from file
+ return QIcon(icon);
+ } else {
+ // try to load icon from QResource
+ if (QResource(":" + icon.toLower() + ".svg").isValid()) {
+ return QIcon(":" + icon.toLower() + ".svg");
+ } else if (QResource(":icons/" + icon.toLower()).isValid()) {
+ return QIcon(":icons/" + icon.toLower());
+ } else if (QResource(":" + icon.toLower()).isValid()) {
+ return QIcon(":" + icon.toLower());
+ } else {
+ return QIcon(":none");
+ }
+ }
+ }
+ }
+ } else if (role == Qt::DisplayRole) {
+ // this is a section item (X Sessions / Virtual Sessions)
+ return item->text();
+ }
+
+ return QVariant();
+}
+
+Qt::ItemFlags SessionTreeModel::flags(const QModelIndex &index) const {
+ if (!index.isValid()) {
+ return 0;
+ }
+
+ SessionTreeItem* item =
+ static_cast<SessionTreeItem*>(index.internalPointer());
+
+ if (item->session()) {
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+ } else {
+ return Qt::ItemIsEnabled;
+ }
+}
+
+QVariant SessionTreeModel::headerData(int /*section*/,
+ Qt::Orientation /*orientation*/,
+ int /*role*/) const {
+ return QVariant();
+}
+
+QModelIndex SessionTreeModel::index(int row, int column,
+ const QModelIndex &parent) const {
+ if (!hasIndex(row, column, parent)) {
+ return QModelIndex();
+ }
+
+ SessionTreeItem *parentItem;
+
+ if (!parent.isValid()) {
+ parentItem = root_;
+ } else {
+ parentItem = static_cast<SessionTreeItem*>(parent.internalPointer());
+ }
+
+ SessionTreeItem *childItem = parentItem->child(row);
+ if (childItem) {
+ return createIndex(row, column, childItem);
+ } else {
+ return QModelIndex();
+ }
+}
+
+QModelIndex SessionTreeModel::parent(const QModelIndex &index) const {
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
+
+ SessionTreeItem *childItem =
+ static_cast<SessionTreeItem*>(index.internalPointer());
+ SessionTreeItem *parentItem = childItem->parent();
+
+ if (parentItem == root_) {
+ return QModelIndex();
+ }
+
+ return createIndex(parentItem->row(), 0, parentItem);
+}
+
+void SessionTreeModel::addItems(const QList<Session*>& sessions,
+ const QString& section) {
+ SessionTreeItem* parentItem;
+
+ bool sectionExists = false;
+
+ for (int i = 0; i < root_->childCount(); ++i) {
+ SessionTreeItem* item = root_->child(i);
+ if (item->text() == section) {
+ parentItem = item;
+ sectionExists = true;
+ break;
+ }
+ }
+
+ if (!sectionExists) {
+ parentItem = new SessionTreeItem(section, root_);
+ root_->appendChild(parentItem);
+ }
+
+ foreach (Session* s, sessions) {
+ parentItem->appendChild(new SessionTreeItem(s, parentItem));
+ }
+}
diff --git a/src/SessionTreeModel.h b/src/SessionTreeModel.h
new file mode 100644
index 0000000..34b830e
--- /dev/null
+++ b/src/SessionTreeModel.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#ifndef VMCHOOSER_SESSIONTREEMODEL_H
+#define VMCHOOSER_SESSIONTREEMODEL_H
+
+#include <QAbstractItemModel>
+#include <QModelIndex>
+#include <QVariant>
+
+class SessionTreeItem;
+class Session;
+
+class SessionTreeModel : public QAbstractItemModel {
+ Q_OBJECT
+
+ public:
+ explicit SessionTreeModel(QObject *parent = 0);
+ ~SessionTreeModel();
+
+ QVariant data(const QModelIndex &index, int role) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column,
+ const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex &index) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ void addItems(const QList<Session*>& sessions, const QString& section);
+
+
+ private:
+ SessionTreeItem* root_;
+};
+
+#endif // VMCHOOSER_SESSIONTREEMODEL_H
diff --git a/src/VSession.cpp b/src/VSession.cpp
new file mode 100644
index 0000000..76e13b0
--- /dev/null
+++ b/src/VSession.cpp
@@ -0,0 +1,356 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#include <QtXml>
+#include <QDir>
+#include <QApplication>
+#include <QProcess>
+#include <QDate>
+#include <QStringList>
+#include <QTextStream>
+#if 0
+#include <QHostInfo> // available since Qt 4.7
+#endif
+#include <limits> // for HOST_NAME_MAX
+#include <unistd.h> // for gethostname(), getuid()
+#include <sys/types.h> // for getuid, getpwuid
+#include <pwd.h> // for getpwuid
+//#include "globals.h"
+
+#include "VSession.h"
+#include "VSessionHandler.h"
+
+bool VSession::debugMode = false;
+
+VSession::VSession(VSessionHandler *parent) {
+ sessionHandler = parent;
+}
+
+bool VSession::init(const QString& xml, const QString& baseDirPath) {
+ this->baseDirPath_ = baseDirPath;
+ _process = new QProcess();
+ return this->doc_.setContent(xml);
+}
+
+void VSession::addNodeWithAttribute(const QString& nodeName,
+ const QString& value,
+ const QString& attribute,
+ bool replace) {
+ QDomElement node =
+ this->doc_.namedItem("eintrag").namedItem(nodeName).toElement();
+
+ if (replace == false || node.isNull()) {
+ // create a new node
+ node = this->doc_.createElement(nodeName);
+ this->doc_.namedItem("eintrag").appendChild(node);
+ }
+
+ node.setAttribute(attribute, value);
+}
+
+QString VSession::icon() const {
+ QString icon(getAttribute("icon"));
+ if (icon.isEmpty()) {
+ if (imgtype() == VMWARE) icon = "vmware";
+ else if (imgtype() == VBOX) icon = "virtualbox";
+ else icon = "unknown";
+ } else if (icon.contains(".") && QDir::isRelativePath(icon)) {
+ // non-built-in icon with relative path
+ icon.prepend(baseDirPath_ + "/");
+ }
+ return icon;
+ }
+
+QString VSession::screenshot() const {
+ QString ret;
+ ret = getAttribute("screenshot");
+// qDebug() << ret;
+ if (ret.size() > 0) {
+ ret.prepend(baseDirPath_ + "/");
+ ret.prepend("file://");
+ return ret;
+ }
+ return QString("qrc:/img/noscreenshot");
+};
+
+
+QString VSession::toXml() const {
+ QDomDocument doc;
+ doc.appendChild(doc.createElement("settings"));
+
+ doc.firstChild().appendChild(doc.importNode(doc_.documentElement(), true));
+
+ QDomNode xmlNode = doc.createProcessingInstruction(
+ "xml", "version=\"1.0\" encoding=\"UTF-8\"");
+ doc.insertBefore(xmlNode, doc.firstChild());
+
+ return doc.toString();
+}
+
+QString VSession::getAttribute(const QString &nodeName,
+ const QString &attribute) const {
+ QDomDocument doc = this->doc_;
+ QDomNode n = doc.namedItem("eintrag").namedItem(nodeName);
+ return this->doc_.namedItem("eintrag").namedItem(nodeName).toElement()
+ .attribute(attribute);
+}
+
+QString VSession::getNodeText(const QString& nodeName) const {
+ QString str;
+ QTextStream stream(&str);
+ QDomNode node = this->doc_.namedItem("eintrag").namedItem(nodeName).toElement();
+ node.save(stream, 4);
+
+// return this->doc_.namedItem("eintrag").namedItem(nodeName).toElement().text();
+ return str;
+}
+
+ImgType VSession::imgtype() const {
+ QString s(getAttribute("virtualmachine"));
+
+ if (s.compare("vmware") == 0) {
+ return VMWARE;
+ } else if (s.compare("virtualbox") == 0 || s.compare("vbox") == 0) {
+ return VBOX;
+ } else {
+ return OTHER;
+ }
+}
+
+bool VSession::isActive() const {
+ QString value(getAttribute("active"));
+
+ if (value.compare("false") == 0) {
+ 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
+ if (debugMode) qDebug() << "Not active. Reason: fromDate is in the future";
+ return false;
+ }
+
+ if (tillDate.isValid() && tillDate < today) {
+ // tillDate is in the past
+ if (debugMode) qDebug() << "Not active. Reason: tillDate is in the past";
+ return false;
+ }
+ }
+
+ if (sessionHandler->hasEnv()) {
+ QStringList pools = getAttribute("pools").split("\\s*,\\s*");
+ if (!pools.isEmpty() && !pools.contains(sessionHandler->getEnv())) {
+ // pools does not contain pool
+ if (debugMode) qDebug() << "Not active. Reason: vsession is not part of active env";
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool VSession::isLocked() const {
+ // default to false
+ return getAttribute("locked").compare("true") == 0;
+}
+
+bool VSession::isValid() const {
+ // default to false
+ return QFile::exists(QString(this->baseDirPath_).append("/").append(getAttribute("image_name")));
+}
+
+int VSession::priority() const {
+ return getAttribute("priority").toInt();
+}
+
+
+void VSession::addPrinters(const QString& script, const QString& type) {
+ QDomElement printersNode =
+ this->doc_.namedItem("eintrag").namedItem(type + "s").toElement();
+
+ if (printersNode.isNull()) {
+ // create new printers node
+ printersNode = this->doc_.createElement(type + "s");
+ this->doc_.namedItem("eintrag").appendChild(printersNode);
+ }
+
+ QProcess addPrintersScript;
+ addPrintersScript.start(script, QIODevice::ReadOnly);
+ while (!addPrintersScript.atEnd()) {
+ QString line(addPrintersScript.readLine());
+ QStringList tokens(line.split("\t"));
+
+ if (tokens.size() < 2 or tokens.size() > 3) {
+ // TODO error message
+ // invalid output of printerScript
+ // printserver\tprinter\tprinter description
+ continue;
+ }
+
+ QDomElement printerNode(doc_.createElement(type));
+ printerNode.setAttribute("name", tokens.at(1));
+ printerNode.setAttribute("path",
+ "\\\\" + tokens.at(0) + "\\" + tokens.at(1));
+ if (tokens.size() == 3) {
+ QDomText printerDescriptionNode(doc_.createTextNode(tokens.at(3)));
+ printerNode.appendChild(printerDescriptionNode);
+ }
+ printersNode.appendChild(printerNode);
+ }
+
+ addPrintersScript.close();
+
+ return;
+}
+
+void VSession::addScanners(const QString& script) {
+ addPrinters(script, "scanner");
+}
+
+void VSession::addUserAndHostname() {
+ QString username(getpwuid(geteuid())->pw_name);
+ this->addNodeWithAttribute("username", username);
+
+ // Qt >= 4.7 has <QHostInfo>
+ // QString hostname(QHostInfo::localHostName());
+ char hname[255];
+ gethostname(hname, sizeof(hname));
+ QString hostname(hname);
+ this->addNodeWithAttribute("hostname", hostname);
+
+ QString image(this->getAttribute("image_name"));
+ if (QFileInfo(image).isRelative()) {
+ // make path to image absolute
+ this->addNodeWithAttribute("image_name",
+ this->baseDirPath_ + "/" + image);
+ }
+
+ // insert computername as the first child of <eintrag>
+ // bootpgm needs computername within the first 500 bytes
+ QDomElement computername(doc_.createElement("computername"));
+ computername.setAttribute("param", hostname);
+ this->doc_.namedItem("eintrag").insertBefore(computername, QDomNode());
+}
+
+void VSession::mergePoolXml() {
+ QDomDocument doc;
+
+ QString poolXmlFile = sessionHandler->getConfPath() + "/vmchooser-" + sessionHandler->getEnv() + ".xml";
+
+ QFile file(poolXmlFile);
+ if (!file.open(QIODevice::ReadOnly)) {
+ return;
+ }
+ if (!doc.setContent(&file)) {
+ file.close();
+ return;
+ }
+ file.close();
+
+ for (QDomElement envNode(doc.firstChildElement("environment"));
+ !envNode.isNull();
+ envNode = envNode.nextSiblingElement()) {
+ if (envNode.attribute("param") != sessionHandler->getEnv()) continue;
+
+ for (QDomElement typeNode(envNode.firstChildElement());
+ !typeNode.isNull();
+ typeNode = typeNode.nextSiblingElement()) {
+ QString type = typeNode.nodeName();
+ if (type != "shared_folders" &&
+ type != "printers" &&
+ type != "scanners") continue;
+
+ QDomElement destinationNode =
+ this->doc_.namedItem("eintrag").namedItem(type).toElement();
+
+ if (destinationNode.isNull()) {
+ // create new node
+ destinationNode = this->doc_.createElement(type);
+ this->doc_.namedItem("eintrag").appendChild(destinationNode);
+ }
+
+ for (QDomElement el(typeNode.firstChildElement());
+ !el.isNull();
+ el = el.nextSiblingElement()) {
+ destinationNode.appendChild(this->doc_.importNode(el, true));
+ }
+ }
+ }
+}
+
+bool VSession::run() const {
+ QString command = getAttribute("command");
+ if (!command.isEmpty()) {
+ return QProcess::startDetached(command);
+ }
+
+ VSession session = *this;
+
+ session.addPrinters(sessionHandler->getPrinterScript());
+ session.addScanners(sessionHandler->getScannerScript());
+
+ session.addUserAndHostname();
+
+ session.mergePoolXml();
+
+ // write xml to temporary file
+ QTemporaryFile tmpfile(QDir::tempPath() + "/vmchooser-XXXXXX.xml");
+ if (!tmpfile.open() ||
+ tmpfile.write(session.toXml().toUtf8()) == -1) {
+ return false;
+ }
+ tmpfile.close();
+ tmpfile.setAutoRemove(false);
+
+ _process->start(sessionHandler->getRunVmScript(), QStringList(tmpfile.fileName()));
+ qDebug() << sessionHandler->getRunVmScript();
+ QObject::connect(_process, SIGNAL(finished(int, QProcess::ExitStatus)), QApplication::instance(), SLOT(quit()));
+ if (_process->state() == QProcess::Starting || QProcess::Running)
+ return true;
+ else
+ return false;
+}
+
+int VSession::type() const {
+ return Session::VSESSION;
+}
+
+bool VSession::operator<(const Session& other) const {
+ int p0 = this->priority();
+ int p1 = other.priority();
+
+ if (p0 < p1) return true;
+ if (p0 == p1) {
+ QString d0 = this->shortDescription();
+ QString d1 = other.shortDescription();
+ return d0.localeAwareCompare(d1) < 0;
+ }
+ return false;
+}
diff --git a/src/VSession.h b/src/VSession.h
new file mode 100644
index 0000000..8eb99cd
--- /dev/null
+++ b/src/VSession.h
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#ifndef VMCHOOSER_VSESSION_H_
+#define VMCHOOSER_VSESSION_H_
+
+#include <QString>
+#include <QList>
+#include <QDomDocument>
+#include <QDir>
+#include <QProcess>
+#include <QFSFileEngine>
+#include <QDateTime>
+
+#include "Session.h"
+#include "VSessionHandler.h"
+
+enum ImgType {
+ VMWARE,
+ VBOX,
+ OTHER
+};
+
+class VSession : public Session {
+ public:
+ VSession(VSessionHandler *parent);
+ bool init(const QString& xml, const QString& baseDirPath);
+
+ ImgType imgtype() const;
+ bool isActive() const;
+ bool isLocked() const;
+ bool isValid() const;
+ int priority() const;
+
+ QString shortDescription() const {
+ return getAttribute("short_description");
+ }
+
+ QString description() const {
+ QString ret;
+ ret = getNodeText("description_html");
+ if (ret.size() > 0) return ret;
+ return getAttribute("long_description");
+ }
+
+ QString icon() const;
+
+ QString os() const {
+ QString ret;
+ ret = getAttribute("operating_system");
+ if (ret.size() > 0) return ret;
+ return getAttribute("os");
+ }
+
+ QString title() const {
+ QString tmp = getAttribute("title");
+ if (tmp.size() > 0) return tmp;
+ return getAttribute("short_description");
+ };
+
+ QString screenshot() const;
+
+ QString emulator() const {
+ return getAttribute("emulator");
+ };
+
+ QString author() const {
+ QString tmp;
+ tmp = getAttribute("creator") + "&lt;" + getAttribute("email") + "&gt;";
+ return tmp;
+ };
+
+ QString creationDate () const {
+ if (QFile::exists(QString(this->baseDirPath_).append("/").append(getAttribute("image_name")))) {
+ QFSFileEngine fe(QString(this->baseDirPath_).append("/").append(getAttribute("image_name"))); //QAbstractFileEngine::ModificationTime
+ return fe.fileTime(QAbstractFileEngine::CreationTime).toString(Qt::SystemLocaleLongDate);
+ }
+ return QString();
+ };
+
+ QString changeDate() const {
+ if (QFile::exists(QString(this->baseDirPath_).append("/").append(getAttribute("image_name")))) {
+ QFSFileEngine fe(QString(this->baseDirPath_).append("/").append(getAttribute("image_name"))); //QAbstractFileEngine::ModificationTime
+ return fe.fileTime(QAbstractFileEngine::AccessTime).toString(Qt::SystemLocaleLongDate);
+ }
+ return QString();
+ };
+
+
+ QString getAttribute(const QString& nodeName,
+ const QString& attribute = "param") const;
+ QString getNodeText(const QString& nodeName) const;
+
+ void addNodeWithAttribute(const QString& nodeName,
+ const QString& value,
+ const QString& attribute = "param",
+ bool replace = true);
+ void addPrinters(const QString& script, const QString& type = "printer");
+ void addScanners(const QString& script);
+ void addUserAndHostname();
+ void mergePoolXml();
+
+ QString toXml() const;
+
+ bool run() const;
+
+ int type() const;
+
+ bool operator<(const Session& other) const;
+
+ static bool debugMode;
+
+
+
+ private:
+ QDomDocument doc_;
+ QString baseDirPath_;
+ VSessionHandler *sessionHandler;
+
+
+ QProcess *_process;
+};
+
+#endif /*VMCHOOSER_VSESSION_H_*/
diff --git a/src/VSessionHandler.cpp b/src/VSessionHandler.cpp
new file mode 100644
index 0000000..bda85d0
--- /dev/null
+++ b/src/VSessionHandler.cpp
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#include "VSessionHandler.h"
+
+#include <QList>
+#include <QString>
+#include <QFile>
+#include <QDir>
+#include <QDirIterator>
+#include <QProcess>
+#include <QDebug>
+#include <QDomDocument>
+
+#include "Defaults.h"
+#include "Session.h"
+#include "VSession.h"
+
+
+VSessionHandler::VSessionHandler() {
+ debugMode = true;
+ _filterScript = QString(LIBCHOOSER_BIN_PATH "/xmlfilter.sh");
+ _runVmScript = QString(LIBCHOOSER_BIN_PATH "/run-virt.sh");
+ _printerScript = QString(LIBCHOOSER_ETC_BASE_PATH "/printer.sh");
+ _scannerScript = QString(LIBCHOOSER_ETC_BASE_PATH "/scanner.sh");
+ _confPath = QString(LIBCHOOSER_ETC_BASE_PATH);
+ _env = QString();
+}
+
+VSessionHandler::~VSessionHandler() {
+ // TODO Auto-generated destructor stub
+}
+
+void VSessionHandler::setEnv(QString env) {
+ _env = env;
+}
+
+void VSessionHandler::setPrinterScript(QString printerScript) {
+ _printerScript = printerScript;
+}
+
+void VSessionHandler::setScannerScript(QString scannerScript) {
+ _scannerScript = scannerScript;
+}
+
+void VSessionHandler::setRunVmScript(QString runVmScript) {
+ _runVmScript = runVmScript;
+}
+
+void VSessionHandler::setConfPath(QString confPath) {
+ _confPath = confPath;
+}
+
+void VSessionHandler::setFilterScript(QString filterScript) {
+ _filterScript = filterScript;
+}
+
+QString VSessionHandler::getEnv() {
+ return _env;
+
+}
+QString VSessionHandler::getPrinterScript() {
+ return _printerScript;
+
+}
+QString VSessionHandler::getScannerScript() {
+ return _scannerScript;
+
+}
+QString VSessionHandler::getRunVmScript() {
+ return _runVmScript;
+
+}
+QString VSessionHandler::getConfPath() {
+ return _confPath;
+
+}
+QString VSessionHandler::getFilterScript() {
+ return _filterScript;
+}
+
+bool VSessionHandler::hasEnv() {
+ return (_env.size() != 0);
+}
+
+/**
+ * - calls xmlfilter.sh to glob a folder for xmls
+ * -> if no xmlfilter.sh is available, it globs for available xmls
+ * - reads all xml files and creates for each its own VSession-struct
+ */
+QList<Session*> VSessionHandler::readXmlDir(const QString& path) {
+ QList<Session*> retval;
+
+ if (QFile::exists(_filterScript)) {
+ // run filterScript
+ // treat every output line as a filename and read it
+ QProcess myFilterScript;
+ myFilterScript.start(_filterScript, QStringList(path),
+ QIODevice::ReadOnly);
+ myFilterScript.waitForFinished();
+ while (!myFilterScript.atEnd()) {
+ QString filename(myFilterScript.readLine());
+ filename = filename.trimmed();
+ if (QDir::isRelativePath(filename)) {
+ filename.prepend(path + "/");
+ }
+ retval.append(readXmlFile(filename));
+ }
+
+ myFilterScript.close();
+ } else {
+ // iterate over all .xml files in directory <path> (and sub-directories)
+ // and read them
+ QDirIterator di(path,
+ QDirIterator::Subdirectories |
+ QDirIterator::FollowSymlinks);
+ while (di.hasNext()) {
+ if (!di.next().endsWith(".xml")) continue;
+
+ if (!di.fileInfo().isReadable()) {
+ if (debugMode) qDebug() << "skip" << di.fileInfo().absoluteFilePath() << ": xml not readable, incorrect file permissions";
+ continue;
+ }
+
+ QList<Session*> vsessionTmp = readXmlFile(di.fileInfo().absoluteFilePath());
+
+ if (vsessionTmp.isEmpty()) {
+ if (debugMode) qDebug() << "skip" << di.fileInfo().absoluteFilePath() << ": reading xml failed for some reason";
+ continue;
+ }
+
+ if (!vsessionTmp.first()->isValid()) {
+ if (debugMode) qDebug() << "skip" << vsessionTmp.first()->shortDescription() << ": vdi/vmdk missing";
+ continue;
+ }
+
+ if (!vsessionTmp.first()->isActive()) {
+ if (debugMode) qDebug() << "skip" << vsessionTmp.first()->shortDescription() << ": not active";
+ continue;
+ }
+
+ retval.append(vsessionTmp);
+ }
+ }
+ return retval;
+}
+
+QList<Session*> VSessionHandler::readXmlFile(const QString& filepath) {
+ QList<Session*> retval;
+
+ QDomDocument doc;
+ QFile file(filepath);
+ if (!file.open(QIODevice::ReadOnly)) {
+ // TODO: error message
+ return retval;
+ }
+ if (!doc.setContent(&file)) {
+ // TODO: error message
+ file.close();
+ return retval;
+ }
+ file.close();
+
+ QString dirName(QFileInfo(filepath).dir().absolutePath());
+ QDomElement settingsNode = doc.firstChildElement("settings");
+ for (QDomElement el(settingsNode.firstChildElement("eintrag"));
+ !el.isNull();
+ el = el.nextSiblingElement("eintrag")) {
+ QDomDocument dummy;
+ dummy.appendChild(dummy.importNode(el, true));
+ VSession* e = new VSession(this);
+ if (e->init(dummy.toString(), dirName)) {
+ retval.append(e);
+ }
+ }
+ return retval;
+}
+
diff --git a/src/VSessionHandler.h b/src/VSessionHandler.h
new file mode 100644
index 0000000..c0806c8
--- /dev/null
+++ b/src/VSessionHandler.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+
+#ifndef VSESSIONHANDLER_H_
+#define VSESSIONHANDLER_H_
+
+#include <QList>
+#include <QString>
+
+class Session;
+
+class VSessionHandler {
+public:
+ VSessionHandler();
+ virtual ~VSessionHandler();
+
+ QList<Session*> readXmlDir(const QString& path);
+ QList<Session*> readXmlFile(const QString& filepath);
+
+
+ void setEnv(QString env);
+ void setPrinterScript(QString printerScript);
+ void setScannerScript(QString scannerScript);
+ void setRunVmScript(QString runVmScript);
+ void setConfPath(QString confPath);
+ void setFilterScript(QString filterScript);
+
+ QString getEnv() ;
+ QString getPrinterScript() ;
+ QString getScannerScript() ;
+ QString getRunVmScript() ;
+ QString getConfPath() ;
+ QString getFilterScript() ;
+
+ bool hasEnv();
+
+
+private:
+ QString _filterScript;
+ QString _env;
+ QString _confPath;
+ QString _printerScript;
+ QString _scannerScript;
+ QString _runVmScript;
+ bool debugMode;
+
+};
+
+#endif /* VSESSIONHANDLER_H_ */
diff --git a/src/XSession.cpp b/src/XSession.cpp
new file mode 100644
index 0000000..47db987
--- /dev/null
+++ b/src/XSession.cpp
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#include <QDir>
+#include <QSettings>
+#include <QLocale>
+#include <QApplication>
+#include <QProcess>
+
+#include "XSession.h"
+
+void XSession::init(const QString& name, const QString& exec,
+ const QString& comment, const QString& icon) {
+ this->name_ = name;
+ this->exec_ = exec;
+ this->comment_ = comment;
+ this->icon_ = icon;
+}
+
+bool XSession::init(const QString& filename) {
+ QSettings settings(filename, QSettings::IniFormat);
+ settings.setIniCodec("UTF-8");
+
+ settings.beginGroup("Desktop Entry");
+
+ if (settings.value("NoDisplay").toString().compare("true") == 0 ||
+ settings.value("Hidden").toString().compare("true") == 0) {
+ return false;
+ }
+
+ if (!settings.contains("Exec")) {
+ return false;
+ }
+ QString exec(settings.value("Exec").toString());
+
+ QString locale(QLocale::system().name());
+ QString language(locale.split("_").at(0));
+ QString name;
+ if (settings.contains("Name[" + locale + "]")) {
+ name = settings.value("Name[" + locale + "]").toString();
+ } else if (settings.contains("Name[" + language + "]")) {
+ name = settings.value("Name[" + language + "]").toString();
+ } else if (settings.contains("Name")) {
+ name = settings.value("Name").toString();
+ } else {
+ return false;
+ }
+
+ QString comment;
+ if (settings.contains("Comment[" + locale + "]")) {
+ comment = settings.value("Comment[" + locale + "]").toString();
+ } else if (settings.contains("Comment[" + language + "]")) {
+ comment = settings.value("Comment[" + language + "]").toString();
+ } else {
+ comment = settings.value("Comment").toString();
+ }
+
+ QString icon(settings.value("Icon").toString());
+ if (QDir::isRelativePath(icon)) {
+ // icons with relative paths are too complicated to find
+ // see http://freedesktop.org/wiki/Specifications/icon-theme-spec
+ // let's just ignore them
+ icon = QString();
+ }
+
+ this->name_ = name;
+ this->exec_ = exec;
+ this->comment_ = comment;
+ this->icon_ = icon;
+
+ _process = new QProcess();
+
+ return true;
+}
+
+bool XSession::isActive() const {
+ return true;
+}
+
+bool XSession::isValid() const {
+ return true;
+}
+
+bool XSession::isLocked() const {
+ return false;
+}
+
+int XSession::priority() const {
+ return 0;
+}
+
+QString XSession::icon() const {
+ QString icon(this->icon_);
+
+ if (icon.isEmpty()) {
+ if (this->exec_.contains("kde", Qt::CaseInsensitive)) {
+ icon = "kde";
+ } else if (this->exec_.contains("gnome", Qt::CaseInsensitive)) {
+ icon = "gnome";
+ } else if (this->exec_.contains("term", Qt::CaseInsensitive)) {
+ icon = "term";
+ } else if (this->exec_.contains("xfce", Qt::CaseInsensitive)) {
+ icon = "xfce";
+ } else if (this->exec_.contains("lxde", Qt::CaseInsensitive)) {
+ icon = "lxde";
+ } else {
+ icon = "linux";
+ }
+ }
+
+ return icon;
+}
+
+bool XSession::run() const {
+ _process->start(this->exec_);
+ QObject::connect(_process, SIGNAL(finished(int, QProcess::ExitStatus)), QApplication::instance(), SLOT(quit()));
+ if (_process->state() == QProcess::Starting || QProcess::Running)
+ return true;
+ else
+ return false;
+}
+
+int XSession::type() const {
+ return Session::XSESSION;
+}
+
+bool XSession::operator<(const Session& other) const {
+ int p0 = this->priority();
+ int p1 = other.priority();
+
+ if (p0 < p1) return true;
+ if (p0 == p1) {
+ QString d0 = this->shortDescription();
+ QString d1 = other.shortDescription();
+ return d0.localeAwareCompare(d1) < 0;
+ }
+ return false;
+}
diff --git a/src/XSession.h b/src/XSession.h
new file mode 100644
index 0000000..c1b83c9
--- /dev/null
+++ b/src/XSession.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#ifndef VMCHOOSER_XSESSION_H_
+#define VMCHOOSER_XSESSION_H_
+
+#include <QString>
+#include <QList>
+#include <QDomDocument>
+#include <QDir>
+#include <QProcess>
+
+#include "Session.h"
+
+class XSession : public Session {
+ public:
+ void init(const QString& name, const QString& exec,
+ const QString& comment, const QString& icon);
+ bool init(const QString& filename);
+
+ bool isActive() const;
+ bool isLocked() const;
+ bool isValid() const;
+ int priority() const;
+
+
+ QString title() const {
+ return this->name_;
+ };
+
+ QString screenshot() const {
+ return QString();
+ };
+
+ QString os() const {
+ return QString();
+ };
+
+ QString emulator() const {
+ return QString();
+ };
+
+ QString author() const {
+ return QString();
+ };
+
+ QString creationDate () const {
+ return QString();
+ };
+
+ QString changeDate() const {
+ return QString();
+ };
+
+
+ QString shortDescription() const {
+ return QString();
+ }
+
+ QString description() const {
+ return QString();
+ }
+
+ QString icon() const;
+
+ bool run() const;
+
+ int type() const;
+
+ bool operator<(const Session& other) const;
+
+ private:
+ QString name_;
+ QString exec_;
+ QString comment_;
+ QString icon_;
+
+ QProcess *_process;
+};
+
+#endif /*VMCHOOSER_XSESSION_H_*/
diff --git a/src/XSessionHandler.cpp b/src/XSessionHandler.cpp
new file mode 100644
index 0000000..4291a9a
--- /dev/null
+++ b/src/XSessionHandler.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+#include <QFile>
+#include <QList>
+#include <QFileInfo>
+
+
+#include "XSessionHandler.h"
+#include "XSession.h"
+#include "Session.h"
+
+XSessionHandler::XSessionHandler() {
+ // TODO Auto-generated constructor stub
+
+}
+
+XSessionHandler::~XSessionHandler() {
+ // TODO Auto-generated destructor stub
+}
+
+
+QList<Session*> XSessionHandler::readSessions(const QString& path) {
+ QList<Session*> retval;
+ foreach (QFileInfo fi, QDir(path).entryInfoList(QStringList("*.desktop"))) {
+ if (fi.baseName().compare("default") == 0) {
+ continue;
+ }
+ XSession* session = new XSession;
+ if (session->init(fi.absoluteFilePath())) {
+ retval.append(session);
+ }
+ }
+ return retval;
+}
diff --git a/src/XSessionHandler.h b/src/XSessionHandler.h
new file mode 100644
index 0000000..461bc4e
--- /dev/null
+++ b/src/XSessionHandler.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2010,2011 - RZ Uni Freiburg
+ * Copyright (c) 2010,2011 - OpenSLX Project
+ *
+ * This program/file is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your feedback to feedback@openslx.org
+ *
+ * General information about OpenSLX - libChooser can be found under
+ * http://openslx.org
+ *
+ */
+
+
+#ifndef XSESSIONHANDLER_H_
+#define XSESSIONHANDLER_H_
+
+class Session;
+
+class XSessionHandler {
+public:
+ XSessionHandler();
+ virtual ~XSessionHandler();
+ QList<Session*> readSessions(const QString& path);
+};
+
+#endif /* XSESSIONHANDLER_H_ */