-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev: Add drag and drop, fixes and review are still needed #78
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#import <Foundation/Foundation.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <memory> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <unordered_map> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <pb/PhotoBook.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <pb/entities/LutIconInfo.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -80,8 +81,14 @@ void post(std::function<void()> f) override { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void onCollageCreated(unsigned index, PB::GenericImagePtr newImage) override {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void onImageMapped(PBDev::ImageToPaperId id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PB::GenericImagePtr image) override {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void onImageMapped(PBDev::ImageToPaperId imageId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PB::GenericImagePtr image) override { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::string imageIdStr = boost::uuids::to_string(*imageId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
NSString* managedImageId = [NSString stringWithUTF8String:imageIdStr.c_str()]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
auto managedImage = [[FrontendImage alloc] initWithCpp:image]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[&mManagedListener onImageMapped:managedImageId image:managedImage]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void onProgressUpdate(PB::ProgressStatus status) override {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[[deprecated]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -212,4 +219,30 @@ - (void) removeImportFolder:(NSString*)root | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return [list copy]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- (void) mapImagesToSPL:(NSDictionary<NSString*, FrontendImage*>*)images | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
auto imageToPaperService = mPhotobook->imageToPaperService(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::unordered_map<PBDev::ImageToPaperId, PB::GenericImagePtr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boost::hash<PBDev::ImageToPaperId>> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
backendMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (NSString *key in images) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::string uuidStr = [key UTF8String]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boost::uuids::string_generator gen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boost::uuids::uuid nativeUuid = gen(uuidStr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PBDev::ImageToPaperId imageId = PBDev::ImageToPaperId(nativeUuid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
backendMap[imageId] = [images[key] unwrap]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (const std::exception& e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
imageToPaperService->map( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PBDev::ImageToPaperServiceId(PB::RuntimeUUID::newUUID()), backendMap); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+222
to
+246
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and validation in mapImagesToSPL. The implementation has several issues:
- (void) mapImagesToSPL:(NSDictionary<NSString*, FrontendImage*>*)images
{
+ if (!images) {
+ NSLog(@"Error: images dictionary is null");
+ return;
+ }
auto imageToPaperService = mPhotobook->imageToPaperService();
std::unordered_map<PBDev::ImageToPaperId, PB::GenericImagePtr,
boost::hash<PBDev::ImageToPaperId>>
backendMap;
for (NSString *key in images) {
+ if (!images[key]) {
+ NSLog(@"Error: null image for key %@", key);
+ continue;
+ }
std::string uuidStr = [key UTF8String];
try {
boost::uuids::string_generator gen;
boost::uuids::uuid nativeUuid = gen(uuidStr);
PBDev::ImageToPaperId imageId = PBDev::ImageToPaperId(nativeUuid);
backendMap[imageId] = [images[key] unwrap];
} catch (const std::exception& e) {
+ NSLog(@"Error parsing UUID %@: %s", key, e.what());
}
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// StagedPhotoLine.swift | ||
// PhotoBook | ||
// | ||
// Created by Cosmin Mihai on 29.01.2025. | ||
// | ||
|
||
import SwiftUI | ||
|
||
class StagedPhotoLineModel: ObservableObject | ||
{ | ||
@Published public var list: [FrontendImage] = [] | ||
} | ||
|
||
struct StagedPhotoLine: View | ||
{ | ||
@ObservedObject var model: StagedPhotoLineModel | ||
@Binding var canvasImage: FrontendImage? | ||
@State var selectedIndex: Int = -1 | ||
|
||
var body: some View { | ||
ScrollView(.horizontal, showsIndicators: false) { | ||
HStack { | ||
ForEach(self.model.list.indices, id: \.self) { index in | ||
if let fileName = self.model.list[index].resources().small | ||
{ | ||
if let nsImage = NSImage(contentsOfFile: fileName) { | ||
Image(nsImage: nsImage) | ||
.cornerRadius(10) | ||
.frame(height: 80) | ||
.overlay( | ||
RoundedRectangle(cornerRadius: 10) | ||
.stroke(selectedIndex == index ? Color.yellow : Color.clear, lineWidth: 3) | ||
) | ||
.onTapGesture { | ||
self.canvasImage = model.list[index] | ||
selectedIndex = index | ||
} | ||
} else { | ||
Text("Image not found") | ||
} | ||
} | ||
} | ||
} | ||
.padding(.horizontal) | ||
.frame(minHeight:80) | ||
.border(Color.BorderColor, width: 1) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// UPLIdentifier.swift | ||
// PhotoBook | ||
// | ||
// Created by Cosmin Mihai on 26.01.2025. | ||
// | ||
|
||
import SwiftUI | ||
import UniformTypeIdentifiers | ||
|
||
class UPLIdentifier: NSObject, Identifiable, NSItemProviderWriting, Encodable, Decodable | ||
{ | ||
public var id = UUID() | ||
public var row:UInt?; | ||
public var indices:[UInt]; | ||
|
||
init(row:UInt?, indices:[UInt]) | ||
{ | ||
self.row = row | ||
self.indices = indices | ||
} | ||
|
||
static var writableTypeIdentifiersForItemProvider: [String] { | ||
return [UTType.plainText.identifier] | ||
} | ||
|
||
func loadData(withTypeIdentifier typeIdentifier: String, forItemProviderCompletionHandler completionHandler: @escaping @Sendable (Data?, (any Error)?) -> Void) -> Progress? { | ||
do { | ||
let encoder = JSONEncoder() | ||
let dataToReturn = try encoder.encode(self) | ||
completionHandler(dataToReturn, nil) | ||
} catch { | ||
completionHandler(nil, error) | ||
} | ||
return Progress(totalUnitCount: 100) | ||
} | ||
Comment on lines
+27
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve progress reporting and error handling. The current implementation has several issues:
Consider this improved implementation: func loadData(withTypeIdentifier typeIdentifier: String, forItemProviderCompletionHandler completionHandler: @escaping @Sendable (Data?, (any Error)?) -> Void) -> Progress? {
// Verify type identifier
guard typeIdentifier == UTType.plainText.identifier else {
completionHandler(nil, NSError(domain: "UPLIdentifier", code: 1, userInfo: [
NSLocalizedDescriptionKey: "Unsupported type identifier: \(typeIdentifier)"
]))
return nil
}
let progress = Progress(totalUnitCount: 100)
do {
let encoder = JSONEncoder()
progress.completedUnitCount = 50 // Encoding started
let dataToReturn = try encoder.encode(self)
progress.completedUnitCount = 100 // Encoding completed
completionHandler(dataToReturn, nil)
} catch {
completionHandler(nil, error)
}
return progress
} |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Remove duplicate protocol implementation
The empty
onImageMapped
implementation at line 115 is redundant asPhotoBookApp
already implements this method at line 39 with proper delegation logic. Having two implementations of the same protocol method within the same type can lead to unexpected behavior.🔗 Analysis chain
Review empty implementation and verify protocol requirements.
The empty implementation raises several concerns:
PhotobookUIListener
might not be needed in this structLet's verify the protocol usage:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 952