RTXI  3.0.0
The Real-Time eXperiment Interface Reference Manual
model_loader.cpp
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah,
4  Weill Cornell Medical College
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19  */
20 
21 #include <algorithm>
22 
23 #include <debug.h>
24 #include <main_window.h>
25 #include <model_loader.h>
26 
27 extern "C" Plugin::Object* createRTXIPlugin(void*)
28 {
29  return new ModelLoader();
30 }
31 
33 {
34  action = MainWindow::getInstance()->createModuleMenuItem(
35  "Load Plugin", this, SLOT(load(void)));
36 
37  // Add recently used modules to the menu
38  MainWindow::getInstance()->insertModuleMenuSeparator();
39  QSettings userprefs;
40  userprefs.setPath(QSettings::NativeFormat,
41  QSettings::SystemScope,
42  "/usr/local/share/rtxi/");
43  userprefs.beginGroup("/recentFileList");
44  QStringList entries = userprefs.childKeys();
45  userprefs.endGroup();
46  int numRecentFiles = entries.size();
47  QString listmodule;
48  QString text;
49  for (int i = 0; i < std::min(numRecentFiles - 2, 10); ++i) {
50  listmodule = userprefs.value("/recentFileList/" + entries[i]).toString();
51  text = tr("&%1 %2").arg(i).arg(listmodule);
52  MainWindow::getInstance()->createModuleMenuItem(text);
53  }
54 
55  // Add recently used settings files to the menu
56  userprefs.beginGroup("/recentSettingsList");
57  entries = userprefs.childKeys();
58  userprefs.endGroup();
59  numRecentFiles = entries.size() - 1;
60  for (int i = 0; i < std::min(numRecentFiles, 10); ++i) {
61  listmodule =
62  userprefs.value("/recentSettingsList/" + entries[i]).toString();
63  text = tr("&%1 %2").arg(i).arg(listmodule);
64  MainWindow::getInstance()->createFileMenuItem(text);
65  }
66 }
67 
69 {
70  MainWindow::getInstance()->removeModuleMenuItem(action);
71 }
72 
74 {
75  QString plugin_dir = QString(EXEC_PREFIX) + QString("/lib/rtxi/");
76  QString filename = QFileDialog::getOpenFileName(
77  0, tr("Load plugin"), plugin_dir, tr("Plugins (*.so);;All (*.*)"));
78 
79  if (filename.isNull() || filename.isEmpty()
80  || filename.contains("model_loader") || filename.contains("analogy"))
81  return;
82 
83  if (filename.startsWith(plugin_dir))
84  filename.remove(0, plugin_dir.length());
85 
86  Plugin::Manager::getInstance()->load(filename.toLatin1());
87 
88  // load QSettings
89  QSettings userprefs;
90  userprefs.setPath(
91  QSettings::NativeFormat, QSettings::SystemScope, "/usr/local/share/rtxi");
92 
93  int oldestmodule = userprefs.value("/recentFileList/start", 0).toInt();
94  if (oldestmodule == 0)
95  userprefs.setValue("/recentFileList/start", 0);
96 
97  int num_module = userprefs.value("/recentFileList/num", 0).toInt();
98  userprefs.beginGroup("/recentFileList");
99  QStringList entries = userprefs.childKeys();
100  userprefs.endGroup();
101 
102  int numRecentFiles = entries.size();
103  QString listmodule;
104 
105  bool doesnotexist = true;
106 
107  for (int i = 0; i < numRecentFiles; ++i) {
108  listmodule = userprefs.value("/recentFileList/" + entries[i]).toString();
109  if (filename == listmodule)
110  doesnotexist = false;
111  }
112  if (doesnotexist) {
113  if (num_module == 10) {
114  userprefs.setValue("/recentFileList/" + QString::number(oldestmodule),
115  filename);
116  oldestmodule++;
117  if (oldestmodule == 10)
118  oldestmodule = 0;
119  userprefs.setValue("/recentFileList/start", oldestmodule);
120  } else {
121  userprefs.setValue("/recentFileList/" + QString::number(num_module++),
122  filename);
123  userprefs.setValue("/recentFileList/num", num_module);
124  }
125  }
126 }
virtual ~ModelLoader(void)
ModelLoader(void)
void load(void)
Plugin::Object * createRTXIPlugin(void *)