Commit e3503844 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

preferences: general

- remove clear history button
- add different type of notifications
- support notifications with actions

Change-Id: I05574cf11a22afdab4572daa6ba37602bab17eef
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent c6c1b4f7
This diff is collapsed.
......@@ -42,11 +42,10 @@ namespace lrc {
@property (retain, nonatomic) id <ChooseAccountDelegate> delegate;
@property (readonly) const lrc::api::account::Info& selectedAccount;
//@property const lrc::api::NewAccountModel* accMdl_;
-(void) enable;
-(void) disable;
//-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(lrc::api::NewAccountModel*) accMdl delegate:(id <ChooseAccountDelegate> )mainWindow;
-(void) updateWithDelegate:(id <ChooseAccountDelegate> )mainWindow andModel:(lrc::api::NewAccountModel*) accMdl;
- (void)selectAccount:(NSString*)accountID;
@end
......@@ -393,4 +393,14 @@ NSMutableDictionary* menuItemsTags;
[accountSelectionButton setEnabled:NO];
}
- (void)selectAccount:(NSString*)accountID {
auto accList = accMdl_->getAccountList();
if(std::find(accList.begin(), accList.end(), [accountID UTF8String]) != accList.end()) {
auto& account = accMdl_->getAccountInfo([accountID UTF8String]);
[accountSelectionManager_ setSavedAccount:account];
[self updatePhoto];
[self setPopUpButtonSelection];
}
}
@end
......@@ -30,7 +30,11 @@ namespace Preferences {
/* KVO compliant */
NSString * const WindowBehaviour = @"window_behaviour";
/* KVO compliant */
NSString * const Notifications = @"enable_notifications";
NSString * const CallNotifications = @"enable_call_notifications";
/* KVO compliant */
NSString * const MessagesNotifications = @"enable_messages_notifications";
/* KVO compliant */
NSString * const ContactRequestNotifications = @"enable_invitations_notifications";
/* download folder for incoming images*/
NSString * const DownloadFolder = @"download_folder";
}
......@@ -18,20 +18,7 @@
*/
#import "GeneralPrefsVC.h"
#import <Quartz/Quartz.h>
//Qt
#import <QSize>
#import <QtMacExtras/qmacfunctions.h>
#import <QPixmap>
//LRC
#import <categorizedhistorymodel.h>
#import <profilemodel.h>
#import <profile.h>
#import <person.h>
#import <globalinstances.h>
#import <media/recordingmodel.h>
//lrc
#import <api/datatransfermodel.h>
#if ENABLE_SPARKLE
......@@ -39,22 +26,13 @@
#endif
#import "Constants.h"
#import "views/NSImage+Extensions.h"
#import "delegates/ImageManipulationDelegate.h"
#import "utils.h"
@interface GeneralPrefsVC () {
__unsafe_unretained IBOutlet NSTextField* historyChangedLabel;
__unsafe_unretained IBOutlet NSButton* startUpButton;
__unsafe_unretained IBOutlet NSButton* toggleAutomaticUpdateCheck;
__unsafe_unretained IBOutlet NSPopUpButton* checkIntervalPopUp;
__unsafe_unretained IBOutlet NSView* sparkleContainer;
__unsafe_unretained IBOutlet NSTextField* historyTextField;
__unsafe_unretained IBOutlet NSStepper* historyStepper;
__unsafe_unretained IBOutlet NSButton* historySwitch;
__unsafe_unretained IBOutlet NSButton* photoView;
__unsafe_unretained IBOutlet NSTextField* profileNameField;
__unsafe_unretained IBOutlet NSImageView* addProfilePhotoImage;
__unsafe_unretained IBOutlet NSButton *downloadFolder;
__unsafe_unretained IBOutlet NSTextField *downloadFolderLabel;
}
......@@ -77,18 +55,7 @@
- (void)loadView
{
[super loadView];
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:Preferences::HistoryLimit options:NSKeyValueObservingOptionNew context:NULL];
[startUpButton setState:[self isLaunchAtStartup]];
int historyLimit = CategorizedHistoryModel::instance().historyLimit();
[historyTextField setStringValue:[NSString stringWithFormat:@"%d", historyLimit]];
[historyStepper setIntValue:historyLimit];
BOOL limited = CategorizedHistoryModel::instance().isHistoryLimited();
[historySwitch setState:limited];
[historyStepper setEnabled:limited];
[historyTextField setEnabled:limited];
#if ENABLE_SPARKLE
[sparkleContainer setHidden:NO];
SUUpdater *updater = [SUUpdater sharedUpdater];
......@@ -99,23 +66,6 @@
#else
[sparkleContainer setHidden:YES];
#endif
[photoView setWantsLayer: YES];
photoView.layer.cornerRadius = photoView.frame.size.width / 2;
photoView.layer.masksToBounds = YES;
[addProfilePhotoImage setWantsLayer: YES];
[addProfilePhotoImage setHidden:NO];
[photoView setBordered:YES];
if (auto pro = ProfileModel::instance().selectedProfile()) {
[profileNameField setStringValue:pro->person()->formattedName().toNSString()];
if (pro->person() && pro->person()->photo().isValid()) {
auto photo = GlobalInstances::pixmapManipulator().contactPhoto(pro->person(), {140,140});
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
[addProfilePhotoImage setHidden:YES];
[photoView setBordered:NO];
}
}
if (appSandboxed()) {
[downloadFolder setHidden:YES];
[downloadFolder setEnabled:NO];
......@@ -127,27 +77,6 @@
}
}
- (void) dealloc
{
[[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:Preferences::HistoryLimit];
}
- (IBAction)clearHistory:(id)sender {
CategorizedHistoryModel::instance().clearAllCollections();
media::RecordingModel::instance().clearAllCollections();
[historyChangedLabel setHidden:NO];
}
- (IBAction)toggleHistory:(NSButton*)sender {
CategorizedHistoryModel::instance().setHistoryLimited([sender state]);
int historyLimit = CategorizedHistoryModel::instance().historyLimit();
[historyTextField setStringValue:[NSString stringWithFormat:@"%d", historyLimit]];
[historyStepper setIntValue:historyLimit];
[historyChangedLabel setHidden:NO];
[historyStepper setEnabled:[sender state]];
[historyTextField setEnabled:[sender state]];
}
- (IBAction)changeDownloadFolder:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
......@@ -163,16 +92,6 @@
[[NSUserDefaults standardUserDefaults] setObject:path forKey:Preferences::DownloadFolder];
}
// KVO handler
-(void)observeValueForKeyPath:(NSString *)aKeyPath ofObject:(id)anObject
change:(NSDictionary *)aChange context:(void *)aContext
{
if ([aKeyPath isEqualToString:Preferences::HistoryLimit]) {
CategorizedHistoryModel::instance().setHistoryLimit([[aChange objectForKey: NSKeyValueChangeNewKey] integerValue]);
[historyChangedLabel setHidden:NO];
}
}
#pragma mark - Startup API
// MIT license by Brian Dunagan
......@@ -238,48 +157,6 @@
return itemRef;
}
#pragma mark - Profile Photo edition
- (IBAction) editPhoto:(id)sender {
auto pictureTaker = [IKPictureTaker pictureTaker];
[pictureTaker beginPictureTakerSheetForWindow:self.view.window
withDelegate:self
didEndSelector:@selector(pictureTakerDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void) pictureTakerDidEnd:(IKPictureTaker *) picker
returnCode:(NSInteger) code
contextInfo:(void*) contextInfo
{
if (auto outputImage = [picker outputImage]) {
[photoView setImage:outputImage];
[addProfilePhotoImage setHidden:YES];
[photoView setBordered:NO];
if (auto pro = ProfileModel::instance().selectedProfile()) {
QPixmap p;
auto smallImg = [NSImage imageResize:outputImage newSize:{100,100}];
if (p.loadFromData(QByteArray::fromNSData([smallImg TIFFRepresentation]))) {
pro->person()->setPhoto(QVariant(p));
}
pro->save();
}
} else if (!photoView.image){
[addProfilePhotoImage setHidden:NO];
[photoView setBordered:YES];
}
}
#pragma mark - NSTextFieldDelegate methods
-(void)controlTextDidChange:(NSNotification *)notif
{
if (auto pro = ProfileModel::instance().selectedProfile()) {
pro->person()->setFormattedName(profileNameField.stringValue.UTF8String);
pro->save();
}
}
#pragma mark - NSOpenSavePanelDelegate delegate methods
- (BOOL) panel:(id)sender shouldEnableURL:(NSURL*)url {
......
......@@ -68,4 +68,8 @@ namespace lrc {
*/
-(void) listTypeChanged;
-(void) showConversation:(NSString* )conversationId forAccount:(NSString*)accountId;
-(void) showCall:(NSString* )callId forAccount:(NSString*)accountId forConversation:(NSString*)conversationId;
-(void) showContactRequestFor:(NSString* )accountId contactUri:(NSString*)uri;
@end
......@@ -535,4 +535,57 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
[smartViewVC reloadConversationWithUid:@(conversationID.c_str())];
}
-(void) showConversation:(NSString* )conversationId forAccount:(NSString*)accountId {
auto& accInfo = self.accountModel->getAccountInfo([accountId UTF8String]);
[chooseAccountVC selectAccount: accountId];
[settingsVC setSelectedAccount: [accountId UTF8String]];
[smartViewVC setConversationModel:accInfo.conversationModel.get()];
[smartViewVC selectConversationList];
[self updateRingID];
auto convInfo = getConversationFromUid([conversationId UTF8String], *accInfo.conversationModel.get());
auto convQueue = accInfo.conversationModel.get()->allFilteredConversations();
if (convInfo != convQueue.end()) {
[conversationVC setConversationUid:convInfo->uid model:accInfo.conversationModel.get()];
[smartViewVC selectConversation: *convInfo model:accInfo.conversationModel.get()];
accInfo.conversationModel.get()->clearUnreadInteractions([conversationId UTF8String]);
}
[self changeViewTo:SHOW_CONVERSATION_SCREEN];
}
-(void) showCall:(NSString* )callId forAccount:(NSString*)accountId forConversation:(NSString*)conversationId {
auto& accInfo = self.accountModel->getAccountInfo([accountId UTF8String]);
[chooseAccountVC selectAccount: accountId];
[settingsVC setSelectedAccount:accInfo.id];
[smartViewVC setConversationModel:accInfo.conversationModel.get()];
[self updateRingID];
auto convInfo = getConversationFromUid([conversationId UTF8String], *accInfo.conversationModel.get());
auto convQueue = accInfo.conversationModel.get()->allFilteredConversations();
if (convInfo != convQueue.end()) {
if (accInfo.contactModel->getContact(convInfo->participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING)
[smartViewVC selectPendingList];
else
[smartViewVC selectConversationList];
[smartViewVC selectConversation: *convInfo model:accInfo.conversationModel.get()];
}
[currentCallVC setCurrentCall:[callId UTF8String]
conversation:[conversationId UTF8String]
account:&accInfo];
[self changeViewTo:SHOW_CALL_SCREEN];
}
-(void) showContactRequestFor:(NSString* )accountId contactUri:(NSString*)uri {
auto& accInfo = self.accountModel->getAccountInfo([accountId UTF8String]);
[chooseAccountVC selectAccount: accountId];
[settingsVC setSelectedAccount:accInfo.id];
[smartViewVC setConversationModel:accInfo.conversationModel.get()];
[self updateRingID];
[smartViewVC selectPendingList];
auto convInfo = getConversationFromURI([uri UTF8String], *accInfo.conversationModel.get());
auto convQueue = accInfo.conversationModel.get()->allFilteredConversations();
if (convInfo != convQueue.end()) {
[conversationVC setConversationUid:convInfo->uid model:accInfo.conversationModel.get()];
[smartViewVC selectConversation: *convInfo model:accInfo.conversationModel.get()];
}
[self changeViewTo:SHOW_CONVERSATION_SCREEN];
}
@end
......@@ -175,6 +175,7 @@
}
// enable Notifications
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:Preferences::Notifications];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:Preferences::CallNotifications];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:Preferences::MessagesNotifications];
}
@end
......@@ -321,7 +321,8 @@ NSInteger const ERROR_REPEAT_MISMATCH = -2;
}
// enable Notifications
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:Preferences::Notifications];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:Preferences::CallNotifications];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:Preferences::MessagesNotifications];
}
- (IBAction)cancel:(id)sender
......
......@@ -129,6 +129,19 @@ static inline lrc::api::ConversationModel::ConversationQueue::const_iterator get
});
}
/**
* This function return an iterator pointing to a Conversation::Info in ConversationModel given its participant uri. Will not work for group chat.
* @param uri URI of participant
* @param model ConversationModel in which to do the lookup
* @return iterator pointing to corresponding Conversation if any. Points to past-the-end element otherwise.
*/
static inline lrc::api::ConversationModel::ConversationQueue::const_iterator getConversationFromURI(const std::string& uri, const lrc::api::ConversationModel& model) {
return std::find_if(model.allFilteredConversations().begin(), model.allFilteredConversations().end(),
[&] (const lrc::api::conversation::Info& conv) {
return uri == conv.participants[0];
});
}
static inline void
setVideoAutoQuality(bool autoQuality, std::string accountId)
{
......
......@@ -44,8 +44,8 @@
/* Class = "NSTextFieldCell"; title = "Update"; ObjectID = "r4u-t3-gBc"; */
"r4u-t3-gBc.title" = "Update";
/* Class = "NSButtonCell"; title = "Enable Desktop Notifications"; ObjectID = "uCL-ye-tsv"; */
"uCL-ye-tsv.title" = "Enable Desktop Notifications";
/* Class = "NSButtonCell"; title = "Enable notifications for incoming calls"; ObjectID = "uCL-ye-tsv"; */
"uCL-ye-tsv.title" = "Enable notifications for incoming calls";
/* Class = "NSButtonCell"; title = "Bring Ring to foreground on incoming calls"; ObjectID = "uYI-hA-JHk"; */
"uYI-hA-JHk.title" = "Bring Ring to foreground on incoming calls";
......
This diff is collapsed.
......@@ -85,6 +85,9 @@
/* Incoming call from {Name} */
"Incoming call from %@" = "Incoming call from %@";
/* Incoming message from {Name} */
"Incoming message from %@" = "Incoming message from %@";
/* Message from {Name} */
"Message from %@" = "Message from %@";
......@@ -114,6 +117,7 @@
/* Button Action */
"Refuse" = "Refuse";
"Accept" = "Accept";
/* Contextual menu entry */
"Remove value" = "Remove value";
......@@ -183,3 +187,6 @@
"Create a new account" = "Create a new account";
"Add a SIP account" = "Add a SIP account";
/* Notification message */
"Send you a contact request" = "Send you a contact request";
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