Browse Source

sets task frequency for generic tasks

logicp 4 years ago
parent
commit
3d89c146b8
7 changed files with 126 additions and 13 deletions
  1. 78 3
      argdialog.ui
  2. 1 0
      headers/generictask.fbs
  3. 16 4
      headers/generictask_generated.h
  4. 16 2
      include/task/task.hpp
  5. 12 4
      src/argdialog.cpp
  6. 1 0
      src/client.cpp
  7. 2 0
      src/generic_task.cpp

+ 78 - 3
argdialog.ui

@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>970</width>
-    <height>864</height>
+    <height>904</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -27,10 +27,10 @@ background-color: rgb(0, 43, 54);</string>
      <x>10</x>
      <y>10</y>
      <width>948</width>
-     <height>851</height>
+     <height>891</height>
     </rect>
    </property>
-   <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0,0,0,0,3,0">
+   <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0,0,0,0,0,3,0">
     <item>
      <widget class="QLabel" name="argDialogTitle">
       <property name="font">
@@ -358,6 +358,81 @@ font-size: 16pt;</string>
       </item>
      </layout>
     </item>
+    <item>
+     <layout class="QHBoxLayout" name="horizontalLayout_7">
+      <item>
+       <widget class="QLabel" name="recurringLabel">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="minimumSize">
+         <size>
+          <width>196</width>
+          <height>0</height>
+         </size>
+        </property>
+        <property name="maximumSize">
+         <size>
+          <width>196</width>
+          <height>16777215</height>
+         </size>
+        </property>
+        <property name="styleSheet">
+         <string notr="true">font: 75 11pt &quot;Noto Sans&quot;;
+color: rgb(131, 148, 150);
+font-weight: 700;
+ qproperty-alignment: 'AlignHCenter';</string>
+        </property>
+        <property name="text">
+         <string>Recurring</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignHCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QComboBox" name="recurring">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="styleSheet">
+         <string notr="true">font: 87 11pt &quot;Noto Sans&quot;;
+background-color: #2f535f;
+color: rgb(131, 148, 150);
+font-weight: 700;
+</string>
+        </property>
+        <item>
+         <property name="text">
+          <string>No</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Hourly</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Daily</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Weekly</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+     </layout>
+    </item>
     <item>
      <widget class="QLabel" name="label">
       <property name="styleSheet">

+ 1 - 0
headers/generictask.fbs

@@ -9,6 +9,7 @@ table GenericTask {
   mask: int;
   header: string;
   user: string;
+  recurring: int;
 }
 
 root_type GenericTask;

+ 16 - 4
headers/generictask_generated.h

@@ -21,7 +21,8 @@ struct GenericTask FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
     VT_IS_VIDEO = 12,
     VT_MASK = 14,
     VT_HEADER = 16,
-    VT_USER = 18
+    VT_USER = 18,
+    VT_RECURRING = 20
   };
   int32_t id() const {
     return GetField<int32_t>(VT_ID, 0);
@@ -47,6 +48,9 @@ struct GenericTask FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
   const flatbuffers::String *user() const {
     return GetPointer<const flatbuffers::String *>(VT_USER);
   }
+  int32_t recurring() const {
+    return GetField<int32_t>(VT_RECURRING, 0);
+  }
   bool Verify(flatbuffers::Verifier &verifier) const {
     return VerifyTableStart(verifier) &&
            VerifyField<int32_t>(verifier, VT_ID) &&
@@ -62,6 +66,7 @@ struct GenericTask FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
            verifier.VerifyString(header()) &&
            VerifyOffset(verifier, VT_USER) &&
            verifier.VerifyString(user()) &&
+           VerifyField<int32_t>(verifier, VT_RECURRING) &&
            verifier.EndTable();
   }
 };
