2007-06-18 03:40:41 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2007-2014 Mnemosyne LLC
|
2007-06-18 03:40:41 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2007-06-18 03:40:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2009-11-27 14:55:52 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
2009-11-27 14:55:52 +00:00
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2009-11-27 14:55:52 +00:00
|
|
|
|
2008-08-11 19:05:02 +00:00
|
|
|
#include "actions.h"
|
2007-12-19 02:46:30 +00:00
|
|
|
#include "conf.h"
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-core.h"
|
|
|
|
#include "tr-prefs.h"
|
2021-10-10 16:52:26 +00:00
|
|
|
#include "util.h"
|
2009-11-27 14:55:52 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
static TrCore* myCore = nullptr;
|
|
|
|
static GtkActionGroup* myGroup = nullptr;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void action_cb(GtkAction* a, gpointer user_data)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_actions_handler(gtk_action_get_name(a), user_data);
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static GtkRadioActionEntry sort_radio_entries[] = {
|
2021-10-06 16:32:17 +00:00
|
|
|
{ "sort-by-activity", nullptr, N_("Sort by _Activity"), nullptr, nullptr, 0 },
|
|
|
|
{ "sort-by-name", nullptr, N_("Sort by _Name"), nullptr, nullptr, 1 },
|
|
|
|
{ "sort-by-progress", nullptr, N_("Sort by _Progress"), nullptr, nullptr, 2 },
|
|
|
|
{ "sort-by-queue", nullptr, N_("Sort by _Queue"), nullptr, nullptr, 3 },
|
|
|
|
{ "sort-by-ratio", nullptr, N_("Sort by Rati_o"), nullptr, nullptr, 4 },
|
|
|
|
{ "sort-by-state", nullptr, N_("Sort by Stat_e"), nullptr, nullptr, 5 },
|
|
|
|
{ "sort-by-age", nullptr, N_("Sort by A_ge"), nullptr, nullptr, 6 },
|
|
|
|
{ "sort-by-time-left", nullptr, N_("Sort by Time _Left"), nullptr, nullptr, 7 },
|
|
|
|
{ "sort-by-size", nullptr, N_("Sort by Si_ze"), nullptr, nullptr, 8 },
|
2007-12-19 02:46:30 +00:00
|
|
|
};
|
|
|
|
|
2020-08-18 10:36:10 +00:00
|
|
|
static void sort_changed_cb(GtkAction* action, GtkRadioAction* current, gpointer user_data)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(action);
|
|
|
|
TR_UNUSED(user_data);
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_quark const key = TR_KEY_sort_mode;
|
|
|
|
int const i = gtk_radio_action_get_current_value(current);
|
|
|
|
char const* val = sort_radio_entries[i].name;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_core_set_pref(myCore, key, val);
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static GtkToggleActionEntry show_toggle_entries[] = {
|
2021-10-06 16:32:17 +00:00
|
|
|
{ "toggle-main-window", nullptr, N_("_Show Transmission"), nullptr, nullptr, G_CALLBACK(action_cb), TRUE },
|
|
|
|
{ "toggle-message-log", nullptr, N_("Message _Log"), nullptr, nullptr, G_CALLBACK(action_cb), FALSE },
|
2007-09-21 16:29:09 +00:00
|
|
|
};
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2020-08-18 10:36:10 +00:00
|
|
|
static void toggle_pref_cb(GtkToggleAction* action, gpointer user_data)
|
2007-12-19 18:42:33 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(user_data);
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* key = gtk_action_get_name(GTK_ACTION(action));
|
2021-10-15 13:28:47 +00:00
|
|
|
if (key != nullptr)
|
|
|
|
{
|
|
|
|
gboolean const val = gtk_toggle_action_get_active(action);
|
|
|
|
gtr_core_set_pref_bool(myCore, tr_quark_new(key), val);
|
|
|
|
}
|
2007-12-19 18:42:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static GtkToggleActionEntry pref_toggle_entries[] = {
|
2021-10-06 16:32:17 +00:00
|
|
|
{ "alt-speed-enabled",
|
|
|
|
nullptr,
|
|
|
|
N_("Enable Alternative Speed _Limits"),
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
G_CALLBACK(toggle_pref_cb),
|
|
|
|
FALSE },
|
|
|
|
{ "compact-view", nullptr, N_("_Compact View"), "<alt>C", nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
|
|
|
|
{ "sort-reversed", nullptr, N_("Re_verse Sort Order"), nullptr, nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
|
|
|
|
{ "show-filterbar", nullptr, N_("_Filterbar"), nullptr, nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
|
|
|
|
{ "show-statusbar", nullptr, N_("_Statusbar"), nullptr, nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
|
|
|
|
{ "show-toolbar", nullptr, N_("_Toolbar"), nullptr, nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
|
2007-12-19 02:46:30 +00:00
|
|
|
};
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static GtkActionEntry entries[] = {
|
2021-10-06 16:32:17 +00:00
|
|
|
{ "file-menu", nullptr, N_("_File"), nullptr, nullptr, nullptr },
|
|
|
|
{ "torrent-menu", nullptr, N_("_Torrent"), nullptr, nullptr, nullptr },
|
|
|
|
{ "view-menu", nullptr, N_("_View"), nullptr, nullptr, nullptr },
|
|
|
|
{ "sort-menu", nullptr, N_("_Sort Torrents By"), nullptr, nullptr, nullptr },
|
|
|
|
{ "queue-menu", nullptr, N_("_Queue"), nullptr, nullptr, nullptr },
|
|
|
|
{ "edit-menu", nullptr, N_("_Edit"), nullptr, nullptr, nullptr },
|
|
|
|
{ "help-menu", nullptr, N_("_Help"), nullptr, nullptr, nullptr },
|
|
|
|
{ "copy-magnet-link-to-clipboard", "edit-copy", N_("Copy _Magnet Link to Clipboard"), "", nullptr, G_CALLBACK(action_cb) },
|
2020-07-27 17:49:45 +00:00
|
|
|
{ "open-torrent-from-url", "document-open", N_("Open _URL…"), "<control>U", N_("Open URL…"), G_CALLBACK(action_cb) },
|
2021-10-06 16:32:17 +00:00
|
|
|
{ "open-torrent-toolbar", "document-open", N_("_Open"), nullptr, N_("Open a torrent"), G_CALLBACK(action_cb) },
|
|
|
|
{ "open-torrent-menu", "document-open", N_("_Open"), nullptr, N_("Open a torrent"), G_CALLBACK(action_cb) },
|
2020-07-27 17:49:45 +00:00
|
|
|
{ "torrent-start", "media-playback-start", N_("_Start"), "<control>S", N_("Start torrent"), G_CALLBACK(action_cb) },
|
2021-08-15 09:41:48 +00:00
|
|
|
{ "torrent-start-now",
|
|
|
|
"media-playback-start",
|
|
|
|
N_("Start _Now"),
|
|
|
|
"<shift><control>S",
|
|
|
|
N_("Start torrent now"),
|
|
|
|
G_CALLBACK(action_cb) },
|
2021-10-06 16:32:17 +00:00
|
|
|
{ "show-stats", nullptr, N_("_Statistics"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "donate", nullptr, N_("_Donate"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "torrent-verify", nullptr, N_("_Verify Local Data"), "<control>V", nullptr, G_CALLBACK(action_cb) },
|
2020-07-27 17:49:45 +00:00
|
|
|
{ "torrent-stop", "media-playback-pause", N_("_Pause"), "<control>P", N_("Pause torrent"), G_CALLBACK(action_cb) },
|
2021-10-06 16:32:17 +00:00
|
|
|
{ "pause-all-torrents",
|
|
|
|
"media-playback-pause",
|
|
|
|
N_("_Pause All"),
|
|
|
|
nullptr,
|
|
|
|
N_("Pause all torrents"),
|
|
|
|
G_CALLBACK(action_cb) },
|
|
|
|
{ "start-all-torrents",
|
|
|
|
"media-playback-start",
|
|
|
|
N_("_Start All"),
|
|
|
|
nullptr,
|
|
|
|
N_("Start all torrents"),
|
|
|
|
G_CALLBACK(action_cb) },
|
|
|
|
{ "relocate-torrent", nullptr, N_("Set _Location…"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "remove-torrent", "list-remove", N_("Remove torrent"), "Delete", nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "delete-torrent", "edit-delete", N_("_Delete Files and Remove"), "<shift>Delete", nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "new-torrent", "document-new", N_("_New…"), nullptr, N_("Create a torrent"), G_CALLBACK(action_cb) },
|
|
|
|
{ "quit", "application-exit", N_("_Quit"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "select-all", "edit-select-all", N_("Select _All"), "<control>A", nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "deselect-all", nullptr, N_("Dese_lect All"), "<shift><control>A", nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "edit-preferences", "preferences-system", N_("_Preferences"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
2021-08-15 09:41:48 +00:00
|
|
|
{ "show-torrent-properties",
|
|
|
|
"document-properties",
|
|
|
|
N_("_Properties"),
|
|
|
|
"<alt>Return",
|
|
|
|
N_("Torrent properties"),
|
|
|
|
G_CALLBACK(action_cb) },
|
2021-10-06 16:32:17 +00:00
|
|
|
{ "open-torrent-folder", "document-open", N_("Open Fold_er"), "<control>E", nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "show-about-dialog", "help-about", N_("_About"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "help", "help-browser", N_("_Contents"), "F1", nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "torrent-reannounce", "network-workgroup", N_("Ask Tracker for _More Peers"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "queue-move-top", "go-top", N_("Move to _Top"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "queue-move-up", "go-up", N_("Move _Up"), "<control>Up", nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "queue-move-down", "go-down", N_("Move _Down"), "<control>Down", nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "queue-move-bottom", "go-bottom", N_("Move to _Bottom"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
|
|
|
{ "present-main-window", nullptr, N_("Present Main Window"), nullptr, nullptr, G_CALLBACK(action_cb) },
|
2007-06-18 03:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* filename;
|
|
|
|
char const* name;
|
2021-08-15 09:41:48 +00:00
|
|
|
} BuiltinIconInfo;
|
|
|
|
|
|
|
|
static BuiltinIconInfo const my_fallback_icons[] = {
|
|
|
|
{ "logo-48", WINDOW_ICON }, //
|
|
|
|
{ "logo-24", TRAY_ICON }, //
|
|
|
|
{ "logo-48", NOTIFICATION_ICON }, //
|
|
|
|
{ "lock", "transmission-lock" }, //
|
|
|
|
{ "utilities", "utilities" }, //
|
|
|
|
{ "turtle-blue", "alt-speed-on" }, //
|
|
|
|
{ "turtle-grey", "alt-speed-off" }, //
|
|
|
|
{ "ratio", "ratio" }, //
|
2007-06-18 03:40:41 +00:00
|
|
|
};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void register_my_icons(void)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkIconTheme* theme = gtk_icon_theme_get_default();
|
|
|
|
GtkIconFactory* factory = gtk_icon_factory_new();
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_icon_factory_add_default(factory);
|
2008-02-07 20:27:17 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (size_t i = 0; i < G_N_ELEMENTS(my_fallback_icons); ++i)
|
2008-02-07 20:27:17 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* name = my_fallback_icons[i].name;
|
2008-02-07 20:27:17 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!gtk_icon_theme_has_icon(theme, name))
|
2008-02-07 20:27:17 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GdkPixbuf* p;
|
|
|
|
gchar* resource_path = g_strdup_printf(TR_RESOURCE_PATH "icons/%s.png", my_fallback_icons[i].filename);
|
2016-02-23 04:34:57 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
p = gdk_pixbuf_new_from_resource(resource_path, nullptr);
|
2012-12-27 17:49:52 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(resource_path);
|
2012-12-27 17:49:52 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (p != nullptr)
|
2012-12-27 17:49:52 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int width;
|
|
|
|
GtkIconSet* icon_set;
|
2012-12-27 17:49:52 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
width = gdk_pixbuf_get_width(p);
|
|
|
|
icon_set = gtk_icon_set_new_from_pixbuf(p);
|
2012-12-27 17:49:52 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_icon_theme_add_builtin_icon(name, width, p);
|
|
|
|
gtk_icon_factory_add(factory, name, icon_set);
|
2012-12-27 17:49:52 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_unref(p);
|
|
|
|
gtk_icon_set_unref(icon_set);
|
2012-12-27 17:49:52 +00:00
|
|
|
}
|
2008-02-07 20:27:17 +00:00
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_unref(G_OBJECT(factory));
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
static GtkUIManager* myUIManager = nullptr;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void gtr_actions_set_core(TrCore* core)
|
2007-12-19 18:42:33 +00:00
|
|
|
{
|
|
|
|
myCore = core;
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void gtr_actions_init(GtkUIManager* ui_manager, gpointer callback_user_data)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
int active = -1;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* match;
|
|
|
|
int const n_entries = G_N_ELEMENTS(entries);
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkActionGroup* action_group;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
myUIManager = ui_manager;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
register_my_icons();
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
action_group = myGroup = gtk_action_group_new("Actions");
|
2021-10-06 16:32:17 +00:00
|
|
|
gtk_action_group_set_translation_domain(action_group, nullptr);
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
match = gtr_pref_string_get(TR_KEY_sort_mode);
|
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (size_t i = 0; active == -1 && i < G_N_ELEMENTS(sort_radio_entries); ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
if (g_strcmp0(sort_radio_entries[i].name, match) == 0)
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
active = i;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
gtk_action_group_add_radio_actions(
|
|
|
|
action_group,
|
|
|
|
sort_radio_entries,
|
|
|
|
G_N_ELEMENTS(sort_radio_entries),
|
|
|
|
active,
|
|
|
|
G_CALLBACK(sort_changed_cb),
|
2021-10-06 16:32:17 +00:00
|
|
|
nullptr);
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
gtk_action_group_add_toggle_actions(
|
|
|
|
action_group,
|
|
|
|
show_toggle_entries,
|
|
|
|
G_N_ELEMENTS(show_toggle_entries),
|
2019-02-10 11:05:16 +00:00
|
|
|
callback_user_data);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (size_t i = 0; i < G_N_ELEMENTS(pref_toggle_entries); ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-15 13:28:47 +00:00
|
|
|
pref_toggle_entries[i].is_active = gtr_pref_flag_get(tr_quark_new(pref_toggle_entries[i].name));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
gtk_action_group_add_toggle_actions(
|
|
|
|
action_group,
|
|
|
|
pref_toggle_entries,
|
|
|
|
G_N_ELEMENTS(pref_toggle_entries),
|
2019-02-10 11:05:16 +00:00
|
|
|
callback_user_data);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
gtk_action_group_add_actions(action_group, entries, n_entries, callback_user_data);
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
|
|
|
|
g_object_unref(G_OBJECT(action_group));
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
static GHashTable* key_to_action = nullptr;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void ensure_action_map_loaded(GtkUIManager* uim)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
if (key_to_action != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
return;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
key_to_action = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, nullptr);
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
for (GList* l = gtk_ui_manager_get_action_groups(uim); l != nullptr; l = l->next)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkActionGroup* action_group = GTK_ACTION_GROUP(l->data);
|
2017-05-13 22:38:31 +00:00
|
|
|
GList* actions = gtk_action_group_list_actions(action_group);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
for (GList* ait = actions; ait != nullptr; ait = ait->next)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
GtkAction* action = GTK_ACTION(ait->data);
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* name = gtk_action_get_name(action);
|
2017-04-19 12:04:45 +00:00
|
|
|
g_hash_table_insert(key_to_action, g_strdup(name), action);
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
g_list_free(actions);
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static GtkAction* get_action(char const* name)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ensure_action_map_loaded(myUIManager);
|
2017-04-21 07:40:57 +00:00
|
|
|
return (GtkAction*)g_hash_table_lookup(key_to_action, name);
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void gtr_action_activate(char const* name)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkAction* action = get_action(name);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
g_assert(action != nullptr);
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_action_activate(action);
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void gtr_action_set_sensitive(char const* name, gboolean b)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkAction* action = get_action(name);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
g_assert(action != nullptr);
|
|
|
|
g_object_set(action, "sensitive", b, nullptr);
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void gtr_action_set_important(char const* name, gboolean b)
|
2009-08-16 03:09:06 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkAction* action = get_action(name);
|
2009-08-16 03:25:58 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
g_assert(action != nullptr);
|
|
|
|
g_object_set(action, "is-important", b, nullptr);
|
2009-08-16 03:09:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void gtr_action_set_toggled(char const* name, gboolean b)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkAction* action = get_action(name);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), b);
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
GtkWidget* gtr_action_get_widget(char const* path)
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return gtk_ui_manager_get_widget(myUIManager, path);
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|