2023-09-19 15:33:33 +00:00
|
|
|
/*Author: Daniel Jones
|
|
|
|
*IDE: QT Creator
|
|
|
|
*Compiler: MinGW
|
|
|
|
*OS: Windows 10
|
|
|
|
*Purpose: QT Widget that displays the verse of the day upon Windows 10 bootup.
|
2024-01-03 21:40:47 +00:00
|
|
|
* Last edited: 1/3/2024
|
2023-09-19 15:33:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "./ui_mainwindow.h"
|
2023-09-19 19:11:06 +00:00
|
|
|
#include <chrono>
|
2024-01-03 20:33:07 +00:00
|
|
|
#include <ctime>
|
2023-09-19 15:33:33 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2024-01-03 21:40:47 +00:00
|
|
|
|
|
|
|
//Function declarations
|
2024-01-03 20:33:07 +00:00
|
|
|
int current_day();
|
|
|
|
int current_month();
|
2023-09-19 15:33:33 +00:00
|
|
|
QString verse_display();
|
2023-09-19 19:11:06 +00:00
|
|
|
std::string verse_grab();
|
2023-09-19 15:33:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
: QMainWindow(parent)
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->verse->setText(verse_display());
|
2024-01-03 20:33:07 +00:00
|
|
|
std::cout << current_day();
|
|
|
|
std::cout << current_month();
|
2023-09-19 15:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2023-09-19 19:11:06 +00:00
|
|
|
|
2023-09-19 15:33:33 +00:00
|
|
|
|
2024-01-03 21:40:47 +00:00
|
|
|
/*
|
|
|
|
* Function: verse_display
|
|
|
|
* description: This function asks verse_grab to get the verse from the sqlite3 database, converts it
|
|
|
|
* to a format that QT can display, and then returns it to MainWindow.
|
|
|
|
* Return type: QString
|
|
|
|
* Param: none
|
|
|
|
*/
|
2023-09-19 15:33:33 +00:00
|
|
|
QString verse_display()
|
|
|
|
{
|
|
|
|
std::string verse_text;
|
2023-09-19 19:11:06 +00:00
|
|
|
|
|
|
|
verse_text = verse_grab();
|
2023-09-19 15:33:33 +00:00
|
|
|
|
|
|
|
QString returned_string = QString::fromStdString(verse_text);
|
|
|
|
|
|
|
|
return returned_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-03 21:40:47 +00:00
|
|
|
/*
|
|
|
|
* Function: verse_grab
|
|
|
|
* description: selects the verse based on the current day and returns the result
|
|
|
|
* Return type: string
|
|
|
|
* Param: none
|
|
|
|
*/
|
2023-09-19 19:11:06 +00:00
|
|
|
std::string verse_grab(){
|
2023-09-19 15:33:33 +00:00
|
|
|
|
|
|
|
std::string my_verse;
|
2024-01-03 21:40:47 +00:00
|
|
|
|
|
|
|
//gets current month and day and returns the result
|
2024-01-03 20:33:07 +00:00
|
|
|
int curmonth = current_month();
|
|
|
|
int curday = current_day();
|
|
|
|
std::string query = "select * from verses where day = " + std::to_string(curday) + " and month = " + std::to_string(curmonth);
|
2023-09-19 15:33:33 +00:00
|
|
|
|
2024-01-03 21:40:47 +00:00
|
|
|
//placeholder until I get the SQLlite3 connection working
|
2024-01-03 20:33:07 +00:00
|
|
|
my_verse = "hello world!";
|
2024-01-03 21:40:47 +00:00
|
|
|
return my_verse;
|
2024-01-03 20:33:07 +00:00
|
|
|
|
|
|
|
}
|
2023-09-19 15:33:33 +00:00
|
|
|
|
|
|
|
|
2024-01-03 21:40:47 +00:00
|
|
|
//UI function that exits when the "go in peace" button is pressed.
|
2023-09-19 15:33:33 +00:00
|
|
|
void MainWindow::on_exitButton_clicked()
|
|
|
|
{
|
|
|
|
QApplication::quit();
|
|
|
|
}
|
|
|
|
|
2024-01-03 20:33:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Everything below this grabs the day and month.
|
|
|
|
typedef std::chrono::system_clock Clock;
|
2024-01-03 21:40:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function: current_day
|
|
|
|
* description: queries the operating system for the current day
|
|
|
|
* Return type: integer
|
|
|
|
* Param: none
|
|
|
|
*/
|
2024-01-03 20:33:07 +00:00
|
|
|
int current_day(){
|
|
|
|
|
|
|
|
auto now = Clock::now();
|
|
|
|
std::time_t now_c = Clock::to_time_t(now);
|
|
|
|
struct tm *parts = std::localtime(&now_c);
|
|
|
|
|
|
|
|
|
|
|
|
int day = parts->tm_mday;
|
|
|
|
|
|
|
|
return day;
|
|
|
|
}
|
|
|
|
|
2024-01-03 21:40:47 +00:00
|
|
|
/*
|
|
|
|
* Function: current_month
|
|
|
|
* description: queries the operating system for the current month
|
|
|
|
* Return type: integer
|
|
|
|
* Param: none
|
|
|
|
*/
|
2024-01-03 20:33:07 +00:00
|
|
|
int current_month(){
|
|
|
|
|
|
|
|
auto now = Clock::now();
|
|
|
|
std::time_t now_c = Clock::to_time_t(now);
|
|
|
|
struct tm *parts = std::localtime(&now_c);
|
|
|
|
|
|
|
|
|
|
|
|
int month = 1 + parts->tm_mon;
|
|
|
|
|
|
|
|
return month;
|
|
|
|
}
|