@@ -94,6 +99,9 @@ struct GenericTaskBuilder {
   void add_user(flatbuffers::Offset<flatbuffers::String> user) {
     fbb_.AddOffset(GenericTask::VT_USER, user);
   }
+  void add_recurring(int32_t recurring) {
+    fbb_.AddElement<int32_t>(GenericTask::VT_RECURRING, recurring, 0);
+  }
   explicit GenericTaskBuilder(flatbuffers::FlatBufferBuilder &_fbb)
         : fbb_(_fbb) {
     start_ = fbb_.StartTable();
@@ -115,8 +123,10 @@ inline flatbuffers::Offset<GenericTask> CreateGenericTask(
     bool is_video = false,
     int32_t mask = 0,
     flatbuffers::Offset<flatbuffers::String> header = 0,
-    flatbuffers::Offset<flatbuffers::String> user = 0) {
+    flatbuffers::Offset<flatbuffers::String> user = 0,
+    int32_t recurring = 0) {
   GenericTaskBuilder builder_(_fbb);
+  builder_.add_recurring(recurring);
   builder_.add_user(user);
   builder_.add_header(header);
   builder_.add_mask(mask);
@@ -137,7 +147,8 @@ inline flatbuffers::Offset<GenericTask> CreateGenericTaskDirect(
     bool is_video = false,
     int32_t mask = 0,
     const char *header = nullptr,
-    const char *user = nullptr) {
+    const char *user = nullptr,
+    int32_t recurring = 0) {
   auto file_info__ = file_info ? _fbb.CreateString(file_info) : 0;
   auto time__ = time ? _fbb.CreateString(time) : 0;
   auto description__ = description ? _fbb.CreateString(description) : 0;
@@ -152,7 +163,8 @@ inline flatbuffers::Offset<GenericTask> CreateGenericTaskDirect(
       is_video,
       mask,
       header__,
-      user__);
+      user__,
+      recurring);
 }
 
 inline const GenericData::GenericTask *GetGenericTask(const void *buf) {

+ 16 - 2
include/task/task.hpp

@@ -27,11 +27,18 @@ static constexpr uint32_t ENVFILE = 0x03;
 static constexpr uint32_t FILENUM = 0x04;
 } // namespace TaskInfo
 
-inline static std::map<std::string, uint32_t> TaskCodes{
-    {"Generic", TaskCode::GENTASKCODE},
+inline static const std::map<std::string, uint32_t> TaskCodes{
+    {"Generic",   TaskCode::GENTASKCODE},
     {"Instagram", TaskCode::IGTASKCODE}
 };
 
+inline static const std::map<std::string, uint32_t> TaskFrequency{
+    {"No",      0x00},
+    {"Hourly",  0x01},
+    {"Daily",   0x02},
+    {"Weekly",  0x03}
+};
+
 inline static uint32_t findTaskCode(QString key) {
   auto it = TaskCodes.find(key.toUtf8().constData());
   return it == TaskCodes.end() ?
@@ -39,6 +46,13 @@ inline static uint32_t findTaskCode(QString key) {
     (*it).second;
 }
 
+inline static int findTaskFrequency(const QString& key) {
+  auto it = TaskFrequency.find(key.toUtf8().constData());
+  return it == TaskFrequency.end() ?
+    TaskCodes.at("No") :
+    (*it).second;
+}
+
 /**
  * Files
  */

+ 12 - 4
src/argdialog.cpp

@@ -155,6 +155,14 @@ ArgDialog::ArgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ArgDialog),
     ui->argList->setRowCount(0);
     qDebug() << "Task cleared and restored to default values";
   });
+
+  QObject::connect(ui->recurring, &QComboBox::currentTextChanged, this, [this](const QString& text) {
+    if (m_task->getType() == Scheduler::TaskType::GENERIC) {
+      m_task->setArgument("recurring", findTaskFrequency(text));
+    }
+  });
+
+
 }
 
 void ArgDialog::showEvent(QShowEvent* event) {
@@ -204,14 +212,15 @@ void ArgDialog::setTaskArguments() {
  * @param type
  */
 void ArgDialog::addItem(QString value, QString type) {
+  auto row = ui->argList->rowCount(); // insert row
+  ui->argList->insertRow(row);
+  // Create UI elements
   QTableWidgetItem *item = new QTableWidgetItem(type);
   QTableWidgetItem *item2 = new QTableWidgetItem(value);
-  auto row = ui->argList->rowCount();
-  ui->argList->insertRow(row);
   QPushButton *q_pb = new QPushButton();
   q_pb->setText("Delete");
   q_pb->setIcon(std::move(QIcon(":/icons/icons/quit.png")));
-  // Set listener on Delete button
+  // Delete listener
   QObject::connect(q_pb, &QPushButton::clicked, this, [this]() {
     auto row_index = ui->argList->currentRow();
     auto name = ui->argList->item(row_index, 0)->text();
@@ -224,7 +233,6 @@ void ArgDialog::addItem(QString value, QString type) {
     }
     ui->argList->removeRow(row_index);
   });
-
   ui->argList->setItem(row, 0, item);
   ui->argList->setItem(row, 1, item2);
   ui->argList->setCellWidget(row, 3, q_pb);

+ 1 - 0
src/client.cpp

@@ -306,6 +306,7 @@ void Client::sendTaskEncoded(Scheduler::Task* task) {
               task->getTaskArgumentValue("header")).toUtf8().constData()}),
             builder.CreateString(std::string{std::get<Scheduler::VariantIndex::QSTRING>(
               task->getTaskArgumentValue("user")).toUtf8().constData()}));
+              task->getTaskArgumentValue("recurring");
     builder.Finish(generic_task);
   }
 

+ 2 - 0
src/generic_task.cpp

@@ -12,6 +12,7 @@ static const uint8_t DATETIME = 2;
 static const uint8_t FILES = 3;
 static const uint8_t USER = 4;
 static const uint8_t IS_VIDEO = 5;
+static const uint8_t RECURRING = 6;
 }  // namespace TaskIndex
 
 /**
@@ -33,6 +34,7 @@ void GenericTask::defineTaskArguments() {
   m_arguments.emplace_back(std::move(new TaskArgument{"files", Type::FILEVECTOR, QVector<KFileData>{}}));
   m_arguments.emplace_back(std::move(new TaskArgument{"user", Type::TEXT, QString{}}));
   m_arguments.emplace_back(std::move(new TaskArgument{"is_video", Type::BOOLEAN, bool{}}));
+  m_arguments.emplace_back(std::move(new TaskArgument{"recurring", Type::INTEGER, findTaskFrequency("No")}));
 }
 
 /**