correctly save and restore to/from plasma-shellrc

This commit is contained in:
Marco Martin 2013-05-08 13:52:40 +02:00
parent c28b0676ac
commit a6c82d8a5e
5 changed files with 88 additions and 13 deletions

View File

@ -45,6 +45,12 @@ DesktopCorona::DesktopCorona(QObject *parent)
{
m_desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop");
m_appConfigSyncTimer = new QTimer(this);
m_appConfigSyncTimer->setSingleShot(true);
connect(m_appConfigSyncTimer, &QTimer::timeout,
this, &DesktopCorona::syncAppConfig);
connect(m_desktopWidget, SIGNAL(resized(int)),
this, SLOT(screenResized(int)));
connect(m_desktopWidget, SIGNAL(screenCountChanged(int)),
@ -64,6 +70,20 @@ DesktopCorona::~DesktopCorona()
{
}
KSharedConfig::Ptr DesktopCorona::applicationConfig()
{
return KSharedConfig::openConfig();
}
void DesktopCorona::requestApplicationConfigSync()
{
// constant controlling how long between requesting a configuration sync
// and one happening should occur. currently 10 seconds
static const int CONFIG_SYNC_TIMEOUT = 10000;
m_appConfigSyncTimer->start(CONFIG_SYNC_TIMEOUT);
}
void DesktopCorona::loadDefaultLayout()
{
WorkspaceScripting::DesktopScriptEngine scriptEngine(this, true);
@ -155,7 +175,7 @@ void DesktopCorona::checkDesktop(/*Activity *activity,*/ bool signalWhenExists,
qWarning() << "Invalid screen";
}
c->flushPendingConstraintsEvents();
requestConfigSync();
requestApplicationConfigSync();
if (signalWhenExists) {
emit containmentAdded(c);
@ -292,6 +312,12 @@ void DesktopCorona::showWidgetExplorer()
m_widgetExplorerView->show();
}
void DesktopCorona::syncAppConfig()
{
qDebug() << "Syncing plasma-shellrc config";
applicationConfig()->sync();
}
void DesktopCorona::printScriptError(const QString &error)
{
qWarning() << error;
@ -302,5 +328,5 @@ void DesktopCorona::printScriptMessage(const QString &message)
qDebug() << message;
}
#include "desktopcorona.moc"
#include "moc_desktopcorona.cpp"

View File

@ -45,6 +45,16 @@ public:
explicit DesktopCorona(QObject * parent = 0);
~DesktopCorona();
/**
* Where to save global configuration that doesn't have anything to do with the scene (e.g. views)
*/
KSharedConfig::Ptr applicationConfig();
/**
* Request saving applicationConfig on disk, it's event compressed, not immediate
*/
void requestApplicationConfigSync();
/**
* Loads the default (system wide) layout for this user
**/
@ -88,6 +98,7 @@ protected Q_SLOTS:
private Q_SLOTS:
void handleContainmentAdded(Plasma::Containment *c);
void showWidgetExplorer();
void syncAppConfig();
private:
QDesktopWidget *m_desktopWidget;
@ -95,6 +106,7 @@ private:
WidgetExplorerView *m_widgetExplorerView;
QHash<Plasma::Containment *, PanelView *> m_panelViews;
KConfigGroup m_desktopDefaultsConfig;
QTimer *m_appConfigSyncTimer;
};
#endif

View File

@ -17,6 +17,7 @@
*/
#include "panelview.h"
#include "desktopcorona.h"
#include <QAction>
#include <QDebug>
@ -29,12 +30,13 @@
#include <Plasma/Containment>
#include <Plasma/Package>
PanelView::PanelView(Plasma::Corona *corona, QWindow *parent)
PanelView::PanelView(DesktopCorona *corona, QWindow *parent)
: View(corona, parent),
m_offset(0),
m_maxLength(0),
m_minLength(0),
m_alignment(Qt::AlignLeft)
m_alignment(Qt::AlignLeft),
m_corona(corona)
{
QSurfaceFormat format;
format.setAlphaBufferSize(8);
@ -70,7 +72,8 @@ PanelView::~PanelView()
config().writeEntry("thickness", size().height());
}
config().writeEntry("alignment", (int)m_alignment);
containment()->corona()->requestConfigSync();
m_corona->requestApplicationConfigSync();
m_corona->requestApplicationConfigSync();
}
}
@ -79,7 +82,7 @@ KConfigGroup PanelView::config() const
if (!containment()) {
return KConfigGroup();
}
KConfigGroup views(KSharedConfig::openConfig(), "PlasmaViews");
KConfigGroup views(m_corona->applicationConfig(), "PlasmaViews");
views = KConfigGroup(&views, QString("Panel %1").arg(containment()->id()));
if (containment()->formFactor() == Plasma::Vertical) {
@ -92,12 +95,12 @@ KConfigGroup PanelView::config() const
void PanelView::init()
{
if (!corona()->package().isValid()) {
if (!m_corona->package().isValid()) {
qWarning() << "Invalid home screen package";
}
setResizeMode(View::SizeRootObjectToView);
setSource(QUrl::fromLocalFile(corona()->package().filePath("views", "Panel.qml")));
setSource(QUrl::fromLocalFile(m_corona->package().filePath("views", "Panel.qml")));
positionPanel();
}
@ -131,6 +134,7 @@ void PanelView::setOffset(int offset)
config().writeEntry("offset", m_offset);
positionPanel();
emit offsetChanged();
m_corona->requestApplicationConfigSync();
}
int PanelView::thickness() const
@ -145,12 +149,13 @@ void PanelView::setThickness(int value)
}
if (formFactor() == Plasma::Vertical) {
return setWidth(value);
setWidth(value);
} else {
return setHeight(value);
setHeight(value);
}
config().writeEntry("thickness", value);
emit thicknessChanged();
m_corona->requestApplicationConfigSync();
}
int PanelView::maximumLength() const
@ -176,6 +181,7 @@ void PanelView::setMaximumLength(int length)
config().writeEntry("maxLength", length);
m_maxLength = length;
emit maximumLengthChanged();
m_corona->requestApplicationConfigSync();
}
int PanelView::minimumLength() const
@ -201,6 +207,7 @@ void PanelView::setMinimumLength(int length)
config().writeEntry("minLength", length);
m_minLength = length;
emit minimumLengthChanged();
m_corona->requestApplicationConfigSync();
}
void PanelView::positionPanel()
@ -289,8 +296,8 @@ void PanelView::restore()
}
m_offset = config().readEntry<int>("offset", 0);
m_maxLength = config().readEntry<int>("max", -1);
m_minLength = config().readEntry<int>("min", -1);
m_maxLength = config().readEntry<int>("maxLength", -1);
m_minLength = config().readEntry<int>("minLength", -1);
m_alignment = (Qt::Alignment)config().readEntry<int>("alignment", Qt::AlignLeft);
setMinimumSize(QSize(-1, -1));

