Kaydet (Commit) aeacebee authored tarafından Stephan Bergmann's avatar Stephan Bergmann

loplugin:staticmethods

Change-Id: I1730694d8856ed009b8bf02a71657ca933bc6101
üst 0617f87c
...@@ -33,6 +33,49 @@ ...@@ -33,6 +33,49 @@
using namespace connectivity::macab; using namespace connectivity::macab;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
namespace {
void manageDuplicateGroups(::std::vector<MacabGroup *> _xGroups)
{
/* If we have two cases of groups, say, family, this makes it:
* family
* family (2)
*/
::std::vector<MacabGroup *>::reverse_iterator iter1, iter2;
sal_Int32 count;
for(iter1 = _xGroups.rbegin(); iter1 != _xGroups.rend(); ++iter1)
{
/* If the name matches the default table name, there is already
* (obviously) a conflict. So, start the count of groups with this
* name at 2 instead of 1.
*/
if( (*iter1)->getName() == MacabAddressBook::getDefaultTableName() )
count = 2;
else
count = 1;
iter2 = iter1;
for( ++iter2; iter2 != _xGroups.rend(); ++iter2)
{
if( (*iter1)->getName() == (*iter2)->getName() )
{
count++;
}
}
// duplicate!
if(count != 1)
{
OUString sName = (*iter1)->getName() + " (" +
OUString::number(count) +
")";
(*iter1)->setName(sName);
}
}
}
}
MacabAddressBook::MacabAddressBook( ) MacabAddressBook::MacabAddressBook( )
{ {
...@@ -202,45 +245,4 @@ MacabGroup *MacabAddressBook::getMacabGroupMatch(OUString const & _groupName) ...@@ -202,45 +245,4 @@ MacabGroup *MacabAddressBook::getMacabGroupMatch(OUString const & _groupName)
return NULL; return NULL;
} }
void MacabAddressBook::manageDuplicateGroups(::std::vector<MacabGroup *> _xGroups) const
{
/* If we have two cases of groups, say, family, this makes it:
* family
* family (2)
*/
::std::vector<MacabGroup *>::reverse_iterator iter1, iter2;
sal_Int32 count;
for(iter1 = _xGroups.rbegin(); iter1 != _xGroups.rend(); ++iter1)
{
/* If the name matches the default table name, there is already
* (obviously) a conflict. So, start the count of groups with this
* name at 2 instead of 1.
*/
if( (*iter1)->getName() == getDefaultTableName() )
count = 2;
else
count = 1;
iter2 = iter1;
for( ++iter2; iter2 != _xGroups.rend(); ++iter2)
{
if( (*iter1)->getName() == (*iter2)->getName() )
{
count++;
}
}
// duplicate!
if(count != 1)
{
OUString sName = (*iter1)->getName() + " (" +
OUString::number(count) +
")";
(*iter1)->setName(sName);
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -41,8 +41,7 @@ namespace connectivity ...@@ -41,8 +41,7 @@ namespace connectivity
MacabRecords *m_xMacabRecords; MacabRecords *m_xMacabRecords;
::std::vector<MacabGroup *> m_xMacabGroups; ::std::vector<MacabGroup *> m_xMacabGroups;
bool m_bRetrievedGroups; bool m_bRetrievedGroups;
private:
void manageDuplicateGroups(::std::vector<MacabGroup *> _xGroups) const;
public: public:
MacabAddressBook(); MacabAddressBook();
~MacabAddressBook(); ~MacabAddressBook();
......
...@@ -38,6 +38,32 @@ using namespace com::sun::star::sdb; ...@@ -38,6 +38,32 @@ using namespace com::sun::star::sdb;
using namespace com::sun::star::frame; using namespace com::sun::star::frame;
using namespace connectivity::macab; using namespace connectivity::macab;
namespace {
/** throws a generic SQL exception with SQLState S1000 and error code 0
*/
void throwGenericSQLException( const OUString& _rMessage )
{
SQLException aError;
aError.Message = _rMessage;
aError.SQLState = "S1000";
aError.ErrorCode = 0;
throw aError;
}
/** throws an SQLException saying than no Mac OS installation was found
*/
void throwNoMacOSException()
{
::connectivity::SharedResources aResources;
const OUString sError( aResources.getResourceString(
STR_NO_MAC_OS_FOUND
) );
throwGenericSQLException( sError );
}
}
// = MacabImplModule // = MacabImplModule
...@@ -122,28 +148,8 @@ void MacabImplModule::impl_unloadModule() ...@@ -122,28 +148,8 @@ void MacabImplModule::impl_unloadModule()
void MacabImplModule::init() void MacabImplModule::init()
{ {
if ( !impl_loadModule() ) if ( !impl_loadModule() )
impl_throwNoMacOSException(); throwNoMacOSException();
}
void MacabImplModule::impl_throwNoMacOSException()
{
::connectivity::SharedResources aResources;
const OUString sError( aResources.getResourceString(
STR_NO_MAC_OS_FOUND
) );
impl_throwGenericSQLException( sError );
}
void MacabImplModule::impl_throwGenericSQLException( const OUString& _rMessage )
{
SQLException aError;
aError.Message = _rMessage;
aError.SQLState = "S1000";
aError.ErrorCode = 0;
throw aError;
} }
......
...@@ -99,15 +99,6 @@ namespace connectivity ...@@ -99,15 +99,6 @@ namespace connectivity
@precond m_hConnectorModule is not <NULL/> @precond m_hConnectorModule is not <NULL/>
*/ */
void impl_unloadModule(); void impl_unloadModule();
/** throws an SQLException saying than no Mac OS installation was found
*/
void impl_throwNoMacOSException();
/** throws a generic SQL exception with SQLState S1000 and error code 0
*/
void impl_throwGenericSQLException( const OUString& _rMessage );
}; };
......
...@@ -32,6 +32,40 @@ ...@@ -32,6 +32,40 @@
using namespace connectivity::macab; using namespace connectivity::macab;
using namespace com::sun::star::util; using namespace com::sun::star::util;
namespace {
void manageDuplicateHeaders(macabfield **_headerNames, const sal_Int32 _length)
{
/* If we have two cases of, say, phone: home, this makes it:
* phone: home (1)
* phone: home (2)
*/
sal_Int32 i, j;
sal_Int32 count;
for(i = _length-1; i >= 0; i--)
{
count = 1;
for( j = i-1; j >= 0; j--)
{
if(CFEqual(_headerNames[i]->value, _headerNames[j]->value))
{
count++;
}
}
// duplicate!
if(count != 1)
{
// There is probably a better way to do this...
OUString newName = CFStringToOUString(static_cast<CFStringRef>(_headerNames[i]->value));
CFRelease(_headerNames[i]->value);
newName += " (" + OUString::number(count) + ")";
_headerNames[i]->value = OUStringToCFString(newName);
}
}
}
}
MacabRecords::MacabRecords(const ABAddressBookRef _addressBook, MacabHeader *_header, MacabRecord **_records, sal_Int32 _numRecords) MacabRecords::MacabRecords(const ABAddressBookRef _addressBook, MacabHeader *_header, MacabRecord **_records, sal_Int32 _numRecords)
{ {
...@@ -811,38 +845,6 @@ MacabHeader *MacabRecords::createHeaderForProperty(const ABPropertyType _propert ...@@ -811,38 +845,6 @@ MacabHeader *MacabRecords::createHeaderForProperty(const ABPropertyType _propert
} }
void MacabRecords::manageDuplicateHeaders(macabfield **_headerNames, const sal_Int32 _length) const
{
/* If we have two cases of, say, phone: home, this makes it:
* phone: home (1)
* phone: home (2)
*/
sal_Int32 i, j;
sal_Int32 count;
for(i = _length-1; i >= 0; i--)
{
count = 1;
for( j = i-1; j >= 0; j--)
{
if(CFEqual(_headerNames[i]->value, _headerNames[j]->value))
{
count++;
}
}
// duplicate!
if(count != 1)
{
// There is probably a better way to do this...
OUString newName = CFStringToOUString(static_cast<CFStringRef>(_headerNames[i]->value));
CFRelease(_headerNames[i]->value);
newName += " (" + OUString::number(count) + ")";
_headerNames[i]->value = OUStringToCFString(newName);
}
}
}
/* Create a MacabRecord out of an ABRecord, using a given MacabHeader and /* Create a MacabRecord out of an ABRecord, using a given MacabHeader and
* the record's type. We go through each property for this record type * the record's type. We go through each property for this record type
* then process it much like we processed the header (above), with two * then process it much like we processed the header (above), with two
......
...@@ -73,7 +73,6 @@ namespace connectivity ...@@ -73,7 +73,6 @@ namespace connectivity
void bootstrap_requiredProperties(); void bootstrap_requiredProperties();
MacabHeader *createHeaderForProperty(const ABRecordRef _record, const CFStringRef _propertyName, const CFStringRef _recordType, const bool _isPropertyRequired) const; MacabHeader *createHeaderForProperty(const ABRecordRef _record, const CFStringRef _propertyName, const CFStringRef _recordType, const bool _isPropertyRequired) const;
MacabHeader *createHeaderForProperty(const ABPropertyType _propertyType, const CFTypeRef _propertyValue, const CFStringRef _propertyName) const; MacabHeader *createHeaderForProperty(const ABPropertyType _propertyType, const CFTypeRef _propertyValue, const CFStringRef _propertyName) const;
void manageDuplicateHeaders(macabfield **_headerNames, const sal_Int32 _length) const;
ABPropertyType getABTypeFromCFType(const CFTypeID cf_type ) const; ABPropertyType getABTypeFromCFType(const CFTypeID cf_type ) const;
void insertPropertyIntoMacabRecord(MacabRecord *_abrecord, const MacabHeader *_header, const OUString& _propertyName, const CFTypeRef _propertyValue) const; void insertPropertyIntoMacabRecord(MacabRecord *_abrecord, const MacabHeader *_header, const OUString& _propertyName, const CFTypeRef _propertyValue) const;
void insertPropertyIntoMacabRecord(const ABPropertyType _propertyType, MacabRecord *_abrecord, const MacabHeader *_header, const OUString& _propertyName, const CFTypeRef _propertyValue) const; void insertPropertyIntoMacabRecord(const ABPropertyType _propertyType, MacabRecord *_abrecord, const MacabHeader *_header, const OUString& _propertyName, const CFTypeRef _propertyValue) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment