Parcourir la source

preliminary work implementing users config and new dropdown in argdialog

logicp il y a 5 ans
Parent
commit
5032d89870
7 fichiers modifiés avec 145 ajouts et 33 suppressions
  1. 51 1
      argdialog.ui
  2. 51 26
      headers/util.hpp
  3. 2 0
      include/argdialog.h
  4. 5 0
      src/argdialog.cpp
  5. 7 6
      src/client.cpp
  6. 1 0
      src/mainwindow.cpp
  7. 28 0
      ui_argdialog.h

+ 51 - 1
argdialog.ui

@@ -52,7 +52,7 @@ color:  rgb(255, 85, 0);
      </widget>
     </item>
     <item>
-     <layout class="QHBoxLayout" name="horizontalLayout">
+     <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0">
       <item>
        <widget class="QLabel" name="label_2">
         <property name="sizePolicy">
@@ -128,6 +128,56 @@ font-weight: 700;
         </item>
        </widget>
       </item>
+      <item>
+       <widget class="QLabel" name="label_6">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+          <horstretch>2</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="minimumSize">
+         <size>
+          <width>196</width>
+          <height>0</height>
+         </size>
+        </property>
+        <property name="maximumSize">
+         <size>
+          <width>196</width>
+          <height>16777215</height>
+         </size>
+        </property>
+        <property name="styleSheet">
+         <string notr="true">font: 75 11pt &quot;Noto Sans&quot;;
+color: rgb(131, 148, 150);
+font-weight: 700;</string>
+        </property>
+        <property name="text">
+         <string>User</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QComboBox" name="user">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="styleSheet">
+         <string notr="true">font: 87 11pt &quot;Noto Sans&quot;;
+background-color: #2f535f;
+color: rgb(131, 148, 150);
+font-weight: 700;
+</string>
+        </property>
+       </widget>
+      </item>
      </layout>
     </item>
     <item>

+ 51 - 26
headers/util.hpp

@@ -9,7 +9,6 @@
 #include <string>
 #include <utility>
 #include <vector>
-#include "json.hpp"
 #include "rapidjson/document.h"
 #include "rapidjson/pointer.h"
 #include "rapidjson/prettywriter.h"
