File: mainwin.cpp

package info (click to toggle)
nmapsi4 0.2~beta1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,356 kB
  • ctags: 300
  • sloc: cpp: 3,770; makefile: 42; sh: 13
file content (138 lines) | stat: -rw-r--r-- 4,599 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/***************************************************************************
 *   Copyright (C) 2008 by Francesco Cecconi                               *
 *   francesco.cecconi@gmail.com                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License.        *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "mainwin.h"


mwClass::mwClass() : logF(0), url(0)
{
    initGUI();
    QTimer::singleShot(0, this, SLOT(initObject()));
}

void mwClass::initGUI() {
    setupUi(this);

    connect(actionOpen, SIGNAL(triggered()),
            this, SLOT(Breader()));

    connect(actionClose, SIGNAL(triggered()),
            this, SLOT(exit()));

    connect(actionQuit, SIGNAL(triggered()),
            this, SLOT(exit()));

    connect(action_About, SIGNAL(triggered()),
            this, SLOT(about()));

    connect(actionAbout_Qt, SIGNAL(triggered()),
            this, SLOT(about_qt()));

    connect(logTree, SIGNAL(itemSelectionChanged()),
            this, SLOT(logFromHistory()));
}

void mwClass::initObject() {
    // Take nmapsi4 geometry info
    QSettings settings("nmapsi4", "nmapsi4");
    QPoint pos = settings.value("window-logr/pos", QPoint(200, 200)).toPoint();
    QSize size = settings.value("window-logr/size", QSize(869, 605)).toSize();
    nHost = settings.value("hostCache").toInt();
    resize(size);
    move(pos);

    logTree->setColumnWidth(0, 350);
    logTree->setColumnWidth(1, 200);
    logHistory *history = new logHistory(logTree, "logReader/urlList", "logReader/urlListTime", nHost);
    history->updateLogHistory();
    delete history;
}

void mwClass::Breader()
{
    url = showBrowser();
    logReader();
}

void mwClass::logReader()
{

    if (url.isEmpty())
        return;

#ifndef LOGR_NO_DEBUG
    qDebug() << "Path Current Item::" << url;
#endif

    //logHistory *history = new logHistory(logTree,"logReader/urlList");
    logHistory *history = new logHistory(logTree, "logReader/urlList", "logReader/urlListTime", nHost);
    history->addItemHistory(url, QDateTime::currentDateTime().toString("ddd MMMM d yy - hh:mm:ss.zzz"));

    if (!logF) logF = new QFile();
#ifndef LOGR_NO_DEBUG
    qDebug() << "nmapsi4-logr:: --> url::" << url;
#endif
    logF->setFileName(url);
    if (!logF->open(QIODevice::ReadOnly)) {
#ifndef LOGR_NO_DEBUG
        qDebug() << "Log File open error." << endl;
#endif
        return;
    }

    QTextStream buffer(logF);
    QString tmpLine;

    treeLogView->setIconSize(QSize::QSize(32, 32));

    while (!buffer.atEnd()) {
        tmpLine = buffer.readLine();

        if (tmpLine.contains("==LogStart")) {
            tmpLine = buffer.readLine();
            if (!(treeLogView->findItems(tmpLine, Qt::MatchFixedString, 0)).size()) {
                root = new QTreeWidgetItem(treeLogView);
                ItemList.push_front(root);
                root->setIcon(0, QIcon(QString::fromUtf8(":/images/images/viewmagfit.png")));
                root->setText(0, tmpLine);
                while (!tmpLine.contains("==LogEnd")) {
                    tmpLine = buffer.readLine();

                    if (!tmpLine.contains("==LogEnd") && !tmpLine.isEmpty()) {
                        item = new QTreeWidgetItem(root);
                        ItemList.push_front(item);
                        item->setText(0, tmpLine);
                    }

                }
            }
        }
    }

    history->updateLogHistory();
    logF->close();
    delete history;

}

mwClass::~mwClass()
{
    itemDeleteAll(ItemList);
    //delete logF;
}