Permalink
Browse files

ClipIt-1.4.2-20111222001

+ Added: Merged "Offline mode" feature, by Eugene Nikolsky
+ Added: Allow to switch focus by Tab key in "Manage History"
	dialog, by Eugene Nikolsky
  • Loading branch information...
pluton8 authored and Cristian Henzel committed Dec 4, 2011
1 parent f2254a2 commit 8c267603c9da5e76dee8d688ff56ffe184cc5a68
Showing with 120 additions and 4 deletions.
  1. +26 −0 .gitignore
  2. +1 −0 AUTHORS
  3. +1 −0 README
  4. +44 −2 src/main.c
  5. +6 −0 src/main.h
  6. +10 −1 src/manage.c
  7. +26 −1 src/preferences.c
  8. +6 −0 src/preferences.h
@@ -0,0 +1,26 @@
*.o
*.gmo
*.m4
stamp-h1
src/clipit
src/.deps
config.*
configure
intltool-*
missing
install-sh
po/*.sin
po/*.sed
po/*.header
po/.intltool-merge-cache
depcomp
ABOUT-NLS
po/POTFILES
po/Rules-quot
po/stamp-it
autom4te.cache
data/*.desktop
po/Makevars.template
*~
Makefile
Makefile.in
@@ -1,2 +1,3 @@
Cristian Henzel <oss@rspwn.com>
Gilberto "Xyhthyx" Miralla <xyhthyx@gmail.com>
Eugene Nikolsky <pluton.od@gmail.com>
1 README
@@ -2,6 +2,7 @@ ClipIt - Lightweight GTK+ Clipboard Manager
-------------------------------------------------------------------------------
Copyright (C) 2010 by Cristian Henzel <oss@rspwn.com>
Copyright (C) 2011 by Eugene Nikolsky <pluton.od@gmail.com>
forked from parcellite, which is
Copyright (C) 2007-2008 Gilberto "Xyhthyx" Miralla <xyhthyx@gmail.com>
@@ -1,4 +1,5 @@
/* Copyright (C) 2010 by Cristian Henzel <oss@rspwn.com>
* Copyright (C) 2011 by Eugene Nikolsky <pluton.od@gmail.com>
*
* forked from parcellite, which is
* Copyright (C) 2007-2008 by Xyhthyx <xyhthyx@gmail.com>
@@ -63,10 +64,15 @@ prefs_t prefs = {DEF_USE_COPY, DEF_USE_PRIMARY, DEF_SYNCHRONIZE,
DEF_HYPERLINKS_ONLY, DEF_CONFIRM_CLEAR, DEF_SINGLE_LINE,
DEF_REVERSE_HISTORY, DEF_ITEM_LENGTH, DEF_ELLIPSIZE,
INIT_HISTORY_KEY, INIT_ACTIONS_KEY, INIT_MENU_KEY,
INIT_SEARCH_KEY, DEF_NO_ICON};
INIT_SEARCH_KEY, INIT_OFFLINE_KEY, DEF_NO_ICON,
DEF_OFFLINE_MODE};
/* Called every CHECK_INTERVAL seconds to check for new items */
static gboolean item_check(gpointer data) {
/* Immediately return in offline mode */
if (prefs.offline_mode)
return TRUE;
/* Grab the current primary and clipboard text */
gchar* primary_temp = gtk_clipboard_wait_for_text(primary);
gchar* clipboard_temp = gtk_clipboard_wait_for_text(clipboard);
@@ -252,7 +258,8 @@ static void show_about_dialog(GtkMenuItem *menu_item, gpointer user_data) {
/* This helps prevent multiple instances */
if (!gtk_grab_get_current()) {
const gchar* authors[] = {"Cristian Henzel <oss@rspwn.com>\n"
"Gilberto \"Xyhthyx\" Miralla <xyhthyx@gmail.com>", NULL};
"Gilberto \"Xyhthyx\" Miralla <xyhthyx@gmail.com>\n"
"Eugene Nikolsky <pluton.od@gmail.com>", NULL};
const gchar* license =
"This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
@@ -501,6 +508,17 @@ static gboolean menu_key_pressed(GtkWidget *history_menu, GdkEventKey *event, gp
return FALSE;
}
static void toggle_offline_mode() {
if (prefs.offline_mode) {
/* Restore clipboard contents before turning offline mode off */
gtk_clipboard_set_text(clipboard, clipboard_text != NULL ? clipboard_text : "", -1);
}
prefs.offline_mode = !prefs.offline_mode;
/* Save the change */
save_preferences();
}
static GtkWidget *create_history_menu(GtkWidget *history_menu) {
GtkWidget *menu_item, *item_label;
history_menu = gtk_menu_new();
@@ -620,6 +638,17 @@ static GtkWidget *create_history_menu(GtkWidget *history_menu) {
elem = elem->next;
}
}
/* Show a notice in offline mode */
if (prefs.offline_mode) {
gtk_menu_shell_append((GtkMenuShell*)history_menu, gtk_separator_menu_item_new());
menu_item = gtk_menu_item_new_with_label("");
item_label = gtk_bin_get_child((GtkBin*)menu_item);
gtk_label_set_markup((GtkLabel*)item_label, "<b>Offline mode is ON</b>");
gtk_label_set_single_line_mode((GtkLabel*)item_label, TRUE);
gtk_widget_set_sensitive(item_label, FALSE);
gtk_menu_shell_append((GtkMenuShell*)history_menu, menu_item);
}
return history_menu;
}
@@ -653,6 +682,11 @@ static GtkWidget *create_tray_menu(GtkWidget *tray_menu, int menu_type) {
* - use_rmb_menu is active and menu_type is right-click, OR
* - use_rmb_menu is inactive and menu_type is left-click */
if ((prefs.use_rmb_menu && (menu_type == 3)) || (!prefs.use_rmb_menu) || (menu_type == 2)) {
/* Offline mode checkbox */
menu_item = gtk_check_menu_item_new_with_mnemonic(_("_Offline mode"));
gtk_check_menu_item_set_active((GtkCheckMenuItem*)menu_item, prefs.offline_mode);
g_signal_connect((GObject*)menu_item, "activate", (GCallback)toggle_offline_mode, NULL);
gtk_menu_shell_append((GtkMenuShell*)tray_menu, menu_item);
/* About */
menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT, NULL);
g_signal_connect((GObject*)menu_item, "activate", (GCallback)show_about_dialog, NULL);
@@ -762,6 +796,11 @@ void search_hotkey(char *keystring, gpointer user_data) {
g_timeout_add(POPUP_DELAY, show_search, NULL);
}
/* Called when offline mode global hotkey is pressed */
void offline_hotkey(char *keystring, gpointer user_data) {
toggle_offline_mode();
}
/* Startup calls and initializations */
static void clipit_init() {
/* Create clipboard */
@@ -782,6 +821,7 @@ static void clipit_init() {
keybinder_bind(prefs.actions_key, actions_hotkey, NULL);
keybinder_bind(prefs.menu_key, menu_hotkey, NULL);
keybinder_bind(prefs.search_key, search_hotkey, NULL);
keybinder_bind(prefs.offline_key, offline_hotkey, NULL);
/* Create status icon */
if (!prefs.no_icon)
@@ -857,11 +897,13 @@ int main(int argc, char **argv) {
keybinder_unbind(prefs.actions_key, actions_hotkey);
keybinder_unbind(prefs.menu_key, menu_hotkey);
keybinder_unbind(prefs.search_key, search_hotkey);
keybinder_unbind(prefs.offline_key, offline_hotkey);
/* Cleanup */
g_free(prefs.history_key);
g_free(prefs.actions_key);
g_free(prefs.menu_key);
g_free(prefs.search_key);
g_free(prefs.offline_key);
g_list_foreach(history, (GFunc)g_free, NULL);
g_list_free(history);
g_free(primary_text);
@@ -1,4 +1,5 @@
/* Copyright (C) 2010 by Cristian Henzel <oss@rspwn.com>
* Copyright (C) 2011 by Eugene Nikolsky <pluton.od@gmail.com>
*
* forked from parcellite, which is
* Copyright (C) 2007-2008 by Xyhthyx <xyhthyx@gmail.com>
@@ -59,8 +60,11 @@ typedef struct {
gchar* actions_key; /* Actions menu hotkey */
gchar* menu_key; /* ClipIt menu hotkey */
gchar* search_key; /* ClipIt search hotkey */
gchar* offline_key; /* ClipIt offline mode hotkey */
gboolean no_icon; /* No icon */
gboolean offline_mode; /* Offline mode */
} prefs_t;
extern prefs_t prefs;
@@ -73,6 +77,8 @@ void menu_hotkey(char *keystring, gpointer user_data);
void search_hotkey(char *keystring, gpointer user_data);
void offline_hotkey(char *keystring, gpointer user_data);
void clear_main_data();
#ifdef HAVE_APPINDICATOR
@@ -1,4 +1,5 @@
/* Copyright (C) 2010 by Cristian Henzel <oss@rspwn.com>
* Copyright (C) 2011 by Eugene Nikolsky <pluton.od@gmail.com>
*
* forked from parcellite, which is
* Copyright (C) 2007-2008 by Xyhthyx <xyhthyx@gmail.com>
@@ -303,6 +304,7 @@ static gboolean treeview_key_pressed(GtkWidget *widget, GdkEventKey *event, GtkW
case XK_Shift_R:
case XK_Control_L:
case XK_Control_R:
case XK_Tab: // allow to switch focus by the Tab key
return FALSE;
case XK_Return:
search_doubleclick();
@@ -343,7 +345,14 @@ gboolean show_search()
GtkWidget* search_dialog = gtk_dialog_new();
gtk_window_set_icon((GtkWindow*)search_dialog, gtk_widget_render_icon(search_dialog, GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL));
gtk_window_set_title((GtkWindow*)search_dialog, _("Manage History"));
gchar *orig_title = _("Manage History");
gchar *title = 0;
if (prefs.offline_mode)
title = g_strconcat(orig_title, _(" (Offline mode)"), NULL);
else
title = g_strdup(orig_title);
gtk_window_set_title((GtkWindow*)search_dialog, title);
g_free(title);
gtk_window_set_resizable((GtkWindow*)search_dialog, TRUE);
gtk_window_set_position((GtkWindow*)search_dialog, GTK_WIN_POS_CENTER);
@@ -1,4 +1,5 @@
/* Copyright (C) 2010 by Cristian Henzel <oss@rspwn.com>
* Copyright (C) 2011 by Eugene Nikolsky <pluton.od@gmail.com>
*
* forked from parcellite, which is
* Copyright (C) 2007-2008 by Xyhthyx <xyhthyx@gmail.com>
@@ -46,6 +47,7 @@ GtkWidget *copy_check,
*actions_key_entry,
*menu_key_entry,
*search_key_entry,
*offline_key_entry,
*save_check,
*confirm_check,
*reverse_check,
@@ -73,6 +75,9 @@ static void apply_preferences()
keybinder_unbind(prefs.search_key, search_hotkey);
g_free(prefs.search_key);
prefs.search_key = NULL;
keybinder_unbind(prefs.offline_key, offline_hotkey);
g_free(prefs.offline_key);
prefs.offline_key = NULL;
/* Get the new preferences */
prefs.use_copy = gtk_toggle_button_get_active((GtkToggleButton*)copy_check);
@@ -97,17 +102,19 @@ static void apply_preferences()
prefs.actions_key = g_strdup(gtk_entry_get_text((GtkEntry*)actions_key_entry));
prefs.menu_key = g_strdup(gtk_entry_get_text((GtkEntry*)menu_key_entry));
prefs.search_key = g_strdup(gtk_entry_get_text((GtkEntry*)search_key_entry));
prefs.offline_key = g_strdup(gtk_entry_get_text((GtkEntry*)offline_key_entry));
/* Bind keys and apply the new history limit */
keybinder_bind(prefs.history_key, history_hotkey, NULL);
keybinder_bind(prefs.actions_key, actions_hotkey, NULL);
keybinder_bind(prefs.menu_key, menu_hotkey, NULL);
keybinder_bind(prefs.search_key, search_hotkey, NULL);
keybinder_bind(prefs.offline_key, offline_hotkey, NULL);
truncate_history();
}
/* Save preferences to CONFIGDIR/clipit/clipitrc */
static void save_preferences()
void save_preferences()
{
/* Create key */
GKeyFile* rc_key = g_key_file_new();
@@ -135,6 +142,8 @@ static void save_preferences()
g_key_file_set_string(rc_key, "rc", "actions_key", prefs.actions_key);
g_key_file_set_string(rc_key, "rc", "menu_key", prefs.menu_key);
g_key_file_set_string(rc_key, "rc", "search_key", prefs.search_key);
g_key_file_set_string(rc_key, "rc", "offline_key", prefs.offline_key);
g_key_file_set_boolean(rc_key, "rc", "offline_mode", prefs.offline_mode);
/* Check config and data directories */
check_dirs();
@@ -172,6 +181,7 @@ static void first_run_check()
prefs.actions_key = DEF_ACTIONS_KEY;
prefs.menu_key = DEF_MENU_KEY;
prefs.search_key = DEF_SEARCH_KEY;
prefs.offline_key = DEF_OFFLINE_KEY;
save_preferences();
}
g_free(rc_file);
@@ -242,6 +252,8 @@ void read_preferences()
prefs.actions_key = g_key_file_get_string(rc_key, "rc", "actions_key", NULL);
prefs.menu_key = g_key_file_get_string(rc_key, "rc", "menu_key", NULL);
prefs.search_key = g_key_file_get_string(rc_key, "rc", "search_key", NULL);
prefs.offline_key = g_key_file_get_string(rc_key, "rc", "offline_key", NULL);
prefs.offline_mode = g_key_file_get_boolean(rc_key, "rc", "offline_mode", NULL);
/* Check for errors and set default values if any */
if ((!prefs.history_limit) || (prefs.history_limit > 1000) || (prefs.history_limit < 0))
@@ -260,6 +272,8 @@ void read_preferences()
prefs.menu_key = g_strdup(DEF_MENU_KEY);
if (!prefs.search_key)
prefs.search_key = g_strdup(DEF_SEARCH_KEY);
if (!prefs.offline_key)
prefs.offline_key = g_strdup(DEF_OFFLINE_KEY);
}
else
{
@@ -268,6 +282,7 @@ void read_preferences()
prefs.actions_key = g_strdup(DEF_ACTIONS_KEY);
prefs.menu_key = g_strdup(DEF_MENU_KEY);
prefs.search_key = g_strdup(DEF_SEARCH_KEY);
prefs.offline_key = g_strdup(DEF_OFFLINE_KEY);
}
g_key_file_free(rc_key);
g_free(rc_file);
@@ -989,6 +1004,15 @@ void show_preferences(gint tab) {
search_key_entry = gtk_entry_new();
gtk_entry_set_width_chars((GtkEntry*)search_key_entry, 10);
gtk_box_pack_end((GtkBox*)hbox, search_key_entry, TRUE, TRUE, 0);
/* Offline mode key combination */
hbox = gtk_hbox_new(TRUE, 4);
gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
label = gtk_label_new(_("Offline mode hotkey:"));
gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
offline_key_entry = gtk_entry_new();
gtk_entry_set_width_chars((GtkEntry*)offline_key_entry, 10);
gtk_box_pack_end((GtkBox*)hbox, offline_key_entry, TRUE, TRUE, 0);
gtk_box_pack_start((GtkBox*)vbox_extras, frame, FALSE, FALSE, 0);
/* Make widgets reflect current preferences */
@@ -1014,6 +1038,7 @@ void show_preferences(gint tab) {
gtk_entry_set_text((GtkEntry*)actions_key_entry, prefs.actions_key);
gtk_entry_set_text((GtkEntry*)menu_key_entry, prefs.menu_key);
gtk_entry_set_text((GtkEntry*)search_key_entry, prefs.search_key);
gtk_entry_set_text((GtkEntry*)offline_key_entry, prefs.offline_key);
/* Read actions */
read_actions();
@@ -1,4 +1,5 @@
/* Copyright (C) 2010 by Cristian Henzel <oss@rspwn.com>
* Copyright (C) 2011 by Eugene Nikolsky <pluton.od@gmail.com>
*
* forked from parcellite, which is
* Copyright (C) 2007-2008 by Xyhthyx <xyhthyx@gmail.com>
@@ -28,6 +29,7 @@ G_BEGIN_DECLS
#define INIT_ACTIONS_KEY NULL
#define INIT_MENU_KEY NULL
#define INIT_SEARCH_KEY NULL
#define INIT_OFFLINE_KEY NULL
#define DEF_USE_COPY TRUE
#define DEF_USE_PRIMARY FALSE
@@ -51,7 +53,9 @@ G_BEGIN_DECLS
#define DEF_ACTIONS_KEY "<Ctrl><Alt>A"
#define DEF_MENU_KEY "<Ctrl><Alt>P"
#define DEF_SEARCH_KEY "<Ctrl><Alt>F"
#define DEF_OFFLINE_KEY "<Ctrl><Alt>O"
#define DEF_NO_ICON FALSE
#define DEF_OFFLINE_MODE FALSE
#define ACTIONS_FILE "clipit/actions"
#define EXCLUDES_FILE "clipit/excludes"
@@ -67,6 +71,8 @@ file still exists though. Do you want to empty the current history file?"
void read_preferences();
void save_preferences();
void show_preferences(gint tab);
G_END_DECLS

0 comments on commit 8c26760

Please sign in to comment.