[kde-doc-english] [kate] kate/app: kate: add dialog box to catch opening large files
Michal Humpula
michal.humpula at seznam.cz
Thu Dec 5 16:53:31 UTC 2013
Git commit fe05a0f151223d9c5ebe90fb1a4f6117cd68ee94 by Michal Humpula.
Committed on 05/12/2013 at 13:07.
Pushed by michalhumpula into branch 'master'.
kate: add dialog box to catch opening large files
GUI: warns the user if he tries (very probably accidentally)
to open large file (>10MB), which might lead to kate freezing
for a long time.
REVIEW: 114315
M +23 -0 kate/app/kateviewmanager.cpp
http://commits.kde.org/kate/fe05a0f151223d9c5ebe90fb1a4f6117cd68ee94
diff --git a/kate/app/kateviewmanager.cpp b/kate/app/kateviewmanager.cpp
index 2dbd1f9..b28f0db 100644
--- a/kate/app/kateviewmanager.cpp
+++ b/kate/app/kateviewmanager.cpp
@@ -65,6 +65,8 @@
//END Includes
+static const qint64 FileSizeAboveToAskUserIfProceedWithOpen = 10 * 1024 * 1024; // 10MB should suffice
+
KateViewManager::KateViewManager (QWidget *parentW, KateMainWindow *parent)
: QSplitter (parentW)
, m_mainWindow(parent)
@@ -255,6 +257,27 @@ void KateViewManager::slotDocumentOpen ()
KateDocumentInfo docInfo;
docInfo.openedByUser = true;
+ QString fileList;
+
+ foreach ( const KUrl &url, r.URLs )
+ {
+ qint64 size = QFile( url.toLocalFile() ).size();
+
+ if ( size > FileSizeAboveToAskUserIfProceedWithOpen )
+ {
+ fileList += QString("<li>%1 (%2MB)</li>").arg( url.fileName() ).arg( size / 1024 / 1024 );
+ }
+ }
+
+ if ( !fileList.isEmpty() )
+ {
+ QString text = i18n( "<p>You are attempting to open one or more large files:</p><ul>%1</ul><p>Do you want to proceed?</p><p><strong>Beware that kate may stop responding for some time when opening large files.</strong></p>" );
+
+ int ret = KMessageBox::warningYesNo( this, text.arg( fileList ), i18n("Opening Large File"), KStandardGuiItem::cont(), KStandardGuiItem::stop() );
+ if ( ret == KMessageBox::No )
+ return;
+ }
+
KTextEditor::Document *lastID = 0;
for (KUrl::List::Iterator i = r.URLs.begin(); i != r.URLs.end(); ++i)
lastID = openUrl( *i, r.encoding, false, false, docInfo);
More information about the kde-doc-english
mailing list