Merge branch 'master' into davidedmundson/framesvg_native

This commit is contained in:
David Edmundson 2014-07-17 12:39:55 +02:00
commit 09e23eb675
14 changed files with 412 additions and 63 deletions

View File

@ -4,8 +4,11 @@ set_package_properties(Qt5Test PROPERTIES PURPOSE "Required for tests")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
include(ECMMarkAsTest)
include(ECMAddTests)
find_package(KF5CoreAddons REQUIRED)
find_package(KF5XmlGui REQUIRED)
find_package(Qt5Widgets REQUIRED)
# add_definitions( -DKDESRCDIR=${CMAKE_CURRENT_SOURCE_DIR} )
@ -35,7 +38,13 @@ PLASMA_UNIT_TESTS(
)
add_executable(storagetest storagetest.cpp ../src/plasma/private/storage.cpp ../src/plasma/private/storagethread.cpp)
target_link_libraries(storagetest Qt5::Gui Qt5::Test Qt5::Sql KF5::KIOCore KF5::Plasma KF5::CoreAddons )
target_link_libraries(storagetest Qt5::Gui Qt5::Test Qt5::Sql KF5::KIOCore KF5::Plasma KF5::CoreAddons)
set(coronatest_srcs coronatest.cpp)
qt5_add_resources(coronatest_srcs coronatestresources.qrc)
ecm_add_test(${coronatest_srcs} TEST_NAME coronatest LINK_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Test KF5::KIOCore KF5::Plasma KF5::CoreAddons KF5::XmlGui)
add_test(plasma-storagetest storagetest)
ecm_mark_as_test(storagetest)

212
autotests/coronatest.cpp Normal file
View File

