Warning, /network/kdeconnect-kde/indicator/serviceregister_mac.mm is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Weixuan XIAO <veyx.shaw@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #import <Foundation/Foundation.h> 0008 #import <AppKit/AppKit.h> 0009 0010 #include <QFile> 0011 #include <QProcess> 0012 #include <QApplication> 0013 0014 @interface KDEConnectSendFileService : NSObject 0015 - (void)sendViaKDEConnect:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error; 0016 @end 0017 0018 static KDEConnectSendFileService *sendFileService = nil; 0019 0020 static void cleanup_service() 0021 { 0022 if (sendFileService != nil) 0023 [sendFileService release]; 0024 0025 sendFileService = nil; 0026 } 0027 0028 void registerServices() { 0029 NSLog(@"Registering KDE Connect Send File Service"); 0030 KDEConnectSendFileService *sendFileService = [[KDEConnectSendFileService alloc] init]; 0031 qAddPostRoutine(cleanup_service); // Remove after quit 0032 0033 NSRegisterServicesProvider(sendFileService, @"SendViaKDEConnect"); 0034 0035 NSLog(@"KDE Connect Send File Service registered"); 0036 } 0037 0038 @implementation KDEConnectSendFileService 0039 0040 - (void)sendViaKDEConnect:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error { 0041 Q_UNUSED(userData); 0042 Q_UNUSED(error); 0043 0044 NSAlert *alert = nil; 0045 // NSPasteboardTypeFileURL is first introduced in macOS 13, avoid to use it now 0046 NSArray *filePathArray = [pboard propertyListForType:NSFilenamesPboardType]; 0047 for (NSString *path in filePathArray) { 0048 BOOL isDirectory = NO; 0049 if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]) { 0050 if (!isDirectory) { 0051 if (QFile::exists(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnect-handler"))) { 0052 QProcess kdeconnect_handler; 0053 kdeconnect_handler.setProgram(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnect-handler")); 0054 kdeconnect_handler.setArguments({QString::fromNSString(path)}); 0055 kdeconnect_handler.startDetached(); 0056 } else { 0057 alert = [[NSAlert alloc] init]; 0058 [alert setInformativeText:@"Cannot find kdeconnect-handler"]; 0059 } 0060 } else { 0061 alert = [[NSAlert alloc] init]; 0062 [alert setInformativeText:@"Cannot share a directory"]; 0063 } 0064 } 0065 break; // Now we only support single file sharing 0066 } 0067 0068 if ([filePathArray count] < 1) { 0069 alert = [[NSAlert alloc] init]; 0070 [alert setInformativeText:@"Cannot share selected item"]; 0071 } 0072 0073 if (alert) { 0074 [alert setMessageText:@"Share file failed"]; 0075 [alert addButtonWithTitle:@"OK"]; 0076 [alert setAlertStyle:NSAlertStyleCritical]; 0077 [alert runModal]; 0078 [alert release]; 0079 } 0080 } 0081 0082 @end