* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "main.h"
#include "bar-keywords.h"
+#include <cstdio>
+#include <cstring>
+
+#include <gdk/gdk.h>
+#include <glib-object.h>
+
+#include "bar.h"
+#include "compat.h"
+#include "debug.h"
+#include "dnd.h"
#include "filedata.h"
+#include "intl.h"
+#include "layout.h"
+#include "main-defines.h"
#include "metadata.h"
+#include "misc.h"
+#include "options.h"
+#include "rcfile.h"
+#include "secure-save.h"
+#include "typedefs.h"
#include "ui-fileops.h"
+#include "ui-menu.h"
#include "ui-misc.h"
#include "ui-utildlg.h"
-#include "bar.h"
-#include "ui-menu.h"
-#include "rcfile.h"
-#include "layout.h"
-#include "dnd.h"
-#include "secure-save.h"
+namespace
+{
+
+GtkListStore *keyword_store = nullptr;
-//static void bar_pane_keywords_keyword_update_all(void);
-static void bar_pane_keywords_changed(GtkTextBuffer *buffer, gpointer data);
+void bar_pane_keywords_changed(GtkTextBuffer *buffer, gpointer data);
-static void autocomplete_keywords_list_load(const gchar *path);
-static GtkListStore *keyword_store = NULL;
-static gboolean autocomplete_keywords_list_save(gchar *path);
-static gboolean autocomplete_activate_cb(GtkWidget *widget, gpointer data);
+void autocomplete_keywords_list_load(const gchar *path);
+gboolean autocomplete_keywords_list_save(gchar *path);
+gboolean autocomplete_activate_cb(GtkWidget *widget, gpointer data);
/*
*-------------------------------------------------------------------
*-------------------------------------------------------------------
*/
-
-GList *keyword_list_pull(GtkWidget *text_widget)
-{
- GList *list;
- gchar *text;
-
- text = text_widget_text_pull(text_widget);
- list = string_to_keywords_list(text);
-
- g_free(text);
-
- return list;
-}
-
-static GList *keyword_list_pull_selected(GtkWidget *text_widget)
+GList *keyword_list_pull_selected(GtkWidget *text_widget)
{
GList *list;
gchar *text;
}
/* the "changed" signal should be blocked before calling this */
-static void keyword_list_push(GtkWidget *textview, GList *list)
+void keyword_list_push(GtkWidget *textview, GList *list)
{
GtkTextBuffer *buffer;
- GtkTextIter start, end;
+ GtkTextIter start;
+ GtkTextIter end;
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
gtk_text_buffer_get_bounds(buffer, &start, &end);
while (list)
{
- const gchar *word = static_cast<const gchar *>(list->data);
+ auto word = static_cast<const gchar *>(list->data);
GtkTextIter iter;
gtk_text_buffer_get_end_iter(buffer, &iter);
FILTER_KEYWORD_COLUMN_COUNT
};
-static GType filter_keyword_column_types[] = {G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN};
+GType filter_keyword_column_types[] = {G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN};
-typedef struct _PaneKeywordsData PaneKeywordsData;
-struct _PaneKeywordsData
+struct PaneKeywordsData
{
PaneData pane;
GtkWidget *widget;
GtkWidget *autocomplete;
};
-typedef struct _ConfDialogData ConfDialogData;
-struct _ConfDialogData
+struct ConfDialogData
{
PaneKeywordsData *pkd;
GtkTreePath *click_tpath;
};
-static void bar_pane_keywords_write(PaneKeywordsData *pkd)
+void bar_pane_keywords_write(PaneKeywordsData *pkd)
{
GList *list;
metadata_write_list(pkd->fd, KEYWORD_KEY, list);
- string_list_free(list);
+ g_list_free_full(list, g_free);
}
gboolean bar_keyword_tree_expand_if_set_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
gboolean set;
gtk_tree_model_get(model, iter, FILTER_KEYWORD_COLUMN_TOGGLE, &set, -1);
gboolean bar_keyword_tree_collapse_if_unset_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
gboolean set;
gtk_tree_model_get(model, iter, FILTER_KEYWORD_COLUMN_TOGGLE, &set, -1);
return FALSE;
}
-static void bar_keyword_tree_sync(PaneKeywordsData *pkd)
+void bar_keyword_tree_sync(PaneKeywordsData *pkd)
{
GtkTreeModel *model;
keywords = keyword_list_pull(pkd->keyword_view);
keyword_show_set_in(GTK_TREE_STORE(keyword_tree), model, keywords);
if (pkd->hide_unchecked) keyword_hide_unset_in(GTK_TREE_STORE(keyword_tree), model, keywords);
- string_list_free(keywords);
+ g_list_free_full(keywords, g_free);
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(model));
if (pkd->collapse_unchecked) gtk_tree_model_foreach(model, bar_keyword_tree_collapse_if_unset_cb, pkd);
}
-static void bar_pane_keywords_update(PaneKeywordsData *pkd)
+void bar_pane_keywords_update(PaneKeywordsData *pkd)
{
- GList *keywords = NULL;
- GList *orig_keywords = NULL;
- GList *work1, *work2;
+ GList *keywords = nullptr;
+ GList *orig_keywords = nullptr;
+ GList *work1;
+ GList *work2;
GtkTextBuffer *keyword_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pkd->keyword_view));
keywords = metadata_read_list(pkd->fd, KEYWORD_KEY, METADATA_PLAIN);
bar_keyword_tree_sync(pkd);
g_signal_handlers_unblock_by_func(keyword_buffer, (gpointer)bar_pane_keywords_changed, pkd);
}
- string_list_free(keywords);
- string_list_free(orig_keywords);
+ g_list_free_full(keywords, g_free);
+ g_list_free_full(orig_keywords, g_free);
}
void bar_pane_keywords_set_fd(GtkWidget *pane, FileData *fd)
void bar_keyword_tree_get_expanded_cb(GtkTreeView *keyword_treeview, GtkTreePath *path, gpointer data)
{
- GList **expanded = static_cast<GList **>(data);
+ auto expanded = static_cast<GList **>(data);
GtkTreeModel *model;
GtkTreeIter iter;
gchar *path_string;
g_free(path_string);
}
-static void bar_pane_keywords_entry_write_config(gchar *entry, GString *outstr, gint indent)
+void bar_pane_keywords_entry_write_config(gchar *entry, GString *outstr, gint indent)
{
struct {
gchar *path;
WRITE_STRING("/>");
}
-static void bar_pane_keywords_write_config(GtkWidget *pane, GString *outstr, gint indent)
+void bar_pane_keywords_write_config(GtkWidget *pane, GString *outstr, gint indent)
{
PaneKeywordsData *pkd;
- GList *path_expanded = NULL;
- gint w, h;
+ GList *path_expanded = nullptr;
+ gint w;
+ gint h;
pkd = static_cast<PaneKeywordsData *>(g_object_get_data(G_OBJECT(pane), "pane_data"));
if (!pkd) return;
gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(pkd->keyword_treeview),
(bar_keyword_tree_get_expanded_cb), &path_expanded);
- g_list_first(path_expanded);
- while (path_expanded)
+ GList *work = g_list_first(path_expanded);
+ while (work)
{
- bar_pane_keywords_entry_write_config(static_cast<gchar *>(path_expanded->data), outstr, indent);
- g_free(path_expanded->data);
- path_expanded = path_expanded->next;
+ bar_pane_keywords_entry_write_config(static_cast<gchar *>(work->data), outstr, indent);
+ work = work->next;
}
- g_list_free(path_expanded);
+ g_list_free_full(path_expanded, g_free);
indent--;
WRITE_NL();
return FALSE;
}
-static void bar_pane_keywords_keyword_toggle(GtkCellRendererToggle *UNUSED(toggle), const gchar *path, gpointer data)
+void bar_pane_keywords_keyword_toggle(GtkCellRendererToggle *, const gchar *path, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreePath *tpath;
g_signal_handlers_block_by_func(keyword_buffer, (gpointer)bar_pane_keywords_changed, pkd);
keyword_list_push(pkd->keyword_view, list);
- string_list_free(list);
+ g_list_free_full(list, g_free);
g_signal_handlers_unblock_by_func(keyword_buffer, (gpointer)bar_pane_keywords_changed, pkd);
/* call this just once in the end */
void bar_pane_keywords_filter_modify(GtkTreeModel *model, GtkTreeIter *iter, GValue *value, gint column, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model));
GtkTreeIter child_iter;
{
GList *keywords = keyword_list_pull(pkd->keyword_view);
gboolean set = keyword_tree_is_set(keyword_tree, &child_iter, keywords);
- string_list_free(keywords);
+ g_list_free_full(keywords, g_free);
g_value_init(value, G_TYPE_BOOLEAN);
g_value_set_boolean(value, set);
gtk_tree_model_get_value(keyword_tree, &child_iter, KEYWORD_COLUMN_IS_KEYWORD, value);
break;
}
- return;
-
}
gboolean bar_pane_keywords_filter_visible(GtkTreeModel *keyword_tree, GtkTreeIter *iter, gpointer data)
{
- GtkTreeModel *filter = static_cast<GtkTreeModel *>(data);
+ auto filter = static_cast<GtkTreeModel *>(data);
return !keyword_is_hidden_in(keyword_tree, iter, filter);
}
-static void bar_pane_keywords_set_selection(PaneKeywordsData *pkd, gboolean append)
+void bar_pane_keywords_set_selection(PaneKeywordsData *pkd, gboolean append)
{
- GList *keywords = NULL;
- GList *list = NULL;
+ GList *keywords = nullptr;
+ GList *list = nullptr;
GList *work;
keywords = keyword_list_pull_selected(pkd->keyword_view);
list = layout_selection_list(pkd->pane.lw);
- list = file_data_process_groups_in_selection(list, FALSE, NULL);
+ list = file_data_process_groups_in_selection(list, FALSE, nullptr);
work = list;
while (work)
{
- FileData *fd = static_cast<FileData *>(work->data);
+ auto fd = static_cast<FileData *>(work->data);
work = work->next;
if (append)
}
filelist_free(list);
- string_list_free(keywords);
+ g_list_free_full(keywords, g_free);
}
-static void bar_pane_keywords_sel_add_cb(GtkWidget *UNUSED(button), gpointer data)
+void bar_pane_keywords_sel_add_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
bar_pane_keywords_set_selection(pkd, TRUE);
}
-static void bar_pane_keywords_sel_replace_cb(GtkWidget *UNUSED(button), gpointer data)
+void bar_pane_keywords_sel_replace_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
bar_pane_keywords_set_selection(pkd, FALSE);
}
-static void bar_pane_keywords_populate_popup_cb(GtkTextView *UNUSED(textview), GtkMenu *menu, gpointer data)
+void bar_pane_keywords_populate_popup_cb(GtkTextView *, GtkMenu *menu, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
menu_item_add_divider(GTK_WIDGET(menu));
- menu_item_add_stock(GTK_WIDGET(menu), _("Add selected keywords to selected files"), GTK_STOCK_ADD, G_CALLBACK(bar_pane_keywords_sel_add_cb), pkd);
- menu_item_add_stock(GTK_WIDGET(menu), _("Replace existing keywords in selected files with selected keywords"), GTK_STOCK_CONVERT, G_CALLBACK(bar_pane_keywords_sel_replace_cb), pkd);
+ menu_item_add_icon(GTK_WIDGET(menu), _("Add selected keywords to selected files"), GQ_ICON_ADD, G_CALLBACK(bar_pane_keywords_sel_add_cb), pkd);
+ menu_item_add_icon(GTK_WIDGET(menu), _("Replace existing keywords in selected files with selected keywords"), GQ_ICON_REPLACE, G_CALLBACK(bar_pane_keywords_sel_replace_cb), pkd);
}
-static void bar_pane_keywords_notify_cb(FileData *fd, NotifyType type, gpointer data)
+void bar_pane_keywords_notify_cb(FileData *fd, NotifyType type, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_METADATA)) && fd == pkd->fd)
{
DEBUG_1("Notify pane_keywords: %s %04x", fd->path, type);
}
}
-static gboolean bar_pane_keywords_changed_idle_cb(gpointer data)
+gboolean bar_pane_keywords_changed_idle_cb(gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
bar_pane_keywords_write(pkd);
bar_keyword_tree_sync(pkd);
pkd->idle_id = 0;
- return FALSE;
+ return G_SOURCE_REMOVE;
}
-static void bar_pane_keywords_changed(GtkTextBuffer *UNUSED(buffer), gpointer data)
+void bar_pane_keywords_changed(GtkTextBuffer *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
if (pkd->idle_id) return;
/* higher prio than redraw */
- pkd->idle_id = g_idle_add_full(G_PRIORITY_HIGH_IDLE, bar_pane_keywords_changed_idle_cb, pkd, NULL);
+ pkd->idle_id = g_idle_add_full(G_PRIORITY_HIGH_IDLE, bar_pane_keywords_changed_idle_cb, pkd, nullptr);
}
*-------------------------------------------------------------------
*/
-
-static GtkTargetEntry bar_pane_keywords_drag_types[] = {
+// @todo Use std::array
+constexpr GtkTargetEntry bar_pane_keywords_drag_types[] = {
{ const_cast<gchar *>(TARGET_APP_KEYWORD_PATH_STRING), GTK_TARGET_SAME_WIDGET, TARGET_APP_KEYWORD_PATH },
{ const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN }
};
-static gint n_keywords_drag_types = 2;
-
+constexpr gint n_keywords_drag_types = 2;
-static GtkTargetEntry bar_pane_keywords_drop_types[] = {
+// @todo Use std::array
+constexpr GtkTargetEntry bar_pane_keywords_drop_types[] = {
{ const_cast<gchar *>(TARGET_APP_KEYWORD_PATH_STRING), GTK_TARGET_SAME_WIDGET, TARGET_APP_KEYWORD_PATH },
{ const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN }
};
-static gint n_keywords_drop_types = 2;
+constexpr gint n_keywords_drop_types = 2;
-static void bar_pane_keywords_dnd_get(GtkWidget *tree_view, GdkDragContext *UNUSED(context),
+void bar_pane_keywords_dnd_get(GtkWidget *tree_view, GdkDragContext *,
GtkSelectionData *selection_data, guint info,
- guint UNUSED(time), gpointer UNUSED(data))
+ guint, gpointer)
{
GtkTreeIter iter;
GtkTreeModel *model;
}
}
-static void bar_pane_keywords_dnd_begin(GtkWidget *tree_view, GdkDragContext *context, gpointer UNUSED(data))
+void bar_pane_keywords_dnd_begin(GtkWidget *tree_view, GdkDragContext *context, gpointer)
{
GtkTreeIter iter;
GtkTreeModel *model;
}
-static void bar_pane_keywords_dnd_end(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context), gpointer UNUSED(data))
+void bar_pane_keywords_dnd_end(GtkWidget *, GdkDragContext *, gpointer)
{
}
-static gboolean bar_pane_keywords_dnd_can_move(GtkTreeModel *keyword_tree, GtkTreeIter *src_kw_iter, GtkTreeIter *dest_kw_iter)
+gboolean bar_pane_keywords_dnd_can_move(GtkTreeModel *keyword_tree, GtkTreeIter *src_kw_iter, GtkTreeIter *dest_kw_iter)
{
gchar *src_name;
GtkTreeIter parent;
}
src_name = keyword_get_name(keyword_tree, src_kw_iter);
- if (keyword_exists(keyword_tree, NULL, dest_kw_iter, src_name, FALSE, NULL))
+ if (keyword_exists(keyword_tree, nullptr, dest_kw_iter, src_name, FALSE, nullptr))
{
g_free(src_name);
return FALSE;
return TRUE;
}
-static gboolean bar_pane_keywords_dnd_skip_existing(GtkTreeModel *keyword_tree, GtkTreeIter *dest_kw_iter, GList **keywords)
+gboolean bar_pane_keywords_dnd_skip_existing(GtkTreeModel *keyword_tree, GtkTreeIter *dest_kw_iter, GList **keywords)
{
/* we have to find at least one keyword that does not already exist as a sibling of dest_kw_iter */
GList *work = *keywords;
while (work)
{
- gchar *keyword = static_cast<gchar *>(work->data);
- if (keyword_exists(keyword_tree, NULL, dest_kw_iter, keyword, FALSE, NULL))
+ auto keyword = static_cast<gchar *>(work->data);
+ if (keyword_exists(keyword_tree, nullptr, dest_kw_iter, keyword, FALSE, nullptr))
{
GList *next = work->next;
g_free(keyword);
return !!*keywords;
}
-static void bar_pane_keywords_dnd_receive(GtkWidget *tree_view, GdkDragContext *UNUSED(context),
+void bar_pane_keywords_dnd_receive(GtkWidget *tree_view, GdkDragContext *,
gint x, gint y,
GtkSelectionData *selection_data, guint info,
- guint UNUSED(time), gpointer data)
+ guint, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
- GtkTreePath *tpath = NULL;
+ auto pkd = static_cast<PaneKeywordsData *>(data);
+ GtkTreePath *tpath = nullptr;
GtkTreeViewDropPosition pos;
GtkTreeModel *model;
GtkTreeModel *keyword_tree;
gboolean src_valid = FALSE;
- GList *new_keywords = NULL;
+ GList *new_keywords = nullptr;
GList *work;
/* iterators for keyword_tree */
keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model));
gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos);
- gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), NULL, pos);
+ gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), nullptr, pos);
switch (info)
{
case TARGET_APP_KEYWORD_PATH:
{
- GList *path = static_cast<GList *>(*(gpointer *)(gtk_selection_data_get_data(selection_data)));
+ auto path = static_cast<GList *>(*reinterpret_cast<const gpointer *>(gtk_selection_data_get_data(selection_data)));
src_valid = keyword_tree_get_iter(keyword_tree, &src_kw_iter, path);
- string_list_free(path);
+ g_list_free_full(path, g_free);
break;
}
default:
- new_keywords = string_to_keywords_list((gchar *)gtk_selection_data_get_data(selection_data));
+ new_keywords = string_to_keywords_list(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)));
break;
}
{
case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
case GTK_TREE_VIEW_DROP_BEFORE:
- gtk_tree_store_insert_before(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter);
+ gtk_tree_store_insert_before(GTK_TREE_STORE(keyword_tree), &new_kw_iter, nullptr, &dest_kw_iter);
break;
case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
case GTK_TREE_VIEW_DROP_AFTER:
- gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter);
+ gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &new_kw_iter, nullptr, &dest_kw_iter);
break;
}
}
}
else
{
- if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, NULL))
+ if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, nullptr))
{
/* the keyword can't be moved if the same name already exist */
return;
}
- if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, NULL, &new_keywords))
+ if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, nullptr, &new_keywords))
{
/* the keywords can't be added if the same name already exist */
return;
}
- gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL);
+ gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, nullptr);
}
work = new_keywords;
while (work)
{
- gchar *keyword = static_cast<gchar *>(work->data);
+ auto keyword = static_cast<gchar *>(work->data);
keyword_set(GTK_TREE_STORE(keyword_tree), &new_kw_iter, keyword, TRUE);
work = work->next;
if (work)
{
GtkTreeIter add;
- gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &new_kw_iter);
+ gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, nullptr, &new_kw_iter);
new_kw_iter = add;
}
}
- string_list_free(new_keywords);
+ g_list_free_full(new_keywords, g_free);
bar_keyword_tree_sync(pkd);
}
-static gint bar_pane_keywords_dnd_motion(GtkWidget *tree_view, GdkDragContext *context,
- gint x, gint y, guint time, gpointer UNUSED(data))
+gint bar_pane_keywords_dnd_motion(GtkWidget *tree_view, GdkDragContext *context,
+ gint x, gint y, guint time, gpointer)
{
- GtkTreePath *tpath = NULL;
+ GtkTreePath *tpath = nullptr;
GtkTreeViewDropPosition pos;
gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos);
if (tpath)
*-------------------------------------------------------------------
*/
-static void bar_pane_keywords_edit_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
+void bar_pane_keywords_edit_destroy_cb(GtkWidget *, gpointer data)
{
- ConfDialogData *cdd = static_cast<ConfDialogData *>(data);
+ auto cdd = static_cast<ConfDialogData *>(data);
gtk_tree_path_free(cdd->click_tpath);
g_free(cdd);
}
-static void bar_pane_keywords_edit_cancel_cb(GenericDialog *UNUSED(gd), gpointer UNUSED(data))
+void bar_pane_keywords_edit_cancel_cb(GenericDialog *, gpointer)
{
}
-static void bar_pane_keywords_edit_ok_cb(GenericDialog *UNUSED(gd), gpointer data)
+void bar_pane_keywords_edit_ok_cb(GenericDialog *, gpointer data)
{
- ConfDialogData *cdd = static_cast<ConfDialogData *>(data);
+ auto cdd = static_cast<ConfDialogData *>(data);
PaneKeywordsData *pkd = cdd->pkd;
GtkTreeModel *model;
if (cdd->edit_existing)
{
if (keywords && keywords->data && /* there should be one keyword */
- !keyword_exists(keyword_tree, NULL, &kw_iter, static_cast<const gchar *>(keywords->data), TRUE, NULL))
+ !keyword_exists(keyword_tree, nullptr, &kw_iter, static_cast<const gchar *>(keywords->data), TRUE, nullptr))
{
keyword_set(GTK_TREE_STORE(keyword_tree), &kw_iter, static_cast<const gchar *>(keywords->data), cdd->is_keyword);
}
while (work)
{
GtkTreeIter add;
- if (keyword_exists(keyword_tree, NULL, (have_dest || append_to) ? &kw_iter : NULL, static_cast<const gchar *>(work->data), FALSE, NULL))
+ if (keyword_exists(keyword_tree, nullptr, (have_dest || append_to) ? &kw_iter : nullptr, static_cast<const gchar *>(work->data), FALSE, nullptr))
{
work = work->next;
continue;
}
else if (append_to)
{
- gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &kw_iter);
+ gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, nullptr, &kw_iter);
}
else
{
- gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &add, NULL);
+ gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &add, nullptr);
append_to = TRUE;
kw_iter = add;
}
work = work->next;
}
}
- string_list_free(keywords);
+ g_list_free_full(keywords, g_free);
}
-static void bar_pane_keywords_conf_set_helper(GtkWidget *UNUSED(widget), gpointer data)
+void bar_pane_keywords_conf_set_helper(GtkWidget *, gpointer data)
{
- ConfDialogData *cdd = static_cast<ConfDialogData *>(data);
+ auto cdd = static_cast<ConfDialogData *>(data);
cdd->is_keyword = FALSE;
}
-static void bar_pane_keywords_conf_set_kw(GtkWidget *UNUSED(widget), gpointer data)
+void bar_pane_keywords_conf_set_kw(GtkWidget *, gpointer data)
{
- ConfDialogData *cdd = static_cast<ConfDialogData *>(data);
+ auto cdd = static_cast<ConfDialogData *>(data);
cdd->is_keyword = TRUE;
}
-static void bar_pane_keywords_edit_dialog(PaneKeywordsData *pkd, gboolean edit_existing)
+void bar_pane_keywords_edit_dialog(PaneKeywordsData *pkd, gboolean edit_existing)
{
ConfDialogData *cdd;
GenericDialog *gd;
GtkWidget *group;
GtkWidget *button;
- gchar *name = NULL;
+ gchar *name = nullptr;
gboolean is_keyword = TRUE;
- if (edit_existing && pkd->click_tpath)
+ if (edit_existing && pkd->click_tpath)
{
GtkTreeModel *model;
GtkTreeIter iter;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));
- if (gtk_tree_model_get_iter(model, &iter, pkd->click_tpath))
+ if (gtk_tree_model_get_iter(model, &iter, pkd->click_tpath))
{
gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name,
FILTER_KEYWORD_COLUMN_IS_KEYWORD, &is_keyword, -1);
cdd = g_new0(ConfDialogData, 1);
cdd->pkd =pkd;
cdd->click_tpath = pkd->click_tpath;
- pkd->click_tpath = NULL;
+ pkd->click_tpath = nullptr;
cdd->edit_existing = edit_existing;
cdd->gd = gd = generic_dialog_new(name ? _("Edit keyword") : _("New keyword"), "keyword_edit",
G_CALLBACK(bar_pane_keywords_edit_destroy_cb), cdd);
- generic_dialog_add_message(gd, NULL, name ? _("Configure keyword") : _("New keyword"), NULL, FALSE);
+ generic_dialog_add_message(gd, nullptr, name ? _("Configure keyword") : _("New keyword"), nullptr, FALSE);
- generic_dialog_add_button(gd, GTK_STOCK_OK, NULL,
+ generic_dialog_add_button(gd, GQ_ICON_OK, "OK",
bar_pane_keywords_edit_ok_cb, TRUE);
table = pref_table_new(gd->vbox, 3, 1, FALSE, TRUE);
- pref_table_label(table, 0, 0, _("Keyword:"), 1.0);
+ pref_table_label(table, 0, 0, _("Keyword:"), GTK_ALIGN_END);
cdd->edit_widget = gtk_entry_new();
gtk_widget_set_size_request(cdd->edit_widget, 300, -1);
- if (name) gtk_entry_set_text(GTK_ENTRY(cdd->edit_widget), name);
- gtk_table_attach_defaults(GTK_TABLE(table), cdd->edit_widget, 1, 2, 0, 1);
+ if (name) gq_gtk_entry_set_text(GTK_ENTRY(cdd->edit_widget), name);
+ gq_gtk_grid_attach_default(GTK_GRID(table), cdd->edit_widget, 1, 2, 0, 1);
/* here could eventually be a text view instead of entry */
generic_dialog_attach_default(gd, cdd->edit_widget);
gtk_widget_show(cdd->edit_widget);
group = pref_group_new(gd->vbox, FALSE, _("Keyword type:"), GTK_ORIENTATION_VERTICAL);
- button = pref_radiobutton_new(group, NULL, _("Active keyword"),
+ button = pref_radiobutton_new(group, nullptr, _("Active keyword"),
(is_keyword),
G_CALLBACK(bar_pane_keywords_conf_set_kw), cdd);
button = pref_radiobutton_new(group, button, _("Helper"),
}
-
-
/*
*-------------------------------------------------------------------
* popup menu
*-------------------------------------------------------------------
*/
-static void bar_pane_keywords_edit_dialog_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_edit_dialog_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
bar_pane_keywords_edit_dialog(pkd, TRUE);
}
-static void bar_pane_keywords_add_dialog_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_add_dialog_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
bar_pane_keywords_edit_dialog(pkd, FALSE);
}
-static void bar_pane_keywords_connect_mark_cb(GtkWidget *menu_widget, gpointer data)
+void bar_pane_keywords_connect_mark_cb(GtkWidget *menu_widget, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *model;
GtkTreeIter iter;
meta_data_connect_mark_with_keyword(keyword_tree, &kw_iter, mark);
}
-static void bar_pane_keywords_disconnect_marks_ok_cb(GenericDialog *UNUSED(gd), gpointer UNUSED(data))
+void bar_pane_keywords_disconnect_marks_ok_cb(GenericDialog *, gpointer)
{
keyword_tree_disconnect_marks();
}
-static void dummy_cancel_cb(GenericDialog *UNUSED(gd), gpointer UNUSED(data))
+void dummy_cancel_cb(GenericDialog *, gpointer)
{
/* no op, only so cancel button appears */
}
-static void bar_pane_keywords_disconnect_marks_cb(GtkWidget *menu_widget, gpointer data)
+void bar_pane_keywords_disconnect_marks_cb(GtkWidget *menu_widget, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GenericDialog *gd;
- GString *message = g_string_new("");
-
- message = g_string_append(message, _("This will disconnect all Marks Keywords connections"));
gd = generic_dialog_new(_("Marks Keywords"),
"marks_keywords", menu_widget, TRUE, dummy_cancel_cb, pkd);
- generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING,
- "Disconnect all Marks Keywords connections?", message->str, TRUE);
- generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, bar_pane_keywords_disconnect_marks_ok_cb, TRUE);
+ generic_dialog_add_message(gd, GQ_ICON_DIALOG_WARNING,
+ _("Disconnect all Marks Keywords connections?"), _("This will disconnect all Marks Keywords connections"), TRUE);
+ generic_dialog_add_button(gd, GQ_ICON_OK, "OK", bar_pane_keywords_disconnect_marks_ok_cb, TRUE);
gtk_widget_show(gd->dialog);
-
- g_string_free(message, TRUE);
}
-static void bar_pane_keywords_delete_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_delete_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *model;
GtkTreeIter iter;
keyword_delete(GTK_TREE_STORE(keyword_tree), &kw_iter);
}
-static void bar_pane_keywords_hide_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_hide_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *model;
GtkTreeIter iter;
keyword_hide_in(GTK_TREE_STORE(keyword_tree), &kw_iter, model);
}
-static void bar_pane_keywords_show_all_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_show_all_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *model;
GtkTreeModel *keyword_tree;
- string_list_free(pkd->expanded_rows);
- pkd->expanded_rows = NULL;
+ g_list_free_full(pkd->expanded_rows, g_free);
+ pkd->expanded_rows = nullptr;
gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(pkd->keyword_treeview),
(bar_keyword_tree_get_expanded_cb), &pkd->expanded_rows);
bar_keyword_tree_sync(pkd);
}
-static void bar_pane_keywords_revert_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_revert_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GList *work;
GtkTreePath *tree_path;
gchar *path;
bar_keyword_tree_sync(pkd);
}
-static void bar_pane_keywords_expand_checked_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_expand_checked_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *model;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));
gtk_tree_model_foreach(model, bar_keyword_tree_expand_if_set_cb, pkd);
}
-static void bar_pane_keywords_collapse_all_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_collapse_all_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
- string_list_free(pkd->expanded_rows);
- pkd->expanded_rows = NULL;
+ g_list_free_full(pkd->expanded_rows, g_free);
+ pkd->expanded_rows = nullptr;
gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(pkd->keyword_treeview),
(bar_keyword_tree_get_expanded_cb), &pkd->expanded_rows);
bar_keyword_tree_sync(pkd);
}
-static void bar_pane_keywords_revert_hidden_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_revert_hidden_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *model;
GtkTreeModel *keyword_tree;
bar_keyword_tree_sync(pkd);
}
-static void bar_pane_keywords_collapse_unchecked_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_collapse_unchecked_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *model;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));
gtk_tree_model_foreach(model, bar_keyword_tree_collapse_if_unset_cb, pkd);
}
-static void bar_pane_keywords_hide_unchecked_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_hide_unchecked_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeModel *model;
GtkTreeModel *keyword_tree;
keywords = keyword_list_pull(pkd->keyword_view);
keyword_hide_unset_in(GTK_TREE_STORE(keyword_tree), model, keywords);
- string_list_free(keywords);
+ g_list_free_full(keywords, g_free);
bar_keyword_tree_sync(pkd);
}
-static void bar_pane_keywords_expand_checked_toggle_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_expand_checked_toggle_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
pkd->expand_checked = !pkd->expand_checked;
bar_keyword_tree_sync(pkd);
}
-static void bar_pane_keywords_collapse_unchecked_toggle_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_collapse_unchecked_toggle_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
pkd->collapse_unchecked = !pkd->collapse_unchecked;
bar_keyword_tree_sync(pkd);
}
-static void bar_pane_keywords_hide_unchecked_toggle_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_hide_unchecked_toggle_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
pkd->hide_unchecked = !pkd->hide_unchecked;
bar_keyword_tree_sync(pkd);
}
/**
* @brief Callback for adding selected keyword to all selected images.
*/
-static void bar_pane_keywords_add_to_selected_cb(GtkWidget *UNUSED(menu_widget), gpointer data)
+void bar_pane_keywords_add_to_selected_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
GtkTreeIter iter; /* This is the iter which initial holds the current keyword */
GtkTreeIter child_iter;
GtkTreeModel *model;
GtkTreeModel *keyword_tree;
- GList *list, *work;
- GList *keywords = NULL;
+ GList *list;
+ GList *work;
+ GList *keywords = nullptr;
GtkTextBuffer *keyword_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pkd->keyword_view));
keyword_tree_set(keyword_tree, &child_iter, &list);
keyword_list_push(pkd->keyword_view, list); /* Set the left keyword view */
- string_list_free(list);
+ g_list_free_full(list, g_free);
bar_pane_keywords_changed(keyword_buffer, pkd); /* Get list of all keywords in the hierarchy */
work = list;
while (work)
{
- FileData *fd = static_cast<FileData *>(work->data);
+ auto fd = static_cast<FileData *>(work->data);
work = work->next;
metadata_append_list(fd, KEYWORD_KEY, keywords);
}
filelist_free(list);
- string_list_free(keywords);
+ g_list_free_full(keywords, g_free);
}
-static void bar_pane_keywords_menu_popup(GtkWidget *UNUSED(widget), PaneKeywordsData *pkd, gint x, gint y)
+void bar_pane_keywords_menu_popup(GtkWidget *, PaneKeywordsData *pkd, gint x, gint y)
{
GtkWidget *menu;
GtkWidget *item;
GtkTreeViewDropPosition pos;
if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath);
- pkd->click_tpath = NULL;
+ pkd->click_tpath = nullptr;
gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(pkd->keyword_treeview), x, y, &pkd->click_tpath, &pos);
menu = popup_menu_short_lived();
- menu_item_add_stock(menu, _("New keyword"), GTK_STOCK_NEW, G_CALLBACK(bar_pane_keywords_add_dialog_cb), pkd);
+ menu_item_add_icon(menu, _("New keyword"), GQ_ICON_NEW, G_CALLBACK(bar_pane_keywords_add_dialog_cb), pkd);
menu_item_add_divider(menu);
if (keyword)
{
text = g_strdup_printf(_("Add \"%s\" to all selected images"), name);
- menu_item_add_stock(menu, text, GTK_STOCK_ADD, G_CALLBACK(bar_pane_keywords_add_to_selected_cb), pkd);
+ menu_item_add_icon(menu, text, GQ_ICON_ADD, G_CALLBACK(bar_pane_keywords_add_to_selected_cb), pkd);
g_free(text);
}
menu_item_add_divider(menu);
if (keyword)
{
text = g_strdup_printf(_("Connect \"%s\" to mark"), name);
- item = menu_item_add(menu, text, NULL, NULL);
+ item = menu_item_add(menu, text, nullptr, nullptr);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
g_free(text);
}
menu_item_add_divider(menu);
text = g_strdup_printf(_("Edit \"%s\""), name);
- menu_item_add_stock(menu, text, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_edit_dialog_cb), pkd);
+ menu_item_add_icon(menu, text, GQ_ICON_EDIT, G_CALLBACK(bar_pane_keywords_edit_dialog_cb), pkd);
g_free(text);
text = g_strdup_printf(_("Remove \"%s\""), name);
- menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_delete_cb), pkd);
+ menu_item_add_icon(menu, text, GQ_ICON_DELETE, G_CALLBACK(bar_pane_keywords_delete_cb), pkd);
g_free(text);
if (mark && mark[0])
{
text = g_strdup_printf(_("Disconnect \"%s\" from mark %s"), name, mark);
- menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd);
+ menu_item_add_icon(menu, text, GQ_ICON_DELETE, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd);
g_free(text);
}
if (keyword)
{
text = g_strdup_printf(_("Disconnect all Mark Keyword connections"));
- menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_disconnect_marks_cb), pkd);
+ menu_item_add_icon(menu, text, GQ_ICON_DELETE, G_CALLBACK(bar_pane_keywords_disconnect_marks_cb), pkd);
g_free(text);
}
menu_item_add_divider(menu);
menu_item_add_divider(menu);
submenu = gtk_menu_new();
- item = menu_item_add(menu, _("On any change"), NULL, NULL);
+ item = menu_item_add(menu, _("On any change"), nullptr, nullptr);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
menu_item_add_check(submenu, _("Expand checked"), pkd->expand_checked, G_CALLBACK(bar_pane_keywords_expand_checked_toggle_cb), pkd);
menu_item_add_check(submenu, _("Collapse unchecked"), pkd->collapse_unchecked, G_CALLBACK(bar_pane_keywords_collapse_unchecked_toggle_cb), pkd);
menu_item_add_check(submenu, _("Hide unchecked"), pkd->hide_unchecked, G_CALLBACK(bar_pane_keywords_hide_unchecked_toggle_cb), pkd);
- gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL);
+ gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
}
-
-static gboolean bar_pane_keywords_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+gboolean bar_pane_keywords_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
bar_pane_keywords_menu_popup(widget, pkd, bevent->x, bevent->y);
*-------------------------------------------------------------------
*/
-//void bar_pane_keywords_close(GtkWidget *bar)
-//{
- //PaneKeywordsData *pkd;
-
- //pkd = g_object_get_data(G_OBJECT(bar), "pane_data");
- //if (!pkd) return;
-
- //g_free(pkd->pane.id);
- //gtk_widget_destroy(pkd->widget);
-//}
-
-static void bar_pane_keywords_destroy(GtkWidget *UNUSED(widget), gpointer data)
+void bar_pane_keywords_destroy(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
gchar *path;
path = g_build_filename(get_rc_dir(), "keywords", NULL);
autocomplete_keywords_list_save(path);
- string_list_free(pkd->expanded_rows);
+ g_list_free_full(pkd->expanded_rows, g_free);
if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath);
if (pkd->idle_id) g_source_remove(pkd->idle_id);
file_data_unregister_notify_func(bar_pane_keywords_notify_cb, pkd);
}
-static GtkWidget *bar_pane_keywords_new(const gchar *id, const gchar *title, const gchar *key, gboolean expanded, gint height)
+GtkWidget *bar_pane_keywords_new(const gchar *id, const gchar *title, const gchar *key, gboolean expanded, gint height)
{
PaneKeywordsData *pkd;
- GtkWidget *hbox, *vbox;
+ GtkWidget *hbox;
+ GtkWidget *vbox;
GtkWidget *scrolled;
GtkTextBuffer *buffer;
GtkTreeModel *store;
pkd->key = g_strdup(key);
pkd->expand_checked = TRUE;
- pkd->expanded_rows = NULL;
+ pkd->expanded_rows = nullptr;
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
pkd->widget = vbox;
g_object_set_data(G_OBJECT(pkd->widget), "pane_data", pkd);
gtk_widget_set_size_request(pkd->widget, -1, height);
gtk_widget_show(hbox);
- scrolled = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
+ scrolled = gq_gtk_scrolled_window_new(nullptr, nullptr);
+ gq_gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0);
gtk_widget_show(scrolled);
pkd->keyword_view = gtk_text_view_new();
- gtk_container_add(GTK_CONTAINER(scrolled), pkd->keyword_view);
+ gq_gtk_container_add(GTK_WIDGET(scrolled), pkd->keyword_view);
g_signal_connect(G_OBJECT(pkd->keyword_view), "populate-popup",
G_CALLBACK(bar_pane_keywords_populate_popup_cb), pkd);
gtk_widget_show(pkd->keyword_view);
if (options->show_predefined_keyword_tree)
{
- scrolled = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
+ scrolled = gq_gtk_scrolled_window_new(nullptr, nullptr);
+ gq_gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0);
gtk_widget_show(scrolled);
}
pkd->autocomplete = gtk_entry_new();
- gtk_box_pack_end(GTK_BOX(vbox), pkd->autocomplete, FALSE, FALSE, 0);
+ gq_gtk_box_pack_end(GTK_BOX(vbox), pkd->autocomplete, FALSE, FALSE, 0);
gtk_widget_show(pkd->autocomplete);
gtk_widget_show(vbox);
- gtk_widget_set_tooltip_text(pkd->autocomplete, "Keyword autocomplete");
+ gtk_widget_set_tooltip_text(pkd->autocomplete, _("Keyword autocomplete"));
path = g_build_filename(get_rc_dir(), "keywords", NULL);
autocomplete_keywords_list_load(path);
keyword_tree_new_default();
}
- store = gtk_tree_model_filter_new(GTK_TREE_MODEL(keyword_tree), NULL);
+ store = gtk_tree_model_filter_new(GTK_TREE_MODEL(keyword_tree), nullptr);
gtk_tree_model_filter_set_modify_func(GTK_TREE_MODEL_FILTER(store),
FILTER_KEYWORD_COLUMN_COUNT,
filter_keyword_column_types,
bar_pane_keywords_filter_modify,
pkd,
- NULL);
+ nullptr);
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(store),
bar_pane_keywords_filter_visible,
store,
- NULL);
+ nullptr);
pkd->keyword_treeview = gtk_tree_view_new_with_model(store);
g_object_unref(store);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(pkd->keyword_treeview), FALSE);
-// gtk_tree_view_set_search_column(GTK_TREE_VIEW(pkd->keyword_treeview), FILTER_KEYWORD_COLUMN_);
-
column = gtk_tree_view_column_new();
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
if (options->show_predefined_keyword_tree)
{
- gtk_container_add(GTK_CONTAINER(scrolled), pkd->keyword_treeview);
+ gq_gtk_container_add(GTK_WIDGET(scrolled), pkd->keyword_treeview);
gtk_widget_show(pkd->keyword_treeview);
}
return pkd->widget;
}
-GtkWidget *bar_pane_keywords_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
-{
- gchar *id = g_strdup("keywords");
- gchar *title = NULL;
- gchar *key = g_strdup(COMMENT_KEY);
- gboolean expanded = TRUE;
- gint height = 200;
- GtkWidget *ret;
-
- while (*attribute_names)
- {
- const gchar *option = *attribute_names++;
- const gchar *value = *attribute_values++;
-
- if (READ_CHAR_FULL("id", id)) continue;
- if (READ_CHAR_FULL("title", title)) continue;
- if (READ_CHAR_FULL("key", key)) continue;
- if (READ_BOOL_FULL("expanded", expanded)) continue;
- if (READ_INT_FULL("height", height)) continue;
-
-
- log_printf("unknown attribute %s = %s\n", option, value);
- }
-
- options->info_keywords.height = height;
- bar_pane_translate_title(PANE_KEYWORDS, id, &title);
- ret = bar_pane_keywords_new(id, title, key, expanded, height);
- g_free(id);
- g_free(title);
- g_free(key);
- return ret;
-}
-
-void bar_pane_keywords_update_from_config(GtkWidget *pane, const gchar **attribute_names, const gchar **attribute_values)
-{
- PaneKeywordsData *pkd;
-
- pkd = static_cast<PaneKeywordsData *>(g_object_get_data(G_OBJECT(pane), "pane_data"));
- if (!pkd) return;
-
- gchar *title = NULL;
-
- while (*attribute_names)
- {
- const gchar *option = *attribute_names++;
- const gchar *value = *attribute_values++;
-
- if (READ_CHAR_FULL("title", title)) continue;
- if (READ_CHAR_FULL("key", pkd->key)) continue;
- if (READ_BOOL_FULL("expanded", pkd->pane.expanded)) continue;
- if (READ_CHAR_FULL("id", pkd->pane.id)) continue;
-
-
- log_printf("unknown attribute %s = %s\n", option, value);
- }
-
- if (title)
- {
- bar_pane_translate_title(PANE_KEYWORDS, pkd->pane.id, &title);
- gtk_label_set_text(GTK_LABEL(pkd->pane.title), title);
- g_free(title);
- }
-
- bar_update_expander(pane);
- bar_pane_keywords_update(pkd);
-}
-
-
-void bar_pane_keywords_entry_add_from_config(GtkWidget *pane, const gchar **attribute_names, const gchar **attribute_values)
-{
- PaneKeywordsData *pkd;
- gchar *path = NULL;
- GtkTreePath *tree_path;
-
- pkd = static_cast<PaneKeywordsData *>(g_object_get_data(G_OBJECT(pane), "pane_data"));
- if (!pkd) return;
-
- while (*attribute_names)
- {
- const gchar *option = *attribute_names++;
- const gchar *value = *attribute_values++;
-
- if (READ_CHAR_FULL("path", path))
- {
- tree_path = gtk_tree_path_new_from_string(path);
- gtk_tree_view_expand_to_path(GTK_TREE_VIEW(pkd->keyword_treeview), tree_path);
- gtk_tree_path_free(tree_path);
- pkd->expanded_rows = g_list_append(pkd->expanded_rows, g_strdup(path));
- continue;
- }
- log_printf("unknown attribute %s = %s\n", option, value);
- }
-}
-
/*
*-----------------------------------------------------------------------------
* Autocomplete keywords
*-----------------------------------------------------------------------------
*/
-static gboolean autocomplete_activate_cb(GtkWidget *UNUSED(widget), gpointer data)
+gboolean autocomplete_activate_cb(GtkWidget *, gpointer data)
{
- PaneKeywordsData *pkd = static_cast<PaneKeywordsData *>(data);
+ auto pkd = static_cast<PaneKeywordsData *>(data);
gchar *entry_text;
GtkTextBuffer *buffer;
GtkTextIter iter;
gboolean found = FALSE;
gchar *string;
- entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(pkd->autocomplete)));
+ entry_text = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(pkd->autocomplete)));
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pkd->keyword_view));
kw_split = strtok(entry_text, ",");
- while (kw_split != NULL)
+ while (kw_split != nullptr)
{
kw_cr = g_strconcat(kw_split, "\n", NULL);
g_strchug(kw_cr);
gtk_text_buffer_get_end_iter(buffer, &iter);
gtk_text_buffer_insert(buffer, &iter, kw_cr, -1);
- kw_split = strtok(NULL, ",");
+ kw_split = strtok(nullptr, ",");
g_free(kw_cr);
}
g_free(entry_text);
- entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(pkd->autocomplete)));
+ entry_text = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(pkd->autocomplete)));
- gtk_entry_set_text(GTK_ENTRY(pkd->autocomplete), "");
+ gq_gtk_entry_set_text(GTK_ENTRY(pkd->autocomplete), "");
valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(keyword_store), &iter_t);
while (valid)
gint autocomplete_sort_iter_compare_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
- gpointer UNUSED(userdata))
+ gpointer)
{
gint ret = 0;
- gchar *name1, *name2;
+ gchar *name1;
+ gchar *name2;
gtk_tree_model_get(model, a, 0, &name1, -1);
gtk_tree_model_get(model, b, 0, &name2, -1);
- if (name1 == NULL || name2 == NULL)
+ if (name1 == nullptr || name2 == nullptr)
{
- if (name1 == NULL && name2 == NULL)
+ if (name1 == nullptr && name2 == nullptr)
{
ret = 0;
}
else
{
- ret = (name1 == NULL) ? -1 : 1;
+ ret = (name1 == nullptr) ? -1 : 1;
}
}
else
return ret;
}
-static void autocomplete_keywords_list_load(const gchar *path)
+void autocomplete_keywords_list_load(const gchar *path)
{
FILE *f;
gchar s_buf[1024];
sortable = GTK_TREE_SORTABLE(keyword_store);
gtk_tree_sortable_set_sort_func(sortable, 0, autocomplete_sort_iter_compare_func,
- GINT_TO_POINTER(0), NULL);
+ GINT_TO_POINTER(0), nullptr);
gtk_tree_sortable_set_sort_column_id(sortable, 0, GTK_SORT_ASCENDING);
pathl = path_from_utf8(path);
f = fopen(pathl, "r");
- g_free(pathl);
if (!f)
{
log_printf("Warning: keywords file %s not loaded", pathl);
+ g_free(pathl);
return;
}
{
fclose(f);
log_printf("Warning: keywords file %s not loaded", pathl);
+ g_free(pathl);
return;
}
+ g_free(pathl);
+
while (fgets(s_buf, sizeof(s_buf), f))
{
if (s_buf[0]=='#') continue;
fclose(f);
}
-static gboolean autocomplete_keywords_list_save(gchar *path)
+gboolean autocomplete_keywords_list_save(gchar *path)
{
SecureSaveInfo *ssi;
gchar *pathl;
return (secure_close(ssi) == 0);
}
+} // namespace
+
+/*
+ *-------------------------------------------------------------------
+ * init
+ *-------------------------------------------------------------------
+ */
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+void bar_pane_keywords_close_unused(GtkWidget *bar)
+{
+ PaneKeywordsData *pkd;
+
+ pkd = static_cast<PaneKeywordsData *>(g_object_get_data(G_OBJECT(bar), "pane_data"));
+ if (!pkd) return;
+
+ g_free(pkd->pane.id);
+ g_object_unref(pkd->widget);
+}
+#pragma GCC diagnostic pop
+
+GtkWidget *bar_pane_keywords_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
+{
+ gchar *id = g_strdup("keywords");
+ gchar *title = nullptr;
+ gchar *key = g_strdup(COMMENT_KEY);
+ gboolean expanded = TRUE;
+ gint height = 200;
+ GtkWidget *ret;
+
+ while (*attribute_names)
+ {
+ const gchar *option = *attribute_names++;
+ const gchar *value = *attribute_values++;
+
+ if (READ_CHAR_FULL("id", id)) continue;
+ if (READ_CHAR_FULL("title", title)) continue;
+ if (READ_CHAR_FULL("key", key)) continue;
+ if (READ_BOOL_FULL("expanded", expanded)) continue;
+ if (READ_INT_FULL("height", height)) continue;
+
+
+ log_printf("unknown attribute %s = %s\n", option, value);
+ }
+
+ options->info_keywords.height = height;
+ bar_pane_translate_title(PANE_KEYWORDS, id, &title);
+ ret = bar_pane_keywords_new(id, title, key, expanded, height);
+ g_free(id);
+ g_free(title);
+ g_free(key);
+ return ret;
+}
+
+void bar_pane_keywords_update_from_config(GtkWidget *pane, const gchar **attribute_names, const gchar **attribute_values)
+{
+ PaneKeywordsData *pkd;
+
+ pkd = static_cast<PaneKeywordsData *>(g_object_get_data(G_OBJECT(pane), "pane_data"));
+ if (!pkd) return;
+
+ gchar *title = nullptr;
+
+ while (*attribute_names)
+ {
+ const gchar *option = *attribute_names++;
+ const gchar *value = *attribute_values++;
+
+ if (READ_CHAR_FULL("title", title)) continue;
+ if (READ_CHAR_FULL("key", pkd->key)) continue;
+ if (READ_BOOL_FULL("expanded", pkd->pane.expanded)) continue;
+ if (READ_CHAR_FULL("id", pkd->pane.id)) continue;
+
+
+ log_printf("unknown attribute %s = %s\n", option, value);
+ }
+
+ if (title)
+ {
+ bar_pane_translate_title(PANE_KEYWORDS, pkd->pane.id, &title);
+ gtk_label_set_text(GTK_LABEL(pkd->pane.title), title);
+ g_free(title);
+ }
+
+ bar_update_expander(pane);
+ bar_pane_keywords_update(pkd);
+}
+
+
+void bar_pane_keywords_entry_add_from_config(GtkWidget *pane, const gchar **attribute_names, const gchar **attribute_values)
+{
+ PaneKeywordsData *pkd;
+ gchar *path = nullptr;
+ GtkTreePath *tree_path;
+
+ pkd = static_cast<PaneKeywordsData *>(g_object_get_data(G_OBJECT(pane), "pane_data"));
+ if (!pkd) return;
+
+ while (*attribute_names)
+ {
+ const gchar *option = *attribute_names++;
+ const gchar *value = *attribute_values++;
+
+ if (READ_CHAR_FULL("path", path))
+ {
+ tree_path = gtk_tree_path_new_from_string(path);
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(pkd->keyword_treeview), tree_path);
+ gtk_tree_path_free(tree_path);
+ pkd->expanded_rows = g_list_append(pkd->expanded_rows, g_strdup(path));
+ continue;
+ }
+ log_printf("unknown attribute %s = %s\n", option, value);
+ }
+}
+
+/*
+ *-------------------------------------------------------------------
+ * keyword / comment utils
+ *-------------------------------------------------------------------
+ */
+
+GList *keyword_list_pull(GtkWidget *text_widget)
+{
+ GList *list;
+ gchar *text;
+
+ text = text_widget_text_pull(text_widget);
+ list = string_to_keywords_list(text);
+
+ g_free(text);
+
+ return list;
+}
+
GList *keyword_list_get()
{
- GList *ret_list = NULL;
+ GList *ret_list = nullptr;
gchar *string;
gchar *string_nl;
GtkTreeIter iter;