Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Language: Cpp
BasedOnStyle: Google
BasedOnStyle: Google
IndentWidth: 4
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ deploy-linux:
@$(MAKE) -C $(scripts_folder) deploy-linux build_options="$(build_options)"

tests-ffi:
@$(MAKE) -C tests-ffi tests
@$(MAKE) -C tests-ffi tests

fmt:
@$(MAKE) -C tools fmt
20 changes: 10 additions & 10 deletions src/front_end/about_widget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ using Self = AboutWidget;
AboutWidget::AboutWidget() { show_about = make_unique<QPushButton>(); }

void Self::setup_event() {
const auto function = [this]() {
if (!about_window) {
about_window = make_unique<AboutWindow>();
}
const auto function = [this]() {
if (!about_window) {
about_window = make_unique<AboutWindow>();
}

about_window->show_window();
};
about_window->show_window();
};

QObject::connect(show_about.get(), &QPushButton::clicked, function);
QObject::connect(show_about.get(), &QPushButton::clicked, function);
}

void Self::setup_widget(QGridLayout *grid_layout) {
show_about->setText("About");
this->setup_event();
grid_layout->addWidget(show_about.get(), 1, 1);
show_about->setText("About");
this->setup_event();
grid_layout->addWidget(show_about.get(), 1, 1);
}
91 changes: 46 additions & 45 deletions src/front_end/about_window.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,67 @@ using std::make_unique;
using Self = AboutWindow;

AboutWindow::AboutWindow() {
about_window = make_unique<QDialog>();
grid_layout = make_unique<QGridLayout>();
github_button = make_unique<QPushButton>();
github_issue_button = make_unique<QPushButton>();
github_pull_button = make_unique<QPushButton>();
about_window = make_unique<QDialog>();
grid_layout = make_unique<QGridLayout>();
github_button = make_unique<QPushButton>();
github_issue_button = make_unique<QPushButton>();
github_pull_button = make_unique<QPushButton>();
}

void Self::is_open_browser_ok(OpenBrowserStatus status) {
switch (status) {
case OpenBrowserStatus::OK:
break;

case OpenBrowserStatus::OPEN_BROWSER_FAILED:
QMessageBox::critical(about_window.get(), "Error",
"Could not open your browser");
break;

case OpenBrowserStatus::WRAP_RAW_C_FAILED:
QMessageBox::critical(about_window.get(), "Error",
"Could not wrap C raw to safety string");

break;
case OpenBrowserStatus::URL_IS_EMPTY:
QMessageBox::critical(about_window.get(), "Error", "Url is empty");
break;
}
switch (status) {
case OpenBrowserStatus::OK:
break;

case OpenBrowserStatus::OPEN_BROWSER_FAILED:
QMessageBox::critical(about_window.get(), "Error",
"Could not open your browser");
break;

case OpenBrowserStatus::WRAP_RAW_C_FAILED:
QMessageBox::critical(about_window.get(), "Error",
"Could not wrap C raw to safety string");

break;
case OpenBrowserStatus::URL_IS_EMPTY:
QMessageBox::critical(about_window.get(), "Error", "Url is empty");
break;
}
}

void Self::open_browser_when_clicked(QPushButton *button, const char *url) {
const auto open_browser = [this, url] {
auto status = Lazyboard::ffi::open_browser(url);
is_open_browser_ok(status);
};
const auto open_browser = [this, url] {
auto status = Lazyboard::ffi::open_browser(url);
is_open_browser_ok(status);
};

QObject::connect(button, &QPushButton::clicked, open_browser);
QObject::connect(button, &QPushButton::clicked, open_browser);
}

