[kde-baseapps] konqueror: Refactoring preloading: no need for a kded module anymore.

David Faure faure at kde.org
Fri Oct 14 17:31:32 UTC 2016


Git commit ba86787c35dee59091959b86bce16f823c14661f by David Faure.
Committed on 14/10/2016 at 17:31.
Pushed by dfaure into branch 'master'.

Refactoring preloading: no need for a kded module anymore.

The DBus service name org.kde.konqueror.preloaded indicates
which process can be used to quickly open a new window.
The first konqueror instance ensures that a --preload process runs
and as soon as the preloaded window is used, another --preload process
is started to handle the next request. To make even the very first
one fast, one can set the "start preload instance on startup" checkbox.

GUI: performance config dialog: the max instances count spinbox is gone,
and "always ensure one preload instance exists" is on by default, to make
the above actually work out of the box.

M  +2    -1    konqueror/CMakeLists.txt
M  +6    -27   konqueror/client/kfmclient.cpp
R  +0    -0    konqueror/konqy_preload.desktop [from: konqueror/preloader/konqy_preload.desktop - 100% similarity]
D  +0    -31   konqueror/preloader/CMakeLists.txt
D  +0    -151  konqueror/preloader/configure.in.in
D  +0    -163  konqueror/preloader/konqy_preloader.desktop
D  +0    -26   konqueror/preloader/org.kde.konqueror.Preloader.xml
D  +0    -151  konqueror/preloader/preloader.cc
D  +0    -59   konqueror/preloader/preloader.h
M  +8    -37   konqueror/settings/performance/konqueror.cpp
M  +0    -2    konqueror/settings/performance/konqueror.h
M  +1    -49   konqueror/settings/performance/konqueror_ui.ui
M  +1    -0    konqueror/src/CMakeLists.txt
M  +1    -9    konqueror/src/KonquerorAdaptor.cpp
M  +0    -6    konqueror/src/KonquerorAdaptor.h
M  +16   -33   konqueror/src/konqmain.cpp
M  +7    -200  konqueror/src/konqmainwindow.cpp
M  +0    -13   konqueror/src/konqmainwindow.h
M  +1    -0    konqueror/src/konqmainwindowfactory.cpp
M  +53   -24   konqueror/src/konqpreloadinghandler.cpp
M  +6    -9    konqueror/src/konqpreloadinghandler.h
M  +2    -13   konqueror/src/konqueror.kcfg
M  +0    -9    konqueror/src/org.kde.Konqueror.Main.xml

http://commits.kde.org/kde-baseapps/ba86787c35dee59091959b86bce16f823c14661f

diff --git a/konqueror/CMakeLists.txt b/konqueror/CMakeLists.txt
index 2ac04e8..a14aeb8 100644
--- a/konqueror/CMakeLists.txt
+++ b/konqueror/CMakeLists.txt
@@ -46,7 +46,6 @@ add_subdirectory( autotests )
 add_subdirectory( about )
 add_subdirectory( pics )
 #add_subdirectory( sidebar )
-add_subdirectory( preloader )
 add_subdirectory( settings )
 add_subdirectory( plugins )
 
@@ -61,6 +60,8 @@ install(FILES konqueror.appdata.xml DESTINATION ${KDE_INSTALL_DATAROOTDIR}/appda
 # This is why konqueror.desktop is installed into services.
 install( FILES konqueror.desktop  DESTINATION  ${KDE_INSTALL_KSERVICES5DIR} )
 
+install(FILES konqy_preload.desktop DESTINATION ${KDE_INSTALL_AUTOSTARTDIR})
+
 # TODO Remove the if/endif lines if Konqueror is split.
 if ("${CMAKE_SOURCE_DIR}" STREQUAL "${Konqueror_SOURCE_DIR}")
   feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/konqueror/client/kfmclient.cpp b/konqueror/client/kfmclient.cpp
index 5706f87..00ed669 100644
--- a/konqueror/client/kfmclient.cpp
+++ b/konqueror/client/kfmclient.cpp
@@ -164,21 +164,8 @@ static void needDBus()
     }
 }
 
-static QString getPreloadedKonqy()
-{
-    KConfig konqCfg(QLatin1String("konquerorrc"));
-    const KConfigGroup reusingGroup(&konqCfg, "Reusing");
-    if (reusingGroup.readEntry("MaxPreloadCount", 1) == 0) {
-        return QString();
-    }
-    needDBus();
-    QDBusInterface ref("org.kde.kded5", "/modules/konqy_preloader", "org.kde.konqueror.Preloader", QDBusConnection::sessionBus());
-    QDBusReply<QString> reply = ref.call("getPreloadedKonqy", currentScreen());
-    if (reply.isValid()) {
-        return reply;
-    }
-    return QString();
-}
+// keep in sync with konqpreloadinghandler.cpp
+static const char s_preloadDBusName[] = "org.kde.konqueror.preloaded";
 
 static QUrl filteredUrl(KCmdLineArgs *args)
 {
@@ -274,20 +261,13 @@ bool ClientApp::createNewWindow(const QUrl &url, bool newTab, bool tempFile, con
         }
     }
 
