Commit 4ac4aeed authored by Edric Milaret's avatar Edric Milaret Committed by Alexandre Lision

fix code style

Use clang-format Chromium style for Objective-C
Use Swimat for swift code
 - 4 Space indent
 - Remove break before opening brace

Change-Id: I4b38b37f07f3973ceaa81b02f56dd56a6592380e
Tuleap: #313
parent a68931d4
......@@ -26,13 +26,13 @@ enum AccountType: String {
}
struct Account {
//MARK: - Properties
// MARK: - Properties
let id: String
//FIXME: This should be private
// FIXME: This should be private
var details: Dictionary<String, String>
var alias: String? {
get {
return details["Account.alias"]
......@@ -41,7 +41,7 @@ struct Account {
details["Account.alias"] = newValue
}
}
var videoEnabled: Bool {
get {
return (details["Account.videoEnabled"]?.toBool())!
......@@ -110,7 +110,7 @@ struct Account {
}
set {
details["Account.enable"] = newValue.toString()
ConfigurationManagerAdaptator.sharedManager().setAccountActive(self.id, newValue)
ConfigurationManagerAdaptator.sharedManager().setAccountActive(self.id, active: newValue)
}
}
......@@ -149,14 +149,14 @@ struct Account {
details["Account.displayName"] = newValue
}
}
//MARK: - Init
// MARK: - Init
init(accID: String) {
id = accID
details = ConfigurationManagerAdaptator.sharedManager().getAccountDetails(id) as! Dictionary<String, String>
}
func save() {
ConfigurationManagerAdaptator.sharedManager().setAccountDetails(id, details)
ConfigurationManagerAdaptator.sharedManager().setAccountDetails(id, details: details)
}
}
\ No newline at end of file
......@@ -22,17 +22,16 @@ import UIKit
class AccountDetailsViewController: UIViewController {
//MARK: - Properties
// MARK: - Properties
var account: Account!
@IBOutlet weak var detailsLabel: UILabel!
//MARK: - UIViewController
// MARK: - UIViewController
override func viewDidLoad() {
super.viewDidLoad()
//FIXME: This is just a placeholder
// FIXME: This is just a placeholder
detailsLabel.text = account.details.description
}
......
......@@ -22,20 +22,20 @@ import Foundation
class AccountModel {
//MARK: - Properties
// MARK: - Properties
let confAdapt = ConfigurationManagerAdaptator.sharedManager()
var accountList: Array<Account> = []
//MARK: - Singleton
// MARK: - Singleton
static let sharedInstance = AccountModel()
private init() {
NSNotificationCenter.defaultCenter().addObserverForName("AccountsChanged", object: nil, queue: nil, usingBlock: {_ in
NSNotificationCenter.defaultCenter().addObserverForName("AccountsChanged", object: nil, queue: nil, usingBlock: { _ in
self.reload()
})
}
//MARK: - Methods
// MARK: - Methods
func reload() {
accountList.removeAll()
for acc in confAdapt.getAccountList() {
......@@ -43,20 +43,20 @@ class AccountModel {
accountList.append(Account(accID: accID))
}
}
func addAccount() {
//TODO: This need work for all account type
// TODO: This need work for all account type
let details = confAdapt.getAccountTemplate("RING")
details.setValue("iOS", forKey: "Account.alias")
details.setValue("iOS", forKey: "Account.displayName")
confAdapt.addAccount(details! as [NSObject : AnyObject])
confAdapt.addAccount(details! as [NSObject: AnyObject])
}
func removeAccount(row: Int) {
if row < accountList.count {
confAdapt.removeAccount(accountList[row].id)
}
}
}
\ No newline at end of file
......@@ -22,14 +22,14 @@ import UIKit
class AccountTableViewCell: UITableViewCell {
//MARK: - Properties
// MARK: - Properties
@IBOutlet weak var activeSwitch: UISwitch!
@IBOutlet weak var accountNameLabel: UILabel!
@IBOutlet weak var accountTypeLabel: UILabel!
var account: Account!
//MARK: - UITableViewCell
// MARK: - UITableViewCell
override func awakeFromNib() {
super.awakeFromNib()
}
......@@ -37,8 +37,8 @@ class AccountTableViewCell: UITableViewCell {
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
//MARK: - Actions
// MARK: - Actions
@IBAction func switchAccountState(sender: UISwitch) {
account.isEnabled = sender.on
}
......
......@@ -36,7 +36,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
return true
}
func pollFunction() {
self.dRingAdapt.pollEvents()
}
......@@ -69,7 +69,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var applicationDocumentsDirectory: NSURL = {
// The directory the application uses to store the Core Data store file. This code uses a directory named "cx.ring.Ring" in the application's documents Application Support directory.
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1]
return urls[urls.count - 1]
}()
lazy var managedObjectModel: NSManagedObjectModel = {
......@@ -99,7 +99,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)")
abort()
}
return coordinator
}()
......
......@@ -15,7 +15,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
*/
#import <Foundation/Foundation.h>
......@@ -24,16 +25,18 @@
+ (id)sharedManager;
- (void) registerConfigurationHandler;
- (void)registerConfigurationHandler;
- (NSArray*) getAccountList;
- (NSMutableDictionary*) getAccountTemplate: (NSString*) accountType;
- (NSString*) addAccount: (NSDictionary*) details;
- (void) removeAccount: (NSString*) accountID;
- (void) setAccountActive: (NSString*) accountID : (bool) active;
- (uint64_t) sendAccountTextMessage: (NSString*) accountID : (NSString*) to : (NSDictionary*) payloads;
- (NSDictionary*) getAccountDetails: (NSString*) accountID;
- (NSDictionary*) getVolatileAccountDetails: (NSString*) accountID;
- (void) setAccountDetails: (NSString*) accountID : (NSDictionary*) details;
- (int) getMessageStatus: (uint64_t) msgID;
- (NSArray*)getAccountList;
- (NSMutableDictionary*)getAccountTemplate:(NSString*)accountType;
- (NSString*)addAccount:(NSDictionary*)details;
- (void)removeAccount:(NSString*)accountID;
- (void)setAccountActive:(NSString*)accountID active:(bool)active;
- (uint64_t)sendAccountTextMessage:(NSString*)accountID
to:(NSString*)to
payloads:(NSDictionary*)payloads;
- (NSDictionary*)getAccountDetails:(NSString*)accountID;
- (NSDictionary*)getVolatileAccountDetails:(NSString*)accountID;
- (void)setAccountDetails:(NSString*)accountID details:(NSDictionary*)details;
- (int)getMessageStatus:(uint64_t)msgID;
@end
......@@ -15,7 +15,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
*/
#import "ConfigurationManagerAdaptator.h"
......@@ -30,103 +31,104 @@ using namespace DRing;
#pragma mark Singleton Methods
+ (id)sharedManager {
static ConfigurationManagerAdaptator *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
static ConfigurationManagerAdaptator* sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
[self registerConfigurationHandler];
}
return self;
if (self = [super init]) {
[self registerConfigurationHandler];
}
return self;
}
- (NSArray*) getAccountList
{
auto accountVector = getAccountList();
- (NSArray*)getAccountList {
auto accountVector = getAccountList();
return [Utils vectorToArray:accountVector];
return [Utils vectorToArray:accountVector];
}
- (NSMutableDictionary*) getAccountTemplate: (NSString*) accountType
{
auto accountTemplate = getAccountTemplate(std::string([accountType UTF8String]));
- (NSMutableDictionary*)getAccountTemplate:(NSString*)accountType {
auto accountTemplate =
getAccountTemplate(std::string([accountType UTF8String]));
return [Utils mapToDictionnary:accountTemplate];
return [Utils mapToDictionnary:accountTemplate];
}
- (NSString*) addAccount: (NSDictionary*) details
{
auto accountID = addAccount([Utils dictionnaryToMap:details]);
- (NSString*)addAccount:(NSDictionary*)details {
auto accountID = addAccount([Utils dictionnaryToMap:details]);
return [NSString stringWithUTF8String:accountID.c_str()];
return [NSString stringWithUTF8String:accountID.c_str()];
}
- (void) removeAccount: (NSString*) accountID
{
removeAccount(std::string([accountID UTF8String]));
- (void)removeAccount:(NSString*)accountID {
removeAccount(std::string([accountID UTF8String]));
}
- (void) setAccountActive: (NSString*) accountID : (bool) active
{
setAccountActive(std::string([accountID UTF8String]), active);
- (void)setAccountActive:(NSString*)accountID active:(bool)active {
setAccountActive(std::string([accountID UTF8String]), active);
}
- (uint64_t) sendAccountTextMessage: (NSString*) accountID : (NSString*) to : (NSDictionary*) payloads
{
return sendAccountTextMessage(std::string([accountID UTF8String]), std::string([to UTF8String]),
[Utils dictionnaryToMap:payloads]);
- (uint64_t)sendAccountTextMessage:(NSString*)accountID
to:(NSString*)to
payloads:(NSDictionary*)payloads {
return sendAccountTextMessage(std::string([accountID UTF8String]),
std::string([to UTF8String]),
[Utils dictionnaryToMap:payloads]);
}
- (NSDictionary*) getAccountDetails: (NSString*) accountID
{
auto accDetails = getAccountDetails(std::string([accountID UTF8String]));
return [Utils mapToDictionnary:accDetails];
- (NSDictionary*)getAccountDetails:(NSString*)accountID {
auto accDetails = getAccountDetails(std::string([accountID UTF8String]));
return [Utils mapToDictionnary:accDetails];
}
- (NSDictionary*) getVolatileAccountDetails: (NSString*) accountID
{
auto volatileDetails = getVolatileAccountDetails(std::string([accountID UTF8String]));
return [Utils mapToDictionnary:volatileDetails];
- (NSDictionary*)getVolatileAccountDetails:(NSString*)accountID {
auto volatileDetails =
getVolatileAccountDetails(std::string([accountID UTF8String]));
return [Utils mapToDictionnary:volatileDetails];
}
- (void) setAccountDetails: (NSString*) accountID : (NSDictionary*) details
{
setAccountDetails(std::string([accountID UTF8String]), [Utils dictionnaryToMap:details]);
- (void)setAccountDetails:(NSString*)accountID details:(NSDictionary*)details {
setAccountDetails(std::string([accountID UTF8String]),
[Utils dictionnaryToMap:details]);
}
- (int) getMessageStatus:(uint64_t) msgID
{
return getMessageStatus(msgID);
- (int)getMessageStatus:(uint64_t)msgID {
return getMessageStatus(msgID);
}
- (void) registerConfigurationHandler
{
std::map<std::string, std::shared_ptr<CallbackWrapperBase>> confHandlers;
confHandlers.insert(exportable_callback<ConfigurationSignal::IncomingAccountMessage>(
[&](const std::string& account_id,
const std::string& from,
const std::map<std::string, std::string>& payloads) {
NSDictionary* userInfo = @{@"accountID": [NSString stringWithUTF8String:account_id.c_str()],
@"from": [NSString stringWithUTF8String:from.c_str()],
@"payloads": [Utils mapToDictionnary:payloads]};
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"IncomingAccountMessage" object:self userInfo:userInfo];
}));
confHandlers.insert(exportable_callback<ConfigurationSignal::AccountsChanged>([&](){
- (void)registerConfigurationHandler {
std::map<std::string, std::shared_ptr<CallbackWrapperBase>> confHandlers;
confHandlers.insert(
exportable_callback<ConfigurationSignal::IncomingAccountMessage>(
[&](const std::string& account_id, const std::string& from,
const std::map<std::string, std::string>& payloads) {
NSDictionary* userInfo = @{
@"accountID" : [NSString stringWithUTF8String:account_id.c_str()],
@"from" : [NSString stringWithUTF8String:from.c_str()],
@"payloads" : [Utils mapToDictionnary:payloads]
};
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"IncomingAccountMessage"
object:self
userInfo:userInfo];
}));
confHandlers.insert(
exportable_callback<ConfigurationSignal::AccountsChanged>([&]() {
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"AccountsChanged" object:[ConfigurationManagerAdaptator sharedManager]];
}));
registerConfHandlers(confHandlers);
[nc postNotificationName:@"AccountsChanged"
object:[ConfigurationManagerAdaptator sharedManager]];
}));
registerConfHandlers(confHandlers);
}
@end
......@@ -15,16 +15,16 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
*/
#import <Foundation/Foundation.h>
@interface DRingAdaptator : NSObject
- (BOOL) initDaemon;
- (BOOL) startDaemon;
- (void) fini;
- (void) pollEvents;
- (nonnull NSString*) getVersion;
- (BOOL)initDaemon;
- (BOOL)startDaemon;
- (void)fini;
- (void)pollEvents;
- (nonnull NSString*)getVersion;
@end
......@@ -15,7 +15,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
*/
#import "DRingAdaptator.h"
......@@ -24,30 +25,25 @@
@implementation DRingAdaptator
- (BOOL) initDaemon
{
int flag = DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG;
return DRing::init(static_cast<DRing::InitFlag>(flag));
- (BOOL)initDaemon {
int flag = DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG;
return DRing::init(static_cast<DRing::InitFlag>(flag));
}
- (BOOL) startDaemon
{
return DRing::start();
- (BOOL)startDaemon {
return DRing::start();
}
- (void) fini
{
DRing::fini();
- (void)fini {
DRing::fini();
}
- (void) pollEvents
{
DRing::pollEvents();
- (void)pollEvents {
DRing::pollEvents();
}
- (NSString*)getVersion
{
return [NSString stringWithUTF8String:DRing::version()];
- (NSString*)getVersion {
return [NSString stringWithUTF8String:DRing::version()];
}
@end
......@@ -21,14 +21,14 @@
import UIKit
class MeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// MARK: - Properties
let accountModel = AccountModel.sharedInstance
@IBOutlet weak var accountTableView: UITableView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var qrImageView: UIImageView!
//MARK: - UIViewController
// MARK: - UIViewController
override func viewDidLoad() {
super.viewDidLoad()
......@@ -44,74 +44,74 @@ class MeViewController: UIViewController, UITableViewDelegate, UITableViewDataSo
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//MARK: - QRCode
// MARK: - QRCode
func createQRFromString(str: String) {
let data = str.dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: false)
let filter = CIFilter(name: "CIQRCodeGenerator")
filter!.setValue(data, forKey: "inputMessage")
let qrImage:CIImage = filter!.outputImage!
let qrImage: CIImage = filter!.outputImage!
let scaleX = qrImageView.frame.size.width / qrImage.extent.size.width
let scaleY = qrImageView.frame.size.height / qrImage.extent.size.height
let resultQrImage = qrImage.imageByApplyingTransform(CGAffineTransformMakeScale(scaleX, scaleY))
qrImageView.image = UIImage(CIImage: resultQrImage)
}
// MARK: - TableView
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1;
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return accountModel.accountList.count + 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row < accountModel.accountList.count {
let cell = tableView.dequeueReusableCellWithIdentifier("accountTableCell", forIndexPath: indexPath) as! AccountTableViewCell
let account = accountModel.accountList[indexPath.row]
cell.account = account
cell.accountNameLabel.text = account.alias
cell.activeSwitch.setOn(account.isEnabled, animated: false)
cell.accountTypeLabel.text = account.accountType.rawValue
return cell
} else {
let cell = tableView.dequeueReusableCellWithIdentifier("addAccountTableCell", forIndexPath: indexPath)
return cell
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == accountModel.accountList.count {
accountModel.addAccount()
accountTableView.reloadData()
}
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
if indexPath.row == accountModel.accountList.count {
return false
}
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
accountModel.removeAccount(indexPath.row)
accountTableView.reloadData()
}
}
//MARK: - Actions
// MARK: - Actions
@IBAction func addAccountClicked(sender: AnyObject) {
let index = NSIndexPath(forRow: accountModel.accountList.count, inSection: 0)
accountTableView.selectRowAtIndexPath(index, animated: false, scrollPosition: UITableViewScrollPosition.None)
......
......@@ -15,13 +15,14 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
*/
//
// Use this file to import your target's public headers that you would like to expose to Swift.
// Use this file to import your target's public headers that you would like to
// expose to Swift.
//
#import "DRingAdaptator.h"
#import "ConfigurationManagerAdaptator.h"
\ No newline at end of file
#import "ConfigurationManagerAdaptator.h"
#import "DRingAdaptator.h"
\ No newline at end of file
......@@ -15,19 +15,21 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
*/
#import <Foundation/Foundation.h>
#import <map>
#import <string>
#import <vector>
#import <map>
@interface Utils : NSObject
+ (NSArray*) vectorToArray: (const std::vector<std::string>&) vector;
+ (NSMutableDictionary*) mapToDictionnary: (const std::map<std::string, std::string>&) map;
+ (std::map<std::string, std::string>) dictionnaryToMap: (NSDictionary*) dict;
+ (NSArray*)vectorToArray:(const std::vector<std::string>&)vector;
+ (NSMutableDictionary*)mapToDictionnary:
(const std::map<std::string, std::string>&)map;
+ (std::map<std::string, std::string>)dictionnaryToMap:(NSDictionary*)dict;
@end
......@@ -15,43 +15,45 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
*/
#import "Utils.h"
@implementation Utils
+ (NSArray*) vectorToArray: (const std::vector<std::string>&) vector
{
NSMutableArray* resArray = [NSMutableArray new];
std::for_each(vector.begin(), vector.end(), ^(std::string str) {
id nsstr = [NSString stringWithUTF8String:str.c_str()];
[resArray addObject:nsstr];
});
return resArray;
+ (NSArray*)vectorToArray:(const std::vector<std::string>&)vector {
NSMutableArray* resArray = [NSMutableArray new];
std::for_each(vector.begin(), vector.end(), ^(std::string str) {
id nsstr = [NSString stringWithUTF8String:str.c_str()];
[resArray addObject:nsstr];
});
return resArray;
}
+ (NSMutableDictionary*) mapToDictionnary: (const std::map<std::string, std::string>&) map
{
NSMutableDictionary* resDictionnary = [NSMutableDictionary new];
+ (NSMutableDictionary*)mapToDictionnary:
(const std::map<std::string, std::string>&)map {
NSMutableDictionary* resDictionnary = [NSMutableDictionary new];
std::for_each(map.begin(), map.end(), ^(std::pair<std::string, std::string> keyValue) {
std::for_each(
map.begin(), map.end(), ^(std::pair<std::string, std::string> keyValue) {
id key = [NSString stringWithUTF8String:keyValue.first.c_str()];
id value = [NSString stringWithUTF8String:keyValue.second.c_str()];
[resDictionnary setObject:value forKey:key];
});
});
return resDictionnary;
return resDictionnary;
}
+ (std::map<std::string, std::string>) dictionnaryToMap: (NSDictionary*) dict
{
std::map<std::string, std::string>resMap;
for (id key in dict)
resMap.insert(std::pair<std::string, std::string>(std::string([key UTF8String]), std::string([[dict objectForKey:key] UTF8String])));
+ (std::map<std::string, std::string>)dictionnaryToMap:(NSDictionary*)dict {
std::map<std::string, std::string> resMap;
for (id key in dict)
resMap.insert(std::pair<std::string, std::string>(
std::string([key UTF8String]),
std::string([[dict objectForKey:key] UTF8String])));
return resMap;
return resMap;
}
@end
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