~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/modules/logview/LogViewWindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : LogViewWindow.cpp
 
4
//   Creation date : Tue Apr 23 2002 18:08:22 by Juanjo Alvarez
 
5
//
 
6
//   This file is part of the KVIrc irc client distribution
 
7
//   Copyright (C) 2002 Juanjo Alvarez
 
8
//   Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
 
9
//
 
10
//   This program is FREE software. You can redistribute it and/or
 
11
//   modify it under the terms of the GNU General Public License
 
12
//   as published by the Free Software Foundation; either version 2
 
13
//   of the License, or (at your opinion) any later version.
 
14
//
 
15
//   This program is distributed in the HOPE that it will be USEFUL,
 
16
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
18
//   See the GNU General Public License for more details.
 
19
//
 
20
//   You should have received a copy of the GNU General Public License
 
21
//   along with this program. If not, write to the Free Software Foundation,
 
22
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
23
//
 
24
//=============================================================================
 
25
 
 
26
#include "LogViewWindow.h"
 
27
#include "LogViewWidget.h"
 
28
 
 
29
#include "KviIconManager.h"
 
30
#include "KviLocale.h"
 
31
#include "KviModule.h"
 
32
#include "KviOptions.h"
 
33
#include "KviMainWindow.h"
 
34
#include "KviIrcView.h"
 
35
#include "KviQString.h"
 
36
#include "KviApplication.h"
 
37
#include "KviFileUtils.h"
 
38
#include "KviTalPopupMenu.h"
 
39
 
 
40
#include <QList>
 
41
#include <QPixmap>
 
42
#include <QToolButton>
 
43
#include <QFileInfo>
 
44
#include <QDir>
 
45
#include <QCursor>
 
46
#include <QHeaderView>
 
47
#include <QLayout>
 
48
#include <QPushButton>
 
49
#include <QTextCodec>
 
50
#include <QDateTimeEdit>
 
51
#include <QLineEdit>
 
52
#include <QLabel>
 
53
#include <QShortcut>
 
54
#include <QMouseEvent>
 
55
#include <QByteArray>
 
56
#include <QMessageBox>
 
57
#include <QSplitter>
 
58
#include <QProgressBar>
 
59
 
 
60
#ifdef COMPILE_ZLIB_SUPPORT
 
61
        #include <zlib.h>
 
62
#endif
 
63
 
 
64
#include <limits.h> //for INT_MAX
 
65
 
 
66
extern LogViewWindow * g_pLogViewWindow;
 
67
 
 
68
LogViewWindow::LogViewWindow(KviModuleExtensionDescriptor * d,KviMainWindow * lpFrm)
 
69
: KviWindow(KviWindow::LogView,lpFrm,"logview"), KviModuleExtension(d)
 
70
{
 
71
        g_pLogViewWindow = this;
 
72
//      m_pLogViewWidget = new KviLogViewWidget(this);
 
73
 
 
74
        m_pSplitter = new KviTalSplitter(Qt::Horizontal,this);
 
75
        m_pSplitter->setObjectName("main_splitter");
 
76
        m_pSplitter->setChildrenCollapsible(false);
 
77
 
 
78
        m_pLeftLayout = new KviTalVBox(m_pSplitter);
 
79
        m_pTabWidget = new QTabWidget(m_pLeftLayout);
 
80
        m_pBottomLayout = new KviTalHBox(m_pLeftLayout);
 
81
        m_pProgressBar = new QProgressBar(m_pBottomLayout);
 
82
        
 
83
        m_pCancelButton = new QPushButton(m_pBottomLayout);
 
84
        m_pCancelButton->setText(__tr2qs_ctx("Cancel","logview"));
 
85
        connect(m_pCancelButton,SIGNAL(clicked()),this,SLOT(abortFilter()));
 
86
        m_pBottomLayout->setVisible(false);
 
87
 
 
88
        m_pIndexTab  = new KviTalVBox(m_pTabWidget);
 
89
        m_pTabWidget->addTab(m_pIndexTab,__tr2qs_ctx("HelpIndex","logview"));
 
90
 
 
91
        m_pListView = new LogViewListView(m_pIndexTab);
 
92
 
 
93
        connect(m_pListView,SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),this,SLOT(itemSelected(QTreeWidgetItem *,QTreeWidgetItem *)));
 