-    QString appId = getPreloadedKonqy();
-    if (!appId.isEmpty()) {
-        qDebug() << "ClientApp::createNewWindow using existing konqueror" << appId;
-        org::kde::Konqueror::Main konq(appId, "/KonqMain", dbus);
-        konq.createNewWindow(url.url(), mimetype, startup_id_str, tempFile);
+    const QString appId = QString::fromLatin1(s_preloadDBusName);
+    org::kde::Konqueror::Main konq(appId, "/KonqMain", dbus);
+    QDBusReply<QDBusObjectPath> reply = konq.createNewWindow(url.url(), mimetype, startup_id_str, tempFile);
+    if (reply.isValid()) {
         sendASNChange();
     } else {
         QString error;
-        /* Well, we can't pass a mimetype through startServiceByDesktopPath !
-        if ( KToolInvocation::startServiceByDesktopPath( QLatin1String("konqueror.desktop"),
-                                                      url.url(), &error ) > 0 )
-        {
-            kError() << "Couldn't start konqueror from konqueror.desktop: " << error << endl;
-            */
         // pass kfmclient's startup id to konqueror using kshell
         KStartupInfoId id;
         id.initId(startup_id_str);
@@ -308,7 +288,6 @@ bool ClientApp::createNewWindow(const QUrl &url, bool newTab, bool tempFile, con
 #endif
         KStartupInfo::resetStartupEnv();
         qDebug() << "ClientApp::createNewWindow KProcess started, pid=" << pid;
-        //}
     }
     return true;
 }
diff --git a/konqueror/preloader/konqy_preload.desktop b/konqueror/konqy_preload.desktop
similarity index 100%
rename from konqueror/preloader/konqy_preload.desktop
rename to konqueror/konqy_preload.desktop
diff --git a/konqueror/preloader/CMakeLists.txt b/konqueror/preloader/CMakeLists.txt
deleted file mode 100644
index 97b4fa9..0000000
--- a/konqueror/preloader/CMakeLists.txt
+++ /dev/null
@@ -1,31 +0,0 @@
-include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_BINARY_DIR}/../src )
-
-
-########### next target ###############
-add_definitions(-DKONQPRIVATE_EXPORT=)
-
-set(kded_konqy_preloader_PART_SRCS preloader.cc )
-
-kconfig_add_kcfg_files(kded_konqy_preloader_PART_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../src/konqsettingsxt.kcfgc)
-
-qt5_add_dbus_adaptor(kded_konqy_preloader_PART_SRCS org.kde.konqueror.Preloader.xml preloader.h KonqyPreloader)
-
-
-add_library(kded_konqy_preloader MODULE ${kded_konqy_preloader_PART_SRCS})
-
-target_link_libraries(kded_konqy_preloader
-   KF5::ConfigGui
-   KF5::CoreAddons
-   KF5::Completion
-   KF5::DBusAddons
-)
-
-install(TARGETS kded_konqy_preloader DESTINATION ${KDE_INSTALL_PLUGINDIR})
-
-
-########### install files ###############
-
-install(FILES konqy_preload.desktop DESTINATION ${KDE_INSTALL_AUTOSTARTDIR})
-install(FILES konqy_preloader.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}/kded)
-install(FILES org.kde.konqueror.Preloader.xml DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} )
-
diff --git a/konqueror/preloader/configure.in.in b/konqueror/preloader/configure.in.in
deleted file mode 100644
index 315b23c..0000000
--- a/konqueror/preloader/configure.in.in
+++ /dev/null
@@ -1,151 +0,0 @@
-dnl check whether mallinfo() is available and which fields to use to find out memory usage
-dnl it's used in konq_mainwindow.cc
-dnl warning, ugly code ahead
-dnl some implementations have mallinfo() in stdlib.h, others in malloc.h
-dnl fields showing memory usage should be hblkhd, uordblks and usmblks,
-dnl different implementations use different combinations of these (which is ok),
-dnl but some of them "reuse" fields they don't use for other purposes
-
-AC_DEFUN([KDE_MALLINFO_CHECK],
-[
-AC_MSG_CHECKING([for mallinfo() in $1])
-AC_CACHE_VAL(kde_cv_func_mallinfo_$2,
-    [
-    AC_LANG_SAVE
-    AC_LANG_CPLUSPLUS
-    AC_TRY_COMPILE([#include $1],
-	[
-	struct mallinfo m;
-	int dummy;
-	m = mallinfo();
-	dummy = m.hblkhd;
-	dummy = m.uordblks;
-	dummy = m.usmblks;
-	dummy = dummy;
-        ],
-    kde_cv_func_mallinfo_$2=yes,
-    kde_cv_func_mallinfo_$2=no)
-    AC_LANG_RESTORE
-    ])
-if test "$kde_cv_func_mallinfo_$2" = "yes"; then
-    kde_mallinfo_type=$2
-fi
-AC_MSG_RESULT($kde_cv_func_mallinfo_$2)
-])
-
-
-AC_DEFUN([KDE_MALLINFO_CHECK_FIELD],
-[
-AC_MSG_CHECKING([whether to use mallinfo field $1])
-AC_CACHE_VAL(kde_cv_func_mallinfo_field_$1,
-    [
-    AC_LANG_SAVE
-    AC_LANG_CPLUSPLUS
-    AC_TRY_RUN(
-	[
-
-#include <$kde_mallinfo_type.h>
-enum use_type { No, Yes, Never };
-use_type use_field = No;
-const int SIZE = 4 * 1024 * 1024;
-const int SMALL_SIZE = 4 * 1024;
-
-void dif( struct mallinfo& m1, struct mallinfo& m2, bool alloc )
-    {
-    int difval = m2.$1 - m1.$1;
-    if( alloc )
-	{
-	if( difval >= SIZE && difval < 2 * SIZE && use_field != Never )
-	    use_field = Yes;
-	}
-    else // !alloc
-	{
-	difval = -difval;
-	if( difval > SMALL_SIZE && ( difval < SIZE || difval >= 2 * SIZE ) && use_field == Yes )
-	    use_field = Never;
-	}
-    }
-
-int main()
-    {
-    free( malloc( SIZE * 2 )); // avoid Doug Lea's malloc feature of having total_max in usmblks
-    struct mallinfo m1 = mallinfo();
-    void* mem1 = malloc( SIZE );
-    struct mallinfo m2 = mallinfo();
-    free( mem1 );
-    struct mallinfo m3 = mallinfo();
-    void* mem2[ SIZE / 32 ];
-    for( int i = 0;
-	 i < SIZE / 32;
-	 ++i )
-	mem2[ i ] = malloc( 32 );
-    struct mallinfo m4 = mallinfo();
-    for( int i = 0;
-	 i < SIZE / 32;
-	 ++i )
-	free( mem2[ i ] );
-    struct mallinfo m5 = mallinfo();
-    void* mem3[ SIZE / 1024 ];
-    for( int i = 0;
-	 i < SIZE / 1024;
-	 ++i )
-	mem3[ i ] = malloc( 1024 );
-    struct mallinfo m6 = mallinfo();
-    for( int i = 0;
-	 i < SIZE / 1024;
-	 ++i )
-	free( mem3[ i ] );
-    struct mallinfo m7 = mallinfo();
-    dif( m1, m2, true );
-    dif( m2, m3, false );
-    dif( m3, m4, true );
-    dif( m4, m5, false );
-    dif( m5, m6, true );
-    dif( m6, m7, false );
-    return use_field == Yes ? 0 : 1;
-    }
-
-        ],
-	[kde_cv_func_mallinfo_field_$1=yes],
-	[kde_cv_func_mallinfo_field_$1=no],
-	[kde_cv_func_mallinfo_field_$1=no])
-    AC_LANG_RESTORE
-    ])
-AC_MSG_RESULT($kde_cv_func_mallinfo_field_$1)        
-kde_mallinfo_$1=$kde_cv_func_mallinfo_field_$1
-if test "$kde_mallinfo_$1" = "yes"; then
-    AC_DEFINE( KDE_MALLINFO_FIELD_$1, 1, [Use mallinfo field $1])
-fi
-])
-
-
-kde_mallinfo_type=
-KDE_MALLINFO_CHECK([<stdlib.h>],stdlib)
-if test -z "$kde_mallinfo_type"; then
-    KDE_MALLINFO_CHECK([<malloc.h>],malloc)
-fi
-
-AC_TRY_LINK_FUNC(mallinfo,
-    [],
-    [ AC_CHECK_LIB(malloc,mallinfo,
-	[ AC_SUBST(LIBMALLOC,"-lmalloc") ],
-	[ kde_mallinfo_type="" ])
-    ])
-    
-if test -n "$kde_mallinfo_type"; then
-    KDE_MALLINFO_CHECK_FIELD(hblkhd)
-    KDE_MALLINFO_CHECK_FIELD(uordblks)
-    KDE_MALLINFO_CHECK_FIELD(usmblks)
-    if test -z "$kde_mallinfo_hblkhd" -a \
-	-z "$kde_mallinfo_uordblks" -a \
-	-z "$kde_mallinfo_usmblks"; then
-	kde_mallinfo_type=
-    fi
-fi
-
-
-if test "$kde_mallinfo_type" = "stdlib"; then
-    AC_DEFINE(KDE_MALLINFO_STDLIB, 1, [mallinfo() is available in <stdlib.h>])
-elif test "$kde_mallinfo_type" = "malloc"; then
-    AC_DEFINE(KDE_MALLINFO_MALLOC, 1, [mallinfo() is available in <malloc.h>])
-fi
diff --git a/konqueror/preloader/konqy_preloader.desktop b/konqueror/preloader/konqy_preloader.desktop
deleted file mode 100644
index 1d674ab..0000000
--- a/konqueror/preloader/konqy_preloader.desktop
+++ /dev/null
@@ -1,163 +0,0 @@
-[Desktop Entry]
-Type=Service
-Name=Konqueror Browser Preloader
-Name[ar]=وحدة كونكيورر لما قبل التحميل
-Name[ast]=Módulu de precarga del restolador Konqueror
-Name[bg]=Предварително зареждане на браузъра Konqueror
-Name[bn]=কনকরার ব্রাউজার প্রি-লোডার
-Name[bs]=Predučitavač K‑osvajača
-Name[ca]=Precarregador del navegador Konqueror
-Name[ca at valencia]=Precarregador del navegador Konqueror
-Name[cs]=Modul pro načítání Konqueroru
-Name[da]=Forudindlæsning af browseren Konqueror
-Name[de]=Konqueror-Webbrowser-Schnellstarter
-Name[el]=Προφόρτωση περιηγητή Konqueror
-Name[en_GB]=Konqueror Browser Preloader
-Name[es]=Módulo de precarga del navegador Konqueror
-Name[et]=Konquerori brauseri eellaadimise moodul
-Name[eu]=Konqueror arakatzailearen aurrekargatzailea
-Name[fi]=Konqueror-selaimen esilataaja
-Name[fr]=Module de préchargement du navigateur Konqueror
-Name[ga]=Réamhluchtóir Bhrabhsálaí Konqueror
-Name[gl]=O precargador do navegador Konqueror
-Name[gu]=કોન્કરર બ્રાઉઝર પૂર્વલાવવું
-Name[he]=טעינה מקדימה של Konqueror
-Name[hi]=कॉन्क्वेरर ब्राउसर प्रीलोडर
-Name[hr]=Predučitavanje pretraživača Konqueror
-Name[hu]=Konqueror-gyorsbetöltő
-Name[ia]=Precargator del Navigator de Konqueror
-Name[id]=Prapemuatan Peramban Konqueror
-Name[is]=Konqueror forræsingareining
-Name[it]=Precaricatore del browser Konqueror
-Name[ja]=Konqueror ブラウザプリローダ
-Name[kk]=Konqueror шолғыштың алдын-ала жүктегіші
-Name[km]=កម្មវិធីផ្ទុកជា​មុន​នៃ​កម្មវិធី​រុករក​បណ្ដាញ​របស់ Konqueror
-Name[kn]=ಕಾಂಕರರ್ ಜಾಲ ವೀಕ್ಷಕ ಪೂರ್ವೋತ್ಥಾಪನಾ (ಪ್ರಿ ಲೋಡ್) ಘಟಕ
-Name[ko]=Konqueror 브라우저 프리로더
-Name[lt]=Konqueror išankstinio įkrovimo modulis
-Name[lv]=Konqueror priekšielādēšanas modulis
-Name[mai]=कान्क्वेरर ब्राउजर प्रीलोडर
-Name[ml]=കോണ്‍ക്വറര്‍ ബ്രൌസര്‍ പ്രീലോഡര്‍ മൊഡ്യൂള്‍
-Name[mr]=कॉन्करर ब्राऊजर प्रीलोडर
-Name[nb]=Forhåndslaster for Konqueror nettleser
-Name[nds]=Konqueror vörladen
-Name[nl]=Konqueror browser preloader-module
-Name[nn]=Førehandslastar for nettlesaren Konqueror
-Name[pa]=ਕੋਨਕਿਉਰੋਰ ਬਰਾਊਜ਼ਰ ਪਹਿਲਾਂ ਲੋਡ ਮੋਡੀਊਲ
-Name[pl]=Wstępne wczytywanie dla Konquerora
-Name[pt]=Pré-Carregamento do Navegador Konqueror
-Name[pt_BR]=Pré-carregamento do navegador Konqueror
-Name[ro]=Preîncărcare Konqueror
-Name[ru]=Предварительная загрузка веб-браузера Konqueror
-Name[si]=Konqueror ගවේශක පෙර ආරම්භකය
-Name[sk]=Prednahratie prehliadača Konqueror
-Name[sl]=Prednalagalnik brskalnika Konqueror
-Name[sr]=Предучитавач К‑освајача
-Name[sr at ijekavian]=Предучитавач К‑освајача
-Name[sr at ijekavianlatin]=Predučitavač K‑osvajača
-Name[sr at latin]=Predučitavač K‑osvajača
-Name[sv]=Ladda Konqueror webbläsare i förväg
-Name[tg]=Боркунии пешакии браузери Konqueror
-Name[th]=ตัวโหลด Konqueror ล่วงหน้า
-Name[tr]=Konqueror Tarayıcı Önyükleyicisi
-Name[ug]=Konqueror توركۆرگۈ ئالدىن يۈكلىگۈچ
-Name[uk]=Попереднє завантаження переглядача Konqueror
-Name[wa]=Prétcherdjeu do betchteu di Konqueror
-Name[x-test]=xxKonqueror Browser Preloaderxx
-Name[zh_CN]=Konqueror 浏览器预加载器
-Name[zh_TW]=Konqueror 瀏覽器預先載入模組
-Comment=Reduces Konqueror startup time
-Comment[af]=Verminder Konqueror se opstart tyd
-Comment[ar]=يقلّل من وقت بدء تشغيل كونكيورر
-Comment[as]=Konqueror আৰম্ভণিৰ সময় কম কৰে
-Comment[ast]=Reduz el tiempu d'aniciu de Konqueror
-Comment[be]=Змяншае час запуску Konqueror
-Comment[be at latin]=Źmianšaje čas, patrebny dla ŭklučeńnia prahramy „Konqueror”
-Comment[bg]=Ускорява зареждането на браузъра Konqueror
-Comment[bn]=কনকরার চালু করার সময় কমায়
-Comment[bn_IN]=Konqueror আরম্ভ করতে ব্যবহৃত সময় হ্রাস করে
-Comment[bs]=Smanjuje vrijeme pokretanja K‑osvajača
-Comment[ca]=Redueix el temps d'inici del Konqueror
-Comment[ca at valencia]=Redueix el temps d'inici del Konqueror
-Comment[cs]=Redukuje čas pro spuštění Konqueroru
-Comment[csb]=Zmiészô czas zrëszaniô Konquerora
-Comment[cy]=Lleihau amser ymgychwyn Konqueror
-Comment[da]=Reducerer Konquerors opstartstid
-Comment[de]=Lädt Konqueror im Voraus und verringert so die Ladezeit
-Comment[el]=Μειώνει το χρόνο εκκίνησης του Konqueror
-Comment[en_GB]=Reduces Konqueror startup time
-Comment[eo]=Mallongigas la Konkerantan startotempon
-Comment[es]=Reduce el tiempo de inicio de Konqueror
-Comment[et]=Kahandab Konquerori käivitamise aega
-Comment[eu]=Konquerorren abiatze denbora laburtzen du
-Comment[fa]=زمان راه‌اندازی Konqueror را کاهش می‌دهد
-Comment[fi]=Vähentää Konquerorin käynnistysaikaa
-Comment[fr]=Réduit le temps de démarrage de Konqueror
-Comment[fy]=Redusearret de begjintiid fan Konqueror
-Comment[ga]=Laghdaíonn sé seo an t-am chun Konqueror a thosú
-Comment[gl]=Reduce o tempo de inicio de Konqueror
-Comment[gu]=કોન્કરર શરૂઆત સમય ઘટાડે છે
-Comment[he]=בשביל להקטין את זמן ההפעלה של Konqueror
-Comment[hi]=कॉन्करर के चालू होने के समय को कम करता है
-Comment[hne]=कान्करर के चालू होए के समय ल कम करथे 
-Comment[hr]=Ubrzava pokretanje Konquerora
-Comment[hsb]=Zredukuje čas za wuwjedźenje konquerora
-Comment[hu]=A Konqueror elindulási idejének lecsökkentése
-Comment[ia]=Il reduce tempore de startar de Konqueror
-Comment[id]=Kurangi waktu hidupkan Konqueror
-Comment[is]=Dregur úr ræsingatíma Konqueror vafrans
-Comment[it]=Riduce il tempo di avvio di Konqueror
-Comment[ja]=Konqueror の起動時間を短縮します
-Comment[ka]=ამცირებს Konqueror-ის გაშვების დროს
-Comment[kk]=Konqueror-ді жүктеу уақытын қысқартады
-Comment[km]=បន្ថយ​រយៈពេល​ចាប់ផ្ដើម​របស់ Konqueror
-Comment[kn]=ಕಾಂಕರರ್ ಪ್ರಾರಂಭಕ್ಕೆ  ಸಮಯ ಕಡಿಮೆಮಾಡುತ್ತದೆ
-Comment[ko]=Konqueror 시작 시간을 줄입니다
-Comment[ku]=Dema vebûna konwuerorê Kêm Dike
-Comment[lt]=Sutrumpina Konqueror paleidimo laiką
-Comment[lv]=Samazina Konqueror palaišanas laiku
-Comment[mai]=कान्करर केर चालू हएबाक समय केँ कम करैत अछि
-Comment[mk]=Го намалува времето за стартување на Konqueror
-Comment[ml]=കോണ്‍ക്വറര്‍ തുടങ്ങുന്നതിനുള്ള സമയം കുറയ്ക്കുന്നു
-Comment[mr]=कॉन्करर चालू होतेवेळी प्रारंभ वेळ कमी करतो
-Comment[ms]=Mengurangkan masa pemulaan Konqueror
-Comment[nb]=Reduserer oppstartstida for Konqueror
-Comment[nds]=Bringt de Starttiet vun Konqueror daal
-Comment[ne]=कन्क्वेरर सुरुआत समय घटाउँछ
-Comment[nl]=Reduceert de opstarttijd van Konqueror
-Comment[nn]=Reduserer oppstartstida til Konqueror
-Comment[or]=Reduces Konqueror startup time
-Comment[pa]=ਕੋਨਕਿਉਰੋਰ ਸਟਾਰਟਅੱਪ ਟਾਈਮ ਘਟਾਉਦਾ ਹੈ
-Comment[pl]=Zmniejsza czas uruchomienia Konquerora
-Comment[pt]=Reduz o tempo de arranque do Konqueror
-Comment[pt_BR]=Reduz o tempo de inicialização do Konqueror
-Comment[ro]=Reduce timpul de pornire al Konqueror
-Comment[ru]=Предварительная загрузка Konqueror во время запуска KDE
-Comment[se]=Unnida Konquerora álggahanáiggi
-Comment[si]=Konqueror ආරම්භක කාලය අඩු කරයි
-Comment[sk]=Zmenšuje dobu štartu Konquerora
-Comment[sl]=Skrajša zagonski čas brskalnika Konqueror
-Comment[sr]=Смањује време покретања К‑освајача
-Comment[sr at ijekavian]=Смањује вријеме покретања К‑освајача
-Comment[sr at ijekavianlatin]=Smanjuje vrijeme pokretanja K‑osvajača
-Comment[sr at latin]=Smanjuje vreme pokretanja K‑osvajača
-Comment[sv]=Minskar Konquerors starttid
-Comment[ta]=கான்கொரர் துவக்க நேரத்தை குறைக்கிறது
-Comment[te]=కాంకెరర్ మొదలు సమయాన్ని తగ్గించును
-Comment[tg]=Вақти боркунии Konqueror кам мекунад
-Comment[th]=ลดเวลาที่ใช้เริ่มทำงานของ Konqueror
-Comment[tr]=Konqueror açılış zamanını azaltır
-Comment[ug]=Konqueror قوزغىلىش ۋاقتىنى قىسقارتىدۇ
-Comment[uk]=Зменшує час запуску Konqueror
-Comment[uz]=Konqueror ishga tushish vaqtini kamaytirish
-Comment[uz at cyrillic]=Konqueror ишга тушиш вақтини камайтириш
-Comment[vi]=Giảm thời gian khởi chạy Konqueror
-Comment[wa]=Rind pus cout l' tins d' enondaedje di Konqueror
-Comment[x-test]=xxReduces Konqueror startup timexx
-Comment[zh_CN]=减少 Konqueror 的启动时间
-Comment[zh_TW]=減少 Konqueror 啟動時間
-X-KDE-ServiceTypes=KDEDModule
-X-KDE-Library=konqy_preloader
-X-KDE-DBus-ModuleName=konqy_preloader
-X-KDE-Kded-autoload=false
-X-KDE-Kded-load-on-demand=true
diff --git a/konqueror/preloader/org.kde.konqueror.Preloader.xml b/konqueror/preloader/org.kde.konqueror.Preloader.xml
deleted file mode 100644
index 3e846ce..0000000
--- a/konqueror/preloader/org.kde.konqueror.Preloader.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
-"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
-<node>
-  <interface name="org.kde.konqueror.Preloader">
-
-    <method name="registerPreloadedKonqy">
-      <arg name="id" type="s" direction="in"/>
-      <arg name="screen" type="i" direction="in"/>
-      <arg type="b" direction="out"/>
-    </method>
-
-    <method name="getPreloadedKonqy">
-      <arg name="screen" type="i" direction="in"/>
-      <arg type="s" direction="out"/>
-    </method>
-
-    <method name="unregisterPreloadedKonqy">
-      <arg name="id" type="s" direction="in"/>
-      <annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
-    </method>
-
-    <method name="reconfigure"/>
-    <method name="unloadAllPreloaded"/>
-
-  </interface>
-</node>
diff --git a/konqueror/preloader/preloader.cc b/konqueror/preloader/preloader.cc
deleted file mode 100644
index 6ba0ef0..0000000
--- a/konqueror/preloader/preloader.cc
+++ /dev/null
@@ -1,151 +0,0 @@
-/* This file is part of the KDE project
-   Copyright (C) 2002 Lubos Lunak <l.lunak at kde.org>
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public
-   License as published by the Free Software Foundation; either
-   version 2 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public License
-   along with this library; see the file COPYING.LIB.  If not, write to
-   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.
-*/
-
-#include "preloader.h"
-#include "konqsettingsxt.h"
-#include "preloaderadaptor.h"
-
-#include <QProcess>
-
-#include <KPluginFactory>
-#include <KPluginLoader>
-
-K_PLUGIN_FACTORY(KonqyPreloaderFactory,
-                 registerPlugin<KonqyPreloader>();
-                )
-K_EXPORT_PLUGIN(KonqyPreloaderFactory("konqypreloader"))
-
-KonqyPreloader::KonqyPreloader(QObject *parent, const QList<QVariant> &)
-    : KDEDModule(parent)
-{
-    reconfigure();
-
-    (void)new PreloaderAdaptor(this);
-
-    connect(QDBusConnection::sessionBus().interface(),
-            SIGNAL(serviceOwnerChanged(const QString &, const QString &, const QString &)),
-            SLOT(appChanged(const QString &, const QString &, const QString &)));
-    check_always_preloaded_timer.setSingleShot(true);
-    connect(&check_always_preloaded_timer, SIGNAL(timeout()),
-            SLOT(checkAlwaysPreloaded()));
-}
-
-KonqyPreloader::~KonqyPreloader()
-{
-    updateCount();
-}
-
-bool KonqyPreloader::registerPreloadedKonqy(const QString &id, int screen)
-{
-    if (instances.count() >= KonqSettings::maxPreloadCount()) {
-        return false;
-    }
-    instances.append(KonqyData(id, screen));
-    return true;
-}
-
-QString KonqyPreloader::getPreloadedKonqy(int screen)
-{
-    if (instances.count() == 0) {
-        return "";
-    }
-    for (InstancesList::Iterator it = instances.begin();
-            it != instances.end();
-            ++it) {
-        if ((*it).screen == screen) {
-            QString ret = (*it).id;
-            instances.erase(it);
-            check_always_preloaded_timer.start(5000);
-            return ret;
-        }
-    }
-    return "";
-}
-
-void KonqyPreloader::unregisterPreloadedKonqy(const QString &id_P)
-{
-    for (InstancesList::Iterator it = instances.begin();
-            it != instances.end();
-            ++it)
-        if ((*it).id == id_P) {
-            instances.erase(it);
-            return;
-        }
-}
-
-void KonqyPreloader::appChanged(const QString & /*id*/,  const QString &oldOwner, const QString &newOwner)
-{
-    if (oldOwner.isEmpty() || !newOwner.isEmpty()) {
-        return;
-    }
-
-    unregisterPreloadedKonqy(oldOwner);
-}
-
-void KonqyPreloader::reconfigure()
-{
-    KonqSettings::self()->load();
-    updateCount();
-    // Ignore "PreloadOnStartup" here, it's used by the .desktop file
-    // in the autostart folder, which will do 'konqueror --preload' in autostart
-    // phase 2. This will also cause activation of this kded module.
-}
-
-void KonqyPreloader::updateCount()
-{
-    while (instances.count() > KonqSettings::maxPreloadCount()) {
-        KonqyData konqy = instances.first();
-        instances.pop_front();
-        QDBusInterface ref(konqy.id, "/", "org.kde.Konqueror.Main");
-        ref.call("terminatePreloaded");
-    }
-    if (KonqSettings::alwaysHavePreloaded() &&
-            KonqSettings::maxPreloadCount() > 0 &&
-            instances.count() == 0) {
-        if (!check_always_preloaded_timer.isActive()) {
-            const QStringList args = { QStringLiteral("--preload") };
-            QProcess::startDetached(QStringLiteral("konqueror"), args);
-            qDebug() << "Preloading Konqueror instance";
-            check_always_preloaded_timer.start(5000);
-        }
-    }
-}
-
-// have 5s interval between attempts to preload a new konqy
-// in order not to start many of them at the same time
-void KonqyPreloader::checkAlwaysPreloaded()
-{
-    // TODO here should be detection whether the system is too busy,
-    // and delaying preloading another konqy in such case
-    // but I have no idea how to do it
-    updateCount();
-}
-
-void KonqyPreloader::unloadAllPreloaded()
-{
-    while (instances.count() > 0) {
-        KonqyData konqy = instances.first();
-        instances.pop_front();
-        QDBusInterface ref(konqy.id, "/", "org.kde.Konqueror.Main");
-        ref.call("terminatePreloaded");
-    }
-    // ignore 'always_have_preloaded' here
-}
-
-#include "preloader.moc"
diff --git a/konqueror/preloader/preloader.h b/konqueror/preloader/preloader.h
deleted file mode 100644
index f3277b4..0000000
--- a/konqueror/preloader/preloader.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* This file is part of the KDE project
-   Copyright (C) 2002 Lubos Lunak <l.lunak at kde.org>
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public
-   License as published by the Free Software Foundation; either
-   version 2 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public License
-   along with this library; see the file COPYING.LIB.  If not, write to
-   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.
-*/
-
-#ifndef _KONQUEROR_PRELOADER_H
-#define _KONQUEROR_PRELOADER_H
-
-#include <kdedmodule.h>
-#include <QtCore/QTimer>
-
-class KonqyPreloader
-    : public KDEDModule
-{
-    Q_OBJECT
-    Q_CLASSINFO("D-Bus Interface", "org.kde.konqueror.Preloader")
-
-public:
-    KonqyPreloader(QObject *parent, const QList<QVariant> &);
-    virtual ~KonqyPreloader();
-
-public Q_SLOTS:
-    bool registerPreloadedKonqy(const QString &id, int screen);
-    QString getPreloadedKonqy(int screen);
-    void unregisterPreloadedKonqy(const QString &id);
-    void reconfigure();
-    void unloadAllPreloaded();
-private Q_SLOTS:
-    void appChanged(const QString &id, const QString &oldOwner, const QString &newOwner);
-    void checkAlwaysPreloaded();
-private:
-    void updateCount();
-    struct KonqyData {
-        KonqyData() {} // for QValueList
-        KonqyData(const QString &id_P, int screen_P)
-            : id(id_P), screen(screen_P) {}
-        QString id;
-        int screen;
-    };
-    typedef QList< KonqyData > InstancesList;
-    InstancesList instances;
-    QTimer check_always_preloaded_timer;
-};
-
-#endif
diff --git a/konqueror/settings/performance/konqueror.cpp b/konqueror/settings/performance/konqueror.cpp
index 8fb3838..0ff8e45 100644
--- a/konqueror/settings/performance/konqueror.cpp
+++ b/konqueror/settings/performance/konqueror.cpp
@@ -30,77 +30,48 @@ namespace KCMPerformance
 Konqueror::Konqueror(QWidget *parent_P)
     : Konqueror_ui(parent_P)
 {
-    QString tmp =
-        i18n("<p>If non-zero, this option allows keeping Konqueror instances "
-             "in memory after all their windows have been closed, up to the "
-             "number specified in this option.</p>"
-             "<p>When a new Konqueror instance is needed, one of these preloaded "
-             "instances will be reused instead, improving responsiveness at "
-             "the expense of the memory required by the preloaded instances.</p>");
-    sb_preload_count->setWhatsThis(tmp);
-    lb_preload_count->setWhatsThis(tmp);
+    // TODO move these strings to konqueror.kcfg and use that from here
     cb_preload_on_startup->setWhatsThis(
-        i18n("<p>If enabled, an instance of Konqueror will be preloaded after the ordinary KDE "
+        i18n("<p>If enabled, an instance of Konqueror will be preloaded after the ordinary Plasma "
              "startup sequence.</p>"
              "<p>This will make the first Konqueror window open faster, but "
-             "at the expense of longer KDE startup times (but you will be able to work "
+             "at the expense of longer Plasma startup times (but you will be able to work "
              "while it is loading, so you may not even notice that it is taking longer).</p>"));
     cb_always_have_preloaded->setWhatsThis(
-        i18n("<p>If enabled, KDE will always try to have one preloaded Konqueror instance ready; "
+        i18n("<p>If enabled, Konqueror will always try to have one preloaded instance ready; "
              "preloading a new instance in the background whenever there is not one available, "
              "so that windows will always open quickly.</p>"
              "<p><b>Warning:</b> In some cases, it is actually possible that this will "
              "reduce perceived performance.</p>"));
-    connect(sb_preload_count, SIGNAL(valueChanged(int)), SLOT(preload_count_changed(int)));
-    connect(sb_preload_count, SIGNAL(valueChanged(int)), SIGNAL(changed()));
     connect(cb_preload_on_startup, SIGNAL(toggled(bool)), SIGNAL(changed()));
     connect(cb_always_have_preloaded, SIGNAL(toggled(bool)), SIGNAL(changed()));
     defaults();
 }
 
-void Konqueror::preload_count_changed(int count)
-{
-    cb_preload_on_startup->setEnabled(count >= 1);
-    // forcing preloading with count == 1 can often do more harm than good, because
-    // if there's one konqy preloaded, and the user requests "starting" new konqueror,
-    // the preloaded instance will be used, new one will be preloaded, and if the user soon
-    // "quits" konqueror, one of the instances will have to be terminated
-    cb_always_have_preloaded->setEnabled(count >= 2);
-}
-
 void Konqueror::load()
 {
     KConfig _cfg("konquerorrc");
     KConfigGroup cfg(&_cfg, "Reusing");
-    sb_preload_count->setValue(cfg.readEntry("MaxPreloadCount", 1));
-    cb_always_have_preloaded->setChecked(cfg.readEntry("AlwaysHavePreloaded", false));
     cb_preload_on_startup->setChecked(cfg.readEntry("PreloadOnStartup", false));
+    cb_always_have_preloaded->setChecked(cfg.readEntry("AlwaysHavePreloaded", true));
 }
 
 void Konqueror::save()
 {
     KConfig _cfg("konquerorrc");
     KConfigGroup cfg(&_cfg, "Reusing");
-    int count = sb_preload_count->value();
-    cfg.writeEntry("MaxPreloadCount", count);
-    cfg.writeEntry("PreloadOnStartup", cb_preload_on_startup->isChecked() && count >= 1);
-    cfg.writeEntry("AlwaysHavePreloaded", cb_always_have_preloaded->isChecked() && count >= 2);
+    cfg.writeEntry("PreloadOnStartup", cb_preload_on_startup->isChecked());
+    cfg.writeEntry("AlwaysHavePreloaded", cb_always_have_preloaded->isChecked());
     cfg.sync();
     QDBusMessage message =
         QDBusMessage::createSignal("/KonqMain", "org.kde.Konqueror.Main", "reparseConfiguration");
     QDBusConnection::sessionBus().send(message);
-
-    QDBusInterface kded("org.kde.kded5", "/modules/konqy_preloader", "org.kde.konqueror.Preloader");
-    kded.call("reconfigure");
 }
 
 void Konqueror::defaults()
 {
-    sb_preload_count->setValue(1);
     cb_preload_on_startup->setChecked(false);
-    cb_always_have_preloaded->setChecked(false);
-    preload_count_changed(sb_preload_count->value());
+    cb_always_have_preloaded->setChecked(true);
 }
 
 } // namespace
-
diff --git a/konqueror/settings/performance/konqueror.h b/konqueror/settings/performance/konqueror.h
index c326740..db919af 100644
--- a/konqueror/settings/performance/konqueror.h
+++ b/konqueror/settings/performance/konqueror.h
@@ -45,8 +45,6 @@ public:
     void defaults();
 Q_SIGNALS:
     void changed();
-private Q_SLOTS:
-    void preload_count_changed(int);
 };
 
 }  // namespace
diff --git a/konqueror/settings/performance/konqueror_ui.ui b/konqueror/settings/performance/konqueror_ui.ui
index 914e92b..b1662a1 100644
--- a/konqueror/settings/performance/konqueror_ui.ui
+++ b/konqueror/settings/performance/konqueror_ui.ui
@@ -18,54 +18,6 @@
      </property>
      <layout class="QVBoxLayout">
       <item>
-       <layout class="QHBoxLayout">
-        <property name="leftMargin">
-         <number>0</number>
-        </property>
-        <property name="topMargin">
-         <number>0</number>
-        </property>
-        <property name="rightMargin">
-         <number>0</number>
-        </property>
-        <property name="bottomMargin">
-         <number>0</number>
-        </property>
-        <item>
-         <widget class="QLabel" name="lb_preload_count">
-          <property name="text">
-           <string>&Maximum number of instances kept preloaded:</string>
-          </property>
-          <property name="wordWrap">
-           <bool>false</bool>
-          </property>
-          <property name="buddy">
-           <cstring>sb_preload_count</cstring>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QSpinBox" name="sb_preload_count"/>
-        </item>
-        <item>
-         <spacer name="spacer2">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeType">
-           <enum>QSizePolicy::Expanding</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>40</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-       </layout>
-      </item>
-      <item>
        <widget class="QCheckBox" name="cb_preload_on_startup">
         <property name="text">
          <string>Preload an instance after KDE startup</string>
