ClipIt-v1.3.4-26112010001

+ Fixed: Now we are warning the user that his history is saved in a
                plain text file and ask for his explicit permission
                to save the history.
+ Fixed: When the user disables history saving we also ask if he wants
                to empty the current history file.
+ Fixed: Renamed "Find" menu entry to "Manage history".
+ Fixed: ClipIt now complies to the "XDG Base Directory Specification".

Changes to be committed:

	modified:   ChangeLog
	modified:   NEWS
	modified:   configure.in
	modified:   src/history.c
	modified:   src/history.h
	modified:   src/main.c
	modified:   src/preferences.c
	modified:   src/preferences.h
	modified:   src/utils.c
	modified:   src/utils.h
This commit is contained in:
Cristian Henzel 2010-11-26 13:44:33 +02:00
parent 81b7d97d83
commit f75139eb4a
10 changed files with 117 additions and 38 deletions

View File

@ -1,3 +1,12 @@
ClipIt-v1.3.4-26112010001 - 26 Nov. 2010
+ Fixed: Now we are warning the user that his history is saved in a
plain text file and ask for his explicit permission
to save the history.
+ Fixed: When the user disables history saving we also ask if he wants
to empty the current history file.
+ Fixed: Renamed "Find" menu entry to "Manage history".
+ Fixed: ClipIt now complies to the "XDG Base Directory Specification".
ClipIt-v1.3.3-23112010001 - 23 Nov. 2010
+ Fixed: Fixed some more markup.
+ Fixed: Rearranged parts of the Preferences dialog to be cleaner.

2
NEWS
View File

@ -1 +1 @@
Project website: http://sourceforge.net/projects/gtkclipit/
Project website: http://gtkclipit.sourceforge.net/

View File

@ -2,7 +2,7 @@
# Autoconf/automake.
# -------------------------------------------------------------------------------
AC_PREREQ([2.5])
AC_INIT([clipit], [1.3.3], [oss@web-tm.com])
AC_INIT([clipit], [1.3.4], [oss@web-tm.com])
AM_INIT_AUTOMAKE([AC_PACKAGE_TARNAME()], [AC_PACKAGE_VERSION()])
AC_CONFIG_MACRO_DIR([m4])

View File

