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
|
/***************************************************************************
* Copyright (C) 2007 by Danny Kukawka *
* <[email protected]>, <[email protected]> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of version 2 of the GNU General Public License *
* as published by the Free Software Foundation. *
* *
* 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., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
/*! \file logviewer.cpp
* \brief In this file can be found the LogViewer related code.
* \author Danny Kukawka, <[email protected]>, <[email protected]>
* \version 0.0.1
* \date 2007
*/
// QT header
#include <tqfile.h>
#include <tqtextstream.h>
// KDE header
#include <ktextedit.h>
#include <klocale.h>
#include <kfiledialog.h>
#include <kmessagebox.h>
// own header
#include "logviewer.h"
/*! This is the default constructor of the class LogViewer. */
LogViewer::LogViewer( TQString filename, TQWidget *parent, const char *name)
:log_viewer(parent, name, false, WDestructiveClose ) {
this->setCaption(i18n("KPowersave Logfile Viewer: %1").arg(filename));
if (!TQFile::exists ( filename ))
return;
log_file = filename;
TQFile file (log_file);
if (file.open(IO_ReadOnly)) {
TQTextStream stream ( &file );
kTextEdit->setText (stream.read());
kTextEdit->setReadOnly(true);
}
file.close();
}
/*! This is the default destructor of the class LogViewer. */
LogViewer::~LogViewer(){
// no need to delete child widgets, TQt does it all for us
}
/*!
* SLOT: Called if the user click on 'Close' Button
*/
void LogViewer::pB_close_clicked() {
close();
}
/*!
* SLOT: Called if the user click on 'Save As ...' Button
*/
void LogViewer::pB_save_clicked() {
TQString sFileName;
bool tryagain = true;
while (tryagain == true) {
int answer;
TQString msg;
sFileName = KFileDialog::getSaveFileName( TQDir::homeDirPath() );
TQFileInfo info (sFileName);
if (TQFile::exists(sFileName) && info.isWritable() && info.isReadable() && info.isFile()) {
msg = i18n("File already exist. Overwrite the file?");
answer = KMessageBox::questionYesNo(this, msg , i18n("Error while save logfile"));
if (answer == KMessageBox::Yes) {
tryagain = false;
}
} else if (TQFile::exists(sFileName)) {
msg = i18n("File already exist.");
answer = KMessageBox::warningContinueCancel(this, msg ,
i18n("Error while save logfile"),
i18n("Try other filename ..."));
if (answer == KMessageBox::Cancel) {
tryagain = false;
return;
}
} else {
tryagain = false;
}
}
TQFile in(log_file);
TQFile out(sFileName);
if (in.open(IO_ReadOnly)) {
if (out.open(IO_WriteOnly)) {
TQByteArray input(4096);
long l = 0;
while (!in.atEnd()) {
l = in.readLine(input.data(), 4096);
out.writeBlock(input, l);
}
out.close();
}
in.close();
}
}
#include "logviewer.moc"
|