@@ -75,7 +27,7 @@
       <item>
        <widget class="QCheckBox" name="cb_always_have_preloaded">
         <property name="text">
-         <string>Always try to have at least one preloaded instance</string>
+         <string>Always try to have one preloaded instance</string>
         </property>
        </widget>
       </item>
diff --git a/konqueror/src/CMakeLists.txt b/konqueror/src/CMakeLists.txt
index d71e798..c6ecd25 100644
--- a/konqueror/src/CMakeLists.txt
+++ b/konqueror/src/CMakeLists.txt
@@ -110,6 +110,7 @@ target_link_libraries(kdeinit_konqueror
    KF5::KCMUtils
    KF5::Konq
    KF5::Parts
+   KF5::DBusAddons
    KF5::KDELibs4Support
    KF5::Crash
 )
diff --git a/konqueror/src/KonquerorAdaptor.cpp b/konqueror/src/KonquerorAdaptor.cpp
index 9301503..8a970ca 100644
--- a/konqueror/src/KonquerorAdaptor.cpp
+++ b/konqueror/src/KonquerorAdaptor.cpp
@@ -126,7 +126,7 @@ QDBusObjectPath KonquerorAdaptor::windowForTab()
         foreach (KonqMainWindow *window, *mainWindows) {
             KWindowInfo winfo(window->winId(), NET::WMDesktop);
             if (winfo.isOnCurrentDesktop() &&
-                    !KonqPreloadingHandler::self()->isPreloaded()) {  // we want a tab in an already shown window
+                    !KonqPreloadingHandler::self()->hasPreloadedWindow()) {  // we want a tab in an already shown window
                 Q_ASSERT(!window->dbusName().isEmpty());
                 return QDBusObjectPath(window->dbusName());
             }
@@ -136,11 +136,3 @@ QDBusObjectPath KonquerorAdaptor::windowForTab()
     // So we use "/" as an indicator for not found.
     return QDBusObjectPath("/");
 }
