kwave  18.07.70
GotoPluginBase.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  GotoPluginBase.cpp - base class for the goto plugin
3  -------------------
4  begin : Thu May 12 2011
5  copyright : (C) 2011 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 <math.h>
21 
22 #include <KLocalizedString>
23 #include <QDialog>
24 #include <QString>
25 
26 #include "libkwave/Plugin.h"
27 #include "libkwave/PluginManager.h"
28 #include "libkwave/SignalManager.h"
29 #include "libkwave/String.h"
30 
31 #include "GotoDialog.h"
32 #include "GotoPluginBase.h"
33 
34 //***************************************************************************
36  const QVariantList &args)
37  :Kwave::Plugin(parent, args),
38  m_mode(Kwave::SelectTimeWidget::bySamples), m_position(0)
39 {
40 }
41 
42 //***************************************************************************
44 {
45 }
46 
47 //***************************************************************************
48 QStringList *Kwave::GotoPluginBase::setup(QStringList &previous_params)
49 {
50  // try to interpret the previous parameters
51  interpreteParameters(previous_params);
52 
53  // create the setup dialog
54  double rate = signalRate();
55  sample_index_t length = signalLength();
56 
57  // get the name of the help section
58  QString help_section = _("plugin_sect_") + command();
59 
61  m_mode, m_position, rate, length, help_section);
62  Q_ASSERT(dialog);
63  if (!dialog) return Q_NULLPTR;
64 
65  // set the title of the dialog, depending on the derived class
66  dialog->setWindowTitle(title());
67 
68  QStringList *list = new QStringList();
69  Q_ASSERT(list);
70  if (list && dialog->exec()) {
71  // user has pressed "OK"
72  *list << QString::number(dialog->mode());
73  *list << QString::number(dialog->pos());
74 
75  emitCommand(_("plugin:execute(") + command() +
76  _(",") + QString::number(dialog->mode()) +
77  _(",") + QString::number(dialog->pos()) +
78  _(")")
79  );
80  } else {
81  // user pressed "Cancel"
82  if (list) delete list;
83  list = Q_NULLPTR;
84  }
85 
86  if (dialog) delete dialog;
87  return list;
88 }
89 
90 //***************************************************************************
91 int Kwave::GotoPluginBase::start(QStringList &params)
92 {
93  // interprete the parameters
94  int result = interpreteParameters(params);
95  if (result) return result;
96 
97  // get current offset of the signal
100 
101  // change the selection through the signal manager
102  QString cmd = _("nomacro:") + command() + _("(%1)");
103  emitCommand(cmd.arg(offset));
104 
105  return result;
106 }
107 
108 //***************************************************************************
110 {
111  bool ok;
112  QString param;
113  int mode;
114 
115  // evaluate the parameter list
116  if (params.count() != 2)
117  return -EINVAL;
118 
119  // selection mode for start
120  param = params[0];
121  mode = param.toInt(&ok);
122  Q_ASSERT(ok);
123  if (!ok) return -EINVAL;
124  Q_ASSERT(
125  (mode == static_cast<int>(Kwave::SelectTimeWidget::byTime)) ||
126  (mode == static_cast<int>(Kwave::SelectTimeWidget::bySamples)) ||
127  (mode == static_cast<int>(Kwave::SelectTimeWidget::byPercents))
128  );
129  if ((mode != static_cast<int>(Kwave::SelectTimeWidget::byTime)) &&
130  (mode != static_cast<int>(Kwave::SelectTimeWidget::bySamples)) &&
131  (mode != static_cast<int>(Kwave::SelectTimeWidget::byPercents)))
132  {
133  return -EINVAL;
134  }
135  m_mode = static_cast<Kwave::SelectTimeWidget::Mode>(mode);
136 
137  // position in ms, samples or percent
138  param = params[1];
139  m_position = param.toUInt(&ok);
140  if (!ok) return -EINVAL;
141 
142  return 0;
143 }
144 
145 //***************************************************************************
146 //***************************************************************************
void emitCommand(const QString &command)
Definition: Plugin.cpp:510
Kwave::SelectTimeWidget::Mode m_mode
Definition: App.h:33
QWidget * parentWidget() const
Definition: Plugin.cpp:450
virtual ~GotoPluginBase() Q_DECL_OVERRIDE
virtual QStringList * setup(QStringList &previous_params) Q_DECL_OVERRIDE
quint64 sample_index_t
Definition: Sample.h:28
virtual int start(QStringList &params) Q_DECL_OVERRIDE
static sample_index_t timeToSamples(Mode mode, quint64 time, double rate, sample_index_t length)
virtual sample_index_t signalLength()
Definition: Plugin.cpp:462
int interpreteParameters(QStringList &params)
unsigned int m_position
virtual double signalRate()
Definition: Plugin.cpp:468
virtual QString command() const =0
#define _(m)
Definition: memcpy.c:66
GotoPluginBase(QObject *parent, const QVariantList &args)
quint64 pos() const
Definition: GotoDialog.h:75
virtual QString title() const =0