View File

@ -24,6 +24,7 @@
#include "panelconfigview.h"
#include <QtCore/qpointer.h>
class DesktopCorona;
class PanelView : public View
{
@ -35,7 +36,7 @@ class PanelView : public View
Q_PROPERTY(int minimumLength READ minimumLength WRITE setMinimumLength NOTIFY minimumLengthChanged)
public:
explicit PanelView(Plasma::Corona *corona, QWindow *parent = 0);
explicit PanelView(DesktopCorona *corona, QWindow *parent = 0);
virtual ~PanelView();
virtual KConfigGroup config() const;
@ -75,6 +76,7 @@ private:
int m_minLength;
Qt::Alignment m_alignment;
QPointer<PanelConfigView> m_panelConfigView;
DesktopCorona *m_corona;
};
#endif // PANELVIEW_H

View File

@ -33,11 +33,31 @@ Rectangle {
height: 64
//END properties
//BEGIN Connections
Connections {
target: panel
onOffsetChanged: offsetHandle.value = panel.offset
onMinimumLengthChanged: minimumLengthHandle.value = panel.minimumLength
onMaximumLengthChanged: maximumLengthHandle.value = panel.maximumLength
}
//END Connections
//BEGIN UI components
// Offset
Rectangle {
id: offsetHandle
width: 32
height: 32
property int value
onValueChanged: {
if (panel.location == 5 || panel.location == 6) {
parent.y = panel.offset
} else {
parent.x = panel.offset
}
}
MouseArea {
drag {
target: parent
@ -63,8 +83,12 @@ Rectangle {
//Minimum length
Rectangle {
id: minimumLengthHandle
width: 32
height: 32
property int value
MouseArea {
drag {
target: parent
@ -90,8 +114,12 @@ Rectangle {
//Maximum length
Rectangle {
id: maximumLengthHandle
width: 32
height: 32
property int value
MouseArea {
drag {
target: parent