Skip to content

Commit

Permalink
Added edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Dec 22, 2017
1 parent bcede58 commit 895936b
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 9 deletions.
Binary file modified lang/tm_de.qm
Binary file not shown.
22 changes: 14 additions & 8 deletions lang/tm_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</message>
<message>
<location filename="../mainwindow.ui" line="55"/>
<location filename="../mainwindow.cpp" line="263"/>
<location filename="../mainwindow.cpp" line="264"/>
<source>Delete</source>
<translation>Löschen</translation>
</message>
Expand Down Expand Up @@ -75,27 +75,33 @@
<translation>Kein plink ausgewählt</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="106"/>
<location filename="../mainwindow.cpp" line="107"/>
<source>%1 already exists</source>
<translation>%1 existiert bereits</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="119"/>
<location filename="../mainwindow.cpp" line="120"/>
<location filename="../mainwindow.cpp" line="316"/>
<source>Not Running</source>
<translation>Läuft nicht</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="191"/>
<location filename="../mainwindow.cpp" line="192"/>
<source>Select plink.exe</source>
<translation>plink.exe auswählen</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="278"/>
<location filename="../mainwindow.cpp" line="279"/>
<source>Running</source>
<translation>Läuft</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="286"/>
<location filename="../mainwindow.cpp" line="282"/>
<source>%1 started</source>
<translation>%1 gestartet</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="289"/>
<source>%1 quited with Exit Code %2</source>
<translation>%1 ist gecrasht mit Exit Code %2</translation>
</message>
Expand Down Expand Up @@ -153,13 +159,13 @@
<translation>Abbrechen</translation>
</message>
<message>
<location filename="../newentry.cpp" line="47"/>
<location filename="../newentry.cpp" line="49"/>
<source>&lt;span style=&quot;color: red;&quot;&gt;%1&lt;/span&gt;</source>
<translatorcomment>Kein Mensch braucht Platzhalter unter tr</translatorcomment>
<translation></translation>
</message>
<message>
<location filename="../newentry.cpp" line="74"/>
<location filename="../newentry.cpp" line="76"/>
<source>Please fill in all fields</source>
<translation>Bitte in alle Felder ausfüllen</translation>
</message>
Expand Down
47 changes: 46 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<QProcess*>(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();
}
4 changes: 4 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class MainWindow : public QMainWindow
QMap<QProcess*, QTreeWidgetItem*> 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);
Expand All @@ -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
19 changes: 19 additions & 0 deletions newentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ NewEntry::NewEntry(QWidget *parent) :
ui->lineUser->setText("");
ui->lineExtIP->setText("");
ui->lineExtPort->setText("");

item = nullptr;
}

NewEntry::~NewEntry()
Expand Down Expand Up @@ -75,10 +77,27 @@ 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);
}

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));
}
5 changes: 5 additions & 0 deletions newentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define NEWENTRY_H

#include <QDialog>
#include <QStringList>
#include <QTreeWidgetItem>

namespace Ui {
class NewEntry;
Expand All @@ -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();
Expand All @@ -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

0 comments on commit 895936b

Please sign in to comment.