From 182bdd709a57ab4d17f163ae28c5663fb3dd4287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sun, 22 May 2011 20:48:02 +0200 Subject: Added TableRoster. diff --git a/Swift/Controllers/Roster/TableRoster.cpp b/Swift/Controllers/Roster/TableRoster.cpp new file mode 100644 index 0000000..fda7de8 --- /dev/null +++ b/Swift/Controllers/Roster/TableRoster.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include + +#include + +#include +#include + +using namespace Swift; + +TableRoster::TableRoster(Roster* model) : model(model) { +} + +size_t TableRoster::getNumberOfSections() const { + return model ? model->getRoot()->getDisplayedChildren().size() : 0; +} + +size_t TableRoster::getNumberOfRowsInSection(size_t section) const { + return boost::polymorphic_downcast(model->getRoot()->getDisplayedChildren()[section])->getDisplayedChildren().size(); +} + +const std::string& TableRoster::getSectionTitle(size_t section) { + return model->getRoot()->getDisplayedChildren()[section]->getDisplayName(); +} + +TableRoster::Item TableRoster::getItem(const Index& index) const { + Item item; + item.name = boost::polymorphic_downcast(model->getRoot()->getDisplayedChildren().at(index.section))->getDisplayedChildren().at(index.row)->getDisplayName(); + item.description = "My Status"; + return item; +} diff --git a/Swift/Controllers/Roster/TableRoster.h b/Swift/Controllers/Roster/TableRoster.h new file mode 100644 index 0000000..7d92995 --- /dev/null +++ b/Swift/Controllers/Roster/TableRoster.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include +#include +#include + +#include + +namespace Swift { + class Roster; + + class TableRoster { + public: + struct Item { + std::string name; + std::string description; + JID jid; + }; + struct Index { + Index(size_t section, size_t row) : section(section), row(row) { + } + size_t section; + size_t row; + }; + + TableRoster(Roster* model); + + size_t getNumberOfSections() const; + size_t getNumberOfRowsInSection(size_t section) const; + + const std::string& getSectionTitle(size_t); + + Item getItem(const Index&) const; + + boost::signal onBeginUpdates; + boost::signal&)> onRowsInserted; + boost::signal&)> onRowsDeleted; + boost::signal&)> onSectionsInserted; + boost::signal&)> onSectionsDeleted; + boost::signal onEndUpdates; + + private: + Roster* model; + }; +} diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript index eed1f4d..a7df3a9 100644 --- a/Swift/Controllers/SConscript +++ b/Swift/Controllers/SConscript @@ -37,6 +37,7 @@ if env["SCONS_STAGE"] == "build" : "Roster/GroupRosterItem.cpp", "Roster/RosterItem.cpp", "Roster/Roster.cpp", + "Roster/TableRoster.cpp", "EventWindowController.cpp", "SoundEventController.cpp", "SystemTrayController.cpp", -- cgit v0.10.2-6-g49f6