Fix some memory leaks in the plugin menu.
[ardour.git] / gtk2_ardour / plugin_selector.cc
1 /*
2     Copyright (C) 2000-2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19 #ifdef WAF_BUILD
20 #include "gtk2ardour-config.h"
21 #endif
22
23 #include <cstdio>
24 #include <lrdf.h>
25 #include <map>
26
27 #include <algorithm>
28
29 #include <gtkmm/table.h>
30 #include <gtkmm/stock.h>
31 #include <gtkmm/button.h>
32 #include <gtkmm/notebook.h>
33
34 #include <gtkmm2ext/utils.h>
35
36 #include "pbd/convert.h"
37
38 #include "ardour/plugin_manager.h"
39 #include "ardour/plugin.h"
40 #include "ardour/configuration.h"
41 #include "ardour/session.h"
42
43 #include "ardour_ui.h"
44 #include "plugin_selector.h"
45 #include "gui_thread.h"
46
47 #include "i18n.h"
48
49 using namespace ARDOUR;
50 using namespace PBD;
51 using namespace Gtk;
52 using namespace std;
53
54 static const char* _filter_mode_strings[] = {
55         N_("Name contains"),
56         N_("Type contains"),
57         N_("Category contains"),
58         N_("Author contains"),
59         N_("Library contains"),
60         N_("Favorites only"),
61         N_("Hidden only"),
62         0
63 };
64
65 PluginSelector::PluginSelector (PluginManager *mgr)
66         : ArdourDialog (_("ardour: plugins"), true, false),
67           filter_button (Stock::CLEAR)
68 {
69         set_position (Gtk::WIN_POS_MOUSE);
70         set_name ("PluginSelectorWindow");
71         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
72
73         manager = mgr;
74         session = 0;
75         in_row_change = false;
76
77         plugin_model = Gtk::ListStore::create (plugin_columns);
78         plugin_display.set_model (plugin_model);
79         /* XXX translators: try to convert "Fav" into a short term
80            related to "favorite" and "Hid" into a short term
81            related to "hidden"
82         */
83         plugin_display.append_column (_("Fav"), plugin_columns.favorite);
84         plugin_display.append_column (_("Hid"), plugin_columns.hidden);
85         plugin_display.append_column (_("Available Plugins"), plugin_columns.name);
86         plugin_display.append_column (_("Type"), plugin_columns.type_name);
87         plugin_display.append_column (_("Category"), plugin_columns.category);
88         plugin_display.append_column (_("Creator"), plugin_columns.creator);
89         plugin_display.append_column (_("# Audio In"),plugin_columns.audio_ins);
90         plugin_display.append_column (_("# Audio Out"), plugin_columns.audio_outs);
91         plugin_display.append_column (_("# MIDI In"),plugin_columns.midi_ins);
92         plugin_display.append_column (_("# MIDI Out"), plugin_columns.midi_outs);
93         plugin_display.set_headers_visible (true);
94         plugin_display.set_headers_clickable (true);
95         plugin_display.set_reorderable (false);
96         plugin_display.set_rules_hint (true);
97
98         CellRendererToggle* fav_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (0));
99         fav_cell->property_activatable() = true;
100         fav_cell->property_radio() = true;
101         fav_cell->signal_toggled().connect (mem_fun (*this, &PluginSelector::favorite_changed));
102
103         CellRendererToggle* hidden_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (1));
104         hidden_cell->property_activatable() = true;
105         hidden_cell->property_radio() = true;
106         hidden_cell->signal_toggled().connect (mem_fun (*this, &PluginSelector::hidden_changed));
107
108         scroller.set_border_width(10);
109         scroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
110         scroller.add(plugin_display);
111
112         amodel = Gtk::ListStore::create(acols);
113         added_list.set_model (amodel);
114         added_list.append_column (_("Plugins to be connected"), acols.text);
115         added_list.set_headers_visible (true);
116         added_list.set_reorderable (false);
117
118         for (int i = 0; i <=8; i++) {
119                 Gtk::TreeView::Column* column = plugin_display.get_column(i);
120                 column->set_sort_column(i);
121         }
122
123         ascroller.set_border_width(10);
124         ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
125         ascroller.add(added_list);
126         btn_add = manage(new Gtk::Button(Stock::ADD));
127         ARDOUR_UI::instance()->tooltips().set_tip(*btn_add, _("Add a plugin to the effect list"));
128         btn_add->set_sensitive (false);
129         btn_remove = manage(new Gtk::Button(Stock::REMOVE));
130         btn_remove->set_sensitive (false);
131         ARDOUR_UI::instance()->tooltips().set_tip(*btn_remove, _("Remove a plugin from the effect list"));
132         Gtk::Button *btn_update = manage(new Gtk::Button(Stock::REFRESH));
133         ARDOUR_UI::instance()->tooltips().set_tip(*btn_update, _("Update available plugins"));
134
135         btn_add->set_name("PluginSelectorButton");
136         btn_remove->set_name("PluginSelectorButton");
137
138         Gtk::Table* table = manage(new Gtk::Table(7, 11));
139         table->set_size_request(750, 500);
140         table->attach(scroller, 0, 7, 0, 5);
141
142         HBox* filter_box = manage (new HBox);
143
144         vector<string> filter_strings = I18N (_filter_mode_strings);
145         Gtkmm2ext::set_popdown_strings (filter_mode, filter_strings);
146         filter_mode.set_active_text (filter_strings.front());
147
148         filter_box->pack_start (filter_mode, false, false);
149         filter_box->pack_start (filter_entry, true, true);
150         filter_box->pack_start (filter_button, false, false);
151
152         filter_entry.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_entry_changed));
153         filter_button.signal_clicked().connect (mem_fun (*this, &PluginSelector::filter_button_clicked));
154         filter_mode.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_mode_changed));
155
156         filter_box->show ();
157         filter_mode.show ();
158         filter_entry.show ();
159         filter_button.show ();
160
161         table->attach (*filter_box, 0, 7, 5, 6, FILL|EXPAND, FILL, 5, 5);
162
163         table->attach(*btn_add, 1, 2, 6, 7, FILL, FILL, 5, 5);
164         table->attach(*btn_remove, 3, 4, 6, 7, FILL, FILL, 5, 5);
165         table->attach(*btn_update, 5, 6, 6, 7, FILL, FILL, 5, 5);
166
167         table->attach(ascroller, 0, 7, 8, 10);
168
169         add_button (Stock::CLOSE, RESPONSE_CLOSE);
170         add_button (_("Insert Plugin(s)"), RESPONSE_APPLY);
171         set_default_response (RESPONSE_APPLY);
172         set_response_sensitive (RESPONSE_APPLY, false);
173         get_vbox()->pack_start (*table);
174
175         table->set_name("PluginSelectorTable");
176         plugin_display.set_name("PluginSelectorDisplay");
177         //plugin_display.set_name("PluginSelectorList");
178         added_list.set_name("PluginSelectorList");
179
180         plugin_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
181         plugin_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::display_selection_changed));
182         plugin_display.grab_focus();
183
184         btn_update->signal_clicked().connect (mem_fun(*this, &PluginSelector::btn_update_clicked));
185         btn_add->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_add_clicked));
186         btn_remove->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_remove_clicked));
187         added_list.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::added_list_selection_changed));
188
189         refill ();
190 }
191
192 void
193 PluginSelector::row_clicked(GdkEventButton* event)
194 {
195         if (event->type == GDK_2BUTTON_PRESS)
196                 btn_add_clicked();
197 }
198
199 void
200 PluginSelector::set_session (Session* s)
201 {
202         ENSURE_GUI_THREAD(bind (mem_fun(*this, &PluginSelector::set_session), s));
203
204         session = s;
205
206         if (session) {
207                 session->GoingAway.connect (bind (mem_fun(*this, &PluginSelector::set_session), static_cast<Session*> (0)));
208         }
209 }
210
211 bool
212 PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& filterstr)
213 {
214         std::string compstr;
215         std::string mode = filter_mode.get_active_text ();
216
217         if (mode == _("Favorites only")) {
218                 return manager->get_status (info) == PluginManager::Favorite;
219         }
220
221         if (mode == _("Hidden only")) {
222                 return manager->get_status (info) == PluginManager::Hidden;
223         }
224
225         if (!filterstr.empty()) {
226
227                 if (mode == _("Name contains")) {
228                         compstr = info->name;
229                 } else if (mode == _("Category contains")) {
230                         compstr = info->category;
231                 } else if (mode == _("Type contains")) {
232
233                         switch (info->type) {
234                         case LADSPA:
235                                 compstr = X_("LADSPA");
236                                 break;
237                         case AudioUnit:
238                                 compstr = X_("AudioUnit");
239                                 break;
240                         case LV2:
241                                 compstr = X_("LV2");
242                                 break;
243                         case VST:
244                                 compstr = X_("VST");
245                                 break;
246                         }
247
248                 } else if (mode == _("Author contains")) {
249                         compstr = info->creator;
250                 } else if (mode == _("Library contains")) {
251                         compstr = info->path;
252                 }
253
254                 if (compstr.empty()) {
255                         return false;
256                 }
257
258                 transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper);
259
260                 if (compstr.find (filterstr) != string::npos) {
261                         return true;
262                 } else {
263                         return false;
264                 }
265         }
266
267         return true;
268 }
269
270 void
271 PluginSelector::setup_filter_string (string& filterstr)
272 {
273         filterstr = filter_entry.get_text ();
274         transform (filterstr.begin(), filterstr.end(), filterstr.begin(), ::toupper);
275 }
276
277 void
278 PluginSelector::refill ()
279 {
280         std::string filterstr;
281
282         in_row_change = true;
283
284         plugin_model->clear ();
285
286         setup_filter_string (filterstr);
287
288         ladspa_refiller (filterstr);
289         lv2_refiller (filterstr);
290         vst_refiller (filterstr);
291         au_refiller (filterstr);
292
293         in_row_change = false;
294 }
295
296 void
297 PluginSelector::refiller (const PluginInfoList& plugs, const::std::string& filterstr, const char* type)
298 {
299         char buf[16];
300
301         for (PluginInfoList::const_iterator i = plugs.begin(); i != plugs.end(); ++i) {
302
303                 if (show_this_plugin (*i, filterstr)) {
304
305                         TreeModel::Row newrow = *(plugin_model->append());
306                         newrow[plugin_columns.favorite] = (manager->get_status (*i) == PluginManager::Favorite);
307                         newrow[plugin_columns.hidden] = (manager->get_status (*i) == PluginManager::Hidden);
308                         newrow[plugin_columns.name] = (*i)->name;
309                         newrow[plugin_columns.type_name] = type;
310                         newrow[plugin_columns.category] = (*i)->category;
311
312                         string creator = (*i)->creator;
313                         string::size_type pos = 0;
314
315                         /* stupid LADSPA creator strings */
316
317                         while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
318                         creator = creator.substr (0, pos);
319
320                         newrow[plugin_columns.creator] = creator;
321
322                         snprintf (buf, sizeof(buf), "%d", (*i)->n_inputs.n_audio());
323                         newrow[plugin_columns.audio_ins] = buf;
324                         snprintf (buf, sizeof(buf), "%d", (*i)->n_inputs.n_midi());
325                         newrow[plugin_columns.midi_ins] = buf;
326
327                         snprintf (buf, sizeof(buf), "%d", (*i)->n_outputs.n_audio());
328                         newrow[plugin_columns.audio_outs] = buf;
329                         snprintf (buf, sizeof(buf), "%d", (*i)->n_outputs.n_midi());
330                         newrow[plugin_columns.midi_outs] = buf;
331
332                         newrow[plugin_columns.plugin] = *i;
333                 }
334         }
335 }
336
337 void
338 PluginSelector::ladspa_refiller (const std::string& filterstr)
339 {
340         refiller (manager->ladspa_plugin_info(), filterstr, "LADSPA");
341 }
342
343 void
344 PluginSelector::lv2_refiller (const std::string& filterstr)
345 {
346 #ifdef HAVE_SLV2
347         refiller (manager->lv2_plugin_info(), filterstr, "LV2");
348 #endif
349 }
350
351 void
352 #ifdef VST_SUPPORT
353 PluginSelector::vst_refiller (const std::string& filterstr)
354 #else
355 PluginSelector::vst_refiller (const std::string&)
356 #endif
357 {
358 #ifdef VST_SUPPORT
359         refiller (manager->vst_plugin_info(), filterstr, "VST");
360 #endif
361 }
362
363 void
364 #ifdef HAVE_AUDIOUNITS
365 PluginSelector::au_refiller (const std::string& filterstr)
366 #else
367 PluginSelector::au_refiller (const std::string&)
368 #endif
369 {
370 #ifdef HAVE_AUDIOUNITS
371         refiller (manager->au_plugin_info(), filterstr, "AU");
372 #endif
373 }
374
375 PluginPtr
376 PluginSelector::load_plugin (PluginInfoPtr pi)
377 {
378         if (session == 0) {
379                 return PluginPtr();
380         }
381
382         return pi->load (*session);
383 }
384
385 void
386 PluginSelector::btn_add_clicked()
387 {
388         std::string name;
389         PluginInfoPtr pi;
390         TreeModel::Row newrow = *(amodel->append());
391         TreeModel::Row row;
392
393         row = *(plugin_display.get_selection()->get_selected());
394         name = row[plugin_columns.name];
395         pi = row[plugin_columns.plugin];
396
397         newrow[acols.text] = name;
398         newrow[acols.plugin] = pi;
399
400         if (!amodel->children().empty()) {
401                 set_response_sensitive (RESPONSE_APPLY, true);
402         }
403 }
404
405 void
406 PluginSelector::btn_remove_clicked()
407 {
408         TreeModel::iterator iter = added_list.get_selection()->get_selected();
409
410         amodel->erase(iter);
411         if (amodel->children().empty()) {
412                 set_response_sensitive (RESPONSE_APPLY, false);
413         }
414 }
415
416 void
417 PluginSelector::btn_update_clicked()
418 {
419         manager->refresh ();
420         refill();
421 }
422
423 void
424 PluginSelector::display_selection_changed()
425 {
426         if (plugin_display.get_selection()->count_selected_rows() != 0) {
427                 btn_add->set_sensitive (true);
428         } else {
429                 btn_add->set_sensitive (false);
430         }
431 }
432
433 void
434 PluginSelector::added_list_selection_changed()
435 {
436         if (added_list.get_selection()->count_selected_rows() != 0) {
437                 btn_remove->set_sensitive (true);
438         } else {
439                 btn_remove->set_sensitive (false);
440         }
441 }
442
443 int
444 PluginSelector::run ()
445 {
446         ResponseType r;
447         TreeModel::Children::iterator i;
448         SelectedPlugins plugins;
449
450         r = (ResponseType) Dialog::run ();
451
452         switch (r) {
453         case RESPONSE_APPLY:
454                 for (i = amodel->children().begin(); i != amodel->children().end(); ++i) {
455                         PluginInfoPtr pp = (*i)[acols.plugin];
456                         PluginPtr p = load_plugin (pp);
457                         if (p) {
458                                 plugins.push_back (p);
459                         }
460                 }
461                 if (interested_object && !plugins.empty()) {
462                         interested_object->use_plugins (plugins);
463                 }
464
465                 break;
466
467         default:
468                 break;
469         }
470
471         hide();
472         amodel->clear();
473         interested_object = 0;
474
475         return (int) r;
476 }
477
478 void
479 PluginSelector::filter_button_clicked ()
480 {
481         filter_entry.set_text ("");
482 }
483
484 void
485 PluginSelector::filter_entry_changed ()
486 {
487         refill ();
488 }
489
490 void
491 PluginSelector::filter_mode_changed ()
492 {
493         std::string mode = filter_mode.get_active_text ();
494
495         if (mode == _("Favorites only") || mode == _("Hidden only")) {
496                 filter_entry.set_sensitive (false);
497         } else {
498                 filter_entry.set_sensitive (true);
499         }
500
501         refill ();
502 }
503
504 void
505 PluginSelector::on_show ()
506 {
507         ArdourDialog::on_show ();
508         filter_entry.grab_focus ();
509 }
510
511 struct PluginMenuCompareByCreator {
512     bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
513             int cmp;
514
515             cmp = strcasecmp (a->creator.c_str(), b->creator.c_str());
516
517             if (cmp < 0) {
518                     return true;
519             } else if (cmp == 0) {
520                     /* same creator ... compare names */
521                     if (strcasecmp (a->name.c_str(), b->name.c_str()) < 0) {
522                             return true;
523                     }
524             }
525             return false;
526     }
527 };
528
529 struct PluginMenuCompareByName {
530     bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
531             int cmp;
532
533             cmp = strcasecmp (a->name.c_str(), b->name.c_str());
534
535             if (cmp < 0) {
536                     return true;
537             } else if (cmp == 0) {
538                     /* same name ... compare type */
539                     if (a->type < b->type) {
540                             return true;
541                     }
542             }
543             return false;
544     }
545 };
546
547 struct PluginMenuCompareByCategory {
548     bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
549             int cmp;
550
551             cmp = strcasecmp (a->category.c_str(), b->category.c_str());
552
553             if (cmp < 0) {
554                     return true;
555             } else if (cmp == 0) {
556                     /* same category ... compare names */
557                     if (strcasecmp (a->name.c_str(), b->name.c_str()) < 0) {
558                             return true;
559                     }
560             }
561             return false;
562     }
563 };
564
565 /** @return a Gtk::manage()d menu */
566 Gtk::Menu*
567 PluginSelector::plugin_menu()
568 {
569         PluginInfoList all_plugs;
570
571         all_plugs.insert (all_plugs.end(), manager->ladspa_plugin_info().begin(), manager->ladspa_plugin_info().end());
572 #ifdef VST_SUPPORT
573         all_plugs.insert (all_plugs.end(), manager->vst_plugin_info().begin(), manager->vst_plugin_info().end());
574 #endif
575 #ifdef HAVE_AUDIOUNITS
576         all_plugs.insert (all_plugs.end(), manager->au_plugin_info().begin(), manager->au_plugin_info().end());
577 #endif
578 #ifdef HAVE_SLV2
579         all_plugs.insert (all_plugs.end(), manager->lv2_plugin_info().begin(), manager->lv2_plugin_info().end());
580 #endif
581
582         using namespace Menu_Helpers;
583
584         Menu* menu = manage (new Menu());
585         menu->set_name("ArdourContextMenu");
586
587         MenuList& items = menu->items();
588         items.clear ();
589
590         Gtk::Menu* favs = create_favs_menu(all_plugs);
591         items.push_back (MenuElem (_("Favorites"), *manage (favs)));
592
593         items.push_back (MenuElem (_("Plugin Manager"), mem_fun (*this, &PluginSelector::show_manager)));
594         items.push_back (SeparatorElem ());
595
596         Menu* by_creator = create_by_creator_menu(all_plugs);
597         items.push_back (MenuElem (_("By Creator"), *manage (by_creator)));
598
599         Menu* by_category = create_by_category_menu(all_plugs);
600         items.push_back (MenuElem (_("By Category"), *manage (by_category)));
601
602         return menu;
603 }
604
605 Gtk::Menu*
606 PluginSelector::create_favs_menu (PluginInfoList& all_plugs)
607 {
608         using namespace Menu_Helpers;
609
610         Menu* favs = new Menu();
611         favs->set_name("ArdourContextMenu");
612
613         PluginMenuCompareByName cmp_by_name;
614         all_plugs.sort (cmp_by_name);
615
616         for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
617                 if (manager->get_status (*i) == PluginManager::Favorite) {
618                         favs->items().push_back (MenuElem ((*i)->name, (bind (mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
619                 }
620         }
621         return favs;
622 }
623
624 Gtk::Menu*
625 PluginSelector::create_by_creator_menu (ARDOUR::PluginInfoList& all_plugs)
626 {
627         using namespace Menu_Helpers;
628
629         typedef std::map<Glib::ustring,Gtk::Menu*> SubmenuMap;
630         SubmenuMap creator_submenu_map;
631
632         Menu* by_creator = new Menu();
633         by_creator->set_name("ArdourContextMenu");
634
635         MenuList& by_creator_items = by_creator->items();
636         PluginMenuCompareByCreator cmp_by_creator;
637         all_plugs.sort (cmp_by_creator);
638
639         for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
640
641                 if (manager->get_status (*i) == PluginManager::Hidden) continue;
642
643                 string creator = (*i)->creator;
644
645                 /* stupid LADSPA creator strings */
646                 string::size_type pos = 0;
647                 while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
648                 creator = creator.substr (0, pos);
649
650                 SubmenuMap::iterator x;
651                 Gtk::Menu* submenu;
652                 if ((x = creator_submenu_map.find (creator)) != creator_submenu_map.end()) {
653                         submenu = x->second;
654                 } else {
655                         submenu = new Gtk::Menu;
656                         by_creator_items.push_back (MenuElem (creator, *manage (submenu)));
657                         creator_submenu_map.insert (pair<Glib::ustring,Menu*> (creator, submenu));
658                         submenu->set_name("ArdourContextMenu");
659                 }
660                 submenu->items().push_back (MenuElem ((*i)->name, (bind (mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
661         }
662         return by_creator;
663 }
664
665 Gtk::Menu*
666 PluginSelector::create_by_category_menu (ARDOUR::PluginInfoList& all_plugs)
667 {
668         using namespace Menu_Helpers;
669
670         typedef std::map<Glib::ustring,Gtk::Menu*> SubmenuMap;
671         SubmenuMap category_submenu_map;
672
673         Menu* by_category = new Menu();
674         by_category->set_name("ArdourContextMenu");
675
676         MenuList& by_category_items = by_category->items();
677         PluginMenuCompareByCategory cmp_by_category;
678         all_plugs.sort (cmp_by_category);
679
680         for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
681
682                 if (manager->get_status (*i) == PluginManager::Hidden) continue;
683
684                 string category = (*i)->category;
685
686                 SubmenuMap::iterator x;
687                 Gtk::Menu* submenu;
688                 if ((x = category_submenu_map.find (category)) != category_submenu_map.end()) {
689                         submenu = x->second;
690                 } else {
691                         submenu = new Gtk::Menu;
692                         by_category_items.push_back (MenuElem (category, *manage (submenu)));
693                         category_submenu_map.insert (pair<Glib::ustring,Menu*> (category, submenu));
694                         submenu->set_name("ArdourContextMenu");
695                 }
696                 submenu->items().push_back (MenuElem ((*i)->name, (bind (mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
697         }
698         return by_category;
699 }
700
701 void
702 PluginSelector::plugin_chosen_from_menu (const PluginInfoPtr& pi)
703 {
704         PluginPtr p = load_plugin (pi);
705
706         if (p && interested_object) {
707                 SelectedPlugins plugins;
708                 plugins.push_back (p);
709                 interested_object->use_plugins (plugins);
710         }
711
712         interested_object = 0;
713 }
714
715 void
716 PluginSelector::favorite_changed (const Glib::ustring& path)
717 {
718         PluginInfoPtr pi;
719
720         if (in_row_change) {
721                 return;
722         }
723
724         in_row_change = true;
725
726         TreeModel::iterator iter = plugin_model->get_iter (path);
727
728         if (iter) {
729
730                 bool favorite = !(*iter)[plugin_columns.favorite];
731
732                 /* change state */
733
734                 (*iter)[plugin_columns.favorite] = favorite;
735                 (*iter)[plugin_columns.hidden] = false;
736                 PluginManager::PluginStatusType status = (favorite ? PluginManager::Favorite : PluginManager::Normal);
737
738                 /* save new statuses list */
739
740                 pi = (*iter)[plugin_columns.plugin];
741
742                 manager->set_status (pi->type, pi->unique_id, status);
743
744                 manager->save_statuses ();
745         }
746         in_row_change = false;
747 }
748
749 void
750 PluginSelector::hidden_changed (const Glib::ustring& path)
751 {
752         PluginInfoPtr pi;
753
754         if (in_row_change) {
755                 return;
756         }
757
758         in_row_change = true;
759
760         TreeModel::iterator iter = plugin_model->get_iter (path);
761
762         if (iter) {
763
764                 bool hidden = !(*iter)[plugin_columns.hidden];
765
766                 /* change state */
767
768                 (*iter)[plugin_columns.favorite] = false;
769                 (*iter)[plugin_columns.hidden] = hidden;
770                 PluginManager::PluginStatusType status = (hidden ? PluginManager::Hidden : PluginManager::Normal);
771
772                 /* save new statuses list */
773
774                 pi = (*iter)[plugin_columns.plugin];
775
776                 manager->set_status (pi->type, pi->unique_id, status);
777
778                 manager->save_statuses ();
779         }
780         in_row_change = false;
781 }
782
783 void
784 PluginSelector::show_manager ()
785 {
786         show_all();
787         run ();
788 }
789
790 void
791 PluginSelector::set_interested_object (PluginInterestedObject& obj)
792 {
793         interested_object = &obj;
794 }