19 #include "kbookmarkimporter_crash.h"
21 #include <tdefiledialog.h>
22 #include <kstringhandler.h>
23 #include <tdelocale.h>
25 #include <tdeapplication.h>
26 #include <kstandarddirs.h>
30 #include <tqtextcodec.h>
31 #include <dcopclient.h>
33 #include <sys/types.h>
38 typedef TQMap<TQString, TQString> ViewMap;
41 void TDECrashBookmarkImporter::parseCrashLog( TQString ,
bool )
46 ViewMap TDECrashBookmarkImporterImpl::parseCrashLog_noemit(
const TQString & filename,
bool del )
48 static const int g_lineLimit = 16*1024;
53 if ( !f.open( IO_ReadOnly ) )
56 TQCString s( g_lineLimit );
58 TQTextCodec * codec = TQTextCodec::codecForName(
"UTF-8" );
63 while ( f.readLine( s.data(), g_lineLimit ) >=0 )
65 if ( s[s.length()-1] !=
'\n' )
67 kdWarning() <<
"Crash bookmarks contain a line longer than " << g_lineLimit <<
". Skipping." << endl;
70 TQString t = codec->toUnicode( s.stripWhiteSpace() );
71 TQRegExp rx(
"(.*)\\((.*)\\):(.*)$" );
72 rx.setMinimal(
true );
73 if ( !rx.exactMatch( t ) )
75 if ( rx.cap(1) ==
"opened" )
76 views[rx.cap(2)] = rx.cap(3);
77 else if ( rx.cap(1) ==
"close" )
78 views.remove( rx.cap(2) );
89 TQStringList TDECrashBookmarkImporter::getCrashLogs()
91 return TDECrashBookmarkImporterImpl::getCrashLogs();
94 TQStringList TDECrashBookmarkImporterImpl::getCrashLogs()
96 TQMap<TQString, bool> activeLogs;
98 DCOPClient* dcop = kapp->dcopClient();
100 QCStringList apps = dcop->registeredApplications();
101 for ( QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it )
103 TQCString &clientId = *it;
105 if ( tqstrncmp(clientId,
"konqueror", 9) != 0 )
108 TQByteArray data, replyData;
110 TQDataStream arg( data, IO_WriteOnly );
112 if ( !dcop->call( clientId.data(),
"KonquerorIface",
113 "crashLogFile()", data, replyType, replyData) )
115 kdWarning() <<
"can't find dcop function KonquerorIface::crashLogFile()" << endl;
119 if ( replyType !=
"TQString" )
122 TQDataStream reply( replyData, IO_ReadOnly );
125 activeLogs[ret] =
true;
129 d.setSorting( TQDir::Time );
130 d.setFilter( TQDir::Files );
131 d.setNameFilter(
"konqueror-crash-*.log" );
133 const TQFileInfoList *list = d.entryInfoList();
134 TQFileInfoListIterator it( *list );
137 TQStringList crashFiles;
140 for ( ; (( fi = it.current() ) != 0) && (count < 20); ++it, ++count )
142 bool stillAlive = activeLogs.contains( fi->absFilePath() );
144 crashFiles << fi->absFilePath();
147 for ( ; ( fi = it.current() ) != 0; ++it )
149 TQFile::remove( fi->absFilePath() );
155 void TDECrashBookmarkImporterImpl::parse()
157 TQDict<bool> signatureMap;
158 TQStringList crashFiles = TDECrashBookmarkImporterImpl::getCrashLogs();
160 for ( TQStringList::Iterator it = crashFiles.begin(); it != crashFiles.end(); ++it )
163 views = parseCrashLog_noemit( *it, m_shouldDelete );
165 for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit )
166 signature +=
"|"+vit.data();
167 if (signatureMap[signature])
174 signatureMap.insert(signature, (
bool *)
true);
176 int outerFolder = ( crashFiles.count() > 1 ) && (views.count() > 0);
178 emit
newFolder( TQString(
"Konqueror Window %1").arg(count++),
false,
"" );
179 for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit )
180 emit
newBookmark( vit.data(), vit.data().latin1(), TQString(
"") );
186 TQString TDECrashBookmarkImporter::crashBookmarksDir()
191 return p->findDefaultLocation();
194 void TDECrashBookmarkImporterImpl::setShouldDelete(
bool shouldDelete )
196 m_shouldDelete = shouldDelete;
199 void TDECrashBookmarkImporter::parseCrashBookmarks(
bool del )
202 importer.setFilename( m_fileName );
203 importer.setShouldDelete( del );
204 importer.setupSignalForwards( &importer,
this );
208 TQString TDECrashBookmarkImporterImpl::findDefaultLocation(
bool )
const
210 return locateLocal(
"tmp",
"" );
213 #include "kbookmarkimporter_crash.moc"
void newFolder(const TQString &text, bool open, const TQString &additionalInfo)
Notify about a new folder Use "bookmark_folder" for the icon.
void endFolder()
Tell the outside world that we're going down one menu.
void newBookmark(const TQString &text, const TQCString &url, const TQString &additionalInfo)
Notify about a new bookmark Use "html" for the icon.
A class for importing all crash sessions as bookmarks.