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