ClipIt-v1.3.2-22112010001

+ Fixed: Fixed most of the markup and indentation (replaced double spaces
		with tabs).
+ Fixed: Removed clipboard restoring from history, as this seems to cause
		more problems than it solves.
This commit is contained in:
Cristian Henzel 2010-11-22 10:59:01 +02:00 committed by Cristian Henzel
parent cba465c964
commit 85d1ec0416
15 changed files with 556 additions and 676 deletions

View File

@ -1,3 +1,9 @@
ClipIt-v1.3.2-22112010001 - 22 Nov. 2010
+ Fixed: Fixed most of the markup and indentation (replaced double spaces
with tabs).
+ Fixed: Removed clipboard restoring from history, as this seems to cause
more problems than it solves.
ClipIt-v1.3.1-17112010001 - 17 Nov. 2010 ClipIt-v1.3.1-17112010001 - 17 Nov. 2010
+ Added: Added autostart support for LXDE. + Added: Added autostart support for LXDE.
+ Fixed: Fixed problem with "Edit" window not appearing. + Fixed: Fixed problem with "Edit" window not appearing.

View File

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

View File

@ -32,8 +32,7 @@ static GtkClipboard* clipboard;
/* Called during the daemon loop to protect primary/clipboard contents */ /* Called during the daemon loop to protect primary/clipboard contents */
static void static void daemon_check()
daemon_check()
{ {
/* Get current primary/clipboard contents */ /* Get current primary/clipboard contents */
gchar *primary_temp = gtk_clipboard_wait_for_text(primary); gchar *primary_temp = gtk_clipboard_wait_for_text(primary);
@ -84,8 +83,7 @@ daemon_check()
} }
/* Called if timeout was destroyed */ /* Called if timeout was destroyed */
static void static void reset_daemon(gpointer data)
reset_daemon(gpointer data)
{ {
if (timeout_id != 0) if (timeout_id != 0)
g_source_remove(timeout_id); g_source_remove(timeout_id);
@ -98,8 +96,7 @@ reset_daemon(gpointer data)
} }
/* Initializes daemon mode */ /* Initializes daemon mode */
void void init_daemon_mode()
init_daemon_mode()
{ {
/* Create clipboard and primary and connect signals */ /* Create clipboard and primary and connect signals */
primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY); primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY);

View File

@ -26,8 +26,7 @@ G_BEGIN_DECLS
#define DAEMON_INTERVAL 500 #define DAEMON_INTERVAL 500
void void init_daemon_mode();
init_daemon_mode();
G_END_DECLS G_END_DECLS

View File

