[Examples] Fix build
* Add QStringLiteral et al where appropriate * Also add override keyword to avoid warnings * Minor style changes and cleanups Differential Revision: https://phabricator.kde.org/D10092
This commit is contained in:
parent
f906178713
commit
595fd88054
@ -49,7 +49,7 @@ bool DataContainersEngine::sourceRequestEvent(const QString &source)
|
|||||||
// the source to make sure it is indeed an http URL.
|
// the source to make sure it is indeed an http URL.
|
||||||
QUrl url(source);
|
QUrl url(source);
|
||||||
qDebug() << "goin to fetch" << source << url << url.scheme();
|
qDebug() << "goin to fetch" << source << url << url.scheme();
|
||||||
if (!url.scheme().startsWith("http", Qt::CaseInsensitive)) {
|
if (!url.scheme().startsWith(QLatin1String("http"), Qt::CaseInsensitive)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ public:
|
|||||||
DataContainersEngine(QObject *parent, const QVariantList &args);
|
DataContainersEngine(QObject *parent, const QVariantList &args);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool sourceRequestEvent(const QString &source);
|
bool sourceRequestEvent(const QString &source) override;
|
||||||
bool updateSourceEvent(const QString &source);
|
bool updateSourceEvent(const QString &source) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,15 +74,15 @@ void HttpContainer::fetchFinished(KJob *job)
|
|||||||
// additional stats. Note that we don't include the source name, as that
|
// additional stats. Note that we don't include the source name, as that
|
||||||
// is implied as this object *is* the DataContainer. setData is called
|
// is implied as this object *is* the DataContainer. setData is called
|
||||||
// with just key/value pairs.
|
// with just key/value pairs.
|
||||||
setData("Contents", m_data);
|
setData(QStringLiteral("Contents"), m_data);
|
||||||
setData("Size", job->processedAmount(KJob::Bytes));
|
setData(QStringLiteral("Size"), job->processedAmount(KJob::Bytes));
|
||||||
|
|
||||||
// Since we only create TransferJobs, it's safe to just static_cast here.
|
// Since we only create TransferJobs, it's safe to just static_cast here.
|
||||||
// In many real-world situations, this isn't the safest thing to do and a
|
// In many real-world situations, this isn't the safest thing to do and a
|
||||||
// qobject_cast with a test on the result is often safer and cleaner.
|
// qobject_cast with a test on the result is often safer and cleaner.
|
||||||
KIO::TransferJob *tjob = static_cast<KIO::TransferJob *>(job);
|
KIO::TransferJob *tjob = static_cast<KIO::TransferJob *>(job);
|
||||||
setData("Error Page", tjob->isErrorPage());
|
setData(QStringLiteral("Error Page"), tjob->isErrorPage());
|
||||||
setData("Mimetype", tjob->mimetype());
|
setData(QStringLiteral("Mimetype"), tjob->mimetype());
|
||||||
|
|
||||||
// Let DataContainer know we have data that needs storing
|
// Let DataContainer know we have data that needs storing
|
||||||
setNeedsToBeStored(true);
|
setNeedsToBeStored(true);
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
namespace KIO
|
namespace KIO
|
||||||
{
|
{
|
||||||
class Job;
|
class Job;
|
||||||
};
|
}
|
||||||
|
|
||||||
class HttpContainer : public Plasma::DataContainer
|
class HttpContainer : public Plasma::DataContainer
|
||||||
{
|
{
|
||||||
|
@ -56,21 +56,21 @@ void SimpleEngine::init()
|
|||||||
// This is the simplest form, with source name and one bit of data.
|
// This is the simplest form, with source name and one bit of data.
|
||||||
// Note how the source name is not translated! They can be marked with
|
// Note how the source name is not translated! They can be marked with
|
||||||
// I18N_NOOP, however, if they should be translatable in a visualization.
|
// I18N_NOOP, however, if they should be translatable in a visualization.
|
||||||
setData("Simple Source", i18n("Very simple data"));
|
setData(QStringLiteral("Simple Source"), i18n("Very simple data"));
|
||||||
|
|
||||||
// a source can have multiple entries, differentiated by key names,
|
// a source can have multiple entries, differentiated by key names,
|
||||||
// which are also not translated:
|
// which are also not translated:
|
||||||
setData("Multiple Source", "First", i18n("First"));
|
setData(QStringLiteral("Multiple Source"), QStringLiteral("First"), i18n("First"));
|
||||||
setData("Multiple Source", "Second", i18n("Second"));
|
setData(QStringLiteral("Multiple Source"), QStringLiteral("Second"), i18n("Second"));
|
||||||
|
|
||||||
// We can also set the data up first and apply it all at once
|
// We can also set the data up first and apply it all at once
|
||||||
// Note how data types other than strings can be used as well; anything
|
// Note how data types other than strings can be used as well; anything
|
||||||
// that works with QVariant, in fact.
|
// that works with QVariant, in fact.
|
||||||
Plasma::DataEngine::Data data;
|
Plasma::DataEngine::Data data;
|
||||||
data.insert("Cow", "mooo");
|
data.insert(QStringLiteral("Cow"), QStringLiteral("mooo"));
|
||||||
data.insert("Black", QColor(0, 0, 0));
|
data.insert(QStringLiteral("Black"), QColor(0, 0, 0));
|
||||||
data.insert("Time", QTime::currentTime());
|
data.insert(QStringLiteral("Time"), QTime::currentTime());
|
||||||
setData("Another Source", data);
|
setData(QStringLiteral("Another Source"), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// export the plugin; use the plugin name and the class name
|
// export the plugin; use the plugin name and the class name
|
||||||
|
@ -51,7 +51,7 @@ bool SourcesOnRequestEngine::sourceRequestEvent(const QString &source)
|
|||||||
|
|
||||||
// We're going to reject any sources that start with the letter 'a'
|
// We're going to reject any sources that start with the letter 'a'
|
||||||
// to demonstrate how to reject a request in a DataEngine.
|
// to demonstrate how to reject a request in a DataEngine.
|
||||||
if (source.startsWith('a') || source.startsWith('A')) {
|
if (source.startsWith(QLatin1Char('a')) || source.startsWith(QLatin1Char('A'))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,13 +62,13 @@ bool SourcesOnRequestEngine::sourceRequestEvent(const QString &source)
|
|||||||
// In such a case the DataEngine will remain happy and Do The Right Thing(tm)
|
// In such a case the DataEngine will remain happy and Do The Right Thing(tm)
|
||||||
// but the visualization will not get the source connected to it as it
|
// but the visualization will not get the source connected to it as it
|
||||||
// expects. So ALWAYS key the new data by the source string as below:
|
// expects. So ALWAYS key the new data by the source string as below:
|
||||||
setData(source, "Update Count", 0);
|
setData(source, QStringLiteral("Update Count"), 0);
|
||||||
|
|
||||||
if (!modelForSource(source)) {
|
if (!modelForSource(source)) {
|
||||||
QStandardItemModel *m = new QStandardItemModel;
|
QStandardItemModel *m = new QStandardItemModel;
|
||||||
m->appendRow(new QStandardItem("Item1, first update"));
|
m->appendRow(new QStandardItem(QStringLiteral("Item1, first update")));
|
||||||
m->appendRow(new QStandardItem("Item2, first update"));
|
m->appendRow(new QStandardItem(QStringLiteral("Item2, first update")));
|
||||||
m->appendRow(new QStandardItem("Item3, first update"));
|
m->appendRow(new QStandardItem(QStringLiteral("Item3, first update")));
|
||||||
setModel(source, m);
|
setModel(source, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,15 +92,15 @@ bool SourcesOnRequestEngine::updateSourceEvent(const QString &source)
|
|||||||
// sourceRequestEvent, however, this will result in expected behavior: visualizations
|
// sourceRequestEvent, however, this will result in expected behavior: visualizations
|
||||||
// connected to the sources which have setData called for them will be notified
|
// connected to the sources which have setData called for them will be notified
|
||||||
// of these changes.
|
// of these changes.
|
||||||
const int updateCount = containerForSource(source)->data().value("Update Count").toInt() + 1;
|
const int updateCount = containerForSource(source)->data().value(QStringLiteral("Update Count")).toInt() + 1;
|
||||||
setData(source, "Update Count", updateCount);
|
setData(source, QStringLiteral("Update Count"), updateCount);
|
||||||
|
|
||||||
QStandardItemModel *m = qobject_cast<QStandardItemModel *>(modelForSource(source));
|
QStandardItemModel *m = qobject_cast<QStandardItemModel *>(modelForSource(source));
|
||||||
if (m) {
|
if (m) {
|
||||||
m->clear();
|
m->clear();
|
||||||
m->appendRow(new QStandardItem(QString("Item1, update %1").arg(updateCount)));
|
m->appendRow(new QStandardItem(QStringLiteral("Item1, update %1").arg(updateCount)));
|
||||||
m->appendRow(new QStandardItem(QString("Item2, update %1").arg(updateCount)));
|
m->appendRow(new QStandardItem(QStringLiteral("Item2, update %1").arg(updateCount)));
|
||||||
m->appendRow(new QStandardItem(QString("Item3, update %1").arg(updateCount)));
|
m->appendRow(new QStandardItem(QStringLiteral("Item3, update %1").arg(updateCount)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we updated the source immediately here, we need to return true so the DataEngine
|
// Since we updated the source immediately here, we need to return true so the DataEngine
|
||||||
|
@ -36,8 +36,8 @@ public:
|
|||||||
SourcesOnRequestEngine(QObject *parent, const QVariantList &args);
|
SourcesOnRequestEngine(QObject *parent, const QVariantList &args);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool sourceRequestEvent(const QString &source);
|
bool sourceRequestEvent(const QString &source) override;
|
||||||
bool updateSourceEvent(const QString &source);
|
bool updateSourceEvent(const QString &source) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,8 +44,6 @@ CustomCorona::CustomCorona(QObject *parent)
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QRect CustomCorona::screenGeometry(int id) const
|
QRect CustomCorona::screenGeometry(int id) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(id);
|
Q_UNUSED(id);
|
||||||
@ -57,7 +55,6 @@ void CustomCorona::load()
|
|||||||
{
|
{
|
||||||
loadLayout(QStringLiteral("exampleplasmashell-appletsrc"));
|
loadLayout(QStringLiteral("exampleplasmashell-appletsrc"));
|
||||||
|
|
||||||
|
|
||||||
bool desktopFound = false;
|
bool desktopFound = false;
|
||||||
for (auto c : containments()) {
|
for (auto c : containments()) {
|
||||||
if (c->containmentType() == Plasma::Types::DesktopContainment) {
|
if (c->containmentType() == Plasma::Types::DesktopContainment) {
|
||||||
@ -69,7 +66,7 @@ void CustomCorona::load()
|
|||||||
if (!desktopFound) {
|
if (!desktopFound) {
|
||||||
qDebug() << "Loading default layout";
|
qDebug() << "Loading default layout";
|
||||||
Plasma::Containment *c = createContainment(QStringLiteral("org.kde.desktopcontainment"));
|
Plasma::Containment *c = createContainment(QStringLiteral("org.kde.desktopcontainment"));
|
||||||
c->createApplet("org.kde.plasma.analogclock");
|
c->createApplet(QStringLiteral("org.kde.plasma.analogclock"));
|
||||||
saveLayout(QStringLiteral("exampleplasmashell-appletsrc"));
|
saveLayout(QStringLiteral("exampleplasmashell-appletsrc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,10 +74,9 @@ void CustomCorona::load()
|
|||||||
for (auto c : containments()) {
|
for (auto c : containments()) {
|
||||||
if (c->containmentType() == Plasma::Types::DesktopContainment) {
|
if (c->containmentType() == Plasma::Types::DesktopContainment) {
|
||||||
//example of a shell without a wallpaper
|
//example of a shell without a wallpaper
|
||||||
c->setWallpaper("null");
|
c->setWallpaper(QStringLiteral("null"));
|
||||||
m_view->setContainment(c);
|
m_view->setContainment(c);
|
||||||
QAction *removeAction = c->actions()->action(QStringLiteral("remove"));
|
if (QAction *removeAction = c->actions()->action(QStringLiteral("remove"))) {
|
||||||
if(removeAction) {
|
|
||||||
removeAction->deleteLater();
|
removeAction->deleteLater();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -29,8 +29,8 @@ class CustomCorona : public Plasma::Corona
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CustomCorona(QObject * parent = nullptr);
|
explicit CustomCorona(QObject *parent = nullptr);
|
||||||
QRect screenGeometry(int id) const;
|
QRect screenGeometry(int id) const override;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void load();
|
void load();
|
||||||
|
@ -27,14 +27,12 @@
|
|||||||
|
|
||||||
#include "customcorona.h"
|
#include "customcorona.h"
|
||||||
|
|
||||||
static const char version[] = "1.0";
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QQuickWindow::setDefaultAlphaBuffer(true);
|
QQuickWindow::setDefaultAlphaBuffer(true);
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
app.setApplicationVersion(version);
|
app.setApplicationVersion(QStringLiteral("1.0"));
|
||||||
app.setOrganizationDomain(QStringLiteral("kde.org"));
|
app.setOrganizationDomain(QStringLiteral("kde.org"));
|
||||||
|
|
||||||
KDBusService service(KDBusService::Unique);
|
KDBusService service(KDBusService::Unique);
|
||||||
|
@ -37,7 +37,7 @@ QList<QAction *> ContextTest::contextualActions()
|
|||||||
Plasma::Containment *c = containment();
|
Plasma::Containment *c = containment();
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
QList<QAction *> actions;
|
QList<QAction *> actions;
|
||||||
actions << c->actions()->action("configure");
|
actions << c->actions()->action(QStringLiteral("configure"));
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,14 @@ public:
|
|||||||
|
|
||||||
void init(const KConfigGroup &config);
|
void init(const KConfigGroup &config);
|
||||||
|
|
||||||
QList<QAction *> contextualActions();
|
QList<QAction *> contextualActions() override;
|
||||||
|
|
||||||
void performNextAction();
|
void performNextAction() override;
|
||||||
void performPreviousAction();
|
void performPreviousAction() override;
|
||||||
|
|
||||||
QWidget *createConfigurationInterface(QWidget *parent);
|
QWidget *createConfigurationInterface(QWidget *parent) override;
|
||||||
void configurationAccepted();
|
void configurationAccepted() override;
|
||||||
void save(KConfigGroup &config);
|
void save(KConfigGroup &config) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Config m_ui;
|
Ui::Config m_ui;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user