94
        connect(m_pListView,SIGNAL(rightButtonPressed(QTreeWidgetItem *,QPoint)),
 
95
                this,SLOT(rightButtonClicked(QTreeWidgetItem *,QPoint)));
 
96
 
 
97
        m_pSearchTab  = new QWidget(m_pTabWidget);
 
98
        m_pTabWidget->addTab(m_pSearchTab,__tr2qs_ctx("Filter","logview"));
 
99
 
 
100
        QGridLayout *layout = new QGridLayout(m_pSearchTab);
 
101
 
 
102
        m_pShowChannelsCheck = new QCheckBox(__tr2qs_ctx("Show channel logs","logview"),m_pSearchTab);
 
103
        m_pShowChannelsCheck->setChecked(true);
 
104
        layout->addWidget(m_pShowChannelsCheck,0,0,1,2);
 
105
 
 
106
        m_pShowQueryesCheck  = new QCheckBox(__tr2qs_ctx("Show query logs","logview"),m_pSearchTab);
 
107
        m_pShowQueryesCheck->setChecked(true);
 
108
        layout->addWidget(m_pShowQueryesCheck,1,0,1,2);
 
109
 
 
110
        m_pShowConsolesCheck = new QCheckBox(__tr2qs_ctx("Show console logs","logview"),m_pSearchTab);
 
111
        m_pShowConsolesCheck->setChecked(true);
 
112
        layout->addWidget(m_pShowConsolesCheck,2,0,1,2);
 
113
 
 
114
        m_pShowDccChatCheck  = new QCheckBox(__tr2qs_ctx("Show DCC chat logs","logview"),m_pSearchTab);
 
115
        m_pShowDccChatCheck->setChecked(true);
 
116
        layout->addWidget(m_pShowDccChatCheck,3,0,1,2);
 
117
 
 
118
        m_pShowOtherCheck   = new QCheckBox(__tr2qs_ctx("Show other logs","logview"),m_pSearchTab);
 
119
        m_pShowOtherCheck->setChecked(true);
 
120
        layout->addWidget(m_pShowOtherCheck,4,0,1,2);
 
121
 
 
122
        QLabel *l;
 
123
        l = new QLabel(__tr2qs_ctx("Contents filter","logview"),m_pSearchTab);
 
124
        layout->addWidget(l,5,0,1,2);
 
125
 
 
126
        l = new QLabel(__tr2qs_ctx("Log name mask:","logview"),m_pSearchTab);
 
127
        m_pFileNameMask = new QLineEdit(m_pSearchTab);
 
128
        connect(m_pFileNameMask,SIGNAL(returnPressed()),this,SLOT(applyFilter()));
 
129
        layout->addWidget(l,6,0);
 
130
        layout->addWidget(m_pFileNameMask,6,1);
 
131
 
 
132
        l = new QLabel(__tr2qs_ctx("Log contents mask:","logview"),m_pSearchTab);
 
133
        m_pContentsMask = new QLineEdit(m_pSearchTab);
 
134
        connect(m_pContentsMask,SIGNAL(returnPressed()),this,SLOT(applyFilter()));
 
135
        layout->addWidget(l,7,0);
 
136
        layout->addWidget(m_pContentsMask,7,1);
 
137
 
 
138
        m_pEnableFromFilter = new QCheckBox(__tr2qs_ctx("Only older than","logview"),m_pSearchTab);
 
139
        m_pFromDateEdit = new QDateEdit(m_pSearchTab);
 
140
        m_pFromDateEdit->setDate(QDate::currentDate());
 
141
        layout->addWidget(m_pEnableFromFilter,8,0);
 
142
        layout->addWidget(m_pFromDateEdit,8,1);
 
143
        connect(m_pEnableFromFilter,SIGNAL(toggled(bool)),m_pFromDateEdit,SLOT(setEnabled(bool)));
 
