Blame view

app/gui/oven_control/cookbook.cpp 2.63 KB
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  #include "cookbook.h"
  
  #include <QApplication>
  #include <QErrorMessage>
  
  static QErrorMessage *errorDialog = NULL;
  static void showError(QString errorMessage)
  {
      if (errorDialog == NULL)
      {
          errorDialog = new QErrorMessage;
          errorDialog->setWindowModality(Qt::ApplicationModal);
          errorDialog->setGeometry(QRect(0, 426, 900, 426));
      }
  
      errorDialog->showMessage(errorMessage);
      errorDialog->exec();
  }
  
  CookBook::CookBook(Define::CookType type)
      : type(type)
  {
      switch (type)
      {
      case Define::Poultry:
          root = QString("/prime/cookbook/poultry/");
          break;
      case Define::Meat:
          root = QString("/prime/cookbook/meat/");
          break;
      case Define::Fish:
          root = QString("/prime/cookbook/fish/");
          break;
      case Define::Desert:
          root = QString("/prime/cookbook/desert/");
          break;
      case Define::Vegetable:
          root = QString("/prime/cookbook/vegetable/");
          break;
      case Define::Bread:
          root = QString("/prime/cookbook/bread/");
          break;
      case Define::Etc:
          root = QString("/prime/cookbook/etc/");
          break;
      default:
          return;
      }
  
      QFile file(root + "list.csv");
      if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
      {
          showError("File not found: " + file.fileName());
          return;
      }
  
      int lineCount = 0;
      while (!file.atEnd())
      {
          lineCount++;
  
          QString line = QString::fromUtf8(file.readLine()).trimmed();
          if (line.isEmpty())
              continue;
  
          if (line.startsWith("directory"))
              continue;
  
          QString errorMessage = QString("%3: %1, line %2").arg(file.fileName()).arg(lineCount);
  
          QString directory = line.section(',', 0, 0).trimmed();
          if (directory.isEmpty())
          {
              showError(errorMessage.arg("Directory name is missed"));
              continue;
          }
  
          QString cookname = line.section(',', 1, 1).trimmed();
          if (cookname.isEmpty())
          {
              showError(errorMessage.arg("Cook name is missed"));
              continue;
          }
  
          list.append(cookname);
          book.append(ListEntity { directory, cookname });
      }
  
      file.close();
  }
  
  Cook CookBook::get(int index)
  {
      if (index < book.size())
      {
          ListEntity e = book.at(index);
          return Cook(type, root + e.directory, e.name);
      }
  
      return Cook();
  }
f588aa273   김태훈   부가 기능 로직 추가
102
103
104
105
106
107
108
109
110
111
112
  QString CookBook::name(QString root)
  {
      QString directory = root.replace(this->root, "").replace("/", "").trimmed();
      foreach (ListEntity e, book)
      {
          if (e.directory == directory)
              return e.name;
      }
  
      return QString();
  }