Skip to content

Commit

Permalink
Merge pull request #441 from minorsecond/develop
Browse files Browse the repository at this point in the history
BuzzBot-v2.4.0
  • Loading branch information
minorsecond authored Sep 25, 2022
2 parents 7b0576f + 76e539c commit b6484dd
Show file tree
Hide file tree
Showing 27 changed files with 744 additions and 328 deletions.
4 changes: 2 additions & 2 deletions BuzzBot-Entitlements.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<false/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<key>com.apple.security.files.all</key>
<true/>
</dict>
</plist>
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ ENDIF()

add_executable(BuzzBot MACOSX_BUNDLE ${ICON_PATH} src/main.cpp src/mainwindow.cpp src/database.cpp src/mainwindow.h
src/database.h src/usersettings.cpp src/usersettings.h src/calculate.cpp src/calculate.h src/beer.cpp
src/liquor.cpp src/wine.cpp src/filters.cpp src/about.cpp src/about.h src/exporters.cpp src/exporters.h
src/liquor.cpp src/wine.cpp src/filters.cpp src/about.cpp src/about.h src/exporters.cpp src/exporters.h
src/standard_drink_calculator.cpp src/standard_drink_calculator.h src/confirm_dialog.cpp src/confirm_dialog.h
src/graphing.cpp src/graphing.h include/qcustomplot.h include/qcustomplot.cpp
src/table_manipulation.cpp src/stats_updaters.cpp src/utilities.cpp src/utilities.h src/drink.h
src/graphing_calculations.h src/graphing_calculations.cpp src/options.h src/drink.cpp src/drink_standards.h src/drink_standards.cpp)
src/graphing_calculations.h src/graphing_calculations.cpp src/options.h src/drink.cpp src/drink_standards.h src/drink_standards.cpp src/options.cpp)
add_executable(functions_test src/database.cpp src/database.h src/calculate.cpp src/calculate.h
test/test_database_functions.cpp test/test_calculations.cpp test/test_graph_calculations.cpp
src/utilities.cpp src/utilities.h src/drink.h src/graphing_calculations.h src/graphing_calculations.cpp src/options.h src/drink.cpp src/drink_standards.h src/drink_standards.cpp)
src/utilities.cpp src/utilities.h src/drink.h src/graphing_calculations.h src/graphing_calculations.cpp src/options.h src/drink.cpp src/drink_standards.h src/drink_standards.cpp src/options.cpp)

if (CMAKE_BUILD_TYPE MATCHES Debug)
message("Building debug")
Expand All @@ -81,11 +81,11 @@ IF(APPLE)

set_target_properties(BuzzBot PROPERTIES
MACOSX_BUNDLE_BUNDLE_NAME "BuzzBot"
MACOSX_BUNDLE_BUNDLE_VERSION "2.3.0"
MACOSX_BUNDLE_BUNDLE_VERSION "2.4.0"
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_ICON_FILE icon.icns
MACOSX_BUNDLE_LONG_VERSION_STRING "2.3.0"
MACOSX_BUNDLE_SHORT_VERSION_STRING "2.3.0"
MACOSX_BUNDLE_LONG_VERSION_STRING "2.4.0"
MACOSX_BUNDLE_SHORT_VERSION_STRING "2.4.0"
MACOSX_BUNDLE_COPYRIGHT "2021 Ross Wardrup"
MACOSX_BUNDLE_GUI_IDENTIFIER com.rwardrup.buzzbot
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@loader_path/Libraries"
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ BuzzBot on macOS
- `cmake ..`
- `cmake --build . --target BuzzBot`. If you want to run tests, run `cmake --build . --target functions_test`.
- If you're running macOS, you'll have a `BuzzBot.app` file in the `build` directory.
- If you're running Linux, you can install the app in `~/.local/bin` by running `cmake --install .`.
The app should then be available in your app menu.
- If you're running Linux, you can install the app in `~/.local/bin` by running `cmake --install .`.
The app should then be available in your app menu.
- If using a Samba share in Linux to share your database across multiple devices, be sure to add the
`nobrl` mount option for the share that the DB file will reside on. This prevents your SMB client from sending byte
range locks to the server. Without this addition, you will get a locked database error.

### Developing BuzzBot
- Dependencies:
Expand Down
1 change: 1 addition & 0 deletions VERS
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
2.2.0 2021-11-01-10-09-05
2.2.1 2021-11-01-10-19-05
2.3.0 2022-09-20-06-43-55
2.4.0 2022-09-25-12-39-36
8 changes: 4 additions & 4 deletions include/qcustomplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10594,7 +10594,7 @@ void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString
QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points.

For custom shapes, you can provide a QPainterPath with the desired shape to the \ref
setCustomPath function or call the constructor that takes a painter path. The scatter shape will
setCustomPath function or call the constructor that takes a painter get_db_path. The scatter shape will
automatically be set to \ref ssCustom.

For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the
Expand Down Expand Up @@ -10727,9 +10727,9 @@ QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) :
scatter shape is set to \ref ssCustom.

The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly
different meaning than for built-in scatter points: The custom path will be drawn scaled by a
factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its
original size by default. To for example double the size of the path, set \a size to 12.
different meaning than for built-in scatter points: The custom get_db_path will be drawn scaled by a
factor of \a size/6.0. Since the default \a size is 6, the custom get_db_path will appear in its
original size by default. To for example double the size of the get_db_path, set \a size to 12.
*/
QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) :
mSize(size),
Expand Down
4 changes: 2 additions & 2 deletions src/about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ About::About() {
this->setFixedSize(237, 272);

// Version text
const std::string version = "2.3.0";
const std::string version = "2.4.0";
ui.versionLabel->setText(QString::fromStdString("Version " + version));

// Make Qt URL clickable
Expand All @@ -34,7 +34,7 @@ About::About() {
const CFStringRef mac_path = CFURLCopyFileSystemPath(app_url_ref, kCFURLPOSIXPathStyle);
const QString icon_path_qstring = CFStringGetCStringPtr(mac_path, CFStringGetSystemEncoding());

// Set path to icon
// Set get_db_path to icon
const std::string icon_path = icon_path_qstring.toStdString() + "/Contents/Resources/mini-icon.png";
CFRelease(app_url_ref);
CFRelease(mac_path);
Expand Down
11 changes: 11 additions & 0 deletions src/calculate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,14 @@ void Calculate::decrement_day(std::tm &date) {
date.tm_mon = search_date->tm_mon;
date.tm_mday = search_date->tm_mday;
}

bool Calculate::equal_double(const double a, const double b) {
/*
* Compare two floats.
* @param a: Float A
* @param b: Float B
* @return: Boolean denoting whether a == b
*/

return fabs(a - b) < std::numeric_limits<double>::epsilon();
}
1 change: 1 addition & 0 deletions src/calculate.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Calculate {
static bool compare_strings(std::string lhs, std::string rhs);
static int weekly_limit(const Options& options);
static int days_in_row(Storage &storage);
static bool equal_double(const double a, const double b);

private:
static void decrement_day(std::tm &date);
Expand Down
11 changes: 11 additions & 0 deletions src/confirm_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@ ConfirmDialog::ConfirmDialog(const std::string& action) {
ui.actionConfirmationLabel->setText("You are attempting to edit a row. Click OK to confirm.");
} else if (action == "Clear Data") {
ui.actionConfirmationLabel->setText("You are attempting to clear the database. Click OK to confirm.");
} else if (action == "Moving DB") {
ui.actionConfirmationLabel->setText(
"After moving the DB, the app will close. You will have to reopoen it after saving preferences.");
} else if (action == "Moved DB") {
ui.actionConfirmationLabel->setText("Closing app. Restart to load data from new location.");
} else if (action == "NoDbPathChange") {
ui.actionConfirmationLabel->setText("Database path unchanged. It is not being moved.");
} else if (action == "DestFileExists") {
ui.actionConfirmationLabel->setText("Destination file already exists. BuzzBot will load it upon next launch. \n"
"Do you want to delete the current file, keeping the destination file?\n"
"BuzzBot will close after your response.");
}
}
58 changes: 41 additions & 17 deletions src/database.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
#include "database.h"
#include "utilities.h"
#include <utility>
#include <iostream>
#include <QStandardPaths>
#include <filesystem>
#include <string>

using namespace sqlite_orm;
std::string Database::path() {
/*
* Find database path and create it if it doesn't exist.
* @return full_path Path where database file should be stored.
*/

// Find path to application support directory
const std::string directory = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).at(0).toStdString();
const std::string full_path = directory + "/buzzbot.db";
std::filesystem::create_directory(directory);

std::cout << "Using DB located at " << full_path << std::endl;

return full_path;
}

std::vector<Drink> Database::read(Storage storage) {
/*
Expand All @@ -28,6 +14,7 @@ std::vector<Drink> Database::read(Storage storage) {
*/

const std::vector<Drink> all_drinks = storage.get_all<Drink>();
std::cout << "Read " + std::to_string(all_drinks.size()) + " drinks from DB" << std::endl;

return all_drinks;
}
Expand All @@ -47,7 +34,7 @@ Storage Database::write(Drink drink, Storage storage) {
* @return Storage: The storage instance
*/

const std::string database_path = path();
const std::string database_path = utilities::get_db_path();
const int inserted_id = storage.insert(drink);
drink.id = inserted_id;
write_db_to_disk(storage);
Expand Down Expand Up @@ -312,3 +299,40 @@ void Database::sort_by_date_id(std::vector<Drink> &drinks) {
sort_order++;
}
}


int Database::move_db(const std::string &current_path, const std::string &new_path) {
/*
* Move DB file if user selects a new get_db_path option.
* @param: None
* @return: 0 if move is successful, else 1
*/

const std::string std_path{utilities::get_application_data_path() + "/buzzbot.db"};

if (utilities::file_exists(std_path + ".bak")) {
std::filesystem::remove(std_path + ".bak");
}

std::filesystem::copy(current_path, std_path + ".bak");

if (!utilities::file_exists(new_path))
{
try {
std::filesystem::copy(current_path, new_path);
if (utilities::file_exists(current_path)) {
std::filesystem::remove(current_path);
}
return 0;
} catch (std::filesystem::filesystem_error &e) {
std::cout << e.what() << std::endl;
std::cout << "Restoring backup!" << std::endl;
std::filesystem::copy(std_path + ".bak", std_path);
}
} else {
std::cout << new_path << " already exists. Not overwriting with " << current_path << std::endl;
return 2;
}

return 1;
}
24 changes: 12 additions & 12 deletions src/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
#include <vector>
#include <QDate>

inline auto initStorage(const std::string& file_name, int db_version) {
inline auto initStorage(const std::string &file_name) {
/*
* Initialize the DB
*/

std::string table_name = "beers";
// Set table name based on DB version
if (db_version > 7) {
table_name = "drinks";
}

const std::string table_name = "drinks";
return sqlite_orm::make_storage(file_name,
sqlite_orm::make_table(table_name,
sqlite_orm::make_column("id", &Drink::id, sqlite_orm::autoincrement(), sqlite_orm::primary_key()),
sqlite_orm::make_column("date", &Drink::date, sqlite_orm::default_value("2020-01-01")),
sqlite_orm::make_column("drink_name", &Drink::name),
sqlite_orm::make_column("id", &Drink::id,
sqlite_orm::autoincrement(),
sqlite_orm::primary_key()),
sqlite_orm::make_column("date", &Drink::date,
sqlite_orm::default_value(
"2020-01-01")),
sqlite_orm::make_column("drink_name", &Drink::name),
sqlite_orm::make_column("drink_type", &Drink::type),
sqlite_orm::make_column("drink_subtype", &Drink::subtype, sqlite_orm::default_value("")),
sqlite_orm::make_column("producer", &Drink::producer, sqlite_orm::default_value("")),
Expand All @@ -35,7 +34,8 @@ inline auto initStorage(const std::string& file_name, int db_version) {
sqlite_orm::make_column("alcohol_type", &Drink::alcohol_type, sqlite_orm::default_value("Beer")),
sqlite_orm::make_column("timestamp", &Drink::timestamp, sqlite_orm::default_value(sqlite_orm::datetime("now", "localtime")))));
}
using Storage = decltype (initStorage("", -1));

using Storage = decltype(initStorage(""));

class Database
{
Expand Down Expand Up @@ -63,7 +63,7 @@ class Database
static void populate_size_field();

public:
static std::string path();
static int move_db(const std::string &current_path, const std::string &new_path);
};

#endif // DATABASE_H
4 changes: 2 additions & 2 deletions src/drink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ double Drink::get_standard_drinks() const {
* @param std_drink_size: the size of the standard drink, in the same unit as amount.
*/

Options options;
Options options; // Reads options from FS
const double alcohol_amt = get_alcohol_volume();
const double std_drink_size {utilities::get_std_drink_size()};
const double std_drink_size{utilities::get_std_drink_size()};

return utilities::round_to_two_decimal_points(alcohol_amt / std_drink_size);
}
Expand Down
2 changes: 1 addition & 1 deletion src/drink.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Drink {

friend class Calculate;
friend class Database;
friend auto initStorage(const std::string& file_name, int db_version);
friend auto initStorage(const std::string &file_name);

public:
// Setters
Expand Down
2 changes: 1 addition & 1 deletion src/exporters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void exporters::to_csv(const std::vector<Drink> &drinks, const std::string &path
/*
* Creates a CSV file containing the current DB contents.
* @param drinks: A vector of Drinks.
* @param path: Path where CSV should be saved.
* @param get_db_path: Path where CSV should be saved.
*/

std::ofstream output_csv(path);
Expand Down
Loading

0 comments on commit b6484dd

Please sign in to comment.