144
        m_pFromDateEdit->setEnabled(false);
 
145
 
 
146
        m_pEnableToFilter = new QCheckBox(__tr2qs_ctx("Only newier than","logview"),m_pSearchTab);
 
147
        m_pToDateEdit = new QDateEdit(m_pSearchTab);
 
148
        m_pToDateEdit->setDate(QDate::currentDate());
 
149
        layout->addWidget(m_pEnableToFilter,9,0);
 
150
        layout->addWidget(m_pToDateEdit,9,1);
 
151
        connect(m_pEnableToFilter,SIGNAL(toggled(bool)),m_pToDateEdit,SLOT(setEnabled(bool)));
 
152
        m_pToDateEdit->setEnabled(false);
 
153
 
 
154
        m_pFilterButton = new QPushButton(__tr2qs_ctx("Apply filter","logview"),m_pSearchTab);
 
155
        connect(m_pFilterButton,SIGNAL(clicked()),this,SLOT(applyFilter()));
 
156
        layout->addWidget(m_pFilterButton,10,1);
 
157
 
 
158
        QWidget *w = new QWidget(m_pSearchTab);
 
159
        w->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
 
160
        layout->addWidget(w,11,1);
 
161
 
 
162
        m_pIrcView = new KviIrcView(m_pSplitter,g_pMainWindow,this);
 
163
        m_pIrcView->setMaxBufferSize(INT_MAX);
 
164
        m_pIrcView->setFocusPolicy(Qt::ClickFocus);
 
165
 
 
166
        QList<int> li;
 
167
        li.append(110);
 
168
        li.append(width()-110);
 
169
        m_pSplitter->setSizes(li);
 
170
 
 
171
        g_pApp->getLocalKvircDirectory(m_szLogDirectory,KviApplication::Log);
 
172
        KviQString::ensureLastCharIs(m_szLogDirectory,'/'); // Does this work on Windows?
 
173
 
 
174
        m_pTimer = new QTimer(this);
 
175
        m_pTimer->setSingleShot(true);
 
176
        m_pTimer->setInterval(0);
 
177
        connect(m_pTimer, SIGNAL(timeout()), this, SLOT(filterNext()));
 
178
        //avoid to execute the long time-consuming procedure of log indexing here:
 
179
        //we could still be inside the context of the "Browse log files" QAction
 
180
        QTimer::singleShot( 0, this, SLOT(cacheFileList()) );
 
181
}
 
182
 
 
183
LogViewWindow::~LogViewWindow()
 
184
{
 
185
        g_pLogViewWindow = 0;
 
186
}
 
187
 
 
188
void LogViewWindow::keyPressEvent(QKeyEvent *e)
 
189
{
 
190
//Make CtrlKey and CommandKey ("Apple") behave equally on MacOSX.
 
191
//This way typical X11 and Apple shortcuts can be used simultanously within the input line.
 
192
        if((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::AltModifier) || (e->modifiers() & Qt::MetaModifier))
 
193
        {
 
194
                if(e->key() == Qt::Key_F)
 
195
                {
 
196
                        m_pIrcView->toggleToolWidget();
 
197
                        return;
 
198
                }
 
199
        }
 
200
        KviWindow::keyPressEvent(e);
 
201
}
 
202
 
 
203
void LogViewWindow::applyFilter()
 
204
{
 
205
        setupItemList();
 
206
}
 
207
 
 
208
QPixmap * LogViewWindow::myIconPtr()
 
209
{
 
210
        return g_pIconManager->getSmallIcon(KviIconManager::Log);
 
211
}
 
212
 
 
213
void LogViewWindow::resizeEvent(QResizeEvent *)
 
214
{
 
215
        m_pSplitter->setGeometry(0,0,width(),height());
 
216
}
 
217
 
 
218
void LogViewWindow::fillCaptionBuffers()
 
219
{
 
220
        m_szPlainTextCaption = __tr2qs_ctx("Log Viewer","logview");
 
221
}
 
222
 
 
223
void LogViewWindow::die()
 
224
{
 
225
        close();
 
226
}
 
227
 
 
228
QSize LogViewWindow::sizeHint() const
 
