@@ -32,7 +32,8 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
32
32
mp_manager(nullptr ),
33
33
mp_mainWindow(nullptr ),
34
34
mp_nameMapper(std::make_shared<kiwix::UpdatableNameMapper>(m_library.getKiwixLibrary(), false)),
35
- m_server(m_library.getKiwixLibrary(), mp_nameMapper)
35
+ m_server(m_library.getKiwixLibrary(), mp_nameMapper),
36
+ mp_session(nullptr )
36
37
{
37
38
try {
38
39
m_translation.setTranslation (QLocale ());
@@ -113,6 +114,8 @@ void KiwixApp::init()
113
114
m_library.asyncUpdateFromDir (dir);
114
115
}
115
116
}
117
+
118
+ restoreTabs ();
116
119
}
117
120
118
121
KiwixApp::~KiwixApp ()
@@ -176,6 +179,28 @@ QString KiwixApp::findLibraryDirectory()
176
179
return currentDataDir;
177
180
}
178
181
182
+ void KiwixApp::restoreTabs ()
183
+ {
184
+ /* Place session file in our global library path */
185
+ QDir dir (m_libraryDirectory);
186
+ mp_session = new QSettings (dir.filePath (" kiwix-desktop.session" ),
187
+ QSettings::defaultFormat (), this );
188
+ QStringList tabsToOpen = mp_session->value (" reopenTabList" ).toStringList ();
189
+
190
+ /* Restart a new session to prevent duplicate records in openURL */
191
+ saveListOfOpenTabs ();
192
+ for (const auto &zimUrl : tabsToOpen)
193
+ {
194
+ try
195
+ {
196
+ /* Throws exception if zim file cannot be found */
197
+ m_library.getArchive (QUrl (zimUrl).host ().split (' .' )[0 ]);
198
+ openUrl (QUrl (zimUrl));
199
+ }
200
+ catch (std::exception &e) { /* Blank */ }
201
+ }
202
+ }
203
+
179
204
KiwixApp *KiwixApp::instance ()
180
205
{
181
206
return static_cast <KiwixApp*>(QApplication::instance ());
@@ -504,3 +529,8 @@ QString KiwixApp::parseStyleFromFile(QString filePath)
504
529
file.close ();
505
530
return styleSheet;
506
531
}
532
+
533
+ void KiwixApp::saveListOfOpenTabs ()
534
+ {
535
+ return mp_session->setValue (" reopenTabList" , getTabWidget ()->getTabUrls ());
536
+ }
0 commit comments