void Self::setup_buttons() {
github_button->setText("GitHub | Source Code");
github_issue_button->setText("Issue | Bug Report");
github_pull_button->setText("Pull Request | Contribute");

this->open_browser_when_clicked(github_button.get(), GITHUB_URL);
this->open_browser_when_clicked(github_issue_button.get(), GITHUB_ISSUE_URL);
this->open_browser_when_clicked(github_pull_button.get(), GITHUB_PULL_URL);

grid_layout->addWidget(github_button.get(), 0, 0);
grid_layout->addWidget(github_issue_button.get(), 0, 1);
grid_layout->addWidget(github_pull_button.get(), 1, 0);
github_button->setText("GitHub | Source Code");
github_issue_button->setText("Issue | Bug Report");
github_pull_button->setText("Pull Request | Contribute");

this->open_browser_when_clicked(github_button.get(), GITHUB_URL);
this->open_browser_when_clicked(github_issue_button.get(),
GITHUB_ISSUE_URL);
this->open_browser_when_clicked(github_pull_button.get(), GITHUB_PULL_URL);

grid_layout->addWidget(github_button.get(), 0, 0);
grid_layout->addWidget(github_issue_button.get(), 0, 1);
grid_layout->addWidget(github_pull_button.get(), 1, 0);
}

void Self::setup_front_end() {
about_window->setLayout(this->grid_layout.get());
this->setup_buttons();
about_window->setLayout(this->grid_layout.get());
this->setup_buttons();
}

void Self::show_window() {
about_window->setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
about_window->setWindowTitle("Lazyboard About");
about_window->setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
about_window->setWindowTitle("Lazyboard About");

this->setup_front_end();
about_window->exec();
this->setup_front_end();
about_window->exec();
}
38 changes: 19 additions & 19 deletions src/front_end/main_window.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ using std::make_unique;
using Self = MainWindow;

Self::MainWindow() {
main_window = make_unique<QMainWindow>();
main_window_preload = make_unique<MainWindowPreload>();
auto central_w = make_unique<QWidget>();
auto layout_w = make_unique<QGridLayout>(central_w.get());
main_window = make_unique<QMainWindow>();
main_window_preload = make_unique<MainWindowPreload>();
auto central_w = make_unique<QWidget>();
auto layout_w = make_unique<QGridLayout>(central_w.get());

main_window->setCentralWidget(central_w.get());
main_window->setCentralWidget(central_w.get());

central_widget = central_w.release();
grid_layout = layout_w.release();
central_widget = central_w.release();
grid_layout = layout_w.release();
}

Self *Self::init_main_window() {
main_window->setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
main_window->setWindowTitle("Lazyboard");
main_window_preload->create_default_config(main_window.get());
this->front_end_show();
main_window->show();
main_window->setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
main_window->setWindowTitle("Lazyboard");
main_window_preload->create_default_config(main_window.get());
this->front_end_show();
main_window->show();

return this;
return this;
}

void Self::front_end_show() {
table_widget = make_unique<TableWidget>();
setting_widget = make_unique<SettingWidget>();
about_widget = make_unique<AboutWidget>();
table_widget = make_unique<TableWidget>();
setting_widget = make_unique<SettingWidget>();
about_widget = make_unique<AboutWidget>();

table_widget->setup_widget(this->grid_layout);
setting_widget->setup_widget(this->grid_layout);
about_widget->setup_widget(this->grid_layout);
table_widget->setup_widget(this->grid_layout);
setting_widget->setup_widget(this->grid_layout);
about_widget->setup_widget(this->grid_layout);
}
86 changes: 43 additions & 43 deletions src/front_end/main_window_preload.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,65 @@ using std::stringstream;
using namespace Lazyboard::ffi;

