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

616 double click image #617

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

616 double click image #617

wants to merge 9 commits into from

Conversation

lidaobing
Copy link
Member

@lidaobing lidaobing commented Jul 2, 2024

Summary by Sourcery

This pull request introduces the ability to handle double-click events on images within the chat history, allowing users to save or copy images. It also includes enhancements to the build system to support a new config-debug option, and updates to the test suite to cover the new functionality and configurations.

  • New Features:
    • Added functionality to handle double-click events on images in chat history, allowing users to save or copy images.
  • Enhancements:
    • Introduced a new method chatHistoryGetImageEventBox in DialogBase to retrieve image event boxes by index.
    • Refactored image save and copy actions to use igtk_dialog_run for dialog execution, enabling better testability.
  • Build:
    • Added a new build option config-debug to enable CONFIG_DEBUG for unit tests.
  • Tests:
    • Enhanced DialogPeer and Application tests to include scenarios for image event box retrieval and interaction.
    • Conditionally included test functions and configurations based on the CONFIG_DEBUG flag.

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

sourcery-ai bot commented Jul 2, 2024

Reviewer's Guide by Sourcery

This pull request introduces several changes to enhance the functionality and testability of the iptux application. The primary focus is on adding support for double-clicking images, improving the debug configuration, and refactoring some existing functions for better clarity and maintainability.

File-Level Changes

Files Changes
src/iptux/UiHelper.cpp
src/iptux/UiHelper.h
Refactored and organized functions, added conditional compilation for debug configuration, and introduced igtk_dialog_run function.
src/iptux/DialogBase.cpp
src/iptux/DialogBase.h
Added chatHistoryGetImageEventBox function, refactored menu item creation, and renamed/refactored image handling functions.
src/meson.build
meson_options.txt
Added configuration and option for CONFIG_DEBUG to support unit tests.
src/iptux/DialogPeerTest.cpp
src/iptux/ApplicationTest.cpp
src/iptux/DataSettingsTest.cpp
Included TestConfig.h and wrapped tests with CONFIG_DEBUG conditional compilation.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • 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.

@lidaobing lidaobing marked this pull request as draft July 2, 2024 03:41
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: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

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.

static bool pop_disabled = false;
static atomic_bool open_url_enabled(true);
static gint igtk_dialog_run_return_val = 0;
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): Consider thread safety for igtk_dialog_run_return_val.

Since igtk_dialog_run_return_val is a global variable, it might be accessed by multiple threads simultaneously. Consider using an atomic type or adding synchronization mechanisms to ensure thread safety.

Comment on lines +24 to +28
enum {
igtk_dialog_run_return_val = 0,
pop_disabled = 0,
open_url_enabled = 1,
};
Copy link

Choose a reason for hiding this comment

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

suggestion: Avoid using enum for non-enumeration constants.

Using an enum to define constants like igtk_dialog_run_return_val, pop_disabled, and open_url_enabled can be misleading since enums are typically used for related sets of constants. Consider using const or constexpr instead.

Suggested change
enum {
igtk_dialog_run_return_val = 0,
pop_disabled = 0,
open_url_enabled = 1,
};
static const gint igtk_dialog_run_return_val = 0;
static const gint pop_disabled = 0;
static const gint open_url_enabled = 1;

}
}

GtkEventBox* DialogBase::chatHistoryGetImageEventBox(int idx) {
Copy link

Choose a reason for hiding this comment

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

issue: Check for negative index values.

Consider adding a check to ensure that the idx parameter is non-negative. Negative values could lead to unexpected behavior.

@@ -880,7 +897,7 @@ void DialogBase::OnChatHistoryInsertChildAnchor(DialogBase* self,
gtk_widget_show_all(event_box);
}

void DialogBase::OnSaveImage(DialogBase* self) {
void DialogBase::onSaveImage(void*, void*, DialogBase* 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 parameters for clarity.

The parameters 'void*, void*' in the onSaveImage and onCopyImage functions are not descriptive. Consider renaming them to provide more context about their purpose.

*/
void pop_disable();
void _ForTestToggleOpenUrl(bool enable);
void setIgtkDialogRunReturnVal(gint val);
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): Consider making setIgtkDialogRunReturnVal thread-safe.

Since setIgtkDialogRunReturnVal modifies a global variable, it should be made thread-safe to avoid race conditions.

'config-debug',
type: 'feature',
value: 'auto',
description: 'enable CONFIG_DEBUG, some unittests need this flag',
Copy link

Choose a reason for hiding this comment

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

suggestion (documentation): Change 'unittests' to 'unit tests' for clarity.

Consider changing 'unittests' to 'unit tests' to improve readability and adhere to common terminology.

Suggested change
description: 'enable CONFIG_DEBUG, some unittests need this flag',
description: 'enable CONFIG_DEBUG, some unit tests need this flag',

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 64.28571% with 10 lines in your changes missing coverage. Please review.

Project coverage is 52.44%. Comparing base (147c087) to head (34f010f).

Files Patch % Lines
src/iptux/UiHelper.cpp 46.15% 7 Missing ⚠️
src/iptux/DialogBase.cpp 76.92% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #617      +/-   ##
==========================================
+ Coverage   52.43%   52.44%   +0.01%     
==========================================
  Files          64       64              
  Lines        8533     8550      +17     
==========================================
+ Hits         4474     4484      +10     
- Misses       4059     4066       +7     

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

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.

double click image in chat history should open image
1 participant