Commit 81c9721c authored by Alexandre Lision's avatar Alexandre Lision

cleanup: run XCode code analysis

enable ARC in CMakelist.txt
fix small potentials leaks across the client

Refs #75600

Change-Id: I72ba17e6daed393abdf38653f45c040bd3427ead
parent 7f3164c1
......@@ -11,7 +11,7 @@ SET(BUNDLE_VERSION "Samuel de Champlain - beta")
SET(PROJ_COPYRIGHT " © 2015 Savoir-faire Linux \n GPLv3 https://www.gnu.org/copyleft/gpl.html")
ADD_DEFINITIONS("-std=c++11")
ADD_DEFINITIONS("-std=c++11 -fobjc-arc")
PROJECT(${PROJ_NAME})
......
......@@ -36,4 +36,4 @@
@end
#endif // ACCSECURITYVC_H
\ No newline at end of file
#endif // ACCSECURITYVC_H
......@@ -49,7 +49,7 @@
@interface AccSecurityVC ()
@property NSTreeController *treeController;
@property QNSTreeController *treeController;
@property (unsafe_unretained) IBOutlet NSOutlineView *cipherListView;
@property (unsafe_unretained) IBOutlet NSButton *useTLS;
@property (unsafe_unretained) IBOutlet NSView *tlsContainer;
......@@ -122,11 +122,11 @@
[self updateControlsWithTag:OUTGOING_TLS_SRV_NAME];
[self updateControlsWithTag:TLS_NEGOTIATION_TAG];
QModelIndex qTlsMethodIdx = [self currentAccount]->tlsMethodModel()->selectionModel()->currentIndex();
QModelIndex qTlsMethodIdx = account->tlsMethodModel()->selectionModel()->currentIndex();
[self.tlsMethodList removeAllItems];
[self.tlsMethodList addItemWithTitle:qTlsMethodIdx.data(Qt::DisplayRole).toString().toNSString()];
treeController = [[QNSTreeController alloc] initWithQModel:[self currentAccount]->cipherModel()];
treeController = [[QNSTreeController alloc] initWithQModel:account->cipherModel()];
[treeController setAvoidsEmptySelection:NO];
[treeController setAlwaysUsesMultipleValuesMarker:YES];
[treeController setChildrenKeyPath:@"children"];
......@@ -145,22 +145,22 @@
NSArray * pathComponentArray = [self pathComponentArray];
if([self currentAccount]->tlsCaListCertificate() != nil) {
NSLog(@"CA ==> %@", [self currentAccount]->tlsCaListCertificate()->path().toNSURL());
[caListPathControl setURL:[self currentAccount]->tlsCaListCertificate()->path().toNSURL()];
NSLog(@"CA ==> %@", account->tlsCaListCertificate()->path().toNSURL());
[caListPathControl setURL:account->tlsCaListCertificate()->path().toNSURL()];
} else {
[caListPathControl setURL:nil];
}
if([self currentAccount]->tlsCertificate() != nil) {
NSLog(@" CERT ==> %@", [self currentAccount]->tlsCertificate()->path().toNSURL());
[certificatePathControl setURL:[self currentAccount]->tlsCertificate()->path().toNSURL()];
NSLog(@" CERT ==> %@", account->tlsCertificate()->path().toNSURL());
[certificatePathControl setURL:account->tlsCertificate()->path().toNSURL()];
} else {
[certificatePathControl setURL:nil];
}
if([self currentAccount]->tlsPrivateKeyCertificate() != nil) {
NSLog(@" PVK ==> %@", [self currentAccount]->tlsPrivateKeyCertificate()->path().toNSURL());
[pvkPathControl setURL:[self currentAccount]->tlsPrivateKeyCertificate()->path().toNSURL()];
NSLog(@" PVK ==> %@", account->tlsPrivateKeyCertificate()->path().toNSURL());
[pvkPathControl setURL:account->tlsPrivateKeyCertificate()->path().toNSURL()];
} else {
[pvkPathControl setURL:nil];
}
......
......@@ -78,15 +78,15 @@
{
auto account = [self currentAccount];
treeController = [[QNSTreeController alloc] initWithQModel:[self currentAccount]->codecModel()->videoCodecs()];
treeController = [[QNSTreeController alloc] initWithQModel:account->codecModel()->videoCodecs()];
[treeController setAvoidsEmptySelection:NO];
[treeController setChildrenKeyPath:@"children"];
[codecsView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil];
[codecsView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil];
[codecsView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil];
[videoPanelContainer setHidden:![self currentAccount]->isVideoEnabled()];
[toggleVideoButton setState:[self currentAccount]->isVideoEnabled()?NSOnState:NSOffState];
[videoPanelContainer setHidden:!account->isVideoEnabled()];
[toggleVideoButton setState:account->isVideoEnabled()?NSOnState:NSOffState];
}
- (IBAction)toggleVideoEnabled:(id)sender {
......
......@@ -178,10 +178,9 @@ public:
- (IBAction)addAccount:(id)sender {
QModelIndex qIdx = AccountModel::instance()->protocolModel()->selectionModel()->currentIndex();
NSString* newAccName = [[NSString alloc] initWithFormat:@"%@ account",
auto newAccName = [[NSString alloc] initWithFormat:@"%@ account",
AccountModel::instance()->protocolModel()->data(qIdx, Qt::DisplayRole).toString().toNSString(), nil];
Account* newAcc =AccountModel::instance()->add([newAccName UTF8String], qIdx);
AccountModel::instance()->add([newAccName UTF8String], qIdx);
AccountModel::instance()->save();
}
......@@ -270,11 +269,10 @@ public:
if ([[tableColumn identifier] isEqualToString:COLUMNID_ENABLE] &&
AccountModel::instance()->ip2ip()->index() == qIdx) {
returnCell = [[NSCell alloc] init];
return [[NSCell alloc] init];
} else {
returnCell = [tableColumn dataCell];
return [tableColumn dataCell];
}
return returnCell;
}
// -------------------------------------------------------------------------------
......@@ -350,9 +348,9 @@ public:
{
// ask the tree controller for the current selection
if([[treeController selectedNodes] count] > 0) {
QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
//Update details view
Account* acc = AccountModel::instance()->getAccountByModelIndex(qIdx);
auto acc = AccountModel::instance()->getAccountByModelIndex(qIdx);
AccountModel::instance()->selectionModel()->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect);
switch (acc->protocol()) {
......
......@@ -32,10 +32,7 @@
#import <Cocoa/Cocoa.h>
@interface GeneralPrefsVC : NSViewController {
NSTextField *historyChangedLabel;
}
@interface GeneralPrefsVC : NSViewController
@end
......
......@@ -34,8 +34,8 @@
#import "Constants.h"
@interface GeneralPrefsVC ()
@property (assign) IBOutlet NSTextField *historyChangedLabel;
@property (assign) IBOutlet NSView *advancedGeneralSettings;
@property (unsafe_unretained) IBOutlet NSTextField *historyChangedLabel;
@property (unsafe_unretained) IBOutlet NSView *advancedGeneralSettings;
@property (unsafe_unretained) IBOutlet NSButton *startUpButton;
@end
......@@ -56,6 +56,12 @@
[advancedGeneralSettings setHidden:![[NSUserDefaults standardUserDefaults] boolForKey:Preferences::ShowAdvanced]];
}
- (void) dealloc
{
[[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:Preferences::HistoryLimit];
[[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:Preferences::ShowAdvanced];
}
- (IBAction)clearHistory:(id)sender {
CategorizedHistoryModel::instance()->clearAllCollections();
[historyChangedLabel setHidden:NO];
......@@ -94,7 +100,7 @@
if (loginItemsRef == nil) return;
if (shouldBeToggled) {
// Add the app to the LoginItems list.
CFURLRef appUrl = (CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
CFURLRef appUrl = (__bridge CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
LSSharedFileListItemRef itemRef = LSSharedFileListInsertItemURL(loginItemsRef, kLSSharedFileListItemLast, NULL, NULL, appUrl, NULL, NULL);
if (itemRef) CFRelease(itemRef);
}
......@@ -109,21 +115,21 @@
- (LSSharedFileListItemRef)itemRefInLoginItems {
LSSharedFileListItemRef itemRef = nil;
NSURL *itemUrl = nil;
CFURLRef itemUrl = nil;
// Get the app's URL.
NSURL *appUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
auto appUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
// Get the LoginItems list.
LSSharedFileListRef loginItemsRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
if (loginItemsRef == nil) return nil;
// Iterate over the LoginItems.
NSArray *loginItems = (NSArray *)LSSharedFileListCopySnapshot(loginItemsRef, nil);
NSArray *loginItems = (__bridge_transfer NSArray *)LSSharedFileListCopySnapshot(loginItemsRef, nil);
for (int currentIndex = 0; currentIndex < [loginItems count]; currentIndex++) {
// Get the current LoginItem and resolve its URL.
LSSharedFileListItemRef currentItemRef = (LSSharedFileListItemRef)[loginItems objectAtIndex:currentIndex];
if (LSSharedFileListItemResolve(currentItemRef, 0, (CFURLRef *) &itemUrl, NULL) == noErr) {
LSSharedFileListItemRef currentItemRef = (__bridge LSSharedFileListItemRef)[loginItems objectAtIndex:currentIndex];
if (LSSharedFileListItemResolve(currentItemRef, 0, &itemUrl, NULL) == noErr) {
// Compare the URLs for the current LoginItem and the app.
if ([itemUrl isEqual:appUrl]) {
if ([(__bridge NSURL *)itemUrl isEqual:appUrl]) {
// Save the LoginItem reference.
itemRef = currentItemRef;
}
......@@ -132,7 +138,6 @@
// Retain the LoginItem reference.
if (itemRef != nil) CFRetain(itemRef);
// Release the LoginItems lists.
[loginItems release];
CFRelease(loginItemsRef);
return itemRef;
......
......@@ -44,7 +44,7 @@
@interface HistoryVC()
@property NSTreeController *treeController;
@property QNSTreeController *treeController;
@property (assign) IBOutlet NSOutlineView *historyView;
@property QSortFilterProxyModel *historyProxyModel;
@end
......
......@@ -62,7 +62,7 @@ public:
@interface PersonsVC ()
@property NSTreeController *treeController;
@property QNSTreeController *treeController;
@property (assign) IBOutlet NSOutlineView *personsView;
@property QSortFilterProxyModel *contactProxyModel;
......
......@@ -34,11 +34,11 @@
@interface PreferencesVC : NSViewController <NSToolbarDelegate>
@property (nonatomic, assign) NSViewController *currentVC;
@property (nonatomic, assign) NSViewController *accountsPrefsVC;
@property (nonatomic, assign) NSViewController *generalPrefsVC;
@property (nonatomic, assign) NSViewController *audioPrefsVC;
@property (nonatomic, assign) NSViewController *videoPrefsVC;
@property (nonatomic, strong) NSViewController *currentVC;
@property (nonatomic, strong) NSViewController *accountsPrefsVC;
@property (nonatomic, strong) NSViewController *generalPrefsVC;
@property (nonatomic, strong) NSViewController *audioPrefsVC;
@property (nonatomic, strong) NSViewController *videoPrefsVC;
- (void) close;
- (void)displayGeneral:(NSToolbarItem *)sender;
......
......@@ -55,7 +55,7 @@
- (id) initWithQModel:(QAbstractItemModel*) model
{
[super init];
self = [super init];
self->privateQModel = model;
topNodes = [[NSMutableArray alloc] init];
......
......@@ -30,9 +30,6 @@
#import <Cocoa/Cocoa.h>
@interface RingWizardWC : NSWindowController <NSWindowDelegate>{
NSButton *goToAppButton;
}
@interface RingWizardWC : NSWindowController <NSWindowDelegate>
@end
......@@ -38,11 +38,11 @@
@interface RingWizardWC ()
@property (assign) IBOutlet NSButton *goToAppButton;
@property (assign) IBOutlet NSTextField *nickname;
@property (assign) IBOutlet NSProgressIndicator *progressBar;
@property (assign) IBOutlet NSTextField *indicationLabel;
@property (assign) IBOutlet NSButton *createButton;
@property (unsafe_unretained) IBOutlet NSButton *goToAppButton;
@property (unsafe_unretained) IBOutlet NSTextField *nickname;
@property (unsafe_unretained) IBOutlet NSProgressIndicator *progressBar;
@property (unsafe_unretained) IBOutlet NSTextField *indicationLabel;
@property (unsafe_unretained) IBOutlet NSButton *createButton;
@end
@implementation RingWizardWC
......@@ -112,7 +112,7 @@
{
LSSharedFileListRef loginItemsRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
if (loginItemsRef == nil) return;
CFURLRef appUrl = (CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
CFURLRef appUrl = (__bridge CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
LSSharedFileListItemRef itemRef = LSSharedFileListInsertItemURL(loginItemsRef, kLSSharedFileListItemLast, NULL, NULL, appUrl, NULL, NULL);
if (itemRef) CFRelease(itemRef);
}
......
......@@ -125,11 +125,14 @@ QPixmap ImageManipulationDelegate::drawDefaultUserPixmap(const QSize& size, bool
QPainter painter(&pxm);
// create the image somehow, load from file, draw into it...
CGImageSourceRef source;
auto sourceImgRef = CGImageSourceCreateWithData((CFDataRef)[[NSImage imageNamed:@"NSUser"] TIFFRepresentation], NULL);
auto imgRef = CGImageSourceCreateImageAtIndex(sourceImgRef, 0, NULL);
auto finalImgRef = resizeCGImage(imgRef, size);
painter.drawPixmap(3,3,QtMac::fromCGImageRef(finalImgRef));
source = CGImageSourceCreateWithData((CFDataRef)[[NSImage imageNamed:@"NSUser"] TIFFRepresentation], NULL);
CGImageRef maskRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
painter.drawPixmap(3,3,QtMac::fromCGImageRef(resizeCGImage(maskRef, size)));
CFRelease(sourceImgRef);
CFRelease(imgRef);
CFRelease(finalImgRef);
return pxm;
}
......@@ -143,8 +146,6 @@ CGImageRef ImageManipulationDelegate::resizeCGImage(CGImageRef image, const QSiz
size.width() * CGImageGetBitsPerComponent(image),
colorspace,
CGImageGetAlphaInfo(image));
CGColorSpaceRelease(colorspace);
if(context == NULL)
return nil;
......
......@@ -73,7 +73,7 @@
NSLog(@"Dragging entered");
NSURL* fileURL = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
CFStringRef fileExtension = (CFStringRef) [fileURL.path pathExtension];
CFStringRef fileExtension = (__bridge CFStringRef) [fileURL.path pathExtension];
CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
// Check if the pasteboard contains image data and source/user wants it copied
......@@ -94,11 +94,12 @@
usingBlock:^(NSDraggingItem *draggingItem, NSInteger idx, BOOL *stop) {
*stop = YES;
}];
CFRelease(fileUTI);
//accept data as a copy operation
return NSDragOperationCopy;
}
CFRelease(fileUTI);
return NSDragOperationNone;
}
......@@ -140,11 +141,13 @@
[self setNeedsDisplay: YES];
NSURL* fileURL = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
CFStringRef fileExtension = (CFStringRef) [fileURL.path pathExtension];
CFStringRef fileExtension = (__bridge CFStringRef) [fileURL.path pathExtension];
CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
BOOL conforms = (UTTypeConformsTo(fileUTI, kUTTypeVideo)) || (UTTypeConformsTo(fileUTI, kUTTypeMovie));
CFRelease(fileUTI);
//check to see if we can accept the data
return (UTTypeConformsTo(fileUTI, kUTTypeVideo)) || (UTTypeConformsTo(fileUTI, kUTTypeMovie));
return conforms;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
......
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