void Self::on_error(WriteConfigStatus status, QMainWindow* main_window) {
switch (status) {
case WriteConfigStatus::OK:
break;

case WriteConfigStatus::CREATE_DIR_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not create config directory");
break;

case WriteConfigStatus::GET_DATA_LOCAL_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not get application local data");
break;

case WriteConfigStatus::CREATE_FILE_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not create configuration file");
break;

case WriteConfigStatus::WRITE_FILE_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not write configuration");
break;

case WriteConfigStatus::TOML_TO_STRING_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not convert TOML data to string");
break;
}
switch (status) {
case WriteConfigStatus::OK:
break;

case WriteConfigStatus::CREATE_DIR_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not create config directory");
break;

case WriteConfigStatus::GET_DATA_LOCAL_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not get application local data");
break;

case WriteConfigStatus::CREATE_FILE_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not create configuration file");
break;

case WriteConfigStatus::WRITE_FILE_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not write configuration");
break;

case WriteConfigStatus::TOML_TO_STRING_FAILED:
QMessageBox::critical(main_window, "Error",
"Could not convert TOML data to string");
break;
}
}

void Self::create_default_config(QMainWindow* main_window) {
auto local_data_raw = ffi::local_data();
auto local_data_raw = ffi::local_data();

stringstream string_stream;
string_stream << local_data_raw << "/Lazyboard";
string config_path = string_stream.str();
stringstream string_stream;
string_stream << local_data_raw << "/Lazyboard";
string config_path = string_stream.str();

auto is_config_exists = ffi::is_exists_path(config_path.data());
ffi::free_c_str(local_data_raw);
auto is_config_exists = ffi::is_exists_path(config_path.data());
ffi::free_c_str(local_data_raw);

if (!is_config_exists) {
// clang-format off
if (!is_config_exists) {
// clang-format off
#if defined (LAZY_DEBUG)
auto q_string_value = QString::fromStdString(config_path);

qDebug() << "Config path not found, generate at: " << q_string_value << "\n";
#endif
// clang-format on
// clang-format on

auto status = ffi::write_default_config();
on_error(status, main_window);
}
auto status = ffi::write_default_config();
on_error(status, main_window);
}

// clang-format off
// clang-format off
#if defined (LAZY_DEBUG)
auto q_string_value = QString::fromStdString(config_path);

qDebug() << "Found config path at: " << q_string_value << "\n";
#endif
// clang-format on
// clang-format on
}
4 changes: 2 additions & 2 deletions src/front_end/setting_widget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using Self = SettingWidget;
SettingWidget::SettingWidget() { open_setting = make_unique<QPushButton>(); }

void Self::setup_widget(QGridLayout *grid_layout) {
open_setting->setText("Settings");
open_setting->setText("Settings");

grid_layout->addWidget(open_setting.get(), 0, 1);
grid_layout->addWidget(open_setting.get(), 0, 1);
}
15 changes: 8 additions & 7 deletions src/front_end/table_widget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ using std::make_unique;
using Self = TableWidget;

Self::TableWidget() noexcept {
table_widget = make_unique<QTableWidget>();
header_labels = {"Time", "Content", "Type", "Pinned"};
table_widget = make_unique<QTableWidget>();
header_labels = {"Time", "Content", "Type", "Pinned"};
}

void Self::setup_widget(QGridLayout* grid_layout) {
table_widget->setRowCount(DEFAULT_MAX_ROW);
table_widget->setColumnCount(4);
table_widget->setHorizontalHeaderLabels(header_labels);
table_widget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
table_widget->setRowCount(DEFAULT_MAX_ROW);
table_widget->setColumnCount(4);
table_widget->setHorizontalHeaderLabels(header_labels);
table_widget->horizontalHeader()->setSectionResizeMode(
QHeaderView::Stretch);

grid_layout->addWidget(table_widget.get(), 0, 0);
grid_layout->addWidget(table_widget.get(), 0, 0);
}
9 changes: 5 additions & 4 deletions src/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ using std::make_unique;
using std::unique_ptr;

int main(int argc, char *argv[]) {
unique_ptr<QApplication> application = make_unique<QApplication>(argc, argv);
unique_ptr<MainWindow> main_window = make_unique<MainWindow>();
unique_ptr<QApplication> application =
make_unique<QApplication>(argc, argv);
unique_ptr<MainWindow> main_window = make_unique<MainWindow>();

main_window->init_main_window();
main_window->init_main_window();

return application->exec();
return application->exec();
}
Loading