editor.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include <string>
  2. #include <gtkmm/grid.h>
  3. #include <gtkmm/entry.h>
  4. #include <gtkmm/label.h>
  5. #include <gtkmm/button.h>
  6. #include "editor.hpp"
  7. #include "light.hpp"
  8. #include "config.hpp"
  9. namespace cx_light {
  10. editor::editor(light *target) {
  11. this->target = target->copy();
  12. this->set_row_spacing(DEFAULT_MARGIN);
  13. this->set_column_spacing(DEFAULT_MARGIN);
  14. std::string description_text = "<b>Edit \"";
  15. description_text += target->get_name();
  16. description_text += "\" light.</b>";
  17. this->description = new Gtk::Label(description_text);
  18. this->description->set_use_markup();
  19. this->description->set_hexpand();
  20. this->description->set_halign(Gtk::Align::START);
  21. this->attach(*this->description, 0, 0, 4, 1);
  22. this->title_label = new Gtk::Label("Title");
  23. this->title_label->set_halign(Gtk::Align::START);
  24. this->attach(*this->title_label, 0, 1, 1, 1);
  25. this->title = new Gtk::Entry();
  26. this->attach(*this->title, 1, 1, 3, 1);
  27. this->address_label = new Gtk::Label("Address");
  28. this->address_label->set_halign(Gtk::Align::START);
  29. this->attach(*this->address_label, 0, 2, 1, 1);
  30. this->address = new Gtk::Entry();
  31. this->attach(*this->address, 1, 2, 3, 1);
  32. this->back = new Gtk::Button("Back");
  33. this->attach(*this->back, 0, 3, 2, 1);
  34. this->save = new Gtk::Button("Save");
  35. this->attach(*this->save, 2, 3, 2, 1);
  36. }
  37. editor::~editor() {
  38. this->remove(*this->save);
  39. this->remove(*this->back);
  40. this->remove(*this->title);
  41. this->remove(*this->address);
  42. this->remove(*this->description);
  43. this->remove(*this->title_label);
  44. this->remove(*this->address_label);
  45. delete this->target;
  46. delete this->save;
  47. delete this->back;
  48. delete this->title;
  49. delete this->address;
  50. delete this->description;
  51. delete this->title_label;
  52. delete this->address_label;
  53. }
  54. std::string editor::get_title() {
  55. std::string current = this->title->get_buffer()->get_text();
  56. if (current.empty()) {
  57. return this->target->get_name();
  58. }
  59. return current;
  60. }
  61. std::string editor::get_address() {
  62. std::string current = this->address->get_buffer()->get_text();
  63. if (current.empty()) {
  64. return this->target->get_address();
  65. }
  66. return current;
  67. }
  68. }