29
|
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 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "btdelegatedevname.h"
|
31
|
19 |
#include <btsettingmodel.h>
|
29
|
20 |
#include <bluetoothuitrace.h>
|
|
21 |
#include <QRegExp>
|
|
22 |
|
31
|
23 |
BtDelegateDevName::BtDelegateDevName(QObject *parent ) :
|
|
24 |
BtAbstractDelegate( NULL, NULL, parent )
|
29
|
25 |
{
|
|
26 |
TRAP_IGNORE( mBtEngSettings = CBTEngSettings::NewL() );
|
|
27 |
Q_CHECK_PTR( mBtEngSettings );
|
|
28 |
|
|
29 |
}
|
|
30 |
|
|
31 |
BtDelegateDevName::~BtDelegateDevName()
|
|
32 |
{
|
|
33 |
delete mBtEngSettings;
|
|
34 |
}
|
|
35 |
|
|
36 |
/*!
|
|
37 |
Validate the bluetooth device name given by the user:
|
|
38 |
Extra spaces (' ', '\n', '\t' and '\r') from the beginning,
|
|
39 |
middle and the end of the name are always removed;
|
|
40 |
the maximum lengthof a name is 30.
|
|
41 |
*/
|
|
42 |
bool BtDelegateDevName::validateName(QString &name )
|
|
43 |
{
|
|
44 |
// remove spaces at the beginning and end:
|
|
45 |
name = name.trimmed();
|
|
46 |
// regular expression of one or more consecutive spaces:
|
|
47 |
QRegExp rx("[ \n\t\r]+");
|
|
48 |
name.replace( rx, " ");
|
|
49 |
if (name.length() > 30 ) {
|
|
50 |
name.resize( 30 );
|
|
51 |
}
|
|
52 |
return name.length() > 0;
|
|
53 |
}
|
|
54 |
|
|
55 |
void BtDelegateDevName::exec( const QVariant ¶ms )
|
|
56 |
{
|
|
57 |
int error = KErrNone;
|
|
58 |
QString btDevName = params.toString();
|
|
59 |
|
|
60 |
validateName(btDevName);
|
|
61 |
|
|
62 |
TPtrC ptrName(reinterpret_cast<const TText*>(btDevName.constData()));
|
|
63 |
|
|
64 |
RBuf16 btName;
|
|
65 |
error = btName.Create(ptrName.Length());
|
|
66 |
|
|
67 |
if(error == KErrNone) {
|
|
68 |
btName.Copy(ptrName);
|
|
69 |
error = mBtEngSettings->SetLocalName(btName);
|
|
70 |
btName.Close();
|
|
71 |
}
|
|
72 |
|
|
73 |
emit commandCompleted(error, btDevName);
|
|
74 |
}
|
|
75 |
|
|
76 |
|
|
77 |
|