@ -0,0 +1,212 @@
/********************************************************************************
* Copyright 2014 Marco Martin <mart@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public License *
* along with this library; see the file COPYING.LIB. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
*********************************************************************************/
#include "coronatest.h"
#include <ksycoca.h>
#include <kactioncollection.h>
#include <QStandardPaths>
#include <QAction>
#include <QApplication>
Plasma::Applet *SimpleLoader::internalLoadApplet(const QString &name, uint appletId,
const QVariantList &args)
{
if (name == "simpleapplet") {
return new SimpleApplet(0, QString(), appletId);
} else if (name == "simplecontainment") {
return new SimpleContainment(0, QString(), appletId);
} else {
return 0;
}
}
SimpleCorona::SimpleCorona(QObject *parent)
: Plasma::Corona(parent)
{
Plasma::PluginLoader::setPluginLoader(new SimpleLoader);
}
SimpleCorona::~SimpleCorona()
{}
QRect SimpleCorona::screenGeometry(int screen) const
{
//completely arbitrary, still not tested
return QRect(100*screen, 100, 100, 100);
}
SimpleApplet::SimpleApplet(QObject *parent , const QString &serviceId, uint appletId)
: Plasma::Applet(parent, serviceId, appletId)
{
QTime time = QTime::currentTime();
qsrand((uint)time.msec());
//updateConstraints(Plasma::Types::UiReadyConstraint);
m_timer.setSingleShot(true);
m_timer.setInterval(qrand() % ((500 + 1) - 100) + 100);
m_timer.start();
connect(&m_timer, &QTimer::timeout, [=]() {
updateConstraints(Plasma::Types::UiReadyConstraint);
});
}
SimpleContainment::SimpleContainment(QObject *parent , const QString &serviceId, uint appletId)
: Plasma::Containment(parent, serviceId, appletId)
{
QTime time = QTime::currentTime();
qsrand((uint)time.msec());
//updateConstraints(Plasma::Types::UiReadyConstraint);
m_timer.setSingleShot(true);
m_timer.setInterval(qrand() % ((500 + 1) - 100) + 100);
m_timer.start();
connect(&m_timer, &QTimer::timeout, [=]() {
updateConstraints(Plasma::Types::UiReadyConstraint);
});
}
static void runKBuildSycoca()
{
QProcess proc;
const QString kbuildsycoca = QStandardPaths::findExecutable(KBUILDSYCOCA_EXENAME);
QVERIFY(!kbuildsycoca.isEmpty());
QStringList args;
args << "--testmode";
proc.setProcessChannelMode(QProcess::MergedChannels); // silence kbuildsycoca output
proc.start(kbuildsycoca, args);
QSignalSpy spy(KSycoca::self(), SIGNAL(databaseChanged(QStringList)));
QVERIFY(spy.wait(10000));
proc.waitForFinished();
QCOMPARE(proc.exitStatus(), QProcess::NormalExit);
}
void CoronaTest::initTestCase()
{
if (!KSycoca::isAvailable()) {
runKBuildSycoca();
}
QStandardPaths::setTestModeEnabled(true);
m_corona = new SimpleCorona;
m_configDir = QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
m_configDir.removeRecursively();
QVERIFY(m_configDir.mkpath("."));
QVERIFY(QFile::copy(QStringLiteral(":/plasma-test-appletsrc"), m_configDir.filePath(QStringLiteral("plasma-test-appletsrc"))));
}
void CoronaTest::cleanupTestCase()
{
m_configDir.removeRecursively();
delete m_corona;
}
void CoronaTest::restore()
{
m_corona->loadLayout("plasma-test-appletsrc");
QCOMPARE(m_corona->containments().count(), 1);
QCOMPARE(m_corona->containments().first()->applets().count(), 2);
}
void CoronaTest::startupCompletion()
{
QVERIFY(!m_corona->isStartupCompleted());
QVERIFY(!m_corona->containments().first()->isUiReady());
QSignalSpy spy(m_corona, SIGNAL(startupCompleted()));
QVERIFY(spy.wait(1000));
QVERIFY(m_corona->isStartupCompleted());
QVERIFY(m_corona->containments().first()->isUiReady());
}
void CoronaTest::addRemoveApplets()
{
m_corona->containments().first()->createApplet("invalid");
QCOMPARE(m_corona->containments().first()->applets().count(), 3);
//remove action present
QVERIFY(m_corona->containments().first()->applets().first()->actions()->action("remove"));
//kill an applet
m_corona->containments().first()->applets().first()->actions()->action("remove")->trigger();
QSignalSpy spy(m_corona->containments().first()->applets().first(), SIGNAL(destroyed()));
QVERIFY(spy.wait(1000));
QCOMPARE(m_corona->containments().first()->applets().count(), 2);
}
//this test has to be the last, since systemimmutability
//can't be programmatically unlocked
void CoronaTest::immutability()
{
//immutability
QCOMPARE(m_corona->immutability(), Plasma::Types::Mutable);
m_corona->setImmutability(Plasma::Types::UserImmutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::UserImmutable);
for (Plasma::Containment *cont : m_corona->containments()) {
QCOMPARE(cont->immutability(), Plasma::Types::UserImmutable);
for (Plasma::Applet *app : cont->applets()) {
QCOMPARE(app->immutability(), Plasma::Types::UserImmutable);
}
}
m_corona->setImmutability(Plasma::Types::Mutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::Mutable);
for (Plasma::Containment *cont : m_corona->containments()) {
QCOMPARE(cont->immutability(), Plasma::Types::Mutable);
for (Plasma::Applet *app : cont->applets()) {
QCOMPARE(app->immutability(), Plasma::Types::Mutable);
}
}
m_corona->setImmutability(Plasma::Types::SystemImmutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable);
for (Plasma::Containment *cont : m_corona->containments()) {
QCOMPARE(cont->immutability(), Plasma::Types::SystemImmutable);
for (Plasma::Applet *app : cont->applets()) {
QCOMPARE(app->immutability(), Plasma::Types::SystemImmutable);
}
}
//can't unlock systemimmutable
m_corona->setImmutability(Plasma::Types::Mutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable);
for (Plasma::Containment *cont : m_corona->containments()) {
QCOMPARE(cont->immutability(), Plasma::Types::SystemImmutable);
for (Plasma::Applet *app : cont->applets()) {
QCOMPARE(app->immutability(), Plasma::Types::SystemImmutable);
}
}
}
QTEST_MAIN(CoronaTest)

