From 895936b7f1043c41d6949d52a4d729cb17b988ed Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Fri, 22 Dec 2017 02:44:10 +0100 Subject: [PATCH] Added edit mode --- lang/tm_de.qm | Bin 2692 -> 2765 bytes lang/tm_de.ts | 22 ++++++++++++++-------- mainwindow.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- mainwindow.h | 4 ++++ newentry.cpp | 19 +++++++++++++++++++ newentry.h | 5 +++++ 6 files changed, 88 insertions(+), 9 deletions(-) diff --git a/lang/tm_de.qm b/lang/tm_de.qm index a1b168438588e1afe7c5403afb4bc70fa713747e..4d6d19d81626c5d06efd1191e4494b56dbd8739a 100644 GIT binary patch delta 386 zcmWkpJxD@P7(G7kd%pKF9n{Lr5SLKWq8~6qTCxyo5cU}l~2+z9PYlV0K; zI`0X)*v`lW>6@(RJSM-F6;Ee?v^c~khBKhW7dEN@+veX-UI+(-Bb5S$4_%7A5?6JP zbM&z0N3>T~iGPV|rA9^HBxl@2zO)oDPEo;#R2y%lf@SHmgOK}`UFYA#7v%|$Ohs1Y zy@epn^K!v@2_JCVr1hC8NYT&QmjJ0r+9EnZq~3smfz_IUflZo$!H|!Ef#DJZOV2_E2KK8AEEiN67#L$2SiUU*(p?O! z9;QJ08v|<(3j+hwUj`4ehd_197<^_X0mXG0{IjZnW;HT|GORcCz!Jdve)&@d2Ik*v ziw*$|WZS@A%<>8--pKwS8E7%%Ru1JIbwK_mjzc?+GB9wg=F~|S2CB2;^x=;LI!uxC zXn;6Se;MZ|Eg;RbmrHlk7a(7cE8LI^=pZYuSy>@K@nmjh2N4Df1`cDM1m#koK@WJg zCmsSST*h-)hY85f<4uow1awyfADaPCBkNkecl?q-i$7&DFmM`A4r08vIg=@c0{{)v BOlJT9 diff --git a/lang/tm_de.ts b/lang/tm_de.ts index c2faafd..110fd90 100644 --- a/lang/tm_de.ts +++ b/lang/tm_de.ts @@ -25,7 +25,7 @@ - + Delete Löschen @@ -75,27 +75,33 @@ Kein plink ausgewählt - + %1 already exists %1 existiert bereits - + + Not Running Läuft nicht - + Select plink.exe plink.exe auswählen - + Running Läuft - + + %1 started + %1 gestartet + + + %1 quited with Exit Code %2 %1 ist gecrasht mit Exit Code %2 @@ -153,13 +159,13 @@ Abbrechen - + <span style="color: red;">%1</span> Kein Mensch braucht Platzhalter unter tr - + Please fill in all fields Bitte in alle Felder ausfüllen diff --git a/mainwindow.cpp b/mainwindow.cpp index 258ab05..a159e4f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -75,6 +75,7 @@ void MainWindow::addNewEntry() { entry = new NewEntry(this); connect(entry, SIGNAL(newEntryAdded(QString,QString,QString,QString,QString,QString,QString,bool)), this, SLOT(newEntryAdded(QString,QString,QString,QString,QString,QString,QString,bool))); + connect(entry, SIGNAL(itemModified(QTreeWidgetItem*,QString,QString,QString,QString,QString,QString,QString)), this, SLOT(itemModified(QTreeWidgetItem*,QString,QString,QString,QString,QString,QString,QString))); connect(entry, SIGNAL(finished(int)), this, SLOT(entryDialogClosed(int))); } entry->show(); @@ -277,14 +278,58 @@ void MainWindow::onTunnelStart() processToWidgetItem[process]->setText(0, tr("Running")); processToWidgetItem[process]->setTextColor(0, QColor("green")); + + ui->statusBar->showMessage(tr("%1 started").arg(processToWidgetItem[process]->text(1))); } void MainWindow::onTunnelCrash(int exitCode) { QProcess *process = dynamic_cast(sender()); - ui->statusBar->showMessage(tr("%1 quited with Exit Code %2").arg(processToWidgetItem[process]->text(0), QString::number(exitCode))); + ui->statusBar->showMessage(tr("%1 quited with Exit Code %2").arg(processToWidgetItem[process]->text(1), QString::number(exitCode))); processToWidgetItem[process]->setText(0, process->readAllStandardError()); processToWidgetItem[process]->setTextColor(0, QColor("red")); } + +void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) +{ + Q_UNUSED(column) + this->addNewEntry(); + + entry->fillForm(itemData[item], item); +} + +void MainWindow::itemModified(QTreeWidgetItem *item, QString name, QString host, QString sshPort, QString user, QString locPort, QString extIP, QString extPort) +{ + QProcess *process = processMap[item]; + processToWidgetItem.remove(process); + processMap.remove(item); + process->disconnect(); + process->kill(); + process->waitForFinished(); + delete process; + + itemData[item].clear(); + itemData[item] << name << host << sshPort << user << locPort << extIP << extPort; + + item->setText(0, tr("Not Running")); + item->setTextColor(0, QColor("red")); + item->setText(1, name); + item->setText(2, host); + item->setText(3, locPort); + item->setText(4, extPort); + + QString plink = ui->linePlink->text(); + QStringList plink_args = buildPlinkOptions(host, sshPort, user, locPort, extIP, extPort); + + process = new QProcess; + processToWidgetItem[process] = item; + connect(process, SIGNAL(started()), this, SLOT(onTunnelStart())); + connect(process, SIGNAL(finished(int)), this, SLOT(onTunnelCrash(int))); + process->start(plink, plink_args); + + processMap[item] = process; + + entry->close(); +} diff --git a/mainwindow.h b/mainwindow.h index d315d7c..c5caecb 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -44,6 +44,9 @@ class MainWindow : public QMainWindow QMap processToWidgetItem; QSystemTrayIcon *trayIcon; +public slots: + void itemModified(QTreeWidgetItem *item, QString name, QString host, QString sshPort, QString user, QString locPort, QString extIP, QString extPort); + private slots: void addNewEntry(); void entryDialogClosed(int id); @@ -56,6 +59,7 @@ private slots: void deleteFromContextMenu(); void onTunnelStart(); void onTunnelCrash(int exitCode); + void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column); }; #endif // MAINWINDOW_H diff --git a/newentry.cpp b/newentry.cpp index 5af808a..43fb405 100644 --- a/newentry.cpp +++ b/newentry.cpp @@ -30,6 +30,8 @@ NewEntry::NewEntry(QWidget *parent) : ui->lineUser->setText(""); ui->lineExtIP->setText(""); ui->lineExtPort->setText(""); + + item = nullptr; } NewEntry::~NewEntry() @@ -75,6 +77,11 @@ void NewEntry::on_buttonOk_clicked() return; } + if (item != nullptr) { + emit itemModified(item, ui->lineName->text(), ui->lineHost->text(), ui->lineSshPort->text(), ui->lineUser->text(), ui->lineLocPort->text(), ui->lineExtIP->text(), ui->lineExtPort->text()); + return; + } + emit newEntryAdded(ui->lineName->text(), ui->lineHost->text(), ui->lineSshPort->text(), ui->lineUser->text(), ui->lineLocPort->text(), ui->lineExtIP->text(), ui->lineExtPort->text(), false); } @@ -82,3 +89,15 @@ void NewEntry::on_buttonCancel_clicked() { close(); } + +void NewEntry::fillForm(QStringList data, QTreeWidgetItem *item_) +{ + item = item_; + ui->lineName->setText(data.at(0)); + ui->lineHost->setText(data.at(1)); + ui->lineSshPort->setText(data.at(2)); + ui->lineUser->setText(data.at(3)); + ui->lineLocPort->setText(data.at(4)); + ui->lineExtIP->setText(data.at(5)); + ui->lineExtPort->setText(data.at(6)); +} diff --git a/newentry.h b/newentry.h index 50946b6..53e7d97 100644 --- a/newentry.h +++ b/newentry.h @@ -13,6 +13,8 @@ #define NEWENTRY_H #include +#include +#include namespace Ui { class NewEntry; @@ -24,6 +26,7 @@ class NewEntry : public QDialog public: explicit NewEntry(QWidget *parent = 0); + void fillForm(QStringList data, QTreeWidgetItem *item); void entryFailed(QString text); void entrySuccess(); void adaptSize(); @@ -35,9 +38,11 @@ private slots: signals: void newEntryAdded(QString name, QString host, QString sshPort, QString user, QString locPort, QString extIP, QString extPort, bool startup); + void itemModified(QTreeWidgetItem *item, QString name, QString host, QString sshPort, QString user, QString locPort, QString extIP, QString extPort); private: Ui::NewEntry *ui; + QTreeWidgetItem *item; }; #endif // NEWENTRY_H