Browse Source

we can now start working on the next task while a previous one is pending scheduling request
will display a popup on successful scheduling of tasks

logicp 4 years ago
parent
commit
c2a564e36e

+ 3 - 0
include/task/generic_task.hpp

@@ -10,6 +10,9 @@ const QString HEADER_TYPE = "header";
 const QString FILE_TYPE = "files";
 const QString DESCRIPTION_TYPE = "description";
 }  // namespace Args
+
+static constexpr const char* GENERIC_NAME = "Generic";
+
 namespace TaskCode {
 static constexpr int GENTASKBYTE = 0xFC;
 }

+ 2 - 0
include/task/instagram_task.hpp

@@ -16,6 +16,8 @@ const QString REQUESTED_BY_TYPE = "requested_by";
 const QString REQUESTED_BY_PHRASE = "requested_by_phrase";
 }  // namespace Args
 
+static constexpr const char* INSTAGRAM_NAME = "Instagram";
+
 namespace TaskCode {
   static constexpr int IGTASKBYTE = 0xFF;
 }

+ 0 - 2
include/task/task.hpp

@@ -12,8 +12,6 @@ namespace Scheduler {
 
 enum TaskType { INSTAGRAM = 1, GENERIC = 2, OTHER = 3 };
 
-static constexpr const char* INSTAGRAM_NAME = "Instagram";
-
 /**
  * Files
  */

+ 12 - 14
include/ui/argdialog.h

@@ -21,21 +21,18 @@
 
 using namespace Scheduler;
 
-typedef std::string Str;
-
-class KLoader : public QWidget {
- public:
-  KLoader() {
-    QWidget* verticalLayoutWidget = new QWidget();
-    verticalLayoutWidget->setObjectName(QString::fromUtf8("verticalLayoutWidget"));
-    verticalLayoutWidget->setGeometry(QRect(10, 10, 500, 500));
-    QVBoxLayout* verticalLayout = new QVBoxLayout(verticalLayoutWidget);
-    verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
-    verticalLayout->setContentsMargins(0, 0, 0, 0);
-    QLabel* loader_title = new QLabel{"Loading...", this};
-    verticalLayout->addWidget(loader_title);
+inline Task* createTask(QString task_name = GENERIC_NAME) {
+  Task* task;
+  if (task_name == INSTAGRAM_NAME) {
+     task = new InstagramTask{};
+  } else {
+    task = new GenericTask{};
   }
-};
+  task->defineTaskArguments();
+  task->setDefaultValues();
+
+  return task;
+}
 
 namespace Ui {
 class ArgDialog;
@@ -77,6 +74,7 @@ class ArgDialog : public QDialog {
   void addFile(QString path);
 
   Task*         m_task;
+  Task*         m_pending_task;
   QString       m_file_path;
   QJsonObject   m_config;
   QString       m_app_name;

+ 12 - 14
src/argdialog.cpp

@@ -141,6 +141,10 @@ ArgDialog::ArgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ArgDialog),
                        }
                        if (m_task->isReady()) {
                          emit ArgDialog::taskRequestReady(m_task);
+                         m_pending_task = m_task;
+                         m_task = nullptr;
+                         m_task = createTask(m_app_name);
+                         clearPost();
                          displayLoader(true);
                        } else {
                          UI::infoMessageBox("Task is still missing arguments", "Task Verification Error");
@@ -157,15 +161,8 @@ ArgDialog::ArgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ArgDialog),
 
 void ArgDialog::showEvent(QShowEvent* event) {
   if (event->type() == QEvent::Show) {
-    if (m_app_name == Scheduler::INSTAGRAM_NAME) {
-      m_task = new InstagramTask{};
-    } else {
-      m_task = new GenericTask{};
-    }
-
-    if (m_task->isEmpty()) {
-      m_task->defineTaskArguments();
-      m_task->setDefaultValues();
+    if (m_task == nullptr) {
+      m_task = createTask(m_app_name);
     }
 
     ui->argType->clear();
@@ -397,8 +394,6 @@ void ArgDialog::setConfig(QJsonObject config) {
 ArgDialog::~ArgDialog() {
   delete m_task;
   delete m_loader;
-//  delete m_loader_layout;
-//  delete m_loader_widget;
   delete ui;
 }
 
@@ -412,15 +407,19 @@ void ArgDialog::setArgTypes() {
 }
 
 void ArgDialog::notifyClientSuccess() {
-  clearPost();
   displayLoader(false);
+  if (m_pending_task != nullptr) {
+    m_task = m_pending_task;
+    m_pending_task = nullptr;
+  } else {
+    clearPost();
+  }
 }
 
 void ArgDialog::displayLoader(bool visible) {
   if (visible) {
     auto height = 400;
     auto width = 480;
-    this->setWindowOpacity(0.3);
     m_loader_widget.setMaximumSize(width, height);
     m_loader_widget.setMinimumSize(width, height);
     m_loader_widget.show();
@@ -443,6 +442,5 @@ void ArgDialog::displayLoader(bool visible) {
     ui->loaderMovie->setVisible(false);
     ui->loaderText->hide();
     ui->loaderText->setVisible(false);
-    this->setWindowOpacity(1);
   }
 }

+ 1 - 0
src/mainwindow.cpp

@@ -313,6 +313,7 @@ void MainWindow::onMessageReceived(int t, const QString& message, StringVec v) {
     if (isKEvent<QString>(message,
                           Event::TASK_SCHEDULED)) {  // Event was scheduled task
       event_message += ". Details:\n" + parseTaskInfo(v);
+      UI::infoMessageBox(event_message, "Schedule request succeeded");
       arg_ui->notifyClientSuccess(); // Update ArgDialog accordingly
     }
     m_events.push_back(event_message);