multiple:make switch funtion work properly

--when the user requests a specific layout in Multiple
Layout mode the new approach is the following. If
the layout has assigned activities this is respected
but if its activities are empty that layout is assigned
only on the current activity and any other layouts assigned
explicitly to that activity are released
pull/20/head
Michail Vourlakos 4 years ago
parent 5101a1314e
commit a83d26a35b

@ -37,6 +37,7 @@ Layout::Layout(Layout &&o)
color(o.color),
background(o.background),
textColor(o.textColor),
lastUsedActivity(o.lastUsedActivity),
isActive(o.isActive),
isBroken(o.isBroken),
isLocked(o.isLocked),
@ -54,6 +55,7 @@ Layout::Layout(const Layout &o)
color(o.color),
background(o.background),
textColor(o.textColor),
lastUsedActivity(o.lastUsedActivity),
isActive(o.isActive),
isBroken(o.isBroken),
isLocked(o.isLocked),
@ -73,6 +75,7 @@ Layout &Layout::operator=(Layout &&rhs)
color = rhs.color;
background = rhs.background;
textColor = rhs.textColor;
lastUsedActivity = rhs.lastUsedActivity;
isActive = rhs.isActive;
isBroken = rhs.isBroken;
isLocked = rhs.isLocked;
@ -93,6 +96,7 @@ Layout &Layout::operator=(const Layout &rhs)
color = rhs.color;
background = rhs.background;
textColor = rhs.textColor;
lastUsedActivity = rhs.lastUsedActivity;
isActive = rhs.isActive;
isBroken = rhs.isBroken;
isLocked = rhs.isLocked;
@ -114,6 +118,7 @@ bool Layout::operator==(const Layout &rhs) const
&& (background == rhs.background)
&& (textColor == rhs.textColor)
&& (isBroken == rhs.isBroken)
//&& (lastUsedActivity == rhs.lastUsedActivity) /*Disabled because it can change too often*/
//&& (isActive == rhs.isActive) /*Disabled but this is not a data but a layout state*/
&& (isLocked == rhs.isLocked)
&& (isShownInMenu == rhs.isShownInMenu)

@ -49,6 +49,7 @@ public:
QString color;
QString background;
QString textColor;
QString lastUsedActivity;
bool isActive{false};
bool isBroken{false};
bool isLocked{false};

@ -225,7 +225,7 @@ void AbstractLayout::setIcon(const QString &icon)
emit iconChanged();
}
QString AbstractLayout::lastUsedActivity()
QString AbstractLayout::lastUsedActivity() const
{
return m_lastUsedActivity;
}

@ -84,7 +84,7 @@ public:
bool preferredForShortcutsTouched() const;
void setPreferredForShortcutsTouched(bool touched);
QString lastUsedActivity();
QString lastUsedActivity() const;
void clearLastUsedActivity(); //!e.g. when we export a layout
QString name() const;

@ -53,7 +53,7 @@ CentralLayout::~CentralLayout()
void CentralLayout::init()
{
connect(this, &CentralLayout::activitiesChanged, this, &CentralLayout::saveConfig);
connect(this, &GenericLayout::activitiesChanged, this, &CentralLayout::saveConfig);
connect(this, &CentralLayout::disableBordersForMaximizedWindowsChanged, this, &CentralLayout::saveConfig);
connect(this, &CentralLayout::showInMenuChanged, this, &CentralLayout::saveConfig);
}
@ -153,6 +153,7 @@ Data::Layout CentralLayout::data() const
cdata.isShownInMenu = showInMenu();
cdata.hasDisabledBorders = disableBordersForMaximizedWindows();
cdata.activities = activities();
cdata.lastUsedActivity = lastUsedActivity();
return cdata;
}

@ -76,7 +76,6 @@ public:
Q_INVOKABLE bool isCurrent() override;
signals:
void activitiesChanged();
void disableBordersForMaximizedWindowsChanged();
void showInMenuChanged();

@ -121,6 +121,7 @@ void GenericLayout::unloadLatteViews()
//!disconnect signals in order to avoid crashes when the layout is unloading
disconnect(this, &GenericLayout::viewsCountChanged, m_corona, &Plasma::Corona::availableScreenRectChanged);
disconnect(this, &GenericLayout::viewsCountChanged, m_corona, &Plasma::Corona::availableScreenRegionChanged);
disconnect(this, &GenericLayout::activitiesChanged, this, &GenericLayout::updateLastUsedActivity);
disconnect(m_corona->activitiesConsumer(), &KActivities::Consumer::currentActivityChanged, this, &GenericLayout::updateLastUsedActivity);
for (const auto view : m_latteViews) {
@ -977,8 +978,8 @@ bool GenericLayout::initToCorona(Latte::Corona *corona)
updateLastUsedActivity();
//! signals
connect(m_corona->activitiesConsumer(), &KActivities::Consumer::currentActivityChanged,
this, &GenericLayout::updateLastUsedActivity);
connect(this, &GenericLayout::activitiesChanged, this, &GenericLayout::updateLastUsedActivity);
connect(m_corona->activitiesConsumer(), &KActivities::Consumer::currentActivityChanged, this, &GenericLayout::updateLastUsedActivity);
connect(m_corona, &Plasma::Corona::containmentAdded, this, &GenericLayout::addContainment);
@ -1000,10 +1001,6 @@ void GenericLayout::updateLastUsedActivity()
return;
}
if (!m_lastUsedActivity.isEmpty() && !m_corona->layoutsManager()->synchronizer()->activities().contains(m_lastUsedActivity)) {
clearLastUsedActivity();
}
QString currentId = m_corona->activitiesConsumer()->currentActivity();
QStringList appliedActivitiesIds = appliedActivities();

@ -218,6 +218,18 @@ void Manager::setOnAllActivities(QString layoutName)
}
}
void Manager::setOnActivities(QString layoutName, QStringList activities)
{
CentralLayout *central = m_synchronizer->centralLayout(layoutName);
if (central) {
central->setActivities(activities);
} else if (m_importer->layoutExists(layoutName)) {
CentralLayout storage(this, m_importer->layoutUserFilePath(layoutName));
storage.setActivities(activities);
}
}
void Manager::cleanupOnStartup(QString path)
{
KSharedConfigPtr filePtr = KSharedConfig::openConfig(path);

@ -81,6 +81,7 @@ public:
void init();
void loadLayoutOnStartup(QString layoutName);
void setOnAllActivities(QString layoutName);
void setOnActivities(QString layoutName, QStringList activities);
void showInfoWindow(QString info, int duration, QStringList activities = {"0"});
void unload();

@ -214,10 +214,7 @@ QStringList Synchronizer::menuLayouts() const
continue;
}
if (m_manager->memoryUsage() == MemoryUsage::SingleLayout
|| (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts && !m_layouts[i].activities.isEmpty())) {
menulayouts << m_layouts[i].name;
}
menulayouts << m_layouts[i].name;
}
for (const auto layout : m_centralLayouts) {
@ -607,6 +604,112 @@ bool Synchronizer::switchToLayoutInSingleMode(QString layoutName)
return initSingleMode(layoutName);
}
bool Synchronizer::switchToLayoutInMultipleModeBasedOnActivities(const QString &layoutName)
{
Data::Layout layoutdata;
CentralLayout *central = centralLayout(layoutName);
if (central) {
layoutdata = central->data();
} else if (m_layouts.containsName(layoutName)) {
QString layoutid = m_layouts.idForName(layoutName);
CentralLayout storagedlayout(this, layoutid);
layoutdata = storagedlayout.data();
m_layouts[layoutid] = layoutdata;
}
if (layoutdata.isEmpty()) {
return false;
}
QString switchToActivity;
if (layoutdata.isOnAllActivities()) {
//! no reason to switch in any activity;
} else if (layoutdata.isForFreeActivities()) {
//! free-activities case
QStringList freerunningactivities = freeRunningActivities();
if (freerunningactivities.count() > 0) {
if (freerunningactivities.contains(layoutdata.lastUsedActivity)) {
switchToActivity = layoutdata.lastUsedActivity;
} else {
switchToActivity = freerunningactivities[0];
}
} else {
QStringList freepausedactivities = freeActivities();
if (freepausedactivities.count() > 0) {
switchToActivity = freepausedactivities[0];
}
}
} else if (!layoutdata.activities.isEmpty()) {
//! set on-explicit activities
QStringList allactivities = activities();
if (layoutdata.activities.contains(layoutdata.lastUsedActivity)) {
switchToActivity = layoutdata.lastUsedActivity;
} else {
switchToActivity = layoutdata.activities[0];
}
} else if (layoutdata.activities.isEmpty() && m_layouts.containsName(layoutName)) {
//! no-activities are set
//! has not been set in any activities but nonetheless it is requested probably by the user
//! requested layout is assigned explicitly in current activity and any remaining explicit layouts
//! are removing current activity from their activities list
QString layoutid = m_layouts.idForName(layoutName);
QString currentactivityid = m_activitiesController->currentActivity();
QStringList layoutIdsChanged;
m_layouts[layoutid].activities = QStringList(currentactivityid);
m_manager->setOnActivities(layoutName, m_layouts[layoutid].activities);
emit layoutActivitiesChanged(m_layouts[layoutid]);
layoutIdsChanged << layoutid;
if (m_assignedLayouts.contains(currentactivityid)) {
//! remove any other explicit set layouts for the current activity
QStringList explicits = m_assignedLayouts[currentactivityid];
for(auto explicitlayoutname : explicits) {
QString explicitlayoutid = m_layouts.idForName(explicitlayoutname);
m_layouts[explicitlayoutid].activities.removeAll(currentactivityid);
m_manager->setOnActivities(explicitlayoutname, m_layouts[explicitlayoutid].activities);
emit layoutActivitiesChanged(m_layouts[explicitlayoutid]);
}
}
QStringList freelayoutnames;
if (m_assignedLayouts.contains(Data::Layout::FREEACTIVITIESID)) {
freelayoutnames = m_assignedLayouts[Data::Layout::FREEACTIVITIESID];
}
reloadAssignedLayouts();
for(auto freelayoutname : freelayoutnames) {
//! inform free activities layouts that their activities probably changed
CentralLayout *central = centralLayout(freelayoutname);
if (central) {
emit central->activitiesChanged();
}
}
}
if (!switchToActivity.isEmpty()) {
if (!m_manager->corona()->activitiesConsumer()->runningActivities().contains(switchToActivity)) {
m_activitiesController->startActivity(switchToActivity);
}
m_activitiesController->setCurrentActivity(switchToActivity);
}
return true;
}
bool Synchronizer::switchToLayoutInMultipleMode(QString layoutName)
{
if (!memoryInitialized() || m_manager->memoryUsage() != MemoryUsage::MultipleLayouts) {
@ -625,6 +728,10 @@ bool Synchronizer::switchToLayoutInMultipleMode(QString layoutName)
return true;
}
} else {
if (!layoutName.isEmpty()) {
switchToLayoutInMultipleModeBasedOnActivities(layoutName);
}
syncMultipleLayoutsToActivities();
}
@ -636,13 +743,13 @@ bool Synchronizer::switchToLayout(QString layoutName, MemoryUsage::LayoutsMemory
{
qDebug() << " >>>>> SWITCHING >> " << layoutName << " __ from memory: " << m_manager->memoryUsage() << " to memory: " << newMemoryUsage;
if (newMemoryUsage == MemoryUsage::Current) {
newMemoryUsage = m_manager->memoryUsage();
}
if (!memoryInitialized() || newMemoryUsage != m_manager->memoryUsage()) {
//! Initiate Layouts memory properly
if (newMemoryUsage != MemoryUsage::Current) {
m_manager->setMemoryUsage(newMemoryUsage);
} else {
newMemoryUsage = m_manager->memoryUsage();
}
m_manager->setMemoryUsage(newMemoryUsage);
return (newMemoryUsage == MemoryUsage::SingleLayout ? initSingleMode(layoutName) : initMultipleMode(layoutName));
}

@ -131,6 +131,7 @@ signals:
void currentLayoutIsSwitching(QString layoutName);
void newLayoutAdded(const Data::Layout &layout);
void layoutActivitiesChanged(const Data::Layout &layout);
private slots:
void onCurrentActivityChanged(const QString &id);
@ -148,6 +149,7 @@ private:
bool switchToLayoutInMultipleMode(QString layoutName);
bool switchToLayoutInSingleMode(QString layoutName);
bool switchToLayoutInMultipleModeBasedOnActivities(const QString &layoutName);
bool isAssigned(QString layoutName) const;
bool memoryInitialized() const;

@ -72,6 +72,7 @@ Layouts::Layouts(Settings::Handler::TabLayouts *parent)
connect(m_handler->corona()->universalSettings(), &UniversalSettings::canDisableBordersChanged, this, &Layouts::applyColumnWidths);
connect(m_handler->corona()->layoutsManager()->synchronizer(), &Latte::Layouts::Synchronizer::newLayoutAdded, this, &Layouts::onLayoutAddedExternally);
connect(m_handler->corona()->layoutsManager()->synchronizer(), &Latte::Layouts::Synchronizer::layoutActivitiesChanged, this, &Layouts::onLayoutActivitiesChangedExternally);
connect(m_model, &QAbstractItemModel::dataChanged, this, &Layouts::dataChanged);
connect(m_model, &Model::Layouts::rowsInserted, this, &Layouts::dataChanged);
@ -421,10 +422,14 @@ void Layouts::initLayouts()
}
}
void Layouts::onLayoutActivitiesChangedExternally(const Data::Layout &layout)
{
m_model->setOriginalActivitiesForLayout(layout);
}
void Layouts::onLayoutAddedExternally(const Data::Layout &layout)
{
m_model->appendOriginalLayout(layout);
m_model->appendLayout(layout);
}
void Layouts::sortByColumn(int column, Qt::SortOrder order)

