examples/NFC/nfcshareexample/nfcsharewindow.cpp

00001 /*
00002  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *  
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  * 
00007  * Redistributions of source code must retain the above copyright notice, this
00008  *  list of conditions and the following disclaimer.
00009  * Redistributions in binary form must reproduce the above copyright notice,
00010  *   this list of conditions and the following disclaimer in the documentation
00011  *   and/or other materials provided with the distribution.
00012  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *  may be used to endorse or promote products derived from this software
00014  * without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *
00027  * Description:  source file of nfc share main window.
00028  * 
00029  */
00030 
00031 // User Include Files.
00032 #include "nfcsharewindow.h"
00033 #include "nfcsharewrapper.h"
00034 
00035 // System Include Files.
00036 #include <QMessageBox>
00037 
00038 
00039 /*
00040  * Constructor, create an instance of the wrapper class, initializes the UI by 
00041  * creating menubar and populates the menu items and 
00042  * connects signals to the slots.
00043  */
00044 NfcShareWindow::NfcShareWindow(QWidget *parent) : QMainWindow(parent)
00045 {
00046     mNfcShareWrapper = new NfcShareWrapper();   
00047     menubar = new QMenuBar(this);
00048     menubar->setObjectName(QString::fromUtf8("menubar"));
00049     menubar->setGeometry(QRect(0, 0, 800, 18));
00050     setMenuBar(menubar);
00051 
00052     createMenu();
00053 }
00054 /*
00055  * Creates the menu actions items, populate them to menubar and 
00056  * connect to respective handlers for the actions.
00057  */
00058 void NfcShareWindow::createMenu()
00059 {
00060     // Add start easy setup menu item.
00061     menu_startEasySetup= new QAction(tr("Start Easy setup"), this);
00062     menuBar()->addAction(menu_startEasySetup);
00063     connect(menu_startEasySetup, SIGNAL(triggered()), this, SLOT(startEasySetupService()));
00064        
00065         // Add start sharing vCard menu item.
00066     menu_startSharingvCard= new QAction(tr("Start Sharing vCard"), this);
00067     menuBar()->addAction(menu_startSharingvCard);
00068     connect(menu_startSharingvCard , SIGNAL(triggered()), this, SLOT(startSharingvCard()));
00069 
00070     // Add start sharing vCal menu item.
00071     menu_startSharingvCal= new QAction(tr("Start Sharing vCal"), this);
00072     menuBar()->addAction(menu_startSharingvCal);
00073     connect(menu_startSharingvCal , SIGNAL(triggered()), this, SLOT(startSharingvCal()));
00074 
00075     // Add stop easy setup menu item.
00076     menu_stopEasySetup = new QAction(tr("Stop Easy setup"), this);
00077     menuBar()->addAction(menu_stopEasySetup);
00078     connect(menu_stopEasySetup, SIGNAL(triggered()), this, SLOT(stopEasySetupService()));
00079 
00080     // Add help menu item.
00081     menu_helpAction = new QAction(tr("Help"), this);
00082     menuBar()->addAction(menu_helpAction);
00083     connect(menu_helpAction, SIGNAL(triggered()), this, SLOT(helpAction()));
00084     
00085     // Add About menu item.
00086     menu_aboutAction = new QAction(tr("About"), this);
00087     menuBar()->addAction(menu_aboutAction);
00088     connect(menu_aboutAction, SIGNAL(triggered()), this, SLOT(aboutAction()));
00089     
00090     // Add Exit menu item.
00091     menu_exitAction = new QAction(tr("Exit"), this);
00092     menuBar()->addAction(menu_exitAction);
00093     connect(menu_exitAction, SIGNAL(triggered()), this, SLOT(close()));
00094     
00095     // Connect the window updated signal of wrapper class to notify window slot.
00096     connect(mNfcShareWrapper, SIGNAL(windowUpdated(QString)), this, SLOT(notifyWindow(QString)));
00097 }
00098 /*
00099  * Displays the help message.
00100  */
00101 void NfcShareWindow::helpAction()
00102 {
00103     QMessageBox msgBox;
00104     // Display the help message.
00105     msgBox.setInformativeText("Select \"Start Easy Setup\" menu option, holding the NFC enabled devices close to commuinicate over NFC channel. "
00106             "After pairing over the bearer channel, select \"Start Sharing  vCard or vCal \" menu option to transfer vCard or vCal.");
00107     msgBox.exec();
00108 }
00109 /*
00110  * Displays the application details message.
00111  */
00112 void NfcShareWindow::aboutAction()
00113 {
00114     QMessageBox msgBox;
00115     // Display the application details.
00116     msgBox.setInformativeText("NFC Sharing application, Ver 1.0 Copyright (c) 2010 Nokia.  All rights reserved");
00117     msgBox.exec();
00118 }
00119 
00120 /*
00121  * Starts the vCard sharing operation.
00122  */
00123 void NfcShareWindow::startSharingvCard()
00124 {  
00125     mNfcShareWrapper->startSharingService(ENfcvCard);
00126 }
00127 
00128 /*
00129  * Starts the calendar event sharing operation.
00130  */
00131 void NfcShareWindow::startSharingvCal()
00132 {
00133     mNfcShareWrapper->startSharingService(ENfcvCal);
00134 }
00135 /*
00136  * Starts the easy setup service to pair the devices.
00137  */     
00138 void NfcShareWindow::startEasySetupService()
00139 {
00140     mNfcShareWrapper->startEasySetupService();
00141 }
00142 
00143 /*
00144  * Stops the setup service to disable current communication.
00145  */
00146 void NfcShareWindow::stopEasySetupService()
00147 {
00148     mNfcShareWrapper->stopService();
00149 }
00150 
00151 /*
00152  * Notification messages from the AIW handler displayed to user.
00153  * @param aStrMsg The message to be displayed to user.
00154  */
00155 void NfcShareWindow::notifyWindow(QString aStrMsg)
00156 {
00157     QMessageBox msgBox;
00158     msgBox.setInformativeText(aStrMsg);
00159     msgBox.exec();
00160 }
00161 
00162 /*
00163  * Destructor.
00164  */
00165 NfcShareWindow::~NfcShareWindow()
00166 {
00167     if(mNfcShareWrapper)
00168         {
00169         delete mNfcShareWrapper;
00170         mNfcShareWrapper = NULL;
00171         }
00172 }

Generated by  doxygen 1.6.2