-
-
-void KonquerorAdaptor::terminatePreloaded()
-{
-    if (KonqPreloadingHandler::self()->isPreloaded()) {
-        qApp->exit();
-    }
-}
diff --git a/konqueror/src/KonquerorAdaptor.h b/konqueror/src/KonquerorAdaptor.h
index 6133854..4240932 100644
--- a/konqueror/src/KonquerorAdaptor.h
+++ b/konqueror/src/KonquerorAdaptor.h
@@ -77,12 +77,6 @@ public slots:
      */
     QDBusObjectPath windowForTab();
 
-    /**
-     * Called from konqy_preloader to terminate this Konqueror instance,
-     * if it's in the preloaded mode, and there are too many preloaded Konqy's
-     */
-    Q_NOREPLY void terminatePreloaded();
-
 Q_SIGNALS:
     /**
      * Emitted by kcontrol when the global configuration changes
diff --git a/konqueror/src/konqmain.cpp b/konqueror/src/konqmain.cpp
index 7804324..deda918 100644
--- a/konqueror/src/konqmain.cpp
+++ b/konqueror/src/konqmain.cpp
@@ -1,5 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 1998, 1999 Simon Hausmann <hausmann at kde.org>
+   Copyright (C) 2016 David Faure <faure at kde.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
@@ -28,21 +29,18 @@
 #include "konqsettingsxt.h"
 
 #include <KLocalizedString>
-#include <kstandarddirs.h>
-#include <QDebug>
 #include <kcmdlineargs.h>
-#include <kglobal.h>
-#include <QtCore/QFile>
 
 #include <config-konqueror.h>
-#if KONQ_HAVE_X11
-#include <QX11Info>
-#endif
 
-#include <QtDBus/QtDBus>
+#include <QDebug>
+#include <QFile>
 #include <QDir>
+#include <QDirIterator>
 #include <QStandardPaths>
 
+#include <KDBusAddons/KDBusService>
+
 static void listSessions()
 {
     const QString dir = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + "sessions/";
@@ -55,26 +53,6 @@ static void listSessions()
 
 static KonqPreloadingHandler s_preloadingHandler;
 
-static bool tryPreload()
-{
-#if KONQ_HAVE_X11
-    if (QX11Info::isPlatformX11() && KonqSettings::maxPreloadCount() > 0) {
-        QDBusInterface ref("org.kde.kded5", "/modules/konqy_preloader", "org.kde.konqueror.Preloader", QDBusConnection::sessionBus());
-        QDBusReply<bool> retVal = ref.call(QDBus::Block, "registerPreloadedKonqy", QDBusConnection::sessionBus().baseService(), QX11Info::appScreen());
-        if (!retVal) {
-            return false;    // too many preloaded or failed
-        }
-        s_preloadingHandler.makePreloadedWindow();
-        qDebug() << "Konqy preloaded :" << QDBusConnection::sessionBus().baseService();
-        return true;
-    } else {
-        return false; // no preloading
-    }
-#else
-    return false; // no preloading
-#endif
-}
-
 extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
 {
     KCmdLineArgs::init(argc, argv, KonqFactory::aboutData());
@@ -104,6 +82,8 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
     KonquerorApplication app(argc, argv);
     KLocalizedString::setApplicationDomain("konqueror");
 
+    KDBusService dbusService(KDBusService::Multiple);
+
     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
     if (app.isSessionRestored()) {
@@ -122,7 +102,7 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
     } else {
         // First the invocations that do not take urls.
         if (args->isSet("preload")) {
-            if (!tryPreload()) {
+            if (!s_preloadingHandler.registerAsPreloaded()) {
                 return 0;    // no preloading
             }
         } else if (args->isSet("sessions")) {
@@ -203,12 +183,15 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
     }
     args->clear();
 
-    app.exec();
+    // In case there is no `konqueror --preload` running, start one
+    // (not this process, it might exit before the preloading is used)
+    s_preloadingHandler.ensurePreloadedProcessExists();
+
+    const int ret = app.exec();
 
     // Delete all KonqMainWindows, so that we don't have
     // any parts loaded when KLibLoader::cleanUp is called.
-    // Their deletion was postponed in their event()
-    // (and Qt doesn't delete WDestructiveClose widgets on exit anyway :()
+    // (and Qt doesn't delete WA_DeleteOnClose widgets on exit anyway :()
     while (KonqMainWindow::mainWindowList() != NULL) {
         // the list will be deleted by last KonqMainWindow
         delete KonqMainWindow::mainWindowList()->first();
@@ -218,5 +201,5 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
     KonqSessionManager::self()->disableAutosave();
     KonqSessionManager::self()->deleteOwnedSessions();
 
-    return 0;
+    return ret;
 }
diff --git a/konqueror/src/konqmainwindow.cpp b/konqueror/src/konqmainwindow.cpp
index 31c05f2..0d0d2a7 100644
--- a/konqueror/src/konqmainwindow.cpp
+++ b/konqueror/src/konqmainwindow.cpp
@@ -49,7 +49,6 @@
 #include "konqbookmarkbar.h"
 #include "konqundomanager.h"
 #include "konqhistorydialog.h"
-#include "konqpreloadinghandler.h"
 #include <config-konqueror.h>
 #include <kstringhandler.h>
 
@@ -79,11 +78,11 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-#include <QtCore/QFile>
+#include <QDesktopServices>
+#include <QFile>
 #include <QClipboard>
-#include <QtCore/QArgument>
 #include <QStackedWidget>
-#include <QtCore/QFileInfo>
+#include <QFileInfo>
 #if KONQ_HAVE_X11
 #include <QX11Info>
 #endif
@@ -145,10 +144,6 @@
 #include <kxmlguifactory.h>
 #include <netwm.h>
 #include <sonnet/configdialog.h>
-#ifdef KDE_MALLINFO_MALLOC
-#include <QDesktopServices>
-#include <malloc.h>
-#endif
 
 #include <sys/time.h>
 #if KONQ_HAVE_X11
@@ -169,21 +164,14 @@
 template class QList<QPixmap *>;
 template class QList<KToggleAction *>;
 
-KBookmarkManager *s_bookmarkManager = 0;
+static KBookmarkManager *s_bookmarkManager = 0;
 QList<KonqMainWindow *> *KonqMainWindow::s_lstViews = 0;
 KConfig *KonqMainWindow::s_comboConfig = 0;
 KCompletion *KonqMainWindow::s_pCompletion = 0;
 
-static qint64 s_initialMemoryUsage = -1;
-static time_t s_startupTime;
-static int s_preloadUsageCount;
-
 KonqOpenURLRequest KonqOpenURLRequest::null;
 
-static qint64 current_memory_usage(int *limit = NULL);
-
 static const unsigned short int s_closedItemsListLength = 10;
-static unsigned long s_konqMainWindowInstancesCount = 0;
 
 static void raiseWindow(KonqMainWindow *window)
 {
@@ -217,8 +205,6 @@ KonqMainWindow::KonqMainWindow(const QUrl &initialURL)
     , m_pURLCompletion(0)
     , m_isPopupWithProxyWindow(false)
 {
-    incInstancesCount();
-
     if (!s_lstViews) {
         s_lstViews = new QList<KonqMainWindow *>;
     }
@@ -322,13 +308,8 @@ KonqMainWindow::KonqMainWindow(const QUrl &initialURL)
 
     resize(700, 480);
 
-    //qDebug() << this << "done";
+    //qDebug() << this << "created";
 
-    if (s_initialMemoryUsage == -1) {
-        s_initialMemoryUsage = current_memory_usage();
-        s_startupTime = time(NULL);
-        s_preloadUsageCount = 0;
-    }
     KonqSessionManager::self();
     m_fullyConstructed = true;
 }
@@ -370,19 +351,8 @@ KonqMainWindow::~KonqMainWindow()
     m_locationLabel = 0;
     m_pUndoManager->disconnect();
     delete m_pUndoManager;
-    decInstancesCount();
-
-    //qDebug() << this << "done";
-}
 
-void KonqMainWindow::incInstancesCount()
-{
-    s_konqMainWindowInstancesCount++;
-}
-
-void KonqMainWindow::decInstancesCount()
-{
-    s_konqMainWindowInstancesCount--;
+    //qDebug() << this << "deleted";
 }
 
 QWidget *KonqMainWindow::createContainer(QWidget *parent, int index, const QDomElement &element, QAction *&containerAction)
@@ -3348,17 +3318,6 @@ void KonqMainWindow::slotUpdateFullScreen(bool set)
         m_prevMenuBarVisible = menuBar()->isVisible();
         menuBar()->hide();
         m_paShowMenuBar->setChecked(false);
-
-        // Qt bug, the flags are lost. They know about it.
-        // happens only with the hackish non-_NET_WM_STATE_FULLSCREEN way
-        setAttribute(Qt::WA_DeleteOnClose);
-        // Qt bug (see below)
-//### KDE4: still relevant?
-#if 0
-        setAcceptDrops(false);
-        topData()->dnd = 0;
-        setAcceptDrops(true);
-#endif
     } else {
         unplugActionList("fullscreen");
 
@@ -3366,21 +3325,6 @@ void KonqMainWindow::slotUpdateFullScreen(bool set)
             menuBar()->show();
             m_paShowMenuBar->setChecked(true);
         }
-
-        // Qt bug, the flags aren't restored. They know about it.
-        //setWFlags( WType_TopLevel | WDestructiveClose );
-#ifdef __GNUC__
-#warning "Dunno how to port this, is the workaround still needed?"
-#endif
-//                (  Qt::Window );
-        setAttribute(Qt::WA_DeleteOnClose);
-
-#if 0 //### KDE4: is this still relevant?
-        // Other Qt bug
-        setAcceptDrops(false);
-        topData()->dnd = 0;
-        setAcceptDrops(true);
-#endif
     }
 }
 
@@ -5020,9 +4964,6 @@ void KonqMainWindow::closeEvent(QCloseEvent *e)
         }
 
         addClosedWindowToUndoList();
-
-        hide();
-        qApp->flush();
     }
     // We're going to close - tell the parts
     MapViews::ConstIterator it = m_mapViews.constBegin();
@@ -5033,10 +4974,6 @@ void KonqMainWindow::closeEvent(QCloseEvent *e)
         }
     }
     KParts::MainWindow::closeEvent(e);
-    if (qApp && !qApp->isSavingSession() && stayPreloaded()) {
-        e->ignore();
-        hide();
-    }
 }
 
 void KonqMainWindow::addClosedWindowToUndoList()
@@ -5537,17 +5474,7 @@ bool KonqMainWindow::refuseExecutingKonqueror(const QString &mimeType)
 
 bool KonqMainWindow::event(QEvent *e)
 {
-    if (e->type() == QEvent::DeferredDelete) {
-        // since the preloading code tries to reuse KonqMainWindow,
-        // the last window shouldn't be really deleted, but only hidden
-        // deleting WDestructiveClose windows is done using deleteLater(),
-        // so catch QEvent::DeferredDelete and check if this window should stay
-        if (stayPreloaded()) {
-            setAttribute(Qt::WA_DeleteOnClose); // was reset before deleteLater()
-            return true; // no deleting
-        }
-
-    } else if (e->type() == QEvent::StatusTip) {
+    if (e->type() == QEvent::StatusTip) {
         if (m_currentView && m_currentView->frame()->statusbar()) {
             KonqFrameStatusBar *statusBar = m_currentView->frame()->statusbar();
             statusBar->message(static_cast<QStatusTipEvent *>(e)->tip());
@@ -5581,131 +5508,11 @@ bool KonqMainWindow::event(QEvent *e)
     return KParts::MainWindow::event(e);
 }
 
-bool KonqMainWindow::stayPreloaded()
-{
-#if KONQ_HAVE_X11
-    // last window?
-    if (mainWindowList()->count() > 1) {
-        return false;
-    }
-    // not running in full KDE environment?
-    if (getenv("KDE_FULL_SESSION") == NULL || getenv("KDE_FULL_SESSION")[ 0 ] == '\0') {
-        return false;
-    }
-    // not the same user like the one running the session (most likely we're run via sudo or something)
-    if (getenv("KDE_SESSION_UID") != NULL && uid_t(atoi(getenv("KDE_SESSION_UID"))) != getuid()) {
-        return false;
-    }
-    if (KonqSettings::maxPreloadCount() == 0) {
-        return false;
-    }
-    viewManager()->clear(); // reduce resource usage before checking it
-    if (!checkPreloadResourceUsage()) {
-        return false;
-    }
-    QDBusInterface ref("org.kde.kded5", "/modules/konqy_preloader", "org.kde.konqueror.Preloader", QDBusConnection::sessionBus());
-    QDBusReply<bool> retVal = ref.call(QDBus::Block, "registerPreloadedKonqy", QDBusConnection::sessionBus().baseService(), QX11Info::appScreen());
-    if (!retVal) {
-        return false;
-    }
-    qDebug() << "Konqy kept for preloading:" << QDBusConnection::sessionBus().baseService();
-    KonqPreloadingHandler::self()->makePreloadedWindow();
-    return true;
-#else
-    return false;
-#endif
-}
-
-// try to avoid staying running when leaking too much memory
-// this is checked by using mallinfo() and comparing
-// memory usage during konqy startup and now, if the difference
-// is too large -> leaks -> quit
-// also, if this process is running for too long, or has been
-// already reused too many times -> quit, just in case
-bool KonqMainWindow::checkPreloadResourceUsage()
-{
-    if (
-#ifndef NDEBUG
-        isatty(STDIN_FILENO) ||
-#endif
-        isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) {
-        qDebug() << "Running from tty, not keeping for preloading";
-        return false;
-    }
-    int limit;
-    qint64 usage = current_memory_usage(&limit);
-    qDebug() << "Memory usage increase: " << (usage - s_initialMemoryUsage)
-             << " (" << usage << " - " << s_initialMemoryUsage << "), increase limit: " << limit;
-    const qint64 max_allowed_usage = s_initialMemoryUsage + limit;
-    if (usage > max_allowed_usage) { // too much memory used?
-        qDebug() << "Not keeping for preloading due to high memory usage";
-        return false;
-    }
-    // working memory usage test ( usage != 0 ) makes others less strict
-    if (++s_preloadUsageCount > (usage != 0 ? 100 : 10)) { // reused too many times?
-        qDebug() << "Not keeping for preloading due to high usage count";
-        return false;
-    }
-    if (time(NULL) > s_startupTime + 60 * 60 * (usage != 0 ? 4 : 1)) {   // running for too long?
-        qDebug() << "Not keeping for preloading due to long usage time";
-        return false;
-    }
-    return true;
-}
-
-static qint64 current_memory_usage(int *limit)
-{
-#ifdef __linux__  //krazy:exclude=cpp
-// Check whole memory usage - VmSize
-    QFile f(QString::fromLatin1("/proc/%1/statm").arg(getpid()));
-    if (f.open(QIODevice::ReadOnly)) {
-        QByteArray buffer; buffer.resize(100);
-        const auto bytes = f.readLine(buffer.data(), buffer.size() - 1);
-        if (bytes != -1) {
-            QString line = QString::fromLatin1(buffer).trimmed();
-            const qint64 usage = line.section(' ', 0, 0).toLongLong();
-            if (usage > 0) {
-                qint64 pagesize = sysconf(_SC_PAGE_SIZE);
-                if (pagesize < 0) {
-                    pagesize = 4096;
-                }
-                if (limit != NULL) {
-                    *limit = 16 * 1024 * 1024;
-                }
-                return usage * pagesize;
-            }
-        }
-    }
-    qWarning() << "Couldn't read VmSize from /proc/*/statm.";
-#endif
-// Check malloc() usage - very imprecise, but better than nothing.
-    int usage_sum = 0;
-#if defined(KDE_MALLINFO_STDLIB) || defined(KDE_MALLINFO_MALLOC)
-    struct mallinfo m = mallinfo();
-#ifdef KDE_MALLINFO_FIELD_hblkhd
-    usage_sum += m.hblkhd;
-#endif
-#ifdef KDE_MALLINFO_FIELD_uordblks
-    usage_sum += m.uordblks;
-#endif
-#ifdef KDE_MALLINFO_FIELD_usmblks
-    usage_sum += m.usmblks;
-#endif
-    // unlike /proc , this doesn't include things like size of dlopened modules,
-    // and also doesn't include malloc overhead
-    if (limit != NULL) {
-        *limit = 6 * 1024 * 1024;
-    }
-#endif
-    return usage_sum;
-}
-
 void KonqMainWindow::slotUndoTextChanged(const QString &newText)
 {
     m_paUndo->setText(newText);
 }
 
