7 Commits 07f4513777 ... 5923071220

Autor SHA1 Mensaje Fecha
  David 'Judah's Shadow' Blue 5923071220 Add first handling for modules of type commentary in the list. Updated module error messages to better reflect what's going on. hace 9 años
  David 'Judah's Shadow' Blue e24d5a765f Add command parsing to handle arguments for list command, if it's not a valid module type (or not provided) then assume bibles is the type to avoid mist chief hace 9 años
  David 'Judah's Shadow' Blue 4b92a65e8e Fix support for categories so you can actually list them. hace 9 años
  David 'Judah's Shadow' Blue 6537471af3 Adding code to list commentaries when we get there. Commit early, commit often. hace 9 años
  David 'Judah's Shadow' Blue e0aab4247f Making module fetching generic on the back side. Not happy about having a bunch of else if statements, but switches don't work well with strings. hace 9 años
  David 'Judah's Shadow' Blue e4072bb4c4 CHange how the moduless list to make it more obvious what to do. hace 9 años
  David 'Judah's Shadow' Blue dfe49a540b Fix spacing for module listing. Can't believe I had set numBibles to 0 >_< hace 9 años
Se han modificado 4 ficheros con 100 adiciones y 24 borrados
  1. 53 9
      src/back/library.cpp
  2. 3 2
      src/back/library.h
  3. 26 1
      src/back/parser.cpp
  4. 18 12
      src/front/interface.cpp

+ 53 - 9
src/back/library.cpp

