Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <string>
  2. #pragma once
  3. #include <algorithm>
  4. #include <vector>
  5. #include <utility>
  6. #pragma once
  7.  
  8. #include <tuple>
  9. #include <cmath>
  10. #include "utils.hpp"
  11. #include "AbstractView.hpp"
  12. #include <fstream>
  13. #include <iostream>
  14. #include <chrono>
  15. #include <ctime>
  16. #include <gtk/gtk.h>
  17.  
  18. using std::string;
  19. using std::cout;
  20. using std::endl;
  21. using std::cerr;
  22. using std::get;
  23. using std::min;
  24. using std::max;
  25. using std::vector;
  26. using std::pair;
  27. using std::tuple;
  28.  
  29. class GtkImageTextView : public AbstractView {
  30. public:
  31.     GtkImageTextView(){}
  32.  
  33.     void SetTextWidget(GtkWidget *text) {
  34.         text_ = text;
  35.     }
  36.  
  37.     void ApplyNotification(const AbstractNotification& notification) {
  38.  
  39.         if (notification.GetType() == AbstractNotification::GetNotificationType<string>()) {
  40.             auto end = std::chrono::system_clock::now();
  41.             std::time_t end_time = std::chrono::system_clock::to_time_t(end);
  42.             auto string_view_date = string(std::ctime(&end_time));
  43.             string appended = string(std::ctime(&end_time)).substr(0, (int)string_view_date.size() - 1) + "\t" + notification.GetMessage();
  44.             AppendText(text_, appended);
  45.         }
  46.     }
  47.  
  48.     static void AppendText(GtkWidget* text, string append_text) {
  49.         string new_text = string(gtk_label_get_text(GTK_LABEL(text))) + "\n" + append_text;
  50.         {
  51.             gchar* string_for_gtk = new gchar[new_text.size() + 1];
  52.             strcpy(string_for_gtk, new_text.c_str());
  53.             gtk_label_set_text(GTK_LABEL(text), string_for_gtk);
  54.             delete[](string_for_gtk);
  55.         }
  56.     }
  57.    
  58.     virtual ~GtkImageTextView() {
  59.     }
  60.  
  61. private:
  62.     GtkWidget* text_;
  63. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement