improve Screens Report

--the new report identifies for all your layouts
when a screen has not been assigned any docks/panels.
That can help user to clean up the ScreensConnectors
if wants to
pull/7/head
Michail Vourlakos 6 years ago
parent dcfcc1b442
commit 7954a3ac39

@ -1205,6 +1205,38 @@ void GenericLayout::syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap)
qDebug() << "end of, syncLatteViewsToScreens ....";
}
QList<int> GenericLayout::viewsScreens()
{
QList<int> screens;
if (isActive()) {
for (const auto containment : m_containments) {
if (m_storage->isLatteContainment(containment)) {
int screenId = -1;
//! valid screen id
if (latteViewExists(containment)) {
screenId = m_latteViews[containment]->positioner()->currentScreenId();
} else {
screenId = containment->screen();
if (screenId == -1) {
screenId = containment->lastScreen();
}
}
if (screenId!=-1 &&!screens.contains(screenId)) {
screens << screenId;
}
}
}
return screens;
} else {
return m_storage->viewsScreens();
}
}
//! STORAGE

@ -130,6 +130,8 @@ public:
//! that latteView
QList<Plasma::Containment *> unassignFromLayout(Latte::View *latteView);
QList<int> viewsScreens();
public slots:
Q_INVOKABLE void addNewView();
Q_INVOKABLE int viewsWithTasks() const;

