From 94829f17066dcbbeb9f641a4870dd88aa916ba24 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 5 Oct 2016 20:07:53 +0200 Subject: A better resource filter api --- examples/client/CMakeLists.txt | 8 -- examples/client/console.cpp | 76 -------------- examples/client/console.h | 42 -------- examples/client/main.cpp | 222 ----------------------------------------- 4 files changed, 348 deletions(-) delete mode 100644 examples/client/CMakeLists.txt delete mode 100644 examples/client/console.cpp delete mode 100644 examples/client/console.h delete mode 100644 examples/client/main.cpp (limited to 'examples/client') diff --git a/examples/client/CMakeLists.txt b/examples/client/CMakeLists.txt deleted file mode 100644 index ef00368..0000000 --- a/examples/client/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -project(sink_client) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) - -add_executable(${PROJECT_NAME} main.cpp console.cpp) -target_link_libraries(${PROJECT_NAME} sink) -qt5_use_modules(${PROJECT_NAME} Widgets Network) -install(TARGETS ${PROJECT_NAME} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/examples/client/console.cpp b/examples/client/console.cpp deleted file mode 100644 index 8b4f1a5..0000000 --- a/examples/client/console.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2014 Aaron Seigo - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#include "console.h" - -#include -#include -#include -#include - -static Console *s_console = 0; - -Console *Console::main() -{ - if (!s_console) { - s_console = new Console(QString()); - } - return s_console; -} - -Console::Console(const QString &title) - : QWidget(0) -{ - if (!s_console) { - s_console = this; - } - - resize(1000, 1500); - - QVBoxLayout *topLayout = new QVBoxLayout(this); - - QLabel *titleLabel = new QLabel(this); - titleLabel->setText(title); - QFont font = titleLabel->font(); - font.setWeight(QFont::Bold); - titleLabel->setFont(font); - titleLabel->setAlignment(Qt::AlignCenter); - - QFont consoleFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); - consoleFont.setPointSize(7); - m_textDisplay = new QTextBrowser(this); - m_textDisplay->document()->setDefaultFont(consoleFont); - topLayout->addWidget(titleLabel); - topLayout->addWidget(m_textDisplay, 10); - - show(); - m_timestamper.start(); -} - -Console::~Console() -{ - -} - -void Console::log(const QString &message) -{ - m_textDisplay->append(QString::number(m_timestamper.elapsed()).rightJustified(6) + ": " + message); -} - diff --git a/examples/client/console.h b/examples/client/console.h deleted file mode 100644 index a6fef01..0000000 --- a/examples/client/console.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2014 Aaron Seigo - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#pragma once - -#include -#include - -class QTextBrowser; - -class Console : public QWidget -{ - Q_OBJECT -public: - static Console *main(); - Console(const QString &title); - ~Console(); - - void log(const QString &message); - -private: - QTextBrowser *m_textDisplay; - QTime m_timestamper; - static Console *s_output; -}; diff --git a/examples/client/main.cpp b/examples/client/main.cpp deleted file mode 100644 index f4b472f..0000000 --- a/examples/client/main.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (C) 2014 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include - -#include "common/store.h" -#include "common/log.h" - -#include -#include -#include -#include -#include -#include -#include - -/** - * A small abstraction layer to use the sink store with the type available as string. - */ -class StoreBase { -public: - virtual ~StoreBase(){}; - virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() = 0; - virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) = 0; - virtual KAsync::Job create(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; - virtual KAsync::Job modify(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; - virtual KAsync::Job remove(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; - virtual QSharedPointer loadModel(const Sink::Query &query) = 0; -}; - -template -class Store : public StoreBase { -public: - Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE { - return T::Ptr::create(); - } - - Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) Q_DECL_OVERRIDE { - return T::Ptr::create(resourceInstanceIdentifier, identifier, 0, QSharedPointer::create()); - } - - KAsync::Job create(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Sink::Store::create(*static_cast(&type)); - } - - KAsync::Job modify(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Sink::Store::modify(*static_cast(&type)); - } - - KAsync::Job remove(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Sink::Store::remove(*static_cast(&type)); - } - - QSharedPointer loadModel(const Sink::Query &query) Q_DECL_OVERRIDE { - return Sink::Store::loadModel(query); - } -}; - -StoreBase& getStore(const QString &type) -{ - if (type == "folder") { - static Store store; - return store; - } else if (type == "mail") { - static Store store; - return store; - } else if (type == "event") { - static Store store; - return store; - } else if (type == "resource") { - static Store store; - return store; - } - Q_ASSERT(false); - qWarning() << "Trying to get a store that doesn't exist, falling back to event"; - static Store store; - return store; -} - -template -class View : public QWidget -{ -public: - View(QAbstractItemModel *model) - : QWidget() - { - auto modelView = new QTreeView(this); - modelView->setModel(model); - resize(1000, 1500); - - auto topLayout = new QVBoxLayout(this); - - auto titleLabel = new QLabel(this); - titleLabel->setText("Demo"); - auto font = titleLabel->font(); - font.setWeight(QFont::Bold); - titleLabel->setFont(font); - titleLabel->setAlignment(Qt::AlignCenter); - - auto syncButton = new QPushButton(this); - syncButton->setText("Synchronize!"); - QObject::connect(syncButton, &QPushButton::pressed, []() { - Sink::Query query; - query.resources << "sink.dummy.instance1"; - Sink::Store::synchronize(query).exec(); - }); - - auto removeButton = new QPushButton(this); - removeButton->setText("Remove"); - QObject::connect(removeButton, &QPushButton::pressed, [modelView]() { - for (auto index : modelView->selectionModel()->selectedIndexes()) { - auto object = index.data(Sink::Store::DomainObjectRole).value(); - Sink::Store::remove(*object).exec(); - } - }); - - topLayout->addWidget(titleLabel); - topLayout->addWidget(syncButton); - topLayout->addWidget(removeButton); - topLayout->addWidget(modelView, 10); - - show(); - } - -}; - -static QSharedPointer loadModel(const QString &type, Sink::Query query) -{ - QTime time; - time.start(); - if (type == "folder") { - query.requestedProperties << "name" << "parent"; - } else if (type == "mail") { - query.requestedProperties << "subject" << "folder" << "date"; - } else if (type == "event") { - query.requestedProperties << "summary"; - } else if (type == "resource") { - query.requestedProperties << "type"; - } - auto model = getStore(type).loadModel(query); - qDebug() << "Folder type " << type; - qDebug() << "Loaded model in " << time.elapsed() << " ms"; - Q_ASSERT(model); - return model; -} - -QMap consumeMap(QList &list) -{ - QMap map; - while(list.size() >= 2) { - map.insert(list.at(0), list.at(1)); - list = list.mid(2); - } - return map; -} - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QCommandLineParser cliOptions; - cliOptions.addPositionalArgument(QObject::tr("[type]"), - QObject::tr("A type to work with")); - cliOptions.addPositionalArgument(QObject::tr("[resource]"), - QObject::tr("A resource to connect to")); - cliOptions.addOption(QCommandLineOption("debuglevel", "A debuglevel from 0-6", "debuglevel")); - cliOptions.addHelpOption(); - cliOptions.process(app); - QStringList args = cliOptions.positionalArguments(); - - if (cliOptions.isSet("debuglevel")) { - Sink::Log::setDebugOutputLevel(static_cast(cliOptions.value("debuglevel").toInt())); - } - - auto type = !args.isEmpty() ? args.takeFirst() : QByteArray(); - auto resources = args; - - Sink::Query query; - for (const auto &res : resources) { - query.resources << res.toLatin1(); - } - query.liveQuery = true; - if (type == "folder") { - query.parentProperty = "parent"; - } - auto model = loadModel(type, query); - if (type == "folder") { - QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { - for (int i = start; i <= end; i++) { - model->fetchMore(model->index(i, 0, index)); - } - }); - auto view = QSharedPointer >::create(model.data()); - app.exec(); - } else if (type == "mail") { - auto view = QSharedPointer >::create(model.data()); - app.exec(); - } else if (type == "event") { - auto view = QSharedPointer >::create(model.data()); - app.exec(); - } - return 0; -} -- cgit v1.2.3