| 1 | /* |
| 2 | Copyright (C) 2010 Andres Cabrera |
| 3 | [email protected] |
| 4 | |
| 5 | This file is part of CsoundQt. |
| 6 | |
| 7 | CsoundQt is free software; you can redistribute it |
| 8 | and/or modify it under the terms of the GNU Lesser General Public |
| 9 | License as published by the Free Software Foundation; either |
| 10 | version 2.1 of the License, or (at your option) any later version. |
| 11 | |
| 12 | CsoundQt is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU Lesser General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Lesser General Public |
| 18 | License along with Csound; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include "pluginspage.h" |
| 24 | #include "ui_pluginspage.h" |
| 25 | |
| 26 | #include <QDir> |
| 27 | #include <QDebug> |
| 28 | |
| 29 | PluginsPage::PluginsPage(QWidget *parent, QString opcodeDir) : |
| 30 | QWizardPage(parent), |
| 31 | ui(new Ui::PluginsPage) |
| 32 | { |
| 33 | ui->setupUi(this); |
| 34 | connect(ui->selectAllButton, SIGNAL(released()), this, SLOT(selectAll())); |
| 35 | connect(ui->selectNoneButton, SIGNAL(released()), this, SLOT(selectNone())); |
| 36 | connect(ui->deselectFltkButton, SIGNAL(released()), this, SLOT(deselectFltk())); |
| 37 | // registerField("plugins", ui->pluginsListWidget); |
| 38 | connect(ui->pluginsListWidget, SIGNAL(itemSelectionChanged () ), this, SLOT(selectionChanged())); |
| 39 | if (!opcodeDir.isEmpty()) { |
| 40 | setField("opcodeDir", opcodeDir); |
| 41 | } |
| 42 | updateOpcodeDir(); |
| 43 | } |
| 44 | |
| 45 | PluginsPage::~PluginsPage() |
| 46 | { |
| 47 | delete ui; |
| 48 | } |
| 49 | |
| 50 | void PluginsPage::selectAll() |
| 51 | { |
| 52 | ui->pluginsListWidget->selectAll(); |
| 53 | } |
| 54 | |
| 55 | void PluginsPage::selectNone() |
| 56 | { |
| 57 | ui->pluginsListWidget->clearSelection(); |
| 58 | } |
| 59 | |
| 60 | void PluginsPage::deselectFltk() |
| 61 | { |
| 62 | QList<QString> fltkNames; |
| 63 | fltkNames << "libwidgets" << "libvirtual" << "libfluidOpcodes"; |
| 64 | QList<QListWidgetItem *> selected = ui->pluginsListWidget->selectedItems(); |
| 65 | foreach (QListWidgetItem *item, selected) { |
| 66 | foreach (QString name, fltkNames) { |
| 67 | if (item->text().startsWith(name)) { |
| 68 | item->setSelected(false); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | void PluginsPage::updateOpcodeDir() |
| 75 | { |
| 76 | QStringList filters; |
| 77 | QStringList plugins; |
| 78 | QString opcodeDir = field("opcodeDir").toString(); |
| 79 | #ifdef Q_OS_MAC |
| 80 | opcodeDir = field("libDir").toString() + "/CsoundLib"; |
| 81 | if (field("useDoubles").toBool()) { |
| 82 | opcodeDir += "64"; |
| 83 | } |
| 84 | opcodeDir += ".framework/Resources/Opcodes"; |
| 85 | if (!QFile::exists(opcodeDir) && !field("opcodeDir").toString().isEmpty() ) { |
| 86 | opcodeDir = field("opcodeDir").toString(); |
| 87 | } |
| 88 | #endif |
| 89 | qDebug() << "PluginsPage::updateOpcodeDir " << opcodeDir; |
| 90 | #ifdef Q_OS_LINUX |
| 91 | filters << "*.so"; |
| 92 | #endif |
| 93 | #ifdef Q_OS_MAC |
| 94 | filters << "*.dylib"; |
| 95 | #endif |
| 96 | #ifdef Q_OS_WIN32 |
| 97 | filters << "*.dll"; |
| 98 | #endif |
| 99 | plugins = QDir(opcodeDir).entryList(filters); |
| 100 | foreach (QString plugin, plugins) { |
| 101 | if (!plugin.startsWith(".")) { |
| 102 | ui->pluginsListWidget->addItem(plugin); |
| 103 | } |
| 104 | } |
| 105 | m_opcodeDir = opcodeDir; |
| 106 | ui->pluginsListWidget->selectAll(); |
| 107 | } |
| 108 | |
| 109 | QString PluginsPage::getOpcodeDir() |
| 110 | { |
| 111 | return m_opcodeDir; |
| 112 | } |
| 113 | |
| 114 | void PluginsPage::changeEvent(QEvent *e) |
| 115 | { |
| 116 | QWizardPage::changeEvent(e); |
| 117 | switch (e->type()) { |
| 118 | case QEvent::LanguageChange: |
| 119 | ui->retranslateUi(this); |
| 120 | break; |
| 121 | default: |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void PluginsPage::selectionChanged() |
| 127 | { |
| 128 | QList<QListWidgetItem *> selected = ui->pluginsListWidget->selectedItems(); |
| 129 | QStringList plugins; |
| 130 | foreach (QListWidgetItem *item, selected) { |
| 131 | plugins << item->text(); |
| 132 | } |
| 133 | setProperty("plugins", plugins); |
| 134 | } |