@ -29,8 +29,7 @@
GSList *history; GSList *history;
/* Reads history from ~/.local/share/clipit/history */ /* Reads history from ~/.local/share/clipit/history */
void void read_history ()
read_history ()
{ {
/* Build file path */ /* Build file path */
gchar *history_path = g_build_filename(g_get_home_dir(), gchar *history_path = g_build_filename(g_get_home_dir(),
@ -68,8 +67,7 @@ read_history ()
} }
/* Saves history to ~/.local/share/clipit/history */ /* Saves history to ~/.local/share/clipit/history */
void void save_history()
save_history()
{ {
/* Check that the directory is available */ /* Check that the directory is available */
check_dirs(); check_dirs();
@ -87,8 +85,9 @@ save_history()
/* Write each element to a binary file */ /* Write each element to a binary file */
for (element = history; element != NULL; element = element->next) for (element = history; element != NULL; element = element->next)
{ {
/* Create new GString from element data, write its length (size) /* Create new GString from element data, write its
* to file followed by the element data itself * length (size) to file followed by the element
* data itself
*/ */
GString *item = g_string_new((gchar*)element->data); GString *item = g_string_new((gchar*)element->data);
fwrite(&(item->len), 4, 1, history_file); fwrite(&(item->len), 4, 1, history_file);
@ -103,8 +102,7 @@ save_history()
} }
/* Checks if item should be included in history and calls append */ /* Checks if item should be included in history and calls append */
void void check_and_append(gchar *item)
check_and_append(gchar* item)
{ {
if (item) if (item)
{ {
@ -129,12 +127,12 @@ check_and_append(gchar* item)
} }
/* Adds item to the end of history */ /* Adds item to the end of history */
void void append_item(gchar *item)
append_item(gchar* item)
{ {
history = g_slist_prepend(history, g_strdup(item)); history = g_slist_prepend(history, g_strdup(item));
/* Shorten history if necessary */ /* Shorten history if necessary */
GSList* last_possible_element = g_slist_nth(history, prefs.history_limit - 1); GSList *last_possible_element = g_slist_nth(history,
prefs.history_limit - 1);
if (last_possible_element) if (last_possible_element)
{ {
/* Free last posible element and subsequent elements */ /* Free last posible element and subsequent elements */
@ -147,13 +145,13 @@ append_item(gchar* item)
} }
/* Truncates history to history_limit items */ /* Truncates history to history_limit items */
void void truncate_history()
truncate_history()
{ {
if (history) if (history)
{ {
/* Shorten history if necessary */ /* Shorten history if necessary */
GSList* last_possible_element = g_slist_nth(history, prefs.history_limit - 1); GSList *last_possible_element = g_slist_nth(history,
prefs.history_limit - 1);
if (last_possible_element) if (last_possible_element)
{ {
/* Free last posible element and subsequent elements */ /* Free last posible element and subsequent elements */
@ -167,8 +165,7 @@ truncate_history()
} }
/* Returns pointer to last item in history */ /* Returns pointer to last item in history */
gpointer gpointer get_last_item()
get_last_item()
{ {
if (history) if (history)
{ {
@ -186,8 +183,7 @@ get_last_item()
} }
/* Deletes duplicate item in history */ /* Deletes duplicate item in history */
void void delete_duplicate(gchar *item)
delete_duplicate(gchar* item)
{ {
GSList *element; GSList *element;
/* Go through each element compare each */ /* Go through each element compare each */

View File

@ -25,6 +25,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define HISTORY_FILE ".local/share/clipit/history" #define HISTORY_FILE ".local/share/clipit/history"
/* Set maximum size of one clipboard entry to 1024KB (1MB) /* Set maximum size of one clipboard entry to 1024KB (1MB)
* 1024 pages × 2000 characters per page - should be more than enough. * 1024 pages × 2000 characters per page - should be more than enough.
* WARNING: if you use all 1000 history items, clipit could use up to * WARNING: if you use all 1000 history items, clipit could use up to
@ -33,26 +34,19 @@ G_BEGIN_DECLS
extern GSList* history; extern GSList* history;
void void read_history();
read_history();
void void save_history();
save_history();
void void check_and_append(gchar* item);
check_and_append(gchar* item);
void void append_item(gchar* item);
append_item(gchar* item);
void void truncate_history();
truncate_history();
gpointer gpointer get_last_item();
get_last_item();
void void delete_duplicate(gchar* item);
delete_duplicate(gchar* item);
G_END_DECLS G_END_DECLS

View File

@ -55,8 +55,7 @@ prefs_t prefs = {DEF_USE_COPY, DEF_USE_PRIMARY, DEF_SYNCHRONIZE,
INIT_MENU_KEY, INIT_SEARCH_KEY, DEF_NO_ICON}; INIT_MENU_KEY, INIT_SEARCH_KEY, DEF_NO_ICON};
/* Called every CHECK_INTERVAL seconds to check for new items */ /* Called every CHECK_INTERVAL seconds to check for new items */
static gboolean static gboolean item_check(gpointer data)
item_check(gpointer data)
{ {
/* Grab the current primary and clipboard text */ /* Grab the current primary and clipboard text */
gchar* primary_temp = gtk_clipboard_wait_for_text(primary); gchar* primary_temp = gtk_clipboard_wait_for_text(primary);
@ -80,12 +79,13 @@ item_check(gpointer data)
/* if use_primary is enabled, we restore from primary */ /* if use_primary is enabled, we restore from primary */
gtk_clipboard_set_text(primary, primary_text, -1); gtk_clipboard_set_text(primary, primary_text, -1);
} }
else /* else
{ * {
/* else, we restore from history */ * /* else, we restore from history
GSList* element = g_slist_nth(history, 0); * GSList* element = g_slist_nth(history, 0);
gtk_clipboard_set_text(primary, (gchar*)element->data, -1); * gtk_clipboard_set_text(primary, (gchar*)element->data, -1);
} * }
*/
} }
} }
else else
@ -186,8 +186,7 @@ item_check(gpointer data)
} }
/* Thread function called for each action performed */ /* Thread function called for each action performed */
static void * static void *execute_action(void *command)
execute_action(void *command)
{ {
/* Execute action */ /* Execute action */
int sys_return; int sys_return;
@ -210,8 +209,7 @@ execute_action(void *command)
} }
/* Called when execution action exits */ /* Called when execution action exits */
static void static void action_exit(GPid pid, gint status, gpointer data)
action_exit(GPid pid, gint status, gpointer data)
{ {
g_spawn_close_pid(pid); g_spawn_close_pid(pid);
if (!prefs.no_icon) if (!prefs.no_icon)
@ -223,8 +221,7 @@ action_exit(GPid pid, gint status, gpointer data)
} }
/* Called when an action is selected from actions menu */ /* Called when an action is selected from actions menu */
static void static void action_selected(GtkButton *button, gpointer user_data)
action_selected(GtkButton *button, gpointer user_data)
{ {
/* Change icon and enable lock */ /* Change icon and enable lock */
actions_lock = TRUE; actions_lock = TRUE;
@ -255,8 +252,7 @@ action_selected(GtkButton *button, gpointer user_data)
} }
/* Called when Edit Actions is selected from actions menu */ /* Called when Edit Actions is selected from actions menu */
static void static void edit_actions_selected(GtkButton *button, gpointer user_data)
edit_actions_selected(GtkButton *button, gpointer user_data)
{ {
/* This helps prevent multiple instances */ /* This helps prevent multiple instances */
if (!gtk_grab_get_current()) if (!gtk_grab_get_current())
@ -275,8 +271,7 @@ item_selected(GtkMenuItem *menu_item, gpointer user_data)
} }
/* Called when Clear is selected from history menu */ /* Called when Clear is selected from history menu */
static void static void clear_selected(GtkMenuItem *menu_item, gpointer user_data)
clear_selected(GtkMenuItem *menu_item, gpointer user_data)
{ {
/* Check for confirm clear option */ /* Check for confirm clear option */
if (prefs.confirm_clear) if (prefs.confirm_clear)
@ -323,8 +318,7 @@ clear_selected(GtkMenuItem *menu_item, gpointer user_data)
} }
/* Called when About is selected from right-click menu */ /* Called when About is selected from right-click menu */
static void static void show_about_dialog(GtkMenuItem *menu_item, gpointer user_data)
show_about_dialog(GtkMenuItem *menu_item, gpointer user_data)
{ {
/* This helps prevent multiple instances */ /* This helps prevent multiple instances */
if (!gtk_grab_get_current()) if (!gtk_grab_get_current())
@ -391,8 +385,7 @@ show_about_dialog(GtkMenuItem *menu_item, gpointer user_data)
} }
/* Called when Preferences is selected from right-click menu */ /* Called when Preferences is selected from right-click menu */
static void static void preferences_selected(GtkMenuItem *menu_item, gpointer user_data)
preferences_selected(GtkMenuItem *menu_item, gpointer user_data)
{ {
/* This helps prevent multiple instances */ /* This helps prevent multiple instances */
if (!gtk_grab_get_current()) if (!gtk_grab_get_current())
@ -401,8 +394,7 @@ preferences_selected(GtkMenuItem *menu_item, gpointer user_data)
} }
/* Called when Quit is selected from right-click menu */ /* Called when Quit is selected from right-click menu */
static void static void quit_selected(GtkMenuItem *menu_item, gpointer user_data)
quit_selected(GtkMenuItem *menu_item, gpointer user_data)
{ {
/* Prevent quit with dialogs open */ /* Prevent quit with dialogs open */
if (!gtk_grab_get_current()) if (!gtk_grab_get_current())
@ -411,8 +403,7 @@ quit_selected(GtkMenuItem *menu_item, gpointer user_data)
} }
/* Called when status icon is control-clicked */ /* Called when status icon is control-clicked */
static gboolean static gboolean show_actions_menu(gpointer data)
show_actions_menu(gpointer data)
{ {
/* Declare some variables */ /* Declare some variables */
GtkWidget *menu, *menu_item, GtkWidget *menu, *menu_item,
@ -521,8 +512,7 @@ show_actions_menu(gpointer data)
return FALSE; return FALSE;
} }
static gboolean static gboolean show_history_menu_full(gpointer data)
show_history_menu_full(gpointer data)
{ {
/* Declare some variables */ /* Declare some variables */
GtkWidget *menu, *menu_item, GtkWidget *menu, *menu_item,
@ -550,32 +540,9 @@ show_history_menu_full(gpointer data)
{ {
GString* string = g_string_new((gchar*)element->data); GString* string = g_string_new((gchar*)element->data);
/* Ellipsize text */ /* Ellipsize text */
if (string->len > prefs.item_length) string = ellipsize_string(string);
{
switch (prefs.ellipsize)
{
case PANGO_ELLIPSIZE_START:
string = g_string_erase(string, 0, string->len-(prefs.item_length));
string = g_string_prepend(string, "...");
break;
case PANGO_ELLIPSIZE_MIDDLE:
string = g_string_erase(string, (prefs.item_length/2), string->len-(prefs.item_length));
string = g_string_insert(string, (string->len/2), "...");
break;
case PANGO_ELLIPSIZE_END:
string = g_string_truncate(string, prefs.item_length);
string = g_string_append(string, "...");
break;
}
}
/* Remove control characters */ /* Remove control characters */
int i = 0; string = remove_newlines_string(string);
while (i < string->len)
{
if (string->str[i] == '\n')
g_string_overwrite(string, i, " ");
i++;
}
/* Make new item with ellipsized text */ /* Make new item with ellipsized text */
gchar* list_item; gchar* list_item;
if (prefs.show_indexes) if (prefs.show_indexes)
@ -642,8 +609,7 @@ show_history_menu_full(gpointer data)
} }
/* Generates the small history menu */ /* Generates the small history menu */
static gboolean static gboolean show_history_menu_small(gpointer data)
show_history_menu_small(gpointer data)
{ {
/* Declare some variables */ /* Declare some variables */
GtkWidget *menu, *menu_item, GtkWidget *menu, *menu_item,
@ -672,32 +638,9 @@ show_history_menu_small(gpointer data)
{ {
GString* string = g_string_new((gchar*)element->data); GString* string = g_string_new((gchar*)element->data);
/* Ellipsize text */ /* Ellipsize text */
if (string->len > prefs.item_length) string = ellipsize_string(string);
{
switch (prefs.ellipsize)
{
case PANGO_ELLIPSIZE_START:
string = g_string_erase(string, 0, string->len-(prefs.item_length));
string = g_string_prepend(string, "...");
break;
case PANGO_ELLIPSIZE_MIDDLE:
string = g_string_erase(string, (prefs.item_length/2), string->len-(prefs.item_length));
string = g_string_insert(string, (string->len/2), "...");
break;
case PANGO_ELLIPSIZE_END:
string = g_string_truncate(string, prefs.item_length);
string = g_string_append(string, "...");
break;
}
}
/* Remove control characters */ /* Remove control characters */
int i = 0; string = remove_newlines_string(string);
while (i < string->len)
{
if (string->str[i] == '\n')
g_string_overwrite(string, i, " ");
i++;
}
/* Make new item with ellipsized text */ /* Make new item with ellipsized text */
gchar* list_item; gchar* list_item;
if (prefs.show_indexes) if (prefs.show_indexes)
@ -771,8 +714,7 @@ show_history_menu_small(gpointer data)
} }
/* Called when status icon is left-clicked */ /* Called when status icon is left-clicked */
static gboolean static gboolean show_history_menu()
show_history_menu()
{ {
if (prefs.small_history) if (prefs.small_history)
g_timeout_add(POPUP_DELAY, show_history_menu_small, NULL); g_timeout_add(POPUP_DELAY, show_history_menu_small, NULL);
@ -783,8 +725,7 @@ show_history_menu()
} }
/* Called when status icon is right-clicked */ /* Called when status icon is right-clicked */
static void static void show_clipit_menu(GtkStatusIcon *status_icon, guint button, guint activate_time)
show_clipit_menu(GtkStatusIcon *status_icon, guint button, guint activate_time)
{ {
/* Declare some variables */ /* Declare some variables */
GtkWidget *menu, *menu_item, GtkWidget *menu, *menu_item,
@ -827,8 +768,7 @@ show_clipit_menu(GtkStatusIcon *status_icon, guint button, guint activate_time)
/* Called when status icon is clicked */ /* Called when status icon is clicked */
/* (checks type of click and calls correct function */ /* (checks type of click and calls correct function */
static void static void status_icon_clicked(GtkStatusIcon *status_icon, GdkEventButton *event )
status_icon_clicked(GtkStatusIcon *status_icon, GdkEventButton *event )
{ {
/* Check what type of click was recieved */ /* Check what type of click was recieved */
GdkModifierType state; GdkModifierType state;
@ -841,11 +781,12 @@ status_icon_clicked(GtkStatusIcon *status_icon, GdkEventButton *event )
g_timeout_add(POPUP_DELAY, show_actions_menu, NULL); g_timeout_add(POPUP_DELAY, show_actions_menu, NULL);
} }
} }
/* Normal click */ /* Left click */
else if (event->button == 1) else if (event->button == 1)
{ {
show_history_menu(); show_history_menu();
} }
/* Right click */
else else
{ {
show_clipit_menu(status_icon, event->button, gtk_get_current_event_time()); show_clipit_menu(status_icon, event->button, gtk_get_current_event_time());
@ -853,36 +794,31 @@ status_icon_clicked(GtkStatusIcon *status_icon, GdkEventButton *event )
} }
/* Called when history global hotkey is pressed */ /* Called when history global hotkey is pressed */
void void history_hotkey(char *keystring, gpointer user_data)
history_hotkey(char *keystring, gpointer user_data)
{ {
g_timeout_add(POPUP_DELAY, show_history_menu, NULL); g_timeout_add(POPUP_DELAY, show_history_menu, NULL);
} }
/* Called when actions global hotkey is pressed */ /* Called when actions global hotkey is pressed */
void void actions_hotkey(char *keystring, gpointer user_data)
actions_hotkey(char *keystring, gpointer user_data)
{ {
g_timeout_add(POPUP_DELAY, show_actions_menu, NULL); g_timeout_add(POPUP_DELAY, show_actions_menu, NULL);
} }
/* Called when actions global hotkey is pressed */ /* Called when actions global hotkey is pressed */
void void menu_hotkey(char *keystring, gpointer user_data)
menu_hotkey(char *keystring, gpointer user_data)
{ {
show_clipit_menu(status_icon, 0, 0); show_clipit_menu(status_icon, 0, 0);
} }
/* Called when search global hotkey is pressed */ /* Called when search global hotkey is pressed */
void void search_hotkey(char *keystring, gpointer user_data)
search_hotkey(char *keystring, gpointer user_data)
{ {
g_timeout_add(POPUP_DELAY, show_search, NULL); g_timeout_add(POPUP_DELAY, show_search, NULL);
} }
/* Startup calls and initializations */ /* Startup calls and initializations */
static void static void clipit_init()
clipit_init()
{ {
/* Create clipboard */ /* Create clipboard */
primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY); primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
@ -913,8 +849,7 @@ clipit_init()
} }
/* This is Sparta! */ /* This is Sparta! */
int int main(int argc, char *argv[])
main(int argc, char *argv[])
{ {
bindtextdomain(GETTEXT_PACKAGE, CLIPITLOCALEDIR); bindtextdomain(GETTEXT_PACKAGE, CLIPITLOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");

View File

@ -65,17 +65,13 @@ prefs_t;
extern prefs_t prefs; extern prefs_t prefs;
void void history_hotkey(char *keystring, gpointer user_data);
history_hotkey(char *keystring, gpointer user_data);
void void actions_hotkey(char *keystring, gpointer user_data);
actions_hotkey(char *keystring, gpointer user_data);
void void menu_hotkey(char *keystring, gpointer user_data);
menu_hotkey(char *keystring, gpointer user_data);
void void search_hotkey(char *keystring, gpointer user_data);
search_hotkey(char *keystring, gpointer user_data);
G_END_DECLS G_END_DECLS

View File

@ -34,8 +34,7 @@ GtkWidget *search_entry;
GtkWidget* treeview_search; GtkWidget* treeview_search;
/* Search through the history */ /* Search through the history */
static void static void search_history()
search_history()
{ {
guint16 search_len = gtk_entry_get_text_length((GtkEntry*)search_entry); guint16 search_len = gtk_entry_get_text_length((GtkEntry*)search_entry);
/* Test if there is text in the search box */ /* Test if there is text in the search box */
@ -62,31 +61,8 @@ search_history()
{ {
GtkTreeIter row_iter; GtkTreeIter row_iter;
gtk_list_store_append(search_list, &row_iter); gtk_list_store_append(search_list, &row_iter);
if (string->len > prefs.item_length) string = ellipsize_string(string);
{ string = remove_newlines_string(string);
switch (prefs.ellipsize)
{
case PANGO_ELLIPSIZE_START:
string = g_string_erase(string, 0, string->len-(prefs.item_length));
string = g_string_prepend(string, "...");
break;
case PANGO_ELLIPSIZE_MIDDLE:
string = g_string_erase(string, (prefs.item_length/2), string->len-(prefs.item_length));
string = g_string_insert(string, (string->len/2), "...");
break;
case PANGO_ELLIPSIZE_END:
string = g_string_truncate(string, prefs.item_length);
string = g_string_append(string, "...");
break;
}
}
int i = 0;
while (i < string->len)
{
if (string->str[i] == '\n')
g_string_overwrite(string, i, " ");
i++;
}
int row_num = g_slist_position(history, element); int row_num = g_slist_position(history, element);
gtk_list_store_set(search_list, &row_iter, 0, row_num, 1, string->str, -1); gtk_list_store_set(search_list, &row_iter, 0, row_num, 1, string->str, -1);
} }
@ -114,31 +90,8 @@ search_history()
GString *string = g_string_new((gchar*)element->data); GString *string = g_string_new((gchar*)element->data);
GtkTreeIter row_iter; GtkTreeIter row_iter;
gtk_list_store_append(search_list, &row_iter); gtk_list_store_append(search_list, &row_iter);
if (string->len > prefs.item_length) string = ellipsize_string(string);
{ string = remove_newlines_string(string);
switch (prefs.ellipsize)
{
case PANGO_ELLIPSIZE_START:
string = g_string_erase(string, 0, string->len-(prefs.item_length));
string = g_string_prepend(string, "...");
break;
case PANGO_ELLIPSIZE_MIDDLE:
string = g_string_erase(string, (prefs.item_length/2), string->len-(prefs.item_length));
string = g_string_insert(string, (string->len/2), "...");
break;
case PANGO_ELLIPSIZE_END:
string = g_string_truncate(string, prefs.item_length);
string = g_string_append(string, "...");
break;
}
}
int i = 0;
while (i < string->len)
{
if (string->str[i] == '\n')
g_string_overwrite(string, i, " ");
i++;
}
int row_num = g_slist_position(history, element); int row_num = g_slist_position(history, element);
gtk_list_store_set(search_list, &row_iter, 0, row_num, 1, string->str, -1); gtk_list_store_set(search_list, &row_iter, 0, row_num, 1, string->str, -1);
@ -150,8 +103,7 @@ search_history()
} }
/* Called when Edit is selected from Manage dialog */ /* Called when Edit is selected from Manage dialog */
static void static void edit_selected()
edit_selected()
{ {
GtkTreeIter sel_iter; GtkTreeIter sel_iter;
GtkTreeSelection* search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search); GtkTreeSelection* search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search);
@ -201,8 +153,7 @@ edit_selected()
/* Insert new element before the old one */ /* Insert new element before the old one */
history = g_slist_insert_before(history, element->next, history = g_slist_insert_before(history, element->next,
g_strdup(gtk_text_buffer_get_text(clipboard_buffer, &start, &end, TRUE)) g_strdup(gtk_text_buffer_get_text(clipboard_buffer, &start, &end, TRUE)));
);
/* Remove old entry */ /* Remove old entry */
history = g_slist_remove(history, element->data); history = g_slist_remove(history, element->data);
@ -213,8 +164,7 @@ edit_selected()
clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text(clipboard, gtk_clipboard_set_text(clipboard,
gtk_text_buffer_get_text(clipboard_buffer, &start, &end, TRUE), gtk_text_buffer_get_text(clipboard_buffer, &start, &end, TRUE),
-1 -1);
);
} }
} }
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
@ -224,8 +174,7 @@ edit_selected()
} }
/* Called when Remove is selected from Manage dialog */ /* Called when Remove is selected from Manage dialog */
static void static void remove_selected()
remove_selected()
{ {
GtkTreeIter sel_iter; GtkTreeIter sel_iter;
GtkTreeSelection* search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search); GtkTreeSelection* search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search);
@ -242,8 +191,7 @@ remove_selected()
} }
} }
static void static void search_doubleclick()
search_doubleclick()
{ {
GtkTreeIter sel_iter; GtkTreeIter sel_iter;
GtkTreeSelection* search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search); GtkTreeSelection* search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search);
@ -260,8 +208,7 @@ search_doubleclick()
} }
} }
gint gint search_click(GtkWidget *widget, GdkEventButton *event, GtkWidget *search_window)
search_click(GtkWidget *widget, GdkEventButton *event, GtkWidget *search_window)
{ {
if(event->type==GDK_2BUTTON_PRESS || event->type==GDK_3BUTTON_PRESS) if(event->type==GDK_2BUTTON_PRESS || event->type==GDK_3BUTTON_PRESS)
{ {
@ -271,8 +218,7 @@ search_click(GtkWidget *widget, GdkEventButton *event, GtkWidget *search_window)
return FALSE; return FALSE;
} }
static gint static gint search_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
search_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{ {
/* Check if [Return] key was pressed */ /* Check if [Return] key was pressed */
if ((event->keyval == 0xff0d) || (event->keyval == 0xff8d)) if ((event->keyval == 0xff0d) || (event->keyval == 0xff8d))
@ -280,8 +226,7 @@ search_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
return FALSE; return FALSE;
} }
void void search_window_response(GtkDialog *dialog, gint response_id, gpointer user_data)
search_window_response(GtkDialog *dialog, gint response_id, gpointer user_data)
{ {
if(response_id < 0) if(response_id < 0)
{ {
@ -291,8 +236,7 @@ search_window_response(GtkDialog *dialog, gint response_id, gpointer user_data)
} }
/* Shows the search dialog */ /* Shows the search dialog */
gboolean gboolean show_search()
show_search()
{ {
/* Prevent multiple instances */ /* Prevent multiple instances */
if(gtk_grab_get_current()) if(gtk_grab_get_current())

View File

@ -24,8 +24,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
gboolean gboolean show_search();
show_search();
G_END_DECLS G_END_DECLS

View File

@ -56,8 +56,7 @@ GtkListStore* exclude_list;
GtkTreeSelection* exclude_selection; GtkTreeSelection* exclude_selection;
/* Apply the new preferences */ /* Apply the new preferences */
static void static void apply_preferences()
apply_preferences()
{ {
/* Unbind the keys before binding new ones */ /* Unbind the keys before binding new ones */
keybinder_unbind(prefs.history_key, history_hotkey); keybinder_unbind(prefs.history_key, history_hotkey);
@ -104,8 +103,7 @@ apply_preferences()
} }
/* Save preferences to ~/.config/clipit/clipitrc */ /* Save preferences to ~/.config/clipit/clipitrc */
static void static void save_preferences()
save_preferences()
{ {
/* Create key */ /* Create key */
GKeyFile* rc_key = g_key_file_new(); GKeyFile* rc_key = g_key_file_new();
@ -142,8 +140,7 @@ save_preferences()
} }
/* Read ~/.config/clipit/clipitrc */ /* Read ~/.config/clipit/clipitrc */
void void read_preferences()
read_preferences()
{ {
gchar* rc_file = g_build_filename(g_get_home_dir(), PREFERENCES_FILE, NULL); gchar* rc_file = g_build_filename(g_get_home_dir(), PREFERENCES_FILE, NULL);
/* Create key */ /* Create key */
@ -203,8 +200,7 @@ read_preferences()
} }
/* Read ~/.clipit/actions into the treeview */ /* Read ~/.clipit/actions into the treeview */
static void static void read_actions()
read_actions()
{ {
/* Open the file for reading */ /* Open the file for reading */
gchar* path = g_build_filename(g_get_home_dir(), ACTIONS_FILE, NULL); gchar* path = g_build_filename(g_get_home_dir(), ACTIONS_FILE, NULL);
@ -243,8 +239,7 @@ read_actions()
} }
/* Save the actions treeview to ~/.local/share/clipit/actions */ /* Save the actions treeview to ~/.local/share/clipit/actions */
static void static void save_actions()
save_actions()
{ {
/* Check config and data directories */ /* Check config and data directories */
check_dirs(); check_dirs();
@ -298,8 +293,7 @@ save_actions()
} }
/* Called when clipboard checks are pressed */ /* Called when clipboard checks are pressed */
static void static void check_toggled(GtkToggleButton *togglebutton, gpointer user_data)
check_toggled(GtkToggleButton *togglebutton, gpointer user_data)
{ {
if (gtk_toggle_button_get_active((GtkToggleButton*)copy_check) && if (gtk_toggle_button_get_active((GtkToggleButton*)copy_check) &&
gtk_toggle_button_get_active((GtkToggleButton*)primary_check)) gtk_toggle_button_get_active((GtkToggleButton*)primary_check))
@ -317,8 +311,7 @@ check_toggled(GtkToggleButton *togglebutton, gpointer user_data)
} }
/* Called when Add... button is clicked */ /* Called when Add... button is clicked */
static void static void add_action(GtkButton *button, gpointer user_data)
add_action(GtkButton *button, gpointer user_data)
{ {
/* Append new item */ /* Append new item */
GtkTreeIter row_iter; GtkTreeIter row_iter;
@ -334,8 +327,7 @@ add_action(GtkButton *button, gpointer user_data)
} }
/* Called when Remove button is clicked */ /* Called when Remove button is clicked */
static void static void remove_action(GtkButton *button, gpointer user_data)
remove_action(GtkButton *button, gpointer user_data)
{ {
GtkTreeIter sel_iter; GtkTreeIter sel_iter;
/* Check if selected */ /* Check if selected */
@ -356,8 +348,7 @@ remove_action(GtkButton *button, gpointer user_data)
} }
/* Called when Up button is clicked */ /* Called when Up button is clicked */
static void static void move_action_up(GtkButton *button, gpointer user_data)
move_action_up(GtkButton *button, gpointer user_data)
{ {
GtkTreeIter sel_iter; GtkTreeIter sel_iter;
/* Check if selected */ /* Check if selected */
@ -378,8 +369,7 @@ move_action_up(GtkButton *button, gpointer user_data)
} }
/* Called when Down button is clicked */ /* Called when Down button is clicked */
static void static void move_action_down(GtkButton *button, gpointer user_data)
move_action_down(GtkButton *button, gpointer user_data)
{ {
GtkTreeIter sel_iter; GtkTreeIter sel_iter;
/* Check if selected */ /* Check if selected */
@ -395,8 +385,7 @@ move_action_down(GtkButton *button, gpointer user_data)
} }
/* Called when delete key is pressed */ /* Called when delete key is pressed */
static void static void delete_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
delete_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{ {
/* Check if DEL key was pressed (keyval: 65535) */ /* Check if DEL key was pressed (keyval: 65535) */
if (event->keyval == 65535) if (event->keyval == 65535)
@ -404,8 +393,7 @@ delete_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
} }
/* Called when a cell is edited */ /* Called when a cell is edited */
static void static void edit_action(GtkCellRendererText *renderer, gchar *path,
edit_action(GtkCellRendererText *renderer, gchar *path,
gchar *new_text, gpointer cell) gchar *new_text, gpointer cell)
{ {
GtkTreeIter sel_iter; GtkTreeIter sel_iter;
@ -420,8 +408,7 @@ edit_action(GtkCellRendererText *renderer, gchar *path,
/* exclude Functions */ /* exclude Functions */
/* Read ~/.clipit/excludes into the treeview */ /* Read ~/.clipit/excludes into the treeview */
static void static void read_excludes()
read_excludes()
{ {
/* Open the file for reading */ /* Open the file for reading */
gchar* path = g_build_filename(g_get_home_dir(), EXCLUDES_FILE, NULL); gchar* path = g_build_filename(g_get_home_dir(), EXCLUDES_FILE, NULL);
@ -454,8 +441,7 @@ read_excludes()
} }
/* Save the actions treeview to ~/.local/share/clipit/excludes */ /* Save the actions treeview to ~/.local/share/clipit/excludes */
static void static void save_excludes()
save_excludes()
{ {
/* Check config and data directories */ /* Check config and data directories */
check_dirs(); check_dirs();
@ -503,8 +489,7 @@ save_excludes()
} }
/* Called when Add... button is clicked */ /* Called when Add... button is clicked */
static void static void add_exclude(GtkButton *button, gpointer user_data)
add_exclude(GtkButton *button, gpointer user_data)
{ {
/* Append new item */ /* Append new item */
GtkTreeIter row_iter; GtkTreeIter row_iter;
@ -520,8 +505,7 @@ add_exclude(GtkButton *button, gpointer user_data)
} }
/* Called when Remove button is clicked */ /* Called when Remove button is clicked */
static void static void remove_exclude(GtkButton *button, gpointer user_data)
remove_exclude(GtkButton *button, gpointer user_data)
{ {
GtkTreeIter sel_iter; GtkTreeIter sel_iter;
/* Check if selected */ /* Check if selected */
@ -542,8 +526,7 @@ remove_exclude(GtkButton *button, gpointer user_data)
} }
/* Called when a cell is edited */ /* Called when a cell is edited */
static void static void edit_exclude(GtkCellRendererText *renderer, gchar *path,
edit_exclude(GtkCellRendererText *renderer, gchar *path,
gchar *new_text, gpointer cell) gchar *new_text, gpointer cell)
{ {
GtkTreeIter sel_iter; GtkTreeIter sel_iter;
@ -556,8 +539,7 @@ edit_exclude(GtkCellRendererText *renderer, gchar *path,
} }
/* Shows the preferences dialog on the given tab */ /* Shows the preferences dialog on the given tab */
void void show_preferences(gint tab)
show_preferences(gint tab)
{ {
/* Declare some variables */ /* Declare some variables */
GtkWidget *frame, *label, GtkWidget *frame, *label,

View File

@ -56,11 +56,9 @@ G_BEGIN_DECLS
#define PREFERENCES_FILE ".config/clipit/clipitrc" #define PREFERENCES_FILE ".config/clipit/clipitrc"
#define THEMES_FOLDER ".config/clipit/themes" #define THEMES_FOLDER ".config/clipit/themes"
void void read_preferences();
read_preferences();
void void show_preferences(gint tab);
show_preferences(gint tab);
G_END_DECLS G_END_DECLS

View File

@ -68,8 +68,7 @@ is_hyperlink(gchar* text)
} }
/* Returns TRUE if text should be excluded from history */ /* Returns TRUE if text should be excluded from history */
gboolean gboolean is_excluded(gchar *text)
is_excluded(gchar* text)
{ {
/* Open the file for reading */ /* Open the file for reading */
gchar *path = g_build_filename(g_get_home_dir(), EXCLUDES_FILE, NULL); gchar *path = g_build_filename(g_get_home_dir(), EXCLUDES_FILE, NULL);
@ -106,11 +105,47 @@ is_excluded(gchar* text)
return FALSE; return FALSE;
} }
/* Ellipsize a string according to the settings */
GString *ellipsize_string(GString *string)
{
if (string->len > prefs.item_length)
{
switch (prefs.ellipsize)
{
case PANGO_ELLIPSIZE_START:
string = g_string_erase(string, 0, string->len-(prefs.item_length));
string = g_string_prepend(string, "...");
break;
case PANGO_ELLIPSIZE_MIDDLE:
string = g_string_erase(string, (prefs.item_length/2), string->len-(prefs.item_length));
string = g_string_insert(string, (string->len/2), "...");
break;
case PANGO_ELLIPSIZE_END:
string = g_string_truncate(string, prefs.item_length);
string = g_string_append(string, "...");
break;
}
}
return string;
}
/* Remove newlines from string */
GString *remove_newlines_string(GString *string)
{
int i = 0;
while (i < string->len)
{
if (string->str[i] == '\n')
g_string_overwrite(string, i, " ");
i++;
}
return string;
}
/* Parses the program arguments. Returns TRUE if program needs /* Parses the program arguments. Returns TRUE if program needs
* to exit after parsing is complete * to exit after parsing is complete
*/ */
gboolean gboolean parse_options(int argc, char* argv[])
parse_options(int argc, char* argv[])
{ {
/* Declare argument options and argument variables */ /* Declare argument options and argument variables */
gboolean icon = FALSE, daemon = FALSE, gboolean icon = FALSE, daemon = FALSE,
@ -207,8 +242,6 @@ parse_options(int argc, char* argv[])
/* Check if anything was piped in */ /* Check if anything was piped in */
if (piped_string->len > 0) if (piped_string->len > 0)
{ {
/* Truncate new line character */
/* g_string_truncate(piped_string, (piped_string->len - 1)); */
/* Copy to clipboard */ /* Copy to clipboard */
gtk_clipboard_set_text(clip, piped_string->str, -1); gtk_clipboard_set_text(clip, piped_string->str, -1);
gtk_clipboard_store(clip); gtk_clipboard_store(clip);

View File

@ -27,14 +27,15 @@ G_BEGIN_DECLS
#define CONFIG_DIR ".local/share/clipit" #define CONFIG_DIR ".local/share/clipit"
#define DATA_DIR ".config/clipit" #define DATA_DIR ".config/clipit"
void void check_dirs();
check_dirs();
gboolean gboolean is_hyperlink(gchar* link);
is_hyperlink(gchar* link);
gboolean GString *ellipsize_string(GString *string);
parse_options(int argc, char* argv[]);
GString *remove_newlines_string(GString *string);
gboolean parse_options(int argc, char* argv[]);
G_END_DECLS G_END_DECLS