1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Name : headsetttyview.cpp |
|
15 * |
|
16 * Description: |
|
17 * |
|
18 * |
|
19 */ |
|
20 |
|
21 #include <hbview.h> |
|
22 #include <hbdocumentloader.h> |
|
23 #include <hblabel.h> |
|
24 #include <hbcombobox.h> |
|
25 #include <accpolaccessorymode.h> |
|
26 #include <accpolgenericiddefinitions.h> |
|
27 #include <accessoriescrkeys.h> |
|
28 #include <AccessoryTypes.h> |
|
29 #include <QDebug> |
|
30 |
|
31 #include "headsetttyview.h" |
|
32 |
|
33 HeadsetTtyView::HeadsetTtyView(HbMainWindow *window,int accessoryType) |
|
34 { |
|
35 // Handle to the central repository. |
|
36 iAccessoryRepository = CRepository::NewL( KCRUidAccessorySettings ); |
|
37 |
|
38 TInt error = iAccServer.Connect(); |
|
39 if(error != KErrNone) |
|
40 { |
|
41 qDebug() << "Failed to connect to accessory server"; |
|
42 return; |
|
43 } |
|
44 error = iAccessorySettings.CreateSubSession( iAccServer ); |
|
45 if(error != KErrNone) |
|
46 { |
|
47 qDebug() << "Failed to connect to accessory sub session"; |
|
48 return; |
|
49 } |
|
50 |
|
51 HbDocumentLoader loader; |
|
52 bool viewLoaded(false); |
|
53 loader.load(":/xml/headset.docml", &viewLoaded); |
|
54 Q_ASSERT_X(viewLoaded, "MainView", "Invalid xml file"); |
|
55 |
|
56 HbLabel *image; |
|
57 HbLabel *acctype; |
|
58 // set the image to be displayed. |
|
59 if( accessoryType == KPCWired || accessoryType == KPCUSB ) //wired |
|
60 { |
|
61 image = qobject_cast<HbLabel*>(loader.findWidget("image")); |
|
62 image->setIcon(HbIcon(":/images/wired_accessory.svg")); |
|
63 } |
|
64 else // wireless |
|
65 { |
|
66 image = qobject_cast<HbLabel*>(loader.findWidget("image")); |
|
67 image->setIcon(HbIcon(":/images/wireless_accessory.svg")); |
|
68 } |
|
69 |
|
70 HbComboBox *comboHandler = qobject_cast<HbComboBox*>(loader.findWidget("combobox")); |
|
71 QStringList comboItems; |
|
72 comboItems <<"HeadSet" <<"TTY"; |
|
73 comboHandler->addItems(comboItems); |
|
74 |
|
75 connect(comboHandler , SIGNAL(currentIndexChanged(int)) , this , SLOT(currentIndexModified(int))); |
|
76 |
|
77 User::LeaveIfError( iAccessoryRepository->Get(KSettingsAccDefaultInfo, defaultaccessory )); |
|
78 |
|
79 // set the name to be displayed along with the image. |
|
80 if( defaultaccessory == 0) // HeadSet |
|
81 { |
|
82 acctype = qobject_cast<HbLabel*>(loader.findWidget("label")); |
|
83 acctype->setPlainText("HeadSet"); |
|
84 acctype->setTextWrapping(Hb::TextWordWrap); |
|
85 comboHandler->setCurrentIndex(0); // set headset as default |
|
86 } |
|
87 else |
|
88 { |
|
89 acctype = qobject_cast<HbLabel*>(loader.findWidget("label")); |
|
90 acctype->setPlainText("TTY"); |
|
91 acctype->setTextWrapping(Hb::TextWordWrap); |
|
92 comboHandler->setCurrentIndex(1); // set TTY as default |
|
93 } |
|
94 |
|
95 // heading for the combobox for user selection |
|
96 acctype = qobject_cast<HbLabel*>(loader.findWidget("label_2")); |
|
97 acctype->setPlainText("Accessory Type"); |
|
98 acctype->setTextWrapping(Hb::TextWordWrap); |
|
99 |
|
100 window->addView(loader.findWidget("view")); |
|
101 } |
|
102 |
|
103 HeadsetTtyView::~HeadsetTtyView() |
|
104 { |
|
105 iAccessorySettings.CloseSubSession(); |
|
106 iAccServer.Disconnect(); |
|
107 delete iAccessoryRepository; |
|
108 } |
|
109 |
|
110 void HeadsetTtyView::currentIndexModified(int var) |
|
111 { |
|
112 if(var == 0) // make headset as default |
|
113 { |
|
114 User::LeaveIfError((iAccessoryRepository->Set(KSettingsAccDefaultInfo, 0))); // 0 is for Headset |
|
115 iAccessorySettings.SetHWDeviceSettingsL( KASHeadset ); |
|
116 } |
|
117 else |
|
118 { |
|
119 User::LeaveIfError((iAccessoryRepository->Set(KSettingsAccDefaultInfo, 7))); // 7 is for TTY |
|
120 iAccessorySettings.SetHWDeviceSettingsL( KASTTY ); |
|
121 } |
|
122 } |
|