File indexing completed on 2024-05-05 05:13:11

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "akregatorcentralwidget.h"
0008 #include "mainwidget.h"
0009 
0010 #include <KConfig>
0011 #include <KConfigGroup>
0012 
0013 #include <QStandardPaths>
0014 
0015 using namespace Akregator;
0016 
0017 AkregatorCentralWidget::AkregatorCentralWidget(QWidget *parent)
0018     : QStackedWidget(parent)
0019     , mCrashWidget(new CrashWidget(this))
0020 {
0021     connect(mCrashWidget, &CrashWidget::restoreSession, this, &AkregatorCentralWidget::slotRestoreSession);
0022     addWidget(mCrashWidget);
0023 }
0024 
0025 Akregator::AkregatorCentralWidget::~AkregatorCentralWidget() = default;
0026 
0027 bool AkregatorCentralWidget::previousSessionCrashed() const
0028 {
0029     KConfig config(QStringLiteral("crashed"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
0030     KConfigGroup configGroup(&config, QStringLiteral("Part"));
0031 
0032     if (!configGroup.readEntry("crashed", false)) {
0033         return false;
0034     }
0035     return true;
0036 }
0037 
0038 void AkregatorCentralWidget::needToRestoreCrashedSession()
0039 {
0040     setCurrentWidget(mCrashWidget);
0041 }
0042 
0043 void AkregatorCentralWidget::slotRestoreSession(Akregator::CrashWidget::CrashAction type)
0044 {
0045     setCurrentWidget(mMainWidget);
0046     Q_EMIT restoreSession(type);
0047 }
0048 
0049 void AkregatorCentralWidget::setMainWidget(Akregator::MainWidget *mainWidget)
0050 {
0051     if (!mMainWidget) {
0052         mMainWidget = mainWidget;
0053         addWidget(mMainWidget);
0054         setCurrentWidget(mMainWidget);
0055     }
0056 }
0057 
0058 #include "moc_akregatorcentralwidget.cpp"