summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--vmchooser/Makefile31
-rw-r--r--vmchooser/SWindow.cxx19
-rw-r--r--vmchooser/addPrinters.cxx130
-rw-r--r--vmchooser/addScanners.cxx130
-rw-r--r--vmchooser/inc/DataEntry.h3
-rw-r--r--vmchooser/inc/SWindow.h32
-rw-r--r--vmchooser/inc/functions.h24
-rw-r--r--vmchooser/main.cxx188
-rw-r--r--vmchooser/readXmlDir.cxx17
-rw-r--r--vmchooser/runImage.cxx103
-rw-r--r--vmchooser/vmchooser.kdevelop4
12 files changed, 529 insertions, 154 deletions
diff --git a/README b/README
index faef5a1..3e280a8 100644
--- a/README
+++ b/README
@@ -29,3 +29,5 @@ Needed libraries to run:
* Some static libraries of fltk-2 - svn version - are located
in fltk-2/ and could be used to link against this program.
- as images are enabled, you should have libjpeg and libpng too.
+===================================
+
diff --git a/vmchooser/Makefile b/vmchooser/Makefile
index 81cdfa9..ea75cfd 100644
--- a/vmchooser/Makefile
+++ b/vmchooser/Makefile
@@ -1,33 +1,40 @@
STATIC=# -static
CXX=g++
-CFLAGS=-c -O2 -I../fltk-2/include/ -I. -Wall -g3
-XMLFLAG=`xml2-config --cflags`
+CFLAGS=-c -O2 -I../fltk-2/include/ -I. -Wall -g3 `xml2-config --cflags`
BOOST=-lboost_regex-s
LDFLAGS=-L../fltk-2/lib/ ../fltk-2/lib/libfltk2.a -lpng ../fltk-2/lib/libfltk2_images.a -ljpeg -lz -lXi -lXinerama -lpthread -lm -lXext -lsupc++ -lXrender -lfontconfig -lxml2 -lXft -lXdmcp -lXau -ldl -lz -lfreetype -lX11
-all: main SWindow readXmlDir readLinSess runImage
- ${CXX} ${STATIC} main.o SWindow.o runImage.o readLinSess.o readXmlDir.o -o vmchooser ${LDFLAGS} ${BOOST}
+all: main.o anyoption.o SWindow.o readXmlDir.o readLinSess.o runImage.o addPrinters.o addScanners.o
+ ${CXX} ${STATIC} main.o anyoption.o SWindow.o runImage.o readLinSess.o readXmlDir.o addPrinters.o addScanners.o -o vmchooser ${LDFLAGS} ${BOOST}
strip vmchooser
+
+main.o: main.cxx
+ ${CXX} ${CFLAGS} -c main.cxx -o main.o
+
+anyoption.o: anyoption.cpp inc/anyoption.h
+ ${CXX} ${CFLAGS} -o anyoption.o anyoption.cpp
-SWindow:
+SWindow.o: SWindow.cxx inc/SWindow.h
${CXX} ${CFLAGS} -c SWindow.cxx -o SWindow.o
-readXmlDir:
- ${CXX} ${CFLAGS} ${XMLFLAG} -o readXmlDir.o readXmlDir.cxx
+readXmlDir.o: readXmlDir.cxx inc/functions.h
+ ${CXX} ${CFLAGS} -o readXmlDir.o readXmlDir.cxx
-readLinSess:
+readLinSess.o: readLinSess.cxx inc/functions.h
${CXX} ${CFLAGS} -o readLinSess.o readLinSess.cxx
-runImage:
+runImage.o: runImage.cxx inc/functions.h
${CXX} ${CFLAGS} -o runImage.o runImage.cxx
-main:
- ${CXX} ${CFLAGS} -c main.cxx -o main.o
+addPrinters.o: addPrinters.cxx inc/functions.h
+ ${CXX} ${CFLAGS} -o addPrinters.o addPrinters.cxx
+addScanners.o: addScanners.cxx inc/functions.h
+ ${CXX} ${CFLAGS} -o addScanners.o addScanners.cxx
clean:
- rm -rf *.o test
+ rm -rf *.o vmchooser
install:
cp vmchooser ../../../../../../openslx/trunk/os-plugins/plugins/vmchooser/files/
diff --git a/vmchooser/SWindow.cxx b/vmchooser/SWindow.cxx
index c7a8a9a..47da162 100644
--- a/vmchooser/SWindow.cxx
+++ b/vmchooser/SWindow.cxx
@@ -16,11 +16,10 @@ using namespace std;
/********************************************************
* Callback for ReturnButton at the bottom of the GUI
* ----------------------------------------------------
- * Should start chosen session entry
+ * Should start chosen session entry -> if something is selected
*********************************************************/
void SWindow::cb_return()
{
- //cout << " Pressed Button!" << endl;
if(curr != 0 && curr->user_data()) {
DataEntry* dat = (DataEntry*) curr->user_data();
runImage(curr, dat);
@@ -42,17 +41,17 @@ void SWindow::cb_select()
}
if( curr == sel.item() ) {
//Doubleclick
+ cout << ((DataEntry*)curr->user_data())->short_description << endl;
if(curr->user_data()) {
runImage(curr, (DataEntry*) curr->user_data() );
}
return;
}
curr = (Item*) sel.item();
- //cout << it->user_data() << endl;
- if(curr->user_data()) {
- DataEntry* dat = (DataEntry*) curr->user_data();
- info.text(dat->description.c_str());
- }
+// if(curr->user_data()) {
+// DataEntry* dat = (DataEntry*) curr->user_data();
+// info.text(dat->description.c_str());
+// }
}
/**
@@ -76,8 +75,8 @@ void SWindow::set_lin_entries(DataEntry** ent, char* slxgroup)
if( ent[i]->pools.empty() || ent[i]->pools.find(slxgroup) != string::npos) {
Item* w= (Item*)sel.add_leaf(ent[i]->short_description.c_str() , lin_entgroup, (void*)ent[i] );
- // Why is just "new" working here ???
((Widget*) w)->image(new xpmImage(get_symbol(ent[i])));
+ w->tooltip(ent[i]->description.c_str());
w->callback(&runImage, (void*)ent[i]);
}
}
@@ -99,8 +98,8 @@ void SWindow::set_entries(DataEntry** ent, char* slxgroup)
if(ent[i]->pools.empty() || ent[i]->pools.find(slxgroup) != string::npos) {
Item* w= (Item*)sel.add_leaf(ent[i]->short_description.c_str(), entgroup, (void*)ent[i] );
- // Why is just "new" working here ??
((Widget*) w)->image(new xpmImage(get_symbol(ent[i])));
+ w->tooltip(ent[i]->description.c_str());
w->callback(&runImage, (void*)ent[i]);
}
}
@@ -159,5 +158,5 @@ char** SWindow::get_symbol(DataEntry* dat) {
}
return linux_xpm;
}
- return linux_xpm;
+ return xp_xpm;
}
diff --git a/vmchooser/addPrinters.cxx b/vmchooser/addPrinters.cxx
new file mode 100644
index 0000000..5e6ab35
--- /dev/null
+++ b/vmchooser/addPrinters.cxx
@@ -0,0 +1,130 @@
+
+
+#include "inc/functions.h"
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <queue>
+
+/**
+ * function addPrinters(xmlNode* node, char* script)
+ * ----------------------------------------------------------
+ * runs content of script (absolute path of a script-file)
+ * -> this expects the script to print out printer information
+ * in the following format
+ *
+ * printserver\tprinter\tprinter description
+ *
+ * all other output has to be directed to /dev/null
+ *
+ * then this function add some printer-nodes to the xml-file
+ * in "settings/eintrag/printers"
+ * (which will be created also if needed.)
+ * in the following form: <br/>
+ *
+ * &lt;printer name=&quot;printer&quot; path=&quot;//printserver/printer&quot; &gt;
+ * Printerdescription
+ * &lt;/printer&gt;
+ */
+bool addPrinters(xmlNode* node, char* script) {
+
+ if(node == NULL) {
+ return false;
+ }
+
+ bool printer = false;
+ vector<string> info_printer;
+
+ const int MAX_LENGTH = 300;
+ char line[MAX_LENGTH];
+ char delims[] = "\t";
+ string strline;
+ FILE* inp = 0;
+
+ unsigned int tindex = 0;
+ xmlNodePtr cur = node->children;
+ xmlNodePtr printernode = NULL;
+
+ // Get <printers> node
+ while(cur != NULL) {
+ if (!xmlStrcmp(cur->name, (const xmlChar *)"printers")){
+ printer = true;
+ printernode = cur;
+ break;
+ }
+ cur = cur->next;
+ }
+ if(! printer) {
+ printernode = xmlNewNode(NULL, (const xmlChar*) "printers");
+ if(printernode != NULL ) {
+ xmlAddChild(node, printernode);
+ }
+ else {
+ cerr << "No <printers> node created" << endl;
+ }
+ }
+
+ // Parse input of printer-Skript (called by "char* script")
+ // and write into <printer> nodes
+ if( (inp = popen(script, "r" )) ) {
+ while(fgets(line, MAX_LENGTH, inp ) != NULL) {
+ strline = string(line);
+ if(strline.length() > 3) {
+
+ queue<unsigned int> temp;
+ temp.push( strline.find_first_of( delims , 0) );
+
+ while( temp.back() != string::npos ) {
+ temp.push( strline.find_first_of( delims, temp.back()+1 ) );
+ }
+
+ unsigned int t_front;
+ string tstr = string("");
+ while( tindex != string::npos ) {
+
+ // build printer-info element
+ t_front = temp.front();
+
+ if(tindex == 0) {
+ tstr = strline.substr(0, t_front);
+ }
+ else if(t_front != string::npos) {
+ tstr = strline.substr(tindex+1, t_front-tindex-1) ;
+ }
+ else {
+ tstr = strline.substr( tindex+1, strline.length() - tindex-2 );
+ }
+ if(tstr.length() > 2) {
+ info_printer.push_back( tstr );
+ // DEBUG
+ cout << info_printer.back() << endl;
+ }
+ tindex = t_front;
+ temp.pop();
+ }
+
+ // Construct <printer> nodes
+ xmlNodePtr pNode = xmlNewNode(NULL, (const xmlChar*) "printer");
+ xmlNewProp(pNode, (const xmlChar*) "name", (const xmlChar*) info_printer.at(1).c_str());
+ xmlNewProp ( pNode, (const xmlChar*) "path", (const xmlChar*)
+ string( string( "//" ) + info_printer.at(0) + string( "/" ) + info_printer.at(1) ).c_str() );
+
+ if(info_printer.size() > 2) {
+ xmlAddChild( pNode, xmlNewText( (const xmlChar*) info_printer.at(2).c_str() ) );
+ }
+
+ if(pNode != NULL) {
+ xmlAddChild( printernode, pNode);
+ }
+
+ info_printer.clear();
+ tindex = 0;
+ }
+ }
+ return true;
+ }
+ fprintf(stderr, "Couldn't run \"%s\" script!", script);
+ return false;
+}
+
diff --git a/vmchooser/addScanners.cxx b/vmchooser/addScanners.cxx
new file mode 100644
index 0000000..526e645
--- /dev/null
+++ b/vmchooser/addScanners.cxx
@@ -0,0 +1,130 @@
+
+
+#include "inc/functions.h"
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <queue>
+
+/**
+ * function addScanners(xmlNode* node, char* script)
+ * ----------------------------------------------------------
+ * runs content of script (absolute path of a script-file)
+ * -> this expects the script to print out scanner information
+ * in the following format
+ *
+ * scanserver\tscanner\tscanner description
+ *
+ * all other output has to be directed to /dev/null
+ *
+ * then this function add some scanner-nodes to the xml-file
+ * in "settings/eintrag/scanners"
+ * (which will be created also if needed.)
+ * in the following form: <br/>
+ *
+ * &lt;scanner name=&quot;scanner&quot; path=&quot;//scanserver/scanner&quot; &gt;
+ * Scannerdescription
+ * &lt;/scanner&gt;
+ */
+bool addScanners(xmlNode* node, char* script) {
+
+ if(node == NULL) {
+ return false;
+ }
+
+ bool scanner = false;
+ vector<string> info_scanner;
+
+ const int MAX_LENGTH = 300;
+ char line[MAX_LENGTH];
+ char delims[] = "\t";
+ string strline;
+ FILE* inp = 0;
+
+ unsigned int tindex = 0;
+ xmlNodePtr cur = node->children;
+ xmlNodePtr scannernode = NULL;
+
+ // Get <scanners> node
+ while(cur != NULL) {
+ if (!xmlStrcmp(cur->name, (const xmlChar *)"scanners")){
+ scanner = true;
+ scannernode = cur;
+ break;
+ }
+ cur = cur->next;
+ }
+ if(! scanner) {
+ scannernode = xmlNewNode(NULL, (const xmlChar*) "scanners");
+ if(scannernode != NULL ) {
+ xmlAddChild(node, scannernode);
+ }
+ else {
+ cerr << "No <scanners> node created" << endl;
+ }
+ }
+
+ // Parse input of scanner-Skript (called by "char* script")
+ // and write into <scanner> nodes
+ if( (inp = popen(script, "r" )) ) {
+ while(fgets(line, MAX_LENGTH, inp ) != NULL) {
+ strline = string(line);
+ if(strline.length() > 3) {
+
+ queue<unsigned int> temp;
+ temp.push( strline.find_first_of( delims , 0) );
+
+ while( temp.back() != string::npos ) {
+ temp.push( strline.find_first_of( delims, temp.back()+1 ) );
+ }
+
+ unsigned int t_front;
+ string tstr = string("");
+ while( tindex != string::npos ) {
+
+ // build scanner-info element
+ t_front = temp.front();
+
+ if(tindex == 0) {
+ tstr = strline.substr(0, t_front);
+ }
+ else if(t_front != string::npos) {
+ tstr = strline.substr(tindex+1, t_front-tindex-1) ;
+ }
+ else {
+ tstr = strline.substr( tindex+1, strline.length() - tindex-2 );
+ }
+ if(tstr.length() > 2) {
+ info_scanner.push_back( tstr );
+ // DEBUG
+ cout << info_scanner.back() << endl;
+ }
+ tindex = t_front;
+ temp.pop();
+ }
+
+ // Construct <scanner> nodes
+ xmlNodePtr pNode = xmlNewNode(NULL, (const xmlChar*) "scanner");
+ xmlNewProp(pNode, (const xmlChar*) "name", (const xmlChar*) info_scanner.at(1).c_str());
+ xmlNewProp ( pNode, (const xmlChar*) "path", (const xmlChar*)
+ string( string( "//" ) + info_scanner.at(0) + string( "/" ) + info_scanner.at(1) ).c_str() );
+
+ if(info_scanner.size() > 2) {
+ xmlAddChild( pNode, xmlNewText( (const xmlChar*) info_scanner.at(2).c_str() ) );
+ }
+
+ if(pNode != NULL) {
+ xmlAddChild( scannernode, pNode);
+ }
+
+ info_scanner.clear();
+ tindex = 0;
+ }
+ }
+ return true;
+ }
+ fprintf(stderr, "Couldn't run \"%s\" script!", script);
+ return false;
+}
+
diff --git a/vmchooser/inc/DataEntry.h b/vmchooser/inc/DataEntry.h
index 82b3149..2f59615 100644
--- a/vmchooser/inc/DataEntry.h
+++ b/vmchooser/inc/DataEntry.h
@@ -2,6 +2,7 @@
#define DATAENTRY_H_
#include <string>
+#include <libxml/tree.h>
using namespace std;
enum ImgType {
@@ -32,6 +33,8 @@ struct DataEntry {
int priority;
string command;
+ string xml_name;
+ xmlDoc* xml;
};
diff --git a/vmchooser/inc/SWindow.h b/vmchooser/inc/SWindow.h
index e1994ec..777b04b 100644
--- a/vmchooser/inc/SWindow.h
+++ b/vmchooser/inc/SWindow.h
@@ -5,7 +5,7 @@
#include <fltk/Window.h>
#include <fltk/ReturnButton.h>
#include <fltk/Browser.h>
-#include <fltk/TextDisplay.h>
+//#include <fltk/TextDisplay.h>
#include <fltk/ItemGroup.h>
#include <fltk/Item.h>
#include <fltk/SharedImage.h>
@@ -29,9 +29,9 @@ private:
fltk::Browser sel;
// TextDisplay to display info about current session
- fltk::TextDisplay info;
+// fltk::TextDisplay info;
// TextBuffer buf is used for info
- fltk::TextBuffer buf;
+// fltk::TextBuffer buf;
// currently selected Browser-Item
fltk::Item* curr;
@@ -51,11 +51,11 @@ private:
* ctor with some reasonable default values
*/
SWindow(char* p = "Choose your session!") :
- fltk::Window(fltk::USEDEFAULT,fltk::USEDEFAULT,500,650,p, true),
- go(10,630, 490, 20, "Ausführen"),
- sel(10,10, 480, 500),
- info(10, 510, 480, 110),
- buf()
+ fltk::Window(fltk::USEDEFAULT,fltk::USEDEFAULT,500,550,p, true),
+ go(10,520, 490, 20, "Ausführen"),
+ sel(10,10, 480, 500) //,
+// info(10, 510, 480, 110),
+// buf()
{
border(false);
go.callback(cb_return,this);
@@ -66,25 +66,13 @@ private:
// (one Column for a lock-symbol)
int widths[] = { 450, 20 };
sel.column_widths(widths);
- info.callback(cb_info, this);
+// info.callback(cb_info, this);
resizable(sel);
end();
- info.wrap_mode(true, 0);
+// info.wrap_mode(true, 0);
//sel.style(fltk::Browser::default_style);
sel.indented(1);
-
- /* Getting foldername of the pictures - obsolete ? */
-// pathsize = 200;
-
- /* Var for the folder name */
-// pname = (char*) malloc(pathsize);
-// int result;
-//
-// result = readlink("/proc/self/exe", pname, pathsize);
-// if (result > 0) {
-// pname[result] = 0; /* add the NULL - not from readlink */
-// }
};
public:
diff --git a/vmchooser/inc/functions.h b/vmchooser/inc/functions.h
index c8dcc86..aa9104e 100644
--- a/vmchooser/inc/functions.h
+++ b/vmchooser/inc/functions.h
@@ -7,13 +7,29 @@
#include "DataEntry.h"
-DataEntry** readXmlDir(char* path); /* Attention: returns malloced array */
+/* Attention: both return malloced array */
+DataEntry** readXmlDir(char* path);
DataEntry** readLinSess(char* path);
-void runImage(fltk::Widget* , void* p); /* This is thought as a callback-function for the Select-Browser */
-string runImage(DataEntry&); /* building command for different Virtualizer */
+/* This is thought as a callback-function for the Select-Browser */
+void runImage(fltk::Widget* , void* p);
-glob_t* globber(char* path, char* filetype); /* Globs for a specific filetype */
+/* building & executing command for different Virtualizer */
+string runImage(DataEntry&, char* confxml);
+
+/* Globs for a specific filetype (2. argument) */
+glob_t* globber(char* path, char* filetype);
+
+/* Gets folder name of this program */
+char* getFolderName();
+
+/* Reads output from a skript (2. argument) */
+/* Adds the elements into xmlNode "printers" (1. argument) */
+bool addPrinters(xmlNode* node, char* script);
+bool addScanners(xmlNode* node, char* script);
+
+/* Write configuration xml */
+const char* writeConfXml(DataEntry& dat);
#endif /* _FUNCTIONS_H_ */
diff --git a/vmchooser/main.cxx b/vmchooser/main.cxx
index 531dfc9..84e4a60 100644
--- a/vmchooser/main.cxx
+++ b/vmchooser/main.cxx
@@ -6,6 +6,7 @@
#include "inc/SWindow.h"
#include "inc/DataEntry.h"
#include "inc/functions.h"
+#include "inc/anyoption.h"
using namespace std;
using namespace fltk;
@@ -21,98 +22,103 @@ using namespace fltk;
*
*
*/
-int main(int argc, char** argv)
-{
+int main(int argc, char** argv) {
+ AnyOption* opt = new AnyOption();
+ char* xmlpath = NULL;
+ char* slxgroup = NULL;
+ char* lsesspath = NULL;
+
+ opt->setVerbose();
+ opt->autoUsagePrint(true);
+
+ opt->addUsage("");
+ opt->addUsage("SessionChooser Usage:");
+ opt->addUsage("\t{-p |--path=} path to vmware (.xml) files");
+ opt->addUsage("\t{-l |--lpath=} path to linux session (.desktop) files");
+ opt->addUsage("\t{-g |--group=} group name");
+ opt->addUsage("\t{-h |--help} prints help");
+ opt->addUsage("");
+
+ opt->setFlag("help",'h');
+ opt->setOption("path", 'p');
+ opt->setOption("lpath", 'l');
+ opt->setOption("group",'g');
+
+ opt->processCommandArgs(argc, argv);
+
+ /** HELP */
+ if(opt->getFlag("help") || opt->getFlag('h')) {
+ opt->printUsage();
+ return 1;
+ }
+
+ /** XML - PATH */
+ if(opt->getValue('p')!=NULL) {
+ xmlpath = opt->getValue('p');
+ }
+ if(opt->getValue("path")!= NULL) {
+ xmlpath = opt->getValue("path");
+ }
+ if (xmlpath == NULL) {
+ //xmlpath="../../../../../../../session-choosers/xml/";
+ xmlpath = "/var/lib/vmware/";
+ }
+
+ /** SLX GROUP */
+ if(opt->getValue('g')!=NULL) {
+ xmlpath = opt->getValue('g');
+ }
+ if(opt->getValue("group")!= NULL) {
+ xmlpath = opt->getValue("group");
+ }
+ if (slxgroup == NULL) {
+ slxgroup = "default";
+ }
+
+ /** LINUX SESSION PATH */
+ if(opt->getValue('l')!=NULL) {
+ lsesspath = opt->getValue('l');
+ }
+ if(opt->getValue("lpath")!= NULL) {
+ lsesspath = opt->getValue("lpath");
+ }
+ if (lsesspath == NULL) {
+ lsesspath = "/usr/share/xsessions/";
+ }
+
+ delete opt;
+
+ /* read xml files */
+ DataEntry** sessions = NULL;
+ DataEntry** lsessions = NULL;
+ if (xmlpath != NULL) {
+ sessions = readXmlDir(xmlpath);
+ } else {
+ fprintf(stderr,"Please give a path to xml directory for session images!");
+ exit(1);
+ }
+ lsessions = readLinSess(lsesspath);
+
+ SWindow& win = *SWindow::getInstance();
+
+ if(lsessions != NULL) {
+ win.set_lin_entries(lsessions, slxgroup);
+ }
+ if (sessions != NULL) {
+ win.set_entries(sessions, slxgroup);
+ }
+
+ //cout << win.pname << endl;
- if (argc > 1 && !(strcmp(argv[1],"-h") | strcmp(argv[1], "--help")) ) {
- /* print help */
- printf("SessionChooser \n");
- printf("\t{-p |--path=}[path to vmware (.xml) files]\n");
- printf("\t{-l |--lpath=}[path to linux session (.desktop) files]\n");
- printf("\t{-g |--group=}[group name]\n");
- printf("\t{-h |--help}[ as first parameter - prints help ]\n");
- exit(0);
- }
+
+ win.unfold_entries();
+ win.show(argc,argv);
+ win.border(false);
- char* xmlpath = NULL;
- char* slxgroup = NULL;
- char* lsesspath = NULL;
-
- for (int i=0; i<argc; i++) {
- /* Get path parameter - path to XML files */
- if (strstr(argv[i],"-p") != NULL) {
- i++;
- xmlpath = argv[i];
- }
- if (strstr(argv[i],"--path=") != NULL) {
- char* temp = strpbrk("=", argv[i] );
- xmlpath = (temp ++);
- }
-
- /* Get path for linux sessions */
- if (strstr(argv[i],"-l") != NULL) {
- i++;
- lsesspath = argv[i];
- }
- if (strstr(argv[i],"--lpath=") != NULL) {
- char* temp = strpbrk("=", argv[i] );
- lsesspath = (temp ++);
- }
-
- /* Get group parameter - SLXGroup */
- if (strstr(argv[i],"-g") != NULL) {
- i++;
- slxgroup = argv[i];
- }
- if (strstr(argv[i],"--group=") != NULL) {
- char* temp = strpbrk("=", argv[i] );
- slxgroup =( temp ++ );
- }
- }
-
- if (xmlpath == NULL) {
- xmlpath="../../../../../../../session-choosers/xml/";
- //xmlpath = "/var/lib/vmware/";
- }
- if (slxgroup == NULL) {
- slxgroup = "default";
- }
- if (lsesspath == NULL) {
- lsesspath = "/usr/share/xsessions/";
- }
-
-
- /* read xml files */
- DataEntry** sessions = NULL;
- DataEntry** lsessions = NULL;
- if (xmlpath != NULL) {
- sessions = readXmlDir(xmlpath);
- } else {
- fprintf(stderr,"Please give a path to xml directory for session images!");
- exit(1);
- }
- lsessions = readLinSess(lsesspath);
-
- SWindow& win = *SWindow::getInstance();
-
- if(lsessions != NULL) {
- win.set_lin_entries(lsessions, slxgroup);
- }
- if (sessions != NULL) {
- win.set_entries(sessions, slxgroup);
- }
-
- //cout << win.pname << endl;
-
-
- win.unfold_entries();
- win.show(argc,argv);
- win.border(false);
-
- bool retval = run();
-
- win.free_entries();
-
- return retval;
+ bool retval = run();
+
+ win.free_entries();
+
+ return retval;
}
diff --git a/vmchooser/readXmlDir.cxx b/vmchooser/readXmlDir.cxx
index 261f8ab..385d02b 100644
--- a/vmchooser/readXmlDir.cxx
+++ b/vmchooser/readXmlDir.cxx
@@ -90,6 +90,10 @@ DataEntry* get_entry(xmlDoc * doc)
{
char *tempc = NULL;
DataEntry* de = new DataEntry();
+
+ if(doc->name != NULL) {
+ de->xml_name = string(doc->name);
+ }
tempc = getAttribute(doc,"short_description");
if (tempc != NULL ) {
@@ -157,7 +161,7 @@ DataEntry* get_entry(xmlDoc * doc)
tempc = getAttribute(doc,"virtualmachine");
if (tempc != NULL ) {
- if ( strcmp(tempc,"vmware") ) {
+ if ( strcmp(tempc,"vmware") == 0 ) {
de->imgtype = VMWARE;
} else {
de->imgtype = VBOX;
@@ -204,6 +208,8 @@ DataEntry* get_entry(xmlDoc * doc)
de->priority = atoi(tempc);
}
tempc = NULL;
+
+ de->xml = doc;
return de;
}
@@ -253,9 +259,9 @@ DataEntry** readXmlDir(char* path)
DataEntry** result = (DataEntry**) malloc(gResult->gl_pathc * sizeof(DataEntry*) +1);
for (int i=0; gResult->gl_pathv[i] != NULL; i++) {
- if (strstr(gResult->gl_pathv[i], "Vorlage") != NULL) {
- continue;
- }
+// if (strstr(gResult->gl_pathv[i], "Vorlage") != NULL) {
+// continue;
+// }
/* DEBUG */
/* printf("%s\n", gResult->gl_pathv[i]);
*/
@@ -281,7 +287,8 @@ DataEntry** readXmlDir(char* path)
if (result[c] != NULL) {
c++;
}
- xmlFreeDoc(doc);
+ /* xmlDoc still needed to write back information for VMware etc. */
+ // xmlFreeDoc(doc);
}
free(gResult);
diff --git a/vmchooser/runImage.cxx b/vmchooser/runImage.cxx
index 477bfd3..c9ae261 100644
--- a/vmchooser/runImage.cxx
+++ b/vmchooser/runImage.cxx
@@ -2,16 +2,22 @@
#include "inc/DataEntry.h"
#include "inc/SWindow.h"
+#include "inc/functions.h"
+
#include <sys/wait.h>
#include <iostream>
#include <string>
#include <boost/regex.hpp>
+
/** *************************************************************
* void runImage runs a (virtual machine) image using fork()
+ * calling runImage(DataEntry*)
***************************************************************/
void runImage(fltk::Widget*, void* p)
{
+ char* confxml = 0;
+
/* printf("runImage called\n"); */
if ( p == NULL ) {
return;
@@ -19,6 +25,10 @@ void runImage(fltk::Widget*, void* p)
DataEntry& dat = *((DataEntry*) p);
+ if(dat.imgtype == VMWARE) {
+ confxml = (char*) writeConfXml(dat);
+ }
+
pid_t pid;
int status;
pid = fork();
@@ -29,7 +39,7 @@ void runImage(fltk::Widget*, void* p)
return;
break;
case 0:
- runImage(dat);
+ runImage(dat, confxml);
break;
default:
exit(0);
@@ -48,17 +58,94 @@ void runImage(fltk::Widget*, void* p)
* Helper-function for runImage(Widget, void)
* - runs the chosen virtualizer image
**/
-string runImage(DataEntry& dat)
+string runImage(DataEntry& dat, char* confxml)
{
if (dat.imgtype == VMWARE) {
- char* arg[] = { strcat("/var/lib/vmware/",dat.imgname.c_str()),
- (char*) dat.os.c_str(),
- (char*)dat.network.c_str(), '\0' };
- // run-vmware.sh imagename os (Window-Title) network
- execvp("/var/X11R6/bin/run-vmware.sh", arg );
+ //cout << dat.xml_name << endl;
+ char* arg[] = { "/var/X11R6/bin/run-vmware.sh",
+ confxml,
+ strcat("/var/lib/vmware/",dat.imgname.c_str()),
+ (char*) dat.os.c_str(),
+ (char*)dat.network.c_str(),
+ '\0' };
+ // run-vmware.sh imagename os (Window-Title) network
+ execvp("/var/X11R6/bin/run-vmware.sh", arg );
}
if(! dat.command.empty() ) {
- execvp((char*) dat.command.c_str(), NULL);
+ char* arg[] = { (char*) dat.command.c_str(), '\0' };
+ execvp((char*) dat.command.c_str(), arg);
}
return string();
}
+
+
+
+
+/**
+ * Helper-Function: Get folder name
+ */
+char* getFolderName() {
+ const int MAX_LENGTH = 200;
+
+ /* Var for the folder name */
+ char* pname = (char*) malloc(MAX_LENGTH);
+ int result;
+
+ result = readlink("/proc/self/exe", pname, MAX_LENGTH);
+ if (result > 0) {
+ pname[result] = 0; /* add the NULL - not done by readlink */
+ }
+
+ int i=result-1;
+ while(pname[i] != '/' && i >= 0) {
+ pname[i] = '\0';
+ i--;
+ }
+ if(pname[i] == '/' ) {
+ pname[i] = '\0';
+ }
+
+ return pname;
+
+}
+
+
+const char* writeConfXml(DataEntry& dat) {
+
+ const int MAX_LENGTH = 300;
+
+ char* pname = getFolderName();
+ xmlNodePtr cur = 0;
+ xmlNodePtr root = 0;
+
+ strncat(pname, "/printer.sh", MAX_LENGTH);
+
+ cur = xmlDocGetRootElement(dat.xml);
+ if(cur == NULL) {
+ printf("Empty XML Document %s!", dat.xml_name.c_str());
+ return dat.xml_name.c_str();
+ }
+
+ // xmlNode "eintrag"
+ root = cur->children;
+ while(xmlStrcmp(root->name, (const xmlChar*)"eintrag") != 0) {
+ root = root->next;
+ }
+ if(xmlStrcmp(root->name, (const xmlChar *)"eintrag") != 0){
+ fprintf(stderr, "%s is not a valid xml file!", dat.xml_name.c_str());
+ return dat.xml_name.c_str();
+ }
+
+ // add "printers" and "scanners" - XML-Nodes
+ addPrinters(root, pname);
+
+ pname = getFolderName();
+ strncat(pname, "/scanner.sh", MAX_LENGTH);
+ addScanners(root, pname);
+
+ free(pname);
+
+ //xmlSaveFile("-", dat.xml);
+ xmlSaveFile( "/tmp/run.xml", dat.xml);
+ return "/tmp/run.xml";
+}
diff --git a/vmchooser/vmchooser.kdevelop b/vmchooser/vmchooser.kdevelop
index 2fe4268..53bf885 100644
--- a/vmchooser/vmchooser.kdevelop
+++ b/vmchooser/vmchooser.kdevelop
@@ -18,8 +18,8 @@
<run>
<directoryradio>executable</directoryradio>
<mainprogram>/home/bastian/studium/hiwi/openslx/openslx-src-tools/trunk/os-plugins/plugins/vmchooser/vmchooser</mainprogram>
- <programargs>-p xmltest</programargs>
- <globaldebugarguments>-p xmltest</globaldebugarguments>
+ <programargs/>
+ <globaldebugarguments/>
<globalcwd>/home/bastian/studium/hiwi/openslx/openslx-src-tools/trunk/os-plugins/plugins/vmchooser</globalcwd>
<useglobalprogram>false</useglobalprogram>
<terminal>false</terminal>