Skip to content

Commit

Permalink
Creation of init.cpp/h
Browse files Browse the repository at this point in the history
  • Loading branch information
KonklaveTtv committed Aug 28, 2023
1 parent 1bc78e7 commit dd04ae4
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 76 deletions.
26 changes: 26 additions & 0 deletions src/include/init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef INIT_H
#define INIT_H

#include "curl.h"
#include "errorhandler.h"
#include "fileutils.h"
#include "filtercriteria.h"
#include "mail.h"
#include "menu.h"

#include <set>
#include <vector>

class Init {
private:
std::string senderEmail, smtpServer;
int smtpPort;
bool useSSL, verifyPeer, verifyHost, verbose;
public:
// Function to display the splashscreen
static void splashscreen();

void Menu();
};

#endif // INIT_H
5 changes: 1 addition & 4 deletions src/include/main.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef MAIN_H
#define MAIN_H

#include "errorhandler.h"
#include "fileutils.h"
#include "mail.h"
#include "menu.h"
#include "init.h"

#endif // MAIN_H
73 changes: 73 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "include/init.h"

using namespace confPaths;
using namespace std;

MenuManager menuManager;

void Init::splashscreen() {
// Clear the console for the splashscreen
ConsoleUtils::clearConsole();

// Set color to cyan
ConsoleUtils::setColor(ConsoleUtils::Color::CYAN);
for (int i = 0; i < 44; ++i) std::cout << '*';
std::cout << std::endl;

ConsoleUtils::resetColor();

// Display splash text centered
std::cout << " VenueSender " << std::endl;
ConsoleUtils::setColor(ConsoleUtils::Color::CYAN);
std::cout << "********************************************" << std::endl;
ConsoleUtils::resetColor();

std::cout << " Version 1.0.0 " << std::endl;

// Display copyright and other text in cyan
ConsoleUtils::setColor(ConsoleUtils::Color::CYAN);
std::cout << "********************************************" << std::endl;
ConsoleUtils::resetColor();

std::cout << " Copyright (c) 2023, Spencer Lievens. " << std::endl;
ConsoleUtils::setColor(ConsoleUtils::Color::CYAN);

// Display bottom border
for (int i = 0; i < 44; ++i) std::cout << '*';
std::cout << std::endl;
ConsoleUtils::resetColor();

std::cout << " Initiailizing... " << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2));
}

void Init::Menu() {
// Main loop for interacting with the user
while (true) {
MenuManager::mainHeader();

// Display main menu options and get the user's choice
int mainChoice = MenuManager::displayMenuOptions();

// Main Menu
switch (mainChoice) {
case MenuManager::VENUE_SELECTION_OPTION:
MenuManager::displayVenueSelectionOptions();
break;
case MenuManager::VENUE_OPTIONS_OPTION:
MenuManager::displayVenueOptions();
break;
case MenuManager::EMAIL_OPTIONS_OPTION:
MenuManager::displayEmailOptions();
break;
case MenuManager::TEMPLATES_OPTION:
MenuManager::displayTemplateOptions();
break;
case MenuManager::CONFIGURATION_OPTION:
EmailManager::viewEmailSettings(useSSL, verifyPeer, verifyHost, verbose, senderEmail, smtpPort, smtpServer);
break;
default:
ErrorHandler::handleErrorAndReturn(ErrorHandler::ErrorType::INVALID_CHOICE_ERROR);
}
}
}
83 changes: 11 additions & 72 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,64 +1,28 @@
#include "include/main.h"

// Use relevant namespaces
using namespace confPaths;
using namespace std;

// Exclude the following code block if UNIT_TESTING is defined
#ifndef UNIT_TESTING

// Declare global objects to be used across different parts of the code
// Global objects to be used across different parts of the code
CurlHandleWrapper& curlWrapper = CurlHandleWrapper::getInstance();
VenueFilter venueFilter;
VenueUtilities venueUtilities;
VenueFilter venueFilter;