88
autotests/coronatest.h Normal file
View File

@ -0,0 +1,88 @@
/******************************************************************************
* Copyright 2014 Marco Martin <mart@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public License *
* along with this library; see the file COPYING.LIB. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
*******************************************************************************/
#ifndef CORONATEST_H
#define CORONATEST_H
#include <QtTest/QtTest>
#include <QTimer>
#include "plasma/corona.h"
#include "plasma/pluginloader.h"
class SimpleLoader : public Plasma::PluginLoader
{
protected:
virtual Plasma::Applet *internalLoadApplet(const QString &name, uint appletId = 0,
const QVariantList &args = QVariantList());
};
class SimpleCorona : public Plasma::Corona
{
Q_OBJECT
public:
explicit SimpleCorona(QObject * parent = 0);
~SimpleCorona();
QRect screenGeometry(int) const;
};
class SimpleApplet : public Plasma::Applet
{
Q_OBJECT
public:
explicit SimpleApplet(QObject *parent = 0, const QString &serviceId = QString(), uint appletId = 0);
private:
QTimer m_timer;
};
class SimpleContainment : public Plasma::Containment
{
Q_OBJECT
public:
explicit SimpleContainment(QObject *parent = 0, const QString &serviceId = QString(), uint appletId = 0);
private:
QTimer m_timer;
};
class CoronaTest : public QObject
{
Q_OBJECT
public Q_SLOTS:
void initTestCase();
void cleanupTestCase();
private Q_SLOTS:
void restore();
void startupCompletion();
void addRemoveApplets();
void immutability();
private:
SimpleCorona *m_corona;
QDir m_configDir;
};
#endif

View File

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>plasma-test-appletsrc</file>
</qresource>
</RCC>

View File

@ -0,0 +1,18 @@
[Containments][1]
formfactor=0
immutability=1
lastScreen=0
location=0
plugin=simplecontainment
[Containments][1][Applets][2]
immutability=1
plugin=invalid
[Containments][1][Applets][3]
immutability=1
plugin=simpleapplet
[General]
immutability=1

View File

