From 28fe7b914a0e626cedc39218f94e11eda14a8b87 Mon Sep 17 00:00:00 2001 From: Bastian Wissler Date: Thu, 19 Feb 2009 12:03:16 +0000 Subject: 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 --- vmchooser/SWindow.cxx | 16 ++++++++++ vmchooser/inc/functions.h | 6 ++++ vmchooser/main.cxx | 4 +-- vmchooser/runImage.cxx | 1 + vmchooser/userSession.cxx | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 vmchooser/userSession.cxx 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 #include @@ -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 +#include +#include +#include +#include + +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; + } + +} -- cgit v1.2.3-55-g7522