229
{
 
230
        QSize ret(m_pSplitter->sizeHint().width(),m_pIrcView->sizeHint().height());
 
231
        return ret;
 
232
}
 
233
 
 
234
void LogViewWindow::setupItemList()
 
235
{
 
236
        if(m_logList.isEmpty())
 
237
                return;
 
238
 
 
239
        m_pFilterButton->setEnabled(false);
 
240
        m_pListView->clear();
 
241
 
 
242
        m_bAborted=false;
 
243
        m_pBottomLayout->setVisible(true);
 
244
        m_pProgressBar->setRange(0, m_logList.count());
 
245
        m_pProgressBar->setValue(0);
 
246
 
 
247
        m_pLastCategory=0;
 
248
        m_pLastGroupItem=0;
 
249
        m_logList.first();
 
250
        m_pTimer->start(); //singleshot
 
251
}
 
252
 
 
253
void LogViewWindow::abortFilter()
 
254
{
 
255
        m_bAborted=true;
 
256
}
 
257
 
 
258
void LogViewWindow::filterNext()
 
259
{
 
260
        QString szCurGroup;
 
261
        LogFile * pFile=m_logList.current();
 
262
        if(!pFile)
 
263
                goto filter_last;
 
264
 
 
265
        if(pFile->type()==LogFile::Channel && !m_pShowChannelsCheck->isChecked())
 
266
                goto filter_next;
 
267
        if(pFile->type()==LogFile::Console && !m_pShowConsolesCheck->isChecked())
 
268
                goto filter_next;
 
269
        if(pFile->type()==LogFile::DccChat && !m_pShowDccChatCheck->isChecked())
 
270
                goto filter_next;
 
271
        if(pFile->type()==LogFile::Other && !m_pShowOtherCheck->isChecked())
 
272
                goto filter_next;
 
273
        if(pFile->type()==LogFile::Query && !m_pShowQueryesCheck->isChecked())
 
274
                goto filter_next;
 
275
 
 
276
        if(m_pEnableFromFilter->isChecked())
 
277
                if(pFile->date()>m_pFromDateEdit->date())
 
278
                        goto filter_next;
 
279
 
 
280
        if(m_pEnableToFilter->isChecked())
 
281
                if(pFile->date()<m_pToDateEdit->date())
 
282
                        goto filter_next;
 
283
 
 
284
        if(!m_pFileNameMask->text().isEmpty())
 
285
                if(!KviQString::matchString(m_pFileNameMask->text(),pFile->name()))
 
286
                        goto filter_next;
 
287
 
 
288
        if(!m_pContentsMask->text().isEmpty())
 
289
        {
 
290
                QString textBuffer;
 
291
                pFile->getText(textBuffer,m_szLogDirectory);
 
292
                if(!KviQString::matchString(m_pContentsMask->text(),textBuffer))
 
293
                        goto filter_next;
 
294
        }
 
295
 
 
296
        if(m_pLastCategory)
 
297
        {
 
298
                if(m_pLastCategory->m_type!=pFile->type())
 
299
                {
 
300
                        m_pLastCategory=0;
 
301
                        for(int i=0;i<m_pListView->topLevelItemCount(); ++i)
 
302
                        {
 
303
                                LogListViewItemType * pTmp = (LogListViewItemType*) m_pListView->topLevelItem(i);
 
304
                                if(pTmp->m_type == pFile->type())
 
305
                                {
 
306
                                        m_pLastCategory=pTmp;
 
307
                                        break;
 
308
                                }
 
309
                        }
 
310
                        if(!m_pLastCategory)
 
311
                                m_pLastCategory = new LogListViewItemType(m_pListView,pFile->type());
 
312
                }
 
313
        } else {
 
314
                m_pLastCategory = new LogListViewItemType(m_pListView,pFile->type());
 
315
        }
 
316
 
 
317
        szCurGroup = QString(__tr2qs_ctx("%1 on %2","logview")).arg(pFile->name(),pFile->network());
 
318
 
 
319
        if(m_szLastGroup!=szCurGroup)
 
320
        {
 
321
                m_szLastGroup=szCurGroup;
 
322
                m_pLastGroupItem=0;
 
323
                for(int i=0;i<m_pLastCategory->childCount(); ++i)
 
324
                {
 
325
                        LogListViewItemFolder * pTmp = (LogListViewItemFolder*) m_pLastCategory->child(i);
 
326
                        if(pTmp->text(0) == m_szLastGroup)
 
327
                        {
 
328
                                m_pLastGroupItem=pTmp;
 
329
                                break;
 
330
                        }
 
331
                }
 
332
                
 
333
                if(!m_pLastGroupItem)
 
334
                        m_pLastGroupItem=new LogListViewItemFolder(m_pLastCategory,m_szLastGroup);
 
335
        }
 
336
 
 
337
        new LogListViewLog(m_pLastGroupItem,pFile->type(),pFile);
 
338
 
 
339
filter_next:
 
340
        pFile = m_logList.next();
 
341
 
 
342
filter_last:
 
343
        if(pFile && !m_bAborted)
 
344
        {
 
345
                m_pProgressBar->setValue(m_pProgressBar->value()+1);
 
346
                m_pTimer->start(); //singleshot
 
347
        } else {
 
348
                m_pBottomLayout->setVisible(false);
 
349
                m_pListView->sortItems(0, Qt::AscendingOrder);
 
350
                m_pProgressBar->setValue(0);
 
351
                m_pFilterButton->setEnabled(true);
 
352
        }
 
353
}
 