@ -76,6 +76,12 @@ bool Storage::isLatteContainment(Plasma::Containment *containment) const
return false;
}
bool Storage::isLatteContainment(const KConfigGroup &group) const
{
QString pluginId = group.readEntry("plugin", "");
return pluginId == "org.kde.latte.containment";
}
void Storage::lock()
{
QFileInfo layoutFileInfo(m_layout->file());
@ -344,6 +350,27 @@ QList<Plasma::Containment *> Storage::importLayoutFile(QString file)
return importedDocks;
}
QList<int> Storage::viewsScreens()
{
QList<int> screens;
KSharedConfigPtr lFile = KSharedConfig::openConfig(m_layout->file());
KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments");
for (const auto &cId : containmentGroups.groupList()) {
if (isLatteContainment(containmentGroups.group(cId))) {
int screenId = containmentGroups.group(cId).readEntry("lastScreen", -1);
if (screenId != -1 && !screens.contains(screenId)) {
screens << screenId;
}
}
}
return screens;
}
QString Storage::availableId(QStringList all, QStringList assigned, int base)
{
bool found = false;

@ -42,6 +42,7 @@ public:
bool isWritable() const;
bool isLatteContainment(Plasma::Containment *containment) const;
bool isLatteContainment(const KConfigGroup &group) const;
bool layoutIsBroken() const;
void importToCorona();
@ -51,6 +52,8 @@ public:
void copyView(Plasma::Containment *containment);
void syncToLayoutFile(bool removeLayoutId);
QList<int> viewsScreens();
/// STATIC
//! Check if an applet config group is valid or belongs to removed applet
static bool appletGroupIsValid(KConfigGroup appletGroup);

@ -104,32 +104,58 @@ ScreenPool::~ScreenPool()
}
QString ScreenPool::reportHtml() const
QString ScreenPool::reportHtml(const QList<int> &assignedScreens) const
{
QString report;
report += "<table cellspacing='6'>";
report += "<tr><td align='center'><b>ID</b></td><td align='center'><b>Name</b></td><td align='center'><b>State</b></td></tr>";
report += "<table cellspacing='8'>";
report += "<tr><td align='center'><b>" + i18nc("screen id","ID") + "</b></td>" +
"<td align='center'><b>" + i18nc("screen name", "Name") + "</b></td>" +
"<td align='center'><b>" + i18nc("screen type", "Type") + "</b></td>" +
"<td align='center'><b>" + i18n("Docks/Panels") + "</b></td></tr>";
report += "<tr><td colspan='4'><hr></td></tr>";
for(const QString &connector : m_connectorForId) {
int scrId = id(connector);
bool hasViews = assignedScreens.contains(scrId);
bool primary = m_primaryConnector == connector;
bool secondary = !primary && screenExists(scrId);
report += "<tr>";
//! ScreenId
QString idStr = primary ? "<b>"+QString::number(id(connector))+"</b>" : QString::number(id(connector));
QString idStr = QString::number(scrId);
if (primary || secondary) {
idStr = "<b>" + idStr +"</b>";
}
report += "<td align='center'>" + idStr + "</td>";
//! ScreenName
QString connectorStr = primary ? "<b>"+connector+"</b>" : connector;
//! ScreenName and Primary flag
QString connectorStr = connector;
if (primary || secondary) {
connectorStr = "<b>"+ connector + "</b>";
}
report += "<td align='center'>" + connectorStr + "</td>";
//! Screen State
//! ScreenType
QString typeStr = "";
if (primary) {
report += "<td><font color='green'>[" + i18nc("primary screen","Primary") + "]</font></td>";
} else {
report += "<td></td>";
typeStr = "<b><font color='green'>[" + i18nc("primary screen","Primary") + "]</font></b>";
} else if (secondary) {
typeStr = "<b>[" + i18nc("secondary screen","Secondary") + "]</b>";
}
report += "<td align='center'>" + typeStr +"</td>";
//! Screen has not assigned any docks/panels
QString notAssignedStr = "";
if (!hasViews) {
notAssignedStr = "<font color='red'><i>[" + i18nc("it has not latte docks/panels", "none") + "]</i></font>";
}
report += "<td align='center'>" + notAssignedStr +"</td>";
report += "</tr>";
}
@ -263,12 +289,12 @@ QList <int> ScreenPool::knownIds() const
return m_connectorForId.keys();
}
bool ScreenPool::hasId(int id)
bool ScreenPool::hasId(int id) const
{
return ((id!=-1) && m_connectorForId.keys().contains(id));
}
bool ScreenPool::screenExists(int id)
bool ScreenPool::screenExists(int id) const
{
if (id != -1 && knownIds().contains(id)) {
QString scrName = connector(id);

@ -43,8 +43,8 @@ public:
void load();
~ScreenPool() override;
bool hasId(int id);
bool screenExists(int id);
bool hasId(int id) const;
bool screenExists(int id) const;
int primaryScreenId() const;
QString primaryConnector() const;
@ -59,7 +59,7 @@ public:
int firstAvailableId() const;
QString reportHtml() const;
QString reportHtml(const QList<int> &assignedScreens) const;
//all ids that are known, included screens not enabled at the moment
QList <int> knownIds() const;

@ -253,14 +253,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona)
}
});
connect(screensAction, &QAction::triggered, this, [&]() {
auto msg = new QMessageBox(this);
msg->setIcon(QMessageBox::Information);
msg->setWindowTitle(i18n("Screens Information"));
msg->setText(m_corona->screenPool()->reportHtml());
msg->open();
});
connect(screensAction, &QAction::triggered, this, &SettingsDialog::showScreensInformation);
//! update all layouts view when runningActivities changed. This way we update immediately
//! the running Activities in Activities checkboxes which are shown as bold
@ -1561,6 +1554,34 @@ bool SettingsDialog::dataAreAccepted()
return true;
}
void SettingsDialog::showScreensInformation()
{
QList<int> assignedScreens;
for (int i = 0; i < m_model->rowCount(); ++i) {
QString id = m_model->data(m_model->index(i, IDCOLUMN), Qt::DisplayRole).toString();
QString name = m_model->data(m_model->index(i, NAMECOLUMN), Qt::DisplayRole).toString();
Layout::GenericLayout *genericActive= m_corona->layoutsManager()->synchronizer()->layout(m_layouts[id]->name());
Layout::GenericLayout *generic = genericActive ? genericActive : m_layouts[id];
QList<int> vScreens = generic->viewsScreens();
for (const int scrId : vScreens) {
if (!assignedScreens.contains(scrId)) {
assignedScreens << scrId;
}
}
}
auto msg = new QMessageBox(this);
msg->setIcon(QMessageBox::Information);
msg->setWindowTitle(i18n("Screens Information"));
msg->setText(m_corona->screenPool()->reportHtml(assignedScreens));
msg->open();
}
bool SettingsDialog::saveAllChanges()
{
if (!dataAreAccepted()) {

@ -94,6 +94,7 @@ private slots:
void reject() override;
void apply();
void restoreDefaults();
void showScreensInformation();
void updatePerLayoutButtonsState();
void layoutsChanged();

Loading…
Cancel
Save