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

data transfer: select download folder

Add setting to select folder for incoming images.

Change-Id: I2ee21e0b9195e8ebfcaf11e101160b8058d39792
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 50b05f5a
......@@ -171,6 +171,7 @@ SET(ringclient_CONTROLLERS
src/MessagesVC.mm
src/PasswordChangeWC.h
src/PasswordChangeWC.mm
src/LrcModelsSProtocol.h
)
SET(ringclient_BACKENDS
......@@ -277,6 +278,7 @@ SET_SOURCE_FILES_PROPERTIES(${myApp_ICON} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
SET(ring_ICONS
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_folder.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_block.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_attachment.png
${CMAKE_CURRENT_SOURCE_DIR}/data/default_avatar_overlay.png
......
ic_folder.png

239 Bytes

......@@ -96,8 +96,8 @@ NSInteger const TAG_TYPE = 400;
QMetaObject::Connection accountChangedConnection, selectedAccountChangedConnection, accountTypeChangedConnection;
- (void)awakeFromNib
{
- (void)loadView {
[super loadView];
treeController = [[QNSTreeController alloc] initWithQModel:&AccountModel::instance()];
[treeController setAvoidsEmptySelection:NO];
[treeController setAlwaysUsesMultipleValuesMarker:YES];
......@@ -111,24 +111,24 @@ QMetaObject::Connection accountChangedConnection, selectedAccountChangedConnecti
QObject::disconnect(selectedAccountChangedConnection);
accountChangedConnection = QObject::connect(&AccountModel::instance(),
&QAbstractItemModel::dataChanged,
[=](const QModelIndex &topLeft, const QModelIndex &bottomRight) {
[accountsListView reloadDataForRowIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(topLeft.row(), bottomRight.row() + 1)]
columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, accountsListView.tableColumns.count)]];
});
&QAbstractItemModel::dataChanged,
[=](const QModelIndex &topLeft, const QModelIndex &bottomRight) {
[accountsListView reloadDataForRowIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(topLeft.row(), bottomRight.row() + 1)]
columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, accountsListView.tableColumns.count)]];
});
selectedAccountChangedConnection = QObject::connect(AccountModel::instance().selectionModel(),
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
[accountDetailsView setHidden:!current.isValid()];
if(!current.isValid()) {
[accountsListView deselectAll:nil];
return;
}
[treeController setSelectionQModelIndex:current];
});
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
[accountDetailsView setHidden:!current.isValid()];
if(!current.isValid()) {
[accountsListView deselectAll:nil];
return;
}
[treeController setSelectionQModelIndex:current];
});
AccountModel::instance().selectionModel()->clearCurrentIndex();
......@@ -137,14 +137,14 @@ QMetaObject::Connection accountChangedConnection, selectedAccountChangedConnecti
AccountModel::instance().protocolModel()->data(qProtocolIdx, Qt::DisplayRole).toString().toNSString()];
QObject::disconnect(accountTypeChangedConnection);
accountTypeChangedConnection = QObject::connect(AccountModel::instance().protocolModel()->selectionModel(),
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
if (!current.isValid()) {
return;
}
[protocolList removeAllItems];
[protocolList addItemWithTitle:AccountModel::instance().protocolModel()->data(current, Qt::DisplayRole).toString().toNSString()];
});
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
if (!current.isValid()) {
return;
}
[protocolList removeAllItems];
[protocolList addItemWithTitle:AccountModel::instance().protocolModel()->data(current, Qt::DisplayRole).toString().toNSString()];
});
self.generalVC = [[AccGeneralVC alloc] initWithNibName:@"AccGeneral" bundle:nil];
[[self.generalVC view] setFrame:[self.generalTabItem.view frame]];
......
......@@ -31,4 +31,6 @@ namespace Preferences {
NSString * const WindowBehaviour = @"window_behaviour";
/* KVO compliant */
NSString * const Notifications = @"enable_notifications";
/* download folder for incoming images*/
NSString * const DownloadFolder = @"download_folder";
}
......@@ -19,7 +19,8 @@
#import <Cocoa/Cocoa.h>
#import "LrcModelsSProtocol.h"
@interface GeneralPrefsVC : NSViewController
@interface GeneralPrefsVC : NSViewController <LrcModelsSProtocol>
@end
\ No newline at end of file
@end
......@@ -32,6 +32,7 @@
#import <person.h>
#import <globalinstances.h>
#import <media/recordingmodel.h>
#import <api/datatransfermodel.h>
#if ENABLE_SPARKLE
#import <Sparkle/Sparkle.h>
......@@ -53,11 +54,24 @@
__unsafe_unretained IBOutlet NSButton* photoView;
__unsafe_unretained IBOutlet NSTextField* profileNameField;
__unsafe_unretained IBOutlet NSImageView* addProfilePhotoImage;
__unsafe_unretained IBOutlet NSButton *downloadFolder;
}
@end
@implementation GeneralPrefsVC
@synthesize dataTransferModel;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(lrc::api::DataTransferModel*) dataTransferModel
{
if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.dataTransferModel = dataTransferModel;
}
return self;
}
- (void)loadView
{
[super loadView];
......@@ -100,6 +114,9 @@
[photoView setBordered:NO];
}
}
if (dataTransferModel) {
downloadFolder.title = [@(dataTransferModel->downloadDirectory.c_str()) lastPathComponent];
}
}
- (void) dealloc
......@@ -123,6 +140,20 @@
[historyTextField setEnabled:[sender state]];
}
- (IBAction)changeDownloadFolder:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:NO];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
if ([panel runModal] != NSFileHandlingPanelOKButton) return;
if ([[panel URLs] lastObject] == nil) return;
NSString * path = [[[[panel URLs] lastObject] path] stringByAppendingString:@"/"];
dataTransferModel->downloadDirectory = std::string([path UTF8String]);
downloadFolder.title = [@(dataTransferModel->downloadDirectory.c_str()) lastPathComponent];
[[NSUserDefaults standardUserDefaults] setObject:path forKey:Preferences::DownloadFolder];
}
// KVO handler
-(void)observeValueForKeyPath:(NSString *)aKeyPath ofObject:(id)anObject
change:(NSDictionary *)aChange context:(void *)aContext
......
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*/
namespace lrc {
namespace api {
class DataTransferModel;
}
}
@protocol LrcModelsSProtocol
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(lrc::api::DataTransferModel*) dataTransferModel;
@property lrc::api::DataTransferModel* dataTransferModel;
@end
......@@ -35,7 +35,6 @@
#import "delegates/ImageManipulationDelegate.h"
#import "utils.h"
#import "views/NSColor+RingTheme.h"
#import "NSString+Extensions.h"
@interface MessagesVC () <NSTableViewDelegate, NSTableViewDataSource> {
......@@ -205,25 +204,6 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
convModel_->refreshFilter();
}
[self reloadConversationForMessage:interactionId shouldUpdateHeight:YES];
//accept incoming transfer
if (interaction.type == lrc::api::interaction::Type::INCOMING_DATA_TRANSFER &&
(interaction.status == lrc::api::interaction::Status::TRANSFER_AWAITING_HOST ||
interaction.status == lrc::api::interaction::Status::TRANSFER_CREATED)) {
lrc::api::datatransfer::Info info = {};
convModel_->getTransferInfo(interactionId, info);
double convertData = static_cast<double>(info.totalSize);
NSString* pathUrl = @(info.displayName.c_str());
NSString* fileExtension = pathUrl.pathExtension;
CFStringRef utiType = UTTypeCreatePreferredIdentifierForTag(
kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtension, NULL);
bool isImage = UTTypeConformsTo(utiType, kUTTypeImage);
if( convertData <= 10485760 && isImage) {
[self acceptFile:interactionId];
}
}
});
// Signals tracking changes in conversation list, we need them as cached conversation can be invalid
......@@ -336,13 +316,7 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
[result invalidateImageConstraints];
NSString* name = @(interaction.body.c_str());
if (name.length > 0) {
if (([name rangeOfString:@"/"].location != NSNotFound)) {
NSArray *listItems = [name componentsSeparatedByString:@"/"];
NSString* name1 = listItems.lastObject;
fileName = name1;
} else {
fileName = name;
}
fileName = [name lastPathComponent];
}
result.transferedFileName.stringValue = fileName;
if (status == lrc::api::interaction::Status::TRANSFER_FINISHED) {
......@@ -756,19 +730,6 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
return aMutableParagraphStyle;
}
- (void)acceptFile:(uint64_t)interactionID {
NSURL *downloadsURL = [[NSFileManager defaultManager]
URLForDirectory:NSDownloadsDirectory
inDomain:NSUserDomainMask appropriateForURL:nil
create:YES error:nil];
auto& inter = [self getCurrentConversation]->interactions.find(interactionID)->second;
if (convModel_ && !convUid_.empty()) {
NSURL *bUrl = [downloadsURL URLByAppendingPathComponent:@(inter.body.c_str())];
const char* fullPath = [bUrl fileSystemRepresentation];
convModel_->acceptTransfer(convUid_, interactionID, fullPath);
}
}
#pragma mark - Actions
- (void)acceptIncomingFile:(id)sender {
......
......@@ -17,8 +17,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import <Cocoa/Cocoa.h>
#import "LrcModelsSProtocol.h"
@interface PreferencesWC : NSWindowController <NSWindowDelegate>
@interface PreferencesWC : NSWindowController <NSWindowDelegate, LrcModelsSProtocol>
- (void)displayGeneral:(NSToolbarItem *)sender;
- (void)displayAudio:(NSToolbarItem *)sender;
......
......@@ -25,6 +25,7 @@
#import <codecmodel.h>
#import <profilemodel.h>
#import <profile.h>
#import <api/datatransfermodel.h>
//Ring
#import "AccountsVC.h"
......@@ -36,9 +37,10 @@
__unsafe_unretained IBOutlet NSView *prefsContainer;
NSViewController *currentVC;
}
@synthesize dataTransferModel;
// Identifiers used in PreferencesWindow.xib for tabs
static auto const kProfilePrefsIdentifier = @"AccountsPrefsIdentifier";
static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
......@@ -53,6 +55,15 @@ static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
[self displayGeneral:nil];
}
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(lrc::api::DataTransferModel*) dataTransferModel
{
if (self = [self initWithWindowNibName:nibNameOrNil])
{
self.dataTransferModel = dataTransferModel;
}
return self;
}
- (void)windowWillClose:(NSNotification *)notification
{
AccountModel::instance().save();
......@@ -63,7 +74,7 @@ static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
{
[[prefsContainer subviews]
makeObjectsPerformSelector:@selector(removeFromSuperview)];
currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil];
currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil model: self.dataTransferModel];
[self resizeWindowWithFrame:currentVC.view.frame];
[prefsContainer addSubview:currentVC.view];
......@@ -90,7 +101,7 @@ static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
- (IBAction)displayAccounts:(NSToolbarItem *)sender
{
[[prefsContainer subviews]
makeObjectsPerformSelector:@selector(removeFromSuperview)];
makeObjectsPerformSelector:@selector(removeFromSuperview)];
currentVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil];
[self resizeWindowWithFrame:currentVC.view.frame];
[prefsContainer addSubview:currentVC.view];
......
......@@ -39,6 +39,7 @@
#import <api/conversation.h>
#import <api/contactmodel.h>
#import <api/contact.h>
#import <api/datatransfermodel.h>
// Ring
#import "AppDelegate.h"
......@@ -123,6 +124,16 @@ NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarIte
NSToolbar *toolbar = self.window.toolbar;
toolbar.delegate = self;
[toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1];
// set download folder (default - 'Downloads')
NSString* path = [[NSUserDefaults standardUserDefaults] stringForKey:Preferences::DownloadFolder];
if (!path || path.length == 0) {
NSURL *downloadsURL = [[NSFileManager defaultManager]
URLForDirectory:NSDownloadsDirectory
inDomain:NSUserDomainMask appropriateForURL:nil
create:YES error:nil];
path = [[downloadsURL path] stringByAppendingString:@"/"];
}
lrc_->getDataTransferModel().downloadDirectory = std::string([path UTF8String]);
}
- (void) connect
......@@ -310,7 +321,7 @@ NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarIte
- (IBAction)openPreferences:(id)sender
{
preferencesWC = [[PreferencesWC alloc] initWithWindowNibName:@"PreferencesWindow"];
preferencesWC = [[PreferencesWC alloc] initWithNibName:@"PreferencesWindow" bundle: nil model:&(lrc_->getDataTransferModel())];
[preferencesWC.window makeKeyAndOrderFront:preferencesWC.window];
}
......
......@@ -119,7 +119,7 @@ NSInteger const REQUEST_SEG = 1;
selectorIsPresent = true;
smartView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleNone;
}
- (void)placeCall:(id)sender
......@@ -506,11 +506,7 @@ NSInteger const REQUEST_SEG = 1;
lastInteractionSnippetFixedString = [lastInteractionSnippetFixedString stringByReplacingOccurrencesOfString:@"📞" withString:@""];
if (conversation.interactions[lastUid].type == lrc::api::interaction::Type::OUTGOING_DATA_TRANSFER
|| conversation.interactions[lastUid].type == lrc::api::interaction::Type::INCOMING_DATA_TRANSFER) {
if (([lastInteractionSnippetFixedString rangeOfString:@"/"].location != NSNotFound)) {
NSArray *listItems = [lastInteractionSnippetFixedString componentsSeparatedByString:@"/"];
NSString* name = listItems.lastObject;
lastInteractionSnippetFixedString = name;
}
lastInteractionSnippetFixedString = [lastInteractionSnippetFixedString lastPathComponent];
}
[interactionSnippet setStringValue:lastInteractionSnippetFixedString];
......
This diff is collapsed.
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