void splashscreen(){
// Clear the console for the splashscreen
ConsoleUtils::clearConsole();

// Set color to cyan
ConsoleUtils::setColor(ConsoleUtils::Color::CYAN);
for (int i = 0; i < 44; ++i) std::cout << '*';
std::cout << std::endl;

ConsoleUtils::resetColor();

// Display splash text centered
std::cout << " VenueSender " << std::endl;
ConsoleUtils::setColor(ConsoleUtils::Color::CYAN);
std::cout << "********************************************" << std::endl;
ConsoleUtils::resetColor();

std::cout << " Version 1.0.0 " << std::endl;

// Display copyright and other text in cyan
ConsoleUtils::setColor(ConsoleUtils::Color::CYAN);
std::cout << "********************************************" << std::endl;
ConsoleUtils::resetColor();

std::cout << " Copyright (c) 2023, Spencer Lievens. " << std::endl;
ConsoleUtils::setColor(ConsoleUtils::Color::CYAN);

// Display bottom border
for (int i = 0; i < 44; ++i) std::cout << '*';
std::cout << std::endl;
ConsoleUtils::resetColor();

std::cout << " Initiailizing... " << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2));
}
// Exclude the following code block if UNIT_TESTING is defined
#ifndef UNIT_TESTING

int main() {
// Load Splashscreen
splashscreen();
Init::splashscreen();

// Initialize necessary variables
vector<Venue> venues;
vector<SelectedVenue> selectedVenuesForTemplates;
string configVenuesCsvPath, smtpServer, smtpUsername, mailPass, mailPassDecrypted, senderEmail, subject, message, attachmentName, attachmentPath, attachmentSize;
int smtpPort;
bool templateExists = false;
bool useSSL, verifyPeer, verifyHost, verbose;

// Load configurations from JSON file
string venuesPathCopy = confPaths::venuesCsvPath;
if (!ConfigManager::loadConfigSettings(useSSL, verifyPeer, verifyHost, verbose, senderEmail, smtpUsername, mailPass, smtpPort, smtpServer, venuesPathCopy)) {
Expand All @@ -78,7 +42,7 @@ int main() {
CURL* curl = setupCurlHandle(curlWrapper, useSSL, verifyPeer, verifyHost, verbose, senderEmail, smtpUsername, mailPassDecrypted, smtpPort, smtpServer);
if (!curl) {
ErrorHandler::handleErrorAndReturn(ErrorHandler::ErrorType::LIBCURL_ERROR);
return 1; // Return error if CURL setup failed
return 1;
}

// Read venues data from CSV file
Expand Down Expand Up @@ -131,34 +95,9 @@ int main() {
templateExists
);

// Main loop for interacting with the user
while (true) {
MenuManager::mainHeader();

// Display main menu options and get the user's choice
int mainChoice = MenuManager::displayMenuOptions();

// Main Menu
switch (mainChoice) {
case MenuManager::VENUE_SELECTION_OPTION:
MenuManager::displayVenueSelectionOptions();
break;
case MenuManager::VENUE_OPTIONS_OPTION:
MenuManager::displayVenueOptions();
break;
case MenuManager::EMAIL_OPTIONS_OPTION:
MenuManager::displayEmailOptions();
break;
case MenuManager::TEMPLATES_OPTION:
MenuManager::displayTemplateOptions();
break;
case MenuManager::CONFIGURATION_OPTION:
EmailManager::viewEmailSettings(useSSL, verifyPeer, verifyHost, verbose, senderEmail, smtpPort, smtpServer);
break;
default:
ErrorHandler::handleErrorAndReturn(ErrorHandler::ErrorType::INVALID_CHOICE_ERROR);
}
}
// Function load filters and display menu
Init initInstance;
initInstance.Menu();

return 0;
}
Expand Down

0 comments on commit dd04ae4

Please sign in to comment.