@@ -27,31 +27,75 @@
 #include <swmodule.h>
 
 std::list<std::string> Library::getBibles() {
-    std::string modules = "";
+    std::list<std::string> bibles;
+    bibles = getModuleList("bible");
+    return bibles;
+}
+
+std::list< std::string > Library::getCommentaries() {
+    std::list<std::string> commentaries;
+    commentaries = getModuleList("commentary");
+    return commentaries;
+}
+
+
+std::list< std::string > Library::getModuleList(std::string moduleType) {
     std::string module = "";
     sword::ModMap::iterator libraryIterator;
-    std::list<std::string> bibleList;
+    std::list<std::string> moduleList;
+    std::string selectedType;
     std::string modType;
 
+    std::string bible = sword::SWMgr::MODTYPE_BIBLES;
+    std::string comentary = sword::SWMgr::MODTYPE_COMMENTARIES;
+    std::string devo = sword::SWMgr::MODTYPE_DAILYDEVOS;
+    std::string book = sword::SWMgr::MODTYPE_GENBOOKS;
+    std::string dict = sword::SWMgr::MODTYPE_LEXDICTS;
+
+    if(moduleType == "bible") {
+        selectedType = bible;
+    }
+    else if(moduleType == "commentary") {
+        selectedType = comentary;
+    }
+    else if(moduleType == "devotion") {
+            selectedType = devo;
+    }
+    else if(moduleType == "book") {
+            selectedType = book;
+    }
+    else if(moduleType == "dictionary") {
+            selectedType = dict;
+    }
+    else {
+            //We should never get here but you never know.
+            module = "Invalid type";
+            moduleList.push_back(module);
+            return moduleList;
+    }
+
     for(libraryIterator = swordLibrary->Modules.begin();
-            libraryIterator != swordLibrary->Modules.end();
-            libraryIterator++) {
+        libraryIterator != swordLibrary->Modules.end();
+        libraryIterator++) {
 
         sword::SWModule *tempMod = libraryIterator->second;
         modType = tempMod->getType();
 
-        if(modType == sword::SWMgr::MODTYPE_BIBLES) {
-            module = tempMod->getDescription();
-            module += " - ";
+        if(modType == selectedType) {
+            module = "For ";
+            module += tempMod->getDescription();
+            module += " select ";
             module += tempMod->getName();
-            bibleList.push_front(module);
+            moduleList.push_front(module);
             module = "";
         }
     }
 
-    return bibleList;
+    return moduleList;
+
 }
 
+
 void Library::setSwordLibrary(sword::SWMgr *library) {
     this->swordLibrary = library;
 }

+ 3 - 2
src/back/library.h

@@ -25,15 +25,16 @@
 #include <list>
 
 #include <swmgr.h>
+#include <swmodule.h>
 
 class Library {
     public:
-        //returns a space separated list of bibles in the current sword library
         std::list<std::string> getBibles();
-
+        std::list<std::string> getCommentaries();
         void setSwordLibrary(sword::SWMgr *library);
     private:
         sword::SWMgr *swordLibrary;
+        std::list<std::string> getModuleList(std::string moduleType);
 };
 
 #endif // LIBRARY_H

+ 26 - 1
src/back/parser.cpp

@@ -52,7 +52,8 @@ std::list< std::string > Parser::parseCommand(std::string command) {
 
     parsedCommand.push_back(commandPart);
 
-    if (tokenizedCommand.empty()) {
+    //TODO: Find a better way for this corner case than to hard code it.
+    if (tokenizedCommand.empty() && commandPart != "list") {
         argumentCount = 0;
         return parsedCommand;
     } else {
@@ -74,6 +75,30 @@ std::list< std::string > Parser::parseCommand(std::string command) {
         //select has only one argument, stick it in line and ignore the rest
         parsedCommand.push_back(argumentPart.front());
     }
+    else if (commandPart == "list") {
+        if(argumentPart.front() == "bibles" ||
+           argumentPart.front() == "commentaries" ||
+           argumentPart.front() == "devotions" ||
+           argumentPart.front() == "books" ||
+           argumentPart.front() == "dictionaries") {
+
+            parsedCommand.push_back(argumentPart.front());
+
+        }
+        //TODO: Find a way to combine these options
+        else {
+            //since list was given and the argument isn't another valid type
+            //assume bibles
+            parsedCommand.push_back("bibles");
+        }
+    }
+    else {
+        //Add a genral case to just pass arguments to the back as a list
+        while(!argumentPart.empty()) {
+            parsedCommand.push_back(argumentPart.front());
+            argumentPart.pop_front();
+        }
+    }
     return parsedCommand;
 }
 

+ 18 - 12
src/front/interface.cpp

@@ -58,7 +58,6 @@ void Interface::configLines() {
 }
 
 std::string Interface::processCommand(std::string command) {
-    //TODO: REFACTOR ME!!!!!!!!!!!!!!!!!!!!!!111111111111111111oneoneone
     std::string validCommands[5];
     std::string text = "";
     std::string ref = "";
@@ -70,7 +69,7 @@ std::string Interface::processCommand(std::string command) {
 
     std::string commandPart;
 
-    std::list<std::string> bibles;
+    std::list<std::string> modules;
     std::list<std::string> parsedCommand;
 
     parsedCommand = commandParser.parseCommand(command);
@@ -152,31 +151,38 @@ std::string Interface::processCommand(std::string command) {
         display.displayHelp();
         return commandPart;
     } else if(commandPart == validCommands[3]) {
-        int numBibles = 0;
+        int numModules = 0;
 
         library.setSwordLibrary(swordLibrary);
-        bibles = library.getBibles();
+        if(parsedCommand.front() == "bibles") {
+            modules = library.getBibles();
+        }
+        else if (parsedCommand.front() == "commentaries") {
+            modules = library.getCommentaries();
+        }
 
-        if(bibles.empty()) {
-            std::cerr <<  "No bibles found, please install in another frontend";
+        if(modules.empty()) {
+            std::cerr <<  "No modules found, of type: ";
+            std::cerr <<  parsedCommand.front();
+            std:: cerr << " please install in another frontend";
             std::cerr <<  std::endl;
             display.displaySpacer(1);
             return "-3";
         }
         else {
-            numBibles = 0;
+            numModules = modules.size();
         }
 
         std::string curBible;
 
-        while(!bibles.empty()) {
-            curBible = bibles.front();
+        while(!modules.empty()) {
+            curBible = modules.front();
             std::cout <<  curBible;
             std::cout << std::endl;
-            bibles.pop_front();
+            modules.pop_front();
         }
 
-        display.displaySpacer(numBibles + 2);
+        display.displaySpacer(numModules);
 
         return commandPart;
     } else if (commandPart == validCommands[4]) {
@@ -228,7 +234,7 @@ int Interface::runInterface() {
             break;
         } else if(command ==  "-3") {
             returnCode = -2;
-            std::cerr <<  "No modules found. Aborting.." <<  std::endl;
+            std::cerr <<  "No relevant modules found. Aborting.." <<  std::endl;
             break;
         }