Browse Source

task arguments will not be replaced upon reopening an argdialog. defaults are only set if the task is empty
added new "isEmpty()" interface to Task (parent class)
cleaned up private args alignment in several classes

logicp 4 years ago
parent
commit
a29d96f995
5 changed files with 63 additions and 39 deletions
  1. 14 12
      include/client/client.hpp
  2. 23 5
      include/task/task.hpp
  3. 5 4
      include/ui/argdialog.h
  4. 16 16
      include/ui/mainwindow.h
  5. 5 2
      src/argdialog.cpp

+ 14 - 12
include/client/client.hpp

@@ -91,17 +91,19 @@ class Client : public QDialog {
   void handleMessages();
   void handleEvent(std::string data);
   void sendPackets(uint8_t* data, int size);
-  int argc;
-  char** argv;
-  int m_client_socket_fd;
-  Task* m_outbound_task;
-  bool executing;
-  bool file_was_sent;
-  CommandMap m_commands;
-  CommandArgMap m_command_arg_map;
-  std::vector<int> selected_commands;
-  QQueue<Scheduler::KFileData> outgoing_files;
-  std::vector<SentFile> sent_files;
-  Scheduler::TaskQueue m_task_queue;
+
+  int                           argc;
+  char**                        argv;
+  int                           m_client_socket_fd;
+  bool                          executing;
+  bool                          file_was_sent;
+
+  Task*                         m_outbound_task;
+  CommandMap                    m_commands;
+  CommandArgMap                 m_command_arg_map;
+  std::vector<int>              selected_commands;
+  std::vector<SentFile>         sent_files;
+  Scheduler::TaskQueue          m_task_queue;
+  QQueue<Scheduler::KFileData>  outgoing_files;
 };
 #endif // CLIENT_HPP

+ 23 - 5
include/task/task.hpp

@@ -29,6 +29,12 @@ struct KFileData {
   FileType type;
   QString path;
   QByteArray bytes;
+
+//  friend std::ostream &operator<<(std::ostream &out, const KFileData& file) {
+//    out << "Name: " << file.name.toUtf8()
+//        << "\nType: " << file.type;
+//    return out;
+//  }
 };
 
 /**
@@ -65,11 +71,13 @@ class Task;
 /**
  * Aliases
  */
-using TaskQueue = QQueue<Task*>;
-using ArgumentType = const char*;
-using ArgumentValues = QVector<QString>;
-using TypeVariant = std::variant<bool, int, QVector<QString>, QString, QVector<KFileData>>;
-using TaskIterator = std::vector<TaskArgumentBase*>::iterator;
+using TaskQueue       = QQueue<Task*>;
+using ArgumentType    = const char*;
+using ArgumentValues  = QVector<QString>;
+using TypeVariant     = std::variant<
+                          bool, int, QVector<QString>, QString, QVector<KFileData>
+                        >;
+using TaskIterator    = std::vector<TaskArgumentBase*>::iterator;
 
 /**
  * The interface expected on our Task Arguments
@@ -289,6 +297,16 @@ class Task {
   virtual const QVector<KFileData> getFiles() = 0;
   virtual bool hasFiles() = 0;
   virtual bool isReady() = 0;
+  virtual bool isEmpty() {
+    bool empty = true;
+    for (const auto& arg : getArgumentValues()) {
+      if (!arg.isEmpty()) {
+        empty = false;
+      }
+    }
+    return empty;
+  }
+
   virtual void clear() = 0;
   virtual ~Task(){};
 };

+ 5 - 4
include/ui/argdialog.h

@@ -56,10 +56,11 @@ class ArgDialog : public QDialog {
   Ui::ArgDialog *ui;
   void addItem(QString value, QString type);
   void addFile(QString path);
-  Task *m_task;
-  QString m_file_path;
-  QJsonObject m_config;
-  QString m_app_name;
+
+  Task*         m_task;
+  QString       m_file_path;
+  QJsonObject   m_config;
+  QString       m_app_name;
 };
 
 #endif  // ARGDIALOG_H

+ 16 - 16
include/ui/mainwindow.h

@@ -71,30 +71,30 @@ public:
       MainWindow* window;
     };
 
-    /** Process arguments */
-    int cli_argc;
-    char** cli_argv;
     /** UI & Messages */
     void connectUi();
     void setConnectScreen(bool visible = true);
-
     QString parseTaskInfo(StringVec v);
+
+    /** Process arguments */
+    int                   cli_argc;
+    char**                cli_argv;
     /** UI Members */
-    MessageParser message_parser;
-    Ui::MainWindow *ui;
-    ArgDialog *arg_ui;
-    MessageDialog message_ui;
+    MessageParser         message_parser;
+    Ui::MainWindow*       ui;
+    ArgDialog*            arg_ui;
+    MessageDialog         message_ui;
     /** Client member */
-    Client* q_client;
+    Client*               q_client;
     /** Models */
-    std::vector<Process> m_processes;
-    QList<QString> m_events;
-    QStandardItemModel* m_process_model;
-    QStandardItemModel* m_event_model;
-    KListViewsStates m_view_states;
+    std::vector<Process>  m_processes;
+    QList<QString>        m_events;
+    QStandardItemModel*   m_process_model;
+    QStandardItemModel*   m_event_model;
+    KListViewsStates      m_view_states;
     /** Misc */
-    QJsonObject m_config;
-    uint16_t m_consecutive_events;
+    QJsonObject           m_config;
+    uint16_t              m_consecutive_events;
 
    private slots:
     /** Receivers */

+ 5 - 2
src/argdialog.cpp

@@ -154,8 +154,11 @@ void ArgDialog::showEvent(QShowEvent* event) {
     } else {
       m_task = new GenericTask{};
     }
-    m_task->defineTaskArguments();
-    m_task->setDefaultValues();
+
+    if (m_task->isEmpty()) {
+      m_task->defineTaskArguments();
+      m_task->setDefaultValues();
+    }
 
     ui->argType->clear();