Browse Source

fixed bug: if argdialog task is not null, compare task code to see if it has changed

logicp 4 years ago
parent
commit
fd74114a29

+ 4 - 6
include/client/client.hpp

@@ -24,13 +24,11 @@ static constexpr int COMMANDS_UPDATE_TYPE = 2;
 static constexpr int EVENT_UPDATE_TYPE = 3;
 static constexpr int PROCESS_REQUEST_TYPE = 4;
 
-using namespace Scheduler;
+//using namespace Scheduler;
 
 namespace TaskCode {
-static constexpr int IGTASKBYTE = 0xFF;
-static constexpr int GENMSGBYTE = 0xFE;
-static constexpr int GENTASKBYTE = 0xFC;
-static constexpr int PINGBYTE = 0xFD;
+static constexpr uint32_t GENMSGBYTE = 0xFE;
+static constexpr uint32_t PINGBYTE = 0xFD;
 }  // namespace TaskCode
 
 typedef std::map<int, std::string> CommandMap;
@@ -98,7 +96,7 @@ class Client : public QDialog {
   bool                          executing;
   bool                          file_was_sent;
 
-  Task*                         m_outbound_task;
+  Scheduler::Task*                         m_outbound_task;
   CommandMap                    m_commands;
   CommandArgMap                 m_command_arg_map;
   std::vector<int>              selected_commands;

+ 1 - 1
include/task/generic_task.hpp

@@ -91,7 +91,7 @@ class GenericTask : public Scheduler::Task {
    *
    * Returns the task's byte code.
    */
-  virtual int getTaskCode() override;
+  virtual uint32_t getTaskCode() override;
 
   /**
    * Overrides @abstract Task::setArgument

+ 1 - 1
include/task/instagram_task.hpp

@@ -96,7 +96,7 @@ class InstagramTask : public Scheduler::Task {
    *
    * Returns the task's byte code.
    */
-  virtual int getTaskCode() override;
+  virtual uint32_t getTaskCode() override;
 
   /**
    * Overrides @abstract Task::setArgument

+ 16 - 1
include/task/task.hpp

@@ -7,11 +7,26 @@
 #include <memory>
 #include <variant>
 #include <vector>
+#include <map>
 
 namespace Scheduler {
 
 enum TaskType { INSTAGRAM = 1, GENERIC = 2, OTHER = 3 };
 
+namespace TaskCode {
+static constexpr uint32_t GENTASKCODE = 0xFC;
+static constexpr uint32_t IGTASKCODE = 0xFF;
+}
+
+inline static std::map<std::string, uint32_t> TaskCodes{
+    {"Generic", TaskCode::GENTASKCODE},
+    {"Instagram", TaskCode::IGTASKCODE}
+};
+
+inline static uint32_t findTaskCode(QString key) {
+  return TaskCodes.at(key.toUtf8().constData());
+}
+
 /**
  * Files
  */
@@ -289,7 +304,7 @@ class Task {
   virtual ArgumentValues getArgumentValues() = 0;
   virtual QVector<QString> getArgumentNames() = 0;
   virtual TaskType getType() = 0;
-  virtual int getTaskCode() = 0;
+  virtual uint32_t getTaskCode() = 0;
   virtual void defineTaskArguments() = 0;
   virtual void setDefaultValues() = 0;
   virtual const QVector<KFileData> getFiles() = 0;

+ 1 - 1
src/argdialog.cpp

@@ -159,7 +159,7 @@ ArgDialog::ArgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ArgDialog),
 
 void ArgDialog::showEvent(QShowEvent* event) {
   if (event->type() == QEvent::Show) {
-    if (m_task == nullptr) {
+    if (m_task == nullptr || m_task->getTaskCode() != findTaskCode(m_app_name)) {
       m_task = createTask(m_app_name);
     }
 

+ 2 - 2
src/generic_task.cpp

@@ -205,9 +205,9 @@ Scheduler::TaskType GenericTask::getType() { return Scheduler::TaskType::GENERIC
 /**
  * @brief getTaskCode
  *
- * @return [out] {int} The task bytecode
+ * @return [out] {uint32_t} The task bytecode
  */
-int GenericTask::getTaskCode() { return TaskCode::GENTASKBYTE; };
+uint32_t GenericTask::getTaskCode() { return TaskCode::GENTASKBYTE; };
 
 
 /**

+ 2 - 2
src/instagram_task.cpp

@@ -228,9 +228,9 @@ Scheduler::TaskType InstagramTask::getType() { return Scheduler::TaskType::INSTA
 /**
  * @brief getTaskCode
  *
- * @return [out] {int} The task bytecode
+ * @return [out] {uint32_t} The task bytecode
  */
-int InstagramTask::getTaskCode() { return TaskCode::IGTASKBYTE; };
+uint32_t InstagramTask::getTaskCode() { return TaskCode::IGTASKBYTE; };
 
 /**
  * @brief InstagramTask::clear