Browse Source

major work to argdialog - layout changes and new arg types. Logic to update rows accordingly and append for the right types

logicp 5 years ago
parent
commit
89d202839b
7 changed files with 142 additions and 56 deletions
  1. 63 8
      argdialog.cpp
  2. 56 39
      argdialog.h
  3. 23 9
      argdialog.ui
  4. BIN
      icons/disconnect.png
  5. BIN
      icons/log.png
  6. BIN
      icons/send-button.png
  7. BIN
      icons/start.png

+ 63 - 8
argdialog.cpp

@@ -28,14 +28,14 @@ ArgDialog::ArgDialog(QWidget *parent) :
 //                QByteArray bytes = file.readAll();
 //                emit ArgDialog::uploadFile(bytes);
 //            }
-        }
-        auto slash_index = file_path.lastIndexOf("/") + 1;
-        QString file_name = file_path.right(file_path.size() - slash_index);
+            auto slash_index = file_path.lastIndexOf("/") + 1;
+            QString file_name = file_path.right(file_path.size() - slash_index);
 
-        addItem(file_name, "file");
+            addItem(file_name, "file");
 
-        m_ig_post.video.name = file_name.toUtf8().constData();
-        m_ig_post.video.path = file_path.toUtf8().constData();
+            m_ig_post.video.name = file_name.toUtf8().constData();
+            m_ig_post.video.path = file_path.toUtf8().constData();
+        }
     });
 
     ui->argList->setHorizontalHeaderLabels(QStringList{"Value", "Type"});
@@ -48,11 +48,19 @@ ArgDialog::ArgDialog(QWidget *parent) :
         QList<QListWidgetItem*> types = ui->argType->selectedItems();
         auto type = types.size() > 0 ? types.at(0)->text() : "Unknown type";
         if (text.size() > 0) {
-            addItem(text, type);
             if (type == Args::HASHTAG_TYPE) {
                 addHashtag(text);
             } else if (type == Args::DESCRIPTION_TYPE) {
+                addItem(text, type);
                 m_ig_post.description = text.toUtf8().constData();
+            } else if (type == Args::PROMOTE_TYPE) {
+                addOrReplaceInArgList(text, "promote/share");
+                m_ig_post.promote_share = text.toUtf8().constData();
+            } else if (type == Args::LINK_BIO_TYPE) {
+                addOrReplaceInArgList(text, "link/bio");
+                m_ig_post.link_in_bio = text.toUtf8().constData();
+            } else if (type == Args::REQUESTED_BY_TYPE) {
+                addRequestedBy(text);
             }
             ui->argInput->clear();
         }
@@ -67,6 +75,8 @@ ArgDialog::ArgDialog(QWidget *parent) :
         auto date_time = ui->dateTime->dateTime();
         qDebug() << "Time changed to" << date_time;
     });
+
+//    QObject::connect(ui->ar)
 }
 
 void ArgDialog::addItem(QString value, QString type) {
@@ -95,9 +105,54 @@ void ArgDialog::clearTask() {
     m_task.time = "";
 }
 
+void ArgDialog::addRequestedBy(QString value) {
+    if (std::find(m_ig_post.requested_by.begin(), m_ig_post.requested_by.end(), value.toUtf8().constData()) == m_ig_post.requested_by.end()) {
+        m_ig_post.requested_by.push_back(value.toUtf8().constData());
+        addToArgList(value, "requested_by");
+    } else {
+        const char* message = "You have already inputted this name under \"requested_by\"";
+        qDebug() << message;
+        QMessageBox::warning(
+            this,
+            tr("Requested By"),
+            tr(message)
+            );
+    }
+}
+
+void ArgDialog::addToArgList(QString value, QString type) {
+    for (int i = 0; i < ui->argList->rowCount(); i++) {
+        auto item = ui->argList->item(i, 1);
+        if (item) {
+            if (QString::compare(item->text(), type) == 0) {
+                auto text = ui->argList->item(i, 0)->text();
+                text.append("\n");
+                text += value;
+                ui->argList->item(i, 0)->setText(text);
+                return;
+            }
+        }
+    }
+    addItem(value, type);
+}
+
+void ArgDialog::addOrReplaceInArgList(QString value, QString type) {
+    for (int i = 0; i < ui->argList->rowCount(); i++) {
+        auto item = ui->argList->item(i, 1);
+        if (item) {
+            if (QString::compare(item->text(), type) == 0) {
+                ui->argList->item(i, 0)->setText(value);
+                return;
+            }
+        }
+    }
+    addItem(value, type);
+}
+
 void ArgDialog::addHashtag(QString tag) {
     if (std::find(m_ig_post.hashtags.begin(), m_ig_post.hashtags.end(), tag.toUtf8().constData()) == m_ig_post.hashtags.end()) {
         m_ig_post.hashtags.push_back(tag.toUtf8().constData());
+        addToArgList(tag, "hashtag");
     } else {
         const char* message = "Can't add the same hashtag twice";
         qDebug() << message;
@@ -105,7 +160,7 @@ void ArgDialog::addHashtag(QString tag) {
             this,
             tr("Hashtags"),
             tr(message)
-        );
+            );
     }
 }
 

