-
Notifications
You must be signed in to change notification settings - Fork 130
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
63a5ce0
c42e9df
0e7ef5a
7491de0
23b2950
7b40efd
ef8c854
8e4a6ab
34f010f
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#ifndef IPTUX_TEST_CONFIG_H | ||
#define IPTUX_TEST_CONFIG_H | ||
|
||
#include "config.h" | ||
#mesondefine CURRENT_SOURCE_PATH | ||
|
||
#endif // IPTUX_TEST_CONFIG_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,25 @@ | |
gtk_text_buffer_delete_mark(buffer, mark); | ||
} | ||
|
||
typedef struct _GetImageCbkCtx { | ||
int idx; | ||
GtkEventBox* res; | ||
} GetImageCbkCtx; | ||
|
||
static void GetImageCbk(GtkWidget* widget, GetImageCbkCtx* ctx) { | ||
if (GTK_IS_EVENT_BOX(widget) && ctx->idx-- == 0) { | ||
ctx->res = GTK_EVENT_BOX(widget); | ||
} | ||
} | ||
|
||
GtkEventBox* DialogBase::chatHistoryGetImageEventBox(int idx) { | ||
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. 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. |
||
GetImageCbkCtx ctx = {idx, nullptr}; | ||
|
||
gtk_container_foreach(GTK_CONTAINER(chat_history_widget), | ||
(GtkCallback)GetImageCbk, &ctx); | ||
return ctx.res; | ||
} | ||
|
||
/** | ||
* 窗口打开情况下,新消息来到以后的接口 | ||
*/ | ||
|
@@ -818,14 +837,12 @@ | |
m_imagePopupMenu = GTK_MENU(gtk_menu_new()); | ||
|
||
GtkWidget* menu_item = gtk_menu_item_new_with_label(_("Save Image")); | ||
gtk_actionable_set_action_name(GTK_ACTIONABLE(menu_item), "win.save_image"); | ||
gtk_menu_shell_append(GTK_MENU_SHELL(m_imagePopupMenu), menu_item); | ||
g_signal_connect_swapped(menu_item, "activate", | ||
G_CALLBACK(DialogBase::OnSaveImage), this); | ||
|
||
menu_item = gtk_menu_item_new_with_label(_("Copy Image")); | ||
gtk_actionable_set_action_name(GTK_ACTIONABLE(menu_item), "win.copy_image"); | ||
gtk_menu_shell_append(GTK_MENU_SHELL(m_imagePopupMenu), menu_item); | ||
g_signal_connect_swapped(menu_item, "activate", | ||
G_CALLBACK(DialogBase::OnCopyImage), this); | ||
|
||
gtk_menu_attach_to_widget(m_imagePopupMenu, GTK_WIDGET(getWindow()), NULL); | ||
} | ||
|
@@ -880,7 +897,7 @@ | |
gtk_widget_show_all(event_box); | ||
} | ||
|
||
void DialogBase::OnSaveImage(DialogBase* self) { | ||
void DialogBase::onSaveImage(void*, void*, DialogBase* self) { | ||
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. 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. |
||
GtkImage* image = self->m_activeImage; | ||
g_return_if_fail(!!image); | ||
|
||
|
@@ -899,7 +916,7 @@ | |
TRUE); | ||
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "image.png"); | ||
|
||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { | ||
if (igtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { | ||
char* save_path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | ||
|
||
GError* error = NULL; | ||
|
@@ -920,7 +937,7 @@ | |
gtk_widget_destroy(dialog); | ||
} | ||
|
||
void DialogBase::OnCopyImage(DialogBase* self) { | ||
void DialogBase::onCopyImage(void*, void*, DialogBase* self) { | ||
GtkImage* image = self->m_activeImage; | ||
g_return_if_fail(!!image); | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,8 +16,17 @@ | |||||||||||||||||
|
||||||||||||||||||
namespace iptux { | ||||||||||||||||||
|
||||||||||||||||||
static atomic_bool open_url_enabled(true); | ||||||||||||||||||
#if CONFIG_DEBUG | ||||||||||||||||||
static bool pop_disabled = false; | ||||||||||||||||||
static atomic_bool open_url_enabled(true); | ||||||||||||||||||
static gint igtk_dialog_run_return_val = 0; | ||||||||||||||||||
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. 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. |
||||||||||||||||||
#else | ||||||||||||||||||
enum { | ||||||||||||||||||
igtk_dialog_run_return_val = 0, | ||||||||||||||||||
pop_disabled = 0, | ||||||||||||||||||
open_url_enabled = 1, | ||||||||||||||||||
}; | ||||||||||||||||||
Comment on lines
+24
to
+28
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. 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
|
||||||||||||||||||
#endif | ||||||||||||||||||
|
||||||||||||||||||
void iptux_open_path(const char* path) { | ||||||||||||||||||
g_return_if_fail(!!path); | ||||||||||||||||||
|
@@ -42,10 +51,6 @@ | |||||||||||||||||
g_free(uri); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
void _ForTestToggleOpenUrl(bool enable) { | ||||||||||||||||||
open_url_enabled = enable; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* 打开URL. | ||||||||||||||||||
* @param url url | ||||||||||||||||||
|
@@ -156,10 +161,6 @@ | |||||||||||||||||
return filelist; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
void pop_disable() { | ||||||||||||||||||
pop_disabled = true; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* 弹出消息提示. | ||||||||||||||||||
* @param parent parent window | ||||||||||||||||||
|
@@ -399,4 +400,24 @@ | |||||||||||||||||
return res; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
gint igtk_dialog_run(GtkDialog* dialog) { | ||||||||||||||||||
if (igtk_dialog_run_return_val) { | ||||||||||||||||||
return igtk_dialog_run_return_val; | ||||||||||||||||||
} | ||||||||||||||||||
return gtk_dialog_run(dialog); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
#if CONFIG_DEBUG | ||||||||||||||||||
void pop_disable() { | ||||||||||||||||||
pop_disabled = true; | ||||||||||||||||||
} | ||||||||||||||||||
void _ForTestToggleOpenUrl(bool enable) { | ||||||||||||||||||
open_url_enabled = enable; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
void setIgtkDialogRunReturnVal(gint val) { | ||||||||||||||||||
igtk_dialog_run_return_val = val; | ||||||||||||||||||
} | ||||||||||||||||||
#endif | ||||||||||||||||||
|
||||||||||||||||||
} // namespace iptux |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,17 +38,12 @@ GSList* selection_data_get_path(GtkSelectionData* data); | |
*/ | ||
GtkImage* igtk_image_new_with_size(const char* filename, int width, int height); | ||
std::string igtk_text_buffer_get_text(GtkTextBuffer* buffer); | ||
gint igtk_dialog_run(GtkDialog* dialog); | ||
|
||
/** | ||
* @brief only used for test, after call this, pop_info, pop_warning, | ||
* and iptux_open_url will only print log | ||
*/ | ||
void pop_disable(); | ||
void pop_info(GtkWidget* parent, const gchar* format, ...) G_GNUC_PRINTF(2, 3); | ||
void pop_warning(GtkWidget* parent, const gchar* format, ...) | ||
G_GNUC_PRINTF(2, 3); | ||
void iptux_open_url(const char* url); | ||
void _ForTestToggleOpenUrl(bool enable); | ||
|
||
std::string ipv4_get_lan_name(in_addr ipv4); | ||
|
||
|
@@ -107,5 +102,15 @@ std::string TimeToStr(time_t t); | |
/* only used for test */ | ||
std::string TimeToStr_(time_t t, time_t now); | ||
|
||
#if CONFIG_DEBUG | ||
/** | ||
* @brief only used for test, after call this, pop_info, pop_warning, | ||
* and iptux_open_url will only print log | ||
*/ | ||
void pop_disable(); | ||
void _ForTestToggleOpenUrl(bool enable); | ||
void setIgtkDialogRunReturnVal(gint val); | ||
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. issue (bug_risk): Consider making setIgtkDialogRunReturnVal thread-safe. Since setIgtkDialogRunReturnVal modifies a global variable, it should be made thread-safe to avoid race conditions. |
||
#endif | ||
|
||
} // namespace iptux | ||
#endif // IPTUX_UIHELPER_H |
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.
suggestion (documentation): Change 'unittests' to 'unit tests' for clarity.
Consider changing 'unittests' to 'unit tests' to improve readability and adhere to common terminology.