You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
6.1 KiB
214 lines
6.1 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kbookmarkimporter_crash.h"
|
||
|
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
15 years ago
|
#include <kstringhandler.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
15 years ago
|
#include <tqfile.h>
|
||
|
#include <tqdir.h>
|
||
|
#include <tqstring.h>
|
||
13 years ago
|
#include <tqtextcodec.h>
|
||
15 years ago
|
#include <dcopclient.h>
|
||
|
|
||
|
#include <sys/types.h>
|
||
|
#include <stddef.h>
|
||
|
#include <dirent.h>
|
||
|
#include <sys/stat.h>
|
||
|
|
||
15 years ago
|
typedef TQMap<TQString, TQString> ViewMap;
|
||
15 years ago
|
|
||
|
// KDE 4.0: remove this BC keeping stub
|
||
12 years ago
|
void TDECrashBookmarkImporter::parseCrashLog( TQString /*filename*/, bool /*del*/ )
|
||
15 years ago
|
{
|
||
|
;
|
||
|
}
|
||
|
|
||
12 years ago
|
ViewMap TDECrashBookmarkImporterImpl::parseCrashLog_noemit( const TQString & filename, bool del )
|
||
15 years ago
|
{
|
||
|
static const int g_lineLimit = 16*1024;
|
||
|
|
||
15 years ago
|
TQFile f( filename );
|
||
15 years ago
|
ViewMap views;
|
||
|
|
||
|
if ( !f.open( IO_ReadOnly ) )
|
||
|
return views;
|
||
|
|
||
15 years ago
|
TQCString s( g_lineLimit );
|
||
15 years ago
|
|
||
15 years ago
|
TQTextCodec * codec = TQTextCodec::codecForName( "UTF-8" );
|
||
15 years ago
|
Q_ASSERT( codec );
|
||
|
if ( !codec )
|
||
|
return views;
|
||
|
|
||
|
while ( f.readLine( s.data(), g_lineLimit ) >=0 )
|
||
|
{
|
||
|
if ( s[s.length()-1] != '\n' )
|
||
|
{
|
||
|
kdWarning() << "Crash bookmarks contain a line longer than " << g_lineLimit << ". Skipping." << endl;
|
||
|
continue;
|
||
|
}
|
||
15 years ago
|
TQString t = codec->toUnicode( s.stripWhiteSpace() );
|
||
|
TQRegExp rx( "(.*)\\((.*)\\):(.*)$" );
|
||
15 years ago
|
rx.setMinimal( true );
|
||
|
if ( !rx.exactMatch( t ) )
|
||
|
continue;
|
||
|
if ( rx.cap(1) == "opened" )
|
||
|
views[rx.cap(2)] = rx.cap(3);
|
||
|
else if ( rx.cap(1) == "close" )
|
||
|
views.remove( rx.cap(2) );
|
||
|
}
|
||
|
|
||
|
f.close();
|
||
|
|
||
|
if ( del )
|
||
|
f.remove();
|
||
|
|
||
|
return views;
|
||
|
}
|
||
|
|
||
12 years ago
|
TQStringList TDECrashBookmarkImporter::getCrashLogs()
|
||
15 years ago
|
{
|
||
12 years ago
|
return TDECrashBookmarkImporterImpl::getCrashLogs();
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TQStringList TDECrashBookmarkImporterImpl::getCrashLogs()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQMap<TQString, bool> activeLogs;
|
||
15 years ago
|
|
||
|
DCOPClient* dcop = kapp->dcopClient();
|
||
|
|
||
|
QCStringList apps = dcop->registeredApplications();
|
||
|
for ( QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it )
|
||
|
{
|
||
15 years ago
|
TQCString &clientId = *it;
|
||
15 years ago
|
|
||
14 years ago
|
if ( tqstrncmp(clientId, "konqueror", 9) != 0 )
|
||
15 years ago
|
continue;
|
||
|
|
||
15 years ago
|
TQByteArray data, replyData;
|
||
|
TQCString replyType;
|
||
|
TQDataStream arg( data, IO_WriteOnly );
|
||
15 years ago
|
|
||
|
if ( !dcop->call( clientId.data(), "KonquerorIface",
|
||
|
"crashLogFile()", data, replyType, replyData) )
|
||
|
{
|
||
14 years ago
|
kdWarning() << "can't find dcop function KonquerorIface::crashLogFile()" << endl;
|
||
15 years ago
|
continue;
|
||
|
}
|
||
|
|
||
15 years ago
|
if ( replyType != "TQString" )
|
||
15 years ago
|
continue;
|
||
|
|
||
15 years ago
|
TQDataStream reply( replyData, IO_ReadOnly );
|
||
|
TQString ret;
|
||
15 years ago
|
reply >> ret;
|
||
|
activeLogs[ret] = true;
|
||
|
}
|
||
|
|
||
12 years ago
|
TQDir d( TDECrashBookmarkImporterImpl().findDefaultLocation() );
|
||
15 years ago
|
d.setSorting( TQDir::Time );
|
||
|
d.setFilter( TQDir::Files );
|
||
15 years ago
|
d.setNameFilter( "konqueror-crash-*.log" );
|
||
|
|
||
14 years ago
|
const TQFileInfoList *list = d.entryInfoList();
|
||
|
TQFileInfoListIterator it( *list );
|
||
15 years ago
|
|
||
15 years ago
|
TQFileInfo *fi;
|
||
|
TQStringList crashFiles;
|
||
15 years ago
|
|
||
|
int count = 0;
|
||
|
for ( ; (( fi = it.current() ) != 0) && (count < 20); ++it, ++count )
|
||
|
{
|
||
14 years ago
|
bool stillAlive = activeLogs.contains( fi->absFilePath() );
|
||
15 years ago
|
if ( !stillAlive )
|
||
|
crashFiles << fi->absFilePath();
|
||
|
}
|
||
|
// Delete remaining ones
|
||
|
for ( ; ( fi = it.current() ) != 0; ++it )
|
||
|
{
|
||
15 years ago
|
TQFile::remove( fi->absFilePath() );
|
||
15 years ago
|
}
|
||
|
|
||
|
return crashFiles;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECrashBookmarkImporterImpl::parse()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDict<bool> signatureMap;
|
||
12 years ago
|
TQStringList crashFiles = TDECrashBookmarkImporterImpl::getCrashLogs();
|
||
15 years ago
|
int count = 1;
|
||
15 years ago
|
for ( TQStringList::Iterator it = crashFiles.begin(); it != crashFiles.end(); ++it )
|
||
15 years ago
|
{
|
||
|
ViewMap views;
|
||
|
views = parseCrashLog_noemit( *it, m_shouldDelete );
|
||
15 years ago
|
TQString signature;
|
||
15 years ago
|
for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit )
|
||
|
signature += "|"+vit.data();
|
||
|
if (signatureMap[signature])
|
||
|
{
|
||
|
// Duplicate... throw away and skip
|
||
15 years ago
|
TQFile::remove(*it);
|
||
15 years ago
|
continue;
|
||
|
}
|
||
|
|
||
|
signatureMap.insert(signature, (bool *) true); // hack
|
||
|
|
||
|
int outerFolder = ( crashFiles.count() > 1 ) && (views.count() > 0);
|
||
|
if ( outerFolder )
|
||
15 years ago
|
emit newFolder( TQString("Konqueror Window %1").arg(count++), false, "" );
|
||
15 years ago
|
for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit )
|
||
15 years ago
|
emit newBookmark( vit.data(), vit.data().latin1(), TQString("") );
|
||
15 years ago
|
if ( outerFolder )
|
||
|
emit endFolder();
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
TQString TDECrashBookmarkImporter::crashBookmarksDir()
|
||
15 years ago
|
{
|
||
12 years ago
|
static TDECrashBookmarkImporterImpl *p = 0;
|
||
15 years ago
|
if (!p)
|
||
12 years ago
|
p = new TDECrashBookmarkImporterImpl;
|
||
14 years ago
|
return p->findDefaultLocation();
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDECrashBookmarkImporterImpl::setShouldDelete( bool shouldDelete )
|
||
15 years ago
|
{
|
||
|
m_shouldDelete = shouldDelete;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECrashBookmarkImporter::parseCrashBookmarks( bool del )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDECrashBookmarkImporterImpl importer;
|
||
15 years ago
|
importer.setFilename( m_fileName );
|
||
|
importer.setShouldDelete( del );
|
||
|
importer.setupSignalForwards( &importer, this );
|
||
|
importer.parse();
|
||
|
}
|
||
|
|
||
12 years ago
|
TQString TDECrashBookmarkImporterImpl::findDefaultLocation( bool ) const
|
||
15 years ago
|
{
|
||
|
return locateLocal( "tmp", "" );
|
||
|
}
|
||
|
|
||
|
#include "kbookmarkimporter_crash.moc"
|