load the default layout when cant find previous

--load the default layout when cant find the previous
layout for some reason. This means that something went
really wrong actually and the previous stored layout
doesnt exist anymore, at least with the same name
ised.
pull/2/head
Michail Vourlakos 7 years ago
parent e7633f7974
commit 3679c1c0cf

@ -148,14 +148,25 @@ void DockCorona::load()
QString assignedLayout = m_layoutManager->shouldSwitchToLayout(m_activityConsumer->currentActivity()); QString assignedLayout = m_layoutManager->shouldSwitchToLayout(m_activityConsumer->currentActivity());
QString loadLayoutName = "";
if (!assignedLayout.isEmpty() && assignedLayout != m_universalSettings->currentLayoutName()) { if (!assignedLayout.isEmpty() && assignedLayout != m_universalSettings->currentLayoutName()) {
m_layoutManager->switchToLayout(assignedLayout); loadLayoutName = assignedLayout;
} else { } else {
m_layoutManager->switchToLayout(m_universalSettings->currentLayoutName()); loadLayoutName = m_universalSettings->currentLayoutName();
}
if (!m_layoutManager->layoutExists(loadLayoutName)) {
QString defaultLayoutName = m_layoutManager->defaultLayoutName();
if (!m_layoutManager->layoutExists(defaultLayoutName)) {
m_layoutManager->importDefaultLayout();
}
loadLayoutName = defaultLayoutName;
} }
/*foreach (auto containment, containments()) m_layoutManager->switchToLayout(loadLayoutName);
addDock(containment);*/
} }
} }

@ -130,6 +130,22 @@ QString LayoutManager::currentLayoutName() const
return QString(); return QString();
} }
QString LayoutManager::defaultLayoutName() const
{
QByteArray presetNameOrig = QString("preset" + QString::number(1)).toUtf8();
QString presetPath = m_corona->kPackage().filePath(presetNameOrig);
QString presetName = LayoutSettings::layoutName(presetPath);
QByteArray presetNameChars = presetName.toUtf8();
presetName = i18n(presetNameChars);
return presetName;
}
bool LayoutManager::layoutExists(QString layoutName) const
{
return m_layouts.contains(layoutName);
}
QStringList LayoutManager::layouts() const QStringList LayoutManager::layouts() const
{ {
return m_layouts; return m_layouts;
@ -341,6 +357,11 @@ QString LayoutManager::newLayout(QString layoutName, QString preset)
return newLayoutPath; return newLayoutPath;
} }
void LayoutManager::importDefaultLayout()
{
importPreset(1);
}
void LayoutManager::importPresets(bool includeDefault) void LayoutManager::importPresets(bool includeDefault)
{ {
int start = 1; int start = 1;
@ -350,7 +371,13 @@ void LayoutManager::importPresets(bool includeDefault)
} }
for (int i = start; i <= 4; ++i) { for (int i = start; i <= 4; ++i) {
QByteArray presetNameOrig = QString("preset" + QString::number(i)).toUtf8(); importPreset(i);
}
}
void LayoutManager::importPreset(int presetNo)
{
QByteArray presetNameOrig = QString("preset" + QString::number(presetNo)).toUtf8();
QString presetPath = m_corona->kPackage().filePath(presetNameOrig); QString presetPath = m_corona->kPackage().filePath(presetNameOrig);
QString presetName = LayoutSettings::layoutName(presetPath); QString presetName = LayoutSettings::layoutName(presetPath);
QByteArray presetNameChars = presetName.toUtf8(); QByteArray presetNameChars = presetName.toUtf8();
@ -362,7 +389,6 @@ void LayoutManager::importPresets(bool includeDefault)
QFile(presetPath).copy(newLayoutFile); QFile(presetPath).copy(newLayoutFile);
} }
} }
}
QStringList LayoutManager::validActivities(QStringList currentList) QStringList LayoutManager::validActivities(QStringList currentList)
{ {

@ -63,9 +63,12 @@ public:
void load(); void load();
bool layoutExists(QString layoutName) const;
QString shouldSwitchToLayout(QString activityId); QString shouldSwitchToLayout(QString activityId);
QString currentLayoutName() const; QString currentLayoutName() const;
QString defaultLayoutName() const;
QStringList layouts() const; QStringList layouts() const;
QStringList menuLayouts() const; QStringList menuLayouts() const;
@ -78,6 +81,7 @@ public:
QStringList activities(); QStringList activities();
void importDefaultLayout();
void importPresets(bool includeDefault = false); void importPresets(bool includeDefault = false);
public slots: public slots:
@ -106,6 +110,8 @@ private:
void confirmDynamicSwitch(); void confirmDynamicSwitch();
void setMenuLayouts(QStringList layouts); void setMenuLayouts(QStringList layouts);
void showInfoWindow(QString info, int duration); void showInfoWindow(QString info, int duration);
void importPreset(int presetNo);
QString layoutPath(QString layoutName); QString layoutPath(QString layoutName);
void loadLayouts(); void loadLayouts();

Loading…
Cancel
Save