+ 56 - 39
argdialog.h

@@ -2,62 +2,79 @@
 #define ARGDIALOG_H
 
 #include <QDialog>
+#include <QFile>
 #include <QFileDialog>
+#include <QMessageBox>
 #include <QPushButton>
-#include <QFile>
 #include <string_view>
-#include <QMessageBox>
+#include <unordered_map>
 
 namespace Args {
-    const QString DESCRIPTION_TYPE = "description";
-    const QString HASHTAG_TYPE = "hashtag";
-}
+const QString DESCRIPTION_TYPE = "description";
+const QString HASHTAG_TYPE = "hashtag";
+const QString PROMOTE_TYPE = "promote/share";
+const QString LINK_BIO_TYPE = "link/bio";
+const QString REQUESTED_BY_TYPE = "requested by";
+}  // namespace Args
+typedef std::string Str;
+//namespace Emoji {
+//    Str SmilingFaceEyes{"U+1F60A"};
+//    const char* SmilingFaceEyesBytes = "😊";
+//}
 
 typedef struct KFile {
-    std::string_view name;
-    std::string_view path;
+  std::string_view name;
+  std::string_view path;
 } KFile;
 
-typedef struct Task{
-    QString time;
-    int mask;
-    std::vector<std::string> args;
+typedef struct Task {
+  QString time;
+  int mask;
+  std::vector<std::string> args;
 } Task;
 
 typedef struct IGPost {
-    std::string description;
-    std::string datetime;
-    std::string promote_share;
-    std::string link_in_bio;
-    std::vector<std::string> hashtags;
-    std::vector<std::string> requested_by;
-    const char* requested_by_phrase = "The phrase was requested by ";
-    KFile video;
+  std::string description;
+  std::string datetime;
+  std::string promote_share = "Share the post through IG story if you enjoy the phrase 🙋‍♀️";
+  std::string link_in_bio = "Download a FREE PDF of basic 245 verbs (link 🔗 in bio 👆)";
+  std::vector<std::string> hashtags;
+  std::vector<std::string> requested_by;
+  const char *requested_by_phrase = "The phrase was requested by ";
+  KFile video;
+  bool isReady() {
+    return description.size() > 0 && datetime.size() > 0 &&
+           promote_share.size() > 0 && link_in_bio.size() > 0 &&
+           hashtags.size() > 0 && requested_by.size() > 0 &&
+           video.path.size() > 0;
+  }
 } IGPost;
 
 namespace Ui {
 class ArgDialog;
 }
 
-class ArgDialog : public QDialog
-{
-    Q_OBJECT
-
-public:
-    explicit ArgDialog(QWidget *parent = nullptr);
-    ~ArgDialog();
-
-signals:
-    void uploadFile(QByteArray bytes);
-
-private:
-    void clearPost();
-    void clearTask();
-    void addHashtag(QString tag);
-    Ui::ArgDialog *ui;
-    void addItem(QString value, QString type);
-    Task m_task;
-    IGPost m_ig_post;
+class ArgDialog : public QDialog {
+  Q_OBJECT
+
+ public:
+  explicit ArgDialog(QWidget *parent = nullptr);
+  ~ArgDialog();
+
+ signals:
+  void uploadFile(QByteArray bytes);
+
+ private:
+  void clearPost();
+  void clearTask();
+  void addToArgList(QString value, QString type);
+  void addOrReplaceInArgList(QString value, QString type);
+  void addHashtag(QString tag);
+  void addRequestedBy(QString value);
+  Ui::ArgDialog *ui;
+  void addItem(QString value, QString type);
+  Task m_task;
+  IGPost m_ig_post;
 };
 
-#endif // ARGDIALOG_H
+#endif  // ARGDIALOG_H

+ 23 - 9
argdialog.ui

@@ -20,7 +20,7 @@
   <property name="styleSheet">
    <string notr="true">background-color: rgb(33, 33, 33);</string>
   </property>
-  <widget class="QDialogButtonBox" name="argButtonBox">
+  <widget class="QDialogButtonBox" name="argCommandButtons">
    <property name="geometry">
     <rect>
      <x>340</x>
@@ -129,9 +129,9 @@ color: rgb(16, 16, 16);</string>
     </rect>
    </property>
    <property name="styleSheet">
-    <string notr="true">background-color: rgb(0, 255, 0);
+    <string notr="true">background-color: rgb(255, 255, 255);
 color: rgb(5, 5, 5);
-font: 87 12pt &quot;Noto Sans&quot;;
+font: 87 10pt &quot;Noto Sans&quot;;
 selection-background-color: rgb(255, 0, 174);</string>
    </property>
    <property name="columnCount">
@@ -165,7 +165,7 @@ selection-background-color: rgb(255, 0, 174);</string>
     </rect>
    </property>
    <property name="styleSheet">
-    <string notr="true">background-color: rgb(0, 255, 0);
+    <string notr="true">background-color: rgb(255, 255, 255);
 color: rgb(5, 5, 5);
 font: 87 10pt &quot;Noto Sans&quot;;
 selection-background-color: rgb(255, 0, 174);</string>
@@ -180,6 +180,21 @@ selection-background-color: rgb(255, 0, 174);</string>
      <string>hashtag</string>
     </property>
    </item>
+   <item>
+    <property name="text">
+     <string>link/bio</string>
+    </property>
+   </item>
+   <item>
+    <property name="text">
+     <string>promote/share</string>
+    </property>
+   </item>
+   <item>
+    <property name="text">
+     <string>requested by</string>
+    </property>
+   </item>
   </widget>
   <widget class="QLabel" name="label_2">
    <property name="geometry">
@@ -230,10 +245,9 @@ selection-background-color: rgb(255, 0, 174);</string>
     </rect>
    </property>
    <property name="styleSheet">
-    <string notr="true">background-color: rgb(0, 255, 0);
+    <string notr="true">background-color: rgb(255, 255, 255);
 color: rgb(5, 5, 5);
-font: 87 12pt &quot;Noto Sans&quot;;
-selection-background-color: rgb(255, 0, 174);</string>
+font: 87 10pt &quot;Noto Sans&quot;;</string>
    </property>
   </widget>
   <widget class="QLabel" name="label_5">
@@ -263,7 +277,7 @@ selection-background-color: rgb(255, 0, 174);</string>
  <resources/>
  <connections>
   <connection>
-   <sender>argButtonBox</sender>
+   <sender>argCommandButtons</sender>
    <signal>accepted()</signal>
    <receiver>ArgDialog</receiver>
    <slot>accept()</slot>
@@ -279,7 +293,7 @@ selection-background-color: rgb(255, 0, 174);</string>
    </hints>
   </connection>
   <connection>
-   <sender>argButtonBox</sender>
+   <sender>argCommandButtons</sender>
    <signal>rejected()</signal>
    <receiver>ArgDialog</receiver>
    <slot>reject()</slot>

BIN
icons/disconnect.png


BIN
icons/log.png


BIN
icons/send-button.png


BIN
icons/start.png