main.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "BoardListModel.h"
  2. #include "ThreadCatalogModel.h"
  3. #include <LibDraw/PNGLoader.h>
  4. #include <LibGUI/GApplication.h>
  5. #include <LibGUI/GBoxLayout.h>
  6. #include <LibGUI/GComboBox.h>
  7. #include <LibGUI/GStatusBar.h>
  8. #include <LibGUI/GTableView.h>
  9. #include <LibGUI/GWindow.h>
  10. int main(int argc, char** argv)
  11. {
  12. GApplication app(argc, argv);
  13. auto* window = new GWindow;
  14. window->set_title("ChanViewer");
  15. window->set_rect(100, 100, 800, 500);
  16. window->set_icon(load_png("/res/icons/16x16/app-chanviewer.png"));
  17. auto* widget = new GWidget;
  18. window->set_main_widget(widget);
  19. widget->set_fill_with_background_color(true);
  20. widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
  21. auto* board_combo = new GComboBox(widget);
  22. board_combo->set_only_allow_values_from_model(true);
  23. board_combo->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
  24. board_combo->set_preferred_size(0, 20);
  25. board_combo->set_model(BoardListModel::create());
  26. auto catalog_view = GTableView::construct(widget);
  27. catalog_view->set_model(ThreadCatalogModel::create());
  28. auto& catalog_model = *static_cast<ThreadCatalogModel*>(catalog_view->model());
  29. auto* statusbar = new GStatusBar(widget);
  30. board_combo->on_change = [&] (auto&, const GModelIndex& index) {
  31. auto selected_board = board_combo->model()->data(index, GModel::Role::Custom);
  32. ASSERT(selected_board.is_string());
  33. catalog_model.set_board(selected_board.to_string());
  34. };
  35. catalog_model.on_load_started = [&] {
  36. statusbar->set_text(String::format("Loading /%s/...", catalog_model.board().characters()));
  37. };
  38. catalog_model.on_load_finished = [&](bool success) {
  39. statusbar->set_text(success ? "Load finished" : "Load failed");
  40. if (success) {
  41. window->set_title(String::format("/%s/ - ChanViewer", catalog_model.board().characters()));
  42. }
  43. };
  44. window->show();
  45. return app.exec();
  46. }