commit 849d2217465d75aab338c2318ee7c9fa6002b341
parent fdc4bd531cf10e88b140b509d4998b76ec8c077a
Author: Oliver Lowe <o@olowe.co>
Date: Fri, 5 Sep 2025 18:24:52 +1000
Delete more single use globals
Diffstat:
7 files changed, 36 insertions(+), 54 deletions(-)
diff --git a/src/common/defs.h b/src/common/defs.h
@@ -46,10 +46,7 @@
#define ACTIONS_RC "actionsrc"
#define COMMAND_HISTORY "command_history"
-#define DEFAULT_SIGNATURE ".signature"
-#define DEFAULT_INC_PATH "/usr/bin/mh/inc"
-#define DEFAULT_SENDMAIL_CMD "/usr/sbin/sendmail -t -i"
#define DEFAULT_BROWSER_CMD "firefox '%s'"
#define DEFAULT_EDITOR_CMD "gedit '%s'"
@@ -62,15 +59,11 @@
#define FOLDER_SPACING 4
#define COLOR_DIM ((double)35000 / 65535)
#define UI_REFRESH_INTERVAL 50000 /* usec */
-#define PROGRESS_UPDATE_INTERVAL 200 /* msec */
-#define SESSION_TIMEOUT_INTERVAL 60 /* sec */
-#define MAX_HISTORY_SIZE 32
#define HSPACING_NARROW 4
#define VSPACING 10
#define VSPACING_NARROW 4
#define VSPACING_NARROW_2 2
#define VBOX_BORDER 8
-#define DEFAULT_ENTRY_WIDTH 80
#define DEFAULT_PIXMAP_THEME "INTERNAL_DEFAULT"
diff --git a/src/common/utils.c b/src/common/utils.c
@@ -749,12 +749,13 @@ GList *add_history(GList *list, const gchar *str)
cm_return_val_if_fail(str != NULL, list);
+ uint maxhist = 32;
old = g_list_find_custom(list, (gpointer)str, (GCompareFunc)g_strcmp0);
if (old) {
oldstr = old->data;
list = g_list_remove(list, old->data);
g_free(oldstr);
- } else if (g_list_length(list) >= MAX_HISTORY_SIZE) {
+ } else if (g_list_length(list) >= maxhist) {
GList *last;
last = g_list_last(list);
diff --git a/src/folder.c b/src/folder.c
@@ -3825,29 +3825,28 @@ void folder_item_discard_cache(FolderItem *item)
}
-static gchar *folder_item_get_cache_file(FolderItem *item)
+static char *folder_item_get_cache_file(FolderItem *item)
{
- gchar *path;
- gchar *file;
- gchar *old_file;
-
- cm_return_val_if_fail(item != NULL, NULL);
+ if (!item)
+ return NULL;
- path = folder_item_get_path(item);
- cm_return_val_if_fail(path != NULL, NULL);
+ char *path = folder_item_get_path(item);
+ if (!path)
+ return NULL;
if (!is_dir_exist(path))
make_dir_hier(path);
- file = g_strconcat(path, "/.claws_cache", NULL);
- g_free(path);
- return file;
+ char file[PATH_MAX];
+ strlcpy(file, path, sizeof(file));
+ strlcat(file, "/.claws_cache", sizeof(file));
+ free(path);
+ return strdup(file);
}
static gchar *folder_item_get_mark_file(FolderItem *item)
{
gchar *path;
gchar *file;
- gchar *old_file;
cm_return_val_if_fail(item != NULL, NULL);
cm_return_val_if_fail(item->path != NULL, NULL);
diff --git a/src/imap.c b/src/imap.c
@@ -1103,7 +1103,8 @@ new_conn:
* A better solution than sending a NOOP every time would be
* for every command to be prepared to retry until it is
* successfully sent. -- mbp */
- if ((time(NULL) - SESSION(session)->last_access_time > SESSION_TIMEOUT_INTERVAL) || session->cancelled) {
+ uint timeout = 60; // seconds
+ if ((time(NULL) - SESSION(session)->last_access_time > timeout) || session->cancelled) {
/* verify that the session is still alive */
r = imap_cmd_noop(session);
@@ -2522,35 +2523,28 @@ static FolderItem *imap_create_special_folder(Folder *folder,
return new_item;
}
-static gchar *imap_item_get_path(Folder *folder, FolderItem *item)
+char *imap_item_get_path(Folder *folder, FolderItem *item)
{
- gchar *folder_path, *path;
- gchar *item_path = NULL;
-
g_return_val_if_fail(folder != NULL, NULL);
g_return_val_if_fail(folder->account != NULL, NULL);
g_return_val_if_fail(item != NULL, NULL);
- folder_path = prefs_account_cache_dir(folder->account->recv_server, folder->account->userid);
- item_path = g_strdup(item->path);
- if (g_path_is_absolute(folder_path)) {
- if (item_path)
- path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
- item_path, NULL);
- else
- path = g_strdup(folder_path);
- } else {
- if (item_path)
- path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
- folder_path, G_DIR_SEPARATOR_S,
- item_path, NULL);
+ char path[PATH_MAX];
+
+ char *dir = prefs_account_cache_dir(folder->account->recv_server, folder->account->userid);
+ if (g_path_is_absolute(dir)) {
+ if (item->path)
+ snprintf(path, sizeof(path), "%s/%s", dir, item->path);
else
- path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
- folder_path, NULL);
+ strlcpy(path, dir, sizeof(path));
+ } else {
+ if (item->path)
+ snprintf(path, sizeof(path), "%s/%s/%s", get_home_dir(), dir, item->path);
+ else
+ snprintf(path, sizeof(path), "%s/%s", get_home_dir(), dir);
}
- g_free(folder_path);
- g_free(item_path);
- return path;
+ free(dir);
+ return strdup(path);
}
static FolderItem *imap_create_folder(Folder *folder, FolderItem *parent,
diff --git a/src/inc.c b/src/inc.c
@@ -970,7 +970,8 @@ static void inc_progress_dialog_update_periodic(IncProgressDialog *inc_dialog,
tv_result += G_USEC_PER_SEC;
}
- if (tv_result > PROGRESS_UPDATE_INTERVAL) {
+ uint progress_update_interval = 200; // milliseconds
+ if (tv_result > progress_update_interval) {
inc_progress_dialog_update(inc_dialog, inc_session);
tv_cur = g_date_time_add(inc_dialog->progress_tv, tv_result);
g_date_time_unref(inc_dialog->progress_tv);
diff --git a/src/prefs_account.c b/src/prefs_account.c
@@ -413,7 +413,7 @@ static PrefParam basic_param[] = {
{"use_mail_command", "FALSE", &tmp_ac_prefs.use_mail_command, P_BOOL,
&basic_page.mailcmd_checkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
- {"mail_command", DEFAULT_SENDMAIL_CMD, &tmp_ac_prefs.mail_command, P_STRING,
+ {"mail_command", "/usr/sbin/sendmail -t -i", &tmp_ac_prefs.mail_command, P_STRING,
&basic_page.mailcmd_entry, prefs_set_data_from_entry, prefs_set_entry},
{"user_id", NULL, &tmp_ac_prefs.userid, P_STRING,
@@ -562,7 +562,7 @@ static PrefParam compose_param[] = {
&compose_page.sigfile_radiobtn,
prefs_account_enum_set_data_from_radiobtn,
prefs_account_enum_set_radiobtn},
- {"signature_path", "~" G_DIR_SEPARATOR_S DEFAULT_SIGNATURE,
+ {"signature_path", "~/.signature",
&tmp_ac_prefs.sig_path, P_STRING, &compose_page.entry_sigpath,
prefs_set_data_from_entry, prefs_set_entry},
@@ -896,7 +896,6 @@ static void basic_create_widget_func(PrefsPage * _page,
acname_entry = gtk_entry_new ();
gtk_widget_show (acname_entry);
- gtk_widget_set_size_request (acname_entry, DEFAULT_ENTRY_WIDTH, -1);
gtk_box_pack_start (GTK_BOX (hbox), acname_entry, TRUE, TRUE, 0);
default_checkbtn = gtk_check_button_new_with_label (_("Set as default"));
@@ -1043,14 +1042,12 @@ static void basic_create_widget_func(PrefsPage * _page,
uid_entry = gtk_entry_new ();
gtk_widget_show (uid_entry);
- gtk_widget_set_size_request (uid_entry, DEFAULT_ENTRY_WIDTH, -1);
gtk_grid_attach(GTK_GRID(serv_table), uid_entry, 1, 7, 2, 1);
gtk_widget_set_hexpand(uid_entry, TRUE);
gtk_widget_set_halign(uid_entry, GTK_ALIGN_FILL);
pass_entry = gtk_entry_new ();
gtk_widget_show (pass_entry);
- gtk_widget_set_size_request (pass_entry, DEFAULT_ENTRY_WIDTH, -1);
gtk_grid_attach(GTK_GRID(serv_table), pass_entry, 1, 8, 2, 1);
gtk_widget_set_hexpand(pass_entry, TRUE);
gtk_widget_set_halign(pass_entry, GTK_ALIGN_FILL);
@@ -1623,7 +1620,6 @@ static void send_create_widget_func(PrefsPage * _page,
smtp_uid_entry = gtk_entry_new ();
gtk_widget_show (smtp_uid_entry);
- gtk_widget_set_size_request (smtp_uid_entry, DEFAULT_ENTRY_WIDTH, -1);
gtk_box_pack_start (GTK_BOX (hbox), smtp_uid_entry, TRUE, TRUE, 0);
label = gtk_label_new (_("Password"));
@@ -1632,7 +1628,6 @@ static void send_create_widget_func(PrefsPage * _page,
smtp_pass_entry = gtk_entry_new ();
gtk_widget_show (smtp_pass_entry);
- gtk_widget_set_size_request (smtp_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
gtk_box_pack_start (GTK_BOX (hbox), smtp_pass_entry, TRUE, TRUE, 0);
gtk_entry_set_visibility (GTK_ENTRY (smtp_pass_entry), FALSE);
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(smtp_pass_entry),
@@ -1886,14 +1881,13 @@ static void oauth2_create_widget_func(PrefsPage * _page,
gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
//gtk_widget_set_size_request (hbox, -1, 50);
- label = gtk_label_new (_("Authorization code"));
+ label = gtk_label_new ("Authorization code");
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
oauth2_authcode_entry = gtk_entry_new ();
gtk_widget_show (oauth2_authcode_entry);
gtk_widget_set_margin_bottom(oauth2_authcode_entry, 8);
- //gtk_widget_set_size_request (oauth2_authcode_entry, DEFAULT_ENTRY_WIDTH, -1);
gtk_widget_set_tooltip_text(oauth2_authcode_entry,
_("Paste complete URL from browser or the provided authorization token"));
gtk_box_pack_start (GTK_BOX (hbox), oauth2_authcode_entry, TRUE, TRUE, 0);
diff --git a/src/prefs_common.c b/src/prefs_common.c
@@ -79,7 +79,7 @@ static PrefParam param[] = {
/* Receive */
{"use_ext_inc", "FALSE", &prefs_common.use_extinc, P_BOOL,
NULL, NULL, NULL},
- {"ext_inc_path", DEFAULT_INC_PATH, &prefs_common.extinc_cmd, P_STRING,
+ {"ext_inc_path", "/usr/bin/mh/inc", &prefs_common.extinc_cmd, P_STRING,
NULL, NULL, NULL},
{"autochk_newmail", "FALSE", &prefs_common.autochk_newmail, P_BOOL,