aboutsummaryrefslogtreecommitdiff
path: root/examples/apscanner
diff options
context:
space:
mode:
authorTomas Junnonen <tomas.junnonen@nokia.com>2010-02-15 14:54:48 +0200
committerTomas Junnonen <tomas.junnonen@nokia.com>2010-02-15 14:54:48 +0200
commit0299123821c6c6367c23f59e135737f32b26c898 (patch)
tree48dcda1537576e0c646b4cfe823e83c2186a6a1e /examples/apscanner
Changes: First public release
RevBy: TrustMe
Diffstat (limited to 'examples/apscanner')
-rw-r--r--examples/apscanner/.gitignore1
-rw-r--r--examples/apscanner/apitemcreator.cpp40
-rw-r--r--examples/apscanner/apitemcreator.h37
-rw-r--r--examples/apscanner/apitemmodel.cpp117
-rw-r--r--examples/apscanner/apitemmodel.h53
-rw-r--r--examples/apscanner/apscanner.cpp83
-rw-r--r--examples/apscanner/apscanner.h56
-rw-r--r--examples/apscanner/apscanner.pro24
-rw-r--r--examples/apscanner/apscannerpage.cpp83
-rw-r--r--examples/apscanner/apscannerpage.h47
-rw-r--r--examples/apscanner/main.cpp34
-rw-r--r--examples/apscanner/pics/1signal.pngbin0 -> 12743 bytes
-rw-r--r--examples/apscanner/pics/2signal.pngbin0 -> 13344 bytes
-rw-r--r--examples/apscanner/pics/3signal.pngbin0 -> 13970 bytes
-rw-r--r--examples/apscanner/pics/4signal.pngbin0 -> 14738 bytes
-rw-r--r--examples/apscanner/pics/5signal.pngbin0 -> 15253 bytes
16 files changed, 575 insertions, 0 deletions
diff --git a/examples/apscanner/.gitignore b/examples/apscanner/.gitignore
new file mode 100644
index 00000000..3d6416d4
--- /dev/null
+++ b/examples/apscanner/.gitignore
@@ -0,0 +1 @@
+apscanner
diff --git a/examples/apscanner/apitemcreator.cpp b/examples/apscanner/apitemcreator.cpp
new file mode 100644
index 00000000..68c9efd6
--- /dev/null
+++ b/examples/apscanner/apitemcreator.cpp
@@ -0,0 +1,40 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libdui.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#include "apitemcreator.h"
+#include "apitemmodel.h"
+
+void APItemCreator::updateCell(const QModelIndex &index, DuiWidget *cell) const
+{
+ DuiContentItem *contentItem = qobject_cast<DuiContentItem *>(cell);
+ QVariant data = index.data(Qt::DisplayRole);
+ QStringList rowData = data.value<QStringList>();
+ contentItem->setTitle(rowData[0]);
+ if (rowData.count() > 1)
+ contentItem->setSubtitle(rowData[1]);
+ contentItem->setPixmap(QPixmap(rowData[2]));
+ contentItem->boundingRect();
+
+ if (index.row() == 0)
+ contentItem->setItemMode(DuiContentItem::SingleColumnTop);
+ else if (index.sibling(index.row() + 1, 0).isValid())
+ contentItem->setItemMode(DuiContentItem::SingleColumnCenter);
+ else
+ contentItem->setItemMode(DuiContentItem::SingleColumnBottom);
+}
diff --git a/examples/apscanner/apitemcreator.h b/examples/apscanner/apitemcreator.h
new file mode 100644
index 00000000..a3fe5731
--- /dev/null
+++ b/examples/apscanner/apitemcreator.h
@@ -0,0 +1,37 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libdui.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#ifndef APITEMCREATOR_H
+#define APITEMCREATOR_H
+
+#include <DuiList>
+#include <DuiContentItem>
+
+class APItemModel;
+
+class APItemCreator : public DuiAbstractCellCreator<DuiContentItem>
+{
+public:
+ void updateCell(const QModelIndex &index, DuiWidget *cell) const;
+
+public:
+ APItemModel *model;
+};
+
+#endif
diff --git a/examples/apscanner/apitemmodel.cpp b/examples/apscanner/apitemmodel.cpp
new file mode 100644
index 00000000..e96dc248
--- /dev/null
+++ b/examples/apscanner/apitemmodel.cpp
@@ -0,0 +1,117 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libdui.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#include <QTime>
+#include "apitemmodel.h"
+
+APItemModel::APItemModel()
+{
+ QTime time;
+ time.start();
+ qsrand(time.hour() + time.second() + time.minute());
+
+ theHeaderData.append("Title");
+ theHeaderData.append("Subtitle");
+ theHeaderData.append("Thumbnail");
+}
+
+APItemModel::~APItemModel()
+{
+}
+
+int APItemModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+
+ return theData.size();
+}
+
+int APItemModel::columnCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+
+ return theHeaderData.size();
+}
+
+QVariant APItemModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole) {
+ if (index.isValid() && index.row() < theData.size()) {
+ QStringList rowData = theData[index.row()];
+ return QVariant(rowData);
+ }
+ }
+
+ return QVariant();
+}
+
+QVariant APItemModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ Q_UNUSED(orientation);
+
+ if (role == Qt::DisplayRole) {
+ if (section < theHeaderData.size()) {
+ return QVariant(theHeaderData.at(section));
+ }
+ }
+
+ return QVariant();
+}
+
+bool APItemModel::insertRows(int row, int count, const QModelIndex &parent)
+{
+ beginInsertRows(parent, row, row + count - 1);
+ for (int i = 0; i < count; ++i) {
+ theData.insert(row + i, QStringList() << accessPointInfo.stationName << accessPointInfo.encryption << QString("./pics/") + QString::number(accessPointInfo.signalStrength) + QString("signal.png"));
+ }
+ endInsertRows();
+
+ return true;
+}
+
+bool APItemModel::removeRows(int row, int count, const QModelIndex &parent)
+{
+ beginRemoveRows(parent, row, row + count - 1);
+ theData.remove(row, count);
+ endRemoveRows();
+
+ return true;
+}
+
+int APItemModel::accessPointDataIndex(const QString &accessPointName)
+{
+ int index = -1;
+
+ for (int i = 0; i < rowCount(); ++i) {
+ QStringList rowData = theData.at(i);
+ if (rowData.at(0) == accessPointName) {
+ index = i;
+ break;
+ }
+ }
+
+ return index;
+}
+
+void APItemModel::updateAccessPointData(int accessPointDataIndex)
+{
+ theData.replace(accessPointDataIndex, QStringList() << accessPointInfo.stationName << accessPointInfo.encryption << QString("./pics/") + QString::number(accessPointInfo.signalStrength) + QString("signal.png"));
+ QModelIndex index = QAbstractItemModel::createIndex(accessPointDataIndex, accessPointDataIndex);
+ emit dataChanged(index, index);
+}
diff --git a/examples/apscanner/apitemmodel.h b/examples/apscanner/apitemmodel.h
new file mode 100644
index 00000000..b8a06bab
--- /dev/null
+++ b/examples/apscanner/apitemmodel.h
@@ -0,0 +1,53 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libdui.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#ifndef APITEMMODEL_H
+#define APITEMMODEL_H
+
+#include <QAbstractTableModel>
+#include <QVector>
+#include <QStringList>
+#include "apscanner.h"
+
+class APItemModel: public QAbstractTableModel
+{
+ Q_OBJECT
+
+public:
+ APItemModel();
+ virtual ~APItemModel();
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
+ bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
+
+public:
+ APScanner::AccessPointInfo accessPointInfo;
+ int accessPointDataIndex(const QString &accessPointName);
+ void updateAccessPointData(int accessPointDataIndex);
+
+private:
+ QVector<QStringList> theData;
+ QStringList theHeaderData;
+};
+
+#endif
diff --git a/examples/apscanner/apscanner.cpp b/examples/apscanner/apscanner.cpp
new file mode 100644
index 00000000..18bc2b31
--- /dev/null
+++ b/examples/apscanner/apscanner.cpp
@@ -0,0 +1,83 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libdui.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#include <QTimer>
+#include "apscanner.h"
+
+APScanner::APScanner()
+{
+ QStringList apNames = QStringList() << "Home"
+ << "Private"
+ << "Zyxel"
+ << "Kotiverkko"
+ << "Shared"
+ << "Tampere 1"
+ << "VoIP"
+ << "SWZone"
+ << "UTA"
+ << "PWLAN"
+ << "mobileAP"
+ << "ARP0482"
+ << "Koskikatu"
+ << "HimosHotelli"
+ << "DLinkWLAN";
+
+ QStringList apEncryptions = QStringList() << "Free" << "WEP" << "WPA" << "WPA2";
+
+ // Populate accessPointInfos list. Only signal strengths will be changed later on.
+ while (apNames.count()) {
+ AccessPointInfo apInfo;
+ apInfo.signalStrength = qrand() % 4; // initial signal strength varies from 0 to 3
+ apInfo.stationName = apNames.takeAt(qrand() % apNames.count());
+ apInfo.encryption = apEncryptions.at(qrand() % apEncryptions.count());
+ accessPointInfos << apInfo;
+ }
+}
+
+APScanner::~APScanner()
+{
+}
+
+void APScanner::startScanning()
+{
+ // Emit initial accessPointInfos if they have positive signal strength
+ for (int i = 0; i < accessPointInfos.count(); ++i) {
+ if (accessPointInfos.at(i).signalStrength > 0)
+ emit accessPointUpdate(accessPointInfos.at(i));
+ }
+
+ // Start timer to update access point infos
+ timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(updateAccessPoints()));
+ timer->start(1000);
+}
+
+void APScanner::updateAccessPoints()
+{
+ // Update accessPointInfos signal strength and emit updated infos
+ for (int i = 0; i < accessPointInfos.count(); ++i) {
+ int newStrength = (qrand() % 3 - 1) + accessPointInfos.at(i).signalStrength;
+ if (accessPointInfos.at(i).signalStrength != newStrength && newStrength >= 0 && newStrength <= 5) {
+
+ // Update signal strength and emit updated access point info
+ accessPointInfos[i].signalStrength = newStrength;
+ emit accessPointUpdate(accessPointInfos.at(i));
+ }
+ }
+}
diff --git a/examples/apscanner/apscanner.h b/examples/apscanner/apscanner.h
new file mode 100644
index 00000000..218f3ade
--- /dev/null
+++ b/examples/apscanner/apscanner.h
@@ -0,0 +1,56 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libdui.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#ifndef APSCANNER_H
+#define APSCANNER_H
+
+#include <QObject>
+#include <QStringList>
+
+class QTimer;
+
+class APScanner: public QObject
+{
+ Q_OBJECT
+
+public:
+ struct AccessPointInfo {
+ int signalStrength;
+ QString stationName;
+ QString encryption;
+ };
+ APScanner();
+ ~APScanner();
+
+public:
+ void startScanning();
+
+public Q_SLOTS:
+ void updateAccessPoints();
+
+Q_SIGNALS:
+ void accessPointUpdate(const APScanner::AccessPointInfo &accessPoint);
+
+private:
+ QStringList accessPointNames;
+ QList<AccessPointInfo> accessPointInfos;
+ QTimer *timer;
+};
+
+#endif
diff --git a/examples/apscanner/apscanner.pro b/examples/apscanner/apscanner.pro
new file mode 100644
index 00000000..b42f0eac
--- /dev/null
+++ b/examples/apscanner/apscanner.pro
@@ -0,0 +1,24 @@
+CONFIG += dui qt link_pkgconfig debug
+TEMPLATE = app
+TARGET = apscanner
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp \
+ apscanner.cpp \
+ apscannerpage.cpp \
+ apitemmodel.cpp \
+ apitemcreator.cpp
+
+HEADERS += apscanner.h \
+ apscannerpage.h \
+ apitemmodel.h \
+ apitemcreator.h
+
+# The following lines are only to allow building the
+# example inside the source tree without installing
+# libdui first:
+INCLUDEPATH += ../../src/include
+QMAKE_LIBDIR += ../../lib/
+LIBS += -ldui
diff --git a/examples/apscanner/apscannerpage.cpp b/examples/apscanner/apscannerpage.cpp
new file mode 100644
index 00000000..5c1b7632
--- /dev/null
+++ b/examples/apscanner/apscannerpage.cpp
@@ -0,0 +1,83 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libdui.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#include <DuiLayout>
+#include <DuiLinearLayoutPolicy>
+#include <DuiList>
+#include "apscannerpage.h"
+#include "apitemcreator.h"
+#include "apitemmodel.h"
+
+APScannerPage::APScannerPage()
+{
+ setTitle("APScanner");
+}
+
+APScannerPage::~APScannerPage()
+{
+ delete scanner;
+}
+
+void APScannerPage::createContent()
+{
+ DuiWidget *panel = centralWidget();
+ DuiLayout *layout = new DuiLayout(panel);
+ layout->setAnimation(NULL);
+ panel->setLayout(layout);
+ DuiLinearLayoutPolicy *policy = new DuiLinearLayoutPolicy(layout, Qt::Vertical);
+
+ // DuiList with fast view
+ list = new DuiList(panel);
+ list->setViewType("fast");
+ list->setObjectName("wgList");
+ list->setSelectionMode(DuiList::MultiSelection);
+ list->setShowGroups(false);
+
+ // Content item creator and item model for the list
+ APItemCreator *cellCreator = new APItemCreator();
+ list->setCellCreator(cellCreator);
+ model = new APItemModel();
+ cellCreator->model = model;
+ list->setItemModel(model);
+ policy->addItem(list);
+
+ // Start scanning access points
+ scanner = new APScanner();
+ connect(scanner, SIGNAL(accessPointUpdate(APScanner::AccessPointInfo)), this, SLOT(accessPointUpdate(APScanner::AccessPointInfo)));
+ scanner->startScanning();
+}
+
+void APScannerPage::accessPointUpdate(const APScanner::AccessPointInfo &accessPoint)
+{
+ int accessPointDataIndex = model->accessPointDataIndex(accessPoint.stationName);
+
+ // Handle adding, removing and updating list items
+ if (accessPointDataIndex == -1) {
+ model->accessPointInfo = accessPoint;
+ model->insertRows(model->rowCount(), 1);
+ } else if (accessPoint.signalStrength == 0) {
+ model->removeRows(accessPointDataIndex, 1);
+ } else {
+ model->accessPointInfo = accessPoint;
+ model->updateAccessPointData(accessPointDataIndex);
+ }
+
+ // Set application title to indicate found action points
+ setTitle("AP Scanner (" + QString::number(model->rowCount()) + " found)");
+}
diff --git a/examples/apscanner/apscannerpage.h b/examples/apscanner/apscannerpage.h
new file mode 100644
index 00000000..a4b94295
--- /dev/null
+++ b/examples/apscanner/apscannerpage.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libdui.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#ifndef APSCANNERPAGE_H
+#define APSCANNERPAGE_H
+
+#include <DuiApplicationPage>
+#include "apscanner.h"
+
+class DuiList;
+class APItemModel;
+
+class APScannerPage: public DuiApplicationPage
+{
+ Q_OBJECT
+
+public:
+ APScannerPage();
+ virtual ~APScannerPage();
+ virtual void createContent();
+
+public Q_SLOTS:
+ void accessPointUpdate(const APScanner::AccessPointInfo &accessPoint);
+
+private:
+ DuiList *list;
+ APScanner *scanner;
+ APItemModel *model;
+};
+
+#endif
diff --git a/examples/apscanner/main.cpp b/examples/apscanner/main.cpp
new file mode 100644
index 00000000..a16b44ef
--- /dev/null
+++ b/examples/apscanner/main.cpp
@@ -0,0 +1,34 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libdui.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#include <DuiApplication>
+#include <DuiApplicationWindow>
+#include "apscannerpage.h"
+
+int main(int argc, char **argv)
+{
+ DuiApplication app(argc, argv);
+ DuiApplicationWindow window;
+ window.show();
+
+ APScannerPage page;
+ page.appear();
+
+ return app.exec();
+}
diff --git a/examples/apscanner/pics/1signal.png b/examples/apscanner/pics/1signal.png
new file mode 100644
index 00000000..2b82c12c
--- /dev/null
+++ b/examples/apscanner/pics/1signal.png
Binary files differ
diff --git a/examples/apscanner/pics/2signal.png b/examples/apscanner/pics/2signal.png
new file mode 100644
index 00000000..08fb1376
--- /dev/null
+++ b/examples/apscanner/pics/2signal.png
Binary files differ
diff --git a/examples/apscanner/pics/3signal.png b/examples/apscanner/pics/3signal.png
new file mode 100644
index 00000000..110f90bc
--- /dev/null
+++ b/examples/apscanner/pics/3signal.png
Binary files differ
diff --git a/examples/apscanner/pics/4signal.png b/examples/apscanner/pics/4signal.png
new file mode 100644
index 00000000..346ac850
--- /dev/null
+++ b/examples/apscanner/pics/4signal.png
Binary files differ
diff --git a/examples/apscanner/pics/5signal.png b/examples/apscanner/pics/5signal.png
new file mode 100644
index 00000000..c8622ee9
--- /dev/null
+++ b/examples/apscanner/pics/5signal.png
Binary files differ