• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

  • sources
  • kde-4.12
  • kdelibs
  • kio
  • bookmarks
kbookmarkimporter_crash.cc
Go to the documentation of this file.
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 <kstandarddirs.h>
28 #include <qfile.h>
29 #include <qdir.h>
30 #include <qstring.h>
31 #include <qtextcodec.h>
32 #include <qset.h>
33 #include <QtDBus/QtDBus>
34 
35 #include <sys/types.h>
36 #include <stddef.h>
37 #include <dirent.h>
38 #include <sys/stat.h>
39 
40 typedef QMap<QString, QString> ViewMap;
41 
42 
43 ViewMap KCrashBookmarkImporterImpl::parseCrashLog_noemit( const QString & filename, bool del )
44 {
45  static const int g_lineLimit = 16*1024;
46 
47  QFile f( filename );
48  ViewMap views;
49 
50  if ( !f.open( QIODevice::ReadOnly ) )
51  return views;
52 
53  QByteArray s( g_lineLimit, 0 );
54 
55  QTextCodec * codec = QTextCodec::codecForName( "UTF-8" );
56  Q_ASSERT( codec );
57  if ( !codec )
58  return views;
59 
60  while ( f.readLine( s.data(), g_lineLimit ) >=0 )
61  {
62  if ( s[s.length()-1] != '\n' )
63  {
64  kWarning() << "Crash bookmarks contain a line longer than " << g_lineLimit << ". Skipping.";
65  continue;
66  }
67  QString t = codec->toUnicode( s.trimmed() );
68  QRegExp rx( "(.*)\\((.*)\\):(.*)$" );
69  rx.setMinimal( true );
70  if ( !rx.exactMatch( t ) )
71  continue;
72  if ( rx.cap(1) == "opened" )
73  views[rx.cap(2)] = rx.cap(3);
74  else if ( rx.cap(1) == "close" )
75  views.remove( rx.cap(2) );
76  }
77 
78  f.close();
79 
80  if ( del )
81  f.remove();
82 
83  return views;
84 }
85 
86 QStringList KCrashBookmarkImporterImpl::getCrashLogs()
87 {
88  QSet<QString> activeLogs;
89 
90  const QStringList apps = QDBusConnection::sessionBus().interface()->registeredServiceNames();
91  foreach ( const QString &clientId, apps )
92  {
93  if ( !clientId.startsWith( QLatin1String("org.kde.konqueror") ) )
94  continue;
95 
96  QDBusReply<QString> reply =
97  QDBusInterface(clientId, "/KonqMain", "org.kde.Konqueror").call("crashLogfile");
98 
99  if ( !reply.isValid() )
100  continue;
101 
102  activeLogs += reply;
103  }
104 
105  QDir d( KCrashBookmarkImporterImpl().findDefaultLocation() );
106  d.setSorting( QDir::Time );
107  d.setFilter( QDir::Files );
108  d.setNameFilters( QStringList( "konqueror-crash-*.log" ) );
109 
110  const QFileInfoList list = d.entryInfoList();
111  QListIterator<QFileInfo> it( list );
112 
113  QStringList crashFiles;
114 
115  int count = 0;
116  while ( it.hasNext() && count < 20 )
117  {
118  count++;
119  QString path = it.next().absoluteFilePath();
120  bool stillAlive = activeLogs.contains( path );
121  if ( !stillAlive )
122  crashFiles << path;
123  }
124  // Delete remaining ones
125  while ( it.hasNext() )
126  {
127  QFile::remove( it.next().absoluteFilePath() );
128  }
129 
130  return crashFiles;
131 }
132 
133 void KCrashBookmarkImporterImpl::parse()
134 {
135  QSet<QString> signatureSet;
136  const QStringList crashFiles = KCrashBookmarkImporterImpl::getCrashLogs();
137  int count = 1;
138  for ( QStringList::ConstIterator it = crashFiles.begin(); it != crashFiles.end(); ++it )
139  {
140  const ViewMap views = parseCrashLog_noemit( *it, m_shouldDelete );
141  QString signature;
142  for ( ViewMap::ConstIterator vit = views.begin(); vit != views.end(); ++vit )
143  signature += '|'+vit.value();
144  if (signatureSet.contains(signature))
145  {
146  // Duplicate... throw away and skip
147  QFile::remove(*it);
148  continue;
149  }
150 
151  signatureSet.insert(signature);
152 
153  int outerFolder = ( crashFiles.count() > 1 ) && (views.count() > 0);
154  if ( outerFolder )
155  emit newFolder( QString("Konqueror Window %1").arg(count++), false, "" );
156  for ( ViewMap::ConstIterator vit = views.begin(); vit != views.end(); ++vit )
157  emit newBookmark( vit.value(), vit.value(), QString("") );
158  if ( outerFolder )
159  emit endFolder();
160  }
161 }
162 
163 QString KCrashBookmarkImporter::crashBookmarksDir()
164 {
165  static KCrashBookmarkImporterImpl *p = 0;
166  if (!p)
167  p = new KCrashBookmarkImporterImpl;
168  return p->findDefaultLocation();
169 }
170 
171 void KCrashBookmarkImporterImpl::setShouldDelete( bool shouldDelete )
172 {
173  m_shouldDelete = shouldDelete;
174 }
175 
176 void KCrashBookmarkImporter::parseCrashBookmarks( bool del )
177 {
178  KCrashBookmarkImporterImpl importer;
179  importer.setFilename( m_fileName );
180  importer.setShouldDelete( del );
181  importer.setupSignalForwards( &importer, this );
182  importer.parse();
183 }
184 
185 QString KCrashBookmarkImporterImpl::findDefaultLocation( bool ) const
186 {
187  return KStandardDirs::locateLocal( "tmp", "" );
188 }
189 
190 #include "kbookmarkimporter_crash.moc"
KCrashBookmarkImporter::m_fileName
QString m_fileName
Definition: kbookmarkimporter_crash.h:49
kdebug.h
kfiledialog.h
KBookmarkImporterBase::endFolder
void endFolder()
Tell the outside world that we're going down one menu.
f
static quint32 f(DES_KEY *key, quint32 r, char *subkey)
Definition: des.cpp:378
QString
KCrashBookmarkImporter::crashBookmarksDir
static QString crashBookmarksDir()
Definition: kbookmarkimporter_crash.cc:163
klocale.h
kbookmarkimporter_crash.h
ViewMap
QMap< QString, QString > ViewMap
Definition: kbookmarkimporter_crash.cc:40
KCrashBookmarkImporterImpl::KCrashBookmarkImporterImpl
KCrashBookmarkImporterImpl()
Definition: kbookmarkimporter_crash.h:58
QStringList
KBookmarkImporterBase::newBookmark
void newBookmark(const QString &text, const QString &url, const QString &additionalInfo)
Notify about a new bookmark Use "html" for the icon.
KBookmarkImporterBase::setFilename
void setFilename(const QString &filename)
Definition: kbookmarkimporter.h:41
KCrashBookmarkImporterImpl::parse
virtual void parse()
Definition: kbookmarkimporter_crash.cc:133
KCrashBookmarkImporter::parseCrashBookmarks
void parseCrashBookmarks(bool del=true)
Definition: kbookmarkimporter_crash.cc:176
QSet< QString >
kstringhandler.h
KCrashBookmarkImporterImpl::getCrashLogs
static QStringList getCrashLogs()
Definition: kbookmarkimporter_crash.cc:86
KBookmarkImporterBase::setupSignalForwards
void setupSignalForwards(QObject *src, QObject *dst)
Definition: kbookmarkimporter.cc:73
KCrashBookmarkImporterImpl::findDefaultLocation
virtual QString findDefaultLocation(bool forSaving=false) const
Definition: kbookmarkimporter_crash.cc:185
KStandardDirs::locateLocal
static QString locateLocal(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
kstandarddirs.h
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KCrashBookmarkImporterImpl
A class for importing all crash sessions as bookmarks.
Definition: kbookmarkimporter_crash.h:55
KCrashBookmarkImporterImpl::setShouldDelete
void setShouldDelete(bool)
Definition: kbookmarkimporter_crash.cc:171
QMap< QString, QString >
KRecentDirs::list
QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.
Definition: krecentdirs.cpp:60
KBookmarkImporterBase::newFolder
void newFolder(const QString &text, bool open, const QString &additionalInfo)
Notify about a new folder Use "bookmark_folder" for the icon.
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal