diff -ruNp old/submenu.c new/submenu.c --- old/submenu.c 2008-06-04 18:46:23.000000000 +0200 +++ new/submenu.c 2008-06-19 08:46:21.000000000 +0200 @@ -37,28 +37,28 @@ cSubMenuNode::cSubMenuNode(TiXmlElement _level = level; if (xml != NULL && xml->Type() == TiXmlNode::ELEMENT) { - const char *tag =xml->Value(); + const char *tag = xml->Value(); if (cSubMenuNode::IsType(tag) != cSubMenuNode::UNDEFINED) { SetType(tag); SetName(xml->Attribute("name")); - if ((_type == COMMAND) || (_type == THREAD)){ + if ((_type == COMMAND) || (_type == THREAD)) { SetCommand(xml->Attribute("execute")); const char * confirmStr = xml->Attribute("confirm"); if (confirmStr != NULL && strcmp(confirmStr, TRUE_STR) == 0) _commandConfirm = true; } - else - if (_type == PLUGIN) // Add Plugin Index - SetPlugin(); - else - if (_type == MENU && xml->NoChildren() == false) { - xml = xml->FirstChildElement(); - do { - cSubMenuNode *node = new cSubMenuNode(xml, level+1, &_subMenus, currentMenu); - _subMenus.Add(node); - } while ((xml=xml->NextSiblingElement()) !=NULL); - } + else if (_type == PLUGIN) { // Add Plugin Index + SetCustomTitle(xml->Attribute("title")); + SetPlugin(); + } + else if (_type == MENU && xml->NoChildren() == false) { + xml = xml->FirstChildElement(); + do { + cSubMenuNode *node = new cSubMenuNode(xml, level+1, &_subMenus, currentMenu); + _subMenus.Add(node); + } while ((xml=xml->NextSiblingElement()) != NULL); + } } } else @@ -86,6 +86,7 @@ void cSubMenuNode::init() { _name = NULL; _command = NULL; + _title = NULL; _pluginMainMenuEntry = NULL; _type = UNDEFINED; _level = 0; @@ -102,6 +103,8 @@ cSubMenuNode::~ cSubMenuNode() free((void*)_name); if (_command != NULL) free((void*)_command); + if (_title != NULL) + free((void*)_title); if (_pluginMainMenuEntry != NULL) free((void*)_pluginMainMenuEntry); } @@ -118,7 +121,7 @@ void cSubMenuNode::SetPlugin() if (strcmp(_name, p->Name()) == 0 && p->MainMenuEntry() != NULL) { SetPluginMainMenuEntry(p->MainMenuEntry()); _pluginIndex = i; - found=true; + found = true; break; } } @@ -127,13 +130,13 @@ void cSubMenuNode::SetPlugin() } if (!found) - _type=UNDEFINED; + _type = UNDEFINED; } bool cSubMenuNode::SaveXml(TiXmlElement * root) { - bool ok=true; + bool ok = true; if (root!=NULL) { TiXmlElement *e = NULL; @@ -159,6 +162,8 @@ bool cSubMenuNode::SaveXml(TiXmlElement case PLUGIN: e = new TiXmlElement(TAG_PLUGIN); e->SetAttribute("name", GetName()); + if (GetCustomTitle() != NULL && strcmp(GetCustomTitle(), "") != 0) + e->SetAttribute("title", GetCustomTitle()); break; case MENU: e = new TiXmlElement(TAG_MENU); @@ -166,7 +171,7 @@ bool cSubMenuNode::SaveXml(TiXmlElement break; case UNDEFINED: default: - ok=false; + ok = false; break; } if (ok) { @@ -201,12 +206,12 @@ cSubMenuNode::Type cSubMenuNode::IsType( void cSubMenuNode::SetType(const char * name) { - _type=IsType(name); + _type = IsType(name); } void cSubMenuNode::SetType(enum Type type) { - _type=type; + _type = type; } @@ -247,10 +252,11 @@ void cSubMenuNode::SetCommand(const char { if (_command != NULL) free((void*)_command); + if (command != NULL) - _command= strdup(command); + _command = strdup(command); else - _command=NULL; + _command = NULL; } const char * cSubMenuNode::GetCommand() @@ -263,14 +269,39 @@ bool cSubMenuNode::CommandConfirm() return(_commandConfirm); } +void cSubMenuNode::SetCommandConfirm(int val) +{ + if (val == 1) + _commandConfirm = true; + else + _commandConfirm = false; +} + +void cSubMenuNode::SetCustomTitle(const char * title) +{ + if (_title != NULL) + free((void*)_title); + + if (title != NULL) + _title = strdup(title); + else + _title = NULL; +} + +const char * cSubMenuNode::GetCustomTitle() +{ + return(_title); +} + void cSubMenuNode::SetName(const char * name) { if (_name) free ((void*)_name); + if (name != NULL) _name = strdup(name); else - _name = NULL; + _name = NULL; } const char * cSubMenuNode::GetName() @@ -285,7 +316,7 @@ int cSubMenuNode::GetLevel() void cSubMenuNode::SetLevel(int level) { - _level =level; + _level = level; if (HasSubMenus()) { //Adjust Levels of Subnodes for (cSubMenuNode *node = _subMenus.First(); node; node = _subMenus.Next(node)) node->SetLevel(level+1); @@ -307,10 +338,12 @@ void cSubMenuNode::SetPluginMainMenuEntr if (_pluginMainMenuEntry != NULL) free((void*)_pluginMainMenuEntry); - if (mainMenuEntry!=NULL) - _pluginMainMenuEntry=strdup(mainMenuEntry); + if (_title != NULL && strcmp(_title, "") != 0) + _pluginMainMenuEntry = strdup(_title); + else if (mainMenuEntry != NULL) + _pluginMainMenuEntry = strdup(mainMenuEntry); else - _pluginMainMenuEntry=NULL; + _pluginMainMenuEntry = NULL; } const char * cSubMenuNode::GetPluginMainMenuEntry() @@ -348,7 +381,7 @@ cSubMenuNodes * cSubMenuNode::GetSubMenu bool cSubMenuNode::HasSubMenus() { - if (_subMenus.Count() >0) + if (_subMenus.Count() > 0) return(true); else return(false); @@ -357,14 +390,14 @@ bool cSubMenuNode::HasSubMenus() void cSubMenuNode::Print(int index) { - for (int i=0; iAttribute("suffix")) == NULL) + char *tmp = NULL; + if ((tmp = (char*)root->Attribute("suffix")) == NULL) asprintf(&_menuSuffix, " "); // set default menuSuffix // asprintf(&_menuSuffix, " ..."); else asprintf(&_menuSuffix, tmp); @@ -433,16 +466,16 @@ bool cSubMenu::LoadXml(char *fname) } catch (char *message) { esyslog("ERROR: while decoding XML Node"); - ok=false; + ok = false; } - } while (ok==true && (root=root->NextSiblingElement()) != NULL); + } while (ok == true && (root = root->NextSiblingElement()) != NULL); addMissingPlugins(); removeUndefinedNodes(); } } else { esyslog("ERROR: in %s, missing Tag \n", fname); - ok=false; + ok = false; } } else { @@ -451,7 +484,7 @@ bool cSubMenu::LoadXml(char *fname) xmlDoc.ErrorDesc(), xmlDoc.ErrorCol(), xmlDoc.ErrorRow()); - ok=false; + ok = false; } return(ok); @@ -466,7 +499,7 @@ bool cSubMenu::SaveXml() bool cSubMenu::SaveXml(char *fname) { - bool ok=true; + bool ok = true; if (_fname != NULL) { TiXmlDocument xml = TiXmlDocument(fname); @@ -485,10 +518,11 @@ bool cSubMenu::SaveXml(char *fname) \n\ \n\ \n\ - \n\ + \n\ \n\ \n\ - \n\ + \n\ + \n\ \n\ ...\n\ \n\ @@ -499,9 +533,6 @@ bool cSubMenu::SaveXml(char *fname) \n\ \n\ "); -/* - -*/ TiXmlElement root("menus"); root.SetAttribute("suffix", _menuSuffix); @@ -509,10 +540,10 @@ bool cSubMenu::SaveXml(char *fname) node->SaveXml(&root); if (xml.InsertEndChild(comment) != NULL && xml.InsertEndChild(root) != NULL) - ok=xml.SaveFile(fname); + ok = xml.SaveFile(fname); } else - ok=false; + ok = false; return(ok); } @@ -532,13 +563,12 @@ void cSubMenu::PrintMenuTree() } - int cSubMenu::GetNrOfNodes() { if (_nrNodes == 0) { if ((_nrNodes = countNodes(&_menuTree)) > 0) { _nodeArray = (cSubMenuNode**) malloc(sizeof(cSubMenuNode*)*_nrNodes); - int index=0; + int index = 0; tree2Array(&_menuTree, index); } } @@ -546,6 +576,7 @@ int cSubMenu::GetNrOfNodes() return(_nrNodes); } + /** * returns the specified node within the current menu * @param index position in the current menu @@ -568,9 +599,9 @@ cSubMenuNode * cSubMenu::GetNode(int ind */ cSubMenuNode * cSubMenu::GetAbsNode(int index) { - cSubMenuNode *node=NULL; + cSubMenuNode *node = NULL; GetNrOfNodes(); - if (_nrNodes>0 && index >= 0 && index < _nrNodes) + if (_nrNodes > 0 && index >= 0 && index < _nrNodes) node = _nodeArray[index]; return(node); @@ -583,9 +614,9 @@ bool cSubMenu::Down(cSubMenuNode *node, bool cSubMenu::Down(int index) #endif /* PINPLUGIN */ { - bool ok=true; + bool ok = true; #ifdef USE_PINPLUGIN - if(_currentMenuTree != NULL && node && node->GetType() == cSubMenuNode::MENU) { + if (_currentMenuTree != NULL && node && node->GetType() == cSubMenuNode::MENU) { #else cSubMenuNode *node = NULL; @@ -595,10 +626,10 @@ bool cSubMenu::Down(int index) #ifdef USE_PINPLUGIN _currentParentIndex = currentIndex; #endif /* PINPLUGIN */ - _currentMenuTree=node->GetSubMenus(); + _currentMenuTree = node->GetSubMenus(); } else { - ok=false; + ok = false; #ifdef USE_PINPLUGIN esyslog("ERROR: illegal call of cSubMenu::Down"); #else @@ -611,7 +642,7 @@ bool cSubMenu::Down(int index) bool cSubMenu::Up(int *parentIndex) { - bool ok=true; + bool ok = true; if (_currentMenuTree != NULL && parentIndex != NULL) { #ifndef USE_PINPLUGIN @@ -623,9 +654,9 @@ bool cSubMenu::Up(int *parentIndex) *parentIndex = _currentParentIndex; #else if (_currentParentMenuTree != NULL) - for (int i=0; (node=_currentParentMenuTree->Get(i)) != NULL; i++) { + for (int i = 0; (node = _currentParentMenuTree->Get(i)) != NULL; i++) { if (_currentMenuTree == node->GetSubMenus()) { - *parentIndex =i; + *parentIndex = i; break; } } @@ -635,10 +666,10 @@ bool cSubMenu::Up(int *parentIndex) if (_currentMenuTree != NULL) _currentParentMenuTree = _currentMenuTree->Get(0)->GetParentMenu(); else - ok=false; + ok = false; } else { - ok=false; + ok = false; esyslog("ERROR: illegal call of cSubMenu::Up()"); } @@ -688,7 +719,6 @@ void cSubMenu::MoveMenu(int index, int t if (where == cSubMenu::INTO && destNode->GetType() != cSubMenuNode::MENU) return; - if (where == cSubMenu::INTO) { if (destNode->GetType() == cSubMenuNode::MENU) { srcNode->GetCurrentMenu()->Del(srcNode, false); @@ -722,9 +752,9 @@ void cSubMenu::MoveMenu(int index, int t * @param index index of destination * @param menuTitle Titel of new Menu entry */ -void cSubMenu::CreateMenu(int index,const char * menuTitle) +void cSubMenu::CreateMenu(int index, const char * menuTitle) { - if (index >= 0 && index < _nrNodes) { + if (index >= 0 && index < _nrNodes) { cSubMenuNode *srcNode = GetAbsNode(index); if (srcNode != NULL) { cSubMenuNode *newNode = new cSubMenuNode(srcNode->GetParentMenu(), srcNode->GetCurrentMenu()); @@ -746,8 +776,8 @@ void cSubMenu::CreateMenu(int index,cons */ void cSubMenu::DeleteMenu(int index) { - if (index >= 0 && index < _nrNodes) { - cSubMenuNode *srcNode = GetAbsNode(index); + if (index >= 0 && index < _nrNodes) { + cSubMenuNode *srcNode = GetAbsNode(index); srcNode->GetCurrentMenu()->Del(srcNode, true); reloadNodeArray(); } @@ -758,7 +788,7 @@ void cSubMenu::DeleteMenu(int index) int cSubMenu::countNodes(cSubMenuNodes * tree) { - int count =0; + int count = 0; if (tree != NULL) { for (cSubMenuNode *node = tree->First(); node; node = tree->Next(node)) { count++; @@ -785,7 +815,7 @@ void cSubMenu::tree2Array(cSubMenuNodes bool cSubMenu::IsPluginInMenu(const char * name) { bool found = false; - for (int i=0; i<_nrNodes && found==false; i++) { + for (int i = 0; i < _nrNodes && found == false; i++) { cSubMenuNode *node = GetAbsNode(i); if (node != NULL && node->GetType() == cSubMenuNode::PLUGIN && strcmp(name, node->GetName()) == 0) found = true; @@ -822,15 +852,59 @@ void cSubMenu::addMissingPlugins() } /** + * Adds the given command to the Menu-Tree + * @param name specifies the name of the command + */ +void cSubMenu::CreateCommand(int index, const char * name, const char * execute, int confirm) +{ + if (index >= 0 && index < _nrNodes) { + cSubMenuNode *srcNode = GetAbsNode(index); + if (srcNode != NULL) { + cSubMenuNode *newNode = new cSubMenuNode(srcNode->GetParentMenu(), srcNode->GetCurrentMenu()); + newNode->SetLevel(srcNode->GetLevel()); + newNode->SetName(name); + newNode->SetType("command"); + newNode->SetCommand(execute); + newNode->SetCommandConfirm(confirm); + newNode->SetParentMenu(srcNode->GetParentMenu()); + newNode->SetCurrentMenu(srcNode->GetCurrentMenu()); + + srcNode->GetCurrentMenu()->Add(newNode, GetAbsNode(index)); + reloadNodeArray(); + } + } +} + +void cSubMenu::CreateThread(int index, const char * name, const char * execute, int confirm) +{ + if (index >= 0 && index < _nrNodes) { + cSubMenuNode *srcNode = GetAbsNode(index); + if (srcNode != NULL) { + cSubMenuNode *newNode = new cSubMenuNode(srcNode->GetParentMenu(), srcNode->GetCurrentMenu()); + newNode->SetLevel(srcNode->GetLevel()); + newNode->SetName(name); + newNode->SetType("thread"); + newNode->SetCommand(execute); + newNode->SetCommandConfirm(confirm); + newNode->SetParentMenu(srcNode->GetParentMenu()); + newNode->SetCurrentMenu(srcNode->GetCurrentMenu()); + + srcNode->GetCurrentMenu()->Add(newNode, GetAbsNode(index)); + reloadNodeArray(); + } + } +} + +/** * reloads the internal Array of Nodes */ void cSubMenu::reloadNodeArray() { - if (_nrNodes >0) + if (_nrNodes > 0) free(_nodeArray); _nodeArray = NULL; - _nrNodes = 0; - _nrNodes = GetNrOfNodes(); + _nrNodes = 0; + _nrNodes = GetNrOfNodes(); } /** @@ -838,15 +912,15 @@ void cSubMenu::reloadNodeArray() */ void cSubMenu::removeUndefinedNodes() { - bool remove=false; + bool remove = false; reloadNodeArray(); - for (int i=0; i<_nrNodes; i++) { + for (int i = 0; i < _nrNodes; i++) { cSubMenuNode *node = GetAbsNode(i); - if (node != NULL && node->GetType()==cSubMenuNode::UNDEFINED) { + if (node != NULL && node->GetType() == cSubMenuNode::UNDEFINED) { cSubMenuNodes *pMenu = node->GetCurrentMenu(); pMenu->Del(node, true); - remove=true; + remove = true; } } if (remove) @@ -859,13 +933,13 @@ void cSubMenu::removeUndefinedNodes() */ const char *cSubMenu::GetParentMenuTitel() { - const char * result=""; + const char * result = ""; if (_currentMenuTree != NULL && _currentParentMenuTree != NULL) { cSubMenuNode *node = NULL; - for (int i=0; (node=_currentParentMenuTree->Get(i))!= NULL ; i++) { + for (int i = 0; (node = _currentParentMenuTree->Get(i)) != NULL; i++) { if (_currentMenuTree == node->GetSubMenus()) { - result=node->GetName(); + result = node->GetName(); break; } } diff -ruNp old/submenu.h new/submenu.h --- old/submenu.h 2008-06-04 18:46:23.000000000 +0200 +++ new/submenu.h 2008-06-16 15:46:45.000000000 +0200 @@ -63,11 +63,14 @@ public: void SetType(enum Type type); void SetPlugin(); cSubMenuNode::Type GetType(); - const char*GetTypeAsString(); - void SetCommand(const char*command); + const char *GetTypeAsString(); + void SetCommand(const char *command); bool CommandConfirm(); - const char*GetCommand(); - void SetName(const char*name); + void SetCommandConfirm(int val); + const char *GetCommand(); + void SetCustomTitle(const char *title); + const char *GetCustomTitle(); + void SetName(const char *name); const char*GetName(); int GetLevel(); void SetLevel(int level); @@ -81,17 +84,18 @@ public: void SetCurrentMenu(cSubMenuNodes *current); cSubMenuNodes *GetSubMenus(); bool HasSubMenus(); - void Print(int index=0); + void Print(int index = 0); private: - Type _type; - int _level; + Type _type; + int _level; // Plugin Variables - int _pluginIndex; - const char *_pluginMainMenuEntry; + int _pluginIndex; + const char *_pluginMainMenuEntry; // common - const char *_name; - const char *_command; - bool _commandConfirm; + const char *_name; + const char *_command; + bool _commandConfirm; + const char *_title; cSubMenuNodes _subMenus; cSubMenuNodes *_parentMenu; cSubMenuNodes *_currentMenu; @@ -123,13 +127,15 @@ public: void PrintMenuTree(); bool IsPluginInMenu(const char *name); void AddPlugin(const char *name); - const char *ExecuteCommand(const char*command); + void CreateCommand(int index, const char *name, const char *execute, int confirm); + void CreateThread(int index, const char *name, const char *execute, int confirm); + const char *ExecuteCommand(const char *command); void MoveMenu(int index, int toindex, enum Where); void CreateMenu(int index, const char *menuTitle); void DeleteMenu(int index); - char *GetMenuSuffix() { return _menuSuffix;} + char *GetMenuSuffix() { return _menuSuffix; } void SetMenuSuffix(char *suffix) { if (_menuSuffix) free(_menuSuffix); asprintf(&_menuSuffix, suffix); } - bool isTopMenu() {return ( _currentParentMenuTree==NULL);} + bool isTopMenu() { return (_currentParentMenuTree == NULL); } const char *GetParentMenuTitel(); private: cSubMenuNodes _menuTree; @@ -138,11 +144,11 @@ private: #ifdef USE_PINPLUGIN int _currentParentIndex; #endif /* PINPLUGIN */ - char *_fname; - char *_commandResult; - int _nrNodes; - cSubMenuNode **_nodeArray; - char *_menuSuffix; + char *_fname; + char *_commandResult; + int _nrNodes; + cSubMenuNode **_nodeArray; + char *_menuSuffix; int countNodes(cSubMenuNodes *tree); void tree2Array(cSubMenuNodes *tree, int &index); void addMissingPlugins();