354
 
 
355
void LogViewWindow::cacheFileList()
 
356
{
 
357
        QString logPath;
 
358
        g_pApp->getLocalKvircDirectory(logPath,KviApplication::Log);
 
359
        recurseDirectory(logPath);
 
360
 
 
361
        setupItemList();
 
362
}
 
363
 
 
364
void LogViewWindow::recurseDirectory(const QString& sDir)
 
365
{
 
366
        QDir dir(sDir);
 
367
        QFileInfoList list = dir.entryInfoList();
 
368
        for (int iList=0;iList<list.count();iList++)
 
369
        {
 
370
                QFileInfo info = list[iList];
 
371
                if (info.isDir())
 
372
                {
 
373
                        // recursive
 
374
                        if (info.fileName()!=".." && info.fileName()!=".")
 
375
                        {
 
376
                                recurseDirectory(info.filePath());
 
377
                        }
 
378
                } else if(info.suffix()=="gz" || info.suffix()=="log") {
 
379
                        m_logList.append(new LogFile(info.filePath()));
 
380
                }
 
381
        }
 
382
}
 
383
 
 
384
void LogViewWindow::itemSelected(QTreeWidgetItem * it,QTreeWidgetItem *)
 
385
{
 
386
        //A parent node
 
387
        m_pIrcView->clearBuffer();
 
388
        if(!it || !it->parent() || !(((LogListViewItem *)it)->m_pFileData) )
 
389
        {
 
390
                return;
 
391
        }
 
392
 
 
393
        QString text;
 
394
        ((LogListViewItem *)it)->m_pFileData->getText(text,m_szLogDirectory);
 
395
 
 
396
        QStringList lines= text.split('\n');
 
397
        bool bOk;
 
398
        int iMsgType;
 
399
        for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) {
 
400
                QString num=(*it).section(' ',0,0);
 
401
                iMsgType=num.toInt(&bOk);
 
402
                if(bOk)
 
403
                        outputNoFmt(iMsgType,(*it).section(' ',1),KviIrcView::NoRepaint | KviIrcView::NoTimestamp);
 
404
                else
 
405
                        outputNoFmt(0,*it,KviIrcView::NoRepaint | KviIrcView::NoTimestamp);
 
406
        }
 
407
        m_pIrcView->repaint();
 
408
}
 
409
 
 
410
void LogViewWindow::rightButtonClicked ( QTreeWidgetItem * it, const QPoint &)
 
