• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/bookmarks
 

tdeio/bookmarks

kbookmarkimporter_crash.cc
00001 //  -*- c-basic-offset:4; indent-tabs-mode:nil -*-
00002 // vim: set ts=4 sts=4 sw=4 et:
00003 /* This file is part of the KDE libraries
00004    Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "kbookmarkimporter_crash.h"
00022 
00023 #include <tdefiledialog.h>
00024 #include <kstringhandler.h>
00025 #include <tdelocale.h>
00026 #include <kdebug.h>
00027 #include <tdeapplication.h>
00028 #include <kstandarddirs.h>
00029 #include <tqfile.h>
00030 #include <tqdir.h>
00031 #include <tqstring.h>
00032 #include <tqtextcodec.h>
00033 #include <dcopclient.h>
00034 
00035 #include <sys/types.h>
00036 #include <stddef.h>
00037 #include <dirent.h>
00038 #include <sys/stat.h>
00039 
00040 typedef TQMap<TQString, TQString> ViewMap;
00041 
00042 // KDE 4.0: remove this BC keeping stub
00043 void TDECrashBookmarkImporter::parseCrashLog( TQString /*filename*/, bool /*del*/ ) 
00044 {
00045     ;
00046 }
00047 
00048 ViewMap TDECrashBookmarkImporterImpl::parseCrashLog_noemit( const TQString & filename, bool del ) 
00049 {
00050     static const int g_lineLimit = 16*1024;
00051 
00052     TQFile f( filename );
00053     ViewMap views;
00054 
00055     if ( !f.open( IO_ReadOnly ) )
00056         return views;
00057 
00058     TQCString s( g_lineLimit );
00059 
00060     TQTextCodec * codec = TQTextCodec::codecForName( "UTF-8" );
00061     Q_ASSERT( codec );
00062     if ( !codec ) 
00063         return views;
00064 
00065     while ( f.readLine( s.data(), g_lineLimit ) >=0 ) 
00066     {
00067         if ( s[s.length()-1] != '\n' )
00068         {
00069             kdWarning() << "Crash bookmarks contain a line longer than " << g_lineLimit << ". Skipping." << endl;
00070             continue;
00071         }
00072         TQString t = codec->toUnicode( s.stripWhiteSpace() );
00073         TQRegExp rx( "(.*)\\((.*)\\):(.*)$" );
00074         rx.setMinimal( true );
00075         if ( !rx.exactMatch( t ) ) 
00076             continue;
00077         if ( rx.cap(1) == "opened" )
00078             views[rx.cap(2)] = rx.cap(3);
00079         else if ( rx.cap(1) == "close" )
00080             views.remove( rx.cap(2) );
00081     }
00082 
00083     f.close();
00084 
00085     if ( del ) 
00086         f.remove();
00087 
00088     return views;
00089 }
00090 
00091 TQStringList TDECrashBookmarkImporter::getCrashLogs() 
00092 {
00093     return TDECrashBookmarkImporterImpl::getCrashLogs();
00094 }
00095 
00096 TQStringList TDECrashBookmarkImporterImpl::getCrashLogs() 
00097 {
00098     TQMap<TQString, bool> activeLogs;
00099 
00100     DCOPClient* dcop = kapp->dcopClient();
00101 
00102     QCStringList apps = dcop->registeredApplications();
00103     for ( QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it ) 
00104     {
00105         TQCString &clientId = *it;
00106 
00107         if ( tqstrncmp(clientId, "konqueror", 9) != 0 ) 
00108             continue;
00109 
00110         TQByteArray data, replyData;
00111         TQCString replyType;
00112         TQDataStream arg( data, IO_WriteOnly );
00113 
00114         if ( !dcop->call( clientId.data(), "KonquerorIface", 
00115                           "crashLogFile()", data, replyType, replyData) ) 
00116         {
00117             kdWarning() << "can't find dcop function KonquerorIface::crashLogFile()" << endl;
00118             continue;
00119         }
00120 
00121         if ( replyType != "TQString" ) 
00122             continue;
00123 
00124         TQDataStream reply( replyData, IO_ReadOnly );
00125         TQString ret;
00126         reply >> ret;
00127         activeLogs[ret] = true;
00128     }
00129 
00130     TQDir d( TDECrashBookmarkImporterImpl().findDefaultLocation() );
00131     d.setSorting( TQDir::Time );
00132     d.setFilter( TQDir::Files );
00133     d.setNameFilter( "konqueror-crash-*.log" );
00134 
00135     const TQFileInfoList *list = d.entryInfoList();
00136     TQFileInfoListIterator it( *list );
00137 
00138     TQFileInfo *fi;
00139     TQStringList crashFiles;
00140 
00141     int count = 0;
00142     for ( ; (( fi = it.current() ) != 0) && (count < 20); ++it, ++count ) 
00143     {
00144         bool stillAlive = activeLogs.contains( fi->absFilePath() );
00145         if ( !stillAlive )
00146             crashFiles << fi->absFilePath();
00147     }
00148     // Delete remaining ones
00149     for ( ; ( fi = it.current() ) != 0; ++it ) 
00150     {
00151         TQFile::remove( fi->absFilePath() );
00152     }
00153 
00154     return crashFiles;
00155 }
00156 
00157 void TDECrashBookmarkImporterImpl::parse() 
00158 {
00159     TQDict<bool> signatureMap;
00160     TQStringList crashFiles = TDECrashBookmarkImporterImpl::getCrashLogs();
00161     int count = 1;
00162     for ( TQStringList::Iterator it = crashFiles.begin(); it != crashFiles.end(); ++it ) 
00163     {
00164         ViewMap views;
00165         views = parseCrashLog_noemit( *it, m_shouldDelete );
00166         TQString signature;
00167         for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit ) 
00168             signature += "|"+vit.data();
00169         if (signatureMap[signature])
00170         {
00171             // Duplicate... throw away and skip
00172             TQFile::remove(*it);
00173             continue;
00174         }
00175             
00176         signatureMap.insert(signature, (bool *) true); // hack
00177 
00178         int outerFolder = ( crashFiles.count() > 1 ) && (views.count() > 0);
00179         if ( outerFolder )
00180             emit newFolder( TQString("Konqueror Window %1").arg(count++), false, "" );
00181         for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit ) 
00182             emit newBookmark( vit.data(), vit.data().latin1(), TQString("") );
00183         if ( outerFolder )
00184             emit endFolder();
00185     }
00186 }
00187 
00188 TQString TDECrashBookmarkImporter::crashBookmarksDir() 
00189 {
00190     static TDECrashBookmarkImporterImpl *p = 0;
00191     if (!p)
00192         p = new TDECrashBookmarkImporterImpl;
00193     return p->findDefaultLocation();
00194 }
00195 
00196 void TDECrashBookmarkImporterImpl::setShouldDelete( bool shouldDelete ) 
00197 {
00198     m_shouldDelete = shouldDelete;
00199 }
00200 
00201 void TDECrashBookmarkImporter::parseCrashBookmarks( bool del ) 
00202 {
00203     TDECrashBookmarkImporterImpl importer;
00204     importer.setFilename( m_fileName );
00205     importer.setShouldDelete( del );
00206     importer.setupSignalForwards( &importer, this );
00207     importer.parse();
00208 }
00209 
00210 TQString TDECrashBookmarkImporterImpl::findDefaultLocation( bool ) const 
00211 {
00212     return locateLocal( "tmp", "" );
00213 }
00214 
00215 #include "kbookmarkimporter_crash.moc"

tdeio/bookmarks

Skip menu "tdeio/bookmarks"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/bookmarks

Skip menu "tdeio/bookmarks"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/bookmarks by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.