Skip to content

Commit

Permalink
added save log button
Browse files Browse the repository at this point in the history
  • Loading branch information
dannagle committed Apr 19, 2015
1 parent bef1a94 commit 06337d8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
//Load local file if it exists
#define SETTINGSFILE ((QFile::exists("ps_settings.ini")) ? ("ps_settings.ini") : ((SETTINGSPATH) + "ps_settings.ini"))
#define PACKETSFILE ((QFile::exists("packets.ini")) ? ("packets.ini") : ((SETTINGSPATH) + "packets.ini"))
#define TRAFFICFILE ((QFile::exists("traffic.ini")) ? ("traffic.ini") : ((SETTINGSPATH) + "traffic.ini"))


#define NAMEINIKEY "NAMES"
Expand Down
55 changes: 54 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ MainWindow::MainWindow(QWidget *parent) :

QDEBUG() << "Settings file loaded" << SETTINGSFILE;
QDEBUG() << "Packets file loaded" << PACKETSFILE;
QDEBUG() << "Traffic file loaded" << TRAFFICFILE;

}

Expand Down Expand Up @@ -1934,3 +1933,57 @@ void MainWindow::on_hideQuickSendCheck_clicked(bool checked)
}

}

void MainWindow::on_saveLogButton_clicked()
{
static QString fileName = QDir::homePath() + QString("/trafficlog.log");

fileName = QFileDialog::getSaveFileName(this, tr("Save Traffic Log"),
QDir::toNativeSeparators(fileName), tr("log (*.log)"));

QStringList testExt = fileName.split(".");
QString ext = "";
if(testExt.size() > 0) {
ext = testExt.last();
}
if(ext != "log") {
fileName.append(".log");
}
QDEBUG() << "Export log to" << fileName;

QString exportString = "";
QString delim = "\t";

QTextStream out;
out.setString(&exportString);

out << "TIME" << delim << "From IP" << delim << "From Port" << delim << "To IP"
<< delim << "To Port" << delim << "Method" << delim << "Error" << delim << "ASCII" << delim << "Hex\n";


Packet tempPacket;
foreach(tempPacket, packetsLogged)
{

exportString.append(tempPacket.timestamp.toString(DATETIMEFORMAT));exportString.append(delim);
exportString.append(tempPacket.fromIP);exportString.append(delim);
exportString.append(QString::number(tempPacket.fromPort));exportString.append(delim);
exportString.append(tempPacket.toIP);exportString.append(delim);
exportString.append(QString::number(tempPacket.port));exportString.append(delim);
exportString.append(tempPacket.tcpOrUdp);exportString.append(delim);
exportString.append(tempPacket.errorString);exportString.append(delim);
exportString.append(tempPacket.hexToASCII(tempPacket.hexString));exportString.append(delim);
exportString.append(tempPacket.hexString);exportString.append(delim);
exportString.append("\n");
}


QFile file(fileName);
if(file.open(QFile::WriteOnly)) {
file.write(exportString.toLatin1());
file.close();
}

statusBarMessage("Save Log: " + fileName);

}
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ private slots:

void on_hideQuickSendCheck_clicked(bool checked);

void on_saveLogButton_clicked();

private:
Ui::MainWindow *ui;
QList<Packet> packetsLogged;
Expand Down
27 changes: 17 additions & 10 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<property name="movable">
<bool>false</bool>
Expand Down Expand Up @@ -309,8 +309,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>903</width>
<height>183</height>
<width>875</width>
<height>95</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_15">
Expand Down Expand Up @@ -380,6 +380,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="saveLogButton">
<property name="text">
<string>Save Log</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -985,11 +992,11 @@ font: 75 24pt &quot;Helvetica&quot;; </string>
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;• If you find Packet Sender useful, please make a donation to help fund development. &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-style:italic;&quot;&gt;Any&lt;/span&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt; donation of &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-style:italic;&quot;&gt;any&lt;/span&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt; amount is &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600;&quot;&gt;greatly&lt;/span&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt; appreciated! &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;• Follow @NagleCode on Twitter for &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600; color:#0515f0;&quot;&gt;#packetsender&lt;/span&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt; updates.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'.Helvetica Neue DeskInterface'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;• If you find Packet Sender useful, please make a donation to help fund development. &lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt; font-style:italic;&quot;&gt;Any&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt; donation of &lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt; font-style:italic;&quot;&gt;any&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt; amount is &lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:600;&quot;&gt;greatly&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt; appreciated! &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;• Follow @NagleCode on Twitter for &lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:600; color:#0515f0;&quot;&gt;#packetsender&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt; updates.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1039,7 +1046,7 @@ p, li { white-space: pre-wrap; }
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'.Helvetica Neue DeskInterface'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:11pt;&quot;&gt;This version of Packet Sender is distributed free (for personal and commercial use). If you were charged for this product &lt;/span&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:600;&quot;&gt;or were compelled to install junkware&lt;/span&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:11pt;&quot;&gt;, consider downloading from somewhere else! The official installers bundles zero &amp;quot;potentially unwanted programs&amp;quot;. &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:11pt;&quot;&gt;http://PacketSender.com/LICENSE.txt&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
Expand Down Expand Up @@ -1076,7 +1083,7 @@ p, li { white-space: pre-wrap; }
<x>0</x>
<y>0</y>
<width>947</width>
<height>21</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down

0 comments on commit 06337d8

Please sign in to comment.