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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
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, or
(at your option) any later version.
*/
/*
Shows the content of a log file
begin: Fri Dec 5 2003
copyright: (C) 2003 by Dario Abatianni
email: eisfuchs@tigress.com
*/
#include "logfilereader.h"
#include "konversationapplication.h"
#include "ircview.h"
#include "ircviewbox.h"
#include <tqlayout.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include <tqdockarea.h>
#include <tqpushbutton.h>
#include <tqlabel.h>
#include <tqregexp.h>
#include <tqspinbox.h>
#include <tqstylesheet.h>
#include <tqwhatsthis.h>
#include <kdialog.h>
#include <ktoolbar.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <kdebug.h>
#include <kio/jobclasses.h>
LogfileReader::LogfileReader(TQWidget* tqparent, const TQString& log) : ChatWindow(tqparent)
{
setType(ChatWindow::LogFileReader);
fileName = log;
TQDockArea* toolBarDock = new TQDockArea(Qt::Horizontal,TQDockArea::Normal,this,"logfile_toolbar_dock");
toolBar = new KToolBar(toolBarDock,"logfile_toolbar",true,true);
toolBar->insertButton("filesaveas",0,TQT_SIGNAL(clicked()),TQT_TQOBJECT(this),TQT_SLOT(saveLog()),true,i18n("Save As..."));
new TQLabel(i18n("Show last:"),toolBar,"logfile_size_label");
sizeSpin = new TQSpinBox(10,1000,10,toolBar,"logfile_size_spinbox");
TQWhatsThis::add(sizeSpin, i18n("Use this box to set the maximum size of the log file. This setting does not take effect until you restart Konversation. Each log file may have a separate setting."));
sizeSpin->setValue(Preferences::logfileBufferSize());
sizeSpin->setSuffix(i18n(" KB"));
sizeSpin->installEventFilter(this);
toolBar->insertButton("reload",0,TQT_SIGNAL(clicked()),TQT_TQOBJECT(this),TQT_SLOT(updateView()),true,i18n("Reload"));
toolBar->insertButton("editdelete",0,TQT_SIGNAL(clicked()),TQT_TQOBJECT(this),TQT_SLOT(clearLog()),true,i18n("Clear Logfile"));
IRCViewBox* ircBox = new IRCViewBox(this, 0);
setTextView(ircBox->ircView());
TQWhatsThis::add(getTextView(), i18n("The messages in the log file are displayed here. The oldest messages are at the top and the most recent are at the bottom."));
updateView();
resize(Preferences::logfileReaderSize());
ircBox->ircView()->setFocusPolicy(TQ_StrongFocus);
setFocusPolicy(TQ_StrongFocus);
setFocusProxy(ircBox->ircView());
connect(getTextView(), TQT_SIGNAL(gotFocus()), getTextView(), TQT_SLOT(setFocus()));
}
LogfileReader::~LogfileReader()
{
Preferences::setLogfileReaderSize(size());
Preferences::setLogfileBufferSize(sizeSpin->value());
delete toolBar;
}
bool LogfileReader::eventFilter(TQObject* /* watched */, TQEvent* e)
{
if (e->type() == TQEvent::KeyPress)
{
TQKeyEvent* ke = TQT_TQKEYEVENT(e);
if (ke->key() == TQt::Key_Return || ke->key() == TQt::Key_Enter)
{
updateView();
return true;
}
else
return false;
}
return false;
}
void LogfileReader::updateView()
{
// get maximum size of logfile to display
unsigned long pos=sizeSpin->value()*1024;
getTextView()->clear();
TQFile file(fileName);
if(file.open(IO_ReadOnly))
{
TQTextStream stream(&file);
stream.setEncoding(TQTextStream::UnicodeUTF8);
// Set file pointer to <pos> bytes from the end
if(stream.tqdevice()->size()>pos)
stream.tqdevice()->at(stream.tqdevice()->size()-pos);
// Skip first line, since it may be incomplete
stream.readLine();
TQString str;
while(!stream.eof())
{
str = TQStyleSheet::escape(stream.readLine());
getTextView()->appendRaw(str, true);
}
stream.unsetDevice();
file.close();
}
}
void LogfileReader::clearLog()
{
if(KMessageBox::warningContinueCancel(this,
i18n("Do you really want to permanently discard all log information of this file?"),
i18n("Clear Logfile"),
KStdGuiItem::del(),
"ClearLogfileQuestion")==KMessageBox::Continue)
{
TQFile::remove(fileName);
updateView();
}
}
void LogfileReader::saveLog()
{
KMessageBox::information(this,
i18n("Note: By saving the logfile you will save all data in the file, not only the part you can see in this viewer."),
i18n("Save Logfile"),
"SaveLogfileNote");
TQString destination=KFileDialog::getSaveFileName(fileName,
TQString(),
this,
i18n("Choose Destination Folder"));
if(!destination.isEmpty())
{
// tqreplace # with %25 to make it URL conforming
KIO::Job* job=KIO::copy(KURL(fileName.tqreplace("#","%23")),
KURL(destination),
true);
connect(job,TQT_SIGNAL(result(KIO::Job*)),this,TQT_SLOT(copyResult(KIO::Job*)));
}
}
void LogfileReader::copyResult(KIO::Job* job)
{
if(job->error()) job->showErrorDialog(this);
job->deleteLater();
}
void LogfileReader::closeLog()
{
delete this;
}
void LogfileReader::childAdjustFocus()
{
getTextView()->setFocus();
}
int LogfileReader::margin() { return KDialog::marginHint(); }
int LogfileReader::spacing() { return KDialog::spacingHint(); }
bool LogfileReader::searchView() { return true; }
#include "logfilereader.moc"
|