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