411
{
 
412
        if(!it) return;
 
413
        m_pListView->setCurrentItem(it);
 
414
 
 
415
        KviTalPopupMenu* popup = new KviTalPopupMenu(this);
 
416
        if(((LogListViewItem *)it)->childCount())
 
417
                popup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Quit)),__tr2qs_ctx("Remove all these channel/query log files","logview"),this,SLOT(deleteCurrent()));
 
418
        else popup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Quit)),__tr2qs_ctx("Remove file","logview"),this,SLOT(deleteCurrent()));
 
419
 
 
420
        popup->exec( QCursor::pos() );
 
421
}
 
422
 
 
423
void LogViewWindow::deleteCurrent()
 
424
{
 
425
        LogListViewItem* pItem = (LogListViewItem *)(m_pListView->currentItem());
 
426
        if(pItem)
 
427
        {
 
428
                if (pItem->childCount())
 
429
                {
 
430
                        if(QMessageBox::question(
 
431
                                this,
 
432
                                __tr2qs("Confirm current user logs delete"),
 
433
                        "Do you really wish to delete all these channel/query logs?", __tr2qs("&Yes"), __tr2qs("&No"),0,1
 
434
                        ) != 0) return;
 
435
                        KviPointerList <LogListViewItem> itemsList;
 
436
                        itemsList.setAutoDelete(false);
 
437
                        for(int i=0;i<pItem->childCount();i++)
 
438
                        {
 
439
                                if (!pItem->child(i)->childCount())
 
440
                                {
 
441
                                        itemsList.append((LogListViewItem*)pItem->child(i));
 
442
                                        continue;
 
443
                                }
 
444
                                LogListViewItem* pChild=(LogListViewItem*)pItem->child(i);
 
445
                                for(int j=0;j<pChild->childCount();j++)
 
446
                                {
 
447
                                        if (!(LogListViewItem*)pChild->child(j))
 
448
                                        {
 
449
                                                qDebug("Null pointer in logviewitem");
 
450
                                                continue;
 
451
                                        }
 
452
                                        itemsList.append((LogListViewItem*)pChild->child(j));
 
453
                                }
 
454
                        }
 
455
                        for(unsigned int i=0;i<itemsList.count();i++)
 
456
                        {
 
457
                                LogListViewItem *pCurItem=itemsList.at(i);
 
458
                                if(!pCurItem->fileName().isNull())
 
459
                                {
 
460
                                        QString szFname;
 
461
                                        g_pApp->getLocalKvircDirectory(szFname,KviApplication::Log,pCurItem->fileName());
 
462
                                        KviFileUtils::removeFile(szFname);
 
463
                                }
 
464
                        }
 
465
                        delete pItem;
 
466
                        return;
 
467
                }
 
468
                        if(!pItem->fileName().isNull())
 
469
                {
 
470
                        QString szFname;
 
471
                        g_pApp->getLocalKvircDirectory(szFname,KviApplication::Log,pItem->fileName());
 
472
                        KviFileUtils::removeFile(szFname);
 
473
                        delete pItem;
 
474
                        m_pIrcView->clearBuffer();
 
475
                        if (!pItem->parent()->childCount()) delete pItem->parent();
 
476
                }
 
477
        }
 
478
}
 
479
 
 
480
LogFile::LogFile(const QString & szName)
 
