Commit e404149a authored by Alexandre Lision's avatar Alexandre Lision Committed by Alexandre Lision

preferences: add user oriented features

- notifications on incoming calls
- history limitation / deletion
- bring app to foreground

Refs #66840

Change-Id: I847d45337f438140904523d9306583c72a8f3625
parent 7837e4ff
......@@ -35,7 +35,7 @@
#import "RingWindowController.h"
#import "PreferencesWindowController.h"
@interface AppDelegate : NSObject <NSApplicationDelegate>
@interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate>
@property RingWindowController* ringWindowController;
......
......@@ -29,14 +29,43 @@
*/
#import "AppDelegate.h"
#import <callmodel.h>
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints"];
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
self.ringWindowController = [[RingWindowController alloc] initWithWindowNibName:@"RingWindow"];
[self.ringWindowController showWindow:nil];
[self connect];
}
- (void) connect
{
QObject::connect(CallModel::instance(),
&CallModel::incomingCall,
[=](Call* call) {
BOOL shouldComeToForeground = [[NSUserDefaults standardUserDefaults] boolForKey:@"window_behaviour"];
BOOL shouldNotify = [[NSUserDefaults standardUserDefaults] boolForKey:@"enable_notifications"];
if(shouldComeToForeground)
[NSApp activateIgnoringOtherApps:YES];
if(shouldNotify) {
[self showIncomingNotification:call];
}
});
}
- (void) showIncomingNotification:(Call*) call{
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = @"Incoming call", call->peerName();
//notification.informativeText = @"A notification";
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
@end
This diff is collapsed.
......@@ -34,6 +34,7 @@
@interface GeneralPrefsVC : NSViewController {
NSTextField *historyChangedLabel;
}
@end
......
......@@ -29,12 +29,35 @@
*/
#import "GeneralPrefsVC.h"
#import <categorizedhistorymodel.h>
@interface GeneralPrefsVC ()
@property (assign) IBOutlet NSTextField *historyChangedLabel;
@end
@implementation GeneralPrefsVC {
}
@synthesize historyChangedLabel;
- (void)loadView
{
[super loadView];
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"history_limit" options:NSKeyValueObservingOptionNew context:NULL];
}
- (IBAction)clearHistory:(id)sender {
CategorizedHistoryModel::instance()->clearAllCollections();
[historyChangedLabel setHidden:NO];
}
// KVO handler
-(void)observeValueForKeyPath:(NSString *)aKeyPath ofObject:(id)anObject
change:(NSDictionary *)aChange context:(void *)aContext
{
NSLog(@"VALUE CHANGED");
[historyChangedLabel setHidden:NO];
}
@end
......@@ -42,7 +42,6 @@
#define COLUMNID_CONTACTMETHOD @"ContactMethodColumn" // the single column name in our outline view
#define COLUMNID_DATE @"DateColumn" // the single column name in our outline view
@interface HistoryViewController()
@property NSTreeController *treeController;
......@@ -81,10 +80,7 @@
[historyView setTarget:self];
[historyView setDoubleAction:@selector(placeCall:)];
NSInteger idx = [historyView columnWithIdentifier:COLUMNID_DAY];
CategorizedHistoryModel::instance()->addCollection<MinimalHistoryBackend>(LoadOptions::FORCE_ENABLED);
}
- (void)placeCall:(id)sender
......
......@@ -18,12 +18,16 @@
***********************************************************************************/
#import "minimalhistorybackend.h"
#import <Cocoa/Cocoa.h>
//Qt
#import <QtCore/QFile>
#import <QtCore/QDir>
#import <QtCore/qlist.h>
#import <QtCore/QHash>
#import <QtWidgets/QApplication>
#import <QtCore/QStandardPaths>
#import <collectioneditor.h>
//Ring
#import <call.h>
......@@ -38,6 +42,7 @@ public:
MinimalHistoryEditor(CollectionMediator<Call>* m, MinimalHistoryBackend* parent);
virtual bool save ( const Call* item ) override;
virtual bool remove ( const Call* item ) override;
virtual bool batchRemove(const QList<Call*> contacts) override;
virtual bool edit ( Call* item ) override;
virtual bool addNew ( const Call* item ) override;
virtual bool addExisting( const Call* item ) override;
......@@ -124,9 +129,15 @@ bool MinimalHistoryEditor::save(const Call* call)
bool MinimalHistoryEditor::remove(const Call* item)
{
mediator()->removeItem(item);
return regenFile(item);
}
bool MinimalHistoryEditor::batchRemove(const QList<Call*> calls) {
QFile::remove(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + "history.ini");
return YES;
}
bool MinimalHistoryEditor::edit( Call* item)
{
Q_UNUSED(item)
......@@ -190,6 +201,9 @@ bool MinimalHistoryBackend::isEnabled() const
bool MinimalHistoryBackend::load()
{
// get history limit from our preferences set
NSInteger historyLimit = [[NSUserDefaults standardUserDefaults] integerForKey:@"history_limit"];
QFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') +"history.ini");
if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
QMap<QString,QString> hc;
......@@ -202,10 +216,13 @@ bool MinimalHistoryBackend::load()
if (pastCall->peerName().isEmpty()) {
pastCall->setPeerName(QObject::tr("Unknown"));
}
pastCall->setRecordingPath(hc[ Call::HistoryMapFields::RECORDING_PATH ]);
pastCall->setCollection(this);
editor<Call>()->addExisting(pastCall);
if(daysSince(pastCall->startTimeStamp()) < historyLimit) {
pastCall->setRecordingPath(hc[ Call::HistoryMapFields::RECORDING_PATH ]);
pastCall->setCollection(this);
editor<Call>()->addExisting(pastCall);
}
hc.clear();
}
// Add to the current set
......@@ -222,6 +239,26 @@ bool MinimalHistoryBackend::load()
return false;
}
int MinimalHistoryBackend::daysSince(time_t timestamp)
{
NSDate *fromDate;
NSDate *toDate;
NSDate* fromDateTime = [NSDate dateWithTimeIntervalSince1970:timestamp];
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar rangeOfUnit:NSCalendarUnitDay startDate:&fromDate
interval:NULL forDate:fromDateTime];
[calendar rangeOfUnit:NSCalendarUnitDay startDate:&toDate
interval:NULL forDate:[NSDate date]];
NSDateComponents *difference = [calendar components:NSCalendarUnitDay
fromDate:fromDate toDate:toDate options:0];
return [difference day];
}
bool MinimalHistoryBackend::reload()
{
return false;
......@@ -239,7 +276,11 @@ CollectionInterface::SupportedFeatures MinimalHistoryBackend::supportedFeatures(
bool MinimalHistoryBackend::clear()
{
QFile::remove(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + "history.ini");
editor<Call>()->batchRemove(items<Call>().toList());
QList<Call*> calls = items<Call>().toList();
for(int i = 0 ; i < calls.count() ; ++i) {
CategorizedHistoryModel::instance()->deleteItem(calls[i]);
}
return true;
}
......
......@@ -32,6 +32,7 @@
#import <QuartzCore/QuartzCore.h>
#import <accountmodel.h>
#import <audio/codecmodel.h>
#import "AccountsVC.h"
#import "GeneralPrefsVC.h"
......@@ -82,7 +83,13 @@ static NSString* const kPowerSettingsIdentifer = @"PowerSettingsIdentifer";
- (void) close
{
// first save codecs for each account
for (int i = 0 ; i < AccountModel::instance()->rowCount(); ++i) {
QModelIndex qIdx = AccountModel::instance()->index(i);
AccountModel::instance()->getAccountByModelIndex(qIdx)->codecModel()->save();
}
// then save accounts
AccountModel::instance()->save();
CGRect frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height);
......
......@@ -20,7 +20,6 @@
#define MINIMALHISTORYBACKEND_H
#import <collectioninterface.h>
#import <collectioneditor.h>
class Call;
......@@ -41,6 +40,8 @@ public:
virtual bool isEnabled() const override;
virtual QByteArray id () const override;
virtual SupportedFeatures supportedFeatures() const override;
int daysSince(time_t timestamp);
private:
CollectionMediator<Call>* m_pMediator;
......
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