bluetoothengine/btindicator/src/btindicator.cpp
changeset 70 f5508c13dfe0
parent 42 b72428996822
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
    14  * Description:
    14  * Description:
    15  *
    15  *
    16  */
    16  */
    17 #include "btindicator.h" 
    17 #include "btindicator.h" 
    18 #include <QVariant.h>
    18 #include <QVariant.h>
    19 //#include <hbmessagebox.h>
       
    20 //#include <xqaiwrequest.h>
       
    21 #include "btindicatorconstants.h"
    19 #include "btindicatorconstants.h"
    22 //#include <XQServiceRequest.h>
    20 
    23 //#include <cpbasesettingview.h>
    21 
    24 //#include <cppluginlauncher.h>
    22 #define LOC_BLUETOOTH hbTrId("txt_bt_dblist_bluetooth") 
    25 #define LOC_BLUETOOTH hbTrId("txt_bt_dblist_bluetooth")
    23 
    26 #define LOC_BLUETOOTH_OFF hbTrId("txt_bt_dblist_bluetooth_val_off")
    24 const QString BT_APPLICATION("btcpplugin.dll");
    27 #define LOC_BLUETOOTH_ON_VISIBLE hbTrId("txt_bt_dblist_bluetooth_val_on_and_visible")
       
    28 #define LOC_BLUETOOTH_VISIBLE_CONNECTED hbTrId("txt_bt_dblist_bluetooth_val_visible_and_connected")
       
    29 #define LOC_BLUETOOTH_ON_HIDDEN hbTrId("txt_bt_dblist_bluetooth_val_on_and_hidden")
       
    30 #define LOC_BLUETOOTH_HIDDEN_CONNECTED hbTrId("txt_bt_dblist_bluetooth_val_hidden_and_connected")
       
    31 
    25 
    32 struct BTIndicatorInfo
    26 struct BTIndicatorInfo
    33     {
    27 {
    34      QString icon;
    28     QString DecorationIcon;
    35      QString secondaryText;
    29     QString MonoDecorationIcon;
    36     };
    30 };
    37 
    31 
    38 static const int BTIndicatorCount = 5;
    32 static const int BTIndicatorCount = 5;
    39 
    33 
    40 
    34 
    41 static const BTIndicatorInfo IndicatorInfo[BTIndicatorCount] = { 
    35 static const BTIndicatorInfo IndicatorInfo[BTIndicatorCount] = { 
    42      { "qtg_large_bluetooth_off", "LOC_BLUETOOTH_OFF" }, 
    36      { "qtg_large_bluetooth_off", "qtg_status_bluetooth_off" },
    43      { "qtg_large_bluetooth", "LOC_BLUETOOTH_ON_VISIBLE" }, 
    37      { "qtg_large_bluetooth","qtg_status_bluetooth" },
    44      { "qtg_large_bluetooth_hide","LOC_BLUETOOTH_ON_HIDDEN" },
    38      { "qtg_large_bluetooth_hide","qtg_status_bluetooth_hide" },
    45      { "qtg_large_bluetooth_active_connection", "LOC_BT_VISIBLE_CONNECT" }, 
    39      { "qtg_large_bluetooth_active_connection", "qtg_status_bluetooth_connection"},
    46      { "qtg_large_bluetooth_hide_connection","LOC_BT_HIDDEN_CONNECT"  }
    40      { "qtg_large_bluetooth_hide_connection", "qtg_status_bluetooth_hide_connection"}
    47  };
    41  };
    48 
    42 
    49 
    43 
    50 // ----------------------------------------------------------------------------
    44 // ----------------------------------------------------------------------------
    51 // BTIndicator::BTIndicator
    45 // BTIndicator::BTIndicator
    52 // ----------------------------------------------------------------------------
    46 // ----------------------------------------------------------------------------
    53 BTIndicator::BTIndicator(const QString &indicatorType) :
    47 BTIndicator::BTIndicator(const QString &indicatorType) :
    54 HbIndicatorInterface(indicatorType,
    48 HbIndicatorInterface(indicatorType,
    55         HbIndicatorInterface::SettingCategory ,
    49         HbIndicatorInterface::SettingCategory ,
    56         InteractionActivated)
    50         InteractionActivated),mRequest(0),mIndicatorStatus(0),mIndicatorlaunch(false)
    57     {
    51 {
    58     mIndicatorStatus = 0;
    52     mSecondaryText << hbTrId("txt_bt_dblist_bluetooth_val_off")
    59     }
    53             << hbTrId("txt_bt_dblist_bluetooth_val_on_and_visible")
       
    54             << hbTrId("txt_bt_dblist_bluetooth_val_on_and_hidden")
       
    55             << hbTrId("txt_bt_dblist_bluetooth_val_visible_and_connected")
       
    56             << hbTrId("txt_bt_dblist_bluetooth_val_hidden_and_connected");
       
    57 }
    60 
    58 
    61 // ----------------------------------------------------------------------------
    59 // ----------------------------------------------------------------------------
    62 // BTIndicator::~BTIndicator
    60 // BTIndicator::~BTIndicator
    63 // ----------------------------------------------------------------------------
    61 // ----------------------------------------------------------------------------
    64 BTIndicator::~BTIndicator()
    62 BTIndicator::~BTIndicator()
    65     {
    63 {
    66     }
    64 	delete mRequest;
       
    65 }
    67 
    66 
    68 
    67 
    69 // ----------------------------------------------------------------------------
    68 // ----------------------------------------------------------------------------
    70 // BTIndicator::handleInteraction
    69 // BTIndicator::handleInteraction
    71 // ----------------------------------------------------------------------------
    70 // ----------------------------------------------------------------------------
    72 bool BTIndicator::handleInteraction(InteractionType type)
    71 bool BTIndicator::handleInteraction(InteractionType type)
    73     {
    72 {
    74   //  bool handled = false;
       
    75     if (type == InteractionActivated) 
    73     if (type == InteractionActivated) 
    76         {
    74 	{
    77     //@TODO need to code for launching the BT Control Panel Plugin is available
    75  /*       if(!mIndicatorlaunch)
    78 
    76             {
    79  //       launchBTCpSettingView();
    77             launchBTCpSettingView();
    80         }
    78             mIndicatorlaunch = true;
       
    79             }*/
       
    80         
       
    81 	}
    81     return true;
    82     return true;
    82     }
    83 }
    83 
    84 
    84 // ----------------------------------------------------------------------------
    85 // ----------------------------------------------------------------------------
    85 // BTIndicator::indicatorData
    86 // BTIndicator::indicatorData
    86 // returns the data and icon that needs to be displayed in the universal pop up and indicator menu 
    87 // returns the data and icon that needs to be displayed in the universal pop up and indicator menu 
    87 // ----------------------------------------------------------------------------
    88 // ----------------------------------------------------------------------------
    88 QVariant BTIndicator::indicatorData(int role) const
    89 QVariant BTIndicator::indicatorData(int role) const
    89 {
    90 {
    90     switch(role)
    91 	QVariant data("");
    91     {
    92 
    92     case PrimaryTextRole: 
    93     if(mIndicatorStatus == 0)
    93         {
    94 	{
    94         QString text(LOC_BLUETOOTH);
    95 		data = QString();
    95         return text;
    96 	}
    96         }
    97     else
    97     case SecondaryTextRole:
    98 	{
    98         {
    99         switch(role) {
    99         return IndicatorInfo[mIndicatorStatus].secondaryText;//mSecDisplayName;
   100             case PrimaryTextRole: 
   100         }
   101 				data = QString(LOC_BLUETOOTH);
   101     case DecorationNameRole:
   102 				break;
   102         {
   103             case SecondaryTextRole:
   103         //QString iconName("qtg_large_bluetooth");
   104 				data = mSecondaryText[mIndicatorStatus];
   104         return IndicatorInfo[mIndicatorStatus].icon;//iconName;
   105 				break;
   105         }
   106             case DecorationNameRole:
   106     case MonoDecorationNameRole :
   107 				data = IndicatorInfo[mIndicatorStatus].DecorationIcon;
   107         {
   108 				break;
   108        // QString iconName("qtg_large_bluetooth");
   109             case MonoDecorationNameRole :
   109         return IndicatorInfo[mIndicatorStatus].icon;//iconName;
   110 				data =  IndicatorInfo[mIndicatorStatus].MonoDecorationIcon;
   110         }
   111 				break;
   111 
   112             default: 
   112     default: 
   113                 data = QString();      
   113         return QVariant();      
   114 				break;
   114      }
   115 		}
       
   116 	}
       
   117 	return data;
   115 }
   118 }
   116 
   119 
   117 // ----------------------------------------------------------------------------
   120 // ----------------------------------------------------------------------------
   118 // BTIndicator::handleClientRequest
   121 // BTIndicator::handleClientRequest
   119 // handles client's activate and deactivate request
   122 // handles client's activate and deactivate request
   120 // ----------------------------------------------------------------------------
   123 // ----------------------------------------------------------------------------
   121 bool BTIndicator::handleClientRequest( RequestType type, 
   124 bool BTIndicator::handleClientRequest( RequestType type, 
   122         const QVariant &parameter)
   125         const QVariant &parameter)
   123     {
   126 {
   124     bool handled(false);
   127     bool handled(false);
   125     switch (type) {
   128     switch (type) {
   126         case RequestActivate:
   129         case RequestActivate:
   127             {
   130             {
   128             mSecDisplayName.clear();
       
   129 /*            if(parameter.toInt() == EBTIndicatorOff)
       
   130                 mSecDisplayName.append("LOC_BLUETOOTH_OFF");
       
   131             else if(parameter.toInt() == EBTIndicatorOnVisible)
       
   132                 mSecDisplayName.append("LOC_BLUETOOTH_ON_VISIBLE");
       
   133             else if(parameter.toInt() == EBTIndicatorOnHidden)
       
   134                 mSecDisplayName.append("LOC_BLUETOOTH_ON_HIDDEN");
       
   135             else if(parameter.toInt() == EBTIndicatorVisibleConnected)
       
   136                 mSecDisplayName.append("LOC_BT_VISIBLE_CONNECT");
       
   137             else if(parameter.toInt() == EBTIndicatorHiddenConnected)
       
   138                 mSecDisplayName.append("LOC_BT_HIDDEN_CONNECT");*/
       
   139             mIndicatorStatus = parameter.toInt();
   131             mIndicatorStatus = parameter.toInt();
   140             emit dataChanged();
   132             if(( !mIndicatorStatus )&&( !mIndicatorlaunch ))
       
   133                 {
       
   134 	            mSecondaryText = QStringList();
       
   135                 emit deactivate();
       
   136                 }
       
   137             else
       
   138                 {
       
   139                 emit dataChanged();
       
   140                 }
   141             handled =  true;
   141             handled =  true;
   142             }
   142             }
   143             break;
   143             break;
   144         default:
   144         case RequestDeactivate:
   145             {
   145             {
   146             mSecDisplayName.clear();
   146             mSecondaryText = QStringList();
       
   147             mIndicatorStatus  = 0;
   147             emit deactivate();
   148             emit deactivate();
   148             }
   149             }
   149             break;
   150             break;
       
   151         default:
       
   152             break;
   150     }
   153     }
   151     return handled;
   154     return handled;
       
   155 }
       
   156 
       
   157 
       
   158 void BTIndicator::launchBTCpSettingView()
       
   159 {
       
   160     if(!mRequest)
       
   161     {
       
   162         mRequest = mAppMgr.create("com.nokia.symbian.ICpPluginLauncher","launchSettingView(QString,QVariant)",false);
       
   163 
       
   164         if (!mRequest)
       
   165         {
       
   166            qDebug("BTIndicator request returned with NULL");
       
   167             return;
       
   168         }
       
   169         else
       
   170         {
       
   171             connect(mRequest, SIGNAL(requestOk(QVariant)), SLOT(handleReturnValue(QVariant)));
       
   172             connect(mRequest, SIGNAL(requestError(int,QString)), SLOT(handleError(int,QString)));
       
   173             // Set arguments for request 
       
   174             QList<QVariant> args;
       
   175             args << QVariant(BT_APPLICATION);
       
   176             mRequest->setArguments(args);
       
   177             mRequest->setSynchronous(false);
       
   178         }
   152     }
   179     }
   153 
   180         // Make the request
   154 
   181     if (!mRequest->send())
   155 /*void BTIndicator::launchBTCpSettingView()
       
   156     {
       
   157     XQAiwRequest *request = mAppMgr.create("obexhighway","com.nokia.symbian.IFileShare","send(QVariant)",true);
       
   158 
       
   159     if (!request)
       
   160     {
       
   161        qDebug("BTIndicator request returned with NULL");
       
   162         return;
       
   163     }
       
   164     else
       
   165     {
       
   166         connect(request, SIGNAL(requestOk(QVariant)), SLOT(handleReturnValue(QVariant)));
       
   167         connect(request, SIGNAL(requestError(int,QString)), SLOT(handleError(int,QString)));
       
   168     }
       
   169     // Set arguments for request 
       
   170     QList<QVariant> args;
       
   171     //c:\resource\qt\plugins\controlpanel\nfccpplugin.qtplugin
       
   172     args << QVariant( "c:\\two.jpg" );//btcpplugin.dll
       
   173 //    args << QVariant ( "c:\\two.jpg" );
       
   174     request->setArguments(args);
       
   175 
       
   176     // Make the request
       
   177     if (!request->send())
       
   178     {
   182     {
   179         //report error  
   183         //report error  
   180         qDebug("BTIndicator::launchBTCpSettingView request not sent");
   184         qDebug("BTIndicator::launchBTCpSettingView request not sent");
   181     }
   185     }
       
   186 	
       
   187 /*	QString service("com.nokia.symbian.ICpPluginLauncher");
       
   188     QString operation("launchSettingView(QString,QVariant)");
       
   189     QList<QVariant> args;
       
   190     XQAiwRequest* request;
       
   191     XQApplicationManager appManager;
       
   192     request = appManager.create(service, operation, false); // not embedded
       
   193     if ( request == NULL )
       
   194         {
       
   195         //Could not create request because of the arguments passed to the create() API.
       
   196         User::Leave(KErrArgument);       
       
   197         }
       
   198     args << QVariant("btcpplugin.dll");
       
   199     request->setArguments(args);
       
   200     TInt error = KErrNone;
       
   201     if(!request->send())
       
   202         {
       
   203         // The only likely Symbian error code that can be associated is KErrNotSupported
       
   204         
       
   205         }
       
   206     delete request;*/
   182     
   207     
   183     delete request;
   208 
   184     
   209 }
   185     }*/
   210 
   186 
   211 
   187 
   212 void BTIndicator::handleReturnValue(const QVariant &returnValue)
   188 /*void BTIndicator::handleReturnValue(const QVariant &returnValue)
   213 {
   189 {
   214     Q_UNUSED(returnValue);
       
   215     mIndicatorlaunch = false;
       
   216     if(!mIndicatorStatus )
       
   217 	{
       
   218         emit deactivate();
       
   219 	}
   190 }
   220 }
   191 
   221 
   192 void BTIndicator::handleError(int errorCode,const QString &errorMessage)
   222 void BTIndicator::handleError(int errorCode,const QString &errorMessage)
   193     {
   223 {
   194     Q_UNUSED(errorCode);
   224     Q_UNUSED(errorCode);
   195     }*/
   225     Q_UNUSED(errorMessage);
       
   226     mIndicatorlaunch = false;
       
   227 }