Update SettingsCoreFoundationPreferences.cpp to our style guidelines
This commit is contained in:
parent
f5756e3f93
commit
bc22754f8c
1 changed files with 20 additions and 22 deletions
|
@ -9,13 +9,13 @@
|
||||||
// Copyright: See COPYING file that comes with this distribution
|
// Copyright: See COPYING file that comes with this distribution
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
#include "Settings.h"
|
|
||||||
#include "Strings.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
#include <string>
|
||||||
#include "../client/telldus-core.h"
|
#include "common/Strings.h"
|
||||||
|
#include "service/Settings.h"
|
||||||
|
#include "client/telldus-core.h"
|
||||||
|
|
||||||
class privateVars {
|
class privateVars {
|
||||||
public:
|
public:
|
||||||
|
@ -34,8 +34,7 @@ public:
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
Settings::Settings(void)
|
Settings::Settings(void) {
|
||||||
{
|
|
||||||
d = new PrivateData();
|
d = new PrivateData();
|
||||||
d->app_ID = CFSTR( "com.telldus.core" );
|
d->app_ID = CFSTR( "com.telldus.core" );
|
||||||
d->userName = kCFPreferencesAnyUser;
|
d->userName = kCFPreferencesAnyUser;
|
||||||
|
@ -45,8 +44,7 @@ Settings::Settings(void)
|
||||||
/*
|
/*
|
||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
Settings::~Settings(void)
|
Settings::~Settings(void) {
|
||||||
{
|
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,21 +101,21 @@ int Settings::getNodeId(Node type, int intNodeIndex) const {
|
||||||
if ( !split || CFArrayGetCount( split ) != 3 ) continue;
|
if ( !split || CFArrayGetCount( split ) != 3 ) continue;
|
||||||
|
|
||||||
// This code crashes!
|
// This code crashes!
|
||||||
//CFNumberRef cfid = (CFNumberRef) CFArrayGetValueAtIndex( split, 1 );
|
// CFNumberRef cfid = (CFNumberRef) CFArrayGetValueAtIndex( split, 1 );
|
||||||
//if (cfid)
|
// if (cfid)
|
||||||
// CFNumberGetValue( cfid, kCFNumberIntType, &id);
|
// CFNumberGetValue( cfid, kCFNumberIntType, &id);
|
||||||
|
|
||||||
CFStringRef cfid = (CFStringRef) CFArrayGetValueAtIndex( split, 1 );
|
CFStringRef cfid = (CFStringRef) CFArrayGetValueAtIndex( split, 1 );
|
||||||
char *cp = NULL;
|
char *cp = NULL;
|
||||||
CFIndex size = CFStringGetMaximumSizeForEncoding( CFStringGetLength( cfid ), kCFStringEncodingUTF8) + 1;
|
CFIndex size = CFStringGetMaximumSizeForEncoding( CFStringGetLength( cfid ), kCFStringEncodingUTF8) + 1;
|
||||||
cp = (char *)malloc(size);
|
cp = reinterpret_cast<char *>(malloc(size));
|
||||||
CFStringGetCString( cfid, cp, size, kCFStringEncodingUTF8 );
|
CFStringGetCString( cfid, cp, size, kCFStringEncodingUTF8 );
|
||||||
char *newcp = (char *)realloc( cp, strlen(cp) + 1);
|
char *newcp = reinterpret_cast<char *>(realloc( cp, strlen(cp) + 1));
|
||||||
if (newcp != NULL) {
|
if (newcp != NULL) {
|
||||||
cp = newcp;
|
cp = newcp;
|
||||||
id = atoi(cp);
|
id = atoi(cp);
|
||||||
} else {
|
} else {
|
||||||
//Should not happen
|
// Should not happen
|
||||||
id = 0;
|
id = 0;
|
||||||
}
|
}
|
||||||
free(cp);
|
free(cp);
|
||||||
|
@ -136,9 +134,9 @@ int Settings::getNodeId(Node type, int intNodeIndex) const {
|
||||||
*/
|
*/
|
||||||
int Settings::addNode(Node type) {
|
int Settings::addNode(Node type) {
|
||||||
int id = getNextNodeId(type);
|
int id = getNextNodeId(type);
|
||||||
setStringSetting( type, id, L"name", L"", false ); //Create a empty name so the node has an entry
|
setStringSetting( type, id, L"name", L"", false ); // Create a empty name so the node has an entry
|
||||||
if (type == Device) {
|
if (type == Device) {
|
||||||
//Is there a reason we do this?
|
// Is there a reason we do this?
|
||||||
setStringSetting( type, id, L"model", L"", false );
|
setStringSetting( type, id, L"model", L"", false );
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
|
@ -163,7 +161,7 @@ int Settings::getNextNodeId(Node type) const {
|
||||||
/*
|
/*
|
||||||
* Remove a device
|
* Remove a device
|
||||||
*/
|
*/
|
||||||
int Settings::removeNode(Node type, int intNodeId){
|
int Settings::removeNode(Node type, int intNodeId) {
|
||||||
int ret = TELLSTICK_ERROR_DEVICE_NOT_FOUND;
|
int ret = TELLSTICK_ERROR_DEVICE_NOT_FOUND;
|
||||||
CFStringRef filterKey = CFStringCreateWithFormat(0, NULL, CFSTR("%ss.%d."), getNodeString(type).c_str(), intNodeId); // The key to search for
|
CFStringRef filterKey = CFStringCreateWithFormat(0, NULL, CFSTR("%ss.%d."), getNodeString(type).c_str(), intNodeId); // The key to search for
|
||||||
|
|
||||||
|
@ -175,7 +173,7 @@ int Settings::removeNode(Node type, int intNodeId){
|
||||||
for (CFIndex k = 0; k < size; ++k) {
|
for (CFIndex k = 0; k < size; ++k) {
|
||||||
CFStringRef key = (CFStringRef) CFArrayGetValueAtIndex(cfarray, k);
|
CFStringRef key = (CFStringRef) CFArrayGetValueAtIndex(cfarray, k);
|
||||||
if (CFStringHasPrefix( key, filterKey ) ) {
|
if (CFStringHasPrefix( key, filterKey ) ) {
|
||||||
CFPreferencesSetValue( key, NULL, d->app_ID, d->userName, d->hostName ); //Remove the key
|
CFPreferencesSetValue( key, NULL, d->app_ID, d->userName, d->hostName ); // Remove the key
|
||||||
ret = TELLSTICK_SUCCESS;
|
ret = TELLSTICK_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,14 +203,14 @@ std::wstring Settings::getStringSetting(Node type, int intNodeId, const std::wst
|
||||||
std::wstring retval;
|
std::wstring retval;
|
||||||
char *cp = NULL;
|
char *cp = NULL;
|
||||||
CFIndex size = CFStringGetMaximumSizeForEncoding( CFStringGetLength( value ), kCFStringEncodingUTF8) + 1;
|
CFIndex size = CFStringGetMaximumSizeForEncoding( CFStringGetLength( value ), kCFStringEncodingUTF8) + 1;
|
||||||
cp = (char *)malloc(size);
|
cp = reinterpret_cast<char *>(malloc(size));
|
||||||
CFStringGetCString( value, cp, size, kCFStringEncodingUTF8 );
|
CFStringGetCString( value, cp, size, kCFStringEncodingUTF8 );
|
||||||
char *newcp = (char *)realloc( cp, strlen(cp) + 1);
|
char *newcp = reinterpret_cast<char *>(realloc( cp, strlen(cp) + 1));
|
||||||
if (newcp != NULL) {
|
if (newcp != NULL) {
|
||||||
cp = newcp;
|
cp = newcp;
|
||||||
retval = TelldusCore::charToWstring(cp);
|
retval = TelldusCore::charToWstring(cp);
|
||||||
} else {
|
} else {
|
||||||
//Should not happen
|
// Should not happen
|
||||||
retval = L"";
|
retval = L"";
|
||||||
}
|
}
|
||||||
free(cp);
|
free(cp);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue