Pārlūkot izejas kodu

fixing removal of files

logicp 4 gadi atpakaļ
vecāks
revīzija
620067f097
3 mainītis faili ar 13 papildinājumiem un 22 dzēšanām
  1. 1 0
      include/task/instagram_task.hpp
  2. 5 5
      include/task/task.hpp
  3. 7 17
      src/argdialog.cpp

+ 1 - 0
include/task/instagram_task.hpp

@@ -7,6 +7,7 @@
 namespace Scheduler {
 namespace Args {
 const QString HEADER_TYPE = "header";
+const QString FILE_TYPE = "files";
 const QString DESCRIPTION_TYPE = "description";
 const QString HASHTAG_TYPE = "hashtags";
 const QString PROMOTE_TYPE = "promote_share";

+ 5 - 5
include/task/task.hpp

@@ -232,11 +232,11 @@ class TaskArgument : TaskArgumentBase {
       } else {
         throw std::out_of_range("Could not find value requested for removal");
       }
-    } else if (value.index() == VariantIndex::STRVEC && unwanted_value.index() == VariantIndex::FILEVEC) {
-      auto&& container = std::get<VariantIndex::STRVEC>(value);
-      auto value_to_remove = std::get<VariantIndex::QSTRING>(unwanted_value);
-      auto it = std::find_if(container.begin(), container.end(), [&value_to_remove](QString s) {
-        return (s == value_to_remove);
+    } else if (value.index() == VariantIndex::FILEVEC && unwanted_value.index() == VariantIndex::QSTRING) {
+      auto&& container = std::get<VariantIndex::FILEVEC>(value);
+      auto file_to_remove = std::get<VariantIndex::QSTRING>(unwanted_value);
+      auto it = std::find_if(container.begin(), container.end(), [&file_to_remove](Scheduler::KFileData f) {
+        return (f.name == file_to_remove);
       });
       if (it != container.end()) {
         container.erase(it);

+ 7 - 17
src/argdialog.cpp

@@ -183,30 +183,20 @@ void ArgDialog::addItem(QString value, QString type) {
   QPushButton *q_pb = new QPushButton();
   q_pb->setText("Delete");
   q_pb->setIcon(std::move(QIcon(":/icons/icons/quit.png")));
+  // Set listener on Delete button
   QObject::connect(q_pb, &QPushButton::clicked, this, [this]() {
     auto row_index = ui->argList->currentRow();
-    // If deleted item is a file, we need to remove it from the task
     auto name = ui->argList->item(row_index, 0)->text();
+    if (name == "file") { // UI displays files as type "file", but the argument is named "files"
+      name = Args::FILE_TYPE;
+    }
     auto value = ui->argList->item(row_index, 1)->text();
-    if (name == "file") {
-      if (!value.isEmpty()) {
-        // All of the following should be done by the task
-        QVector<Scheduler::KFileData> task_files = std::get<VariantIndex::FILEVEC>(m_task->getTaskArgumentValue("files"));
-        auto file_it = std::find_if(task_files.begin(), task_files.end(),
-                                    [value](const Scheduler::KFileData &file) { return file.name == value; });
-        if (file_it != task_files.end()) {  // If file was matched
-          qDebug() << "Removing file from task arguments";
-          task_files.erase(file_it);
-          m_task->setArgument("files", task_files); // Probably not necessary. Try without doing this
-        }
-      }
-    } else {
-      for (auto&& s : value.split("\n")) { // If there are multiple values, they are separated by line breaks
-        m_task->removeArgument(name, s);
-      }
+    for (auto&& s : value.split("\n")) { // If there are multiple values, they are separated by line breaks
+      m_task->removeArgument(name, s);
     }
     ui->argList->removeRow(row_index);
   });
+
   ui->argList->setItem(row, 0, item);
   ui->argList->setItem(row, 1, item2);
   ui->argList->setCellWidget(row, 3, q_pb);