@@ -49,7 +48,6 @@ typedef QQueue<Task> TaskQueue;
 
 namespace {
 using namespace rapidjson;
-using json = nlohmann::json;
 
 typedef std::string KOperation;
 
@@ -244,37 +242,64 @@ QVector<QString> getShortArgs(const char* data) {
 }
 
 QVector<QString> getArgs(const char* data) {
-    Document d;
-    d.Parse(data);
-    QVector<QString> args{};
-    if (d.HasMember("args")) {
-        for (const auto& m : d["args"].GetArray()) {
-            args.push_back(m.GetString());
-        }
+  Document d;
+  d.Parse(data);
+  QVector<QString> args{};
+  if (d.HasMember("args")) {
+    for (const auto& m : d["args"].GetArray()) {
+      args.push_back(m.GetString());
     }
-    return args;
+  }
+  return args;
 }
 
+QList<QString> getValueArgs(const char* data, QString key) {
+  auto key_value = key.toUtf8();
+  Document d;
+  d.Parse(data);
+  QList<QString> args{};
+  for (const auto& m : d.GetObject()) {
+    auto name = m.name.GetString();
+    if (name == key.toUtf8()) {
+      if (m.value.IsArray()) {
+        for (const auto& a : m.value.GetArray()) {
+          args.push_back(a.GetString());
+        }
+      }
+    }
+  }
+  return args;
+}
 
 CommandMap getArgMap(const char* data) {
-    Document d;
-    d.Parse(data);
-    CommandMap cm{};
-    if (d.HasMember("args")) {
-        for (const auto& m : d["args"].GetObject()) {
-            cm.emplace(std::stoi(m.name.GetString()), m.value.GetString());
-        }
+  Document d;
+  d.Parse(data);
+  CommandMap cm{};
+  if (d.HasMember("args")) {
+    for (const auto& m : d["args"].GetObject()) {
+      cm.emplace(std::stoi(m.name.GetString()), m.value.GetString());
     }
-    return cm;
+  }
+  return cm;
 }
 
 ConfigJson getConfigObject(QString json_string) {
     Document d;
     d.Parse(json_string.toUtf8());
+    StringBuffer buffer;
+    Writer<StringBuffer> writer(buffer);
     std::map<QString, QString> config_map{};
     if (d.IsObject()) {
         for (const auto& m : d.GetObject()) {
+          auto type = m.value.GetType();
+          if (m.value.GetType() == kStringType) {
             config_map.emplace(m.name.GetString(), m.value.GetString());
+          }
+          if (m.value.GetType() == kObjectType) {
+            m.value.Accept(writer);
+            QString config_value{buffer.GetString()};
+            config_map.emplace(m.name.GetString(), config_value);
+          }
         }
     }
     return config_map;
@@ -381,14 +406,14 @@ bool serverWaitingForFile(const char* data) {
     return false;
 }
 
-std::string stringTupleVecToJson(
-    std::vector<std::pair<std::string, std::string>> v) {
-    json j{};
-    for (const auto& row : v) {
-        j[row.first] = row.second;
-    }
-    return j;
-}
+// std::string stringTupleVecToJson(
+//    std::vector<std::pair<std::string, std::string>> v) {
+//    json j{};
+//    for (const auto& row : v) {
+//        j[row.first] = row.second;
+//    }
+//    return j;
+//}
 
 inline size_t findNullIndex(uint8_t* data) {
     size_t index = 0;

+ 2 - 0
include/argdialog.h

@@ -60,6 +60,7 @@ class ArgDialog : public QDialog {
   virtual void keyPressEvent(QKeyEvent* e);
   void setFilePath(QString path);
   virtual void accept() override;
+  void setConfig(QString config_string);
 
   ~ArgDialog();
 
@@ -82,6 +83,7 @@ class ArgDialog : public QDialog {
   Task m_task;
   IGPost m_ig_post;
   QString m_file_path;
+  QString m_config_string;
 };
 
 #endif  // ARGDIALOG_H

+ 5 - 0
src/argdialog.cpp

@@ -286,6 +286,11 @@ void ArgDialog::keyPressEvent(QKeyEvent *e) {
 
 void ArgDialog::setFilePath(QString path) { m_file_path = path; }
 
+void ArgDialog::setConfig(QString config_string) {
+  m_config_string = config_string;
+  ui->user->addItems(getValueArgs(m_config_string.toUtf8(), "users"));
+}
+
 ArgDialog::~ArgDialog()
 {
     delete ui;

+ 7 - 6
src/client.cpp

@@ -1,18 +1,19 @@
-#include <include/client.hpp>
-#include <arpa/inet.h>
+#include <arpa/inet.h>
+#include <math.h>
 #include <netdb.h>
 #include <string.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <functional>
+#include <QByteArray>
+#include <QDebug>
 #include <algorithm>
 #include <cstring>
-#include <QDebug>
-#include <QByteArray>
+#include <functional>
+#include <future>
+#include <include/client.hpp>
 #include <iostream>
 #include <vector>
-#include <future>
 #define FLATBUFFERS_DEBUG_VERIFICATION_FAILURE
 #include <headers/kmessage_codec.hpp>
 #include <headers/instatask_generated.h>

+ 1 - 0
src/mainwindow.cpp

@@ -274,6 +274,7 @@ void MainWindow::updateMessages(int t, const QString& message, StringVec v) {
     }
     if (message == "New Session") {
       ui->led->setState(true);
+      arg_ui->setConfig(configValue("instagram", m_config));
       if (configBoolValue("schedulerMode", std::ref(m_config))) {
         arg_ui->show();
       }

+ 28 - 0
ui_argdialog.h

@@ -36,6 +36,8 @@ public:
     QHBoxLayout *horizontalLayout;
     QLabel *label_2;
     QComboBox *argType;
+    QLabel *label_6;
+    QComboBox *user;
     QHBoxLayout *horizontalLayout_2;
     QLabel *label_3;
     QTextEdit *argInput;
@@ -121,6 +123,31 @@ public:
 
         horizontalLayout->addWidget(argType);
 
+        label_6 = new QLabel(verticalLayoutWidget);
+        label_6->setObjectName(QString::fromUtf8("label_6"));
+        sizePolicy.setHeightForWidth(label_6->sizePolicy().hasHeightForWidth());
+        label_6->setSizePolicy(sizePolicy);
+        label_6->setMinimumSize(QSize(196, 0));
+        label_6->setMaximumSize(QSize(196, 16777215));
+        label_6->setStyleSheet(QString::fromUtf8("font: 75 11pt \"Noto Sans\";\n"
+"color: rgb(131, 148, 150);\n"
+"font-weight: 700;"));
+        label_6->setAlignment(Qt::AlignCenter);
+
+        horizontalLayout->addWidget(label_6);
+
+        user = new QComboBox(verticalLayoutWidget);
+        user->setObjectName(QString::fromUtf8("user"));
+        sizePolicy1.setHeightForWidth(user->sizePolicy().hasHeightForWidth());
+        user->setSizePolicy(sizePolicy1);
+        user->setStyleSheet(QString::fromUtf8("font: 87 11pt \"Noto Sans\";\n"
+"background-color: #2f535f;\n"
+"color: rgb(131, 148, 150);\n"
+"font-weight: 700;\n"
+""));
+
+        horizontalLayout->addWidget(user);
+
 
         verticalLayout->addLayout(horizontalLayout);
 
@@ -368,6 +395,7 @@ public:
         argType->setItemText(3, QCoreApplication::translate("ArgDialog", "promote/share", nullptr));
         argType->setItemText(4, QCoreApplication::translate("ArgDialog", "link/bio", nullptr));
 
+        label_6->setText(QCoreApplication::translate("ArgDialog", "User", nullptr));
         label_3->setText(QCoreApplication::translate("ArgDialog", "Input", nullptr));
         addArgument->setText(QCoreApplication::translate("ArgDialog", "Add", nullptr));
         label_4->setText(QCoreApplication::translate("ArgDialog", "Add file attachment", nullptr));