Переглянути джерело

dynamically providing argType values through InstagramTask::getArgumentNames()

logicp 4 роки тому
батько
коміт
074860c7f2
4 змінених файлів з 51 додано та 7 видалено
  1. 17 3
      include/task/instagram_task.hpp
  2. 1 0
      include/task/task.hpp
  3. 10 4
      src/argdialog.cpp
  4. 23 0
      src/instagram_task.cpp

+ 17 - 3
include/task/instagram_task.hpp

@@ -9,9 +9,10 @@ namespace Args {
 const QString HEADER_TYPE = "header";
 const QString DESCRIPTION_TYPE = "description";
 const QString HASHTAG_TYPE = "hashtag";
-const QString PROMOTE_TYPE = "promote/share";
-const QString LINK_BIO_TYPE = "link/bio";
-const QString REQUESTED_BY_TYPE = "requested by";
+const QString PROMOTE_TYPE = "promote_share";
+const QString LINK_BIO_TYPE = "link_in_bio";
+const QString REQUESTED_BY_TYPE = "requested_by";
+const QString REQUESTED_BY_PHRASE = "requested_by_phrase";
 }  // namespace Args
 }  // namespace Scheduler
 
@@ -26,36 +27,49 @@ class InstagramTask : public Scheduler::Task {
    * @constructor
    */
   InstagramTask();
+
   /**
    * Overrides @abstract Task::defineTaskArguments
    *
    * Useful for avoiding repetitive input of data.
    */
   virtual void defineTaskArguments() override;
+
   /**
    * Overrides @abstract Task::getTaskArguments
    *
    * Use this method to take over ownership of the task's arguments.
    */
   virtual const Scheduler::TaskArguments&& getTaskArguments() override;
+
   /**
    * Overrides @abstract Task::getTaskArgument
    *
    * Easy access to an argument's value.
    */
   virtual const Scheduler::TypeVariant getTaskArgument(QString name) override;
+
   /**
    * Overrides @abstract Task::getArgumentValues
    *
    * Easy access to all of the arguments that can be represented as a string.
    */
   virtual Scheduler::ArgumentValues getArgumentValues() override;
+
+  /**
+   * Overrides @abstract Task::getArgumentNames
+   *
+   * Provides the names of the arguments.
+   */
+  virtual QVector<QString> getArgumentNames() override;
+
   /**
    * Overrides @abstract Task::getFiles
    *
    * Easy access to the task's files.
    */
   virtual const QVector<Scheduler::KFileData> getFiles() override;
+
   /**
    * Overrides @abstract Task::getType
    *

+ 1 - 0
include/task/task.hpp

@@ -233,6 +233,7 @@ class Task {
   virtual const TaskArguments&& getTaskArguments() = 0;
   virtual const TypeVariant getTaskArgument(QString name) = 0;
   virtual ArgumentValues getArgumentValues() = 0;
+  virtual QVector<QString> getArgumentNames() = 0;
   virtual TaskType getType() = 0;
   virtual void defineTaskArguments() = 0;
   virtual void setDefaultValues() = 0;

+ 10 - 4
src/argdialog.cpp

@@ -19,6 +19,10 @@ ArgDialog::ArgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ArgDialog),
   m_task->defineTaskArguments();
   m_task->setDefaultValues();
 
+  for (const auto& name : m_task->getArgumentNames()) {
+    ui->argType->addItem(name, QVariant::String);
+  }
+
   ui->argCommandButtons->button(QDialogButtonBox::Close)
       ->setStyleSheet(QString("background:%1").arg("#2f535f"));
 
@@ -93,10 +97,6 @@ ArgDialog::ArgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ArgDialog),
 
   QObject::connect(ui->addArgument, &QPushButton::clicked, this, [this]() {
     QString text = ui->argInput->toPlainText();
-    // TODO: argType values need to be set by configuration
-    // Can this somehow be known via the flatbuffer schema? I think not
-    // handling of type needs to be abstracted by a class which can be
-    // subclassed for various types of task: Instagram, etc
     auto type = ui->argType->currentText();
     if (text.size() > 0) {
       if (type == Args::HASHTAG_TYPE) {
@@ -112,6 +112,12 @@ ArgDialog::ArgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ArgDialog),
         m_task->setArgument("link_bio", text);
       } else if (type == Args::REQUESTED_BY_TYPE) {
         addRequestedBy(text);
+      } else if (type == Args::HEADER_TYPE) {
+        addItem(text, type);
+        m_task->setArgument("header", text);
+      } else if (type == Args::REQUESTED_BY_PHRASE) {
+        addItem(text, type);
+        m_task->setArgument("requested_by_phrase", text);
       }
       ui->argInput->clear();
     }

+ 23 - 0
src/instagram_task.cpp

@@ -134,6 +134,29 @@ ArgumentValues InstagramTask::getArgumentValues() {
   return values;
 }
 
+/**
+ * @warning This method does not necessarily need to return all argument names.
+ *          In this use case, we are retrieving names to populate options in our
+ *          ArgType widget, thus we only return names for arguments whose values are
+ *          to be set or modified using the ArgType widget. For this reason, we have
+ *          hardcoded the return to be explicit about which arguments names are available.
+ *
+ * @brief InstagramTask::getArgumentNames
+ *
+ * @return [out] {QVector<QString>} A vector of argument names as strings.
+ */
+QVector<QString> InstagramTask::getArgumentNames() {
+  return QVector<QString>{
+      Scheduler::Args::DESCRIPTION_TYPE,
+      Scheduler::Args::HASHTAG_TYPE,
+      Scheduler::Args::REQUESTED_BY_TYPE,
+      Scheduler::Args::PROMOTE_TYPE,
+      Scheduler::Args::LINK_BIO_TYPE,
+      Scheduler::Args::HEADER_TYPE,
+      Scheduler::Args::REQUESTED_BY_PHRASE
+  };
+}
+
 /**
  * @warning This method is used to claim ownership of the task's arguments. Use of this method will effectively REMOVE all arguments from
  *          the task upon which it is called.