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

tdeio/bookmarks

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

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.9.1
This website is maintained by Timothy Pearson.