commit - 77c35669c9ee41a65effd7edd82224fad9db5f6c
commit + f4fa939c1d17b04ae803f6b535005ba88f46071c
blob - 7867db3b7510bb8a48aa3a9a3fe66b5a24e0d172
blob + 5cdb3fa303aa441481fc3e419b1d70a4d5cc944d
--- src/common/defs.h
+++ src/common/defs.h
#define RC_DIR ".claws-mail"
#define COMMON_RC "clawsrc"
#define ACCOUNT_RC "accountrc"
-#define OAUTH2_RC "oauth2rc"
#define DISPLAY_HEADER_RC "dispheaderrc"
#define FOLDERITEM_RC "folderitemrc"
#define MENU_RC "menurc"
#define CACHE_VERSION 24
#define MARK_VERSION 2
-#define ACTIONS_RC "actionsrc"
#define COMMAND_HISTORY "command_history"
#define DEFAULT_BROWSER_CMD "firefox '%s'"
#define DEFAULT_PIXMAP_THEME "INTERNAL_DEFAULT"
-#define AVATAR_FACE 2
-
#endif /* __DEFS_H__ */
blob - e805e85ebb84a3a47032fb0e819cc85cf299cef9
blob + 2b3b17682eb88014b716bdf5fc96fa8f7cca2743
--- src/common/prefs.c
+++ src/common/prefs.c
snprintf(path, sizeof(path), "%s/%s", get_rc_dir(), rcfile);
return prefs_is_readonly(path);
}
-
-/*!
- *\brief Selects current section in preferences file
- * Creates section if file is written
- *
- *\param pfile Preferences file struct
- *
- *\return 0 on success, -1 on failure and pfile is freed.
- */
-gint prefs_set_block_label(PrefFile *pfile, const gchar *label)
-{
- gchar *block_label;
- gchar buf[BUFFSIZE];
-
- block_label = g_strdup_printf("[%s]", label);
- if (!pfile->writing) {
- while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
- gint val;
-
- val = strncmp(buf, block_label, strlen(block_label));
- if (val == 0) {
- debug_print("Found %s\n", block_label);
- break;
- }
- }
- } else {
- if ((pfile->orig_fp = g_fopen(pfile->path, "rb")) != NULL) {
- gboolean block_matched = FALSE;
-
- while (fgets(buf, sizeof(buf), pfile->orig_fp) != NULL) {
- gint val;
-
- val = strncmp(buf, block_label, strlen(block_label));
- if (val == 0) {
- debug_print("Found %s\n", block_label);
- block_matched = TRUE;
- break;
- } else {
- if (fputs(buf, pfile->fp) == EOF) {
- g_warning("failed to write configuration to file");
- prefs_file_close_revert(pfile);
- g_free(block_label);
-
- return -1;
- }
- }
- }
-
- if (!block_matched) {
- fclose(pfile->orig_fp);
- pfile->orig_fp = NULL;
- }
- }
-
- if (fputs(block_label, pfile->fp) == EOF ||
- fputc('\n', pfile->fp) == EOF) {
- g_warning("failed to write configuration to file");
- prefs_file_close_revert(pfile);
- g_free(block_label);
-
- return -1;
- }
- }
-
- g_free(block_label);
-
- return 0;
-}
blob - 129891cbaf3d42b37eb9e4fc426540222b2a5b6c
blob + 006626015603e63f8f30d1adf53e289404cd1918
--- src/common/prefs.h
+++ src/common/prefs.h
gint prefs_file_close (PrefFile *pfile);
gint prefs_file_close_revert (PrefFile *pfile);
gboolean prefs_rc_is_readonly (const gchar *rcfile);
-gint prefs_set_block_label (PrefFile *pfile,
- const gchar *block_label);
#endif
blob - 634c3df2e60b96658314aa3b9f138c0659dd5171
blob + 4fc6adc284c496e71eb304a82a0700320fa2f33e
--- src/common/socket.c
+++ src/common/socket.c
#define SOCKET_IS_VALID(s) (s != -1)
-gint fd_connect_inet(gushort port)
-{
- gint sock;
- struct sockaddr_in addr;
-
- sock = socket(AF_INET, SOCK_STREAM, 0);
- if (!SOCKET_IS_VALID(sock)) {
- perror("fd_connect_inet(): socket");
- return -1;
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-
- if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- close(sock);
- return -1;
- }
-
- return sock;
-}
-
-gint fd_open_inet(gushort port)
-{
- gint sock;
- struct sockaddr_in addr;
- gint val;
-
- sock = socket(AF_INET, SOCK_STREAM, 0);
- if (!SOCKET_IS_VALID(sock)) {
- perror("fd_open_inet(): socket");
- return -1;
- }
-
- val = 1;
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&val,
- sizeof(val)) < 0) {
- perror("setsockopt");
- close(sock);
- return -1;
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-
- if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- perror("bind");
- close(sock);
- return -1;
- }
-
- if (listen(sock, 1) < 0) {
- perror("listen");
- close(sock);
- return -1;
- }
-
- return sock;
-}
-
gint fd_connect_unix(const gchar *path)
{
#ifdef G_OS_UNIX
blob - c2a52227fed84adffd26b8017dd402d2760b36e8
blob + c2485430bfcdf1b6a9cf450a1e8194b3834da2da
--- src/common/socket.h
+++ src/common/socket.h
gint fd_open_unix (const gchar *path);
gint fd_accept (gint sock);
-gint fd_connect_inet(gushort port);
-gint fd_open_inet(gushort port);
-
gint fd_write (gint sock, const gchar *buf, gint len);
gint fd_write_all (gint sock, const gchar *buf, gint len);
gint fd_gets (gint sock, gchar *buf, gint len);
-gint fd_close (gint sock);
#endif /* __SOCKET_H__ */
blob - dbcb4b1b451fa139e7586d611da8ac698151f653
blob + f16699c840c04168c2bd33be987fbe6c33ef5b13
--- src/common/utils.c
+++ src/common/utils.c
return h;
}
-gint to_number(const gchar *nstr)
-{
- register const gchar *p;
-
- if (*nstr == '\0') return -1;
-
- for (p = nstr; *p != '\0'; p++)
- if (!g_ascii_isdigit(*p)) return -1;
-
- return atoi(nstr);
-}
-
/* convert integer into string,
nstr must be not lower than 11 characters length */
gchar *itos_buf(gchar *nstr, gint n)
}
while ((dir_name = g_dir_read_name(dp)) != NULL) {
- file_no = to_number(dir_name);
+ file_no = atoi(dir_name);
if (file_no > 0 && first <= file_no && file_no <= last) {
if (is_dir_exist(dir_name)) {
gchar *dot_file = g_strdup_printf(".%s", dir_name);
}
while ((dir_name = g_dir_read_name(dp)) != NULL) {
- file_no = to_number(dir_name);
+ file_no = atoi(dir_name);
if (is_dir_exist(dir_name))
continue;
if (file_no > 0 && g_hash_table_lookup(wanted_files, GINT_TO_POINTER(file_no)) == NULL) {
blob - 8604b46219b1585be292d6b897d8c559518322f3
blob + 50637dda11805c03019c5998ed7f932edb4891c9
--- src/common/utils.h
+++ src/common/utils.h
guint str_case_hash (gconstpointer key);
/* number-string conversion */
-gint to_number (const gchar *nstr);
gchar *itos_buf (gchar *nstr,
gint n);
gchar *itos (gint n);
blob - 18771428ffd4a769a492b41e72020fdccd777f6a
blob + 6cc515ed2f05b31eff2caa94c4ad97e089afdbcb
--- src/common/xmlprops.c
+++ src/common/xmlprops.c
#include <string.h>
#include <stdlib.h>
+#include "file-utils.h"
+#include "mgutils.h"
#include "prefs.h"
+#include "utils.h"
#include "xml.h"
-#include "mgutils.h"
#include "xmlprops.h"
-#include "utils.h"
-#include "file-utils.h"
/* Element tag names */
#define XMLS_ELTAG_PROP_LIST "property-list"
#define XMLS_ATTAG_NAME "name"
#define XMLS_ATTAG_VALUE "value"
-static void xmlprops_clear ( XmlProperty *props );
-
typedef struct _HashLoopData {
FILE *fp;
int error;
return props;
}
-/*
- * Properties - file path.
- */
-void xmlprops_set_path( XmlProperty *props, const gchar *value ) {
- cm_return_if_fail( props != NULL );
- props->path = mgu_replace_string( props->path, value );
-}
-
-/*
- * Free hash table visitor function.
- */
-static gint xmlprops_free_entry_vis( gpointer key, gpointer value, gpointer data ) {
- g_free( key );
- g_free( value );
- key = NULL;
- value = NULL;
- return TRUE;
-}
-
-/*
- * Clear all properties.
- * Enter: props Property object.
- */
-static void xmlprops_clear( XmlProperty *props ) {
- cm_return_if_fail( props != NULL );
- g_hash_table_foreach_remove(
- props->propertyTable, xmlprops_free_entry_vis, NULL );
-}
-
-/*
- * Free props.
- * Enter: props Property object.
- */
-void xmlprops_free( XmlProperty *props ) {
- cm_return_if_fail( props != NULL );
-
- /* Clear property table */
- xmlprops_clear( props );
- g_hash_table_destroy( props->propertyTable );
-
- /* Free up internal objects */
- g_free( props->path );
- g_free( props->encoding );
-
- props->path = NULL;
- props->encoding = NULL;
- props->propertyTable = NULL;
- props->retVal = 0;
-
- g_free( props );
-}
-
static int xmlprops_write_elem_s( FILE *fp, gint lvl, gchar *name ) {
gint i;
for( i = 0; i < lvl; i++ ) {
blob - b987803d4ade1a298b7b1f6566b553c7f6da84aa
blob + d9b0ba39573f308469f8d143691fead16152c553
--- src/common/xmlprops.h
+++ src/common/xmlprops.h
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ *
*/
/*
/* Function prototypes */
XmlProperty *xmlprops_create ( void );
-void xmlprops_free ( XmlProperty *props );
-void xmlprops_set_path ( XmlProperty *props, const gchar *value );
-gint xmlprops_load_file ( XmlProperty *props );
gint xmlprops_save_file ( XmlProperty *props );
void xmlprops_set_property ( XmlProperty *props, const gchar *name,
const gchar *value );
blob - 90fa1cfcc5129d889893201df64bf8fd6aaeb89f
blob + 82fb4949fe25525feed4df6d56815b589fb807f2
--- src/gtk/gtkcmctree.c
+++ src/gtk/gtkcmctree.c
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
-#include "gtkcmctree.h"
+
#include "claws-marshal.h"
+#include "gtkcmctree.h"
+#include "gtkutils.h"
+#include "prefs_common.h"
#include "utils.h"
-#include "gtkutils.c"
#define PM_SIZE 8
#define TAB_SIZE (PM_SIZE + 6)
blob - 6fb7191bb6c17bcd4bd15eeadd74ad135d4dce8a
blob + 47cf181ea76416503d8c7c175f7ce55b59dedb34
--- src/gtk/gtkutils.c
+++ src/gtk/gtkutils.c
return (h*4 + m/15);
}
-GtkWidget *gtkut_time_select_combo_new()
-{
- GtkWidget *combo = gtk_combo_box_text_new_with_entry();
- GList *times = get_predefined_times();
-
- gtk_combo_box_set_active(GTK_COMBO_BOX(combo), -1);
- combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(combo), times);
-
- list_free_strings_full(times);
-
- return combo;
-}
-
-
-void gtkut_time_select_select_by_time(GtkComboBox *combo, int hour, int minute)
-{
- gchar *time_text = g_strdup_printf("%02d:%02d", hour, minute);
- gint num = get_list_item_num(hour, minute);
-
- if (num > -1)
- combobox_select_by_text(combo, time_text);
- else
- gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo))), time_text);
-
- g_free(time_text);
-}
-
static void get_time_from_combo(GtkComboBox *combo, int *h, int *m)
{
gchar *tmp;
g_free(tmp);
}
-gboolean gtkut_time_select_get_time(GtkComboBox *combo, int *hour, int *minute)
-{
- const gchar *value = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo))));
-
- if (value == NULL || strlen(value) != 5)
- return FALSE;
-
- if (hour == NULL || minute == NULL)
- return FALSE;
-
- get_time_from_combo(combo, hour, minute);
-
- if (*hour < 0 || *hour > 23)
- return FALSE;
- if (*minute < 0 || *minute > 59)
- return FALSE;
-
- return TRUE;
-}
-
#define RGBA_ELEMENT_TO_BYTE(x) (int)((gdouble)x * 255)
gchar *gtkut_gdk_rgba_to_string(GdkRGBA *rgba)
{
blob - 5bc9ff44ffa5aad6b08a738b78800ed6f20d3cec
blob + 66a70f2a745d207117a2ea576a9d4fae310d0d22
--- src/gtk/gtkutils.h
+++ src/gtk/gtkutils.h
GtkUIManager *gtkut_create_ui_manager(void);
GtkUIManager *gtkut_ui_manager(void);
-GtkWidget *gtkut_time_select_combo_new();
-void gtkut_time_select_select_by_time(GtkComboBox *combo, int hour, int minute);
-gboolean gtkut_time_select_get_time(GtkComboBox *combo, int *hour, int *minute);
-
typedef void (*ClawsIOFunc)(gpointer data, gint source, GIOCondition condition);
gint
claws_input_add (gint source,
blob - e93b916a962baafb05cec67a43c54fcb471a1afb
blob + 7bcd5382abb660b0ed07e823c16fc3f34b452241
--- src/imap.c
+++ src/imap.c
g_return_val_if_fail(parent != NULL, NULL);
g_return_val_if_fail(name != NULL, NULL);
- if (to_number(name) > 0) {
- gchar *cached_msg = imap_get_cached_filename(parent, to_number(name));
+ if (atoi(name) > 0) {
+ gchar *cached_msg = imap_get_cached_filename(parent, atoi(name));
if (is_file_exist(cached_msg)) {
if (unlink(cached_msg) != 0) {
g_free(cached_msg);
blob - ee669ce3c65fbede914f96ccdc99323646ee7eda
blob + be3f7314ca4eef338e1b11f2fb49ec9b90175ffe
--- src/main.c
+++ src/main.c
#include "prefs_message.h"
#include "prefs_receive.h"
#include "prefs_summaries.h"
-#include "prefs_themes.h"
#include "prefs_other.h"
#include "prefs_send.h"
#include "prefs_compose_writing.h"
folder_system_init();
prefs_common_read_config();
- prefs_themes_init();
prefs_ext_prog_init();
prefs_compose_writing_init();
prefs_summaries_init();
prefs_toolbar_done();
addressbook_destroy();
- prefs_themes_done();
prefs_ext_prog_done();
prefs_compose_writing_done();
prefs_summaries_done();
blob - ac957d612079e8b81315b2a4ccb6a2d4d429abd4
blob + 2d3b050c3f8d3cacbda3ba6544dc63cbf8c9d17e
--- src/mh.c
+++ src/mh.c
while ((d = g_dir_read_name(dp)) != NULL) {
fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, d, NULL);
- if ((num = to_number(d)) > 0 &&
+ if ((num = atoi(d)) > 0 &&
g_file_test(fullpath, G_FILE_TEST_IS_REGULAR)) {
if (max < num)
max = num;
g_free(path);
while ((d = g_dir_read_name(dp)) != NULL) {
- if ((num = to_number(d)) > 0) {
+ if ((num = atoi(d)) > 0) {
*list = g_slist_prepend(*list, GINT_TO_POINTER(num));
nummsgs++;
}
g_free(real_name);
g_free(path);
- if (to_number(name) > 0) {
- MsgInfo *info = folder_item_get_msginfo(parent, to_number(name));
+ if (atoi(name) > 0) {
+ MsgInfo *info = folder_item_get_msginfo(parent, atoi(name));
if (info != NULL) {
gboolean ok = mh_renumber_msg(info);
procmsg_msginfo_free(&info);
blob - bcfc5342ec9377e2884066f90319527c60316722
blob + c10a90c4c1b81c59764449f7a2bb6dd3a7bc5e4e
--- src/prefs_actions.c
+++ src/prefs_actions.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <err.h>
#include <errno.h>
#include "prefs_gtk.h"
void prefs_actions_read_config(void)
{
- gchar *rcpath;
FILE *fp;
gchar buf[PREFSBUFSIZE];
gchar *act;
- debug_print("Reading actions configurations...\n");
-
- rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL);
- if ((fp = g_fopen(rcpath, "rb")) == NULL) {
- if (ENOENT != errno) FILE_OP_ERROR(rcpath, "g_fopen");
- g_free(rcpath);
+ char rcpath[PATH_MAX];
+ strlcpy(rcpath, get_rc_dir(), sizeof(rcpath));
+ strlcat(rcpath, "/actionsrc", sizeof(rcpath));
+ if ((fp = fopen(rcpath, "r")) == NULL) {
+ warn("open %s", rcpath);
return;
}
- g_free(rcpath);
while (prefs_common.actions_list != NULL) {
act = (gchar *)prefs_common.actions_list->data;
void prefs_actions_write_config(void)
{
- gchar *rcpath;
PrefFile *pfile;
GSList *cur;
debug_print("Writing actions configuration...\n");
- rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL);
+ char rcpath[PATH_MAX];
+ strlcpy(rcpath, get_rc_dir(), sizeof(rcpath));
+ strlcat(rcpath, "/actionsrc", sizeof(rcpath));
if ((pfile= prefs_write_open(rcpath)) == NULL) {
- g_warning("failed to write configuration to file");
- g_free(rcpath);
+ warn("write actions configuration file %s", rcpath);
return;
}
FILE_OP_ERROR(rcpath, "fputs || fputc");
prefs_file_close_revert(pfile);
g_free(act);
- g_free(rcpath);
return;
}
g_free(act);
}
-
- g_free(rcpath);
-
- if (prefs_file_close(pfile) < 0) {
- g_warning("failed to write configuration to file");
- return;
- }
+ prefs_file_close(pfile);
}
static void prefs_actions_clear_list(GtkListStore *list_store)
blob - c95b48af5d97ecfb672fae8c3ea1bb2ea2fa134c
blob + 0f0c423db68172110af8c6c1710caaee89a4b6a3
--- src/prefs_common.c
+++ src/prefs_common.c
P_INT, NULL, NULL, NULL},
/* Other */
- {"uri_open_command", DEFAULT_BROWSER_CMD,
+ {"uri_open_command", "firefox '%s'",
&prefs_common.uri_cmd, P_STRING, NULL, NULL, NULL},
{"ext_editor_command", DEFAULT_EDITOR_CMD,
&prefs_common.ext_editor_cmd, P_STRING, NULL, NULL, NULL},
void prefs_common_write_config(void)
{
prefs_write_config(param, "Common", COMMON_RC);
-
- prefs_common_save_history(COMMAND_HISTORY, prefs_common.mime_open_cmd_history);
prefs_common_save_history(COMPOSE_SAVE_TO_HISTORY, prefs_common.compose_save_to_history);
}
blob - f57361f2c8351839755d96af61c9e02a3ed4c660
blob + 8bf7df40168360c1225a31dc1f0ae2aab2c33189
--- src/prefs_gtk.c
+++ src/prefs_gtk.c
gchar *clawsrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
gchar *folderitemrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FOLDERITEM_RC, NULL);
gchar *accountrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
- gchar *oauth2rc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, OAUTH2_RC, NULL);
if (whole_cache == NULL) {
whole_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free(clawsrc);
g_free(folderitemrc);
g_free(accountrc);
- g_free(oauth2rc);
return;
}
if (prefs_cache(clawsrc) < 0 ||
prefs_cache(folderitemrc) < 0 ||
- prefs_cache(accountrc) < 0 ||
- prefs_cache(oauth2rc) < 0)
+ prefs_cache(accountrc) < 0)
prefs_destroy_cache();
g_free(clawsrc);
g_free(folderitemrc);
g_free(accountrc);
- g_free(oauth2rc);
}
void prefs_destroy_cache(void)
blob - 0f9a71d1c27782d9da8b0618fcbb6d64ea32d462 (mode 644)
blob + /dev/null
--- src/prefs_themes.c
+++ /dev/null
-/*
- * Claws Mail -- a GTK based, lightweight, and fast e-mail client
- * Copyright (C) 2003-2023 the Claws Mail team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "defs.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-
-#include "utils.h"
-#include "codeconv.h"
-#include "prefs_common.h"
-#include "prefs_gtk.h"
-
-#include "gtk/gtkutils.h"
-#include "gtk/prefswindow.h"
-#include "gtk/filesel.h"
-#include "gtk/manage_window.h"
-
-#include "stock_pixmap.h"
-#include "mainwindow.h"
-#include "compose.h"
-#include "alertpanel.h"
-#include "addr_compl.h"
-#include "file-utils.h"
-
-#define IS_CURRENT_THEME(path) (strcmp(prefs_common.pixmap_theme_path, path) == 0)
-#define IS_INTERNAL_THEME(path) (strcmp(DEFAULT_PIXMAP_THEME, path) == 0)
-#define IS_SYSTEM_THEME(path) (prefs_themes_is_system_theme(path))
-
-#define PREVIEW_ICONS 7
-#define THEMEINFO_FILE ".claws_themeinfo"
-#define PIXMAP_THEME_DIR "themes"
-
-typedef struct _ThemesPage
-{
- PrefsPage page;
-
- GtkWidget *window; /* do not modify */
-
- GtkWidget *op_menu;
- GtkWidget *btn_install;
- GtkWidget *btn_more;
- GtkWidget *global;
-
- GtkWidget *name;
- GtkWidget *author;
- GtkWidget *url;
- GtkWidget *status;
-
- GtkWidget *icons[PREVIEW_ICONS];
-
- GtkWidget *btn_remove;
-
- GdkPixbuf *pixbufs[PREVIEW_ICONS];
-} ThemesPage;
-
-typedef struct _ThemeInfo
-{
- gchar *name;
- gchar *author;
- gchar *url;
- gchar *status;
-} ThemeInfo;
-
-typedef struct _ThemeName
-{
- gchar *name;
- GList *item;
-} ThemeName;
-
-typedef struct _ThemesData
-{
- GList *themes;
- GList *names;
- gchar *displayed;
- ThemesPage *page;
-} ThemesData;
-
-typedef void (*FileFunc) (const gchar *filename, gpointer data);
-
-typedef struct _DirInfo {
- gint bytes;
- gint files;
- gint pixms;
- /* extensions info */
- const char **supported;
- gint *length;
-} DirInfo;
-
-typedef struct _CopyInfo {
- gchar *dest;
- gchar *status;
-} CopyInfo;
-
-static ThemesData *prefs_themes_data;
-
-StockPixmap prefs_themes_icons[PREVIEW_ICONS] = {
- STOCK_PIXMAP_DIR_CLOSE,
- STOCK_PIXMAP_MAIL_SEND,
- STOCK_PIXMAP_MAIL_RECEIVE,
- STOCK_PIXMAP_MAIL_ATTACH,
- STOCK_PIXMAP_BOOK,
- STOCK_PIXMAP_MIME_TEXT_PLAIN,
- STOCK_PIXMAP_REPLIED
-};
-
-
-
-static void prefs_themes_btn_remove_clicked_cb (GtkWidget *widget, gpointer data);
-static void prefs_themes_btn_install_clicked_cb (GtkWidget *widget, gpointer data);
-static void prefs_themes_btn_viewall_clicked_cb (GtkWidget *widget, gpointer data);
-static void prefs_themes_viewall_close_btn_clicked (GtkWidget *widget, gpointer data);
-static void prefs_themes_menu_item_activated_cb (GtkWidget *widget, gpointer data);
-
-static void prefs_themes_update_buttons (const ThemesData *tdata);
-static void prefs_themes_display_global_stats (const ThemesData *tdata);
-static void prefs_themes_get_theme_info (ThemesData *tdata);
-static void prefs_themes_display_theme_info (ThemesData *tdata, const ThemeInfo *info);
-static void prefs_themes_get_themes_and_names (ThemesData *tdata);
-static int prefs_themes_cmp_name(gconstpointer a, gconstpointer b);
-static void prefs_themes_free_names (ThemesData *tdata);
-
-static void prefs_themes_set_themes_menu (GtkComboBox *combo, const ThemesData *tdata);
-
-static gchar *prefs_themes_get_theme_stats (const gchar *dirname);
-static gboolean prefs_themes_is_system_theme (const gchar *dirname);
-
-static void prefs_themes_create_widget (PrefsPage *page, GtkWindow *window, gpointer data);
-static void prefs_themes_destroy_widget (PrefsPage *page);
-static void prefs_themes_save (PrefsPage *page);
-
-static void prefs_themes_foreach_file (const gchar *dirname, const FileFunc func, gpointer data);
-static void prefs_themes_file_stats (const gchar *filename, gpointer data);
-static void prefs_themes_file_remove (const gchar *filename, gpointer data);
-static void prefs_themes_file_install (const gchar *filename, gpointer data);
-
-
-
-static void prefs_themes_file_stats(const gchar *filename, gpointer data)
-{
-
- GStatBuf s;
- goffset size;
- DirInfo *di = (DirInfo *)data;
- gint len;
- gint i;
-
- if ((i = g_stat(filename, &s)) != 0) {
- debug_print("g_stat on '%s' failed: %d\n", filename, i);
- return;
- }
- if (!S_ISREG(s.st_mode)) {
- return;
- }
- size = s.st_size;
-
- di->bytes += size;
- di->files++;
- len = strlen(filename);
- for (i = 0; (di->supported)[i] != NULL; ++i) {
- gint curlen = (di->length)[i];
- if (len <= curlen)
- continue;
- const gchar *extension = filename + (len - curlen);
- if (!strcmp(extension, (di->supported)[i])) {
- di->pixms++;
- break;
- }
- }
-}
-
-static void prefs_themes_file_remove(const gchar *filename, gpointer data)
-{
- gchar **status = (gchar **)data;
- gchar *base;
-
- if ((*status) != NULL)
- return;
-
- base = g_path_get_basename(filename);
- if (TRUE == is_dir_exist(filename)) {
- if (strcmp(base, ".") != 0 && strcmp(base, "..") != 0)
- g_warning("prefs_themes_file_remove(): subdir in theme dir skipped: '%s'",
- base);
- }
- else if (0 != unlink(filename)) {
- (*status) = g_strdup(filename);
- }
- g_free(base);
-}
-
-static void prefs_themes_file_install(const gchar *filename, gpointer data)
-{
- CopyInfo *ci = (CopyInfo *)data;
- gchar *base;
-
- if (ci->status != NULL)
- return;
-
- base = g_path_get_basename(filename);
- if (TRUE == is_dir_exist(filename)) {
- if (strcmp(base, ".") != 0 && strcmp(base, "..") !=0 )
- g_warning("prefs_themes_file_install(): subdir in theme dir skipped: '%s'",
- base);
- }
- else {
- gchar *fulldest;
-
- fulldest = g_strconcat(ci->dest, G_DIR_SEPARATOR_S, base, NULL);
-
- if (0 != copy_file(filename, fulldest, FALSE)) {
- ci->status = g_strdup(filename);
- }
- g_free(fulldest);
- }
- g_free(base);
-}
-
-static void prefs_themes_foreach_file(const gchar *dirname, const FileFunc func, gpointer data)
-{
- const gchar *entry;
- gchar *fullentry;
- GDir *dp;
- GError *error = NULL;
-
- cm_return_if_fail(dirname != NULL);
- cm_return_if_fail(func != NULL);
-
- if ((dp = g_dir_open(dirname, 0, &error)) == NULL) {
- debug_print("couldn't open dir '%s': %s (%d)\n", dirname,
- error->message, error->code);
- g_error_free(error);
- return;
- }
-
- while ((entry = g_dir_read_name(dp)) != NULL) {
-
- fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
-
- (*func)(fullentry, data);
-
- g_free(fullentry);
- }
- g_dir_close(dp);
-}
-
-static gboolean prefs_themes_is_system_theme(const gchar *dirname)
-{
- return FALSE;
-}
-
-static void prefs_themes_set_themes_menu(GtkComboBox *combo, const ThemesData *tdata)
-{
- GtkListStore *store;
- GtkTreeIter iter;
- GList *themes = tdata->names;
- gint i = 0, active = 0;
- GList *sorted_list = NULL;
-
- cm_return_if_fail(combo != NULL);
-
- /* sort theme data list by data name */
- while (themes != NULL) {
- ThemeName *tname = (ThemeName *)(themes->data);
-
- sorted_list = g_list_insert_sorted(sorted_list, (gpointer)(tname),
- (GCompareFunc)prefs_themes_cmp_name);
-
- themes = g_list_next(themes);
- }
-
- store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
-
- /* feed gtk_menu w/ sorted themes names */
- themes = sorted_list;
- while (themes != NULL) {
- ThemeName *tname = (ThemeName *)(themes->data);
- gchar *tpath = (gchar *)(tname->item->data);
-
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- 0, tname->name,
- 1, tname->item->data, -1);
-
- if (tdata->displayed != NULL && !g_strcmp0(tdata->displayed,tpath))
- active = i;
- ++i;
-
- themes = g_list_next(themes);
- }
-
- g_list_free(sorted_list);
-
- g_signal_connect(G_OBJECT(combo), "changed",
- G_CALLBACK(prefs_themes_menu_item_activated_cb),
- NULL);
-
- gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
- gtk_combo_box_set_active(combo, active);
-}
-
-static int prefs_themes_cmp_name(gconstpointer a_p, gconstpointer b_p)
-{
- /* compare two ThemeData structures by their name attribute */
- return g_strcmp0((gchar *)(((ThemeName*)a_p)->name),
- (gchar *)(((ThemeName*)b_p)->name));
-}
-
-static void prefs_themes_get_themes_and_names(ThemesData *tdata)
-{
- GList *tpaths;
-
- cm_return_if_fail(tdata != NULL);
-
- stock_pixmap_themes_list_free(tdata->themes);
- prefs_themes_free_names(tdata);
-
- tdata->themes = stock_pixmap_themes_list_new();
-
- tpaths = tdata->themes;
- while (tpaths != NULL) {
- ThemeName *name = g_new0(ThemeName, 1);
- gchar *sname = g_path_get_basename((const gchar *)(tpaths->data));
-
- if (IS_INTERNAL_THEME(sname))
- name->name = g_strdup(_("Default internal theme"));
- else
- name->name = g_strdup(sname);
- name->item = tpaths;
-
- tdata->names = g_list_append(tdata->names, name);
- if (!g_strcmp0(tpaths->data, prefs_common.pixmap_theme_path)) {
- tdata->displayed = (gchar *)tpaths->data;
- }
- tpaths = g_list_next(tpaths);
- g_free(sname);
- }
-}
-
-void prefs_themes_init(void)
-{
- ThemesData *tdata;
- ThemesPage *page;
- GList *tpaths;
- static gchar *path[3];
-
- path[0] = _("Display");
- path[1] = _("Themes");
- path[2] = NULL;
-
- debug_print("Creating preferences for themes...\n");
-
- tdata = g_new0(ThemesData, 1);
- prefs_themes_data = tdata;
-
- prefs_themes_get_themes_and_names(tdata);
-
- page = g_new0(ThemesPage, 1);
-
- page->page.path = path;
- page->page.create_widget = prefs_themes_create_widget;
- page->page.destroy_widget = prefs_themes_destroy_widget;
- page->page.save_page = prefs_themes_save;
- page->page.weight = 130.0;
- prefs_gtk_register_page((PrefsPage *) page);
-
- tdata->page = page;
-
- tpaths = g_list_first(tdata->themes);
- if (tdata->displayed == NULL)
- tdata->displayed = (gchar *)(tpaths->data);
-}
-
-static void prefs_themes_free_names(ThemesData *tdata)
-{
- GList *names;
-
- cm_return_if_fail(tdata != NULL);
-
- if (tdata->names == NULL)
- return;
-
- names = tdata->names;
- while (names != NULL) {
- ThemeName *tn = (ThemeName *)(names->data);
-
- tn->item = NULL;
- g_free(tn->name);
- g_free(tn);
-
- names = g_list_next(names);
- }
- g_list_free(tdata->names);
- tdata->names = NULL;
-}
-
-void prefs_themes_done(void)
-{
- ThemesData *tdata = prefs_themes_data;
-
- debug_print("Finished preferences for themes.\n");
-
- stock_pixmap_themes_list_free(tdata->themes);
- prefs_themes_free_names(tdata);
- g_free(tdata->page);
- g_free(tdata);
-}
-
-static void prefs_themes_btn_remove_clicked_cb(GtkWidget *widget, gpointer data)
-{
- ThemesData *tdata = prefs_themes_data;
- gchar *theme_str;
- gchar *alert_title = NULL;
- AlertValue val = 0;
- gchar *tmp = NULL;
-
- theme_str = tdata->displayed;
-
- tmp = g_path_get_basename(theme_str);
- alert_title = g_strdup_printf(_("Remove theme '%s'"), tmp);
- g_free(tmp);
-
- val = alertpanel(alert_title,
- _("Are you sure you want to remove this theme?"),
- NULL, _("_No"), NULL, _("_Yes"), NULL, NULL, ALERTFOCUS_FIRST);
- g_free(alert_title);
-
- if (G_ALERTALTERNATE == val) {
- gchar *status = NULL;
-
- prefs_themes_foreach_file(theme_str, prefs_themes_file_remove, &status);
- if (0 != rmdir(theme_str)) {
- if (status != NULL) {
- alertpanel_error(_("File %s failed\nwhile removing theme."), status);
- g_free(status);
- }
- else
- alertpanel_error(_("Removing theme directory failed."));
- }
- else {
- alertpanel_notice(_("Theme removed successfully"));
- /* update interface back to first theme */
- prefs_themes_get_themes_and_names(tdata);
- prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
- prefs_themes_display_global_stats(tdata);
- tdata->displayed = (gchar *)((g_list_first(tdata->themes))->data);
- prefs_themes_get_theme_info(tdata);
- }
- }
-}
-
-static void prefs_themes_btn_install_clicked_cb(GtkWidget *widget, gpointer data)
-{
- gchar *filename, *source;
- gchar *themeinfo, *themename;
- gchar *alert_title = NULL;
- CopyInfo *cinfo;
- AlertValue val = 0;
- ThemesData *tdata = prefs_themes_data;
-
- filename = filesel_select_file_open_folder(_("Select theme folder"), NULL);
- if (filename == NULL)
- return;
-
- if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR)
- filename = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL);
- else
- filename = g_strdup(filename);
-
- cinfo = g_new0(CopyInfo, 1);
- source = g_path_get_dirname(filename);
- themename = g_path_get_basename(source);
- debug_print("Installing '%s' theme from %s\n", themename, filename);
-
- themeinfo = g_strconcat(source, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
- alert_title = g_strdup_printf(_("Install theme '%s'"), themename);
- if (file_exist(themeinfo, FALSE) == FALSE) {
- val = alertpanel(alert_title,
- _("This folder doesn't seem to be a theme"
- "folder.\nInstall anyway?"),
- NULL, _("_No"), NULL, _("_Yes"), NULL, NULL, ALERTFOCUS_FIRST);
- if (G_ALERTALTERNATE != val)
- goto end_inst;
- }
-
- cinfo->dest = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- PIXMAP_THEME_DIR, G_DIR_SEPARATOR_S,
- themename, NULL);
- if (TRUE == is_dir_exist(cinfo->dest)) {
- AlertValue val = alertpanel_full(_("Theme exists"),
- _("A theme with the same name is\n"
- "already installed in this location.\n\n"
- "Do you want to replace it?"),
- NULL, _("_Cancel"), NULL, _("Overwrite"), NULL, NULL,
- ALERTFOCUS_FIRST, FALSE, NULL, ALERT_WARNING);
- if (val == G_ALERTALTERNATE) {
- if (remove_dir_recursive(cinfo->dest) < 0) {
- alertpanel_error(_("Couldn't delete the old theme in %s."),
- cinfo->dest);
- goto end_inst;
- }
- } else {
- goto end_inst;
- }
- }
- if (0 != make_dir_hier(cinfo->dest)) {
- alertpanel_error(_("Couldn't create destination directory %s."),
- cinfo->dest);
- goto end_inst;
- }
- prefs_themes_foreach_file(source, prefs_themes_file_install, cinfo);
- if (cinfo->status == NULL) {
- GList *insted;
-
- /* update interface to show newly installed theme */
- prefs_themes_get_themes_and_names(tdata);
- insted = g_list_find_custom(tdata->themes,
- (gpointer)(cinfo->dest),
- (GCompareFunc)g_strcmp0);
- if (NULL != insted) {
- alertpanel_notice(_("Theme installed successfully."));
- tdata->displayed = (gchar *)(insted->data);
- prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
- prefs_themes_display_global_stats(tdata);
- prefs_themes_get_theme_info(tdata);
- }
- else
- alertpanel_error(_("Failed installing theme"));
- }
- else
- alertpanel_error(_("File %s failed\nwhile installing theme."), cinfo->status);
-end_inst:
- g_free(cinfo->dest);
- g_free(filename);
- g_free(source);
- g_free(themeinfo);
- g_free(cinfo);
- g_free(themename);
- g_free(alert_title);
-}
-
-static void prefs_themes_viewall_close_btn_clicked(GtkWidget *widget, gpointer data)
-{
- GtkWidget **window = (GtkWidget **) data;
-
- cm_return_if_fail(window != NULL);
- cm_return_if_fail(*window != NULL);
-
- gtk_widget_destroy(*window);
- *window = NULL;
-}
-
-#define ICONS_PER_ROW 19
-
-static void prefs_themes_btn_viewall_clicked_cb(GtkWidget *widget, gpointer data)
-{
- static GtkWidget *viewall_win = NULL;
-
- ThemesData *tdata = prefs_themes_data;
- GtkWidget *vbox;
- GtkWidget *hbox;
- GtkWidget *icons[N_STOCK_PIXMAPS];
- GdkPixbuf *pixbufs[N_STOCK_PIXMAPS];
- GtkWidget *separator;
- GtkWidget *confirm_area;
- GtkWidget *close_btn;
- gchar *save_prefs_path;
- gint i;
-
- viewall_win = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_themes_view_all");
- gtk_container_set_border_width(GTK_CONTAINER(viewall_win), 5);
- gtk_window_set_title(GTK_WINDOW(viewall_win), _("View all theme icons"));
- gtk_window_set_position(GTK_WINDOW(viewall_win), GTK_WIN_POS_CENTER);
-
- vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
- gtk_widget_show(vbox);
- gtk_container_add(GTK_CONTAINER(viewall_win), vbox);
-
- save_prefs_path = prefs_common.pixmap_theme_path;
- prefs_common.pixmap_theme_path = tdata->displayed;
- hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
- gtk_widget_show(hbox);
- for (i = 0; i < N_STOCK_PIXMAPS; ++i) {
- icons[i] = gtk_image_new();
- gtk_widget_show (icons[i]);
- stock_pixbuf_gdk(i, &(pixbufs[i]));
- gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), pixbufs[i]);
- gtk_box_pack_start(GTK_BOX(hbox), icons[i], TRUE, TRUE, 5);
- if ((i + 1) % ICONS_PER_ROW == 0) {
- gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
- if (i + 1 < N_STOCK_PIXMAPS) {
- hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
- gtk_widget_show(hbox);
- }
- }
- }
- prefs_common.pixmap_theme_path = save_prefs_path;
-
- separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
- gtk_widget_show(separator);
- gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0);
-
- gtkut_stock_button_set_create(&confirm_area,
- &close_btn, "window-close", _("_Close"),
- NULL, NULL, NULL, NULL, NULL, NULL);
- gtk_box_pack_start(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 5);
- gtk_widget_show(confirm_area);
- gtk_widget_grab_default(close_btn);
- gtk_widget_grab_focus(close_btn);
-
- g_signal_connect(G_OBJECT(close_btn), "clicked",
- G_CALLBACK(prefs_themes_viewall_close_btn_clicked),
- &viewall_win);
-
- manage_window_set_transient(GTK_WINDOW(viewall_win));
- gtk_window_set_modal(GTK_WINDOW(viewall_win), TRUE);
- gtk_widget_show(viewall_win);
-}
-
-static void prefs_themes_menu_item_activated_cb(GtkWidget *widget, gpointer data)
-{
- ThemesData *tdata = prefs_themes_data;
- gchar *path;
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- cm_return_if_fail(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter));
-
- model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
- gtk_tree_model_get(model, &iter, 1, &path, -1);
-
- tdata->displayed = path;
- prefs_themes_get_theme_info(tdata);
-}
-
-static void prefs_themes_update_buttons(const ThemesData *tdata)
-{
- ThemesPage *theme = tdata->page;
- gboolean can_rem;
-
- can_rem = !IS_CURRENT_THEME(tdata->displayed) &&
- !IS_INTERNAL_THEME(tdata->displayed) &&
- !IS_SYSTEM_THEME(tdata->displayed);
-
- if (theme->btn_remove != NULL)
- gtk_widget_set_sensitive(theme->btn_remove, can_rem);
-}
-
-/* placeholders may already be utf8 (i18n) */
-#define SET_LABEL_TEXT_UTF8(label, text) \
-{ \
- gchar *tmpstr; \
- \
- if (!g_utf8_validate(text, -1, NULL)) \
- tmpstr = conv_codeset_strdup(text, \
- conv_get_locale_charset_str(), CS_UTF_8); \
- else \
- tmpstr = g_strdup(text); \
- \
- gtk_label_set_text(GTK_LABEL(label), tmpstr); \
- gtk_label_set_selectable(GTK_LABEL(label), TRUE); \
- g_free(tmpstr); \
-}
-static void prefs_themes_display_theme_info(ThemesData *tdata, const ThemeInfo *info)
-{
- ThemesPage *theme = tdata->page;
- gchar *save_prefs_path;
- gint i;
-
- SET_LABEL_TEXT_UTF8(theme->name, info->name);
- SET_LABEL_TEXT_UTF8(theme->author, info->author);
- SET_LABEL_TEXT_UTF8(theme->url, info->url);
- SET_LABEL_TEXT_UTF8(theme->status, info->status);
-
- save_prefs_path = prefs_common.pixmap_theme_path;
- prefs_common.pixmap_theme_path = tdata->displayed;
- for (i = 0; i < PREVIEW_ICONS; ++i) {
- stock_pixbuf_gdk(prefs_themes_icons[i], &(theme->pixbufs[i]));
- gtk_image_set_from_pixbuf(GTK_IMAGE(theme->icons[i]),
- theme->pixbufs[i]);
- }
- prefs_common.pixmap_theme_path = save_prefs_path;
-
- prefs_themes_update_buttons(tdata);
-}
-#undef SET_LABEL_TEXT_UTF8
-
-static void prefs_themes_display_global_stats(const ThemesData *tdata)
-{
- ThemesPage *theme = tdata->page;
- GList *tnames = tdata->names;
- gchar *gstats;
- gint sys = 0;
- gint usr = 0;
- gint all = 0;
-
- while (tnames != NULL) {
- ThemeName *tname = (ThemeName *)(tnames->data);
- gchar *tpath = (gchar *)(tname->item->data);
-
- if (IS_SYSTEM_THEME(tpath))
- ++sys;
- else if (!IS_INTERNAL_THEME(tpath))
- ++usr;
- ++all;
- tnames = g_list_next(tnames);
- }
-
- gstats = g_strdup_printf(_("%d themes available (%d user, %d system, 1 internal)"),
- all, usr, sys);
- gtk_label_set_text(GTK_LABEL(theme->global), gstats);
- gtk_label_set_justify (GTK_LABEL (theme->global), GTK_JUSTIFY_LEFT);
- gtkut_widget_set_small_font_size (theme->global);
- g_free(gstats);
-}
-
-#define INFOFILE_LINE_LEN 80
-
-#define FGETS_INFOFILE_LINE() \
- line[0] = '\0'; \
- if (fgets(line, INFOFILE_LINE_LEN, finfo) != NULL && (len = strlen(line)) > 0) { \
- if (line[len - 1] == '\n') line[len - 1] = '\0'; \
- } \
- else { \
- g_strlcpy(line, _("Unknown"),sizeof(line)); \
- }
-
-static void prefs_themes_get_theme_info(ThemesData *tdata)
-{
- FILE *finfo;
- gchar *sinfo;
- gchar *path;
- gchar line[INFOFILE_LINE_LEN];
- gint len;
- ThemeInfo *info;
- ThemesPage *theme = tdata->page;
-
- cm_return_if_fail(theme != NULL);
- path = tdata->displayed;
- cm_return_if_fail(path != NULL);
-
- debug_print("Getting theme info for %s\n", path);
-
- info = g_new0(ThemeInfo, 1);
-
- if (IS_INTERNAL_THEME(path)) {
- info->name = g_strdup(_("Default internal theme"));
- info->author = g_strdup(_("The Claws Mail Team"));
- info->url = g_strdup(HOMEPAGE_URI);
- info->status = g_strdup_printf(_("Internal theme has %d icons"), N_STOCK_PIXMAPS);
- }
- else {
- sinfo = g_strconcat(path, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
- finfo = g_fopen(sinfo, "r");
- if (finfo == NULL) {
- info->name = g_strdup(_("No info file available for this theme"));
- info->author = g_strdup(_("Unknown"));
- info->url = g_strdup(_("Unknown"));
- }
- else {
- FGETS_INFOFILE_LINE()
- info->name = g_strdup(line);
- FGETS_INFOFILE_LINE()
- info->author = g_strdup(line);
- FGETS_INFOFILE_LINE()
- info->url = g_strdup(line);
-
- fclose(finfo);
- }
- g_free(sinfo);
-
- info->status = prefs_themes_get_theme_stats(path);
- if (info->status == NULL) {
- info->status = g_strdup(_("Error: couldn't get theme status"));
- }
- }
-
- prefs_themes_display_theme_info(tdata, info);
-
- g_free(info->name);
- g_free(info->author);
- g_free(info->url);
- g_free(info->status);
-
- g_free(info);
-}
-
-#undef FGETS_INFOFILE_LINE
-
-static gchar *prefs_themes_get_theme_stats(const gchar *dirname)
-{
- gchar *stats;
- DirInfo *dinfo;
- gint i;
-
- dinfo = g_new0(DirInfo, 1);
- dinfo->supported = stock_pixmap_theme_extensions();
- for (i = 0; (dinfo->supported)[i] != NULL; ++i);
- dinfo->length = g_malloc(i * sizeof(gint));
- for (i = 0; (dinfo->supported)[i] != NULL; ++i) {
- (dinfo->length)[i] = strlen((dinfo->supported)[i]);
- }
- prefs_themes_foreach_file(dirname, prefs_themes_file_stats, dinfo);
- stats = g_strdup_printf(_("%d files (%d icons), size: %s"),
- dinfo->files, dinfo->pixms,
- to_human_readable((goffset)dinfo->bytes));
- g_free(dinfo->length);
- g_free(dinfo);
- return stats;
-}
-
-static void prefs_themes_create_widget(PrefsPage *page, GtkWindow *window, gpointer data)
-{
- ThemesPage *prefs_themes = (ThemesPage *)page;
- ThemesData *tdata = prefs_themes_data;
-
- GtkWidget *vbox1;
- GtkWidget *frame1;
- GtkWidget *vbox2;
- GtkWidget *hbox3;
- GtkWidget *menu_themes;
- GtkWidget *btn_install;
- GtkWidget *btn_more;
- GtkWidget *label_global_status;
- GtkWidget *frame_info;
- GtkWidget *table1;
- GtkWidget *label1;
- GtkWidget *label2;
- GtkWidget *label3;
- GtkWidget *label_name;
- GtkWidget *label_author;
- GtkWidget *label_url;
- GtkWidget *label4;
- GtkWidget *label_status;
- GtkWidget *frame_preview;
- GtkWidget *hbox1;
- GtkWidget *icon_1;
- GtkWidget *icon_2;
- GtkWidget *icon_3;
- GtkWidget *icon_4;
- GtkWidget *icon_5;
- GtkWidget *icon_6;
- GtkWidget *icon_7;
- GtkWidget *btn_viewall;
- GtkWidget *frame_buttons;
- GtkWidget *hbuttonbox1;
- GtkWidget *btn_remove;
- GtkCellRenderer *renderer;
-
- vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
- gtk_container_set_border_width (GTK_CONTAINER (vbox1), 5);
- gtk_widget_show (vbox1);
-
- vbox2 = gtkut_get_options_frame(vbox1, &frame1, _("Selector"));
-
- hbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
- gtk_widget_show (hbox3);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox3, FALSE, FALSE, 0);
- // gtk_container_set_border_width (GTK_CONTAINER (hbox3), 5);
-
- menu_themes = gtk_combo_box_new();
- gtk_widget_show (menu_themes);
- gtk_box_pack_start (GTK_BOX (hbox3), menu_themes, FALSE, FALSE, 0);
-
- btn_install = gtk_button_new_with_label (_("Install new..."));
- gtk_widget_show (btn_install);
- gtk_box_pack_start (GTK_BOX (hbox3), btn_install, FALSE, FALSE, 0);
- gtk_widget_set_can_default (btn_install, TRUE);
-
- btn_more = gtk_link_button_new_with_label("https://www.claws-mail.org/themes.php", "Get more...");
- gtk_widget_show (btn_more);
- gtk_box_pack_start (GTK_BOX (hbox3), btn_more, FALSE, FALSE, 0);
-
- label_global_status = gtk_label_new ("");
- gtk_widget_show (label_global_status);
- gtk_box_pack_start (GTK_BOX (vbox2), label_global_status, FALSE, FALSE, 0);
- gtk_label_set_justify (GTK_LABEL (label_global_status), GTK_JUSTIFY_LEFT);
- gtk_label_set_xalign (GTK_LABEL (label_global_status), 0.0);
- gtk_widget_set_margin_start(GTK_WIDGET(label_global_status), 1);
- gtk_widget_set_margin_end(GTK_WIDGET(label_global_status), 0);
-
- PACK_FRAME(vbox1, frame_info, _("Information"));
-
- table1 = gtk_grid_new();
- gtk_widget_show (table1);
- gtk_container_add (GTK_CONTAINER (frame_info), table1);
- gtk_container_set_border_width (GTK_CONTAINER (table1), 5);
- gtk_grid_set_row_spacing(GTK_GRID(table1), 4);
- gtk_grid_set_column_spacing(GTK_GRID(table1), 8);
-
- label1 = gtk_label_new (_("Name"));
- gtk_widget_show (label1);
- gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT);
- gtk_label_set_xalign (GTK_LABEL (label1), 1.0);
- gtk_grid_attach(GTK_GRID(table1), label1, 0, 0, 1, 1);
-
- label2 = gtk_label_new (_("Author"));
- gtk_widget_show (label2);
- gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_LEFT);
- gtk_label_set_xalign (GTK_LABEL (label2), 1.0);
- gtk_grid_attach(GTK_GRID(table1), label2, 0, 1, 1, 1);
-
- label3 = gtk_label_new (_("URL"));
- gtk_widget_show (label3);
- gtk_label_set_xalign (GTK_LABEL (label3), 1.0);
- gtk_grid_attach(GTK_GRID(table1), label3, 0, 2, 1, 1);
-
- label_name = gtk_label_new ("");
- gtk_widget_show (label_name);
- gtk_label_set_xalign (GTK_LABEL (label_name), 0.0);
- gtk_grid_attach(GTK_GRID(table1), label_name, 1, 0, 1, 1);
- gtk_widget_set_hexpand(label_name, TRUE);
- gtk_widget_set_halign(label_name, GTK_ALIGN_FILL);
-
- label_author = gtk_label_new ("");
- gtk_widget_show (label_author);
- gtk_label_set_xalign (GTK_LABEL (label_author), 0.0);
- gtk_grid_attach(GTK_GRID(table1), label_author, 1, 1, 1, 1);
- gtk_widget_set_hexpand(label_author, TRUE);
- gtk_widget_set_halign(label_author, GTK_ALIGN_FILL);
-
- label_url = gtk_label_new ("");
- gtk_widget_show (label_url);
- gtk_label_set_xalign (GTK_LABEL (label_url), 0.0);
- gtk_grid_attach(GTK_GRID(table1), label_url, 1, 2, 1, 1);
- gtk_widget_set_hexpand(label_url, TRUE);
- gtk_widget_set_halign(label_url, GTK_ALIGN_FILL);
-
- label4 = gtk_label_new (_("Status"));
- gtk_widget_show (label4);
- gtk_label_set_xalign (GTK_LABEL (label4), 1.0);
- gtk_grid_attach(GTK_GRID(table1), label4, 0, 3, 1, 1);
-
- label_status = gtk_label_new ("");
- gtk_widget_show (label_status);
- gtk_label_set_xalign (GTK_LABEL (label_status), 0.0);
- gtk_grid_attach(GTK_GRID(table1), label_status, 1, 3, 1, 1);
- gtk_widget_set_hexpand(label_status, TRUE);
- gtk_widget_set_halign(label_status, GTK_ALIGN_FILL);
-
- PACK_FRAME(vbox1, frame_preview, _("Preview"));
-
- hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_widget_show (hbox1);
- gtk_container_add (GTK_CONTAINER (frame_preview), hbox1);
- gtk_container_set_border_width (GTK_CONTAINER (hbox1), 5);
-
- icon_1 = gtk_image_new();
- gtk_widget_show (icon_1);
- gtk_box_pack_start (GTK_BOX (hbox1), icon_1, TRUE, TRUE, 2);
- gtk_widget_set_margin_start(GTK_WIDGET(icon_1), 0);
- gtk_widget_set_margin_end(GTK_WIDGET(icon_1), 5);
-
- icon_2 = gtk_image_new();
- gtk_widget_show (icon_2);
- gtk_box_pack_start (GTK_BOX (hbox1), icon_2, TRUE, TRUE, 2);
- gtk_widget_set_margin_start(GTK_WIDGET(icon_2), 0);
- gtk_widget_set_margin_end(GTK_WIDGET(icon_2), 5);
-
- icon_3 = gtk_image_new();
- gtk_widget_show (icon_3);
- gtk_box_pack_start (GTK_BOX (hbox1), icon_3, TRUE, TRUE, 2);
- gtk_widget_set_margin_start(GTK_WIDGET(icon_3), 0);
- gtk_widget_set_margin_end(GTK_WIDGET(icon_3), 5);
-
- icon_4 = gtk_image_new();
- gtk_widget_show (icon_4);
- gtk_box_pack_start (GTK_BOX (hbox1), icon_4, TRUE, TRUE, 2);
- gtk_widget_set_margin_start(GTK_WIDGET(icon_4), 0);
- gtk_widget_set_margin_end(GTK_WIDGET(icon_4), 5);
-
- icon_5 = gtk_image_new();
- gtk_widget_show (icon_5);
- gtk_box_pack_start (GTK_BOX (hbox1), icon_5, TRUE, TRUE, 2);
- gtk_widget_set_margin_start(GTK_WIDGET(icon_5), 0);
- gtk_widget_set_margin_end(GTK_WIDGET(icon_5), 5);
-
- icon_6 = gtk_image_new();
- gtk_widget_show (icon_6);
- gtk_box_pack_start (GTK_BOX (hbox1), icon_6, TRUE, TRUE, 2);
- gtk_widget_set_margin_start(GTK_WIDGET(icon_6), 0);
- gtk_widget_set_margin_end(GTK_WIDGET(icon_6), 5);
-
- icon_7 = gtk_image_new();
- gtk_widget_show (icon_7);
- gtk_box_pack_start (GTK_BOX (hbox1), icon_7, TRUE, TRUE, 2);
- gtk_widget_set_margin_start(GTK_WIDGET(icon_7), 0);
- gtk_widget_set_margin_end(GTK_WIDGET(icon_7), 5);
-
- PACK_FRAME(vbox1, frame_buttons, _("Actions"));
-
- hbuttonbox1 = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
- gtk_widget_show (hbuttonbox1);
- gtk_container_add (GTK_CONTAINER (frame_buttons), hbuttonbox1);
- gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox1), 8);
- gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_START);
- gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 5);
-
- btn_remove = gtkut_stock_button("list-remove", _("_Remove"));
- gtk_widget_show (btn_remove);
- gtk_container_add (GTK_CONTAINER (hbuttonbox1), btn_remove);
- gtk_widget_set_can_default (btn_remove, TRUE);
-
- btn_viewall = gtk_button_new_with_label(_("View all"));
- gtk_widget_show (btn_viewall);
- gtk_box_pack_start (GTK_BOX (hbuttonbox1), btn_viewall, FALSE, FALSE, 5);
-
- g_signal_connect(G_OBJECT(btn_remove), "clicked",
- G_CALLBACK(prefs_themes_btn_remove_clicked_cb),
- NULL);
- g_signal_connect(G_OBJECT(btn_install), "clicked",
- G_CALLBACK(prefs_themes_btn_install_clicked_cb),
- NULL);
- g_signal_connect(G_OBJECT(btn_viewall), "clicked",
- G_CALLBACK(prefs_themes_btn_viewall_clicked_cb),
- NULL);
-
- prefs_themes->window = GTK_WIDGET(window);
-
- prefs_themes->name = label_name;
- prefs_themes->author = label_author;
- prefs_themes->url = label_url;
- prefs_themes->status = label_status;
- prefs_themes->global = label_global_status;
-
- prefs_themes->icons[0] = icon_1;
- prefs_themes->icons[1] = icon_2;
- prefs_themes->icons[2] = icon_3;
- prefs_themes->icons[3] = icon_4;
- prefs_themes->icons[4] = icon_5;
- prefs_themes->icons[5] = icon_6;
- prefs_themes->icons[6] = icon_7;
-
- prefs_themes->btn_remove = btn_remove;
- prefs_themes->btn_install = btn_install;
- prefs_themes->btn_more = btn_more;
-
- prefs_themes->op_menu = menu_themes;
-
- prefs_themes->page.widget = vbox1;
-
- prefs_themes_set_themes_menu(GTK_COMBO_BOX(menu_themes), tdata);
- renderer = gtk_cell_renderer_text_new();
- gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(menu_themes), renderer, TRUE);
- gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(menu_themes), renderer,
- "text", 0, NULL);
-
- prefs_themes_get_theme_info(tdata);
- prefs_themes_display_global_stats(tdata);
-}
-
-static void prefs_themes_destroy_widget(PrefsPage *page)
-{
- /* ThemesPage *theme = (ThemesPage *)page; */
-}
-
-static void prefs_themes_save(PrefsPage *page)
-{
- ThemesData *tdata = prefs_themes_data;
- gchar *theme_str = tdata->displayed;
-
- if (!IS_CURRENT_THEME(theme_str)) {
- debug_print("Changing theme to %s\n", theme_str);
- g_free(prefs_common.pixmap_theme_path);
-
- prefs_common.pixmap_theme_path = g_strdup(theme_str);
-
- main_window_reflect_prefs_all_real(TRUE);
- compose_reflect_prefs_pixmap_theme();
- addrcompl_reflect_prefs_pixmap_theme();
-
- prefs_themes_update_buttons(tdata);
- }
-}
-
blob - 82bc8e98d670370e258716ed93d81b5c74ba2a29 (mode 644)
blob + /dev/null
--- src/prefs_themes.h
+++ /dev/null
-/*
- * Claws Mail -- a GTK based, lightweight, and fast e-mail client
- * Copyright (C) 2003-2012 Hiroyuki Yamamoto and the Claws Mail team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef PREFS_THEMES_H
-#define PREFS_THEMES_H
-
-void prefs_themes_init(void);
-void prefs_themes_done(void);
-
-
-#endif /* PREFS_THEMES_H */
-