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

kio/bookmarks

  • kio
  • bookmarks
kbookmarkimporter_crash.cc
1 // -*- c-basic-offset:4; indent-tabs-mode:nil -*-
2 // vim: set ts=4 sts=4 sw=4 et:
3 /* This file is part of the KDE libraries
4  Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kbookmarkimporter_crash.h"
22 
23 #include <kfiledialog.h>
24 #include <kstringhandler.h>
25 #include <klocale.h>
26 #include <kdebug.h>
27 #include <kapplication.h>
28 #include <kstandarddirs.h>
29 #include <tqfile.h>
30 #include <tqdir.h>
31 #include <tqstring.h>
32 #include <tqtextcodec.h>
33 #include <dcopclient.h>
34 
35 #include <sys/types.h>
36 #include <stddef.h>
37 #include <dirent.h>
38 #include <sys/stat.h>
39 
40 typedef TQMap<TQString, TQString> ViewMap;
41 
42 // KDE 4.0: remove this BC keeping stub
43 void KCrashBookmarkImporter::parseCrashLog( TQString /*filename*/, bool /*del*/ )
44 {
45  ;
46 }
47 
48 ViewMap KCrashBookmarkImporterImpl::parseCrashLog_noemit( const TQString & filename, bool del )
49 {
50  static const int g_lineLimit = 16*1024;
51 
52  TQFile f( filename );
53  ViewMap views;
54 
55  if ( !f.open( IO_ReadOnly ) )
56  return views;
57 
58  TQCString s( g_lineLimit );
59 
60  TQTextCodec * codec = TQTextCodec::codecForName( "UTF-8" );
61  Q_ASSERT( codec );
62  if ( !codec )
63  return views;
64 
65  while ( f.readLine( s.data(), g_lineLimit ) >=0 )
66  {
67  if ( s[s.length()-1] != '\n' )
68  {
69  kdWarning() << "Crash bookmarks contain a line longer than " << g_lineLimit << ". Skipping." << endl;
70  continue;
71  }
72  TQString t = codec->toUnicode( s.stripWhiteSpace() );
73  TQRegExp rx( "(.*)\\((.*)\\):(.*)$" );
74  rx.setMinimal( true );
75  if ( !rx.exactMatch( t ) )
76  continue;
77  if ( rx.cap(1) == "opened" )
78  views[rx.cap(2)] = rx.cap(3);
79  else if ( rx.cap(1) == "close" )
80  views.remove( rx.cap(2) );
81  }
82 
83  f.close();
84 
85  if ( del )
86  f.remove();
87 
88  return views;
89 }
90 
91 TQStringList KCrashBookmarkImporter::getCrashLogs()
92 {
93  return KCrashBookmarkImporterImpl::getCrashLogs();
94 }
95 
96 TQStringList KCrashBookmarkImporterImpl::getCrashLogs()
97 {
98  TQMap<TQString, bool> activeLogs;
99 
100  DCOPClient* dcop = kapp->dcopClient();
101 
102  QCStringList apps = dcop->registeredApplications();
103  for ( QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it )
104  {
105  TQCString &clientId = *it;
106 
107  if ( tqstrncmp(clientId, "konqueror", 9) != 0 )
108  continue;
109 
110  TQByteArray data, replyData;
111  TQCString replyType;
112  TQDataStream arg( data, IO_WriteOnly );
113 
114  if ( !dcop->call( clientId.data(), "KonquerorIface",
115  "crashLogFile()", data, replyType, replyData) )
116  {
117  kdWarning() << "can't find dcop function KonquerorIface::crashLogFile()" << endl;
118  continue;
119  }
120 
121  if ( replyType != "TQString" )
122  continue;
123 
124  TQDataStream reply( replyData, IO_ReadOnly );
125  TQString ret;
126  reply >> ret;
127  activeLogs[ret] = true;
128  }
129 
130  TQDir d( KCrashBookmarkImporterImpl().findDefaultLocation() );
131  d.setSorting( TQDir::Time );
132  d.setFilter( TQDir::Files );
133  d.setNameFilter( "konqueror-crash-*.log" );
134 
135  const TQFileInfoList *list = d.entryInfoList();
136  TQFileInfoListIterator it( *list );
137 
138  TQFileInfo *fi;
139  TQStringList crashFiles;
140 
141  int count = 0;
142  for ( ; (( fi = it.current() ) != 0) && (count < 20); ++it, ++count )
143  {
144  bool stillAlive = activeLogs.contains( fi->absFilePath() );
145  if ( !stillAlive )
146  crashFiles << fi->absFilePath();
147  }
148  // Delete remaining ones
149  for ( ; ( fi = it.current() ) != 0; ++it )
150  {
151  TQFile::remove( fi->absFilePath() );
152  }
153 
154  return crashFiles;
155 }
156 
157 void KCrashBookmarkImporterImpl::parse()
158 {
159  TQDict<bool> signatureMap;
160  TQStringList crashFiles = KCrashBookmarkImporterImpl::getCrashLogs();
161  int count = 1;
162  for ( TQStringList::Iterator it = crashFiles.begin(); it != crashFiles.end(); ++it )
163  {
164  ViewMap views;
165  views = parseCrashLog_noemit( *it, m_shouldDelete );
166  TQString signature;
167  for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit )
168  signature += "|"+vit.data();
169  if (signatureMap[signature])
170  {
171  // Duplicate... throw away and skip
172  TQFile::remove(*it);
173  continue;
174  }
175 
176  signatureMap.insert(signature, (bool *) true); // hack
177 
178  int outerFolder = ( crashFiles.count() > 1 ) && (views.count() > 0);
179  if ( outerFolder )
180  emit newFolder( TQString("Konqueror Window %1").arg(count++), false, "" );
181  for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit )
182  emit newBookmark( vit.data(), vit.data().latin1(), TQString("") );
183  if ( outerFolder )
184  emit endFolder();
185  }
186 }
187 
188 TQString KCrashBookmarkImporter::crashBookmarksDir()
189 {
190  static KCrashBookmarkImporterImpl *p = 0;
191  if (!p)
192  p = new KCrashBookmarkImporterImpl;
193  return p->findDefaultLocation();
194 }
195 
196 void KCrashBookmarkImporterImpl::setShouldDelete( bool shouldDelete )
197 {
198  m_shouldDelete = shouldDelete;
199 }
200 
201 void KCrashBookmarkImporter::parseCrashBookmarks( bool del )
202 {
203  KCrashBookmarkImporterImpl importer;
204  importer.setFilename( m_fileName );
205  importer.setShouldDelete( del );
206  importer.setupSignalForwards( &importer, this );
207  importer.parse();
208 }
209 
210 TQString KCrashBookmarkImporterImpl::findDefaultLocation( bool ) const
211 {
212  return locateLocal( "tmp", "" );
213 }
214 
215 #include "kbookmarkimporter_crash.moc"
KBookmarkImporterBase::endFolder
void endFolder()
Tell the outside world that we're going down one menu.
KBookmarkImporterBase::newFolder
void newFolder(const TQString &text, bool open, const TQString &additionalInfo)
Notify about a new folder Use "bookmark_folder" for the icon.
KBookmarkImporterBase::newBookmark
void newBookmark(const TQString &text, const TQCString &url, const TQString &additionalInfo)
Notify about a new bookmark Use "html" for the icon.
KCrashBookmarkImporterImpl
A class for importing all crash sessions as bookmarks.
Definition: kbookmarkimporter_crash.h:60

kio/bookmarks

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

kio/bookmarks

Skip menu "kio/bookmarks"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/bookmarks by doxygen 1.8.6
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |