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

#604: cop/save image not work under Linux #607

Merged
merged 3 commits into from
Jun 23, 2024
Merged

Conversation

lidaobing
Copy link
Member

@lidaobing lidaobing commented Jun 23, 2024

Summary by Sourcery

This pull request addresses the issue with the 'Save Image' functionality not working under Linux by properly managing the image popup menu. Additionally, it refactors the image context menu creation to be initialized once after the window is created, enhancing code maintainability.

  • Bug Fixes:
    • Fixed the issue where the 'Save Image' functionality was not working under Linux by ensuring the image popup menu is properly created and managed.
  • Enhancements:
    • Refactored the image context menu creation to be initialized once after the window is created, improving code maintainability and reducing redundancy.

@lidaobing lidaobing linked an issue Jun 23, 2024 that may be closed by this pull request
@lidaobing lidaobing self-assigned this Jun 23, 2024
Copy link

sourcery-ai bot commented Jun 23, 2024

Reviewer's Guide by Sourcery

This pull request refactors the image context menu handling in the DialogBase class to fix the issue of saving images not working under Linux. The changes include introducing a new method, afterWindowCreated, to initialize the image context menu and updating the OnImageButtonPress, OnSaveImage, and OnCopyImage methods to use class members for the menu and active image. Additionally, the afterWindowCreated method is called in the CreateMainWindow methods of DialogGroup and DialogPeer to ensure proper initialization.

File-Level Changes

Files Changes
src/iptux/DialogBase.cpp
src/iptux/DialogBase.h
Refactored image context menu handling by introducing afterWindowCreated method and using class members for menu and active image.
src/iptux/DialogGroup.cpp
src/iptux/DialogPeer.cpp
Ensured afterWindowCreated is called after main window creation to initialize image context menu.

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: 8 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.

}

gboolean DialogBase::OnImageButtonPress(DialogBase* self,
GdkEventButton* event,
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): Pointer dereference without null check

Ensure that event is not null before dereferencing it. Although it is likely that event will always be valid, adding a null check can prevent potential crashes in edge cases.

GtkEventBox* event_box) {
if (event.type != GDK_BUTTON_PRESS || event.button != 3) {
if (event->type != GDK_BUTTON_PRESS || event->button != 3) {
Copy link

Choose a reason for hiding this comment

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

suggestion: Magic number usage

Consider defining a constant for the button number 3 to improve code readability and maintainability.

Suggested change
if (event->type != GDK_BUTTON_PRESS || event->button != 3) {
#define RIGHT_MOUSE_BUTTON 3
if (event->type != GDK_BUTTON_PRESS || event->button != RIGHT_MOUSE_BUTTON) {

@@ -824,20 +842,10 @@ gboolean DialogBase::OnImageButtonPress(DialogBase*,
LOG_ERROR("image not found in event box.");
return FALSE;
}
self->m_activeImage = GTK_IMAGE(image);
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 type safety issue

Ensure that image is indeed a GtkImage before casting. If image can be of different types, consider adding a type check.


gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent*)&event);
g_signal_connect(menu, "hide", G_CALLBACK(gtk_widget_destroy), menu);
gtk_widget_show_all(GTK_WIDGET(self->m_imagePopupMenu));
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 null pointer dereference

Ensure that self->m_imagePopupMenu is not null before calling gtk_widget_show_all. Although it is likely initialized, adding a null check can prevent potential crashes.

void DialogBase::OnSaveImage(GtkImage* image) {
void DialogBase::OnSaveImage(DialogBase* self) {
GtkImage* image = self->m_activeImage;
g_return_if_fail(!!image);
Copy link

Choose a reason for hiding this comment

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

suggestion: Double negation usage

Using double negation !!image is unconventional and might be confusing. Consider using image != NULL for clarity.

Suggested change
g_return_if_fail(!!image);
g_return_if_fail(image != NULL);

@@ -109,6 +111,10 @@ class DialogBase : public SessionAbstract, public sigc::trackable {
int64_t totalsendsize; // 总计待发送大小(包括已发送)
struct timeval lasktime; // 上一次更新UI的时间
guint timersend; // 发送文件界面更新计时器ID

private:
GtkMenu* m_imagePopupMenu = 0;
Copy link

Choose a reason for hiding this comment

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

suggestion: Use nullptr instead of 0 for pointer initialization

Consider using nullptr instead of 0 for pointer initialization to improve code clarity and type safety.

Suggested change
GtkMenu* m_imagePopupMenu = 0;
GtkMenu* m_imagePopupMenu = nullptr;


private:
GtkMenu* m_imagePopupMenu = 0;
GtkImage* m_activeImage = 0;
Copy link

Choose a reason for hiding this comment

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

suggestion: Use nullptr instead of 0 for pointer initialization

Consider using nullptr instead of 0 for pointer initialization to improve code clarity and type safety.

Suggested change
GtkImage* m_activeImage = 0;
GtkImage* m_activeImage = nullptr;

Copy link

codecov bot commented Jun 23, 2024

Codecov Report

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

Project coverage is 51.47%. Comparing base (0b47207) to head (f780bc2).

Files Patch % Lines
src/iptux/DialogBase.cpp 47.61% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #607      +/-   ##
==========================================
+ Coverage   51.37%   51.47%   +0.10%     
==========================================
  Files          64       64              
  Lines        8345     8354       +9     
==========================================
+ Hits         4287     4300      +13     
+ Misses       4058     4054       -4     

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

@lidaobing lidaobing merged commit 8afe210 into master Jun 23, 2024
15 of 16 checks passed
@lidaobing lidaobing deleted the 604-image-linux-not-work branch June 23, 2024 01:54
@iptux-src iptux-src deleted a comment from sourcery-ai bot Feb 16, 2025
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.

the save/copy image function does not work under Linux
1 participant