summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBastian Wissler2009-02-19 13:03:16 +0100
committerBastian Wissler2009-02-19 13:03:16 +0100
commit28fe7b914a0e626cedc39218f94e11eda14a8b87 (patch)
tree6ab779784ddc2327cbe0fb2515307882e2efd27f
parentvmchooser binary: (diff)
downloadvmchooser-28fe7b914a0e626cedc39218f94e11eda14a8b87.tar.gz
vmchooser-28fe7b914a0e626cedc39218f94e11eda14a8b87.tar.xz
vmchooser-28fe7b914a0e626cedc39218f94e11eda14a8b87.zip
vmchooser source: * added feature to save last session and choose it again next time.
git-svn-id: http://svn.openslx.org/svn/openslx/openslx-src-tools/vmchooser/trunk@2619 95ad53e4-c205-0410-b2fa-d234c58c8868
-rw-r--r--vmchooser/SWindow.cxx16
-rw-r--r--vmchooser/inc/functions.h6
-rw-r--r--vmchooser/main.cxx4
-rw-r--r--vmchooser/runImage.cxx1
-rw-r--r--vmchooser/userSession.cxx74
5 files changed, 99 insertions, 2 deletions
diff --git a/vmchooser/SWindow.cxx b/vmchooser/SWindow.cxx
index e388d3f..a3ec373 100644
--- a/vmchooser/SWindow.cxx
+++ b/vmchooser/SWindow.cxx
@@ -1,6 +1,7 @@
#include "inc/SWindow.h"
+#include "inc/functions.h"
#include <iostream>
#include <map>
@@ -183,6 +184,8 @@ void SWindow::free_entries()
/******************************************************
* Small helper function to unfold the 2 parent groups
+ *
+ * ADDED: Now reads session from ~/.vmchooser via helper
******************************************************/
void SWindow::unfold_entries() {
sel.goto_index(0);
@@ -199,6 +202,19 @@ void SWindow::unfold_entries() {
//sel.set_focus();
//sel.set_item_selected(true,1);
//sel.indented(false);
+
+ char* prename = readSession();
+ sel.goto_index(0);
+ Item* it = (Item*) sel.next();
+
+ while( it ) {
+ if(! strcmp(prename,it->label()) ) {
+ sel.select_only_this(0);
+ curr = it;
+ return;
+ }
+ it = (Item*) sel.next();
+ }
}
diff --git a/vmchooser/inc/functions.h b/vmchooser/inc/functions.h
index b4a1bbc..afccc9b 100644
--- a/vmchooser/inc/functions.h
+++ b/vmchooser/inc/functions.h
@@ -33,5 +33,11 @@ void addInfo(xmlNode* node); /* This is defined in addPrinters.cxx */
string writeConfXml(DataEntry& dat);
+
+/** Extra functions - defined in userSession.cxx */
+void saveSession(DataEntry* dat);
+char* readSession(void);
+
+
#endif /* _FUNCTIONS_H_ */
diff --git a/vmchooser/main.cxx b/vmchooser/main.cxx
index 3b82ef3..4f91117 100644
--- a/vmchooser/main.cxx
+++ b/vmchooser/main.cxx
@@ -17,7 +17,7 @@ SWindow* mainwin;
*
* ----------------------
*
- * main procedure of vmchooser
+ * main function of vmchooser
*
*
*
@@ -112,7 +112,7 @@ int main(int argc, char** argv) {
delete opt;
// just print out version information - helps testing
- cout << "virtual machine chooser 0.0.6"<< endl;
+ cout << "virtual machine chooser 0.0.7"<< endl;
if(version) {
exit(1);
}
diff --git a/vmchooser/runImage.cxx b/vmchooser/runImage.cxx
index ff9f340..4b7c3e5 100644
--- a/vmchooser/runImage.cxx
+++ b/vmchooser/runImage.cxx
@@ -73,6 +73,7 @@ void runImage(fltk::Widget*, void* p)
// fltk::alert("Failed to create child thread!");
// return;
//}
+ saveSession((DataEntry*)p);
runImage(dat, confxml);
break;
}
diff --git a/vmchooser/userSession.cxx b/vmchooser/userSession.cxx
new file mode 100644
index 0000000..af11d4b
--- /dev/null
+++ b/vmchooser/userSession.cxx
@@ -0,0 +1,74 @@
+
+
+
+#include "inc/DataEntry.h"
+#include "inc/functions.h"
+
+#include <cstdlib>
+#include <cstring>
+#include <string>
+#include <iostream>
+#include <fstream>
+
+using namespace std;
+
+/**
+ * @function saveSession: Saves chosen session to prechoose this session next time.
+ *
+ * @param dat: Pointer to the wanted Image/Linux Session
+ * @return void
+ *
+ */
+void saveSession(DataEntry* dat) {
+
+ // get home folder
+ char* home = getenv("HOME");
+ if(home == NULL) {
+ cout << "HOME is not set. Not storing session." << endl;
+ return;
+ }
+
+ // build path
+ string fname = home;
+ fname.append("/.vmchooser");
+
+ // write file with ofstream
+ ofstream fout(fname.c_str(),ios::trunc); // overwrite file
+ fout << dat->short_description << endl;
+}
+
+
+
+/**
+ * @function readSession: Read predefined session from users home folder
+ *
+ * @return: if not found, return null, else filename for Image XML/ Linux .desktop file
+ */
+char* readSession() {
+
+ // read HOME variable
+ char* home = getenv("HOME");
+ if(home==NULL) {
+ cout << "HOME is not set. Not reading session." << endl;
+ return NULL;
+ }
+
+ // build file name
+ string fname = home;
+ fname.append("/.vmchooser");
+
+ // read presaved session with ifstream
+ ifstream fin(fname.c_str());
+ string sessname;
+ getline(fin,sessname);
+ char* blub = (char*) malloc(sessname.size());
+ strncpy(blub,sessname.c_str(),sessname.size()+1);
+
+ if(!sessname.empty()) {
+ return blub;
+ }
+ else {
+ return NULL;
+ }
+
+}