@ -26,7 +26,6 @@ Item {
width: root.cellWidth
height: root.cellHeight
property real borderOpacity: daysCalendar.borderOpacity
property bool today: root.today.toDateString() == new Date(yearNumber, monthNumber - 1, dayNumber).toDateString() // for some reason the comparison doesn't work without toDateString()
onHeightChanged: {

View File

@ -29,58 +29,66 @@ Item {
// but 56*7 + 6 (the inner spacing) is 398, so we split the remaining 6 to avoid
// wrong alignment)
anchors {
leftMargin: Math.floor(((parent.width + borderWidth) % 7) / 2);
leftMargin: Math.floor(((parent.width - (root.columns + 1) * borderWidth) % root.columns) / 2)
rightMargin: anchors.leftMargin
bottomMargin: anchors.leftMargin
}
property real borderOpacity: 1.0
// Paints the inner grid and the outer frame
Canvas {
id: canvas
anchors.fill: parent
opacity: root.borderOpacity
antialiasing: false
clip: false
onPaint: {
var ctx = getContext("2d");
// this is needed as otherwise the canvas seems to have some sort of
// inner clip region which does not update on size changes
ctx.reset();
ctx.save();
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = theme.textColor;
ctx.lineWidth = root.borderWidth
ctx.globalAlpha = 1.0;
Rectangle {
id: allAroundFrame
color: "transparent"
border.width: borderWidth
border.color: theme.textColor
opacity: borderOpacity
width: (root.cellWidth + borderWidth) * calendarGrid.rows
height: (root.cellHeight + borderWidth) * calendarGrid.columns
}
ctx.beginPath();
Repeater {
id: verticalGridLineRepeater
model: calendarGrid.columns - 1
delegate: Rectangle {
x: root.cellWidth + (index * (root.cellWidth + borderWidth))
// The first grid row does not have any columns, so start at cellHeight and add borderWidth
// to not create conjuction points which looks bad as the lines are semi-transparent
y: root.cellHeight + borderWidth
width: borderWidth
// Subtract the most bottom border width to avoid conjuction points
height: (root.cellHeight + borderWidth) * (calendarGrid.columns - 1) - borderWidth
color: theme.textColor
opacity: borderOpacity
}
}
// This isn't the real width/height, but rather the X coord where the line will stop
// and as the coord system starts from (0,0), we need to do "-1" to not get off-by-1 errors
var rectWidth = (root.cellWidth + root.borderWidth) * calendarGrid.columns + root.borderWidth - 1
var rectHeight = (root.cellHeight + root.borderWidth) * calendarGrid.rows + root.borderWidth - 1
Repeater {
id: horizontalGridLineRepeater
model: calendarGrid.rows - 1
delegate: Rectangle {
// Start the horizontal line so that it does not cross the leftmost vertical borderline
// but is rathar adjacent to it
x: borderWidth
y: root.cellHeight + (index * (root.cellHeight + borderWidth))
// To each cell add one border width and then subtract the outer border widths
// so the lines do not cross
width: (root.cellWidth + borderWidth) * calendarGrid.rows - (borderWidth * 2)
height: borderWidth
color: theme.textColor
opacity: borderOpacity
// the outer frame
ctx.strokeRect(0, 0, rectWidth, rectHeight);
// horizontal lines
for (var i = 0; i < calendarGrid.rows - 1; i++) {
var lineY = (rectHeight / calendarGrid.columns) * (i + 1);
ctx.moveTo(0, lineY);
ctx.lineTo(rectWidth, lineY);
}
// vertical lines
for (var i = 0; i < calendarGrid.columns - 1; i++) {
var lineX = (rectWidth / calendarGrid.rows) * (i + 1);
ctx.moveTo(lineX, root.borderWidth + root.cellHeight);
ctx.lineTo(lineX, rectHeight);
}
ctx.closePath();
ctx.stroke();
ctx.restore();
}
}
Grid {
id: calendarGrid
// Pad the grid to not overlap with the top and left frame
x: root.borderWidth
y: root.borderWidth
columns: calendarBackend.days
rows: calendarBackend.weeks + 1
spacing: 1
@ -118,9 +126,7 @@ Item {
id: repeater
model: calendarBackend.daysModel
DayDelegate {
borderOpacity: daysCalendar.borderOpacity
}
DayDelegate {}
}
}
}

View File

@ -52,8 +52,8 @@ Item {
return Math.min(
Math.max(
mWidth * 3,
// Take the calendar width, subtract the inner spacings and divide by number of columns (==days in week)
Math.floor((calendar.width - (root.columns - 1) * borderWidth) / root.columns)
// Take the calendar width, subtract the inner and outer spacings and divide by number of columns (==days in week)
Math.floor((calendar.width - (root.columns + 1) * borderWidth) / root.columns)
),
mWidth * 100
)
@ -64,7 +64,7 @@ Item {
Math.max(
mHeight * 1.5,
// Take the calendar height, subtract the inner spacings and divide by number of rows (root.weeks + one row for day names)
Math.floor((calendar.height - (root.rows - 1) * borderWidth) / (root.rows + 1))
Math.floor((calendar.height - (root.rows + 1) * borderWidth) / (root.rows + 1))
),
mHeight * 40
)
@ -141,8 +141,6 @@ Item {
bottom: parent.bottom
}
borderOpacity: root.borderOpacity
PlasmaComponents.Label {
text: "◀"
opacity: leftmouse.containsMouse ? 1 : 0.4

View File

@ -281,6 +281,12 @@ void Containment::restoreContents(KConfigGroup &group)
d->createApplet(plugin, QVariantList(), appId);
}
for (Applet *applet : Containment::applets()) {
if (!applet->pluginInfo().isValid()) {
applet->updateConstraints(Plasma::Types::UiReadyConstraint);
}
}
}
Plasma::Types::ContainmentType Containment::containmentType() const
@ -536,7 +542,7 @@ QHash<QString, ContainmentActions *> &Containment::containmentActions()
bool Containment::isUiReady() const
{
return d->uiReady && Applet::d->started;
return d->uiReady && d->appletsUiReady && Applet::d->started;
}
void Containment::setActivity(const QString &activityId)

View File

@ -442,6 +442,8 @@ Containment *CoronaPrivate::addContainment(const QString &name, const QVariantLi
delete applet;
}
applet = containment = new Containment(q, 0, id);
//if it's a dummy containment, just say its ui is ready, not blocking the corona
applet->updateConstraints(Plasma::Types::UiReadyConstraint);
// we want to provide something and don't care about the failure to launch
containment->setFormFactor(Plasma::Types::Planar);
@ -538,8 +540,9 @@ QList<Plasma::Containment *> CoronaPrivate::importLayout(const KConfigGroup &con
if (!containment->isUiReady() && containment->lastScreen() < q->numScreens()) {
++containmentsStarting;
QObject::connect(containment, &Plasma::Containment::uiReadyChanged, [=](bool ready) {
if (!ready)
if (!ready) {
return;
}
--containmentsStarting;
if (containmentsStarting <= 0) {

View File

@ -357,8 +357,9 @@ void AppletPrivate::scheduleConstraintsUpdate(Plasma::Types::Constraints c)
if (c & Plasma::Types::StartupCompletedConstraint) {
started = true;
if (q->isContainment())
if (q->isContainment()) {
qobject_cast<Containment*>(q)->d->setStarted();
}
}
pendingConstraints |= c;

View File

@ -47,7 +47,8 @@ ContainmentPrivate::ContainmentPrivate(Containment *c):
location(Types::Floating),
lastScreen(-1), // never had a screen
type(Plasma::Types::NoContainmentType),
uiReady(false)
uiReady(false),
appletsUiReady(false)
{
//if the parent is an applet (i.e we are the systray)
//we want to follow screen changed signals from the parent's containment
@ -234,28 +235,30 @@ void ContainmentPrivate::setStarted()
if (!q->Applet::d->started) {
q->Applet::d->started = true;
if (uiReady)
if (uiReady) {
emit q->uiReadyChanged(true);
}
}
}
void ContainmentPrivate::setUiReady()
{
//if we are the containment and there is still some uncomplete applet, we're still incomplete
if (!uiReady && loadingApplets.isEmpty()) {
if (!uiReady) {
uiReady = true;
if (q->Applet::d->started)
if (q->Applet::d->started && appletsUiReady && loadingApplets.isEmpty()) {
emit q->uiReadyChanged(true);
}
}
}
void ContainmentPrivate::appletLoaded(Applet* applet)
{
loadingApplets.remove(q);
loadingApplets.remove(applet);
if (loadingApplets.isEmpty() && !uiReady) {
uiReady = true;
if (q->Applet::d->started) {
if (loadingApplets.isEmpty() && !appletsUiReady) {
appletsUiReady = true;
if (q->Applet::d->started && uiReady) {
emit q->uiReadyChanged(true);
}
}

View File

@ -91,6 +91,7 @@ public:
QString activityId;
Types::ContainmentType type;
bool uiReady : 1;
bool appletsUiReady : 1;
static const char defaultWallpaper[];
};

View File

@ -100,10 +100,10 @@ KConfigLoader *WallpaperInterface::configScheme()
cfg = KConfigGroup(&cfg, "Wallpaper");
if (xmlPath.isEmpty()) {
m_configLoader = new KConfigLoader(cfg, 0);
m_configLoader = new KConfigLoader(cfg, 0, this);
} else {
QFile file(xmlPath);
m_configLoader = new KConfigLoader(cfg, &file);
m_configLoader = new KConfigLoader(cfg, &file, this);
}
}