-// outlined because of QPointer and gcc3
 KonqView *KonqMainWindow::currentView() const
 {
     return m_currentView;
diff --git a/konqueror/src/konqmainwindow.h b/konqueror/src/konqmainwindow.h
index 64f6029..129dbe1 100644
--- a/konqueror/src/konqmainwindow.h
+++ b/konqueror/src/konqmainwindow.h
@@ -569,15 +569,6 @@ private:
     void plugViewModeActions();
     void unplugViewModeActions();
 
-    bool stayPreloaded();
-    bool checkPreloadResourceUsage();
-
-    /**
-    * Manage how many instances of this class are out there.
-    */
-    void incInstancesCount();
-    void decInstancesCount();
-
     QObject *lastFrame(KonqView *view);
 
     QLineEdit *comboEdit();
@@ -714,10 +705,6 @@ private: // members
     */
     bool m_isPopupWithProxyWindow;
     QPointer<KonqMainWindow> m_popupProxyWindow;
-
-    // TODO: move to a KonqPreloadHandler class
-    static bool s_preloaded;
-    static KonqMainWindow *s_preloadedWindow;
 };
 
 #endif // KONQMAINWINDOW_H
diff --git a/konqueror/src/konqmainwindowfactory.cpp b/konqueror/src/konqmainwindowfactory.cpp
index 48dd419..8dc4820 100644
--- a/konqueror/src/konqmainwindowfactory.cpp
+++ b/konqueror/src/konqmainwindowfactory.cpp
@@ -53,6 +53,7 @@ KonqMainWindow *KonqMainWindowFactory::createEmptyWindow()
             return new KonqMainWindow;
         }
     } else if (KonqMainWindow *mainWindow = KonqPreloadingHandler::self()->takePreloadedWindow()) {
+        qDebug() << "Using preloaded window";
         KStartupInfo::setWindowStartupId(mainWindow->winId(), KStartupInfo::startupId());
         mainWindow->reparseConfiguration();
         return mainWindow;
diff --git a/konqueror/src/konqpreloadinghandler.cpp b/konqueror/src/konqpreloadinghandler.cpp
index 25ceec8..f4d646a 100644
--- a/konqueror/src/konqpreloadinghandler.cpp
+++ b/konqueror/src/konqpreloadinghandler.cpp
@@ -23,8 +23,8 @@
 #include "konqviewmanager.h"
 #include "konqsettingsxt.h"
 
-#include <QDBusInterface>
 #include <QDBusConnection>
+#include <QDBusConnectionInterface>
 #include <QProcess>
 
 static KonqPreloadingHandler *s_self = nullptr;
@@ -39,52 +39,81 @@ KonqPreloadingHandler *KonqPreloadingHandler::self()
     return s_self;
 }
 
