kwave  18.07.70
MemoryPlugin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  MemoryPlugin.cpp - setup of Kwave's memory management
3  -------------------
4  begin : Sun Aug 05 2001
5  copyright : (C) 2001 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 #include <errno.h>
20 #include <limits.h>
21 
22 #include <QString>
23 #include <QStringList>
24 
25 #include <KLocalizedString>
26 
27 #include "libkwave/MemoryManager.h"
28 #include "libkwave/Plugin.h"
29 #include "libkwave/String.h"
30 
31 #include "MemoryDialog.h"
32 #include "MemoryPlugin.h"
33 
34 KWAVE_PLUGIN(memory, MemoryPlugin)
35 
36 
37 #define DEFAULT_PHYSICAL_LIMIT 2048
38 
40 #define DEFAULT_VIRTUAL_LIMIT 2048
41 
43 #define DEFAULT_UNDO_LIMIT 1024
44 
45 //***************************************************************************
47  const QVariantList &args)
48  :Kwave::Plugin(parent, args),
49  m_physical_limited(true),
50  m_physical_limit(DEFAULT_PHYSICAL_LIMIT),
51  m_virtual_enabled(true),
52  m_virtual_limited(false),
53  m_virtual_limit(DEFAULT_VIRTUAL_LIMIT),
54  m_virtual_directory(_("/var/tmp")),
55  m_undo_limit(DEFAULT_UNDO_LIMIT)
56 {
57 }
58 
59 //***************************************************************************
61 {
62 }
63 
64 //***************************************************************************
66 {
67  bool ok;
68  QString param;
69 
70  // evaluate the parameter list
71  if (params.count() < 6) return -EINVAL;
72 
73  // parameter #0: physical memory is limited ?
74  param = params[0];
75  m_physical_limited = param.toUInt(&ok) != 0;
76  if (!ok) return -EINVAL;
77 
78  // parameter #1: limit for physical memory
79  param = params[1];
80  m_physical_limit = param.toUInt(&ok);
81  if (!ok) return -EINVAL;
82 
83  // parameter #2: virtual memory is enabled ?
84  param = params[2];
85  m_virtual_enabled = param.toUInt(&ok) != 0;
86  if (!ok) return -EINVAL;
87 
88  // parameter #3: virtual memory is limited ?
89  param = params[3];
90  m_virtual_limited = param.toUInt(&ok) != 0;
91  if (!ok) return -EINVAL;
92 
93  // parameter #4: limit for virtual memory
94  if (m_virtual_limited) {
95  param = params[4];
96  m_virtual_limit = param.toUInt(&ok);
97  if (!ok) return -EINVAL;
98  } else {
99  m_virtual_limit = INT_MAX;
100  }
101 
102  // parameter #5: directory for virtual memory files
103  param = params[5];
104  m_virtual_directory = param;
105 
106  // parameter #6: limit for undo/redo
107  if (params.count() >= 7)
108  {
109  param = params[6];
110  m_undo_limit = param.toUInt(&ok);
111  if (!ok) return -EINVAL;
112  }
113 
114  return 0;
115 }
116 
117 //***************************************************************************
118 void Kwave::MemoryPlugin::load(QStringList &params)
119 {
120  interpreteParameters(params);
121  applySettings();
122 }
123 
124 //***************************************************************************
126 {
130  (m_virtual_limited ? m_virtual_limit : INT_MAX) :
131  0);
134 }
135 
136 //***************************************************************************
137 QStringList *Kwave::MemoryPlugin::setup(QStringList &previous_params)
138 {
139  QStringList *result = Q_NULLPTR;
140 
141  // try to interpret the list of previous parameters, ignore errors
142  if (previous_params.count()) interpreteParameters(previous_params);
143 
148  Q_ASSERT(dlg);
149  if (!dlg) return Q_NULLPTR;
150 
151  if (dlg->exec() == QDialog::Accepted) {
152  // get the new parameters and let them take effect
153  result = new QStringList();
154  Q_ASSERT(result);
155  if (result) {
156  dlg->params(*result);
157  interpreteParameters(*result);
158  applySettings();
159  }
160  };
161 
162  delete dlg;
163  return result;
164 }
165 
166 //***************************************************************************
167 #include "MemoryPlugin.moc"
168 //***************************************************************************
169 //***************************************************************************
unsigned int m_virtual_limit
Definition: MemoryPlugin.h:104
MemoryPlugin(QObject *parent, const QVariantList &args)
void setVirtualLimit(quint64 mb) Q_DECL_EXPORT
Definition: App.h:33
static MemoryManager & instance() Q_DECL_EXPORT
QWidget * parentWidget() const
Definition: Plugin.cpp:450
void params(QStringList &par)
void setUndoLimit(quint64 mb) Q_DECL_EXPORT
unsigned int m_physical_limit
Definition: MemoryPlugin.h:87
int interpreteParameters(QStringList &params)
#define DEFAULT_VIRTUAL_LIMIT
virtual QStringList * setup(QStringList &previous_params) Q_DECL_OVERRIDE
void setSwapDirectory(const QString &dir) Q_DECL_EXPORT
unsigned int m_undo_limit
Definition: MemoryPlugin.h:112
void setPhysicalLimit(quint64 mb) Q_DECL_EXPORT
#define KWAVE_PLUGIN(name, class)
Definition: Plugin.h:54
#define _(m)
Definition: memcpy.c:66
#define DEFAULT_PHYSICAL_LIMIT
#define DEFAULT_UNDO_LIMIT
virtual ~MemoryPlugin() Q_DECL_OVERRIDE
QString m_virtual_directory
Definition: MemoryPlugin.h:107
virtual void load(QStringList &params) Q_DECL_OVERRIDE