Skip to content
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

#596: support copy image #601

Merged
merged 1 commit into from
Jun 20, 2024
Merged

#596: support copy image #601

merged 1 commit into from
Jun 20, 2024

Conversation

lidaobing
Copy link
Member

@lidaobing lidaobing commented Jun 20, 2024

Summary by Sourcery

This pull request introduces a new feature that allows users to copy images to the clipboard directly from the image context menu in the application.

  • New Features:
    • Added support for copying images to the clipboard from the image context menu.

@lidaobing lidaobing linked an issue Jun 20, 2024 that may be closed by this pull request
Copy link

sourcery-ai bot commented Jun 20, 2024

Reviewer's Guide by Sourcery

This pull request adds support for copying images to the clipboard. The changes include adding a new 'Copy Image' menu item to the image context menu in DialogBase.cpp, connecting this menu item to a new OnCopyImage callback function, and ensuring proper cleanup of the menu widget. Additionally, the OnCopyImage method is declared in the DialogBase class in DialogBase.h.

File-Level Changes

Files Changes
src/iptux/DialogBase.cpp
src/iptux/DialogBase.h
Implemented support for copying images to the clipboard by adding a new menu item and corresponding callback function.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @lidaobing - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

gtk_widget_show_all(menu);

gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent*)&event);
g_signal_connect(menu, "hide", G_CALLBACK(gtk_widget_destroy), menu);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Potential double-free or use-after-free issue.

Connecting the 'hide' signal to gtk_widget_destroy might lead to a double-free or use-after-free if the menu is already being managed elsewhere. Ensure that this widget is not being destroyed elsewhere in the code.

@@ -910,4 +915,15 @@ void DialogBase::OnSaveImage(GtkImage* image) {
gtk_widget_destroy(dialog);
}

void DialogBase::OnCopyImage(GtkImage* image) {
GdkPixbuf* pixbuf = gtk_image_get_pixbuf(image);
if (!pixbuf) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider providing more context in the error log.

The error log 'Failed to create pixbuf from image.' could be more informative. Consider including details about the image or the context in which this failure occurred to aid in debugging.

Suggested change
if (!pixbuf) {
if (!pixbuf) {
LOG_ERROR("Failed to create pixbuf from image. Image pointer: %p", image);
return;

return;
}

GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Check for null clipboard.

Consider adding a null check for the clipboard to handle cases where gtk_clipboard_get might fail.

Suggested change
GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
if (clipboard == nullptr) {
return;
}

@@ -90,6 +90,7 @@ class DialogBase : public SessionAbstract, public sigc::trackable {
GtkTextChildAnchor* anchor,
GtkTextBuffer* buffer);
static void OnSaveImage(GtkImage* self);
static void OnCopyImage(GtkImage* self);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider renaming the parameter for consistency.

The parameter name 'self' is typically used in Python. Consider renaming it to 'image' for consistency with the implementation and other function signatures.

Suggested change
static void OnCopyImage(GtkImage* self);
static void OnCopyImage(GtkImage* image);

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.

Project coverage is 51.36%. Comparing base (8ea6c1c) to head (53d1235).

Files Patch % Lines
src/iptux/DialogBase.cpp 0.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #601      +/-   ##
==========================================
- Coverage   51.44%   51.36%   -0.08%     
==========================================
  Files          64       64              
  Lines        8333     8344      +11     
==========================================
- Hits         4287     4286       -1     
- Misses       4046     4058      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lidaobing lidaobing merged commit a28cf30 into master Jun 20, 2024
13 of 15 checks passed
@lidaobing lidaobing deleted the 596-copy-image branch June 20, 2024 05:22
@lidaobing lidaobing added this to the 0.9.2 milestone Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support copy image & copy thumbnail from chat history
1 participant