-void KonqPreloadingHandler::setPreloadedFlag(bool preloaded)
+// keep in sync with kfmclient.cpp
+static const char s_preloadDBusName[] = "org.kde.konqueror.preloaded";
+
+bool KonqPreloadingHandler::registerAsPreloaded()
+{
+    auto connection = QDBusConnection::sessionBus();
+    if (!connection.registerService(QString::fromLatin1(s_preloadDBusName))) {
+        return false; // another process holds this name already
+    }
+    KonqSessionManager::self()->disableAutosave(); // don't save sessions
+    makePreloadedWindow();
+    qDebug() << "Konqy preloaded:" << QDBusConnection::sessionBus().baseService();
+    return true;
+}
+
+void KonqPreloadingHandler::startNextPreloadedProcess()
 {
-    if (m_preloaded == preloaded) {
+    // Let's make another process ready for the next window
+    if (!KonqSettings::alwaysHavePreloaded()) {
         return;
     }
-    m_preloaded = preloaded;
-    if (m_preloaded) {
-        KonqSessionManager::self()->disableAutosave(); // don't save sessions
-        return; // was registered before calling this
+
+    // not running in full KDE environment?
+    if (qEnvironmentVariableIsEmpty("KDE_FULL_SESSION")) {
+        return;
     }
-    delete m_preloadedWindow; // preloaded state was abandoned without reusing the window
-    m_preloadedWindow = nullptr;
-    KonqSessionManager::self()->enableAutosave(); // enable session saving again
-    QDBusInterface ref("org.kde.kded5", "/modules/konqy_preloader", "org.kde.konqueror.Preloader", QDBusConnection::sessionBus());
-    ref.call("unregisterPreloadedKonqy", QDBusConnection::sessionBus().baseService());
+    // not the same user like the one running the session (most likely we're run via sudo or something)
+    bool uidSet = false;
+    const int uidEnvValue = qEnvironmentVariableIntValue("KDE_SESSION_UID", &uidSet);
+    if (uidSet && uid_t(uidEnvValue) != getuid()) {
+        return;
+    }
+
+    qDebug() << "Preloading next Konqueror instance";
+    const QStringList args = { QStringLiteral("--preload") };
+    QProcess::startDetached(QStringLiteral("konqueror"), args);
 }
 
-bool KonqPreloadingHandler::isPreloaded() const
+bool KonqPreloadingHandler::hasPreloadedWindow() const
 {
-    return m_preloaded;
+    return m_preloadedWindow;
 }
 
 void KonqPreloadingHandler::makePreloadedWindow()
 {
     KonqMainWindow *win = new KonqMainWindow(QUrl("about:blank")); // prepare an empty window, with the web renderer preloaded
-    // KonqMainWindow ctor sets always the preloaded flag to false, so create the window before this
-    setPreloadedFlag(true);
     win->viewManager()->clear();
     m_preloadedWindow = win;
 }
 
 KonqMainWindow *KonqPreloadingHandler::takePreloadedWindow()
 {
-    if (!m_preloaded)
+    if (!m_preloadedWindow)
         return nullptr;
 
     KonqMainWindow *win = m_preloadedWindow;
     m_preloadedWindow = nullptr;
-    setPreloadedFlag(false);
 
-    // Let's make another process ready for the next window
-    if (KonqSettings::alwaysHavePreloaded()) {
-        qDebug() << "Preloading next Konqueror instance";
-        const QStringList args = { QStringLiteral("--preload") };
-        QProcess::startDetached(QStringLiteral("konqueror"), args);
-    }
+    KonqSessionManager::self()->enableAutosave(); // enable session saving again
+    auto connection = QDBusConnection::sessionBus();
+    connection.unregisterService(QString::fromLatin1(s_preloadDBusName));
+
+    startNextPreloadedProcess();
 
     return win;
 }
+
+void KonqPreloadingHandler::ensurePreloadedProcessExists()
+{
+    if (!KonqSettings::alwaysHavePreloaded()) {
+        return;
+    }
+
+    auto connection = QDBusConnection::sessionBus();
+    if (!connection.interface()->isServiceRegistered(QString::fromLatin1(s_preloadDBusName))) {
+        startNextPreloadedProcess();
+    }
+}
diff --git a/konqueror/src/konqpreloadinghandler.h b/konqueror/src/konqpreloadinghandler.h
index 7c76f9a..1d1288a 100644
--- a/konqueror/src/konqpreloadinghandler.h
+++ b/konqueror/src/konqpreloadinghandler.h
@@ -29,21 +29,18 @@ public:
 
     static KonqPreloadingHandler *self();
 
-    /**
-     * When the "preloaded" flag is set in this process, it means
-     * this process is the one that has an empty window ready to be used.
-     * The flag is set to false again as soon as the window is used.
-     */
-    bool isPreloaded() const;
+    bool registerAsPreloaded();
 
-    void makePreloadedWindow();
+    bool hasPreloadedWindow() const;
 
     KonqMainWindow *takePreloadedWindow();
 
+    void ensurePreloadedProcessExists();
+
 private:
-    void setPreloadedFlag(bool preloaded);
+    void startNextPreloadedProcess();
+    void makePreloadedWindow();
 
-    bool m_preloaded = false;
     KonqMainWindow *m_preloadedWindow = nullptr;
 };
 
diff --git a/konqueror/src/konqueror.kcfg b/konqueror/src/konqueror.kcfg
index c0d7b8e..f2e8447 100644
--- a/konqueror/src/konqueror.kcfg
+++ b/konqueror/src/konqueror.kcfg
@@ -462,24 +462,13 @@ PATH_JAVA
   </group>
 
   <group name="Reusing" >
-    <entry key="SafeParts" type="StringList">
-      <default>SAFE</default>
-      <label></label>
-      <whatsthis></whatsthis>
-    </entry>
     <entry key="AlwaysHavePreloaded" type="Bool">
-      <default>false</default>
-      <label></label>
-      <whatsthis></whatsthis>
-      <!-- checked -->
-    </entry>
-    <entry key="MaxPreloadCount" type="Int">
-      <default>1</default>
+      <default>true</default>
       <label></label>
       <whatsthis></whatsthis>
-      <!-- checked -->
     </entry>
     <entry key="PreloadOnStartup" type="Bool">
+      <default>false</default>
       <label></label>
       <whatsthis></whatsthis>
     </entry>
diff --git a/konqueror/src/org.kde.Konqueror.Main.xml b/konqueror/src/org.kde.Konqueror.Main.xml
index 9b702da..acb9689 100644
--- a/konqueror/src/org.kde.Konqueror.Main.xml
+++ b/konqueror/src/org.kde.Konqueror.Main.xml
@@ -22,9 +22,6 @@
       <arg name="filesToSelect" type="as" direction="in"/>
       <arg name="startup_id" type="ay" direction="in"/>
     </method>
-    <method name="crashLogFile">
-      <arg type="s" direction="out"/>
-    </method>
     <method name="windowForTab">
       <arg type="o" direction="out"/>
     </method>
@@ -36,11 +33,5 @@
     </method>
     <method name="comboCleared">
     </method>
-    <method name="processCanBeReused">
-      <arg type="b" direction="out"/>
-      <arg name="screen" type="i" direction="in"/>
-    </method>
-    <method name="terminatePreloaded">
-    </method>
   </interface>
 </node>


More information about the kde-doc-english mailing list