@ -28,11 +28,11 @@
GSList *history;
/* Reads history from ~/.local/share/clipit/history */
/* Reads history from DATADIR/clipit/history */
void read_history ()
{
/* Build file path */
gchar *history_path = g_build_filename(g_get_home_dir(),
gchar *history_path = g_build_filename(g_get_user_data_dir(),
HISTORY_FILE,
NULL);
@ -66,13 +66,13 @@ void read_history ()
}
}
/* Saves history to ~/.local/share/clipit/history */
/* Saves history to DATADIR/clipit/history */
void save_history()
{
/* Check that the directory is available */
check_dirs();
/* Build file path */
gchar *history_path = g_build_filename(g_get_home_dir(),
gchar *history_path = g_build_filename(g_get_user_data_dir(),
HISTORY_FILE,
NULL);
/* Open the file for writing */

View File

@ -24,7 +24,7 @@
G_BEGIN_DECLS
#define HISTORY_FILE ".local/share/clipit/history"
#define HISTORY_FILE "clipit/history"
/* Set maximum size of one clipboard entry to 1024KB (1MB)
* 1024 pages × 2000 characters per page - should be more than enough.

View File

@ -450,7 +450,7 @@ static gboolean show_actions_menu(gpointer data)
/* -------------------- */
gtk_menu_shell_append((GtkMenuShell*)menu, gtk_separator_menu_item_new());
/* Actions */
gchar* path = g_build_filename(g_get_home_dir(), ACTIONS_FILE, NULL);
gchar* path = g_build_filename(g_get_user_data_dir(), ACTIONS_FILE, NULL);
FILE* actions_file = fopen(path, "rb");
g_free(path);
/* Check that it opened and begin read */
@ -746,8 +746,10 @@ static void show_clipit_menu(GtkStatusIcon *status_icon, guint button, guint act
g_signal_connect((GObject*)menu_item, "activate", (GCallback)show_history_menu_full, NULL);
gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
}
/* Search */
menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_FIND, NULL);
/* Manage history */
menu_item = gtk_image_menu_item_new_with_mnemonic(_("_Manage history"));
menu_image = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image((GtkImageMenuItem*)menu_item, menu_image);
g_signal_connect((GObject*)menu_item, "activate", (GCallback)show_search, NULL);
gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
/* Preferences */

View File

@ -102,7 +102,7 @@ static void apply_preferences()
truncate_history();
}
/* Save preferences to ~/.config/clipit/clipitrc */
/* Save preferences to CONFIGDIR/clipit/clipitrc */
static void save_preferences()
{
/* Create key */
@ -133,16 +133,81 @@ static void save_preferences()
/* Check config and data directories */
check_dirs();
/* Save key to file */
gchar* rc_file = g_build_filename(g_get_home_dir(), PREFERENCES_FILE, NULL);
gchar* rc_file = g_build_filename(g_get_user_config_dir(), PREFERENCES_FILE, NULL);
g_file_set_contents(rc_file, g_key_file_to_data(rc_key, NULL, NULL), -1, NULL);
g_key_file_free(rc_key);
g_free(rc_file);
}
/* Read ~/.config/clipit/clipitrc */
/* This will be run if there is no config file */
static void first_run_check()
{
/* If the configfile doesn't exist, we ask the user if he wants to save the history */
gchar *rc_file = g_build_filename(g_get_user_config_dir(), PREFERENCES_FILE, NULL);
/* Check if config file exists */
if (!g_file_test(rc_file, G_FILE_TEST_EXISTS))
{
GtkWidget* confirm_dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_OTHER,
GTK_BUTTONS_YES_NO,
SAVE_HIST_MESSAGE);
gtk_window_set_title((GtkWindow*)confirm_dialog, "Save history");
if (gtk_dialog_run((GtkDialog*)confirm_dialog) == GTK_RESPONSE_YES)
{
prefs.save_history = TRUE;
} else {
prefs.save_history = FALSE;
}
gtk_widget_destroy(confirm_dialog);
/* We make sure these aren't empty */
prefs.history_key = DEF_HISTORY_KEY;
prefs.actions_key = DEF_ACTIONS_KEY;
prefs.menu_key = DEF_MENU_KEY;
prefs.search_key = DEF_SEARCH_KEY;
save_preferences();
}
}
/* Ask the user if he wants to delete the history file and act accordingly */
static void check_saved_hist_file()
{
/* If the history file doesn't exist, there's nothing to do here */
gchar *history_path = g_build_filename(g_get_user_data_dir(), HISTORY_FILE, NULL);
/* Check if config file exists */
if (g_file_test(history_path, G_FILE_TEST_EXISTS))
{
GtkWidget* confirm_dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_OTHER,
GTK_BUTTONS_YES_NO,
CHECK_HIST_MESSAGE);
gtk_window_set_title((GtkWindow*)confirm_dialog, "Remove history file");
if (gtk_dialog_run((GtkDialog*)confirm_dialog) == GTK_RESPONSE_YES)
{
/* Open the file for writing */
FILE *history_file = fopen(history_path, "wb");
g_free(history_path);
/* Check that it opened and begin write */
if (history_file)
{
/* Write 0 to indicate end of file */
gint end = 0;
fwrite(&end, 4, 1, history_file);
fclose(history_file);
}
}
gtk_widget_destroy(confirm_dialog);
}
}
/* Read CONFIGDIR/clipit/clipitrc */
void read_preferences()
{
gchar* rc_file = g_build_filename(g_get_home_dir(), PREFERENCES_FILE, NULL);
first_run_check();
gchar* rc_file = g_build_filename(g_get_user_config_dir(), PREFERENCES_FILE, NULL);
/* Create key */
GKeyFile* rc_key = g_key_file_new();
if (g_key_file_load_from_file(rc_key, rc_file, G_KEY_FILE_NONE, NULL))
@ -199,11 +264,11 @@ void read_preferences()
g_free(rc_file);
}
/* Read ~/.clipit/actions into the treeview */
/* Read DATADIR/clipit/actions into the treeview */
static void read_actions()
{
/* Open the file for reading */
gchar* path = g_build_filename(g_get_home_dir(), ACTIONS_FILE, NULL);
gchar* path = g_build_filename(g_get_user_data_dir(), ACTIONS_FILE, NULL);
FILE* actions_file = fopen(path, "rb");
g_free(path);
/* Check that it opened and begin read */
@ -238,13 +303,13 @@ static void read_actions()
}
}
/* Save the actions treeview to ~/.local/share/clipit/actions */
/* Save the actions treeview to DATADIR/clipit/actions */
static void save_actions()
{
/* Check config and data directories */
check_dirs();
/* Open the file for writing */
gchar* path = g_build_filename(g_get_home_dir(), ACTIONS_FILE, NULL);
gchar* path = g_build_filename(g_get_user_data_dir(), ACTIONS_FILE, NULL);
FILE* actions_file = fopen(path, "wb");
g_free(path);
/* Check that it opened and begin write */
@ -407,11 +472,11 @@ static void edit_action(GtkCellRendererText *renderer, gchar *path,
/* exclude Functions */
/* Read ~/.clipit/excludes into the treeview */
/* Read DATADIR/clipit/excludes into the treeview */
static void read_excludes()
{
/* Open the file for reading */
gchar* path = g_build_filename(g_get_home_dir(), EXCLUDES_FILE, NULL);
gchar* path = g_build_filename(g_get_user_data_dir(), EXCLUDES_FILE, NULL);
FILE* excludes_file = fopen(path, "rb");
g_free(path);
/* Check that it opened and begin read */
@ -440,13 +505,13 @@ static void read_excludes()
}
}
/* Save the actions treeview to ~/.local/share/clipit/excludes */
/* Save the actions treeview to DATADIR/clipit/excludes */
static void save_excludes()
{
/* Check config and data directories */
check_dirs();
/* Open the file for writing */
gchar* path = g_build_filename(g_get_home_dir(), EXCLUDES_FILE, NULL);
gchar* path = g_build_filename(g_get_user_data_dir(), EXCLUDES_FILE, NULL);
FILE* excludes_file = fopen(path, "wb");
g_free(path);
/* Check that it opened and begin write */
@ -823,13 +888,6 @@ void show_preferences(gint tab)
tree_column = gtk_tree_view_column_new_with_attributes(_("Regex"), name_renderer_exclude, "text", 0, NULL);
gtk_tree_view_column_set_resizable(tree_column, TRUE);
gtk_tree_view_append_column((GtkTreeView*)treeview_exclude, tree_column);
/* GtkCellRenderer* command_renderer_exclude = gtk_cell_renderer_text_new();
g_object_set(command_renderer_exclude, "editable", TRUE, NULL);
g_object_set(command_renderer_exclude, "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
g_signal_connect((GObject*)command_renderer_exclude, "edited", (GCallback)edit_action, (gpointer)1);
tree_column = gtk_tree_view_column_new_with_attributes(_("Command"), command_renderer_exclude, "text", 1, NULL);
gtk_tree_view_column_set_expand(tree_column, TRUE);
gtk_tree_view_append_column((GtkTreeView*)treeview_exclude, tree_column); */
gtk_container_add((GtkContainer*)scrolled_window_exclude, treeview_exclude);
gtk_box_pack_start((GtkBox*)vbox_exclude, scrolled_window_exclude, TRUE, TRUE, 0);
@ -939,6 +997,9 @@ void show_preferences(gint tab)
gtk_notebook_set_current_page((GtkNotebook*)notebook, tab);
if (gtk_dialog_run((GtkDialog*)dialog) == GTK_RESPONSE_ACCEPT)
{
/* If the user disabled history saving, we ask him if he wants to delete the history file */
if(prefs.save_history && !gtk_toggle_button_get_active((GtkToggleButton*)save_check))
check_saved_hist_file();
/* Apply and save preferences */
apply_preferences();
save_preferences();

View File

@ -51,10 +51,17 @@ G_BEGIN_DECLS
#define DEF_SEARCH_KEY "<Ctrl><Alt>F"
#define DEF_NO_ICON FALSE
#define ACTIONS_FILE ".local/share/clipit/actions"
#define EXCLUDES_FILE ".local/share/clipit/excludes"
#define PREFERENCES_FILE ".config/clipit/clipitrc"
#define THEMES_FOLDER ".config/clipit/themes"
#define ACTIONS_FILE "clipit/actions"
#define EXCLUDES_FILE "clipit/excludes"
#define PREFERENCES_FILE "clipit/clipitrc"
#define THEMES_FOLDER "clipit/themes"
#define SAVE_HIST_MESSAGE "ClipIt can save your history in a plain text file. If you copy \
passwords or other sensible data and other people have access to the computer, this might be a \
security risk. Do you want to enable history saving?"
#define CHECK_HIST_MESSAGE "It appears that you have disabled history saving, the current history \
file still exists though. Do you want to empty the current history file?"
void read_preferences();

View File

@ -31,8 +31,8 @@
void
check_dirs()
{
gchar *data_dir = g_build_path("/", g_get_home_dir(), DATA_DIR, NULL);
gchar *config_dir = g_build_path("/", g_get_home_dir(), CONFIG_DIR, NULL);
gchar *data_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_user_data_dir(), DATA_DIR, NULL);
gchar *config_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), CONFIG_DIR, NULL);
/* Check if data directory exists */
if (!g_file_test(data_dir, G_FILE_TEST_EXISTS))
{
@ -71,7 +71,7 @@ is_hyperlink(gchar *text)
gboolean is_excluded(gchar *text)
{
/* Open the file for reading */
gchar *path = g_build_filename(g_get_home_dir(), EXCLUDES_FILE, NULL);
gchar *path = g_build_filename(g_get_user_data_dir(), EXCLUDES_FILE, NULL);
FILE *excludes_file = fopen(path, "rb");
g_free(path);
/* Check that it opened and begin read */

View File

@ -24,8 +24,8 @@
G_BEGIN_DECLS
#define CONFIG_DIR ".local/share/clipit"
#define DATA_DIR ".config/clipit"
#define CONFIG_DIR "clipit"
#define DATA_DIR "clipit"
void check_dirs();