@ -112,6 +112,7 @@ private slots:
void onNameDuplicatedFrom(const QString &provenId, const QString &trialId);
void onLayoutAddedExternally(const Data::Layout &layout);
void onLayoutActivitiesChangedExternally(const Data::Layout &layout);
private:
void initView();

@ -321,44 +321,6 @@ void TabLayouts::switchLayout()
} else {
m_corona->layoutsManager()->switchToLayout(selectedLayoutOriginal.name, MemoryUsage::MultipleLayouts);
m_layoutsController->setOriginalInMultipleMode(true);
/*CentralLayout singleLayout(this, selectedLayoutCurrent.id);
QString switchToActivity;
if (selectedLayoutCurrent.isForFreeActivities()) {
QStringList freerunningactivities = m_corona->layoutsManager()->synchronizer()->freeRunningActivities();
if (freerunningactivities.count() > 0) {
if (freerunningactivities.contains(singleLayout.lastUsedActivity())) {
switchToActivity = singleLayout.lastUsedActivity();
} else {
switchToActivity = freerunningactivities[0];
}
} else {
QStringList freepausedactivities = m_corona->layoutsManager()->synchronizer()->freeActivities();
if (freepausedactivities.count() > 0) {
switchToActivity = freepausedactivities[0];
}
}
} else if (!selectedLayoutCurrent.activities.isEmpty()) {
QStringList activities = m_corona->layoutsManager()->synchronizer()->activities();
if (selectedLayoutCurrent.activities.contains(singleLayout.lastUsedActivity())) {
switchToActivity = singleLayout.lastUsedActivity();
} else {
switchToActivity = selectedLayoutCurrent.activities[0];
}
}
if (!switchToActivity.isEmpty()) {
if (!m_corona->activitiesConsumer()->runningActivities().contains(switchToActivity)) {
m_corona->layoutsManager()->synchronizer()->activitiesController()->startActivity(switchToActivity);
}
m_corona->layoutsManager()->synchronizer()->activitiesController()->setCurrentActivity(switchToActivity);
}*/
}
updatePerLayoutButtonsState();
@ -400,11 +362,12 @@ void TabLayouts::updatePerLayoutButtonsState()
Latte::Data::Layout selectedLayout = m_layoutsController->selectedLayoutCurrentData();
//! Switch Button
if (m_layoutsController->inMultipleMode() && selectedLayout.activities.isEmpty()) {
setTwinProperty(m_switchLayoutAction, TWINENABLED, true);
/*if (m_layoutsController->inMultipleMode()) {
setTwinProperty(m_switchLayoutAction, TWINENABLED, false);
} else {
setTwinProperty(m_switchLayoutAction, TWINENABLED, true);
}
}*/
//! Pause Button - enabled
if (m_layoutsController->inMultipleMode()) {

@ -144,6 +144,8 @@ void Layouts::appendOriginalLayout(const Latte::Data::Layout &layout)
{
int newRow = o_layoutsTable.sortedPosForName(layout.name);
o_layoutsTable.insert(newRow, layout);
appendLayout(layout);
}
void Layouts::applyData()
@ -616,6 +618,16 @@ QStringList Layouts::cleanStrings(const QStringList &original, const QStringList
return result;
}
void Layouts::setOriginalActivitiesForLayout(const Latte::Data::Layout &layout)
{
if (o_layoutsTable.containsId(layout.id) && m_layoutsTable.containsId(layout.id)) {
o_layoutsTable[layout.id].activities = layout.activities;
int mrow = rowForId(layout.id);
setActivities(mrow, layout.activities);
}
}
void Layouts::setActivities(const int &row, const QStringList &activities)
{
if (!m_layoutsTable.rowExists(row) || m_layoutsTable[row].activities == activities) {

@ -135,6 +135,8 @@ public:
void setOriginalInMultipleMode(const bool &inmultiple);
void setOriginalData(Latte::Data::LayoutsTable &data);
void setOriginalActivitiesForLayout(const Latte::Data::Layout &layout);
signals:
void inMultipleModeChanged();
void nameDuplicated(const QString &provenId, const QString &trialId);

Loading…
Cancel
Save