481
{
 
482
        /*
 
483
        Log is in the format
 
484
        $type_$nick.$network_$YYYY.$MM.$DD.log
 
485
        Examples:
 
486
        query_noldor.azzurra_2009.05.20.log
 
487
        channel_#slackware.azzurra_2009.11.03.log
 
488
        */
 
489
 
 
490
        m_szFilename = szName;
 
491
 
 
492
        QFileInfo fi(m_szFilename);
 
493
        QString szTmpName = fi.fileName();
 
494
 
 
495
        m_bCompressed = (fi.suffix() == "gz");
 
496
        if(m_bCompressed)
 
497
        {
 
498
                //removes trailing dot and extension
 
499
                szTmpName.chop(3);
 
500
        }
 
501
        QString szTypeToken = szTmpName.section('_',0,0);
 
502
        // Ignore non-logs files, this includes '.' and '..'
 
503
        if(KviQString::equalCI(szTypeToken,"channel"))
 
504
                m_type = Channel;
 
505
        else if(KviQString::equalCI(szTypeToken,"console"))
 
506
                m_type = Console;
 
507
        else if(KviQString::equalCI(szTypeToken,"dccchat"))
 
508
                m_type = DccChat;
 
509
        else if(KviQString::equalCI(szTypeToken,"query"))
 
510
                m_type = Query;
 
511
        else
 
512
                m_type = Other;
 
513
 
 
514
        KviCString szUndecoded = szTmpName.section('.',0,0);
 
515
        szUndecoded.cutToFirst('_');
 
516
        m_szName = szUndecoded.hexDecode(szUndecoded.ptr()).ptr();
 
517
 
 
518
        szUndecoded = szTmpName.section('.',1).section('_',0,-2);
 
519
        m_szNetwork = szUndecoded.hexDecode(szUndecoded.ptr()).ptr();
 
520
 
 
521
        QString szDate = szTmpName.section('_',-1).section('.',0,-2);
 
522
        int iYear = szDate.section('.',0,0).toInt();
 
523
        int iMonth = szDate.section('.',1,1).toInt();
 
524
        int iDay = szDate.section('.',2,2).toInt();
 
525
        m_date.setYMD(iYear,iMonth,iDay);
 
526
 
 
527
        //qDebug("type=%i, name=%s, net=%s, date=%i %i %i",m_type,m_szName.ascii(),m_szNetwork.ascii(),iYear,iMonth,iDay);
 
528
}
 
529
 
 
530
void LogFile::getText(QString & text,const QString&)
 
531
{
 
532
        QString logName = fileName();
 
533
        QFile logFile;
 
534
#ifdef COMPILE_ZLIB_SUPPORT
 
535
        if(m_bCompressed)
 
536
        {
 
537
                gzFile file=gzopen(logName.toLocal8Bit().data(),"rb");
 
538
                if(file)
 
539
                {
 
540
                        char buff[1025];
 
541
                        int len;
 
542
                        QByteArray data;
 
543
                        //QCString data;
 
544
                        len=gzread(file,buff,1024);
 
545
                        while(len>0)
 
546
                        {
 
547
                                buff[len]=0;
 
548
                                data.append(buff);
 
549
                                len=gzread(file,buff,1024);
 
550
                        }
 
551
                        gzclose(file);
 
552
                        text = QString::fromUtf8(data);
 
553
                } else {
 
554
                        qDebug("Cannot open compressed file %s",logName.toLocal8Bit().data());
 
555
                }
 
556
        } else {
 
557
#endif
 
558
                logFile.setFileName(logName);
 
559
 
 
560
                if(!logFile.open(QIODevice::ReadOnly))
 
561
                return;
 
562
 
 
563
                QByteArray bytes;
 
564
                bytes=logFile.readAll();
 
565
                text = QString::fromUtf8(bytes.data(), bytes.size());
 
566
                logFile.close();
 
567
#ifdef COMPILE_ZLIB_SUPPORT
 
568
        }
 
569
#endif
 
570
}
 
571
 
 
572
LogViewListView::LogViewListView(QWidget * par)
 
573
: QTreeWidget(par)
 
574
{
 
575
        header()->setSortIndicatorShown(true);
 
576
        setColumnCount(1);
 
577
        setHeaderLabel(__tr2qs_ctx("Log File","logview"));
 
578
        setSelectionMode(QAbstractItemView::SingleSelection);
 
579
        setSortingEnabled(true);
 
580
        setRootIsDecorated(true);
 
581
        setAnimated(true);
 
582
}
 
583
 
 
584
void LogViewListView::mousePressEvent (QMouseEvent *e)
 
585
{
 
586
        if (e->button() == Qt::RightButton)
 
587
        {
 
588
                QTreeWidgetItem *i=itemAt(e->pos());
 
589
                if (i) emit rightButtonPressed(i,QCursor::pos());
 
590
        }
 
591
        QTreeWidget::mousePressEvent(e);
 
592
}
 
593
 
 
594
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
 
595
#include "LogViewWindow.moc"
 
596
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES