warning message for broken MultipleLayouts startup

--if the app crashed and the user trys to reopen Latte
then the Containments must first return to their Original
Layouts. This code provides that and informs also the user
during the startup.
pull/2/head
Michail Vourlakos 7 years ago
parent e56478fb8a
commit 94914ee578

@ -163,7 +163,7 @@ void DockCorona::load()
loadLayoutName = m_layoutNameOnStartUp;
}
m_layoutManager->switchToLayout(loadLayoutName);
m_layoutManager->loadLayoutOnStartup(loadLayoutName);
}
}

@ -31,6 +31,7 @@
#include <KArchive/KTar>
#include <KArchive/KArchiveEntry>
#include <KArchive/KArchiveDirectory>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KNotification>
@ -498,7 +499,13 @@ QString Importer::nameOfConfigFile(const QString &fileName)
bool Importer::layoutExists(QString layoutName)
{
return QFile::exists(QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte");
return QFile::exists(layoutFilePath(layoutName));
}
QString Importer::layoutFilePath(QString layoutName)
{
return QString(QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte");
}
QString Importer::uniqueLayoutName(QString name)
@ -521,4 +528,55 @@ QString Importer::uniqueLayoutName(QString name)
return name;
}
QStringList Importer::checkRepairMultipleLayoutsLinkedFile()
{
QString linkedFilePath = QDir::homePath() + "/.config/latte/" + Layout::MultipleLayoutsName + ".layout.latte";
KSharedConfigPtr filePtr = KSharedConfig::openConfig(linkedFilePath);
KConfigGroup linkedContainments = KConfigGroup(filePtr, "Containments");
//! layoutName and its Containments
QHash<QString, QStringList> linkedLayoutContainmentGroups;
foreach (auto cId, linkedContainments.groupList()) {
QString layoutName = linkedContainments.group(cId).readEntry("layoutId", QString());
if (!layoutName.isEmpty()) {
qDebug() << layoutName;
linkedLayoutContainmentGroups[layoutName].append(cId);
linkedContainments.group(cId).writeEntry("layoutId", QString());
}
}
QStringList updatedLayouts;
foreach (auto layoutName, linkedLayoutContainmentGroups.uniqueKeys()) {
if (layoutName != Layout::MultipleLayoutsName && layoutExists(layoutName)) {
updatedLayouts << layoutName;
KSharedConfigPtr layoutFilePtr = KSharedConfig::openConfig(layoutFilePath(layoutName));
KConfigGroup origLayoutContainments = KConfigGroup(layoutFilePtr, "Containments");
//Clear old containments
origLayoutContainments.deleteGroup();
//Update containments
foreach (auto cId, linkedLayoutContainmentGroups[layoutName]) {
KConfigGroup newContainment = origLayoutContainments.group(cId);
linkedContainments.group(cId).copyTo(&newContainment);
linkedContainments.group(cId).deleteGroup();
}
origLayoutContainments.sync();
}
}
//! clear all remaining ghost containments
foreach (auto cId, linkedContainments.groupList()) {
linkedContainments.group(cId).deleteGroup();
}
linkedContainments.sync();
return updatedLayouts;
}
}

@ -73,9 +73,17 @@ public:
//! if the function didnt succeed return an empty string
static QString importLayoutHelper(QString fileName);
//! return the file path of a layout either existing or not
static QString layoutFilePath(QString layoutName);
static QString nameOfConfigFile(const QString &fileName);
static QString uniqueLayoutName(QString name);
static QStringList availableLayouts();
//! it checks the linked file if there are Containments in it that belong
//! to Original Layouts and moves them accordingly. This is used mainly on
//! startup and if such state occurs, it basically means that the app didnt
//! close correctly, e.g. there was a crash.
static QStringList checkRepairMultipleLayoutsLinkedFile();
private:
//! checks if this old layout can be imported. If it can it returns

@ -24,6 +24,7 @@
#include <QDir>
#include <QFile>
#include <QMessageBox>
#include <QQmlProperty>
#include <QtDBus/QtDBus>
@ -490,6 +491,27 @@ void LayoutManager::loadLayouts()
emit menuLayoutsChanged();
}
void LayoutManager::loadLayoutOnStartup(QString layoutName)
{
if (memoryUsage() == Dock::MultipleLayouts) {
QStringList layouts = m_importer->checkRepairMultipleLayoutsLinkedFile();
//! Latte didnt close correctly, maybe a crash
if (layouts.size() > 0) {
QMessageBox *msg = new QMessageBox();
msg->setAttribute(Qt::WA_DeleteOnClose);
msg->setIcon(QMessageBox::Warning);
msg->setWindowTitle(i18n("Mutliple Layouts Warning"));
msg->setText(i18n("Latte did not close properly in the previous session.The following layout(s) <b>[%0]</b> were updated for consistency !!!").arg(layouts.join(",")));
msg->setStandardButtons(QMessageBox::Ok);
msg->open();
}
}
switchToLayout(layoutName);
}
void LayoutManager::loadLatteLayout(QString layoutPath)
{
qDebug() << " -------------------------------------------------------------------- ";

@ -61,6 +61,7 @@ public:
Importer *importer();
void load();
void loadLayoutOnStartup(QString layoutName);
void unload();
void addDock(Plasma::Containment *containment, bool forceLoading = false, int expDockScreen = -1);
void recreateDock(Plasma::Containment *containment);

Loading…
Cancel
Save