[Telepathy-commits] [telepathy-qt4/master] Account: Added accounts example that list all accounts exposed by AM.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Wed Feb 11 20:51:53 PST 2009


---
 configure.ac                          |    1 +
 examples/Makefile.am                  |    2 +-
 examples/accounts/Makefile.am         |   33 +++++++
 examples/accounts/account-item.cpp    |  158 +++++++++++++++++++++++++++++++++
 examples/accounts/account-item.h      |   88 ++++++++++++++++++
 examples/accounts/accounts-window.cpp |   95 ++++++++++++++++++++
 examples/accounts/accounts-window.h   |   55 ++++++++++++
 examples/accounts/main.cpp            |   21 +++++
 8 files changed, 452 insertions(+), 1 deletions(-)
 create mode 100644 examples/accounts/Makefile.am
 create mode 100644 examples/accounts/account-item.cpp
 create mode 100644 examples/accounts/account-item.h
 create mode 100644 examples/accounts/accounts-window.cpp
 create mode 100644 examples/accounts/accounts-window.h
 create mode 100644 examples/accounts/main.cpp

diff --git a/configure.ac b/configure.ac
index 3e1c9ab..bce95d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -241,6 +241,7 @@ AC_OUTPUT([
     doxygen.cfg
     examples/Makefile
     examples/extensions/Makefile
+    examples/accounts/Makefile
     m4/Makefile
     spec/Makefile
     tests/Makefile
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 1b5c62d..e399b2e 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1 +1 @@
-SUBDIRS = extensions
+SUBDIRS = extensions accounts
diff --git a/examples/accounts/Makefile.am b/examples/accounts/Makefile.am
new file mode 100644
index 0000000..d4143cf
--- /dev/null
+++ b/examples/accounts/Makefile.am
@@ -0,0 +1,33 @@
+AM_CXXFLAGS = \
+	$(ERROR_CXXFLAGS) \
+	$(QTGUI_CFLAGS) \
+	$(QTDBUS_CFLAGS) \
+	$(TP_QT4_CFLAGS)
+
+noinst_PROGRAMS = accounts
+
+accounts_LDADD = \
+	$(QTGUI_LIBS) \
+	$(QTDBUS_LIBS) \
+	$(top_builddir)/TelepathyQt4/libtelepathy-qt4.la
+
+accounts_SOURCES = \
+	main.cpp \
+	account-item.cpp \
+	account-item.h \
+	accounts-window.cpp \
+	accounts-window.h
+
+nodist_accounts_SOURCES = \
+	_gen/account-item.moc.hpp \
+	_gen/accounts-window.moc.hpp
+
+BUILT_SOURCES = \
+	$(nodist_accounts_SOURCES)
+
+CLEANFILES = \
+	$(BUILT_SOURCES)
+
+_gen/%.moc.hpp: %.h
+	$(mkdir_p) _gen
+	$(MOC) @QTCORE_CFLAGS@ @QTDBUS_CFLAGS@ -I$(top_builddir) -I$(top_srcdir) -i $< -o $@
diff --git a/examples/accounts/account-item.cpp b/examples/accounts/account-item.cpp
new file mode 100644
index 0000000..5b9ddf7
--- /dev/null
+++ b/examples/accounts/account-item.cpp
@@ -0,0 +1,158 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * 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) 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
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "account-item.h"
+#include "_gen/account-item.moc.hpp"
+
+#include <TelepathyQt4/Client/AccountManager>
+#include <TelepathyQt4/Client/PendingReadyAccount>
+
+#include <QDebug>
+#include <QComboBox>
+#include <QTableWidget>
+
+AccountItem::AccountItem(Telepathy::Client::AccountManager *am,
+        const QString &objectPath, QTableWidget *table, int row, QObject *parent)
+    : QObject(parent),
+      acc(new Telepathy::Client::Account(am, objectPath, this)),
+      mTable(table),
+      mRow(row)
+{
+    connect(acc->becomeReady(),
+            SIGNAL(finished(Telepathy::Client::PendingOperation *)),
+            SLOT(onReady(Telepathy::Client::PendingOperation *)));
+}
+
+AccountItem::~AccountItem()
+{
+}
+
+void AccountItem::setupGui()
+{
+    mTable->setItem(mRow, ColumnValid, new QTableWidgetItem(acc->isValid() ? "true" : "false"));
+    mTable->setItem(mRow, ColumnEnabled, new QTableWidgetItem(acc->isEnabled() ? "true" : "false"));
+    mTable->setItem(mRow, ColumnConnectionManager, new QTableWidgetItem(acc->cmName()));
+    mTable->setItem(mRow, ColumnProtocol, new QTableWidgetItem(acc->protocol()));
+    mTable->setItem(mRow, ColumnDisplayName, new QTableWidgetItem(acc->displayName()));
+    mTable->setItem(mRow, ColumnNickname, new QTableWidgetItem(acc->nickname()));
+    mTable->setItem(mRow, ColumnConnectsAutomatically, new QTableWidgetItem(acc->connectsAutomatically() ? "true" : "false"));
+    mTable->setItem(mRow, ColumnAutomaticPresence, new QTableWidgetItem(acc->automaticPresence().status));
+    mTable->setItem(mRow, ColumnCurrentPresence, new QTableWidgetItem(acc->currentPresence().status));
+    mTable->setItem(mRow, ColumnRequestedPresence, new QTableWidgetItem(acc->requestedPresence().status));
+    mTable->setItem(mRow, ColumnConnectionStatus, new QTableWidgetItem(QString::number(acc->connectionStatus())));
+    mTable->setItem(mRow, ColumnConnection, new QTableWidgetItem(acc->connectionObjectPath()));
+}
+
+void AccountItem::onReady(Telepathy::Client::PendingOperation *op)
+{
+    setupGui();
+
+    connect(acc,
+            SIGNAL(validityChanged(bool)),
+            SLOT(onValidityChanged(bool)));
+    connect(acc,
+            SIGNAL(stateChanged(bool)),
+            SLOT(onStateChanged(bool)));
+    connect(acc,
+            SIGNAL(displayNameChanged(const QString &)),
+            SLOT(onDisplayNameChanged(const QString &)));
+    connect(acc,
+            SIGNAL(nicknameChanged(const QString &)),
+            SLOT(onNicknameChanged(const QString &)));
+    connect(acc,
+            SIGNAL(connectsAutomaticallyPropertyChanged(bool)),
+            SLOT(onConnectsAutomaticallyPropertyChanged(bool)));
+    connect(acc,
+            SIGNAL(automaticPresenceChanged(const Telepathy::SimplePresence &)),
+            SLOT(onAutomaticPresenceChanged(const Telepathy::SimplePresence &)));
+    connect(acc,
+            SIGNAL(presenceChanged(const Telepathy::SimplePresence &)),
+            SLOT(onCurrentPresenceChanged(const Telepathy::SimplePresence &)));
+    connect(acc,
+            SIGNAL(requestedPresenceChanged(const Telepathy::SimplePresence &)),
+            SLOT(onRequestedPresenceChanged(const Telepathy::SimplePresence &)));
+    connect(acc,
+            SIGNAL(connectionStatusChanged(Telepathy::ConnectionStatus, Telepathy::ConnectionStatusReason)),
+            SLOT(onConnectionStatusChanged(Telepathy::ConnectionStatus, Telepathy::ConnectionStatusReason)));
+    connect(acc,
+            SIGNAL(haveConnectionChanged(bool)),
+            SLOT(onHaveConnectionChanged(bool)));
+}
+
+void AccountItem::onValidityChanged(bool valid)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnValid);
+    item->setText((valid ? "true" : "false"));
+}
+
+void AccountItem::onStateChanged(bool enabled)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnEnabled);
+    item->setText((enabled ? "true" : "false"));
+}
+
+void AccountItem::onDisplayNameChanged(const QString &name)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnDisplayName);
+    item->setText(name);
+}
+
+void AccountItem::onNicknameChanged(const QString &name)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnNickname);
+    item->setText(name);
+}
+
+void AccountItem::onConnectsAutomaticallyPropertyChanged(bool value)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnConnectsAutomatically);
+    item->setText((value ? "true" : "false"));
+}
+
+void AccountItem::onAutomaticPresenceChanged(const Telepathy::SimplePresence &presence)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnAutomaticPresence);
+    item->setText(presence.status);
+}
+
+void AccountItem::onCurrentPresenceChanged(const Telepathy::SimplePresence &presence)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnCurrentPresence);
+    item->setText(presence.status);
+}
+
+void AccountItem::onRequestedPresenceChanged(const Telepathy::SimplePresence &presence)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnRequestedPresence);
+    item->setText(presence.status);
+}
+
+void AccountItem::onConnectionStatusChanged(Telepathy::ConnectionStatus status,
+        Telepathy::ConnectionStatusReason reason)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnConnectionStatus);
+    item->setText(QString::number(status));
+}
+
+void AccountItem::onHaveConnectionChanged(bool haveConnection)
+{
+    QTableWidgetItem *item = mTable->item(mRow, ColumnConnection);
+    item->setText(acc->connectionObjectPath());
+}
diff --git a/examples/accounts/account-item.h b/examples/accounts/account-item.h
new file mode 100644
index 0000000..225f2dd
--- /dev/null
+++ b/examples/accounts/account-item.h
@@ -0,0 +1,88 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * 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) 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
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _TelepathyQt4_examples_accounts_account_item_h_HEADER_GUARD_
+#define _TelepathyQt4_examples_accounts_account_item_h_HEADER_GUARD_
+
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/Client/Account>
+
+#include <QString>
+
+namespace Telepathy {
+namespace Client {
+class AccountManager;
+class PendingOperation;
+}
+}
+
+class QTableWidget;
+
+class AccountItem : public QObject
+{
+    Q_OBJECT
+
+public:
+    enum Columns {
+        ColumnValid = 0,
+        ColumnEnabled,
+        ColumnConnectionManager,
+        ColumnProtocol,
+        ColumnDisplayName,
+        ColumnNickname,
+        ColumnConnectsAutomatically,
+        ColumnAutomaticPresence,
+        ColumnCurrentPresence,
+        ColumnRequestedPresence,
+        ColumnConnectionStatus,
+        ColumnConnection,
+        NumColumns
+    };
+    Q_ENUMS(Columns)
+
+    AccountItem(Telepathy::Client::AccountManager *am, const QString &objectPath,
+                QTableWidget *table, int row, QObject *parent = 0);
+    virtual ~AccountItem();
+
+    int row() const { return mRow; }
+
+private Q_SLOTS:
+    void onReady(Telepathy::Client::PendingOperation *);
+    void onValidityChanged(bool);
+    void onStateChanged(bool);
+    void onDisplayNameChanged(const QString &);
+    void onNicknameChanged(const QString &);
+    void onConnectsAutomaticallyPropertyChanged(bool);
+    void onAutomaticPresenceChanged(const Telepathy::SimplePresence &);
+    void onCurrentPresenceChanged(const Telepathy::SimplePresence &);
+    void onRequestedPresenceChanged(const Telepathy::SimplePresence &);
+    void onConnectionStatusChanged(Telepathy::ConnectionStatus,
+            Telepathy::ConnectionStatusReason);
+    void onHaveConnectionChanged(bool);
+
+private:
+    void setupGui();
+
+    Telepathy::Client::Account *acc;
+    QTableWidget *mTable;
+    int mRow;
+};
+
+#endif
diff --git a/examples/accounts/accounts-window.cpp b/examples/accounts/accounts-window.cpp
new file mode 100644
index 0000000..e501096
--- /dev/null
+++ b/examples/accounts/accounts-window.cpp
@@ -0,0 +1,95 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * 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) 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
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "accounts-window.h"
+#include "_gen/accounts-window.moc.hpp"
+
+#include "account-item.h"
+
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/Client/Account>
+#include <TelepathyQt4/Client/AccountManager>
+#include <TelepathyQt4/Client/PendingOperation>
+
+#include <QCheckBox>
+#include <QDebug>
+#include <QHBoxLayout>
+#include <QItemEditorCreatorBase>
+#include <QItemEditorFactory>
+#include <QTableWidget>
+
+AccountsWindow::AccountsWindow(QWidget *parent)
+    : QMainWindow(parent)
+{
+    setupGui();
+
+    mAM = new Telepathy::Client::AccountManager(this);
+    connect(mAM->becomeReady(),
+            SIGNAL(finished(Telepathy::Client::PendingOperation *)),
+            SLOT(onAMReady(Telepathy::Client::PendingOperation *)));
+    connect(mAM,
+            SIGNAL(accountCreated(const QString &)),
+            SLOT(onAccountCreated(const QString &)));
+}
+
+AccountsWindow::~AccountsWindow()
+{
+}
+
+void AccountsWindow::setupGui()
+{
+    mTable = new QTableWidget;
+
+    mTable->setColumnCount(AccountItem::NumColumns);
+    QStringList headerLabels;
+    headerLabels <<
+        "Valid" <<
+        "Enabled" <<
+        "Connection Manager" <<
+        "Protocol" <<
+        "Display Name" <<
+        "Nickname" <<
+        "Connects Automatically" <<
+        "Automatic Presence" <<
+        "Current Presence" <<
+        "Requested Presence" <<
+        "Connection Status" <<
+        "Connection";
+    mTable->setHorizontalHeaderLabels(headerLabels);
+
+    setCentralWidget(mTable);
+}
+
+void AccountsWindow::onAMReady(Telepathy::Client::PendingOperation *op)
+{
+    mTable->setRowCount(mAM->validAccountPaths().count());
+
+    int row = 0;
+    foreach (const QString &path, mAM->allAccountPaths()) {
+        (void) new AccountItem(mAM, path, mTable, row++, this);
+    }
+}
+
+void AccountsWindow::onAccountCreated(const QString &path)
+{
+    int row = mTable->rowCount();
+    mTable->insertRow(row);
+    (void) new AccountItem(mAM, path, mTable, row, this);
+}
diff --git a/examples/accounts/accounts-window.h b/examples/accounts/accounts-window.h
new file mode 100644
index 0000000..88d1ccd
--- /dev/null
+++ b/examples/accounts/accounts-window.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * 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) 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
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _TelepathyQt4_examples_accounts_accounts_window_h_HEADER_GUARD_
+#define _TelepathyQt4_examples_accounts_accounts_window_h_HEADER_GUARD_
+
+#include <QMainWindow>
+
+namespace Telepathy {
+namespace Client {
+class AccountManager;
+class PendingOperation;
+}
+}
+
+class QTableWidget;
+class QTableWidgetItem;
+
+class AccountsWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    AccountsWindow(QWidget *parent = 0);
+    virtual ~AccountsWindow();
+
+private Q_SLOTS:
+    void onAMReady(Telepathy::Client::PendingOperation *);
+    void onAccountCreated(const QString &);
+
+private:
+    void setupGui();
+
+    Telepathy::Client::AccountManager *mAM;
+    QTableWidget *mTable;
+};
+
+#endif
diff --git a/examples/accounts/main.cpp b/examples/accounts/main.cpp
new file mode 100644
index 0000000..e6e87e1
--- /dev/null
+++ b/examples/accounts/main.cpp
@@ -0,0 +1,21 @@
+#include <TelepathyQt4/Debug>
+#include <TelepathyQt4/Constants>
+#include <TelepathyQt4/Types>
+
+#include <QtGui>
+
+#include "accounts-window.h"
+
+int main(int argc, char **argv)
+{
+    QApplication app(argc, argv);
+
+    Telepathy::registerTypes();
+    Telepathy::enableDebug(true);
+    Telepathy::enableWarnings(true);
+
+    AccountsWindow w;
+    w.show();
+
+    return app.exec();
+}
-- 
1.5.6.5



More information about the telepathy-commits mailing list